[Python/Doc] Improved documentation of sensitivity parameters
This commit is contained in:
parent
12f3b2739c
commit
5b7a8d1b4e
1 changed files with 53 additions and 0 deletions
53
interfaces/cython/cantera/reactor.pyx
Normal file → Executable file
53
interfaces/cython/cantera/reactor.pyx
Normal file → Executable file
|
|
@ -194,6 +194,12 @@ cdef class Reactor(ReactorBase):
|
||||||
self.reactor.setEnergy(int(value))
|
self.reactor.setEnergy(int(value))
|
||||||
|
|
||||||
def add_sensitivity_reaction(self, m):
|
def add_sensitivity_reaction(self, m):
|
||||||
|
"""
|
||||||
|
Specifies that the sensitivity of the state variables with respect to
|
||||||
|
reaction *m* should be computed. *m* is the 0-based reaction index.
|
||||||
|
The reactor must be part of a network first. Specifying the same
|
||||||
|
reaction more than one time raises an exception.
|
||||||
|
"""
|
||||||
self.reactor.addSensitivityReaction(m)
|
self.reactor.addSensitivityReaction(m)
|
||||||
|
|
||||||
def component_index(self, name):
|
def component_index(self, name):
|
||||||
|
|
@ -812,12 +818,40 @@ cdef class ReactorNet:
|
||||||
self.net.setVerbose(v)
|
self.net.setVerbose(v)
|
||||||
|
|
||||||
def sensitivity(self, species, int p, int r=0):
|
def sensitivity(self, species, int p, int r=0):
|
||||||
|
"""
|
||||||
|
Returns the sensitivity of the solution variable *species* in reactor
|
||||||
|
*r* with respect to the parameter *p*. Returns an empty array until the
|
||||||
|
first time step is taken. See `ReactorNet.component_index` and
|
||||||
|
`sensitivities` to determine the integer index for the variables.
|
||||||
|
Otherwise, a string can be passed into *species* to automatically look
|
||||||
|
up the index.
|
||||||
|
"""
|
||||||
|
|
||||||
if isinstance(species, int):
|
if isinstance(species, int):
|
||||||
return self.net.sensitivity(species,p)
|
return self.net.sensitivity(species,p)
|
||||||
elif isinstance(species, (str, unicode)):
|
elif isinstance(species, (str, unicode)):
|
||||||
return self.net.sensitivity(stringify(species), p, r)
|
return self.net.sensitivity(stringify(species), p, r)
|
||||||
|
|
||||||
def sensitivities(self):
|
def sensitivities(self):
|
||||||
|
"""
|
||||||
|
Returns the senstivities of all of the solution variables with respect
|
||||||
|
to all of the registered parameters. The sensitivities are returned in
|
||||||
|
an array with dimensions *(n_vars, n_sensitivity_params)*, unless no
|
||||||
|
timesteps have been taken, in which case the shape is
|
||||||
|
*(0, n_sensitivity_params)*. The order of the variables (i.e. rows) is:
|
||||||
|
|
||||||
|
`Reactor` or `IdealGasReactor`:
|
||||||
|
|
||||||
|
- 0 - mass
|
||||||
|
- 1 - volume
|
||||||
|
- 2 - internal energy or temperature
|
||||||
|
- 3+ - mass fractions of the species
|
||||||
|
|
||||||
|
`ConstPressureReactor` or `IdealGasConstPressureReactor`:
|
||||||
|
- 0 - mass
|
||||||
|
- 1 - enthalpy or temperature
|
||||||
|
- 2+ - mass fractions of the species
|
||||||
|
"""
|
||||||
cdef np.ndarray[np.double_t, ndim=2] data = \
|
cdef np.ndarray[np.double_t, ndim=2] data = \
|
||||||
np.empty((self.n_vars, self.n_sensitivity_params))
|
np.empty((self.n_vars, self.n_sensitivity_params))
|
||||||
cdef int p,k
|
cdef int p,k
|
||||||
|
|
@ -827,12 +861,31 @@ cdef class ReactorNet:
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def sensitivity_parameter_name(self, int p):
|
def sensitivity_parameter_name(self, int p):
|
||||||
|
"""
|
||||||
|
Name of the sensitivity parameter with index *p*.
|
||||||
|
"""
|
||||||
return pystr(self.net.sensitivityParameterName(p))
|
return pystr(self.net.sensitivityParameterName(p))
|
||||||
|
|
||||||
property n_sensitivity_params:
|
property n_sensitivity_params:
|
||||||
|
"""
|
||||||
|
The number of registered sensitivity parameters.
|
||||||
|
"""
|
||||||
def __get__(self):
|
def __get__(self):
|
||||||
return self.net.nparams()
|
return self.net.nparams()
|
||||||
|
|
||||||
property n_vars:
|
property n_vars:
|
||||||
|
"""
|
||||||
|
The number of state variables in the system. This is the sum of the
|
||||||
|
number of variables for each `Reactor` and `Wall` in the system.
|
||||||
|
Equal to:
|
||||||
|
|
||||||
|
`Reactor` and `IdealGasReactor`: `n_species` + 3 (mass, volume,
|
||||||
|
internal energy or temperature).
|
||||||
|
|
||||||
|
`ConstPressureReactor` and `IdealGasConstPressureReactor`:
|
||||||
|
`n_species` + 2 (mass, enthalpy or temperature).
|
||||||
|
|
||||||
|
`Wall`: number of surface species
|
||||||
|
"""
|
||||||
def __get__(self):
|
def __get__(self):
|
||||||
return self.net.neq()
|
return self.net.neq()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue