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

Documentation

System Types

BioChemicalTreatment.ProcessSimulator.ReactorType
Reactor(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 equations
  • t: Time symbol
  • ps: Parameters
  • ode_system: A ODESystem from ModelingToolkit for simulating the reactor
  • systems: Vector of subsystems of the reactor (can be empty)
  • inflows: Vector of the inflow connectors of the reactor
  • outflows: Vector of the outflow connectors of the reactor
  • rates: The rates connector of the reactor
  • states: The states connector of the reactor
  • exogenous_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:

source
BioChemicalTreatment.ProcessSimulator.ProcessType
Process

An implementation of AbstractProcessElement for processes used to compute and provide the reaction rates to reactors.

It has fields:

  • eqs: The equations
  • t: Time symbol
  • ps: Parameters
  • ode_system: A ODESystem from ModelingToolkit for simulating the reactor
  • rates: The rates connector of the reactor
  • states: The states connector of the reactor
  • exogenous_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:

source
BioChemicalTreatment.ProcessSimulator.FlowElementType
FlowElement

An implementation of AbstractProcessElement for flow elements without dynamics, e.g. a flow unifier or splitter.

It has fields:

  • eqs: The equations
  • t: Time symbol
  • ps: Parameters
  • ode_system: A ODESystem from ModelingToolkit for simulating the reactor
  • systems: Vector of subsystems of the reactor (can be empty)
  • inflows: Vector of the inflow connectors of the reactor
  • outflows: Vector of the outflow connectors of the reactor
  • exogenous_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:

source
BioChemicalTreatment.ProcessSimulator.MTKStandardLibraryInterfaceType
MTKStandardLibraryInterface

An implementation of AbstractProcessElement for compatibility interface elements for the ModelingToolkitStandardLibrary.

It has fields:

  • eqs: The equations
  • t: Time symbol
  • ode_system: A ODESystem from ModelingToolkit for simulating the reactor
  • inflows: Vector of the inflow connectors of the reactor
  • outflows: Vector of the outflow connectors of the reactor
  • rates: The rates connector of the reactor
  • states: The states connector of the reactor
  • exogenous_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:

source

Defaults

BioChemicalTreatment.ProcessSimulator.default_processesFunction
default_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.
source
BioChemicalTreatment.ProcessSimulator.@set_processMacro
@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
source
BioChemicalTreatment.ProcessSimulator.set_default_processFunction
set_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
source
BioChemicalTreatment.ProcessSimulator.@add_processMacro
add_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
source
BioChemicalTreatment.ProcessSimulator.add_default_processFunction
add_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 process
  • args...: The arguments to call the functions with
  • name: The name of the process. Will be extended for each system to avoid name clashes.
  • kwargs...: Keyword arguments to generate the process
source
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 with
  • name: The name of the process. Will be extended for each system to avoid name clashes.
  • kwargs...: Keyword arguments to generate the process
source
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
source
BioChemicalTreatment.ProcessSimulator.@set_state_mappingMacro
@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…
source
BioChemicalTreatment.ProcessSimulator.set_default_state_mappingFunction
set_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…
source
BioChemicalTreatment.ProcessSimulator.@add_state_mappingMacro
@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…
source
BioChemicalTreatment.ProcessSimulator.add_default_state_mappingFunction
add_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, …
source
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, …
source
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)
source
BioChemicalTreatment.ProcessSimulator.get_default_stateFunction
get_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
source
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
source
BioChemicalTreatment.ProcessSimulator.default_statesFunction
default_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.

source

Helpers and Accessor functions

BioChemicalTreatment.ProcessSimulator.inflowsFunction
inflows(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.

source
inflows(sys, names::Vector{Symbol})

Get the vector of inflow connectors in sys called names.

source
inflows(sys, names::Symbol)

Get the inflow connector in sys called names.

source
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.

source
BioChemicalTreatment.ProcessSimulator.inflow_namesFunction
inflow_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.

source
BioChemicalTreatment.ProcessSimulator.outflowsFunction
outflows(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.

source
outflows(sys, names::Vector{Symbol})

Get the vector of outflow connectors in sys called names.

source
outflows(sys, names::Symbol)

Get the outflow connector in sys called names.

source
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.

source
BioChemicalTreatment.ProcessSimulator.outflow_namesFunction
outflow_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.

source
BioChemicalTreatment.ProcessSimulator.ratesFunction
rates(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 Reactors and Processes. 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)

source
BioChemicalTreatment.ProcessSimulator.statesFunction
sates(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)

source
BioChemicalTreatment.ProcessSimulator.exogenous_inputsFunction
exogenous_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.

source
exogenous_inputs(sys, names::Vector{Symbol})

Get the vector of exogenous input connectors in sys called names.

source
exogenous_inputs(sys, names::Symbol)

Get the exogenous input connector in sys called names.

source
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.

source
BioChemicalTreatment.ProcessSimulator.exogenous_input_namesFunction
exogenous_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.

source
BioChemicalTreatment.ProcessSimulator.exogenous_outputsFunction
exogenous_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.

source
exogenous_outputs(sys, names::Vector{Symbol})

Get the vector of exogenous output connectors in sys called names.

source
exogenous_outputs(sys, names::Symbol)

Get the exogenous output connector in sys called names.

source
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.

source
BioChemicalTreatment.ProcessSimulator.exogenous_output_namesFunction
exogenous_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.

source
BioChemicalTreatment.ProcessSimulator.subsystemsFunction
subsystems(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.

source
subsystems(sys, names::Vector{Symbol})

Get the vector of subsystems in sys called names.

source
subsystems(sys, names::Symbol)

Get the subsystem in sys called names.

source
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.

source
BioChemicalTreatment.ProcessSimulator.subsystem_namesFunction
subsystem_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.

source
BioChemicalTreatment.ProcessSimulator.iscolloidalFunction
iscolloidal(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.

source
BioChemicalTreatment.ProcessSimulator.isparticulateFunction
isparticulate(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.

source
BioChemicalTreatment.ProcessSimulator.issolubleFunction
issoluble(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.

source

ProcessDiagram

BioChemicalTreatment.ProcessSimulator.ProcessDiagramType
ProcessDiagram(systems, equations; only_flow = true, printing_options...)

Draw a the process diagram resulting of the systems connected by equations.

Warning

This feature is considered experimental and a nice looking diagram is not guaranteed! However, manual ordering of the elements can help with this.

Note

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.

Indexing

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 be AbstractProcessElement or ModelingToolkit.ODESystem
  • equations: The connection equations between the systems.
  • only_flow: If only the flow connections are to be drawn. Defaults to true
  • printing_options: Options for the displaying. See below for details.

Printing Options

  • linewidth = "0.4pt"*: The linewidth for the graph

  • nodedistance = ".5cm"*: The spacing between the nodes/elements in the graph

  • blockwidth = "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.

source

Printing options

BioChemicalTreatment.ProcessSimulator.set_innersep!Function
set_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.

source
BioChemicalTreatment.ProcessSimulator.print_connector_names!Function
print_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.

source

Element Ordering

BioChemicalTreatment.ProcessSimulator.insert_empty_columns!Function
insert_empty_columns!(chains, shifts, idx, n_cols = 1)

Insert empty columns (all missing) into the ProcessDiagram defined by chains, shifts.

Warning

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 the ProcessDiagram
  • shifts: The shifts of the ProcessDiagram
  • idx: The index to insert the empty column to
  • n_cols: The number of empty columns to insert
source
insert_empty_columns!(pd, idx, n_cols = 1)

Insert empty columns into the ProcessDiagram pd.

Parameters

  • pd: The ProcessDiagram to insert
  • idx: The index to insert the empty column to
  • n_cols: The number of empty columns to insert
source
BioChemicalTreatment.ProcessSimulator.move_column!Function
move_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.

source
BioChemicalTreatment.ProcessSimulator.get_elemFunction
get_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).

source
BioChemicalTreatment.ProcessSimulator.move_elem!Function
move_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).

source
BioChemicalTreatment.ProcessSimulator.switch_elem!Function
switch_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).

source

Output options

BioChemicalTreatment.ProcessSimulator.get_latexFunction
get_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.

source