-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
Add element weights interface #314
Add element weights interface #314
Conversation
Including deuterium and tritium in the list of elements starts to make things a bit messy in several locations. I wonder if they should be moved into a separate list for named isotopes? |
OK, so I pushed a few more commits here, and I think its pretty close to working how I want it to now. In Python, the intended interface is to use the
will all give an object with the information about argon. I think I will probably delete the other functions to get this information. The only thing that might be nice is to be able to get a list of all the elements available in Cantera, so I need to decide on an interface for that still. I think the C++ layer should be pretty much set now though. I took out all the map interfaces and dictionary building, because it didn't seem that useful once I thought of this class. One thing I definitely need to do is add documentation, I mostly wanted to push here so that I could get this stuff on my other machines. I also need to clean up the commit history. |
@@ -10,6 +10,8 @@ | |||
|
|||
#include "cantera/base/ct_defs.h" | |||
|
|||
using namespace std; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using namespace std
should never appear in a header file, since that forces any user code which may indirectly include this header to also be using the namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remove this line, I get compiler errors for several files that indirectly include Elements.h:
include/cantera/thermo/Elements.h:115:1: error: 'string' does not name a type
string getElementSymbol(const std::string& ename);
This is on Ubuntu 14.04 with gcc 4.8.4. My cantera.conf is
python3_package = 'n'
f90_interface = 'n'
system_sundials = 'n'
How should I handle that? You said you couldn't reproduce the error, but this is definitely repeatable for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This SO answer says to add the qualifier just in the header file. Is that correct then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. In the header file you need to use the fully qualified name,
then in the cpp file you can have the 'using namespace' and use the
unqualified names.
On Wed, Dec 23, 2015, 3:14 AM Bryan W. Weber notifications@github.com
wrote:
In include/cantera/thermo/Elements.h
#314 (comment):@@ -10,6 +10,8 @@
#include "cantera/base/ct_defs.h"
+using namespace std;
This SO answer http://stackoverflow.com/a/5527669/2449192 says to add
the qualifier just in the header file. Is that correct then?—
Reply to this email directly or view it on GitHub
https://github.com/Cantera/cantera/pull/314/files#r48255824.
I like the more object-oriented interface. |
bf6689c
to
c85f765
Compare
OK I think this is pretty much finished now; at least, its working like I want it to. Please let me know any other fixes/changes! Thank you for all your comments already. |
c85f765
to
58b9665
Compare
The following behavior is probably not desirable: >>> foo = ct.Element('Carbon')
>>> foo.name
'calcium' |
That does seem less than desirable... One way to fix this is to define two methods instead of one for the string lookup, one for the name and one for the symbol, and if users specify a string they have to specify if its the name or symbol:
Then the string lowercasing can be done in Python. Alternately, would there be any problem with checking the length of the input, and comparing inputs longer than 2 characters only to the element names? I'm not sure what the input to that function is expected to be (for instance, if a user is supposed to be allowed to pass in a string with only the first two characters filled and the rest blank, that would be a problem for this method). Finally, the last fix I can think of is to switch the order the checking is done so the whole string is checked against the whole list of names first, then the first couple of characters are checked against the list of symbols. That would be slower though. |
I think this would be my preferred solution: speth/cantera@76f63b8 This also makes the element name checks case insensitive, and changes a couple of stylistic things. You can merge these changes into your existing commits if you like. |
Deprecate LookupWtElements. Also split the atomic weights database into one for named elements and for named isotopes.
Add functions to get the atomic number, name, symbol, and weight of elements looked up by the atomic number, name, or symbol.
Also make check for element names case-insensitive.
…tring splitting method
5bf27da
to
c72f1b6
Compare
This PR adds an interface to the
LookupWtElements
C++ function (defined insrc/thermo/Elements.cpp
) to look up element weights by name, symbol, or atomic number. This is my first work in Cython, so recommendations and improvements are definitely welcome.There is also a commit here (labeled
BROKEN
) that contains some commented out code because it causes a compiler error related to thecompositionMap
. I'm trying to add some way to return the element'sstruct
as something that can be turned into a dictionary in Python, with either the symbol or the name as the dictionary index. Unfortunately, my attempt to copy the way thatgetMoleFractionsByName
works didn't work here. Any help is appreciated.Finally, I think it would be good to add a case-normalization somewhere in here, so the user can get the element regardless of the case of the name or symbol they type. I could do that in C++ but its ugly and involves defining a bunch of temporary strings; or I could do that in Python and make it prettier but only applicable to the Python interface. Any preference?