ProcessSimulator
This module is for simulating complex processes with different reactor combinations. It provides a series of reactors, settlers and connection elements to be used for building process configurations.
Index
ModelingToolkit.t
BioChemicalTreatment.ProcessSimulator.FlowElement
BioChemicalTreatment.ProcessSimulator.MTKStandardLibraryInterface
BioChemicalTreatment.ProcessSimulator.Process
BioChemicalTreatment.ProcessSimulator.ProcessDiagram
BioChemicalTreatment.ProcessSimulator.Reactor
BioChemicalTreatment.ProcessSimulator.add_default_process
BioChemicalTreatment.ProcessSimulator.add_default_state_mapping
BioChemicalTreatment.ProcessSimulator.cleanup!
BioChemicalTreatment.ProcessSimulator.clear_default_processes
BioChemicalTreatment.ProcessSimulator.clear_default_state_mapping
BioChemicalTreatment.ProcessSimulator.default_processes
BioChemicalTreatment.ProcessSimulator.default_state_mapping
BioChemicalTreatment.ProcessSimulator.default_states
BioChemicalTreatment.ProcessSimulator.exogenous_input_names
BioChemicalTreatment.ProcessSimulator.exogenous_inputs
BioChemicalTreatment.ProcessSimulator.exogenous_output_names
BioChemicalTreatment.ProcessSimulator.exogenous_outputs
BioChemicalTreatment.ProcessSimulator.get_default_state
BioChemicalTreatment.ProcessSimulator.get_elem
BioChemicalTreatment.ProcessSimulator.get_latex
BioChemicalTreatment.ProcessSimulator.get_latex_preamble
BioChemicalTreatment.ProcessSimulator.get_tikzpicture
BioChemicalTreatment.ProcessSimulator.hasexogenous_inputs
BioChemicalTreatment.ProcessSimulator.hasexogenous_outputs
BioChemicalTreatment.ProcessSimulator.hasinflows
BioChemicalTreatment.ProcessSimulator.hasoutflows
BioChemicalTreatment.ProcessSimulator.hasrates
BioChemicalTreatment.ProcessSimulator.hasstates
BioChemicalTreatment.ProcessSimulator.hassubsystems
BioChemicalTreatment.ProcessSimulator.inflow_names
BioChemicalTreatment.ProcessSimulator.inflows
BioChemicalTreatment.ProcessSimulator.insert_empty_columns!
BioChemicalTreatment.ProcessSimulator.iscolloidal
BioChemicalTreatment.ProcessSimulator.isparticulate
BioChemicalTreatment.ProcessSimulator.issoluble
BioChemicalTreatment.ProcessSimulator.merge_chains!
BioChemicalTreatment.ProcessSimulator.move_chain_horizontally!
BioChemicalTreatment.ProcessSimulator.move_chain_vertically!
BioChemicalTreatment.ProcessSimulator.move_column!
BioChemicalTreatment.ProcessSimulator.move_elem!
BioChemicalTreatment.ProcessSimulator.num_exogenous_inputs
BioChemicalTreatment.ProcessSimulator.num_exogenous_outputs
BioChemicalTreatment.ProcessSimulator.num_inflows
BioChemicalTreatment.ProcessSimulator.num_outflows
BioChemicalTreatment.ProcessSimulator.num_rates
BioChemicalTreatment.ProcessSimulator.num_states
BioChemicalTreatment.ProcessSimulator.num_subsystems
BioChemicalTreatment.ProcessSimulator.outflow_names
BioChemicalTreatment.ProcessSimulator.outflows
BioChemicalTreatment.ProcessSimulator.print_connector_names!
BioChemicalTreatment.ProcessSimulator.rates
BioChemicalTreatment.ProcessSimulator.set_background!
BioChemicalTreatment.ProcessSimulator.set_blockheight!
BioChemicalTreatment.ProcessSimulator.set_blockwidth!
BioChemicalTreatment.ProcessSimulator.set_default_process
BioChemicalTreatment.ProcessSimulator.set_default_state_mapping
BioChemicalTreatment.ProcessSimulator.set_innersep!
BioChemicalTreatment.ProcessSimulator.set_linewidth!
BioChemicalTreatment.ProcessSimulator.set_nodedistance!
BioChemicalTreatment.ProcessSimulator.states
BioChemicalTreatment.ProcessSimulator.subsystem_names
BioChemicalTreatment.ProcessSimulator.subsystems
BioChemicalTreatment.ProcessSimulator.switch_chains!
BioChemicalTreatment.ProcessSimulator.switch_columns!
BioChemicalTreatment.ProcessSimulator.switch_elem!
BioChemicalTreatment.ProcessSimulator.@add_process
BioChemicalTreatment.ProcessSimulator.@add_state_mapping
BioChemicalTreatment.ProcessSimulator.@set_process
BioChemicalTreatment.ProcessSimulator.@set_state_mapping
Documentation
System Types
BioChemicalTreatment.ProcessSimulator.Reactor
— TypeReactor(eqs, t, ps, inflows, outflows, rates, states; systems=ODESystem[], exogenous_inputs=ODESystem[], name)
An implementation of AbstractProcessElement
for reactors. They implement the mass transport, while the processes happening are provided by a Process
.
It has fields:
eqs
: The equationst
: Time symbolps
: Parametersode_system
: AODESystem
fromModelingToolkit
for simulating the reactorsystems
: Vector of subsystems of the reactor (can be empty)inflows
: Vector of the inflow connectors of the reactoroutflows
: Vector of the outflow connectors of the reactorrates
: The rates connector of the reactorstates
: The states connector of the reactorexogenous_inputs
: The exogenous input connectors to the reactor or the subsystems.name
: The name of the reactors
It supports the following interfaces from the AbstractProcessElement
:
BioChemicalTreatment.ProcessSimulator.Process
— TypeProcess
An implementation of AbstractProcessElement
for processes used to compute and provide the reaction rates to reactors.
It has fields:
eqs
: The equationst
: Time symbolps
: Parametersode_system
: AODESystem
fromModelingToolkit
for simulating the reactorrates
: The rates connector of the reactorstates
: The states connector of the reactorexogenous_inputs
: The exogenous input connectors to the reactor or the subsystems.internal_states
: States that are internal to the process but neither input nor output from the system. (e.g. for intermediate computations)name
: The name of the reactors
It supports the following interfaces from the AbstractProcessElement
:
BioChemicalTreatment.ProcessSimulator.FlowElement
— TypeFlowElement
An implementation of AbstractProcessElement
for flow elements without dynamics, e.g. a flow unifier or splitter.
It has fields:
eqs
: The equationst
: Time symbolps
: Parametersode_system
: AODESystem
fromModelingToolkit
for simulating the reactorsystems
: Vector of subsystems of the reactor (can be empty)inflows
: Vector of the inflow connectors of the reactoroutflows
: Vector of the outflow connectors of the reactorexogenous_inputs
: The exogenous input connectors to the reactor or the subsystems.exogenous_outputs
: The exogenous output connectors to the reactor or the subsystems.name
: The name of the reactors
It supports the following interfaces from the AbstractProcessElement
:
BioChemicalTreatment.ProcessSimulator.MTKStandardLibraryInterface
— TypeMTKStandardLibraryInterface
An implementation of AbstractProcessElement
for compatibility interface elements for the ModelingToolkitStandardLibrary.
It has fields:
eqs
: The equationst
: Time symbolode_system
: AODESystem
fromModelingToolkit
for simulating the reactorinflows
: Vector of the inflow connectors of the reactoroutflows
: Vector of the outflow connectors of the reactorrates
: The rates connector of the reactorstates
: The states connector of the reactorexogenous_inputs
: The exogenous input connectors to the reactor or the subsystems.exogenous_outputs
: The exogenous output connectors to the reactor or the subsystems.name
: The name of the reactors
It supports the following interfaces from the AbstractProcessElement
:
Defaults
BioChemicalTreatment.ProcessSimulator.default_processes
— Functiondefault_processes(;name_prefix = rand(UInt), name_postfix = "")::Vector{Process}
Get the default processes.
Returns a vector of the generated default processes. For the names, a prefix and postfix can be added to avoid name clashes.
Keyword arguments:
name_prefix
: Prefix for the name. Defaults to a random number.name_postfix
: Postfix for the name. Defaults to nothing.
BioChemicalTreatment.ProcessSimulator.@set_process
— Macro@set_process
Set the default process. Clears all current ones and adds the supplied ones. Syntax is equal to the one of @add_process
.
Example
julia> @set_process asm = Process("ASM1", Y_OHO = 1) #with setting a parameter
Process ASM1 'asm':
States (14): see states(asm)
S_Alk(t) [guess is 0.0]: S_Alk
S_B(t) [guess is 0.0]: S_B
S_BN(t) [guess is 0.0]: S_BN
S_N2(t) [guess is 0.0]: S_N2
S_NHx(t) [guess is 0.0]: S_NHx
S_NOx(t) [guess is 0.0]: S_NOx
S_O2(t) [guess is 0.0]: S_O2
S_U(t) [guess is 0.0]: S_U
⋮
Parameters (35): see parameters(asm)
K_NHxOHO [defaults to 0.05]
m_ANOMax [defaults to 0.8]
m_OHOMax [defaults to 6]
K_O2ANO [defaults to 0.4]
K_XCBhyd [defaults to 0.03]
COD_P [defaults to 40]
COD_C [defaults to 32]
Y_ANO [defaults to 0.24]
⋮
julia> nameof(only(default_processes(name_prefix="")))
:asm
julia> @set_process asm_replaced = Process("ASM1"; Y_OHO = 1) #note the set
Process ASM1 'asm_replaced':
States (14): see states(asm_replaced)
S_Alk(t) [guess is 0.0]: S_Alk
S_B(t) [guess is 0.0]: S_B
S_BN(t) [guess is 0.0]: S_BN
S_N2(t) [guess is 0.0]: S_N2
S_NHx(t) [guess is 0.0]: S_NHx
S_NOx(t) [guess is 0.0]: S_NOx
S_O2(t) [guess is 0.0]: S_O2
S_U(t) [guess is 0.0]: S_U
⋮
Parameters (35): see parameters(asm_replaced)
K_NHxOHO [defaults to 0.05]
m_ANOMax [defaults to 0.8]
m_OHOMax [defaults to 6]
K_O2ANO [defaults to 0.4]
K_XCBhyd [defaults to 0.03]
COD_P [defaults to 40]
COD_C [defaults to 32]
Y_ANO [defaults to 0.24]
⋮
julia> nameof(only(default_processes(name_prefix="")))
:asm_replaced
BioChemicalTreatment.ProcessSimulator.set_default_process
— Functionset_default_process(process, args...; name, kwargs...)::Bool
Set the default process. Clears all current ones and adds the supplied ones.
Example
julia> add_default_process(Process, "ASM1"; name=:asm1, Y_OHO = 1) #with setting a parameter
true
julia> nameof(only(default_processes(name_prefix="")))
:asm1
julia> set_default_process(Process, "ASM1"; name=:asm_replaced, Y_OHO = 1) #note the set
true
julia> nameof(only(default_processes(name_prefix="")))
:asm_replaced
BioChemicalTreatment.ProcessSimulator.@add_process
— Macroadd_process
Add a process to the default processes. Syntax is specified as usually generating a process, the name
argument is taken from the variable name (similar to @named
) Further the process is assigned to a variable with the same name.
It is possible to add multiple processes at once.
Example
julia> @add_process aer = Aeration()
Process Aeration 'aer':
States (1): see states(aer)
S_O(t) [guess is 0.0]: S_O
Exogenous Inputs (1): see exogenous_inputs(aer)
:k_La
Parameters (1): see parameters(aer)
S_O_max [defaults to 8]
julia> nameof.(default_processes(name_prefix=""))
1-element Vector{Symbol}:
:aer
julia> nameof(aer) # the variables also exist
:aer
The macro also allows adding multiple processes at once
@add_process begin
asm1 = Process("ASM1"; Y_OHO=1)
asm2 = ASM1(Y_H=2)
end # Multiple processes can be added at once
nameof.(default_processes(name_prefix=""))
# output
2-element Vector{Symbol}:
:asm1
:asm2
BioChemicalTreatment.ProcessSimulator.add_default_process
— Functionadd_default_process(process::Function, args...; name, kwargs...)::Bool
Add a default process for newly created reactors.
Example: Adding ASM1
as default process.
Let's say normally ASM1
is directly created using:
julia> asm = ASM1(; name=:asm1, Y_H = 1); #with setting a parameter
julia> nameof(asm)
:asm1
Adding it as default then works as:
julia> add_default_process(ASM1; name=:asm1, Y_H = 1) #with setting a parameter
true
julia> nameof(only(default_processes(name_prefix="")))
:asm1
And from then on this process will be added for every new process, until it gets removed from here.
Arguments:
process
: Function to call to build the processargs...
: The arguments to call the functions withname
: The name of the process. Will be extended for each system to avoid name clashes.kwargs...
: Keyword arguments to generate the process
add_default_process(process::AbstractString, args...; name, kwargs...)::Bool
Add a default matrix-defined process for newly created reactors. (Simplified syntax)
Example: Adding the matrix-defined ASM1
as default process.
Let's say normally ASM1
is directly created using:
julia> asm = Process("ASM1"; name=:asm1, Y_OHO = 1); #with setting a parameter
julia> nameof(asm)
:asm1
Adding it as default then works as:
julia> add_default_process("ASM1"; name=:asm1, Y_OHO = 1) #with setting a parameter
true
julia> nameof(only(default_processes(name_prefix="")))
:asm1
This is equivalent to the more general
julia> add_default_process(Process, "ASM1"; name=:asm1, Y_OHO = 1) #with setting a parameter
true
julia> nameof(only(default_processes(name_prefix="")))
:asm1
which is as well the form to be used when e.g. loading from files.
Arguments:
process
: Name of the matrix-defined process (only for predefined ones)args...
: The arguments to call the functions withname
: The name of the process. Will be extended for each system to avoid name clashes.kwargs...
: Keyword arguments to generate the process
add_default_process(process::Vector, args::Vector{<:Tuple} = Tuple[]; name::Vector{Symbol}, kwargs::Vector{<:AbstractDict} = [Dict()])::Bool
Add a series of processes to the default processes at once. Equivalent to adding all individually.
Example
julia> add_default_process([Process, ASM1], [("ASM1",), ()]; name=[:asm1, :asm2], kwargs=[Dict([:Y_OHO => 1]), Dict([:Y_H => 2])]) #with setting a parameter
true
julia> nameof.(default_processes(name_prefix=""))
2-element Vector{Symbol}:
:asm1
:asm2
BioChemicalTreatment.ProcessSimulator.clear_default_processes
— Functionclear_default_processes()::Bool
Remove all default processes. Already created reactors are not modified, this holds only for new ones.
BioChemicalTreatment.ProcessSimulator.default_state_mapping
— Functiondefault_state_mapping()::Dict{Symbol, Set}
Get the current state mapping.
BioChemicalTreatment.ProcessSimulator.@set_state_mapping
— Macro@set_state_mapping
Clear the current state mappings and set new ones. Uses the same syntax as @add_state_mapping
Example
julia> @set_state_mapping S_O = (:S_O, :S_O2) [:soluble] X = (:X_H, :X_OHO) [:particulate]
true
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 2 entries:
:X => (names = Set([:X_OHO, :X_H, :X]), particulate = 1, colloidal = 0, sol…
:S_O => (names = Set([:S_O, :S_O2]), particulate = 0, colloidal = 0, soluble …
julia> @set_state_mapping S_O = (:S_O, :S_OHO) [:soluble]
true
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 1 entry:
:S_O => (names = Set([:S_O, :S_OHO]), particulate = 0, colloidal = 0, soluble…
BioChemicalTreatment.ProcessSimulator.set_default_state_mapping
— Functionset_default_state_mapping(...)::Bool
Clear the current state mappings and set the new ones. Accepts all syntax available for add_default_state_mapping()
Example
julia> set_default_state_mapping(;S_O = ([:S_O, :S_O2], false, false, true), X = ([:X_H, :X_OHO], true, false, false))
true
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 2 entries:
:X => (names = Set([:X_OHO, :X_H, :X]), particulate = 1, colloidal = 0, sol…
:S_O => (names = Set([:S_O, :S_O2]), particulate = 0, colloidal = 0, soluble …
julia> set_default_state_mapping(:S_O, [:S_O, :S_OHO], false, false, true)
true
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 1 entry:
:S_O => (names = Set([:S_O, :S_OHO]), particulate = 0, colloidal = 0, soluble…
BioChemicalTreatment.ProcessSimulator.@add_state_mapping
— Macro@add_state_mapping
Add a new set of state mappings using a macro.
Macro syntax is:
- New symbol (the states are mapped to) (e.g.
S_O2
) =
- Tuple of mapped states (e.g.
(S_O2, S_O)
) - Vector of solubility properties (optional if at least one of the mapped states is a symbol) (e.g.
[:soluble]
)
E.g. the syntax for a example would be
julia> @add_state_mapping S_O2 = (:S_O, :S_O2) [:soluble]
true
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 1 entry:
:S_O2 => (names = Set([:S_O, :S_O2]), particulate = 0, colloidal = 0, soluble…
Example
julia> @add_state_mapping a = (:a, :b) [:colloidal]
true
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 1 entry:
:a => (names = Set([:a, :b]), particulate = 0, colloidal = 1, soluble = 0)
julia> @add_state_mapping X_H = :X_OHO [:particulate] # For single mappings, only the symbols can be provided
true
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 2 entries:
:a => (names = Set([:a, :b]), particulate = 0, colloidal = 1, soluble = 0)
:X_H => (names = Set([:X_OHO, :X_H]), particulate = 1, colloidal = 0, soluble…
Multiple mappings can also provided, but they need to be wrapped in {...} if using a begin ... end
block.
@add_state_mapping begin
{X_A = :X_ANO [:particulate]}
{S_ALK = :S_alk [:soluble]}
end
default_state_mapping()
# output
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 2 entries:
:X_A => (names = Set([:X_A, :X_ANO]), particulate = 1, colloidal = 0, solub…
:S_ALK => (names = Set([:S_ALK, :S_alk]), particulate = 0, colloidal = 0, sol…
BioChemicalTreatment.ProcessSimulator.add_default_state_mapping
— Functionadd_default_state_mapping(name::Symbol, equal_states::AbstractSet{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool)::Bool
Add a new state mapping.
If any of the newly added equal states is already in an other group of equal states, the newly added states get set equal to all in this group.
If the newly added equal states combine multiple other groups (intersection with multiples), all of these sets get combined to a new one.
Example
julia> set_default_state_mapping(;S_O = ([:S_O, :S_O2], false, false, true), X = ([:X_H, :X_OHO], true, false, false))
true
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 2 entries:
:X => (names = Set([:X_OHO, :X_H, :X]), particulate = 1, colloidal = 0, sol…
:S_O => (names = Set([:S_O, :S_O2]), particulate = 0, colloidal = 0, soluble …
julia> add_default_state_mapping(:S_O, [:S_O, :S_OHO], false, false, true)
┌ Info: Adding Set([:S_O, :S_OHO]) to the already existing equal states of (names = Set([:S_O, :S_O2]), particulate = false, colloidal = false, soluble = true)
│
│ Now the following states are all considered equal:
│
└ Set([:S_O, :S_O2, :S_OHO])
true
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 2 entries:
:X => (names = Set([:X_OHO, :X_H, :X]), particulate = 1, colloidal = 0, sol…
:S_O => (names = Set([:S_O, :S_O2, :S_OHO]), particulate = 0, colloidal = 0, …
julia> add_default_state_mapping(:X, [:X_H, :S_OHO], true, false, false)
ERROR: ArgumentError: Cannot add Set([:X_H, :X, :S_OHO]) to the state mapping with the name X.
This overlapps with the existing mappings Set{Symbol}[Set([:X_OHO, :X_H, :X]), Set([:S_O, :S_O2, :S_OHO])]
which are associated with the different names [:X, :S_O].
[...]
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 2 entries:
:X => (names = Set([:X_OHO, :X_H, :X]), particulate = 1, colloidal = 0, sol…
:S_O => (names = Set([:S_O, :S_O2, :S_OHO]), particulate = 0, colloidal = 0, …
julia> add_default_state_mapping(:X, [:X_H, :X_B], false, true, false) # If added, need to have same solubility properties
ERROR: ArgumentError: Cannot add Set([:X_H, :X_B, :X]) to the state mapping with the name X.
X is already mapped to Set([:X_OHO, :X_H, :X]) which have solubility properties (particulate,)
while the given states have the following solubility properties: (colloidal,).
[...]
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 2 entries:
:X => (names = Set([:X_OHO, :X_H, :X]), particulate = 1, colloidal = 0, sol…
:S_O => (names = Set([:S_O, :S_O2, :S_OHO]), particulate = 0, colloidal = 0, …
add_default_state_mapping(name::Symbol, equal_states::AbstractSet{<:Union{<:Num, <:SymbolicUtils.BasicSymbolic}})::Bool
Add a new state mapping.
Provide the equal states as symbols, allows to extract particulate info directly from there.
Example
julia> @variables S_O [particulate=false, colloidal=false, soluble=true] S_O2 [particulate=false, colloidal=false, soluble=true]
2-element Vector{Num}:
S_O
S_O2
julia> @variables X_H [particulate=true, colloidal=false, soluble=false] X_OHO [particulate=true, colloidal=false, soluble=false]
2-element Vector{Num}:
X_H
X_OHO
julia> set_default_state_mapping(;S_O = [S_O, S_O2], X = [X_H, X_OHO])
true
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 2 entries:
:X => (names = Set([:X_OHO, :X_H, :X]), particulate = 1, colloidal = 0, sol…
:S_O => (names = Set([:S_O, :S_O2]), particulate = 0, colloidal = 0, soluble …
julia> add_default_state_mapping(:S_O, [:S_O, :S_OHO], false, false, true)
┌ Info: Adding Set([:S_O, :S_OHO]) to the already existing equal states of (names = Set([:S_O, :S_O2]), particulate = false, colloidal = false, soluble = true)
│
│ Now the following states are all considered equal:
│
└ Set([:S_O, :S_O2, :S_OHO])
true
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 2 entries:
:X => (names = Set([:X_OHO, :X_H, :X]), particulate = 1, colloidal = 0, sol…
:S_O => (names = Set([:S_O, :S_O2, :S_OHO]), particulate = 0, colloidal = 0, …
julia> add_default_state_mapping(:X, [:X_H, :S_OHO], true, false, false)
ERROR: ArgumentError: Cannot add Set([:X_H, :X, :S_OHO]) to the state mapping with the name X.
This overlapps with the existing mappings Set{Symbol}[Set([:X_OHO, :X_H, :X]), Set([:S_O, :S_O2, :S_OHO])]
which are associated with the different names [:X, :S_O].
[...]
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 2 entries:
:X => (names = Set([:X_OHO, :X_H, :X]), particulate = 1, colloidal = 0, sol…
:S_O => (names = Set([:S_O, :S_O2, :S_OHO]), particulate = 0, colloidal = 0, …
add_default_state_mapping(;kwargs...)::Bool
Add a new set of state mappings. Takes kwargs as inputs for nice syntax.
Example
julia> add_default_state_mapping(; a = ([:a, :b], true, false, false)) # Note the semicolon in the beginning
true
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 1 entry:
:a => (names = Set([:a, :b]), particulate = 1, colloidal = 0, soluble = 0)
julia> d = Dict([:d => ([:e, :f], true, false, false)])
Dict{Symbol, Tuple{Vector{Symbol}, Bool, Bool, Bool}} with 1 entry:
:d => ([:e, :f], 1, 0, 0)
julia> add_default_state_mapping(;d...) # Allows dicts to be splatted
true
julia> default_state_mapping()
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}} with 2 entries:
:a => (names = Set([:a, :b]), particulate = 1, colloidal = 0, soluble = 0)
:d => (names = Set([:f, :d, :e]), particulate = 1, colloidal = 0, soluble = 0)
BioChemicalTreatment.ProcessSimulator.clear_default_state_mapping
— Functionclear_default_state_mapping()::Bool
Clear the current default state mapping. Only affects future generated systems.
BioChemicalTreatment.ProcessSimulator.get_default_state
— Functionget_default_state(sys::Symbol; state_mapping::AbstractDict{Symbol, <:AbstractSet} = default_state_mapping())::Symbol
Get the default state to which the given symbol is mapped to. I.e. a reverse lookup in the state mapping.
If the given symbol is not in the state mapping, it is directly returned.
Throws an error if the mapping of this symbol is invalid (i.e. different defaults for this same symbol). The default mapping should not allow this. But it cannot be excluded in case of a bug or a provided mapping. No error is thrown if the mapping is invalid, but everything is fine for the symbol asked for.
Example
julia> set_default_state_mapping(S_O2=(Set([:S_O, :S_O2]), false, false, true))
true
julia> get_default_state(:S_O)
:S_O2
julia> get_default_state(:S_O2)
:S_O2
julia> get_default_state(:X_H)
:X_H
julia> get_default_state(:S_O, state_mapping=Dict([:S_O2 => (names=Set([:S_O, :S_O2]), particulate=false, colloidal=false, soluble=true), :DO => (names=Set([:S_O]), particulate=false, colloidal=false, soluble=true)]))
ERROR: State Mapping error: S_O is mapped to multiple default states ([:DO, :S_O2]).
This means there is an error in the state mapping
Dict{Symbol, @NamedTuple{names::Set{Symbol}, particulate::Bool, colloidal::Bool, soluble::Bool}}(:DO => (names = Set([:S_O]), particulate = 0, colloidal = 0, soluble = 1), :S_O2 => (names = Set([:S_O, :S_O2]), particulate = 0, colloidal = 0, soluble = 1)).
If you used the default one: Did you modify any internals? If not, please file an issue.
[...]
julia> get_default_state(:S_O2, state_mapping=Dict([:S_O2 => (names=Set([:S_O, :S_O2]), particulate=false, colloidal=false, soluble=true), :DO => (names=Set([:S_O]), particulate=false, colloidal=false, soluble=true)]))
:S_O2
get_default_state(sys; state_mapping = default_state_mapping())::Symbol
Allow for non-symbol state queries (e.g. Symbolics variables or strings.)
Examples
julia> set_default_state_mapping(S_O2=(Set([:S_O, :S_O2]), false, false, true))
true
julia> get_default_state("S_O")
:S_O2
julia> get_default_state(only(@variables S_O(t)))
:S_O2
BioChemicalTreatment.ProcessSimulator.default_states
— Functiondefault_states(;processes = default_processes(), state_mapping = default_state_mapping())
Get the default states using the given processes and mapping.
Get the combined states of all given processes with all equally named ones only once. Applies the state_mapping to rename given states and combine the ones mapped to the same name.
Helpers and Accessor functions
ModelingToolkit.t
— Constantt
Symbol for time.
BioChemicalTreatment.ProcessSimulator.inflows
— Functioninflows(sys)
Get the vector of inflow connectors of the system represented by the process element sys
.
This function returns the inflows of the system. Inflows are all flows into the system.
Extended Help
Implementation
This function should be overridden for each type inheriting from AbstractProcessElement
which could have one or more inflows.
inflows(sys, names::Vector{Symbol})
Get the vector of inflow connectors in sys
called names
.
inflows(sys, names::Symbol)
Get the inflow connector in sys
called names
.
inflows(sys, idxs::Union{Int, Vector{Int}})
Get the inflow connectors in sys
at indices idxs
.
If idxs
is a single integer, the output will be the connector, if it is a vector of integers, the output will be a vecotr of connectors.
BioChemicalTreatment.ProcessSimulator.inflow_names
— Functioninflow_names(sys)
Return the names of each inflow of the process element sys
.
Extended Help
Implementation
This function defaults to output the names assigned to each inflow connector. It is recomended to set these names to the names that should be output here and this function should only be overridden in special cases.
BioChemicalTreatment.ProcessSimulator.hasinflows
— Functionhasinflows(sys)
Returns true
if the AbstractProcessElement
has inflows (i.e. the inflows
function does not throw an error).
BioChemicalTreatment.ProcessSimulator.num_inflows
— Functionnum_inflows(sys)
Returns the number of inflows of the AbstractProcessElement
. Zero if there are none
BioChemicalTreatment.ProcessSimulator.outflows
— Functionoutflows(sys)
Get the vector of outflow connectors of the system represented by the process element sys
.
This function returns the outflows of the system. Outflows are all flows leaving the system.
Extended Help
Implementation
This function should be overridden for each type inheriting from AbstractProcessElement
which could have one or more outflows.
outflows(sys, names::Vector{Symbol})
Get the vector of outflow connectors in sys
called names
.
outflows(sys, names::Symbol)
Get the outflow connector in sys
called names
.
outflows(sys, idxs::Union{Int, Vector{Int}})
Get the outflow connectors in sys
at indices idxs
.
If idxs
is a single integer, the output will be the connector, if it is a vector of integers, the output will be a vecotr of connectors.
BioChemicalTreatment.ProcessSimulator.outflow_names
— Functionoutflow_names(sys)
Return the names of each outflow of the process element sys
.
Extended Help
Implementation
This function defaults to output the names assigned to each outflow connector. It is recomended to set these names to the names that should be output here and this function should only be overridden in special cases.
BioChemicalTreatment.ProcessSimulator.hasoutflows
— Functionhasoutflows(sys)
Returns true
if the AbstractProcessElement
has outflows (i.e. the outflows
function does not throw an error).
BioChemicalTreatment.ProcessSimulator.num_outflows
— Functionnum_outflows(sys)
Returns the number of outflows of the AbstractProcessElement
.
BioChemicalTreatment.ProcessSimulator.rates
— Functionrates(sys)
Get the rates connector of the system represented by the process element sys
.
This function returns the rates of the system. Not all process elements have rates, but this mainly used for Reactor
s and Process
es. The Reactor
uses the rates as reaction rates for the process happening in the Reactor
and the Process
provides these rates to the reactor.
Extended Help
Implementation
This function should be overridden for each type inheriting from AbstractProcessElement
which needs or provides rates. Note that depending on if it needs or provides rates, different connectors are needed (ReactionInputPort
vs. ReactionOutputPort
)
BioChemicalTreatment.ProcessSimulator.hasrates
— Functionhasrates(sys)
Returns true
if the AbstractProcessElement
has rates (i.e. the rates
function does not throw an error).
BioChemicalTreatment.ProcessSimulator.num_rates
— Functionnum_rates(sys)
Returns the number of rates of the AbstractProcessElement
.
BioChemicalTreatment.ProcessSimulator.states
— Functionsates(sys)
Get the states connector of the dynamical system represented by the process element sys
.
This function returns the states of the dynamical system, i.e. all variables that are involved as derivatives in any of the differential equations describing the model. As not all systems are dynamic (they can be static as well), this function is not applicable to static systems. Additionally this connector is used for all process elements which need the internal states of a dynamical systems for processing, i.e. the Process
need the states of the associated Reactor
to compute the rates.
Extended Help
Implementation
This function should be overridden for each type inheriting from AbstractProcessElement
which has states or needs the states of another AbstractProcessElement
. Note that depending on if it needs or provides states, different connectors are needed (StateInputPort
vs. StateOutputPort
)
BioChemicalTreatment.ProcessSimulator.hasstates
— Functionhasstates(sys)
Returns true
if the AbstractProcessElement
has states (i.e. the states
function does not throw an error).
BioChemicalTreatment.ProcessSimulator.num_states
— Functionnum_states(sys)
Returns the number of states in the AbstractProcessElement
.
BioChemicalTreatment.ProcessSimulator.exogenous_inputs
— Functionexogenous_inputs(sys)
Get the vector of exogenous input connectors of the system represented by the process element sys
.
This function returns the exogenous inputs of the system. Exogenous inputs are all inputs to the system which are not connectors provided by this package, i.e. not flows, states nor rates.
Extended Help
Implementation
This function should be overridden for each type inheriting from AbstractProcessElement
which could have one or more exogenous inputs.
exogenous_inputs(sys, names::Vector{Symbol})
Get the vector of exogenous input connectors in sys
called names
.
exogenous_inputs(sys, names::Symbol)
Get the exogenous input connector in sys
called names
.
exogenous_inputs(sys, idxs::Union{Int, Vector{Int}})
Get the exogenous input connectors in sys
at indices idxs
.
If idxs
is a single integer, the output will be the connector, if it is a vector of integers, the output will be a vecotr of connectors.
BioChemicalTreatment.ProcessSimulator.exogenous_input_names
— Functionexogenous_input_names(sys)
Return the names of each exogenous input of the process element sys
.
Extended Help
Implementation
This function defaults to output the names assigned to each exogenous input connector. It is recomended to set these names to the names that should be output here and this function should only be overridden in special cases.
BioChemicalTreatment.ProcessSimulator.hasexogenous_inputs
— Functionhasexogenous_inputs(sys)
Returns true
if the AbstractProcessElement
has exogenousinputs (i.e. the [`exogenousinputs`](@ref) function does not throw an error).
BioChemicalTreatment.ProcessSimulator.num_exogenous_inputs
— Functionnum_exogenous_inputs(sys)
Returns the number of exogenous_inputs in the AbstractProcessElement
.
BioChemicalTreatment.ProcessSimulator.exogenous_outputs
— Functionexogenous_outputs(sys)
Get the vector of exogenous output connectors of the system represented by the process element sys
.
This function returns the exogenous outputs of the system. Exogenous outputs are all outputs of the system which are not connectors provided by this package, i.e. not flows, states nor rates.
Extended Help
Implementation
This function should be overridden for each type inheriting from AbstractProcessElement
which could have one or more exogenous outputs.
exogenous_outputs(sys, names::Vector{Symbol})
Get the vector of exogenous output connectors in sys
called names
.
exogenous_outputs(sys, names::Symbol)
Get the exogenous output connector in sys
called names
.
exogenous_outputs(sys, idxs::Union{Int, Vector{Int}})
Get the exogenous output connectors in sys
at indices idxs
.
If idxs
is a single integer, the output will be the connector, if it is a vector of integers, the output will be a vecotr of connectors.
BioChemicalTreatment.ProcessSimulator.exogenous_output_names
— Functionexogenous_output_names(sys)
Return the names of each exogenous output of the process element sys
.
Extended Help
Implementation
This function defaults to output the names assigned to each exogenous output connector. It is recomended to set these names to the names that should be output here and this function should only be overridden in special cases.
BioChemicalTreatment.ProcessSimulator.hasexogenous_outputs
— Functionhasexogenous_outputs(sys)
Returns true
if the AbstractProcessElement
has exogenousoutputs (i.e. the [`exogenousoutputs`](@ref) function does not throw an error).
BioChemicalTreatment.ProcessSimulator.num_exogenous_outputs
— Functionnum_exogenous_outputs(sys)
Returns the number of exogenous_outputs in the AbstractProcessElement
.
BioChemicalTreatment.ProcessSimulator.subsystems
— Functionsubsystems(sys)
Get the vector of subsystems of the process element sys
.
Extended Help
Implementation
This function should be overridden for each type inheriting from AbstractProcessElement
which could have one or more subsystems.
subsystems(sys, names::Vector{Symbol})
Get the vector of subsystems in sys
called names
.
subsystems(sys, names::Symbol)
Get the subsystem in sys
called names
.
subsystems(sys, idxs::Union{Int, Vector{Int}})
Get the subsystems in sys
at indices idxs
.
If idxs
is a single integer, the output will be the subsystem, if it is a vector of integers, the output will be a vecotr of systems.
BioChemicalTreatment.ProcessSimulator.subsystem_names
— Functionsubsystem_names(sys)
Return the names of each subsystem of the process element sys
.
Extended Help
Implementation
This function defaults to output the names assigned to each subsystem. It is recomended to set these names to the names that should be output here and this function should only be overridden in special cases.
BioChemicalTreatment.ProcessSimulator.hassubsystems
— Functionhassubsystems(sys)
Returns true
if the AbstractProcessElement
has subsystems (i.e. the subsystems
function does not throw an error).
BioChemicalTreatment.ProcessSimulator.num_subsystems
— Functionnum_subsystems(sys)
Returns the number of subsystems in the AbstractProcessElement
.
BioChemicalTreatment.ProcessSimulator.iscolloidal
— Functioniscolloidal(x; default = nothing)
Determine if the symbolic variable x
is marked as colloidal or not.
default
indicates how unlabeled variables should be treated, by default it is nothing
to be able to distinct between labeled and unlabeled variables.
BioChemicalTreatment.ProcessSimulator.isparticulate
— Functionisparticulate(x; default = nothing)
Determine if the symbolic variable x
is marked as particulate or not.
default
indicates how unlabeled variables should be treated, by default it is nothing
to be able to distinct between labeled and unlabeled variables.
BioChemicalTreatment.ProcessSimulator.issoluble
— Functionissoluble(x; default = nothing)
Determine if the symbolic variable x
is marked as soluble or not.
default
indicates how unlabeled variables should be treated, by default it is nothing
to be able to distinct between labeled and unlabeled variables.
ProcessDiagram
BioChemicalTreatment.ProcessSimulator.ProcessDiagram
— TypeProcessDiagram(systems, equations; only_flow = true, printing_options...)
Draw a the process diagram resulting of the systems
connected by equations
.
This feature is considered experimental and a nice looking diagram is not guaranteed! However, manual ordering of the elements can help with this.
Currently, only printing using TikZ/LaTeX is supported.
The systems are automatically positioned in a grid s.t. it should look nice. The rows in the grid are named chains
, the columns columns
.
However, it can be adapted manually using the appropriate functions.
For adapting the diagram, generally indices are required. When using this, consider that it the indices are 1-based and start on the top left. I.e. the top chain (row) is at index 1, as is the most left column.
Parameters
systems
: The vector containing all systems. Each one must beAbstractProcessElement
orModelingToolkit.ODESystem
equations
: The connection equations between the systems.only_flow
: If only the flow connections are to be drawn. Defaults totrue
printing_options
: Options for the displaying. See below for details.
Printing Options
linewidth = "0.4pt"
*: The linewidth for the graphnodedistance = ".5cm"
*: The spacing between the nodes/elements in the graphblockwidth = "4.5cm"
*: The text width for the elements in the graph (wider text is scaled)blockheight = "2em+10mm"
*: The text height for the elements in the graph (higher text is scaled)innersep = "5mm"
*: The separation between the text and the shape in a node.background = nothing
: The background color for the whole graph.nothing
for transparent or valid color for LaTex.print_connector_names = false
: If each name of the connector is supposed to be printed at the edge of the element where it connects. This is intended only for debugging, the names might be printed in very different sizes and also very small.Argument for tikz, provide as string with the appropriate unit. If you do arithmetics, wrap the whole in parenthesis.
Printing options
BioChemicalTreatment.ProcessSimulator.set_linewidth!
— Functionset_linewidth!(pd, linewidth)
Set the linewidth for all lines when printing pd
.
This is used as argument for tikz, provide as string with the appropriate units. If you do arithmetics, wrap the whole in parenthesis.
BioChemicalTreatment.ProcessSimulator.set_nodedistance!
— Functionset_nodedistance!(pd, nodedistance)
Set the distance inbetween the blocks when printing pd
.
This is used as argument for tikz, provide as string with the appropriate units. If you do arithmetics, wrap the whole in parenthesis.
BioChemicalTreatment.ProcessSimulator.set_blockwidth!
— Functionset_blockwidth!(pd, blockwidth)
Set the width of the blocks when printing pd
.
This is used as argument for tikz, provide as string with the appropriate units. If you do arithmetics, wrap the whole in parenthesis.
BioChemicalTreatment.ProcessSimulator.set_blockheight!
— Functionset_blockheight!(pd, blockheight)
Set the height of the blocks when printing pd
.
This is used as argument for tikz, provide as string with the appropriate units. If you do arithmetics, wrap the whole in parenthesis.
BioChemicalTreatment.ProcessSimulator.set_innersep!
— Functionset_innersep!(pd, innersep)
Set the inner separation of the nodes (i.e. the distance between the drawn box and the text) when printing pd
.
This is used as argument for tikz, provide as string with the appropriate units. If you do arithmetics, wrap the whole in parenthesis.
BioChemicalTreatment.ProcessSimulator.set_background!
— Functionset_background!(pd, background)
Set the background color when printing pd
. Set to nothing
for transparent.
This is used as argument for tikz, provide as string with a valid latex color definition or nothing
.
BioChemicalTreatment.ProcessSimulator.print_connector_names!
— Functionprint_connector_names!(pd, print_names=true)
Set if the name of each connector is supposed to be printed at the edge of the element where it connects.
This is helpful for debugging, but the names might be printed in very different sizes and also very small.
Element Ordering
BioChemicalTreatment.ProcessSimulator.switch_chains!
— Functionswitch_chains!(pd::ProcessDiagram, idx1::Integer, idx2::Integer)
Switch two chains (rows) in the ProcessDiagram
. The indices are 1-based and from the top.
BioChemicalTreatment.ProcessSimulator.move_chain_vertically!
— Functionmove_chain_vertically!(pd::ProcessDiagram, old_idx::Integer, new_idx::Integer)
Move a chain (row) vertically from old_idx
to new_idx
in the ProcessDiagram
. The indices are 1-based and from the top.
BioChemicalTreatment.ProcessSimulator.move_chain_horizontally!
— Functionmove_chain_horizontally!(pd::ProcessDiagram, chain_idx::Integer, shift::Integer)
Shift the chain (row) at chain_idx
horizontally by shift
in the ProcessDiagram
. The indices are 1-based and from the top.
BioChemicalTreatment.ProcessSimulator.merge_chains!
— Functionmerge_chains!(pd::ProcessDiagram, idx1::Integer, idx2::Integer)
Merge the two chains (rows) at idx1
and idx2
in the ProcessDiagram
. The indices are 1-based and from the top.
BioChemicalTreatment.ProcessSimulator.insert_empty_columns!
— Functioninsert_empty_columns!(chains, shifts, idx, n_cols = 1)
Insert empty columns (all missing
) into the ProcessDiagram
defined by chains
, shifts
.
If you do some indexing into the shifts
, do it using view(shifts, idxs)
and not directly (shifts[idxs]
), as otherwise they are not updated.
Parameters
chains
: The chains of theProcessDiagram
shifts
: The shifts of theProcessDiagram
idx
: The index to insert the empty column ton_cols
: The number of empty columns to insert
insert_empty_columns!(pd, idx, n_cols = 1)
Insert empty columns into the ProcessDiagram
pd
.
Parameters
pd
: TheProcessDiagram
to insertidx
: The index to insert the empty column ton_cols
: The number of empty columns to insert
BioChemicalTreatment.ProcessSimulator.switch_columns!
— Functionswitch_columns!(pd::ProcessDiagram, idx1::Integer, idx2::Integer)
Switch columns at idx1
and idx2
. The indices are 1-based and from the left.
BioChemicalTreatment.ProcessSimulator.move_column!
— Functionmove_column!(pd::ProcessDiagram, old_idx::Integer, new_idx::Integer)
Move column at old_idx
to new_idx
. The indices are 1-based and from the left.
Columns right of old_idx
, are shifted to the left and the ones right of new_idx
to the right. Columns right of both are left where they are.
BioChemicalTreatment.ProcessSimulator.get_elem
— Functionget_elem(pd, chain_idx, column_idx)
Get the element at (chain_idx
, column_idx
). If there is none, return missing
chain_idx
is the row, column_idx
the column index. The indices are relative to a grid and start from the top left (treated including empty positions).
BioChemicalTreatment.ProcessSimulator.move_elem!
— Functionmove_elem!(pd, from, to)
Move the element currently at position from
to position to
. The positions are to given as tuples of (chain_idx, column_idx)
.
chain_idx
is the row, column_idx
the column index. The indices are relative to a grid and start from the top left (treated including empty positions).
BioChemicalTreatment.ProcessSimulator.switch_elem!
— Functionswitch_elem!(pd, first, second)
Switch the elements at positions first
and second
. The positions are to given as tuples of (chain_idx, column_idx)
.
chain_idx
is the row, column_idx
the column index. The indices are relative to a grid and start from the top left (treated including empty positions).
BioChemicalTreatment.ProcessSimulator.cleanup!
— Functioncleanup!(pd)
Clean up the ProcessDiagram
pd
by removeing all empty chains and columns.
Meaning:
- Strip all chains (
strip_chains!
) - Remove all empty chains (
remove_empty_chains!
) - Remove all empty columns (
remove_empty_columns!
)
Output options
BioChemicalTreatment.ProcessSimulator.get_latex_preamble
— Functionget_latex_preamble(pd::ProcessDiagram; include_tikz=true)
Get the preamble for a latex document with a tikzpicture showing pd
.
If include_tikz
, then also import tikz
itself.
BioChemicalTreatment.ProcessSimulator.get_tikzpicture
— Functionget_tikzpicture(pd::ProcessDiagram)
Get the TikZ/LaTeX code for the tikzpicture representing pd
.
Includes the full tikzpicture environment, but no preamble or similar.
BioChemicalTreatment.ProcessSimulator.get_latex
— Functionget_latex(pd::ProcessDiagram)
Get the LaTeX code for a complete, renderable, LaTeX document containing the tikzpicture representing pd
.
Includes every thing needed, from preamble, to the document itself.
Uses the standalone documentclass.