Reaction integration related questions in PeleLMeX #422
Replies: 9 comments 25 replies
-
In PelePhysics, the state vector that is given to CVode or the other chemical integrators is the species and temperature (rather than enthalpy), which simplifies the Jacobian. See here: https://amrex-combustion.github.io/PelePhysics/CvodeInPP.html#the-different-reactors (although don't read too far because some of that documentation has fallen very out of date). The bits of code you've called out ensure that the initial temperature for chemistry integration is consistent with the initial enthalpy and that the enthalpy gets updated properly at the end of chemistry integration. |
Beta Was this translation helpful? Give feedback.
-
Okay. To replace the reaction integration in PeleLMeX (currently done using CVODE) with the DeepONet, I have an intermediate C++ file (with one of the headers being #include <Python.h> ) that calls the necessary functions from the DeepONet code (in python) and returns the required outputs, i.e., species MF and temperature. I have added this function in the ReactorCvode.cpp file (in the CPU region, after the box_flatten, and before the box_unflatten) and included the intermediate C++ file in the header accordingly. Even though I have added the header files and libraries in the Cmake file. I added in BuildPelePhysicsLib.cmake Can you please help with this? Thanks for your time. |
Beta Was this translation helpful? Give feedback.
-
As a general word of advice, I would recommend adding a new I haven't previously written software that calls python functions from C++ code (the reverse is more common) so I can't provide useful advice on how to approach that or get things to compile properly. Also, it seems likely to me that this strategy will not end up being computationally efficient. If you are training your models using pytorch or tensorflow in python, it isn't that difficult to link Pele to C++ versions of these libraries and execute a network that was exported from your python training scripts. There are some very basic examples of doing that here: https://github.nrel.gov/bperry/ML-Models-CPP, and we have previously integrated both tensorflow and pytorch models into Pele in this manner. I could provide further pointers if you're interested in this strategy. A final option would be to take advantage of the home-rolled neural network evaluator that is now in PelePhysics (https://github.com/AMReX-Combustion/PelePhysics/blob/development/Source/Utility/BlackBoxFunction/NeuralNetHomerolled.H), although this implementation is very specific and would have to be adapted for your use case. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your advice. I will try to implement them in my work. I tried compiling the Python code and the intermediate C++ file (that calls the python functions) with PeleLMeX. It is compiling now, but there is some issue while linking Python, and that's why the executable is not created. I have added this to the "Make.PeleLMeX" file in the "Exec" folder:
I have added the Python files and the intermediate C++ in the folder of the case that I am running (Exec/RegTests/EB_BackwardStepFlame) and in the Submodules/PelePhysics/Source/Reactions directory. This is the error that I get on the terminal:
I will highly appreciate any help from your side in my work. If you have any idea how to resolve this, please let me know. Thank you so much. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
That initial condition looks reasonable to me. From that output, it looks like the linear solvers are converging, although not quite to the default criterion. You can adjust the tolerances as documented here: https://amrex-combustion.github.io/PeleLMeX/manual/html/LMeXControls.html#linear-solvers I'd recommend something around 1e-9 for rtol and 1e-10 for atoll for both mac and nodal projections. |
Beta Was this translation helpful? Give feedback.
-
I did that, and now the linear solver is converging, but it said in the command window that dt is too small and the simulation will stop. So I added Now, the simulation is running without issues, but when i try to visualize any plotfile except the initial one, it looks like this: Every other variable contour looks exactly like the above one. When I look at the values of variables using spreadsheet view, I see a lot of zeros and NaNs. Any idea why this is happening? |
Beta Was this translation helpful? Give feedback.
-
Okay. Running the code with debug mode gave me something like this
|
Beta Was this translation helpful? Give feedback.
-
Can you add divu to the plot file and look to see if there is something unexpected in that field? |
Beta Was this translation helpful? Give feedback.
-
Hi. I am trying to understand the algorithm of PeleLMeX, and I have some questions.

So I understand that this code uses an operator splitting technique to solve for transport and reactions separately. In the documentation (Step 2 of the algorithm), it is given that after calculating the advective and diffusive terms for reactions and enthalpy, we end up with this ODE system:
Then, these equations are integrated with the CVODE package in SUNDIALS.
In PeleLMeX_Advance.cpp file, the advanceChemistry function is called. Then that function loops over all the AMR levels and integrates chemistry in each of them. When integrating, PeleLMeX_Reactions.cpp falls the m_reactor -> react object, which takes us into the react (the one with box as one of the inputs) function in the ReactorCvode.cpp file (because our chem_integrator = "ReactorCvode") . Inside that function, before integrating, the data is flattened from multidimensional to 1D using box_flatten function, and after the reaction integration has taken place, the the data is unflattened using the box_unflatten function.
My questions are:
During flattening (using box_flatten function defined in ReactorUtils.H), why is the temperature updated using the EOS?

During unflattering (using box_unflatten function defined in ReactorUtils.H), which happens after the reaction ODEs have integrated, why is the value of energy updated again using the frcEExt term, which is essentially the advection and diffusion term related to energy? The advection and diffusion terms were already considered while integrating the reactions, right?
I understand that after energy calculations, we need to calculate temperature, which is done here using the EOS.
Thank you. Waiting for your response.
Beta Was this translation helpful? Give feedback.
All reactions