List of Functions
Single Reactor Solvers
ADM1jl.ADM1sol
— Functionfunction ADM1sol(tspan::Tuple,u0::Vector,IV::Vector; <keyword arguments>)
Compute the solution for the given timespan, tspan
; initial condition, u0
; and inflow vector IV
.
Also return the time (in seconds) the solution took to compute. The difference between this function and ExampleSol is that this function reads in the parameter values from a .csv file.
Optional Arguments
alg = Rodas4P()
: the ODE solver algorithm.tols = 1e-4
: the absolute and relative tolerance of the solver method.tMax = 300.0
: the maximum time (in seconds), that the function will run before timing out.saveAt = []
: specific times to save the solution. If given a numbern
, the solver will save the solution everyn
timesteps
Examples
julia> u0 = initialConditions();
julia> IV = inflowvector_definition();
julia> sol, tSol = ADM1sol((0.0,200.0),u0,IV);
julia> sol
retcode: Success
Interpolation: specialized 3rd order "free" stiffness-aware interpolation
t: 146-element Vector{Float64}:
[...]
u: 146-element Vector{Vector{Float64}}:
[...]
julia> tSol
0.3854937
function ADM1sol(tspan::Tuple,u0::Vector,IV::Vector{Vector{Float64}},IVtimes::Vector{Float64}; <keyword arguments>)
Compute the solution with variable inflow for the given timespan, tspan
; initial condition, u0
; and variable inflow vector IV
where each entry in IV
corresponds to the inflow vector at the corresponding entry in IVtimes
Also return the time (in seconds) the solution took to compute.
Optional Arguments
alg = Rodas4P()
: the ODE solver algorithm.tols = 1e-4
: the absolute and relative tolerance of the solver method.tMax = 300.0
: the maximum time (in seconds), that the function will run before timing out.saveAt = []
: specific times to save the solution. If given a numbern
, the solver will save the solution everyn
timesteps
Examples
julia> u0 = initialConditions();
julia> t = [i for i in 0.0:0.1:50.0];
julia> IV_temp = inflowvector_definition();
julia> IV = [IV_temp*(0.5*rand()+1.0) for i in 1:length(t)]
julia> sol,tSol = ADM1sol((0.0,50.0),u0,IV,t);
julia> sol
retcode: Success
Interpolation: specialized 3rd order "free" stiffness-aware interpolation
t: 2011-element Vector{Float64}:
[...]
u: 2011-element Vector{Vector{Float64}}:
[...]
julia> tSol
14.4643811
Multiple Reactor Solvers
ADM1jl.MultiChamberSolution
— Functionfunction MultiChamberSolution(tspan::Tuple,u0::Tuple,IV::Vector,nChambers::Int64; <keyword arguments>)
Compute the solution for a system of nChambers
connected CSTRs with u0
initial conditions. The inflow of the first CSTR is given by IV
, the outflow of the first CSTR becomes the inflow of second CSTR and so on.
This function reads in the parameter values from a .csv file. The names of the .csv files that contain the parameter values should be "modelparameters.csv", "modelparameters2.csv", "model_parameters3.csv", ... and so on.
Arguments
alg = Rodas4P()
: the ODE solver algorithm.tols = 1e-4
: the absolute and relative tolerance of the solver method.tMax = 300.0
: the maximum time (in seconds), that the function will run before timing out.saveAt = []
: specific times to save the solution. If given a numbern
, the solver will save the solution everyn
timesteps
Examples
julia> u0 = initialConditions();
julia> IV = inflowvector_definition();
julia> sols = MultiChamberSolution((0.0,200.0),(u0,u0,u0),IV,3);
Finished Chamber 1
Finished Chamber 2
Finished Chamber 3
julia> sols[1]
retcode: Success
Interpolation: specialized 3rd order "free" stiffness-aware interpolation
t: 115-element Vector{Float64}:
[...]
u: 115-element Vector{Vector{Float64}}:
[...]
julia> sols[2]
retcode: Success
Interpolation: specialized 3rd order "free" stiffness-aware interpolation
t: 115-element Vector{Float64}:
[...]
u: 115-element Vector{Vector{Float64}}:
[...]
julia> sols[3]
retcode: Success
Interpolation: specialized 3rd order "free" stiffness-aware interpolation
t: 115-element Vector{Float64}:
[...]
u: 115-element Vector{Vector{Float64}}:
[...]
function MultiChamberSolution(tspan::Tuple,u0::Tuple,IV::Vector{Vector{Float64}},IVtimes::Vector{Float64},nChambers::Int64;<keyword arguments>)
Compute the solution for a system of nChambers
connected CSTRs with u0
initial conditions. The inflow of the first CSTR is given by variable inflow vector IV
where each entry in IV
corresponds to the inflow vector at the corresponding entry in IVtimes
, the outflow of the first CSTR becomes the inflow of second CSTR and so on.
This function reads in the parameter values from a .csv file. The names of the .csv files that contain the parameter values should be "modelparameters.csv", "modelparameters2.csv", "model_parameters3.csv", ... and so on.
Arguments
alg = Rodas4P()
: the ODE solver algorithm.tols = 1e-4
: the absolute and relative tolerance of the solver method.tMax = 300.0
: the maximum time (in seconds), that the function will run before timing out.saveAt = []
: specific times to save the solution. If given a numbern
, the solver will save the solution everyn
timesteps
Examples
julia> u0 = initialConditions();
julia> t = [i for i in 0.0:0.1:50.0];
julia> IV_temp = inflowvector_definition();
julia> IV = [IV_temp*(0.5*rand()+1.0) for i in 1:length(t)];
julia> sols = MultiChamberSolution((0.0,50.0),(u0,u0,u0),IV,t,3);
Finished Chamber 1
Finished Chamber 2
Finished Chamber 3
julia> sols[1]
retcode: Success
Interpolation: specialized 3rd order "free" stiffness-aware interpolation
t: 115-element Vector{Float64}:
[...]
u: 115-element Vector{Vector{Float64}}:
[...]
julia> sols[2]
retcode: Success
Interpolation: specialized 3rd order "free" stiffness-aware interpolation
t: 115-element Vector{Float64}:
[...]
u: 115-element Vector{Vector{Float64}}:
[...]
julia> sols[3]
retcode: Success
Interpolation: specialized 3rd order "free" stiffness-aware interpolation
t: 115-element Vector{Float64}:
[...]
u: 115-element Vector{Vector{Float64}}:
[...]
Parameter Definitions
ADM1jl.initialConditions
— Function initialConditions()
Returns the default initial conditions as a Vector{Float64} of length 35.
Examples
julia> initialConditions()
35-element Vector{Float64}:
0.012
0.0053
⋮
1.63
0.014
ADM1jl.inflowvector_definition
— Function inflowvector_definition()
Returns the default inflow vector as a Vector{Float64} of length 35.
Examples
julia> inflowvector_definition()
35-element Vector{Float64}:
0.01
0.001
0.001
0.001
⋮
0.02
0.0
0.0
0.0
Plotting
ADM1jl.plotSols
— FunctionplotSols(sol;<keyword arguments>)
Plot the solutions returned by ADM1sol. The plots are split between two figures and are displayed by default. However, due to an error in Julia's Plots package, the plot's windows may overwrite eachother in some circumstances. If this occurs, use the keyword arguments to view both plots manually.
Arguments
sol::Vector
:ODESolution
returned by ADM1 sol
Optional Arguments
titleText = "Plot of Solutions"
: The title of the plotsdisplayPlots = true
: Boolean to display the plots or not.savePNG = false
: Boolean to save pngs of the plots to the working directory as titleText(1 of 2).png and titleText(2 of 2).pngreturnPlots = false
: Boolean to return the plots as a tuple so they can be displayed manually
Examples
julia> u0 = initialConditions();
julia> IV = inflowvector_definition();
julia> sol, tSol = ADM1sol((0.0,200.0),u0,IV); # compute the solution
julia> plotSols(sol); # display the plots
julia> u0 = initialConditions();
julia> IV = inflowvector_definition();
julia> sol, tSol = ADM1sol((0.0,200.0),u0,IV); # compute the solution
julia> plt1,plt2 = plotSols(sol,displayPlots=false,returnPlots=true); # return the plots
julia> display(plt1); # display the first plot
julia> display(plt2); # display the second plot
Functions used by solvers
ADM1jl.pressureOfGasses
— FunctionpressureOfGasses(sx,php,rp)
Compute the pressures of the gasses.
Arguments
sx::Vector
: the state vector.php::Vector
: the physicochemical parameters.rp::Vector
: the reactor parameters.
Examples
julia> u0 = initialConditions();
julia> rp = reactorParameterDefinition();
julia> php = physiochemicalParameterDefinition(rp);
julia> pressureOfGasses(u0,php,rp)
5-element Vector{Float64}:
1.6333471490625e-5
0.6525381992578124
0.35869584449999997
1.0669181223042932
2695.9061152146637
ADM1jl.monod
— Functionmonod(u, k)
Compute the monod function u/(u+k)
where u
is the state varible and k
is the half-saturation concentration.
If u <= 0
return 0
.
Examples
julia> monod(3.0,2.0) # when u is non-zero positive
0.6
julia> monod(-3.0,2.0) # when u is negative
0
ADM1jl.RHSfun
— FunctionRHSfun(du,u,p,t)
Return the right-hand side of the system of ODEs, this is an in-place function.
Arguments
du::Vector
: the rate change of the state vector (required since the function is defined in-place).u::Vector
: the state vector.p::Vector
: all of the model parameters.t
: the timestep, usually a Float64.
ADM1jl.RHSfunInflowVaried
— FunctionRHSfunInflowVaried(du,u,p,t)
Return the right-hand side of the system of ODEs, this is an in-place function.
Arguments
du::Vector
: the rate change of the state vector (required since the function is defined in-place).u::Vector
: the state vector.p::Vector
: all of the model parameters.t
: the timestep, usually a Float64.
Matrix Definition
ADM1jl.transportmatrix_definition
— Functiontransportmatrix_definition(rp,pressures)
Transport matrix
```
ADM1jl.reactionrates
— Functionreactionrates(bp,rp,php,pressures,sx,NREAC::Int)
Compute and return the vector of reaction rates.
Arguments
bp::Vector
: the biochemical parameters.rp::Vector
: the reactor parameters.php::Vector
: the physiochemical parameters.pressures::Vector
: the gas pressures.sx::Vector
: the state vector.NREAC::Integer
: the number of reaction rates.
Examples
julia> u0 = initialConditions();
julia> bp = biochemicalparameter_definition();
julia> rp = reactorParameterDefinition();
julia> php = physiochemicalParameterDefinition(rp);
julia> pressures = pressureOfGasses(u0,php,rp);
julia> NREAC = 29;
julia> reactionrates(bp,rp,php,pressures,u0,NREAC)
29-element Vector{Real}:
0.155
0.28
1.0
0.29000000000000004
0.2950855111452082
⋮
0.0
7.402547081085608e-6
1.295220255437568
0.052518812965057435
ADM1jl.petersenmatrixtranspose_definition
— Functionpetersenmatrixtranspose_definition(rp,bp,sp,cc)
Transpose of the Petersen matrix
Other Functions
ADM1jl.individualSolutions
— FunctionindividualSolutions(sol)
Rearranges the ODESolution
returned by ADM1sol
into a 1D array containing vectors of each solution over time.
i.e. A[i] is a vector containing the values of the ith solution for all times.
So, if we say t is a vector containing the timesteps, then plot(t,A[i])
will plot the ith solution vs time.
Arguments
sol::Vector
:ODESolution
returned by ADM1 sol
Examples
julia> u0 = initialConditions();
julia> IV = inflowvector_definition();
julia> sol, tSol = ADM1sol((0.0,200.0),u0,IV); # compute the solution
julia> indSols = individualSolutions(sol)
35-element Vector{Vector{Float64}}:
[0.012, 0.011999986305998722, 0.011999977102201841, 0.01199997267285494, 0.011999969386113186, 0.011999967149464337, 0.011999965091000644, 0.011999963258166062, 0.01199996178749697, 0.011999961662742068 … 0.01195750330094027, 0.011957024281388772, 0.01195654102848209, 0.011955980109704207, 0.011955371939386264, 0.011955036272014314, 0.011954879037458292, 0.011954836213455822, 0.011954830158706282, 0.011954829810563401]
[0.0053, 0.005299528080754454, 0.005299211849244109, 0.005299059933102669, 0.005298947319276687, 0.005298870740171685, 0.005298800301401363, 0.005298737615364131, 0.005298687337685513, 0.005298683073531872 … 0.00531290262808903, 0.005313145376836529, 0.005313458937485294, 0.00531386295705003, 0.0053143158605383585, 0.0053145727297110815, 0.005314697865111298, 0.00531473416356305, 0.0053147398286552405, 0.0053147401832121036]
⋮
[1.63, 1.6300010043803432, 1.630003893522008, 1.6300064891566448, 1.6300090584027846, 1.630011157417349, 1.630013359837308, 1.6300155516628245, 1.6300174749013072, 1.6300176449752604 … 1.6258740229661408, 1.6256583127128807, 1.6256250660754588, 1.625621749084325, 1.625620443499663, 1.6256197935003422, 1.6256194976733636, 1.6256194164919724, 1.6256194045086088, 1.6256194037384155]
[0.014, 0.013987846051651676, 0.01395723325778608, 0.013936637777305555, 0.013919032066060481, 0.013905958298756526, 0.01389316476641871, 0.013881173393149072, 0.013871152739877324, 0.013870287064082722 … 0.01414633009687048, 0.014149764848711631, 0.01415028486767014, 0.014150328062007254, 0.01415033918241631, 0.014150344102072282, 0.014150346161797715, 0.014150346675181056, 0.014150346741486993, 0.014150346745679485]
julia> indSols[1] # Solution vector for the first state variable (S_su)
115-element Vector{Float64}:
0.012
0.011999986305998722
⋮
0.011954830158706282
0.011954829810563401