From 4aa14af6d4dfb8b84e28ad3180bf75f2553b790a Mon Sep 17 00:00:00 2001
From: xiao312 <121787251+xiao312@users.noreply.github.com>
Date: Mon, 13 Feb 2023 10:19:17 +0800
Subject: [PATCH 01/28] Update README.md
---
README.md | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/README.md b/README.md
index 64a3ddd3..8471290e 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,11 @@
+
+
+
+
+
+
+
+
# DeepFlame v1.0.0
DeepFlame is a deep learning empowered computational fluid dynamics package for single or multiphase, laminar or turbulent, reacting flows at all speeds. It aims to provide an open-source platform to combine the individual strengths of [OpenFOAM](https://openfoam.org), [Cantera](https://cantera.org), and [PyTorch](https://pytorch.org/) libraries for deep learning assisted reacting flow simulations. It also has the scope to leverage the next-generation heterogenous supercomputing and AI acceleration infrastructures such as GPU and FPGA.
From 1f03758c950605a45b7671df606ae6966eb8baab Mon Sep 17 00:00:00 2001
From: xiao312 <121787251+xiao312@users.noreply.github.com>
Date: Mon, 13 Feb 2023 15:39:28 +0800
Subject: [PATCH 02/28] Update examples.rst
---
docs/source/qs/examples.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/source/qs/examples.rst b/docs/source/qs/examples.rst
index 886165bb..9028c2c7 100644
--- a/docs/source/qs/examples.rst
+++ b/docs/source/qs/examples.rst
@@ -78,7 +78,7 @@ If the case is successfully run, the result can be found in ``/postProcessing/pr
.. code-block:: bash
- gunplot
+ gnuplot
plot "/your/path/to/postProcessing/probes/0/T"
You will get a graph:
From 37092ecc0510901576a4afd2e3769e22fe792974 Mon Sep 17 00:00:00 2001
From: Runze
Date: Wed, 15 Feb 2023 14:00:15 +0800
Subject: [PATCH 03/28] fix bugs in updating solution buffer
---
src/dfChemistryModel/dfChemistryModel.C | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/dfChemistryModel/dfChemistryModel.C b/src/dfChemistryModel/dfChemistryModel.C
index 3b086b86..81a671d3 100644
--- a/src/dfChemistryModel/dfChemistryModel.C
+++ b/src/dfChemistryModel/dfChemistryModel.C
@@ -1570,9 +1570,9 @@ Foam::scalar Foam::dfChemistryModel::solve_DNN(
/*=============================construct solutions=============================*/
std::chrono::steady_clock::time_point start6 = std::chrono::steady_clock::now();
- std::vector outputsVec0(star, star+outputLength[0] * 21); //the float number is sample_length*sample_number
- std::vector outputsVec1(star+outputLength[0] * 21, star+outputLength[1] * 21);
- std::vector outputsVec2(star+outputLength[1] * 21, star+outputLength[2] * 21);
+ std::vector outputsVec0(star, star+outputLength[0] * 7); //the float number is sample_length*sample_number
+ std::vector outputsVec1(star+outputLength[0] * 7, star+outputLength[1] * 7);
+ std::vector outputsVec2(star+outputLength[1] * 7, star+outputLength[2] * 7);
std::vector> results = {outputsVec0, outputsVec1, outputsVec2};
updateSolutionBuffer(solutionBuffer, results, cellIDBuffer, problemCounter);
std::chrono::steady_clock::time_point stop6 = std::chrono::steady_clock::now();
From d4b7d20cfad0ccf3369d2cf5915ce794f30a18b4 Mon Sep 17 00:00:00 2001
From: Runze
Date: Wed, 15 Feb 2023 14:01:17 +0800
Subject: [PATCH 04/28] Update CanteraTorchProperties
---
.../H2/pytorchIntegrator/constant/CanteraTorchProperties | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/df0DFoam/zeroD_cubicReactor/H2/pytorchIntegrator/constant/CanteraTorchProperties b/examples/df0DFoam/zeroD_cubicReactor/H2/pytorchIntegrator/constant/CanteraTorchProperties
index dc261039..ebf63603 100644
--- a/examples/df0DFoam/zeroD_cubicReactor/H2/pytorchIntegrator/constant/CanteraTorchProperties
+++ b/examples/df0DFoam/zeroD_cubicReactor/H2/pytorchIntegrator/constant/CanteraTorchProperties
@@ -38,7 +38,7 @@ splittingStrategy off;
TorchSettings
{
- torch off;
+ torch on;
GPU off;
log on;
torchModel "HE04_Hydrogen_ESH2_GMS_sub_20221101";
From 34cdfa991dd4f76bb3cd3afaffe29e8d43ae8a94 Mon Sep 17 00:00:00 2001
From: Runze
Date: Wed, 15 Feb 2023 14:02:25 +0800
Subject: [PATCH 05/28] Update corrtest.cpp
---
test/corrtest.cpp | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/test/corrtest.cpp b/test/corrtest.cpp
index 2099f3a4..a2b68593 100644
--- a/test/corrtest.cpp
+++ b/test/corrtest.cpp
@@ -25,10 +25,8 @@ float TGV400 = readTGV(1098,"2DTGV/4/data_T.xy");
TEST(corrtest,df0DFoam_H2){
- // EXPECT_FLOAT_EQ(H2maxT,2588.48); // compare the maximum temperature of H2 case
- // EXPECT_FLOAT_EQ(H2midT,1021.41); // compare the temperature of H2 case at the maximum gradient when t = 0.000245s
- EXPECT_FLOAT_EQ(H2maxT,2586.21); // compare the maximum temperature of H2 case
- EXPECT_FLOAT_EQ(H2midT,1020.71); // compare the temperature of H2 case at the maximum gradient when t = 0.000245s
+ EXPECT_FLOAT_EQ(H2maxT,2588.48); // compare the maximum temperature of H2 case
+ EXPECT_FLOAT_EQ(H2midT,1021.41); // compare the temperature of H2 case at the maximum gradient when t = 0.000245s
}
From 034443545ecc6c7fe0b4dd41fc3a3251b526c55d Mon Sep 17 00:00:00 2001
From: Runze
Date: Wed, 15 Feb 2023 15:00:04 +0800
Subject: [PATCH 06/28] Update dfChemistryModel.C
---
src/dfChemistryModel/dfChemistryModel.C | 34 ++++++++++++-------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/src/dfChemistryModel/dfChemistryModel.C b/src/dfChemistryModel/dfChemistryModel.C
index 81a671d3..94d5be83 100644
--- a/src/dfChemistryModel/dfChemistryModel.C
+++ b/src/dfChemistryModel/dfChemistryModel.C
@@ -839,26 +839,26 @@ void Foam::dfChemistryModel::getGPUProblems
if (((Qdot_[cellI] < 3e7) && (T_[cellI] < 2000) && ( T_[cellI] >= 700)) || (T_[cellI] < 700))//choose1
{
// if use CVODE
- ode_problem.Y = problem.Y;
- ode_problem.Ti = Ti;
- ode_problem.pi = pi;
- ode_problem.rhoi = rhoi;
- ode_problem.deltaT = deltaT[cellI];
- ode_problem.cpuTime = cpuTimes_[cellI];
- ode_problem.cellid = cellI;
- if (!(Pstream::myProcNo() % cores_)) // submaster
- {
- ode_problem.local = false;
- }
- CPUproblemList.append(ode_problem);
+ // ode_problem.Y = problem.Y;
+ // ode_problem.Ti = Ti;
+ // ode_problem.pi = pi;
+ // ode_problem.rhoi = rhoi;
+ // ode_problem.deltaT = deltaT[cellI];
+ // ode_problem.cpuTime = cpuTimes_[cellI];
+ // ode_problem.cellid = cellI;
+ // if (!(Pstream::myProcNo() % cores_)) // submaster
+ // {
+ // ode_problem.local = false;
+ // }
+ // CPUproblemList.append(ode_problem);
- selectDNN_[cellI]=0;
- continue;
+ // selectDNN_[cellI]=0;
+ // continue;
// if use DNN
- // problem.DNNid = 0;
- // GPUproblemList.append(problem);
- // continue;
+ problem.DNNid = 0;
+ GPUproblemList.append(problem);
+ continue;
}
if(((Qdot_[cellI] >= 3e7) && (T_[cellI] < 2000)&&(T_[cellI] >= 700))||((Qdot_[cellI] > 7e8) && T_[cellI] > 2000)) //choose2
{
From a0c414b7ea345f86fcc112ffb002f74fcd105f91 Mon Sep 17 00:00:00 2001
From: Zhi Chen
Date: Thu, 16 Feb 2023 11:51:05 +0800
Subject: [PATCH 07/28] Create README.md
---
README.md | 1 -
1 file changed, 1 deletion(-)
diff --git a/README.md b/README.md
index 8471290e..74195bd6 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,6 @@
-# DeepFlame v1.0.0
DeepFlame is a deep learning empowered computational fluid dynamics package for single or multiphase, laminar or turbulent, reacting flows at all speeds. It aims to provide an open-source platform to combine the individual strengths of [OpenFOAM](https://openfoam.org), [Cantera](https://cantera.org), and [PyTorch](https://pytorch.org/) libraries for deep learning assisted reacting flow simulations. It also has the scope to leverage the next-generation heterogenous supercomputing and AI acceleration infrastructures such as GPU and FPGA.
The deep learning algorithms and models used in the DeepFlame tutorial examples are developed and trained independently by our collaborators team – [DeepCombustion](https://github.com/deepcombustion/deepcombustion). Please refer to their website for detailed information.
From 7ac1d1f57de872aa7186793f016e9c0d3b228e10 Mon Sep 17 00:00:00 2001
From: xiao312 <121787251+xiao312@users.noreply.github.com>
Date: Thu, 16 Feb 2023 14:48:08 +0800
Subject: [PATCH 08/28] Update README.md
---
README.md | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 74195bd6..5498111d 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,19 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
DeepFlame is a deep learning empowered computational fluid dynamics package for single or multiphase, laminar or turbulent, reacting flows at all speeds. It aims to provide an open-source platform to combine the individual strengths of [OpenFOAM](https://openfoam.org), [Cantera](https://cantera.org), and [PyTorch](https://pytorch.org/) libraries for deep learning assisted reacting flow simulations. It also has the scope to leverage the next-generation heterogenous supercomputing and AI acceleration infrastructures such as GPU and FPGA.
From 4bfd09f0a41c73705181497ea4204c33851c784d Mon Sep 17 00:00:00 2001
From: of
Date: Sun, 19 Feb 2023 20:48:59 +0800
Subject: [PATCH 09/28] refactor dfChemistryModel
---
src/dfChemistryModel/dfChemistryModel.C | 919 +----------------------
src/dfChemistryModel/dfChemistryModel.H | 175 ++---
src/dfChemistryModel/libtorchFunctions.H | 234 ++++++
src/dfChemistryModel/pytorchFunctions.H | 254 +++++++
src/dfChemistryModel/torchFunctions.H | 247 ++++++
5 files changed, 829 insertions(+), 1000 deletions(-)
create mode 100644 src/dfChemistryModel/libtorchFunctions.H
create mode 100644 src/dfChemistryModel/pytorchFunctions.H
create mode 100644 src/dfChemistryModel/torchFunctions.H
diff --git a/src/dfChemistryModel/dfChemistryModel.C b/src/dfChemistryModel/dfChemistryModel.C
index 94d5be83..43780323 100644
--- a/src/dfChemistryModel/dfChemistryModel.C
+++ b/src/dfChemistryModel/dfChemistryModel.C
@@ -135,7 +135,6 @@ Foam::dfChemistryModel::dfChemistryModel
#endif
#ifdef USE_LIBTORCH
- torchModelName_ = this->lookupOrDefault("torchModel", word(""));
torchModelName1_ = this->subDict("TorchSettings").lookupOrDefault("torchModel1", word(""));
torchModelName2_ = this->subDict("TorchSettings").lookupOrDefault("torchModel2", word(""));
torchModelName3_ = this->subDict("TorchSettings").lookupOrDefault("torchModel3", word(""));
@@ -180,7 +179,7 @@ Foam::dfChemistryModel::dfChemistryModel
if (torchSwitch_)
{
labelList subRank;
- for (size_t rank = 0; rank < Pstream::nProcs(); rank ++)
+ for (int rank = 0; rank < Pstream::nProcs(); rank ++)
{
if (rank % cores_)
{
@@ -306,24 +305,8 @@ Foam::scalar Foam::dfChemistryModel::solve
)
{
scalar result = 0;
-#ifdef USE_LIBTORCH
- if(torchSwitch_)
- {
- if (useDNN)
- {
- result = solve_DNN(deltaT);
- }
- else
- {
- result = solve_CVODE(deltaT);
- useDNN = true;
- }
- }
- else
- {
- result = solve_CVODE(deltaT);
- }
-#elif USE_PYTORCH
+
+#if defined USE_LIBTORCH || defined USE_PYTORCH
if(torchSwitch_)
{
if (useDNN)
@@ -394,7 +377,8 @@ void Foam::dfChemistryModel::correctThermo()
T_[celli] = CanteraGas_->temperature();
- psi_[celli] = CanteraGas_->meanMolecularWeight()/CanteraGas_->RT(); // meanMolecularWeight() kg/kmol RT() Joules/kmol
+ // meanMolecularWeight() kg/kmol RT() Joules/kmol
+ psi_[celli] = CanteraGas_->meanMolecularWeight()/CanteraGas_->RT();
mu_[celli] = mixture_.CanteraTransport()->viscosity(); // Pa-s
@@ -556,7 +540,8 @@ void Foam::dfChemistryModel::solveSingle
CanteraGas_->setState_TPY(Ti, pi, yPre_.begin());
react.insert(mixture_.CanteraSolution());
- react.setEnergy(0); // keep T const before and after sim.advance. this will give you a little improvement
+ // keep T const before and after sim.advance. this will give you a little improvement
+ react.setEnergy(0);
Cantera::ReactorNet sim;
sim.addReactor(react);
setNumerics(sim);
@@ -678,9 +663,9 @@ Foam::dfChemistryModel::updateReactionRates
{
for(label j = 0; j < mixture_.nSpecies(); j++)
{
- this->RR_[j][solution.cellid] = solution.RRi[j];
+ RR_[j][solution.cellid] = solution.RRi[j];
}
- this->Qdot_[solution.cellid] = solution.Qdoti;
+ Qdot_[solution.cellid] = solution.Qdoti;
cpuTimes_[solution.cellid] = solution.cpuTime;
}
@@ -733,7 +718,7 @@ Foam::scalar Foam::dfChemistryModel::solve_CVODE
scalar t_solveBuffer(0);
scalar t_unbalance(0);
- if(!this->chemistry_)
+ if(!chemistry_)
{
return great;
}
@@ -792,893 +777,19 @@ Foam::scalar Foam::dfChemistryModel::solve_CVODE
return updateReactionRates(incomingSolutions, List);
}
-#if defined USE_LIBTORCH || defined USE_PYTORCH
-template
-template
-void Foam::dfChemistryModel::getGPUProblems
-(
- const DeltaTType &deltaT,
- Foam::DynamicList& GPUproblemList,
- Foam::DynamicList& CPUproblemList
-)
-{
- DynamicList problemList; //single core TODO:rename it
- // get cuda problemList, for all cell
- // each get problem
- forAll(T_, cellI)
- {
- scalar Ti = T_[cellI];
- 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());
- problem.cellid = cellI;
- problem.Ti = Ti;
- problem.pi = pi/101325;
- for (int i = 0; i < mixture_.nSpecies(); i++)
- {
- problem.Y[i] = Y_[i][cellI];
- }
- problem.rhoi = rhoi;
-
- // choose DNN module
- if (((Qdot_[cellI] < 3e7) && (T_[cellI] < 2000) && ( T_[cellI] >= 700)) || (T_[cellI] < 700))//choose1
- {
- // if use CVODE
- // ode_problem.Y = problem.Y;
- // ode_problem.Ti = Ti;
- // ode_problem.pi = pi;
- // ode_problem.rhoi = rhoi;
- // ode_problem.deltaT = deltaT[cellI];
- // ode_problem.cpuTime = cpuTimes_[cellI];
- // ode_problem.cellid = cellI;
- // if (!(Pstream::myProcNo() % cores_)) // submaster
- // {
- // ode_problem.local = false;
- // }
- // CPUproblemList.append(ode_problem);
-
- // selectDNN_[cellI]=0;
- // continue;
-
- // if use DNN
- problem.DNNid = 0;
- GPUproblemList.append(problem);
- continue;
- }
- if(((Qdot_[cellI] >= 3e7) && (T_[cellI] < 2000)&&(T_[cellI] >= 700))||((Qdot_[cellI] > 7e8) && T_[cellI] > 2000)) //choose2
- {
- problem.DNNid = 1;
- GPUproblemList.append(problem);
-
- selectDNN_[cellI]=1;
- continue;
- }
- if ((Qdot_[cellI] < 7e8) && (T_[cellI] >= 2000) && (Qdot_[cellI]!=0)) //choose3
- {
- problem.DNNid = 2;
- GPUproblemList.append(problem);
- selectDNN_[cellI]=2;
- continue;
- }
-
- }
-
- return;
-}
-
-template
-void Foam::dfChemistryModel::getDNNinputs
-(
- const Foam::DynamicBuffer& problemBuffer,
- std::vector