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
1 change: 1 addition & 0 deletions Allwmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ wmake src/TurbulenceModels/compressible
wmake src/TurbulenceModels/turbulenceModels
wmake src/regionModels/surfaceFilmModels
src/lagrangian/Allwmake $targetType $*
wmake src/dfCombustionModels
wmake src/dynamicMesh
wmake src/dynamicFvMesh

Expand Down
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# DeepFlame v0.3.0
DeepFlame is a computational fluid dynamics suite for single or multiphase, laminar or turbulent reacting flows at all speeds with machine learning capabilities. It aims to provide an open-source platform bringing together the individual strengths of [OpenFOAM](https://openfoam.org), [Cantera](https://cantera.org) and [pyTorch](https://pytorch.org/) libraries for machine learning assisted reacting flow simulations. It is also has the scope to incorporate next-generation heterogenous supercomputing and AI acceleration infrustructures such as GPU and FPGAs.
# DeepFlame v0.4.0
DeepFlame is a computational fluid dynamics suite for single or multiphase, laminar or turbulent reacting flows at all speeds with machine learning capabilities. It aims to provide an open-source platform bringing together the individual strengths of [OpenFOAM](https://openfoam.org), [Cantera](https://cantera.org) and [pyTorch](https://pytorch.org/) libraries for machine learning assisted reacting flow simulations. It is also has the scope to incorporate next-generation heterogenous supercomputing and AI acceleration infrustructures such as GPU and FPGAs.

## Dependencies
[OpenFOAM-7](https://openfoam.org/version/7), [Cantera C++ lib 2.6.0](https://anaconda.org/conda-forge/libcantera-devel), [Torch C++ lib 1.11.0](https://pytorch.org/)

## Features
New in v0.4.0 (2022/09/26):
- Adapt combustion library from OpenFOAM into DeepFlame
- laminar; EDC; PaSR combustion models

New in v0.3.0:
- 1/2/3D adaptive mesh refinement
- Add Sigma/dynSmag LES turbulence models
Expand All @@ -23,7 +27,7 @@ From v0.1.0:
- Two-phase Lagrangian/Euler spray reacting flow solver `dfSprayFoam`
- Cantera's native SUNDIALS CVODE solver for chemical reaction rate evaluation
- Torch's tensor operation functionality for neutral network I/O and calculation
- Interface for DNN model to obtain chemical reaction rates
- Interface for DNN model to obtain chemical reaction rates
- Multiple example and tutorial cases with `Allrun` and `Allclean` scripts
- 0D Perfectly Stirred Reactor
- 1D Freely Propagating Premixed Flame
Expand All @@ -33,11 +37,11 @@ From v0.1.0:
- 3D Aachen Bomb Spray Flame

## How to install
The installation of DeepFlame is simple and requires [OpenFOAM-7](https://openfoam.org/version/7), [LibCantera](https://anaconda.org/conda-forge/libcantera-devel) and [LibTorch](https://pytorch.org/) .
The installation of DeepFlame is simple and requires [OpenFOAM-7](https://openfoam.org/version/7), [LibCantera](https://anaconda.org/conda-forge/libcantera-devel) and [LibTorch](https://pytorch.org/) .

### 1. Install [OpenFOAM-7](https://openfoam.org/version/7) (if not already installed)
Quick install (for Ubuntu no later than 20.04):

Quick install (for Ubuntu no later than 20.04):
```
sudo sh -c "wget -O - https://dl.openfoam.org/gpg.key | apt-key add -"
sudo add-apt-repository http://dl.openfoam.org/ubuntu
Expand All @@ -48,7 +52,7 @@ sudo apt-get -y install openfoam7

### 2. Source your OpenFOAM via the default path below (or your own path for OpenFOAM bashrc)
```
source $HOME/OpenFOAM/OpenFOAM-7/etc/bashrc
source $HOME/OpenFOAM/OpenFOAM-7/etc/bashrc
```
### 3. Install [LibCantera](https://anaconda.org/conda-forge/libcantera-devel) via [conda](https://docs.conda.io/en/latest/miniconda.html#linux-installers)
```
Expand All @@ -66,7 +70,7 @@ git clone https://github.com/deepmodeling/deepflame-dev.git

cd deepflame-dev
```
### 5. Install precompiled [LibTorch](https://pytorch.org/)
### 5. Install precompiled [LibTorch](https://pytorch.org/)
```
wget https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.11.0%2Bcpu.zip

Expand All @@ -81,7 +85,7 @@ Note: Some compiling issues may happen due to system compatability. Instead of u
## Running DeepFlame examples
1. Source your OpenFOAM, for example (depends on your OpenFOAM path):
```
source $HOME/OpenFOAM/OpenFOAM-7/etc/bashrc
source $HOME/OpenFOAM/OpenFOAM-7/etc/bashrc
```
2. Source deepflame-dev/bashrc, for example (depends on your DeepFlame path):
```
Expand All @@ -94,11 +98,11 @@ cd $HOME/deepflame-dev/examples/df0DFoam/zeroD_cubicReactor/H2/cvodeSolver
./Allrun
```

Note: For the example cases with torchSolver, an additional DNN model file in the `.pt` format is required. Please contact the developers if you would like a test run.
Note: For the example cases with torchSolver, an additional DNN model file in the `.pt` format is required. Please contact the developers if you would like a test run.


## Citing DeepFlame
If you use DeepFlame for a publication, please use the citation:
If you use DeepFlame for a publication, please use the citation:

DeepFlame: A computational fluid dynamics suite for multiphase turbulent reacting flows at all speeds with machine learning. URL:https://github.com/deepmodeling/deepflame-dev, 2022.

Expand Down
2 changes: 1 addition & 1 deletion applications/solvers/df0DFoam/Make/options
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ EXE_INC = -std=c++14 \
-I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/dynamicFvMesh/lnInclude \
-I$(DF_SRC)/CanteraMixture/lnInclude \
-I$(DF_SRC)/dfChemistryModel \
-I$(DF_SRC)/dfChemistryModel/lnInclude \
-I$(CANTERA_ROOT)/include \
-I$(TORCH_ROOT)/include \
-I$(TORCH_ROOT)/include/torch/csrc/api/include
Expand Down
2 changes: 1 addition & 1 deletion applications/solvers/df0DFoam/YEqn.H
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ tmp<fv::convectionScheme<scalar>> mvConvection

Y[inertIndex] = scalar(1) - Yt;
Y[inertIndex].max(0.0);
}
}
9 changes: 1 addition & 8 deletions applications/solvers/df0DFoam/df0DFoam.C
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,23 @@
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.

OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.

Application
rhoPimpleFoam

Description
Transient solver for turbulent flow of compressible fluids for HVAC and
similar applications, with optional mesh motion and mesh topology changes.

Uses the flexible PIMPLE (PISO-SIMPLE) solution for time-resolved and
pseudo-transient simulations.

\*---------------------------------------------------------------------------*/
#include "dfChemistryModel.H"
#include "CanteraMixture.H"
Expand Down Expand Up @@ -106,4 +99,4 @@ int main(int argc, char *argv[])
}


// ************************************************************************* //
// ************************************************************************* //
2 changes: 1 addition & 1 deletion applications/solvers/dfHighSpeedFoam/Make/options
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ EXE_INC = -std=c++14 \
-I$(LIB_SRC)/Pstream/mpi \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(DF_SRC)/CanteraMixture/lnInclude \
-I$(DF_SRC)/dfChemistryModel \
-I$(DF_SRC)/dfChemistryModel/lnInclude \
-I$(CANTERA_ROOT)/include \
-I$(TORCH_ROOT)/include \
-I$(TORCH_ROOT)/include/torch/csrc/api/include
Expand Down
4 changes: 3 additions & 1 deletion applications/solvers/dfLowMachFoam/Make/options
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ EXE_INC = -std=c++14 \
-I$(LIB_SRC)/dynamicFvMesh/lnInclude \
-I$(LIB_SRC)/Pstream/mpi \
-I$(DF_SRC)/CanteraMixture/lnInclude \
-I$(DF_SRC)/dfChemistryModel \
-I$(DF_SRC)/dfChemistryModel/lnInclude \
-I$(DF_SRC)/dfCombustionModels/lnInclude \
-I$(CANTERA_ROOT)/include \
-I$(TORCH_ROOT)/include \
-I$(TORCH_ROOT)/include/torch/csrc/api/include
Expand All @@ -29,6 +30,7 @@ EXE_LIBS = \
-ldfCompressibleTurbulenceModels \
-lCanteraMixture \
-ldfChemistryModel \
-ldfCombustionModels \
$(CANTERA_ROOT)/lib/libcantera.so \
$(TORCH_ROOT)/lib/libtorch.so \
$(TORCH_ROOT)/lib/libc10.so \
Expand Down
12 changes: 6 additions & 6 deletions applications/solvers/dfLowMachFoam/YEqn.H
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ tmp<fv::convectionScheme<scalar>> mvConvection

forAll(Y, i)
{
sumYDiffError += chemistry.rhoD(i)*fvc::grad(Y[i]);
sumYDiffError += chemistry->rhoD(i)*fvc::grad(Y[i]);
}
const surfaceScalarField phiUc = linearInterpolate(sumYDiffError) & mesh.Sf();

{
start = std::clock();
chemistry.solve(mesh.time().deltaTValue());
combustion->correct();
label flag_mpi_init;
MPI_Initialized(&flag_mpi_init);
if(flag_mpi_init) MPI_Barrier(PstreamGlobals::MPI_COMM_FOAM);
Expand All @@ -34,20 +34,20 @@ const surfaceScalarField phiUc = linearInterpolate(sumYDiffError) & mesh.Sf();
forAll(Y, i)
{
volScalarField& Yi = Y[i];
hDiffCorrFlux += chemistry.hai(i)*(chemistry.rhoD(i)*fvc::grad(Yi) - Yi*sumYDiffError);
diffAlphaD += fvc::laplacian(thermo.alpha()*chemistry.hai(i), Yi);
hDiffCorrFlux += chemistry->hai(i)*(chemistry->rhoD(i)*fvc::grad(Yi) - Yi*sumYDiffError);
diffAlphaD += fvc::laplacian(thermo.alpha()*chemistry->hai(i), Yi);

if (i != inertIndex)
{
tmp<volScalarField> DEff = chemistry.rhoD(i) + turbulence->mut()/Sct;
tmp<volScalarField> DEff = chemistry->rhoD(i) + turbulence->mut()/Sct;
fvScalarMatrix YiEqn
(
fvm::ddt(rho, Yi)
+ mvConvection->fvmDiv(phi, Yi)
- fvm::laplacian(DEff(), Yi)
+ mvConvection->fvmDiv(phiUc, Yi)
==
chemistry.RR(i)
combustion->R(Yi)
);

YiEqn.relax();
Expand Down
25 changes: 16 additions & 9 deletions applications/solvers/dfLowMachFoam/createFields.H
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ volScalarField rho
thermo.rho()
);

dfChemistryModel<basicThermo> chemistry(thermo);
PtrList<volScalarField>& Y = chemistry.Y();
const word inertSpecie(chemistry.lookup("inertSpecie"));
const label inertIndex(chemistry.species()[inertSpecie]);

chemistry.correctThermo();
Info<< "At initial time, min/max(T) = " << min(T).value() << ", " << max(T).value() << endl;

Info<< "Reading field U\n" << endl;
volVectorField U
(
Expand Down Expand Up @@ -62,6 +54,21 @@ autoPtr<compressible::turbulenceModel> turbulence
)
);

Info<< "Creating reaction model\n" << endl;
autoPtr<CombustionModel<basicThermo>> combustion
(
CombustionModel<basicThermo>::New(thermo, turbulence())
);
Info<< "end Creating reaction model\n" << endl;
dfChemistryModel<basicThermo>* chemistry = combustion->chemistry();
PtrList<volScalarField>& Y = chemistry->Y();
const word inertSpecie(chemistry->lookup("inertSpecie"));
const label inertIndex(chemistry->species()[inertSpecie]);


chemistry->correctThermo();
Info<< "At initial time, min/max(T) = " << min(T).value() << ", " << max(T).value() << endl;

Info<< "Creating field dpdt\n" << endl;
volScalarField dpdt
(
Expand All @@ -85,7 +92,7 @@ forAll(Y, i)
}
fields.add(thermo.he());

const scalar Sct = chemistry.lookupOrDefault("Sct", 1.);
const scalar Sct = chemistry->lookupOrDefault("Sct", 1.);
volScalarField diffAlphaD
(
IOobject
Expand Down
4 changes: 3 additions & 1 deletion applications/solvers/dfLowMachFoam/dfLowMachFoam.C
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Description
#include "localEulerDdtScheme.H"
#include "fvcSmooth.H"
#include "PstreamGlobals.H"
#include "basicThermo.H"
#include "CombustionModel.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Expand Down Expand Up @@ -128,7 +130,7 @@ int main(int argc, char *argv[])
time_monitor_E += double(end - start) / double(CLOCKS_PER_SEC);

start = std::clock();
chemistry.correctThermo();
chemistry->correctThermo();
end = std::clock();
time_monitor_corrThermo += double(end - start) / double(CLOCKS_PER_SEC);

Expand Down
4 changes: 3 additions & 1 deletion applications/solvers/dfSprayFoam/Make/options
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ EXE_INC = -std=c++14 \
-I$(LIB_SRC)/thermophysicalModels/thermophysicalProperties/lnInclude \
-I$(DF_SRC)/thermophysicalModels/SLGThermo/lnInclude \
-I$(DF_SRC)/CanteraMixture/lnInclude \
-I$(DF_SRC)/dfChemistryModel \
-I$(DF_SRC)/dfChemistryModel/lnInclude \
-I$(DF_SRC)/dfCombustionModels/lnInclude \
-I$(CANTERA_ROOT)/include \
-I$(TORCH_ROOT)/include \
-I$(TORCH_ROOT)/include/torch/csrc/api/include
Expand All @@ -49,6 +50,7 @@ EXE_LIBS = \
-ldfLagrangianSpray \
-lCanteraMixture \
-ldfChemistryModel \
-ldfCombustionModels \
$(CANTERA_ROOT)/lib/libcantera.so \
$(TORCH_ROOT)/lib/libtorch.so \
$(TORCH_ROOT)/lib/libc10.so \
Expand Down
13 changes: 6 additions & 7 deletions applications/solvers/dfSprayFoam/YEqn.H
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,23 @@ tmp<fv::convectionScheme<scalar>> mvConvection

forAll(Y, i)
{
sumYDiffError += chemistry.rhoD(i)*fvc::grad(Y[i]);
sumYDiffError += chemistry->rhoD(i)*fvc::grad(Y[i]);
}
const surfaceScalarField phiUc = linearInterpolate(sumYDiffError) & mesh.Sf();

{
//combustion->correct();
chemistry.solve(mesh.time().deltaTValue());
combustion->correct();
volScalarField Yt(0.0*Y[0]);

forAll(Y, i)
{
volScalarField& Yi = Y[i];
hDiffCorrFlux += chemistry.hai(i)*(chemistry.rhoD(i)*fvc::grad(Yi) - Yi*sumYDiffError);
diffAlphaD += fvc::laplacian(thermo.alpha()*chemistry.hai(i), Yi);
hDiffCorrFlux += chemistry->hai(i)*(chemistry->rhoD(i)*fvc::grad(Yi) - Yi*sumYDiffError);
diffAlphaD += fvc::laplacian(thermo.alpha()*chemistry->hai(i), Yi);

if (i != inertIndex)
{
tmp<volScalarField> DEff = chemistry.rhoD(i) + turbulence->mut()/Sct;
tmp<volScalarField> DEff = chemistry->rhoD(i) + turbulence->mut()/Sct;
fvScalarMatrix YEqn
(
fvm::ddt(rho, Yi)
Expand All @@ -41,7 +40,7 @@ const surfaceScalarField phiUc = linearInterpolate(sumYDiffError) & mesh.Sf();
+ mvConvection->fvmDiv(phiUc, Yi)
==
parcels.SYi(i, Yi)
+ chemistry.RR(i)
+ combustion->R(Yi)
//+ fvOptions(rho, Yi)
);

Expand Down
26 changes: 17 additions & 9 deletions applications/solvers/dfSprayFoam/createFields.H
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ volScalarField rho
thermo.rho()
);

dfChemistryModel<basicThermo> chemistry(thermo);
PtrList<volScalarField>& Y = chemistry.Y();
const word inertSpecie(chemistry.lookup("inertSpecie"));
const label inertIndex(chemistry.species()[inertSpecie]);

chemistry.correctThermo();
Info<< "At initial time, min/max(T) = " << min(T).value() << ", " << max(T).value() << endl;

Info<< "\nReading field U\n" << endl;
volVectorField U
(
Expand Down Expand Up @@ -83,6 +75,22 @@ autoPtr<compressible::turbulenceModel> turbulence
)
);

Info<< "Creating reaction model\n" << endl;
autoPtr<CombustionModel<basicThermo>> combustion
(
CombustionModel<basicThermo>::New(thermo, turbulence())
);
Info<< "end Creating reaction model\n" << endl;
dfChemistryModel<basicThermo>* chemistry = combustion->chemistry();
PtrList<volScalarField>& Y = chemistry->Y();
const word inertSpecie(chemistry->lookup("inertSpecie"));
const label inertIndex(chemistry->species()[inertSpecie]);


chemistry->correctThermo();
Info<< "At initial time, min/max(T) = " << min(T).value() << ", " << max(T).value() << endl;


Info<< "Creating field dpdt\n" << endl;
volScalarField dpdt
(
Expand Down Expand Up @@ -113,7 +121,7 @@ fields.add(thermo.he());

// for diffusion velocity correction

const scalar Sct = chemistry.lookupOrDefault("Sct", 1.);
const scalar Sct = chemistry->lookupOrDefault("Sct", 1.);
volScalarField diffAlphaD
(
IOobject
Expand Down
4 changes: 3 additions & 1 deletion applications/solvers/dfSprayFoam/dfSprayFoam.C
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Description
#include "pimpleControl.H"
#include "CorrectPhi.H"
//#include "fvOptions.H"
#include "basicThermo.H"
#include "CombustionModel.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Expand Down Expand Up @@ -134,7 +136,7 @@ int main(int argc, char *argv[])
#include "UEqn.H"
#include "YEqn.H"
#include "EEqn.H"
chemistry.correctThermo();
chemistry->correctThermo();
Info<< "T gas min/max " << min(T).value() << ", "
<< max(T).value() << endl;

Expand Down
Loading