Skip to content

Commit

Permalink
Merge branch 'master' into py
Browse files Browse the repository at this point in the history
  • Loading branch information
zhixchen authored Nov 20, 2023
2 parents 0325064 + 77c4611 commit 22f3660
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
22 changes: 19 additions & 3 deletions docs/source/qs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ Alternatively, one can `compile OpenFOAM-7 from source code <https://openfoam.or
**LibCantera** and **PyTorch** can be easily installed via `conda <https://docs.conda.io/en/latest/miniconda.html#linux-installers>`_. If your platform is compatible, run the following command to install the dependencies.

.. code-block:: bash
conda create -n deepflame python=3.8
conda activate deepflame
conda install -c conda-forge libcantera-devel
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
conda install pybind11
conda install -c conda-forge easydict
.. Note:: Please go to `the official website of PyTorch <https://pytorch.org/>`_ to check your system compatibility and choose the installation command line that is suitable for your platform.

.. code-block:: bash
Expand Down Expand Up @@ -123,8 +132,15 @@ Finally you can build and install DeepFlame:
. install.sh
.. Note:: You may come accross an error regarding shared library ``libmkl_rt.so.2`` when libcantera is installed through cantera channel. If so, go to your conda environment and check the existance of ``libmkl_rt.so.2`` and ``libmkl_rt.so.1``, and then link ``libmkl_rt.so.2`` to ``libmkl_rt.so.1``.
.. Note:: You may see an error ``fmt`` or ``eigen`` files cannot be found. If so, go to your conda environment and install the packages as follows.

.. code-block:: bash
conda install fmt
conda install eigen
.. Note:: You may also come accross an error regarding shared library ``libmkl_rt.so.2`` when libcantera is installed through cantera channel. If so, go to your conda environment and check the existance of ``libmkl_rt.so.2`` and ``libmkl_rt.so.1``, and then link ``libmkl_rt.so.2`` to ``libmkl_rt.so.1``.

.. code-block:: bash
cd ~/miniconda3/envs/deepflame/lib
Expand All @@ -144,7 +160,7 @@ DeepFlame also provides users with LibTorch and CVODE (no DNN version) options.
conda create -n df-libtorch python=3.8
conda activate df-libtorch
conda install -c cantera libcantera-devel
conda install -c conda-forge libcantera-devel
Then you can pass your own libtorch path to DeepFlame.

Expand All @@ -164,7 +180,7 @@ Then you can pass your own libtorch path to DeepFlame.
conda create -n df-notorch python=3.8
conda activate df-notorch
conda install -c cantera libcantera-devel
conda install -c conda-forge libcantera-devel
If the conda env ``df-notorch`` is activated, install DeepFlame by running:

Expand Down
8 changes: 4 additions & 4 deletions src/dfChemistryModel/pytorchFunctions.H
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ Foam::scalar Foam::dfChemistryModel<ThermoType>::solve_DNN(const DeltaTType &del
pybind11::module_ call_torch = pybind11::module_::import("inference"); // import python file
pybind11::object result = call_torch.attr("inference")(vec0, vec1, vec2); // call python function
const double* star = result.cast<pybind11::array_t<double>>().data();
std::vector<double> outputsVec0(star, star+outputLength[0] * 7); //the float number is sample_length*sample_number
std::vector<double> outputsVec1(star+outputLength[0] * 7, star+outputLength[1] * 7);
std::vector<double> outputsVec2(star+outputLength[1] * 7, star+outputLength[2] * 7);
std::vector<double> outputsVec0(star, star+outputLength[0] * mixture_.nSpecies()); //the float number is sample_length*sample_number
std::vector<double> outputsVec1(star+outputLength[0] * mixture_.nSpecies(), star+outputLength[1] * mixture_.nSpecies());
std::vector<double> outputsVec2(star+outputLength[1] * mixture_.nSpecies(), star+outputLength[2] * mixture_.nSpecies());
std::vector<std::vector<double>> results = {outputsVec0, outputsVec1, outputsVec2};
updateSolutionBuffer(solutionBuffer, results, cellIDBuffer, problemCounter);
DynamicList<GpuSolution> finalList;
Expand All @@ -301,4 +301,4 @@ Foam::scalar Foam::dfChemistryModel<ThermoType>::solve_DNN(const DeltaTType &del
time_allsolve_ += processingTime.count();

return deltaTMin;
}
}
6 changes: 3 additions & 3 deletions src/dfChemistryModel/torchFunctions.H
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ void Foam::dfChemistryModel<ThermoType>::getDNNinputs

if (gpulog_)
{
std::cout<<"inputsDNN0 = "<<inputsDNN0.size()/10 << "\n";
std::cout<<"inputsDNN1 = "<<inputsDNN1.size()/10 << "\n";
std::cout<<"inputsDNN2 = "<<inputsDNN2.size()/10 << "\n";
std::cout<<"inputsDNN0 = "<<inputsDNN0.size()/(mixture_.nSpecies()+3) << "\n";
std::cout<<"inputsDNN1 = "<<inputsDNN1.size()/(mixture_.nSpecies()+3) << "\n";
std::cout<<"inputsDNN2 = "<<inputsDNN2.size()/(mixture_.nSpecies()+3) << "\n";
}

return;
Expand Down

0 comments on commit 22f3660

Please sign in to comment.