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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ polyMesh/
thirdParty
libtorch*.zip*
.DS_Store
__pycache__/
4 changes: 4 additions & 0 deletions applications/solvers/df0DFoam/EEqn.H
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
volScalarField& he = thermo.he();
if (constProp == "volume") he[0] = u0 + p[0]/rho[0];
start = std::clock();
chemistry.correctThermo();
end = std::clock();
time_monitor_corrThermo += double(end - start) / double(CLOCKS_PER_SEC);

}
1 change: 1 addition & 0 deletions applications/solvers/df0DFoam/Make/options
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ EXE_INC = -std=c++14 \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/Pstream/mpi \
-I$(LIB_SRC)/dynamicFvMesh/lnInclude \
-I$(DF_SRC)/CanteraMixture/lnInclude \
-I$(DF_SRC)/dfChemistryModel/lnInclude \
Expand Down
15 changes: 14 additions & 1 deletion applications/solvers/df0DFoam/YEqn.H
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ tmp<fv::convectionScheme<scalar>> mvConvection
);

{
chemistry.solve(mesh.time().deltaTValue());
{
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
chemistry.solve(mesh.time().deltaTValue());
label flag_mpi_init;
MPI_Initialized(&flag_mpi_init);
if(flag_mpi_init) MPI_Barrier(PstreamGlobals::MPI_COMM_FOAM);
std::chrono::steady_clock::time_point stop = std::chrono::steady_clock::now();
std::chrono::duration<double> processingTime = std::chrono::duration_cast<std::chrono::duration<double>>(stop - start);
time_monitor_chem += processingTime.count();
}

volScalarField Yt(0.0*Y[0]);

start = std::clock();
forAll(Y, i)
{
if (i != inertIndex)
Expand Down Expand Up @@ -43,4 +53,7 @@ tmp<fv::convectionScheme<scalar>> mvConvection

Y[inertIndex] = scalar(1) - Yt;
Y[inertIndex].max(0.0);

end = std::clock();
time_monitor_Y += double(end - start) / double(CLOCKS_PER_SEC);
}
4 changes: 3 additions & 1 deletion applications/solvers/df0DFoam/createFields.H
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,6 @@ if
}

volScalarField& he = thermo.he();
scalar u0 = he[0] - p[0]/rho[0];
scalar u0 = he[0] - p[0]/rho[0];

const Switch log_ = CanteraTorchProperties.subDict("TorchSettings").lookupOrDefault("log", false);
30 changes: 28 additions & 2 deletions applications/solvers/df0DFoam/df0DFoam.C
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Description
//#include "fvOptions.H"
#include "localEulerDdtScheme.H"
#include "fvcSmooth.H"
#include "PstreamGlobals.H"

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

Expand All @@ -73,6 +74,11 @@ int main(int argc, char *argv[])
#include "createFields.H"
#include "createFieldRefs.H"
#include "createRhoUfIfPresent.H"

double time_monitor_chem=0;
double time_monitor_Y=0;
double time_monitor_corrThermo=0;
clock_t start, end;

turbulence->validate();

Expand Down Expand Up @@ -107,9 +113,29 @@ int main(int argc, char *argv[])

runTime.write();

Info<< "========Time Spent in diffenet parts========"<< endl;
Info<< "Chemical sources = " << time_monitor_chem << " s" << endl;
Info<< "Species Equations = " << time_monitor_Y << " s" << endl;
Info<< "thermo & Trans Properties = " << time_monitor_corrThermo << " s" << endl;
Info<< "============================================"<<nl<< endl;

Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
<< " ClockTime = " << runTime.elapsedClockTime() << " s"
<< nl << endl;
<< " ClockTime = " << runTime.elapsedClockTime() << " s"<<endl;
#ifdef USE_PYTORCH
if (log_)
{
Info<< " allsolveTime = " << chemistry.time_allsolve() << " s"
<< " submasterTime = " << chemistry.time_submaster() << " s" << nl
<< " sendProblemTime = " << chemistry.time_sendProblem() << " s"
<< " recvProblemTime = " << chemistry.time_RecvProblem() << " s"
<< " sendRecvSolutionTime = " << chemistry.time_sendRecvSolution() << " s" << nl
<< " getDNNinputsTime = " << chemistry.time_getDNNinputs() << " s"
<< " DNNinferenceTime = " << chemistry.time_DNNinference() << " s"
<< " updateSolutionBufferTime = " << chemistry.time_updateSolutionBuffer() << " s" << nl
<< " vec2ndarrayTime = " << chemistry.time_vec2ndarray() << " s"
<< " pythonTime = " << chemistry.time_python() << " s"<< nl << endl;
}
#endif
}

Info<< "End\n" << endl;
Expand Down
3 changes: 2 additions & 1 deletion applications/solvers/dfLowMachFoam/createFields.H
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,5 @@ IOdictionary CanteraTorchProperties
IOobject::NO_WRITE
)
);
const Switch splitting = CanteraTorchProperties.lookupOrDefault("splittingStrategy", false);
const Switch splitting = CanteraTorchProperties.lookupOrDefault("splittingStrategy", false);
const Switch log_ = CanteraTorchProperties.subDict("TorchSettings").lookupOrDefault("log", false);
22 changes: 13 additions & 9 deletions applications/solvers/dfLowMachFoam/dfLowMachFoam.C
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,20 @@ int main(int argc, char *argv[])

runTime.write();

Info<< "MonitorTime_chem = " << time_monitor_chem << " s" << nl << endl;
Info<< "MonitorTime_Y = " << time_monitor_Y << " s" << nl << endl;
Info<< "MonitorTime_flow = " << time_monitor_flow << " s" << nl << endl;
Info<< "MonitorTime_E = " << time_monitor_E << " s" << nl << endl;
Info<< "MonitorTime_corrThermo = " << time_monitor_corrThermo << " s" << nl << endl;
Info<< "========Time Spent in diffenet parts========"<< endl;
Info<< "Chemical sources = " << time_monitor_chem << " s" << endl;
Info<< "Species Equations = " << time_monitor_Y << " s" << endl;
Info<< "U & p Equations = " << time_monitor_flow << " s" << endl;
Info<< "Energy Equations = " << time_monitor_E << " s" << endl;
Info<< "thermo & Trans Properties = " << time_monitor_corrThermo << " s" << endl;
Info<< "============================================"<<nl<< endl;

Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
<< " ClockTime = " << runTime.elapsedClockTime() << " s"
<< " ClockTime = " << runTime.elapsedClockTime() << " s" << endl
#ifdef USE_PYTORCH
<< " allsolveTime = " << chemistry->time_allsolve() << " s"
if (log_)
{
Info<< " allsolveTime = " << chemistry->time_allsolve() << " s"
<< " submasterTime = " << chemistry->time_submaster() << " s" << nl
<< " sendProblemTime = " << chemistry->time_sendProblem() << " s"
<< " recvProblemTime = " << chemistry->time_RecvProblem() << " s"
Expand All @@ -206,9 +210,9 @@ int main(int argc, char *argv[])
<< " DNNinferenceTime = " << chemistry->time_DNNinference() << " s"
<< " updateSolutionBufferTime = " << chemistry->time_updateSolutionBuffer() << " s" << nl
<< " vec2ndarrayTime = " << chemistry->time_vec2ndarray() << " s"
<< " pythonTime = " << chemistry->time_python() << " s"
<< " pythonTime = " << chemistry->time_python() << " s"<< nl << endl;
}
#endif
<< nl << endl;
}

Info<< "End\n" << endl;
Expand Down
177 changes: 177 additions & 0 deletions configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
#!/bin/sh


unset USE_LIBTORCH
unset USE_PYTORCH
unset LIBTORCH_DIR
unset LIBCANTERA_DIR
unset PYTORCH_INC
unset PYTORCH_LIB

print_usage() {
echo "Usage: . install.sh --libtorch_no (default) | --libtorch_dir _path_to_libtorch | --libtorch_autodownload | --use_pytorch | --libcantera_dir _path_to_libcantera"
}

# default
LIBTORCH_AUTO=false
USE_LIBTORCH=false
USE_PYTORCH=false

while test $# -gt 0; do
case "$1" in
-h|--help)
print_usage
return
;;
--libtorch_dir)
shift
if test $# -gt 0; then
LIBTORCH_DIR=$1
USE_LIBTORCH=true
else
print_usage
return
fi
shift
;;
--libtorch_autodownload)
USE_LIBTORCH=true
LIBTORCH_AUTO=true
LIBTORCH_DIR="$PWD/thirdParty/libtorch"
shift
;;
--libtorch_no)
shift
USE_LIBTORCH=false
shift
;;
--use_pytorch)
shift
USE_PYTORCH=true
shift
;;
--libcantera_dir)
shift
if test $# -gt 0; then
LIBCANTERA_DIR=$1
else
print_usage
return
fi
shift
;;
-h|--help)
shift
print_usage
shift
;;
*)
echo "$1 is not a recognized flag!"
print_usage
return
;;
esac
done



# if LIBCANTERA_DIR empty and CONDA_PREFIX empty
if [ -z "$LIBCANTERA_DIR" ] && [ -z "$CONDA_PREFIX" ]; then
echo "ERROR! either offer libcantera dir or ensure in the conda enviorment including libcantera-devel!"
return
fi


# if LIBCANTERA_DIR not empty and CONDA_PREFIX not empty
# --libcantera_dir _path_to_libcantera has a higher priority than the path from conda enviornment
if [ ! -z "$LIBCANTERA_DIR" ] && [ ! -z "$CONDA_PREFIX" ]; then
echo "duplicate libcantera dir from args and from conda!"
echo "from args: "$LIBCANTERA_DIR
echo "from args: "$CONDA_PREFIX
echo "we are going to use the dir from args: "$LIBCANTERA_DIR
fi


# if LIBCANTERA_DIR empty and CONDA_PREFIX not empty
if [ -z "$LIBCANTERA_DIR" ] && [ ! -z "$CONDA_PREFIX" ]; then
LIBCANTERA_DIR=$CONDA_PREFIX
fi


# if LIBCANTERA_DIR not empty and CONDA_PREFIX empty
# just use LIBCANTERA_DIR


if [ $USE_LIBTORCH = true ] && [ $USE_PYTORCH = true ]; then
echo "ERROR! either use libtorch or pytorch!"
return
fi


if [ $LIBTORCH_AUTO = true ]; then
if [ -d "thirdParty/libtorch" ]; then
echo "libtorch already exist."
else
if [ -e libtorch-cxx11-abi-shared-with-deps-1.11.0+cpu.zip ]
then
echo "libtorch.zip exist."
else
wget https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.11.0%2Bcpu.zip
fi
unzip libtorch-cxx11-abi-shared-with-deps-1.11.0+cpu.zip -d thirdParty
fi
fi


if [ $USE_PYTORCH = true ]; then
PYTORCH_INC=`python3 -m pybind11 --includes`
if [ -z "$PYTORCH_INC" ]; then
return
fi
PYTORCH_LIB=`python3 -c "from distutils import sysconfig; \
import os.path as op; v = sysconfig.get_config_vars(); \
fpaths = [op.join(v[pv], v['LDLIBRARY']) for pv in ('LIBDIR', 'LIBPL')]; \
print(list(filter(op.exists, fpaths))[0])" | xargs dirname`
fi



echo "setup for deepflame bashrc:"
echo LIBCANTERA_DIR=$LIBCANTERA_DIR
if [ $USE_LIBTORCH = true ]; then
echo LIBTORCH_DIR=$LIBTORCH_DIR
echo PYTORCH_INC=""
echo PYTORCH_LIB=""
fi
if [ $USE_PYTORCH = true ]; then
echo PYTORCH_INC=$PYTORCH_INC
echo PYTORCH_LIB=$PYTORCH_LIB
echo LIBTORCH_DIR=""
fi

cp bashrc.in bashrc
sed -i "s#pwd#$PWD#g" ./bashrc
sed -i "s#LIBTORCH_DIR#$LIBTORCH_DIR#g" ./bashrc
sed -i "s#PYTORCH_INC#$PYTORCH_INC#g" ./bashrc
sed -i "s#PYTORCH_LIB#$PYTORCH_LIB#g" ./bashrc
sed -i "s#LIBCANTERA_DIR#$LIBCANTERA_DIR#g" ./bashrc




if [ -d "src_orig" ]; then
echo "src_orig exist."
else
mkdir -p src_orig/TurbulenceModels
mkdir -p src_orig/thermophysicalModels
mkdir -p src_orig/lagrangian
mkdir -p src_orig/regionModels
mkdir -p src_orig/functionObjects
cp -r $FOAM_SRC/TurbulenceModels/compressible src_orig/TurbulenceModels
cp -r $FOAM_SRC/thermophysicalModels/basic src_orig/thermophysicalModels
cp -r $FOAM_SRC/thermophysicalModels/thermophysicalProperties src_orig/thermophysicalModels
cp -r $FOAM_SRC/lagrangian/intermediate src_orig/lagrangian
cp -r $FOAM_SRC/lagrangian/turbulence src_orig/lagrangian
cp -r $FOAM_SRC/regionModels/surfaceFilmModels src_orig/regionModels
cp -r $FOAM_SRC/functionObjects/field src_orig/functionObjects
fi
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,21 @@ odeCoeffs
"absTol" 1e-24;
}
inertSpecie "N2";

zeroDReactor
{
constantProperty "pressure";//cvorcp "UV";
}

torch on;
GPU on;
torchModel1 "ESH2-sub1.pt";
torchModel2 "ESH2-sub2.pt";
torchModel3 "ESH2-sub3.pt";

torchParameters1
TorchSettings
{
Tact 700 ;
Qdotact 3e7;
torch off;
GPU off;
log on;
torchModel1 "ESH2-sub1.pt";
torchModel2 "ESH2-sub2.pt";
torchModel3 "ESH2-sub3.pt";
coresPerGPU 4;
}
torchParameters2
{
Tact 2000;
Qdotact 3e7;
}
torchParameters3
{
Tact 2000;
Qdotact 7e8;
}
loadbalancing
{
active false;
Expand Down
Loading