Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

electron-temperature reaction #1099

Merged
merged 12 commits into from
Jan 13, 2022
Merged

electron-temperature reaction #1099

merged 12 commits into from
Jan 13, 2022

Conversation

BangShiuh
Copy link
Contributor

@BangShiuh BangShiuh commented Sep 15, 2021

Changes proposed in this pull request

  • Add a new reaction type electron-temperature
  • Add a new kinetics class PlasmaKinetics
  • This is a part of the previous PR for plasma (aka Electron). The PR was difficult to merge to the main branch at once!

If applicable, fill in the issue number this pull request is fixing

Closes #

If applicable, provide an example illustrating new features this pull request is introducing

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • The pull request is ready for review

@BangShiuh BangShiuh changed the title Ex reaction electron-temperature reaction Sep 15, 2021
@codecov
Copy link

codecov bot commented Sep 15, 2021

Codecov Report

Merging #1099 (f6307ed) into main (80c1e56) will decrease coverage by 0.94%.
The diff coverage is 90.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1099      +/-   ##
==========================================
- Coverage   66.10%   65.15%   -0.95%     
==========================================
  Files         313      315       +2     
  Lines       44963    45389     +426     
  Branches    19144    19279     +135     
==========================================
- Hits        29721    29574     -147     
- Misses      12658    13347     +689     
+ Partials     2584     2468     -116     
Impacted Files Coverage Δ
src/thermo/Phase.cpp 81.51% <ø> (+0.14%) ⬆️
include/cantera/thermo/Phase.h 84.61% <71.42%> (-2.06%) ⬇️
src/kinetics/Arrhenius.cpp 91.25% <85.07%> (-5.05%) ⬇️
src/kinetics/ReactionData.cpp 86.73% <90.90%> (-0.11%) ⬇️
include/cantera/kinetics/Arrhenius.h 97.77% <100.00%> (+0.67%) ⬆️
include/cantera/kinetics/Reaction.h 100.00% <100.00%> (ø)
include/cantera/kinetics/ReactionData.h 93.75% <100.00%> (+0.72%) ⬆️
src/kinetics/Reaction.cpp 79.31% <100.00%> (-0.56%) ⬇️
src/kinetics/ReactionFactory.cpp 92.11% <100.00%> (-1.92%) ⬇️
src/kinetics/ReactionRateFactory.cpp 94.00% <100.00%> (+0.25%) ⬆️
... and 79 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 80c1e56...f6307ed. Read the comment docs.

@BangShiuh
Copy link
Contributor Author

One difficult problem is the use of template (see my last commit). Since electron-temperature reaction use an extra data "Te", I built a special template to deal with the difference. Maybe there is a better way to handle this.

@ischoegl
Copy link
Member

ischoegl commented Oct 8, 2021

Hi @BangShiuh ... thank you for submitting this PR (and for being persistent in getting this merged). As you probably have seen, the code base for reactions has changed considerably from 2.5.1, and is still in the process of changing. The background here is Cantera/enhancements#87, which will eliminate RateCoeffMgr.h in favor of MultiRate.h - the main advantage here will be that it will become much easier to add new reaction types (and corresponding rate objects). The new 'framework' will be an exact/intuitive reflection of the YAML input format, where reaction rates are created using an extensible factory approach (instead of the legacy 'hard-coded' instantiation approach).

The current main branch already contains new objects for a range of reaction types used by GasKinetics, with the exception of Falloff and BlowersMasel, both of which rely on information defined outside of the reaction rate object itself. I am in the midst of porting these to the new framework (see #1101), which will complete the transition for GasKinetics. While most of the major parts are already implemented, I still have to work out some details (mostly due to unit conversion for Falloff).

That said, it would be ideal if your addition would use the new framework; I am sure that @speth can provide some additional context. Also, note that ReactionData.h should provide a vehicle to make electron temperature available to the reaction rate evaluator that does not require the declaration of new methods or templates. Also, #1101 proposes a new inheritance structure in Arrhenius.h which should make a definition of your new reaction rate (which is very similar to Arrhenius) much simpler.

Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @BangShiuh ... thank you for continuing to push this forward. As explained in a previous comment, the way reactions are handled is currently undergoing significant changes. The proposed new functions for PlasmaKinetics should likely use the new 'framework', which replaces RateCoeffMgr.h in favor of MultiRate.h. The comments you see below are meant to help you understand how the new framework is different from the legacy approach.

While most of what I am referring to is already in place, there are some pending changes in #1101, which may help clarify how the electron temperature can be handled. Of course, #1101 is not merged yet, so some details are still subject to change.

include/cantera/kinetics/RateCoeffMgr.h Outdated Show resolved Hide resolved
include/cantera/kinetics/GasKinetics.h Outdated Show resolved Hide resolved
include/cantera/kinetics/Reaction.h Outdated Show resolved Hide resolved
include/cantera/kinetics/Reaction.h Outdated Show resolved Hide resolved
include/cantera/kinetics/ReactionData.h Outdated Show resolved Hide resolved
src/kinetics/GasKinetics.cpp Outdated Show resolved Hide resolved
src/kinetics/GasKinetics.cpp Outdated Show resolved Hide resolved
src/kinetics/Reaction.cpp Outdated Show resolved Hide resolved
src/kinetics/ReactionFactory.cpp Outdated Show resolved Hide resolved
test/data/ET_test.yaml Outdated Show resolved Hide resolved
@speth
Copy link
Member

speth commented Dec 5, 2021

@BangShiuh, now that #1101 has been merged, can you implement a version of this that is works using the new reaction rate framework? I think this should now be possible without needing a new Kinetics type. You may be able to introduce the new reaction as a class derived from ArrheniusBase, without needing to re-implement most of what is already there. If you have any questions, feel free to ask.

@BangShiuh
Copy link
Contributor Author

BangShiuh commented Dec 12, 2021

I can't figure out how to make the rate match in test_reaction.py. The eval function is suspicious. This might be wrong. rate(self.gas.T, self.gas.Te). Also, there are too many layers of functions in test_reaction.py.

@ischoegl
Copy link
Member

The eval function is suspicious. This might be wrong. rate(self.gas.T, self.gas.Te).

As of #1101, the second argument is pressure, with other parameters being buffered internally. I just simplified this in #1153, which will make what you are attempting here possible …

Also, there are too many layers of functions in test_reaction.py.

The idea of this unit test is that everything is handled the same way. The revised update mechanism in #1153 should help here as well.

@BangShiuh BangShiuh force-pushed the ex_reaction branch 2 times, most recently from 6d131b7 to 7cc5706 Compare December 21, 2021 21:55
@BangShiuh
Copy link
Contributor Author

@ischoegl @speth test_reaction still fail on TestETempRate. I have tried my best to find the bugs such as checking if ETempData update. The number produced from test_from_yaml is suspicious, 8.1017090227726e-07 - 8.1017090227726e-10. The 3 order of magnitude maybe is the unit issue.

@speth
Copy link
Member

speth commented Dec 22, 2021

Yes, I think what you're seeing are issues with units. In kineticsfromscratch.yaml, you're specifying that the rate constant is in cm+mol units, but there is no corresponding unit specification in the _input or _yaml entries in the test class in test_reaction.py. The units for the activation energies also need to be consistent -- for example, the value of Te=1300 K corresponds to ~ 10.8e6 J/kmol in Cantera's natural units, not just 10.8.

@ischoegl
Copy link
Member

@BangShiuh ... I believe @speth is correct in his assessment. Another way to look at this is that _input should correspond to the output of the input_data property in Python.

@BangShiuh
Copy link
Contributor Author

@speth Thanks. I think I fixed it. The units are a little tricky. I will update the oxygen comments soon.

@BangShiuh
Copy link
Contributor Author

BangShiuh commented Dec 22, 2021

I have reviewed the PR and is ready to be reviewed. The assertNear tolerance is still a problem.

@BangShiuh BangShiuh force-pushed the ex_reaction branch 2 times, most recently from d1e2459 to 953f617 Compare December 23, 2021 01:33
Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @BangShiuh ... the inconsistency in failing CI tests was somewhat puzzling to me, so I pulled and compiled locally (ubuntu 20.04 / Python 3.8); tests ran without problems.

Once I added the missing overrides to the three methods (clang complained about this, although gcc did not), nine of the test_reaction.py::TestETemp tests started to fail (rate and entries to gas.forward_rate_constant evaluate as NaN; there was also a failure in KineticsAddSpecies3.add_species_sequential). It appears that the final keyword (which imho belongs here) does make a difference. On a related note, adding final and override to BlowersMaselRate (which imho should be added), does not produce any additional errors.

Regarding naming, I still hope that ETempRate could be improved upon (see previous review).

include/cantera/kinetics/Arrhenius.h Outdated Show resolved Hide resolved
include/cantera/kinetics/Arrhenius.h Outdated Show resolved Hide resolved
include/cantera/kinetics/Arrhenius.h Show resolved Hide resolved
include/cantera/kinetics/Arrhenius.h Outdated Show resolved Hide resolved
@BangShiuh
Copy link
Contributor Author

BangShiuh commented Jan 2, 2022

@ischoegl I found out that void updateTe(double Te) need to be virtual. Do you know why? Maybe because update is override so the parent struct need access to updateTe. Once we agree on the name of the class (maybe TwoTempPlasmaReaction), I will update the code.

@ischoegl
Copy link
Member

ischoegl commented Jan 2, 2022

I found out that void updateTe(double Te) need to be virtual

I’m not sure why as there isn’t an overload involved. The base class doesn’t know about it (and it certainly shouldn’t be added to the base).

@BangShiuh
Copy link
Contributor Author

I found out that void updateTe(double Te) need to be virtual

I’m not sure why as there isn’t an overload involved. The base class doesn’t know about it (and it certainly shouldn’t be added to the base).

I guess we need to figure out the difference of c++ version .

@BangShiuh
Copy link
Contributor Author

@ischoegl m_elec_temp needs to have an initial value. Do you know how to prevent this kind of error in the future?

Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @BangShiuh ... happy you located the bug! (which looks like one of the frustrating/hard-to-find ones). I have some minor remaining comments about nomenclature, but apart from that this looks mostly good to go from my side.

include/cantera/kinetics/Arrhenius.h Outdated Show resolved Hide resolved
include/cantera/thermo/Phase.h Outdated Show resolved Hide resolved
interfaces/cython/cantera/reaction.pyx Outdated Show resolved Hide resolved
interfaces/cython/cantera/reaction.pyx Outdated Show resolved Hide resolved
@@ -26,6 +26,7 @@ Phase::Phase() :
m_xml(new XML_Node("phase")),
m_id("<phase>"),
m_temp(0.001),
m_elec_temp(0.001),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a more generic comment, shouldn't the electron temperature follow the phase temperature in cases that do not involve plasma (non-equilibrium)? This can likely be addressed when implementing Cantera/enhancements#127

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be.

@ischoegl
Copy link
Member

ischoegl commented Jan 8, 2022

Hi @BangShiuh ... feel free to cherry-pick ischoegl/cantera@d618e63

Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the update, @BangShiuh. This looks all good to me!

@ischoegl ischoegl merged commit 591c28e into Cantera:main Jan 13, 2022
virtual void getParameters(AnyMap& node) const override;

double evalFromStruct(const TwoTempPlasmaData& shared_data) {
return m_A * std::exp(m_b * shared_data.logTe -
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BangShiuh this is not equivalent to the form given in the docstrings above, isn't it?

k_f = A T_e^b \exp (-E_a/RT) \exp (-E_{a,e}/RT_e)

which is the form I would expect in 2-T plasma

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TwoTempPlasma is no longer in Arrhenius. The docstrings should be update-to-date in TwoTempPlasmaRate.h.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm don't think the currently implemented form would work for (at least) our plasma models.

The currently implemented form is (1) :

k_f =  A T_e^b \exp (-E_{a,g}/RT) \exp (E_{a,e} (T_e - T)/(R T T_e))

For T_e >> T which is typical in the discharge phase, it reduces to (2) :

k_f = A T_e^b \exp (E_{a,e}-E_{a,g}/RT)

This doesn't let you model Ionization and Excitation reactions.

In Kossyi's paper, these reactions are modeled as a function of the reduced electric field
For instance nitrogen ionization below :

image

In a 2-T model you could write them as a function of electron temperature. E/N is proportional to Te in the drift-diffusion approximation. You could convert these to an Arrhenius form, where the temperature is electron temperature :

k_f = A T_e^b \exp (-E_a/RT) \exp (-E_{a,e}/RT_e)

However, the form currently implemented in Cantera won't help.

It seems to be good to model electron attachment and detachment processes, as used by Kosssyi, but unfortunately these are not the main mechanisms in (at least) our plasma-assisted-combustion models.


How hard would it be to add the Electron-temperature Arrhenius form back ?
I'm really not familiar with C so cannot help unfortunately.

Copy link
Contributor Author

@BangShiuh BangShiuh Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$k_f = A T_e^b \exp (-E_{a,g}/RT) \exp (E_{a,e} (T_e - T)/(R T T_e))$
is the same as
$k_f = A T_e^b \exp (-E_{a,g}/RT) \exp (E_{a,e}/(R T)) \exp(-E_{a,e}/(R T_e))$
You need to cancel $\exp (E_{a,e}/(R T))$ by setting $E_{a,g} = E_{a,e}$.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am working on ElectronCollisionPlasmaRate which will use the cross-section data and electron energy distribution function to calculate the reaction rates. Thank you for your interest in this feature! We would like to see more people contribute to this!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. It might be hard to read and slightly slower to compute, but it works so that's enough.

Your end goal is challenging but very helpful. How do you solve the electron energy distribution ? Bolsig / Bolos ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will write an electron Boltzmann equation solver similar to BOLOS in C++.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use this right-away 👏 🚀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth an update to the documentation to note this use case of setting $E_{a,g} = E_{a,e}$ to support reactions with the rate expression desired here, since that transformation of the rate expression might not occur to users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants