Skip to content

Commit 89c22f2

Browse files
committed
update port maps through Register for Splitter
1 parent c8dbbd1 commit 89c22f2

9 files changed

Lines changed: 12 additions & 10 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/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+
)

tests/.DS_Store

-6 KB
Binary file not shown.

0 commit comments

Comments
 (0)