Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/dfChemistryModel/pytorchFunctions.H
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ Foam::scalar Foam::dfChemistryModel<ThermoType>::solve_DNN(const DeltaTType &del
std::chrono::steady_clock::time_point start8 = std::chrono::steady_clock::now();

pybind11::array_t<double> vec0 = pybind11::array_t<double>({DNNinputs[0].size()}, {8}, &DNNinputs[0][0]); // cast vector to np.array
pybind11::array_t<double> vec1 = pybind11::array_t<double>({DNNinputs[1].size()}, {8}, &DNNinputs[1][0]);
pybind11::array_t<double> vec2 = pybind11::array_t<double>({DNNinputs[2].size()}, {8}, &DNNinputs[2][0]);

std::chrono::steady_clock::time_point stop8 = std::chrono::steady_clock::now();
std::chrono::duration<double> processingTime8 = std::chrono::duration_cast<std::chrono::duration<double>>(stop8 - start8);
Expand All @@ -130,7 +128,7 @@ Foam::scalar Foam::dfChemistryModel<ThermoType>::solve_DNN(const DeltaTType &del

std::chrono::steady_clock::time_point start9 = std::chrono::steady_clock::now();

pybind11::object result = call_torch.attr("inference")(vec0, vec1, vec2); // call python function
pybind11::object result = call_torch.attr("inference")(vec0); // call python function
const double* star = result.cast<pybind11::array_t<double>>().data();

std::chrono::steady_clock::time_point stop9 = std::chrono::steady_clock::now();
Expand All @@ -146,9 +144,7 @@ Foam::scalar Foam::dfChemistryModel<ThermoType>::solve_DNN(const DeltaTType &del
/*=============================construct solutions=============================*/
std::chrono::steady_clock::time_point start6 = std::chrono::steady_clock::now();
std::vector<double> outputsVec0(star, star+outputLength[0] * mixture_.nSpecies()); //the float number is sample_length*sample_number
std::vector<double> outputsVec1(star+outputLength[0] * mixture_.nSpecies(), star+outputLength[1] * mixture_.nSpecies());
std::vector<double> outputsVec2(star+outputLength[1] * mixture_.nSpecies(), star+outputLength[2] * mixture_.nSpecies());
std::vector<std::vector<double>> results = {outputsVec0, outputsVec1, outputsVec2};
std::vector<std::vector<double>> results = {outputsVec0};
updateSolutionBuffer(solutionBuffer, results, cellIDBuffer, problemCounter);
std::chrono::steady_clock::time_point stop6 = std::chrono::steady_clock::now();
std::chrono::duration<double> processingTime6 = std::chrono::duration_cast<std::chrono::duration<double>>(stop6 - start6);
Expand Down Expand Up @@ -270,15 +266,11 @@ Foam::scalar Foam::dfChemistryModel<ThermoType>::solve_DNN(const DeltaTType &del
problemBuffer.append(GPUproblemList);
getDNNinputs(problemBuffer, outputLength, DNNinputs, cellIDBuffer, problemCounter);
pybind11::array_t<double> vec0 = pybind11::array_t<double>({DNNinputs[0].size()}, {8}, &DNNinputs[0][0]); // cast vector to np.array
pybind11::array_t<double> vec1 = pybind11::array_t<double>({DNNinputs[1].size()}, {8}, &DNNinputs[1][0]);
pybind11::array_t<double> vec2 = pybind11::array_t<double>({DNNinputs[2].size()}, {8}, &DNNinputs[2][0]);
pybind11::module_ call_torch = pybind11::module_::import("inference"); // import python file
pybind11::object result = call_torch.attr("inference")(vec0, vec1, vec2); // call python function
pybind11::object result = call_torch.attr("inference")(vec0); // call python function
const double* star = result.cast<pybind11::array_t<double>>().data();
std::vector<double> outputsVec0(star, star+outputLength[0] * mixture_.nSpecies()); //the float number is sample_length*sample_number
std::vector<double> outputsVec1(star+outputLength[0] * mixture_.nSpecies(), star+outputLength[1] * mixture_.nSpecies());
std::vector<double> outputsVec2(star+outputLength[1] * mixture_.nSpecies(), star+outputLength[2] * mixture_.nSpecies());
std::vector<std::vector<double>> results = {outputsVec0, outputsVec1, outputsVec2};
std::vector<std::vector<double>> results = {outputsVec0};
updateSolutionBuffer(solutionBuffer, results, cellIDBuffer, problemCounter);
DynamicList<GpuSolution> finalList;
finalList = solutionBuffer[0];
Expand Down
23 changes: 6 additions & 17 deletions src/dfChemistryModel/torchFunctions.H
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ void Foam::dfChemistryModel<ThermoType>::getGPUProblems
scalar pi = p_[cellI];
scalar rhoi = rho_[cellI];

// if T < 700, set RR=0
if (T_[cellI] < 700)
{
Qdot_[cellI] = 0;
for (int i = 0; i < mixture_.nSpecies(); i++)
{
RR_[i][cellI] = 0.0;
}
continue;
}

// set problems
GpuProblem problem(mixture_.nSpecies());
ChemistryProblem ode_problem(mixture_.nSpecies());
Expand Down Expand Up @@ -147,12 +136,12 @@ void Foam::dfChemistryModel<ThermoType>::getDNNinputs
cellIDBuffer = {cellIDList0Buffer, cellIDList1Buffer, cellIDList2Buffer};
problemCounter = {problemCounter0, problemCounter1, problemCounter2};

if (gpulog_)
{
std::cout<<"inputsDNN0 = "<<inputsDNN0.size()/(mixture_.nSpecies()+3) << "\n";
std::cout<<"inputsDNN1 = "<<inputsDNN1.size()/(mixture_.nSpecies()+3) << "\n";
std::cout<<"inputsDNN2 = "<<inputsDNN2.size()/(mixture_.nSpecies()+3) << "\n";
}
//if (gpulog_)
//{
// std::cout<<"inputsDNN0 = "<<inputsDNN0.size()/(mixture_.nSpecies()+3) << "\n";
// std::cout<<"inputsDNN1 = "<<inputsDNN1.size()/(mixture_.nSpecies()+3) << "\n";
// std::cout<<"inputsDNN2 = "<<inputsDNN2.size()/(mixture_.nSpecies()+3) << "\n";
//}

return;
}
Expand Down