-
Notifications
You must be signed in to change notification settings - Fork 5
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
Export Solution to Chemkin Format #52
Comments
Something that would make this much smoother would be if it were possible for Cantera to load the notes from the yaml format. My method of reparsing the yaml file for these notes has holes in it if there are duplicate reactions, specified or unspecified. |
I actually think it is not a big deal whether the notes are preserved during format conversion. Normally, the situation that you want to get a Chemkin format is for uncertainty quantification and optimization. Those checkin mech files are temporal files and you can also look up the notes from the original mechanism. As long as users can find a copy of the original mechanism, the missing notes in checkin file is not a problem. It might also helpful that if we set a hub for reaction mechanisms and put different formats together. For example, https://github.com/jiweiqi/CollectionOfMechanisms |
I don't view the CK files as temp files. A CK mechanism is the final product that others in the community will use because it is the de facto standard, for better or worse. In my experience, the link between reaction and source are often lost in published mechanisms. From my perspective, why create an opportunity for loss of information if there's no reason to? Every reaction should have a source, even if that source is present work: analogy to X, or else it's just numbers. Hubs and whatnot are always useful if you have someone with the time/funding to maintain them. Would it be more appropriate for this functionality to be more basic aka written in C++? |
This would likely be the best case. In the development version, @speth introduced a class called |
I think supporting conversion of Cantera YAML files (or Solution objects) to Chemkin format is important because that would allow the Cantera YAML format to serve as an extensible interchange format. Without that capability, we're stuck with the Chemkin format being the only thing that can be converted to every other format. In addition to working towards YAML serialization (#11), I am working on making all of the YAML input data (not just the fields used by Cantera) available in the Python interface, which should make writing a script to output to any desired format relatively easy. I don't think it would make sense to add output capabilities to any format besides YAML at the C++ level. |
Doesn't this effectively limit CK export to the Python interface? I know we don't get to spend as much effort on the other interfaces, but I think it would be very useful to be able to export other formats from, say, the MATLAB or Fortran interface. Presumably, that would be easier if the functionality were wrapped up in the C++ layer rather than delegating to each interface independently. On the other side, the only way to import CK files is by converting them with a Python script. I would say that the distinction is that the conversion script is more-or-less independent of Cantera functionality, whereas the output to CK format is most useful after some work has been done within Cantera. |
I believe that emitting Would it make sense to create a function |
My thoughts are summed up well by @bryanwweber. It seems to be a question of how core this functionality should be because if it's something that each interface is going to want then the redundancy of writing the same function in multiple languages would be a hindrance. @ischoegl one possible downfall of going directly from yaml2ck is that the yaml mechanism isn't necessarily a functioning mechanism if it's created by the user. This is only a problem in the sense that error checking would have to be included as well. I'm not sure Why someone would do this, but it's possible. Would there be an advantage to going directly from yaml to ck? |
I guess the way I think of the input file converters, both to and from Cantera formats, is as utilities that exist outside of using any particular Cantera interface. I'm not trying to relegate them to the Python interface -- they're packaged as scripts rather than just functions in the Python module for exactly this reason, and I don't think this functionality should be duplicated in multiple interfaces, either. The main reason I think a |
What @speth said makes a lot of sense I think. Since we already wrote a |
I agree with both @speth and @kyleniemeyer ... C++ is efficient/fast whereas Python is convenient and easier to maintain. As the conversion is presumably not done very often, speed is not a primary concern. Regarding porting this to multiple platforms (beyond Python) I do not believe that the benefit justifies the effort. |
@tsikes ... I created a draft PR that makes the annotations you re-read from YAML (in the I realize that there are plans to add custom user-defined fields to YAML down the road. However, imho |
@ischoegl, Fantastic! Thank you for the help with this. I was not happy with my solution to this part of the problem. |
I created an initial implementation of yaml2ck here. This version is based upon Cantera/cantera#881. If this PR doesn't end up being merged, then I can revert the notes part of yaml2ck to my prior implementation. I have a few open questions/remarks:
|
I could be wrong, but I don't think CK supports the 9-coefficient NASA format. Rather, that format is used by the NASA CEA code and related tools.
I know @ischoegl will probably disagree with me, but I think the lack of regularity in CK files makes trying to do this with any degree of precision impossible.
If you and @kyleniemeyer agree, the copyright could be reassigned to Cantera, which would probably be the simplest solution. |
I'm actually not disagreeing here 😉 ... I think that exactly reproducing CK input (as in a round-trip conversion) is likely unnecessary. As long as |
It looks like I'll have to implement a refit procedure then. I have written one of those already, but the downside of it is that it requires scipy's optimization functions to work. This was the easiest way to solve the matrix with constraints on continuity of Cp, H, S and their 1st/2nd derivatives. Alternatively, yaml2ck could simply throw an error warning that it doesn't support NASA9.
I'd like to make it reproduce as faithfully as possible; however, I don't think it's a great use of time, hah. Right now it does preserve all comments. The logic in place is that if a comment is a single line long, assume that it's an inline comment. If it is multiple lines long, assume that the last line is an inline comment. This works reasonably well with the mechanisms I've played with. If "just preserve comments" is the prevailing opinion, I'll leave it how it is.
I have no issue with this. |
Regarding the copyright question, mostly it would be nice if the original authors (me and a few students here) could be credited in the git history, but I'm not sure if this is possible or how hard it would be. |
Yes, absolutely, credit where credit is due. There is a convention for this that GitHub recognizes, which is to add lines like |
My personal preference is that |
Everyone: what's the suggested way forward regarding Cantera/cantera#881? The implementation would work for Cantera 2.5 and enable If there's a consensus to wait for #11, I'll simply close the PR. |
Alright: while I do not see the actual conflict with #11, I closed Cantera/cantera#881. |
Now that #11 is implemented via Cantera/cantera#984, I reopened and updated Cantera/cantera#881, which now draws directly on the YAML parameters. |
@tsikes ... I believe with Cantera/cantera#1031 and Cantera/cantera#1129 all YAML data are now accessible from within Cantera, so I believe everything should be ready for adding |
@ischoegl That's great. I'll take a look at it. |
@ischoegl I've updated yaml2ck to use Cantera/cantera#1031 and Cantera/cantera#1129. I've done a few tests with a mock mechanism to go from CK to YAML and back. Few notes:
|
@tsikes That’s great to hear! Per prior discussion, it would be great if you were willing to add the converter to Cantera. So I hope to see a PR soon! |
Closed via Cantera/cantera#1286 |
Dear @tsikes I tried to compile the soln2ck that you provided using python and add this command to it gas= ct.Solution('gri30-reduced-40-reaction.yaml') I get the following msg: PS C:\Users\DELL\Desktop\python-folder\Mechanism\propane> & C:/Users/DELL/AppData/Local/Programs/Python/Python310/python.exe c:/Users/DELL/Desktop/python-folder/Mechanism/propane/soln2ck.py InputFileError thrown by Kinetics::checkDuplicates:
PS C:\Users\DELL\Desktop\python-folder\Mechanism\propane> Any help with this error? I tried Another option pymars --convert -m model.cti but I got this msg: #!/bin/sh -- coding: utf-8 --import re from pymars.main import main if name == 'main': So please if you have any suggestion say me it Thanks |
@khaledcomb If you have questions about using Cantera, please direct them to our Google Group at https://groups.google.com/g/cantera-users instead of posting on closed GitHub issues. Thank you! |
Thank you |
Can you please adivise how to use this script. The proper procedure to use this a script as stand alone would be good. Thank you! |
Please direct questions to the Cantera Users' Group. |
Abstract
As we all know the Chemkin format is ubiquitous in chemical kinetics simulations. There are a number of reasons that it would be beneficial for Cantera to be able to export into this format from being able to export a modified reaction mechanism for use by the community to being able to use with CFD software.
Motivation
Describe the need for the work being done:
Description
My code builds off of soln2ck from Kyle Niemeyer's pyMARS. In it I have added additional functionality of printing notes from a yaml style input file, a few bug fixes, and improved formatting. I use this function to output modified kinetics mechanisms that have been optimized to experiments. I have seen this functionality requested before and think that a unified approach will help more people adopt Cantera in the community.
Alternatives
I have considered outputting to the yaml format; however, this lacks the compatibility that I have mentioned.
References
My version of soln2ck
The text was updated successfully, but these errors were encountered: