Skip to content

Commit f351e0f

Browse files
authored
Merge pull request #12 from pathsim/update-port-labels-latest-pathsim-api
Update port labels latest pathsim api
2 parents c8dbbd1 + 0c3a553 commit f351e0f

11 files changed

Lines changed: 56 additions & 37 deletions

File tree

.DS_Store

-8 KB
Binary file not shown.

docs/.DS_Store

-6 KB
Binary file not shown.

docs/source/.DS_Store

-6 KB
Binary file not shown.

docs/source/modules/.DS_Store

-6 KB
Binary file not shown.

src/.DS_Store

-6 KB
Binary file not shown.

src/pathsim_chem/.DS_Store

-6 KB
Binary file not shown.

src/pathsim_chem/tritium/.DS_Store

-6 KB
Binary file not shown.

src/pathsim_chem/tritium/bubbler.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from pathsim.blocks.dynsys import DynamicalSystem
1212
from pathsim.events.schedule import ScheduleList
13+
from pathsim.utils.register import Register
1314

1415

1516
# BLOCK DEFIINITIONS ====================================================================
@@ -92,18 +93,6 @@ class Bubbler4(DynamicalSystem):
9293
of a full vial with an empty one.
9394
"""
9495

95-
_port_map_out = {
96-
"vial1": 0,
97-
"vial2": 1,
98-
"vial3": 2,
99-
"vial4": 3,
100-
"sample_out": 4,
101-
}
102-
_port_map_in = {
103-
"sample_in_soluble": 0,
104-
"sample_in_insoluble": 1,
105-
}
106-
10796
def __init__(
10897
self,
10998
conversion_efficiency=0.9,
@@ -149,7 +138,30 @@ def _fn_a(x, u, t):
149138
return np.hstack([x, sample_out])
150139

151140
#initialization just like `DynamicalSystem` block
152-
super().__init__(func_dyn=_fn_d, func_alg=_fn_a, initial_value=np.zeros(4))
141+
super().__init__(
142+
func_dyn=_fn_d,
143+
func_alg=_fn_a,
144+
initial_value=np.zeros(4),
145+
)
146+
147+
# define port maps
148+
self.inputs = Register(
149+
size=2,
150+
mapping={
151+
"sample_in_soluble": 0,
152+
"sample_in_insoluble": 1,
153+
},
154+
)
155+
self.outputs = Register(
156+
size=5,
157+
mapping={
158+
"vial1": 0,
159+
"vial2": 1,
160+
"vial3": 2,
161+
"vial4": 3,
162+
"sample_out": 4,
163+
},
164+
)
153165

154166
#create internal vial reset events
155167
self._create_reset_events()

src/pathsim_chem/tritium/residencetime.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy as np
1010

1111
from pathsim.blocks.dynsys import DynamicalSystem
12-
12+
from pathsim.utils.register import Register
1313

1414
# BLOCKS ================================================================================
1515

@@ -50,30 +50,35 @@ class ResidenceTime(DynamicalSystem):
5050

5151
def __init__(self, tau=1, betas=None, gammas=None, initial_value=0, source_term=0):
5252

53-
#input validation
53+
# input validation
5454
if np.isclose(tau, 0):
5555
raise ValueError(f"'tau' must be nonzero but is {tau}")
5656

57-
#time constant and input/output weights
57+
# time constant and input/output weights
5858
self.tau = tau
5959
self.betas = 1 if betas is None else np.array(betas)
6060
self.gammas = 1 if gammas is None else np.array(gammas)
6161
self.source_term = source_term
6262

63-
#rhs of residence time ode
63+
# rhs of residence time ode
6464
def _fn_d(x, u, t):
6565
return -x/self.tau + self.source_term + sum(self.betas*u)
6666

67-
#jacobian of rhs wrt x
67+
# jacobian of rhs wrt x
6868
def _jc_d(x, u, t):
6969
return -1/self.tau
7070

71-
#output function of residence time ode
71+
# output function of residence time ode
7272
def _fn_a(x, u, t):
7373
return self.gammas * x
7474

75-
#initialization just like `DynamicalSystem` block
76-
super().__init__(func_dyn=_fn_d, jac_dyn=_jc_d, func_alg=_fn_a, initial_value=initial_value)
75+
# initialization just like `DynamicalSystem` block
76+
super().__init__(
77+
func_dyn=_fn_d,
78+
jac_dyn=_jc_d,
79+
func_alg=_fn_a,
80+
initial_value=initial_value,
81+
)
7782

7883

7984
class Process(ResidenceTime):
@@ -112,11 +117,11 @@ class Process(ResidenceTime):
112117
constant source term / generation term of the process
113118
"""
114119

115-
#max number of ports
116-
_n_out_max = 2
117-
118-
#maps for input and output port labels
119-
_port_map_out = {"x": 0, "x/tau": 1}
120-
121120
def __init__(self, tau=1, initial_value=0, source_term=0):
122121
super().__init__(tau, 1, [1, 1/tau], initial_value, source_term)
122+
123+
# define output port maps based on fractions
124+
self.outputs = Register(
125+
size=2,
126+
mapping={"x": 0, "x/tau": 1}
127+
)

src/pathsim_chem/tritium/splitter.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import numpy as np
1010

1111
from pathsim.blocks.function import Function
12+
from pathsim.utils.register import Register
1213

1314

1415
# BLOCKS ================================================================================
@@ -28,22 +29,23 @@ class Splitter(Function):
2829
must sum up to one
2930
"""
3031

31-
#max number of ports
32-
_n_in_max = 1
33-
34-
#maps for input and output port labels
35-
_port_map_in = {"in": 0}
36-
3732
def __init__(self, fractions=None):
3833

3934
self.fractions = np.ones(1) if fractions is None else np.array(fractions)
4035

41-
#input validation
36+
# input validation
4237
if not np.isclose(sum(self.fractions), 1):
4338
raise ValueError(f"'fractions' must sum to one and not {sum(self.fractions)}")
4439

45-
#initialize like `Function` block
40+
# initialize like `Function` block
4641
super().__init__(func=lambda u: self.fractions*u)
4742

48-
#dynamically define output port map based on fractions
49-
self._port_map_out = {f"out {fr}": i for i, fr in enumerate(self.fractions)}
43+
# define port maps based on fractions
44+
self.inputs = Register(
45+
size=1,
46+
mapping={"in": 0}
47+
)
48+
self.outputs = Register(
49+
size=len(self.fractions),
50+
mapping={f"out {fr}": i for i, fr in enumerate(self.fractions)}
51+
)

0 commit comments

Comments
 (0)