Cantera : Diffusion Fluxes Calculation

631 views
Skip to first unread message

Marina Kovaleva

unread,
Jun 18, 2022, 12:44:04 AM6/18/22
to Cantera Users' Group
I've recently been looking into trying to calculate the multi-component diffusion fluxes for specific species of 1D laminar premixed flames (burner, freeflame, impinging jet etc.) 

Writing the script directly in the python interface leads to unstable and near-infinite values in the mass diffusion contribution in many cases (occurring in areas of low species concentrations). I have trialed this on a few mechanisms and 1D flame models with no luck. 

Please find attached the code I have been using for this based on a known result from paper (Lu, 2015), based on my best attempt to create the modified GRI mech from that paper. I have another version of the same code but utilising a CHEMKIN or Cantera csv file solution. In this code, the same issue occurs at low species concentrations (i.e if looking at a species with low concentrations like 'H' or 'OH'). 

Weirdly, the thermal diffusion result in the code attached seems to be relatively accurate and stable. Unfortunately, I do not have enough knowledge of cantera to try to code this formulation directly into the C++ codes as was done in ember. I have been tempted to use ember, however, I believe it only has the mixture averaged formulation? 

I've been stuck on this for a few weeks now, so would really appreciate any thoughts or suggestions you may have. 

To replicate issue, please call the diffusion.py TransportCalc class with the following script : 
from folder_containing_file.diffusion import TransportCalc

def main():
    TransportCalc('../path/to/mech/gri-liu.cti', 'H2')

if __name__=="__main__":
    main()
diffusion copy 2.py
gri-liu.cti

Bryan Weber

unread,
Jun 21, 2022, 10:58:53 AM6/21/22
to Cantera Users' Group
Hi Marina,

I didn't get a chance to run your code, but I noted a few things stood out to me (not all of these will affect the result though):

1. Why are you using np.float32 as the dtype for most of your arrays? The default, np.float64, should be more appropriate I think.
2. You can set the transport model when you create the `Solution`, self.gas_temp = ct.Solution(..., transport_model="Multi"). Then you don't have to set it in your loop.
3. You have this line:

self.D_kj[:, n] = self.gas_temp.multi_diff_coeffs[self.species, :] # we only care about species k (col) in gas all (row)

If species "k" is in the column, then it should be the second index. This code is actually doing, take one row for the species of interest and get all the columns, the opposite of your comment. However, I think the code is correct and the comment is not :-)

4. I found an equation here: https://ntrs.nasa.gov/api/citations/20040090466/downloads/20040090466.pdf that looks a little different from your code. The mass flux of species i, J_i, is given by

J_i = rho M_i/M^2 * sum(j != i) M_j D_ij grad(X_j)

One of the things I noted in your code was that you weren't avoiding the sum where j == i, you just have the loop over all the species. This might explain the very large results for small-concentration species.

Hope that helps!
Bryan

Marina Kovaleva

unread,
Jun 23, 2022, 3:57:49 PM6/23/22
to Cantera Users' Group
Dear Bryan,

Thank you for the reply - that was a huge help. In response to your points: 
1. I added the float specification as I was varying types in the arrays but it does not seem to make a difference in this case. 
2. Thank you for the recommendation - script adjusted. 
3. Thank you for clarification - that helps my understanding.  
4. D(i = j) gives a 0 diffusion value, so when I excluded it, it did not make a difference to my calculation. However using the flux calculation (from the NASA paper you attached) removes the near-infinite values. Essentially, I have been using the CHEMKIN documentation equations in which the units are m/s, but here are kg/m^2s. 

FYI (and for anyone interested in the future) from paper you sent, the slide below also includes the thermal diffusion flux term: 

The results are still strange when implementing this equation so I'll get back to you with an updated code after I have exhausted my options or a solution. However, this is progress- thank you for your help on this.

Kind regards,

Marina

Marina Kovaleva

unread,
Jun 25, 2022, 5:40:33 PM6/25/22
to Cantera Users' Group
Dear Bryan, 

Just to follow up on this. The script with the ammended equations you have suggested still seems to give an error - however, now instead of infinity values, it gives the same molecular flux trend for all species. Since I am really struggling to find the error in these calculations, I am wondering if there are any is there an underlying C++ functions in Cantera that already calculates these flux values that perhaps I could use? If so, please could it be possible to have some pointers - I am guessing I would need to use Cython to bring them out into the python interface? 

The ember script gives the correct results, but does not have the flame configurations I would be looking to recreate. I believe in ember, the calculation is in the src/flameSolver.cpp - FlameSolver::updateCrossTerms function - this is the kind of C++ calculation I would be looking for. 

FIles attached: 
- Ember script with flux calculation results (ember.py_
- Diffusion script with results compared to thoses published in following paper by Fillo et al.  (main.py to call diffusion_copy, mechanism file, Fillo et al paper used for validation): 


Kind regards,

Marina

10220564.pdf
ember.py.txt
hong.cti
diffusion_copy.py.txt
main.py.txt

Steven DeCaluwe

unread,
Jun 26, 2022, 4:48:47 AM6/26/22
to Cantera Users' Group
Hi Marina,

Cantera does have C++ functions for calculating the multi-component species fluxes:

See here for the mass fluxes and here for the molar fluxes (although this latter function just calls the mass fluxes and divides by MW_k)

Hope these are helpful.  

Best,
Steven

——————————————————
Steven C. DeCaluwe, Ph.D | Associate Professor of Mechanical Engineering
COLORADOSCHOOLOFMINES
Brown Building W410B
Golden, CO 80401

Twitter: @CORESresearch
He / Him / His





--
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/fd3212e3-512e-447e-98c2-d97415c5759an%40googlegroups.com.
<10220564.pdf><ember.py.txt><hong.cti><diffusion_copy.py.txt><main.py.txt>

Reply all
Reply to author
Forward
0 new messages