[Python] Added basic implementation of Func1 and its children
This commit is contained in:
parent
dfb18b461e
commit
21169b3a38
3 changed files with 33 additions and 0 deletions
|
|
@ -46,6 +46,15 @@ cdef extern from "cantera/equil/MultiPhase.h" namespace "Cantera":
|
|||
void setPressure(double)
|
||||
double pressure()
|
||||
|
||||
cdef extern from "cantera/numerics/Func1.h":
|
||||
cdef cppclass CxxFunc1 "Cantera::Func1":
|
||||
CxxFunc1()
|
||||
double eval(double)
|
||||
string write(string)
|
||||
|
||||
cdef cppclass CxxSin1 "Cantera::Sin1":
|
||||
CxxSin1(double)
|
||||
|
||||
cdef extern from "cantera/thermo/ThermoFactory.h" namespace "Cantera":
|
||||
cdef CxxThermoPhase* newPhase(string, string) except +
|
||||
cdef CxxThermoPhase* newPhase(XML_Node&) except +
|
||||
|
|
@ -67,3 +76,6 @@ cdef class _SolutionBase:
|
|||
cdef class Mixture:
|
||||
cdef CxxMultiPhase* mix
|
||||
cdef list _phases
|
||||
|
||||
cdef class Func1:
|
||||
cdef CxxFunc1* func
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ from _cantera cimport *
|
|||
|
||||
include "utils.pyx"
|
||||
include "constants.pyx"
|
||||
include "func1.pyx"
|
||||
|
||||
include "base.pyx"
|
||||
include "thermo.pyx"
|
||||
|
|
|
|||
20
interfaces/cython/cantera/func1.pyx
Normal file
20
interfaces/cython/cantera/func1.pyx
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
cdef class Func1:
|
||||
def __cinit__(self, *args, **kwargs):
|
||||
self.func = NULL # derived classes should allocate this object
|
||||
|
||||
def __dealloc__(self):
|
||||
del self.func
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
assert self.func != NULL
|
||||
|
||||
def __call__(self, t):
|
||||
return self.func.eval(t)
|
||||
|
||||
def __str__(self):
|
||||
cdef bytes s = self.func.write(stringify("t")).c_str()
|
||||
return s.decode()
|
||||
|
||||
cdef class Sin1(Func1):
|
||||
def __cinit__(self, freq):
|
||||
self.func = <CxxFunc1*>(new CxxSin1(freq))
|
||||
Loading…
Add table
Reference in a new issue