atomica.model.ResidualJunctionCompartment¶
- class atomica.model.ResidualJunctionCompartment(pop, name, duration_group=None)[source]¶
Bases:
JunctionCompartment
Junction with a residual outflow
A residual outflow junction has a single additional outflow link
A TimedCompartment has a duration group by virtue of having a .parameter attribute and a flush link. A junction might belong to a duration group by having inflows and outflows exclusively from that group. However, it might not be directly attached to any timed compartments, if the connections are entirely via upstream and downstream junctions. Junctions also do not have flush links. Therefore, we record membership in the duration group by specifying the name of the parameter in the (indirect) upstream and downstream compartments.
Note that having connections to timed compartments does not itself indicate membership in the duration group - the junction is only a member if all of the upstream and downstream compartments belong to the same duration group. The duration group is determined in framework validation and stored in the framework.
Attributes
Variable code name
Return the outflow at all times
Store the name of the duration group, if the junction belongs to one
Unique identifier for the integration object
The units for the quantity, used for plotting and for validation.
Reference back to the Population containing this object
Methods
Balance junction inflows and outflows
Construct link out of this compartment
expected_duration
expected_outflow
Perform an initial junction flush
Produce a time series plot
Preallocate junction values
relink
Resolve outgoing links and convert to number
Make the variable a dependency
unlink
Update the junction at given time index
- balance(ti)[source]¶
Balance junction inflows and outflows
For a ResidualJunctionCompartment, if the outflows sum to less than 1, rather than scaling them up proportionately, the residual is assigned to the residual link.
- connect(dest, par)¶
Construct link out of this compartment
For junctions, outgoing links are normal links unless the junction belongs to a duration group. If the junction belongs to a duration group, then the output links should all be
TimedLink
instances.- Parameters:
dest – A
Compartment
instancepar – The parameter that the Link will be associated with
- Return type:
- duration_group¶
Store the name of the duration group, if the junction belongs to one
- id¶
Unique identifier for the integration object
- property name: str¶
Variable code name
This is implemented as a property method because the
id
of theVariable
is a tuple containing the population name and the variable code name, so this property method returns just the variable code name portion. That way, storage does not need to be duplicated.- Returns:
A code name
- property outflow: array¶
Return the outflow at all times
- Returns:
The sum of outgoing links at all time indices
- plot()¶
Produce a time series plot
This is a quick function to make a basic line plot of this
Variable
. Mainly intended for debugging. Production-ready plots should be generated using the plotting library functions instead- Return type:
- pop¶
Reference back to the Population containing this object
- preallocate(tvec, dt)¶
Preallocate junction values
Junction preallocation pre-fills the values with zeros, since the junction must be empty at all times.
- resolve_outflows(ti)¶
Resolve outgoing links and convert to number
For junctions, links are updated in a separate step because the logic is different - instead of the value of links coming from parameters, they come from the inflow into the junction. We cannot update the junctions in the same step as compartments because while the junction subgraphs must be acyclic, the entire system may contain cycles. Therefore it is not possible to determine a topological ordering for the entire system. The system is solvable because for normal compartments, only one transition per timestep is allowed. But regardless, this prevents using graph analysis to determine an execution order for the entire system that would allow junction computation in the same step.
- set_dynamic(**kwargs)¶
Make the variable a dependency
For Compartments and Links, this does nothing. For Characteristics and Parameters, it will set the dynamic flag, but in addition, any validation constraints e.g. a Parameter that depends on Links cannot itself be dynamic, will be enforced.
This method generally must be overloaded in derived classes e.g.
Parameter.set_dynamic()
- Return type:
- units¶
The units for the quantity, used for plotting and for validation. Note that the default
'unknown'
units are distinct to dimensionless units, which have value''
- update(ti)¶
Update the junction at given time index
For compartments the
update
methods steps them forward in time. However, for junctions the value never needs to be stepped forward, because it’s always zero. Thus, this function does nothing.