Skip to content

Commit 14fd054

Browse files
authored
Merge pull request #15 from pathsim/adapt-to-port-label-refactor
refactor the port labels to be class attributes
2 parents 5b9e1ee + 22f8f27 commit 14fd054

4 files changed

Lines changed: 37 additions & 61 deletions

File tree

src/pathsim_chem/tritium/bubbler.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ class Bubbler4(DynamicalSystem):
9393
of a full vial with an empty one.
9494
"""
9595

96+
input_port_labels = {
97+
"sample_in_soluble": 0,
98+
"sample_in_insoluble": 1,
99+
}
100+
output_port_labels = {
101+
"vial1": 0,
102+
"vial2": 1,
103+
"vial3": 2,
104+
"vial4": 3,
105+
"sample_out": 4,
106+
}
107+
96108
def __init__(
97109
self,
98110
conversion_efficiency=0.9,
@@ -144,25 +156,6 @@ def _fn_a(x, u, t):
144156
initial_value=np.zeros(4),
145157
)
146158

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-
)
165-
166159
#create internal vial reset events
167160
self._create_reset_events()
168161

src/pathsim_chem/tritium/glc.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,23 @@ class GLC(pathsim.blocks.Function):
364364
BCs: Boundary conditions type, "C-C" (Closed-Closed) or "O-C" (Open-Closed), default is "C-C"
365365
"""
366366

367+
input_port_labels = {
368+
"c_T_in": 0,
369+
"flow_l": 1,
370+
"y_T2_inlet": 2,
371+
"flow_g": 3,
372+
}
373+
output_port_labels = {
374+
"c_T_out": 0,
375+
"y_T2_out": 1,
376+
"eff": 2,
377+
"P_out": 3,
378+
"Q_l": 4,
379+
"Q_g_out": 5,
380+
"n_T_out_liquid": 6,
381+
"n_T_out_gas": 7,
382+
}
383+
367384
def __init__(
368385
self,
369386
P_in,
@@ -385,29 +402,6 @@ def __init__(
385402
}
386403
super().__init__(func=self.func)
387404

388-
self.inputs = Register(
389-
size=4,
390-
mapping={
391-
"c_T_in": 0,
392-
"flow_l": 1,
393-
"y_T2_inlet": 2,
394-
"flow_g": 3,
395-
},
396-
)
397-
self.outputs = Register(
398-
size=8,
399-
mapping={
400-
"c_T_out": 0,
401-
"y_T2_out": 1,
402-
"eff": 2,
403-
"P_out": 3,
404-
"Q_l": 4,
405-
"Q_g_out": 5,
406-
"n_T_out_liquid": 6,
407-
"n_T_out_gas": 7,
408-
},
409-
)
410-
411405
def func(self, c_T_in, flow_l, y_T2_inlet, flow_g):
412406
new_params = self.params.copy()
413407
new_params["c_T_in"] = c_T_in

src/pathsim_chem/tritium/residencetime.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,9 @@ class Process(ResidenceTime):
115115
initial value of state / initial quantity of process
116116
source_term : float
117117
constant source term / generation term of the process
118-
"""
118+
"""
119+
input_port_labels = None
120+
output_port_labels = {"x": 0, "x/tau": 1}
119121

120122
def __init__(self, tau=1, initial_value=0, source_term=0):
121-
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-
)
123+
super().__init__(tau, 1, [1, 1/tau], initial_value, source_term)

src/pathsim_chem/tritium/splitter.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class Splitter(Function):
2929
must sum up to one
3030
"""
3131

32+
input_port_labels = {"in": 0}
33+
output_port_labels = None
34+
3235
def __init__(self, fractions=None):
3336

3437
self.fractions = np.ones(1) if fractions is None else np.array(fractions)
@@ -38,14 +41,4 @@ def __init__(self, fractions=None):
3841
raise ValueError(f"'fractions' must sum to one and not {sum(self.fractions)}")
3942

4043
# initialize like `Function` block
41-
super().__init__(func=lambda u: self.fractions*u)
42-
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-
)
44+
super().__init__(func=lambda u: self.fractions*u)

0 commit comments

Comments
 (0)