Skip to content

Commit 26d1c7a

Browse files
user20250420maorz1998zhixchenpkuLmqOpenFOAMFans
authored
add CANTERA_THERMO to control method to calculate h cp and update T. CANTERA_THERMO=1(current default) means using Cantera. CANTERA_THERMO=0 means using deepflame. (#555)
* change energy from ha to hs * Update README.md * Update README.md * Update CanteraMixture.C * change ha to h in fvSolution * fix * fix bug * rever commit: change ha to hs * fix EEqn * Increase the test error of the dfLowMachFoam_2DaachenBomb case to 30. --------- Co-authored-by: maorz1998 <[email protected]> Co-authored-by: Zhi Chen <[email protected]> Co-authored-by: pkuLmq <[email protected]> Co-authored-by: OpenFOAMFans <[email protected]>
1 parent dee8408 commit 26d1c7a

File tree

39 files changed

+719
-343
lines changed

39 files changed

+719
-343
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Detailed guide for installation and tutorials is available on [our documentation
2929
## Features
3030
New in v1.5 (2025/1/8):
3131
- Provide a new boundary condition, totalFlowRateAdvectiveDiffusion (adopted from OpenFOAM v7), which accounts for diffusion effects at the boundary
32-
- Develop a new solver, `dfBuoyancyFoam`(adopted from fireFoam), a transient, compressible solver designed to model turbulent reacting flows while incorporating buoyancy effects
32+
- Develop a new solver, `dfBuoyancyFoam`(adopted from fireFoam in OpenFOAM v7), a transient, compressible solver designed to model turbulent reacting flows incorporating buoyancy effects
3333
- Add radiation models, which are integrated into the current `dfBuoyancyFoam` solver, and can be incorporated into other solvers if needed
3434
- Add new combustion models (including infinitelyFastChemistry and eddyDissipationModel) to the `dfBuoyancyFoam` solver
3535
- Imply DeepFlame on Arm architecture platforms

applications/solvers/df0DFoam/Make/options

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ EXE_INC = -std=c++14 \
55
-Wno-unused-but-set-variable \
66
-Wno-old-style-cast \
77
$(PFLAGS) $(PINC) \
8+
$(if $(CANTERA_THERMO),-DCANTERA_THERMO,) \
89
$(if $(LIBTORCH_ROOT),-DUSE_LIBTORCH,) \
910
$(if $(PYTHON_INC_DIR),-DUSE_PYTORCH,) \
1011
-I$(CANTERA_ROOT)/include \

applications/solvers/dfHighSpeedFoam/Make/options

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ EXE_INC = -std=c++14 \
55
-Wno-unused-but-set-variable \
66
-Wno-old-style-cast \
77
$(PFLAGS) $(PINC) \
8+
$(if $(CANTERA_THERMO),-DCANTERA_THERMO,) \
89
$(if $(LIBTORCH_ROOT),-DUSE_LIBTORCH,) \
910
$(if $(PYTHON_INC_DIR),-DUSE_PYTORCH,) \
1011
-I$(FOAM_APP)/solvers/compressible/rhoCentralFoam/BCs/lnInclude \

applications/solvers/dfHighSpeedFoam/rhoEEqn.H

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ else
3939
ea = rhoE/rho - 0.5*magSqr(U);
4040
ea.correctBoundaryConditions();
4141

42-
ha = ea + p/rho;
42+
// ha = ea + p/rho;
4343
chemistry->correctThermo(); // before this, we must update ha = e + p/rho
4444

4545
rhoE.boundaryFieldRef() == rho.boundaryField()*(ea.boundaryField() + 0.5*magSqr(U.boundaryField()));
@@ -49,15 +49,15 @@ if (!inviscid)
4949
if((ddtSchemes == "RK2SSP") || (ddtSchemes == "RK3SSP"))
5050
{
5151
rhoE_rhs = fvc::laplacian(turbulence->alphaEff()*thermo.gamma(), ea)
52-
- diffAlphaD
52+
- diffAlphaD
5353
+ fvc::div(hDiffCorrFlux);
54-
54+
5555
rhoE += rkcoe3[nrk]*rhoE_rhs*runTime.deltaT();
5656

5757
ea = rhoE/rho - 0.5*magSqr(U);
5858
ea.correctBoundaryConditions();
5959

60-
ha = ea + p/rho;
60+
// ha = ea + p/rho;
6161
chemistry->correctThermo(); // before this, we must update ha = e + p/rho
6262
}
6363
else
@@ -84,12 +84,12 @@ if (!inviscid)
8484

8585
eEqn.solve("ea");
8686

87-
ha = ea + p/rho;
87+
// ha = ea + p/rho;
8888
chemistry->correctThermo();
8989
rhoE = rho*(ea + 0.5*magSqr(U));
9090
rhoE.boundaryFieldRef() == rho.boundaryField()*(ea.boundaryField() + 0.5*magSqr(U.boundaryField()));
9191
}
92-
92+
9393
}
9494

9595
Info<< "min/max(T) = "

applications/solvers/dfLowMachFoam/EEqn.H

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
volScalarField& he = thermo.he();
3+
4+
35
tmp<fvScalarMatrix> thcSource(new fvScalarMatrix(he, dimEnergy/dimTime));
46
fvScalarMatrix& hcSource = thcSource.ref();
57
forAll(Y, i)
@@ -8,6 +10,7 @@
810
}
911
//hSource.source() -= parcels.hsTrans()/runTime.deltaT();// equivalent to parcels.Sh(he)
1012

13+
1114
start1 = std::clock();
1215
fvScalarMatrix EEqn
1316
(
@@ -16,33 +19,43 @@
1619
+ fvc::ddt(rho, K) + fvc::div(phi, K)
1720
- dpdt
1821
==
22+
(
23+
turbName == "laminar"
24+
?
1925
(
20-
turbName == "laminar"
21-
?
22-
(
23-
fvm::laplacian(turbulence->alpha(), he)
24-
- diffAlphaD
25-
+ fvc::div(hDiffCorrFlux)
26-
// + rho*(U&g)
27-
+ parcels.Sh(he)
28-
+ hcSource
29-
)
30-
:
31-
(
32-
fvm::laplacian(turbulence->alphaEff(), he)
33-
// + rho*(U&g)
34-
+ parcels.Sh(he)
35-
+ hcSource
36-
)
26+
fvm::laplacian(turbulence->alpha(), he)
27+
- diffAlphaD
28+
+ fvc::div(hDiffCorrFlux)
3729
)
30+
:
31+
fvm::laplacian(turbulence->alphaEff(), he)
32+
)
33+
+ parcels.Sh(he)
34+
// + rho*(U&g)
3835
);
36+
37+
if(CanteraMixture::getEnergyName() == word("hs"))
38+
{
39+
EEqn -= combustion->Qdot();
40+
}
41+
else if(CanteraMixture::getEnergyName() == word("ha"))
42+
{
43+
EEqn -= hcSource;
44+
}
45+
else
46+
{
47+
FatalErrorInFunction
48+
<< "Wrong CanteraMixture enregy name: " << CanteraMixture::getEnergyName()
49+
<< abort(FatalError);
50+
}
51+
3952
end1 = std::clock();
4053
time_monitor_EEqn += double(end1 - start1) / double(CLOCKS_PER_SEC);
4154
time_monitor_EEqn_mtxAssembly += double(end1 - start1) / double(CLOCKS_PER_SEC);
4255

4356
// EEqn.relax();
4457
start1 = std::clock();
45-
EEqn.solve("ha");
58+
EEqn.solve("h");
4659
end1 = std::clock();
4760
time_monitor_EEqn += double(end1 - start1) / double(CLOCKS_PER_SEC);
4861
time_monitor_EEqn_solve += double(end1 - start1) / double(CLOCKS_PER_SEC);

applications/solvers/dfLowMachFoam/EEqn_GPU.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
)
3838
);
3939
// EEqn.relax();
40-
EEqn.solve("ha");
40+
EEqn.solve("h");
4141
// checkResult
4242
// TODO: for temp, now we compare ldu, finally we compare csr
4343
std::vector<double> h_internal_coeffs(dfDataBase.num_boundary_surfaces);

applications/solvers/dfLowMachFoam/Make/options

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ EXE_INC = -std=c++14 \
88
-Wno-old-style-cast \
99
-I. \
1010
$(PFLAGS) $(PINC) \
11+
$(if $(CANTERA_THERMO),-DCANTERA_THERMO,) \
1112
$(if $(LIBTORCH_ROOT),-DUSE_LIBTORCH,) \
1213
$(if $(PYTHON_INC_DIR),-DUSE_PYTORCH,) \
1314
-I$(FOAM_APP)/solvers/lagrangian/reactingParcelFoam \

applications/solvers/dfSprayFoam/EEqn.H

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
hcSource.source() -= parcels.rhoTrans(i)*chemistry->mixture().Hc(i)/runTime.deltaT();
1010
}
1111
//hSource.source() -= parcels.hsTrans()/runTime.deltaT();// equivalent to parcels.Sh(he)
12-
13-
12+
13+
1414
fvScalarMatrix EEqn
1515
(
1616
turbName == "laminar"
@@ -22,9 +22,8 @@
2222
- fvm::laplacian(turbulence->alphaEff(), he)
2323
+ diffAlphaD
2424
==
25-
rho*(U&g)
25+
rho*(U&g)
2626
+ parcels.Sh(he)
27-
+ hcSource
2827
+ fvc::div(hDiffCorrFlux)
2928
//+ radiation->Sh(thermo, he)
3029
//+ fvOptions(rho, he)
@@ -38,20 +37,34 @@
3837
==
3938
rho*(U&g)
4039
+ parcels.Sh(he)
41-
+ hcSource
4240
//+ radiation->Sh(thermo, he)
4341
//+ fvOptions(rho, he)
4442
)
4543
);
4644

45+
if(CanteraMixture::getEnergyName() == word("hs"))
46+
{
47+
EEqn -= combustion->Qdot();
48+
}
49+
else if(CanteraMixture::getEnergyName() == word("ha"))
50+
{
51+
EEqn -= hcSource;
52+
}
53+
else
54+
{
55+
FatalErrorInFunction
56+
<< "Wrong CanteraMixture enregy name: " << CanteraMixture::getEnergyName()
57+
<< abort(FatalError);
58+
}
59+
4760
EEqn.relax();
4861

4962
//fvOptions.constrain(EEqn);
5063

51-
EEqn.solve("ha");
64+
EEqn.solve("h");
5265

5366
//fvOptions.correct(he);
5467

5568
//radiation->correct();
56-
69+
5770
}

applications/solvers/dfSprayFoam/Make/options

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ EXE_INC = -std=c++14 \
3535
-I$(CANTERA_ROOT)/include \
3636
$(if $(LIBTORCH_ROOT),-I$(LIBTORCH_ROOT)/include,) \
3737
$(if $(LIBTORCH_ROOT),-I$(LIBTORCH_ROOT)/include/torch/csrc/api/include,) \
38+
$(if $(CANTERA_THERMO),-DCANTERA_THERMO,) \
3839
$(if $(LIBTORCH_ROOT),-DUSE_LIBTORCH,) \
3940
$(if $(PYTHON_INC_DIR),-DUSE_PYTORCH,) \
4041
$(PYTHON_INC_DIR)

bashrc.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ export LIBTORCH_ROOT=LIBTORCH_DIR
55
export PYTHON_INC_DIR="PYTORCH_INC"
66
export PYTHON_LIB_DIR="PYTORCH_LIB"
77
export CANTERA_ROOT=LIBCANTERA_DIR
8+
export CANTERA_MECH=1
9+
export CANTERA_REACTION=1
10+
export CANTERA_THERMO=1
11+
export CANTERA_TRANSPORT=1
812
export CANTERA_DATA=$CANTERA_ROOT/share/cantera/data
913
export LD_LIBRARY_PATH=$LIBTORCH_ROOT/lib:$LD_LIBRARY_PATH
1014
export LD_LIBRARY_PATH=$CANTERA_ROOT/lib:$LD_LIBRARY_PATH

0 commit comments

Comments
 (0)