Skip to content

Commit

Permalink
[Python] Update transport constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Jul 3, 2022
1 parent 4361d1b commit 3193495
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
1 change: 1 addition & 0 deletions interfaces/cython/cantera/_cantera.pxd
Expand Up @@ -255,6 +255,7 @@ cdef extern from "cantera/base/Solution.h" namespace "Cantera":
void setKinetics(shared_ptr[CxxKinetics])
shared_ptr[CxxTransport] transport()
void setTransport(shared_ptr[CxxTransport])
void setTransport(const string&) except +translate_exception
CxxAnyMap parameters(cbool) except +translate_exception
size_t nAdjacent()
shared_ptr[CxxSolution] adjacent(size_t)
Expand Down
30 changes: 20 additions & 10 deletions interfaces/cython/cantera/base.pyx
Expand Up @@ -82,7 +82,7 @@ cdef class _SolutionBase:
cxx_soln.get().setSource(stringify("none"))
cxx_soln.get().setThermo(newThermo(stringify("none")))
cxx_soln.get().setKinetics(newKinetics(stringify("none")))
cxx_soln.get().setTransport(newTransport(NULL, stringify("none")))
cxx_soln.get().setTransport(stringify("none"))
_assign_Solution(self, cxx_soln, True)
self._selected_species = np.ndarray(0, dtype=np.uint64)

Expand Down Expand Up @@ -119,19 +119,18 @@ cdef class _SolutionBase:
if isinstance(infile, PurePath):
infile = str(infile)

# Transport model: "" is a sentinel value to use the default model
transport = kwargs.get("transport_model", "")

# Parse YAML input
if infile or yaml:
# Transport model: "" is a sentinel value to use the default model
transport_model = kwargs.get("transport_model", "")
self._init_yaml(infile, name, adjacent, yaml, transport_model)
self._init_yaml(infile, name, adjacent, yaml, transport)
self._selected_species = np.ndarray(0, dtype=np.uint64)
return

else:
# Assign base and set managers to NULL
_assign_Solution(self, CxxNewSolution(), True)
self._init_parts(thermo, species, kinetics, adjacent, reactions)

# Assign base and set managers
_assign_Solution(self, CxxNewSolution(), True)
self._init_parts(thermo, species, kinetics, transport, adjacent, reactions)
self._selected_species = np.ndarray(0, dtype=np.uint64)

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -239,9 +238,13 @@ cdef class _SolutionBase:
if not isinstance(self, Kinetics):
soln.get().setKinetics(newKinetics(stringify("none")))

# Transport
if not isinstance(self, Transport):
soln.get().setTransport(stringify("none"))

_assign_Solution(self, soln, reset_adjacent)

def _init_parts(self, thermo, species, kinetics, adjacent, reactions):
def _init_parts(self, thermo, species, kinetics, transport, adjacent, reactions):
"""
Instantiate a set of new Cantera C++ objects based on a string defining
the model type and a list of Species objects.
Expand Down Expand Up @@ -274,6 +277,13 @@ cdef class _SolutionBase:
self.kinetics.addReaction(reaction._reaction, False)
self.kinetics.resizeReactions()

if not transport:
transport = "none"

if isinstance(self, Transport):
self.base.setTransport(stringify(transport))
self.transport = self.base.transport().get()

property input_data:
"""
Get input data corresponding to the current state of this Solution,
Expand Down
13 changes: 1 addition & 12 deletions interfaces/cython/cantera/transport.pyx
Expand Up @@ -170,17 +170,6 @@ cdef class Transport(_SolutionBase):
Not all transport properties are implemented in all transport models.
"""
def __init__(self, *args, **kwargs):
if self.transport == NULL and kwargs.get("init", True):
# @todo ... after removal of CTI/XML, this should be handled by base.pyx
if 'transport_model' not in kwargs:
self.base.setTransport(newTransport(self.thermo, stringify("default")))
else:
model = kwargs['transport_model']
if not model:
model = 'None'
self.base.setTransport(newTransport(self.thermo, stringify(model)))
self.transport = self.base.transport().get()

super().__init__(*args, **kwargs)
if self._references is None:
raise ValueError(
Expand Down Expand Up @@ -264,7 +253,7 @@ cdef class Transport(_SolutionBase):

property multi_diff_coeffs:
"""Multicomponent diffusion coefficients, D[i,j], the diffusion
coefficient for species i due to concentration gradients in
coefficient for species i due to concentration gradients in
species j [m**2/s]."""
def __get__(self):
return get_transport_2d(self, tran_getMultiDiffCoeffs)
Expand Down

0 comments on commit 3193495

Please sign in to comment.