Skip to content

Commit 882182d

Browse files
committed
[Python] Make reactor 'name' arguments consistent
1 parent 266f862 commit 882182d

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

interfaces/cython/cantera/reactor.pyx

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ cdef class ReactorBase:
1616
Common base class for reactors and reservoirs.
1717
"""
1818
reactor_type = "none"
19-
def __cinit__(self, _SolutionBase contents=None, name=None, *, **kwargs):
19+
def __cinit__(self, _SolutionBase contents=None, *, name="(none)", **kwargs):
2020
if isinstance(contents, _SolutionBase):
2121
self._reactor = newReactor(stringify(self.reactor_type),
2222
contents._base, stringify(name))
@@ -26,8 +26,8 @@ cdef class ReactorBase:
2626
self._reactor.get().setName(stringify(name))
2727
self.rbase = self._reactor.get()
2828

29-
def __init__(self, _SolutionBase contents=None, name=None, *, volume=None,
30-
node_attr=None):
29+
def __init__(self, _SolutionBase contents=None, *,
30+
name="(none)", volume=None, node_attr=None):
3131
self._inlets = []
3232
self._outlets = []
3333
self._walls = []
@@ -198,16 +198,19 @@ cdef class Reactor(ReactorBase):
198198
def __cinit__(self, *args, **kwargs):
199199
self.reactor = <CxxReactor*>(self.rbase)
200200

201-
def __init__(self, contents=None, *, name=None, energy='on', group_name="", **kwargs):
201+
def __init__(self, contents=None, *,
202+
name="(none)", energy='on', group_name="", **kwargs):
202203
"""
203204
:param contents:
204205
Reactor contents. If not specified, the reactor is initially empty.
205206
In this case, call `insert` to specify the contents. Providing valid
206207
contents will become mandatory after Cantera 3.1.
207208
:param name:
208-
Used only to identify this reactor in output. If not specified,
209-
defaults to ``'Reactor_n'``, where *n* is an integer assigned in
210-
the order `Reactor` objects are created.
209+
Name string. If not specified, the name initially defaults to ``'(none)'``
210+
and changes to ``'<reactor_type>_n'`` when `Reactor` objects are installed
211+
within a `ReactorNet`. For the latter, ``<reactor_type>`` is the type of
212+
the reactor and *n* is an integer assigned in the order reactors are
213+
installed.
211214
:param energy:
212215
Set to ``'on'`` or ``'off'``. If set to ``'off'``, the energy
213216
equation is not solved, and the temperature is held at its
@@ -234,7 +237,7 @@ cdef class Reactor(ReactorBase):
234237
>>> r3 = Reactor(name='adiabatic_reactor', contents=gas)
235238
236239
"""
237-
super().__init__(contents, name, **kwargs)
240+
super().__init__(contents, name=name, **kwargs)
238241

239242
if energy == 'off':
240243
self.energy_enabled = False
@@ -787,8 +790,10 @@ cdef class ReactorSurface:
787790
Represents a surface in contact with the contents of a reactor.
788791
789792
:param name:
790-
Name string. If omitted, the name is ``'ReactorSurface_n'``, where ``'n'``
791-
is an integer assigned in the order reactor surfaces are created.
793+
Name string. If not specified, the name initially defaults to ``'(none)'`` and
794+
changes to ``'ReactorSurface_n'`` when when associated `Reactor` objects are
795+
installed within a `ReactorNet`. For the latter, *n* is an integer assigned in
796+
the order reactor surfaces are detected.
792797
:param kin:
793798
The `Kinetics` or `Interface` object representing reactions on this
794799
surface.
@@ -803,14 +808,14 @@ cdef class ReactorSurface:
803808
.. versionadded:: 3.1
804809
Added the ``node_attr`` parameter.
805810
"""
806-
def __cinit__(self, *args, **kwargs):
807-
name = kwargs.get("name")
811+
def __cinit__(self, *args, name="(none)", **kwargs):
808812
self.surface = new CxxReactorSurface(stringify(name))
809813

810814
def __dealloc__(self):
811815
del self.surface
812816

813-
def __init__(self, kin=None, Reactor r=None, *, name=None, A=None, node_attr=None):
817+
def __init__(self, kin=None, Reactor r=None, *,
818+
name="(none)", A=None, node_attr=None):
814819
if kin is not None:
815820
self.kinetics = kin
816821
if r is not None:
@@ -946,21 +951,23 @@ cdef class WallBase:
946951
Common base class for walls.
947952
"""
948953
wall_type = "none"
949-
def __cinit__(self, *args, **kwargs):
950-
name = kwargs.get("name")
954+
def __cinit__(self, *args, name="(none)", **kwargs):
951955
self._wall = newWall(stringify(self.wall_type), stringify(name))
952956
self.wall = self._wall.get()
953957

954-
def __init__(self, left, right, *, name=None, A=None, K=None, U=None,
958+
def __init__(self, left, right, *, name="(none)", A=None, K=None, U=None,
955959
Q=None, velocity=None, edge_attr=None):
956960
"""
957961
:param left:
958962
Reactor or reservoir on the left. Required.
959963
:param right:
960964
Reactor or reservoir on the right. Required.
961965
:param name:
962-
Name string. If omitted, the name is ``'Wall_n'``, where ``'n'``
963-
is an integer assigned in the order walls are created.
966+
Name string. If not specified, the name initially defaults to ``'(none)'``
967+
and changes to ``'<wall_type>_n'`` when when associated `Reactor` objects
968+
are installed within a `ReactorNet`. For the latter, ``<wall_type>`` is
969+
the type of the wall and *n* is an integer assigned in the order walls are
970+
detected.
964971
:param A:
965972
Wall area [m^2]. Defaults to 1.0 m^2.
966973
:param K:
@@ -1219,12 +1226,11 @@ cdef class FlowDevice:
12191226
pressure between the upstream and downstream reactors.
12201227
"""
12211228
flowdevice_type = "none"
1222-
def __cinit__(self, *args, **kwargs):
1223-
name = kwargs.get("name")
1229+
def __cinit__(self, *args, name="(none)", **kwargs):
12241230
self._dev = newFlowDevice(stringify(self.flowdevice_type), stringify(name))
12251231
self.dev = self._dev.get()
12261232

1227-
def __init__(self, upstream, downstream, *, name=None, edge_attr=None):
1233+
def __init__(self, upstream, downstream, *, name="(none)", edge_attr=None):
12281234
assert self.dev != NULL
12291235
self._rate_func = None
12301236
self.edge_attr = edge_attr or {}
@@ -1390,7 +1396,7 @@ cdef class MassFlowController(FlowDevice):
13901396
"""
13911397
flowdevice_type = "MassFlowController"
13921398

1393-
def __init__(self, upstream, downstream, *, name=None, mdot=1., **kwargs):
1399+
def __init__(self, upstream, downstream, *, name="(none)", mdot=1., **kwargs):
13941400
super().__init__(upstream, downstream, name=name, **kwargs)
13951401
self.mass_flow_rate = mdot
13961402

@@ -1464,7 +1470,7 @@ cdef class Valve(FlowDevice):
14641470
"""
14651471
flowdevice_type = "Valve"
14661472

1467-
def __init__(self, upstream, downstream, *, name=None, K=1., **kwargs):
1473+
def __init__(self, upstream, downstream, *, name="(none)", K=1., **kwargs):
14681474
super().__init__(upstream, downstream, name=name, **kwargs)
14691475
if isinstance(K, _numbers.Real):
14701476
self.valve_coeff = K
@@ -1507,14 +1513,8 @@ cdef class PressureController(FlowDevice):
15071513
"""
15081514
flowdevice_type = "PressureController"
15091515

1510-
def __init__(self, upstream, downstream, *,
1511-
name=None, primary=None, K=1., **kwargs):
1512-
if "master" in kwargs:
1513-
warnings.warn(
1514-
"PressureController: The 'master' keyword argument is deprecated; "
1515-
"use 'primary' instead.", DeprecationWarning)
1516-
primary = kwargs["master"]
1517-
super().__init__(upstream, downstream, name=name, **kwargs)
1516+
def __init__(self, upstream, downstream, *, name="(none)", primary=None, K=1.):
1517+
super().__init__(upstream, downstream, name=name)
15181518
if primary is not None:
15191519
self.primary = primary
15201520
if isinstance(K, _numbers.Real):

0 commit comments

Comments
 (0)