Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
Binary file removed docs/.DS_Store
Binary file not shown.
Binary file removed docs/source/.DS_Store
Binary file not shown.
Binary file removed docs/source/modules/.DS_Store
Binary file not shown.
Binary file removed src/.DS_Store
Binary file not shown.
Binary file removed src/pathsim_chem/.DS_Store
Binary file not shown.
Binary file removed src/pathsim_chem/tritium/.DS_Store
Binary file not shown.
38 changes: 25 additions & 13 deletions src/pathsim_chem/tritium/bubbler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from pathsim.blocks.dynsys import DynamicalSystem
from pathsim.events.schedule import ScheduleList
from pathsim.utils.register import Register


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

_port_map_out = {
"vial1": 0,
"vial2": 1,
"vial3": 2,
"vial4": 3,
"sample_out": 4,
}
_port_map_in = {
"sample_in_soluble": 0,
"sample_in_insoluble": 1,
}

def __init__(
self,
conversion_efficiency=0.9,
Expand Down Expand Up @@ -149,7 +138,30 @@ def _fn_a(x, u, t):
return np.hstack([x, sample_out])

#initialization just like `DynamicalSystem` block
super().__init__(func_dyn=_fn_d, func_alg=_fn_a, initial_value=np.zeros(4))
super().__init__(
func_dyn=_fn_d,
func_alg=_fn_a,
initial_value=np.zeros(4),
)

# define port maps
self.inputs = Register(
size=2,
mapping={
"sample_in_soluble": 0,
"sample_in_insoluble": 1,
},
)
self.outputs = Register(
size=5,
mapping={
"vial1": 0,
"vial2": 1,
"vial3": 2,
"vial4": 3,
"sample_out": 4,
},
)

#create internal vial reset events
self._create_reset_events()
Expand Down
33 changes: 19 additions & 14 deletions src/pathsim_chem/tritium/residencetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np

from pathsim.blocks.dynsys import DynamicalSystem

from pathsim.utils.register import Register

# BLOCKS ================================================================================

Expand Down Expand Up @@ -50,30 +50,35 @@ class ResidenceTime(DynamicalSystem):

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

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

#time constant and input/output weights
# time constant and input/output weights
self.tau = tau
self.betas = 1 if betas is None else np.array(betas)
self.gammas = 1 if gammas is None else np.array(gammas)
self.source_term = source_term

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

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

#output function of residence time ode
# output function of residence time ode
def _fn_a(x, u, t):
return self.gammas * x

#initialization just like `DynamicalSystem` block
super().__init__(func_dyn=_fn_d, jac_dyn=_jc_d, func_alg=_fn_a, initial_value=initial_value)
# initialization just like `DynamicalSystem` block
super().__init__(
func_dyn=_fn_d,
jac_dyn=_jc_d,
func_alg=_fn_a,
initial_value=initial_value,
)


class Process(ResidenceTime):
Expand Down Expand Up @@ -112,11 +117,11 @@ class Process(ResidenceTime):
constant source term / generation term of the process
"""

#max number of ports
_n_out_max = 2

#maps for input and output port labels
_port_map_out = {"x": 0, "x/tau": 1}

def __init__(self, tau=1, initial_value=0, source_term=0):
super().__init__(tau, 1, [1, 1/tau], initial_value, source_term)

# define output port maps based on fractions
self.outputs = Register(
size=2,
mapping={"x": 0, "x/tau": 1}
)
22 changes: 12 additions & 10 deletions src/pathsim_chem/tritium/splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import numpy as np

from pathsim.blocks.function import Function
from pathsim.utils.register import Register


# BLOCKS ================================================================================
Expand All @@ -28,22 +29,23 @@ class Splitter(Function):
must sum up to one
"""

#max number of ports
_n_in_max = 1

#maps for input and output port labels
_port_map_in = {"in": 0}

def __init__(self, fractions=None):

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

#input validation
# input validation
if not np.isclose(sum(self.fractions), 1):
raise ValueError(f"'fractions' must sum to one and not {sum(self.fractions)}")

#initialize like `Function` block
# initialize like `Function` block
super().__init__(func=lambda u: self.fractions*u)

#dynamically define output port map based on fractions
self._port_map_out = {f"out {fr}": i for i, fr in enumerate(self.fractions)}
# define port maps based on fractions
self.inputs = Register(
size=1,
mapping={"in": 0}
)
self.outputs = Register(
size=len(self.fractions),
mapping={f"out {fr}": i for i, fr in enumerate(self.fractions)}
)
Binary file removed tests/.DS_Store
Binary file not shown.