From 34956060ffcfb8c07e9f2fcc0e218c2ae69cc029 Mon Sep 17 00:00:00 2001 From: risinyoung Date: Fri, 22 Dec 2023 14:46:34 +0800 Subject: [PATCH 1/2] modified to DF-ODENet v0.1 --- src/dfChemistryModel/pytorchFunctions.H | 16 ++++------------ src/dfChemistryModel/torchFunctions.H | 11 ----------- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/dfChemistryModel/pytorchFunctions.H b/src/dfChemistryModel/pytorchFunctions.H index dfaf439c8..5ed4200c5 100644 --- a/src/dfChemistryModel/pytorchFunctions.H +++ b/src/dfChemistryModel/pytorchFunctions.H @@ -118,8 +118,6 @@ Foam::scalar Foam::dfChemistryModel::solve_DNN(const DeltaTType &del std::chrono::steady_clock::time_point start8 = std::chrono::steady_clock::now(); pybind11::array_t vec0 = pybind11::array_t({DNNinputs[0].size()}, {8}, &DNNinputs[0][0]); // cast vector to np.array - pybind11::array_t vec1 = pybind11::array_t({DNNinputs[1].size()}, {8}, &DNNinputs[1][0]); - pybind11::array_t vec2 = pybind11::array_t({DNNinputs[2].size()}, {8}, &DNNinputs[2][0]); std::chrono::steady_clock::time_point stop8 = std::chrono::steady_clock::now(); std::chrono::duration processingTime8 = std::chrono::duration_cast>(stop8 - start8); @@ -130,7 +128,7 @@ Foam::scalar Foam::dfChemistryModel::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>().data(); std::chrono::steady_clock::time_point stop9 = std::chrono::steady_clock::now(); @@ -146,9 +144,7 @@ Foam::scalar Foam::dfChemistryModel::solve_DNN(const DeltaTType &del /*=============================construct solutions=============================*/ std::chrono::steady_clock::time_point start6 = std::chrono::steady_clock::now(); std::vector outputsVec0(star, star+outputLength[0] * mixture_.nSpecies()); //the float number is sample_length*sample_number - std::vector outputsVec1(star+outputLength[0] * mixture_.nSpecies(), star+outputLength[1] * mixture_.nSpecies()); - std::vector outputsVec2(star+outputLength[1] * mixture_.nSpecies(), star+outputLength[2] * mixture_.nSpecies()); - std::vector> results = {outputsVec0, outputsVec1, outputsVec2}; + std::vector> results = {outputsVec0}; updateSolutionBuffer(solutionBuffer, results, cellIDBuffer, problemCounter); std::chrono::steady_clock::time_point stop6 = std::chrono::steady_clock::now(); std::chrono::duration processingTime6 = std::chrono::duration_cast>(stop6 - start6); @@ -270,15 +266,11 @@ Foam::scalar Foam::dfChemistryModel::solve_DNN(const DeltaTType &del problemBuffer.append(GPUproblemList); getDNNinputs(problemBuffer, outputLength, DNNinputs, cellIDBuffer, problemCounter); pybind11::array_t vec0 = pybind11::array_t({DNNinputs[0].size()}, {8}, &DNNinputs[0][0]); // cast vector to np.array - pybind11::array_t vec1 = pybind11::array_t({DNNinputs[1].size()}, {8}, &DNNinputs[1][0]); - pybind11::array_t vec2 = pybind11::array_t({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>().data(); std::vector outputsVec0(star, star+outputLength[0] * mixture_.nSpecies()); //the float number is sample_length*sample_number - std::vector outputsVec1(star+outputLength[0] * mixture_.nSpecies(), star+outputLength[1] * mixture_.nSpecies()); - std::vector outputsVec2(star+outputLength[1] * mixture_.nSpecies(), star+outputLength[2] * mixture_.nSpecies()); - std::vector> results = {outputsVec0, outputsVec1, outputsVec2}; + std::vector> results = {outputsVec0}; updateSolutionBuffer(solutionBuffer, results, cellIDBuffer, problemCounter); DynamicList finalList; finalList = solutionBuffer[0]; diff --git a/src/dfChemistryModel/torchFunctions.H b/src/dfChemistryModel/torchFunctions.H index f7d9a83c7..ee76ccef2 100644 --- a/src/dfChemistryModel/torchFunctions.H +++ b/src/dfChemistryModel/torchFunctions.H @@ -18,17 +18,6 @@ void Foam::dfChemistryModel::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()); From fbbdc85cc0bf00bc8929de8713943813483dd0b1 Mon Sep 17 00:00:00 2001 From: risinyoung Date: Fri, 22 Dec 2023 16:08:09 +0800 Subject: [PATCH 2/2] modified to DF-ODENet v0.1 --- src/dfChemistryModel/torchFunctions.H | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dfChemistryModel/torchFunctions.H b/src/dfChemistryModel/torchFunctions.H index ee76ccef2..8b5252548 100644 --- a/src/dfChemistryModel/torchFunctions.H +++ b/src/dfChemistryModel/torchFunctions.H @@ -136,12 +136,12 @@ void Foam::dfChemistryModel::getDNNinputs cellIDBuffer = {cellIDList0Buffer, cellIDList1Buffer, cellIDList2Buffer}; problemCounter = {problemCounter0, problemCounter1, problemCounter2}; - if (gpulog_) - { - std::cout<<"inputsDNN0 = "<