Dear all,
I hope this message finds you well.
After a 7+ years break in chemistry and combustion, I am starting again in this field, and I have greatly appreciated Cantera and the available tutorials, they really kick-started my learning again !
I have mostly dabbled with the python interface, and I am now trying to dive deeper to make sure I have everything right. The goal I set myself with is to reproduce in python the case of the infinite adiabatic flame, using Cantera only “for the chemistry” as a black box. This means re-writing the residual calculation, and the Newton solver (re-calculate the Jacobian). I think there would be value for some Cantera users in having such a tutorial. I know I would have liked it 🙂
This approach of re-writing one’s own residual is similar to some of the available tutorials (i.e., 1D_packbed.ipynb), except that a DAE integrator was used to advance the solution in space.
I was able to access the residual calculated by Cantera, in order to compare it with my own. There are major differences in their amplitudes, which tells me that something is very wrong with my calculations.
I have attached three python files, in case someone can help:
my_adiabatic_flame.py, in which I use Cantera’s solver to obtain a solution for the flame, and where I display the different terms composing the residual that I re-calculated, based on that solution. I also compare the total residual with that of Cantera (re-scaled, and multiplied by 5e5 to be of comparable order with my residuals, for the plot).
my_tools.py, where I coded the spatial derivatives. I use a central difference adapted for non-uniform grids for interior grid points. At the inlet, an upward scheme is used, and at the outlet, a backward scheme. I (quickly) tested the implementation of the first and second order of these derivatives in test_derivatives.py.
Before continuing with the Jacobian implementation and then the Newton solver, I was wondering if someone experienced in the flux calculations could have a look in my_adiabatic_flame.py, near lines 90-107, and in the writing of the residual terms, lines 110-147, to see if it seems ok to you. Is there any other reason why the residual would be so different from the one calculated by Cantera (maybe the way I import it) ? I suspect a problem of units somewhere.
Any help is appreciated,
Regards, and a happy new year in advance to you :)
Rémi
--
You received this message because you are subscribed to the Google Groups "Cantera Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cantera-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cantera-users/c3c155c3-f59f-4c41-a332-d7d4e95c60ean%40googlegroups.com.
Dear all,
progress has been made since the time of my initial message, and I would now like to share it with the community. Those who are interested can have a look a pyromancy, a code that attempts to only call Cantera for the chemistry part, and that re-introduces its own residual calculation, Jacobian calculation and Newton solver. Doing so was quite educational, even though I am still stuck.
In its current state, the code I developed is not really useful, as it does not allow one to solve for a free flame. At least not yet ! The reason is still a bit unclear to me, but I currently suspect that solving the linear system is the key step I am still not doing properly. In Cantera, this step relies on LAPACK solvers that can handle the band matrix structure of the Jacobian, with an LU step for the factorization. While I was able to call similar LAPACK routines from python’s scipy package, I found that they would not “tolerate'' the Jacobian I calculated, as it is too ill-conditioned. It is thus possible that errors remain in my Residual or Jacobian calculation. Or that I am missing a key conditioning step.
For those of you who want to dig in the code, let me know :) Hopefully I’m not the only one with an interest in this python partial “rewrite”.
In terms of structure, pyromancy somewhat follows Cantera’s, with some changes. I am still not fully set on them, and things might change in the future. Currently, only a single domain is supported, and only the equations of a free flame have been coded.
I have created an “examples” folder with a script in which I compare the residual calculation done by Cantera and pyromancy. There is also a “start_here.py” script to get you started, should you wish to 🙂
I have also created a “tests” folder where I stored the current tests I am developing to see what works, and especially what doesn’t (it’s not a unit-test folder).
I am currently working on the script “tests/test_FreeFlame_convergence.py”, where I create a flame (which can be initialized by Cantera’s solution), a Jacobian object (I compare my Jacobian implementation with the default implementation that does not make use of the banded structure), and I calculate a Newton step in a few different ways. I then attempt to solve the problem, to no avail at the moment. I created a SolidConduction class to code a (simpler) residual for the heat equation (with more well-conditioned Jacobian). The resolution seems to work, even though I obtain small differences between the Newton solver and the time-stepping solution.
I am short of ideas in terms of what to try next, especially since I do not know how to return the Jacobian matrix directly from Cantera in order to compare it with my own. So I’ll consider any input 🙂
Best,
Remi