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

Created a sample ThermoPhase.pyx #823

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions interfaces/cython/cantera/sample_wrapper/ThermoPhase.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This is a sample cython code that contains a sample wrapper for the function "setState_PX" in class "ThermoPhase" in namespace "Cantera".
# I have made this wrapper assuming we would pass a third parameter (datatype = string) in the function containing which units we want, which by default would be SI unit(Pascal(Pa) in this case).
# Right now I have added support for only atm and Pa and will extend to other Methods, Classes and Units once this sample is approved

cdef extern from "ThermoPhase.h" namespace "Cantera":
cdef cppclass ThermoPhase:
ThermoPhase()
virtual void setState_PX(doublereal p, doublereal* x);

cdef class PyThermoPhase:
cdef ThermoPhase *thisptr # hold a C++ instance which we're wrapping
def __cinit__(self):
self.thisptr = new ThermoPhase()
def __dealloc__(self):
del self.thisptr
def setState_PX(self, doublereal p, doublereal* x, string units)
if units == "atm": # if the user entered his input in atm(atmosphere)
return self.thisptr.setState_PX(p*101325,x)
else # in all other cases we assume it to be Pa(Pascal)
return self.thisptr.setState_PX(p,x)