System creation
PlantModules.generate_system — Function
generate_system(plantstructure::PlantStructure, plantparams::PlantParameters,
plantcoupling::PlantCoupling)Create a ModelingToolkit.System that describes the functional behaviour of the input graph structure.
Arguments
plantstructure: A graph specifying how the structural modules are connected.plantparams: Additional functional information about the connections between structural modules. SeePlantParameters.plantcoupling: Coupling between functional and structural modules. SeePlantCoupling.
PlantModules.PlantStructure — Type
PlantStructure{T} <: AbstractGraph{T}The internal graph implementation used for generate_system.
Constructor
PlantStructure(graphs::Vector, intergraph_connections::Vector; return_id_conversions::Bool = false)Connect graphs together into a single PlantStructure graph.
Warning: This function defines its own node ids to simplify the integration with the rest of the Graphs.jl ecosystem.
Inputs:
graphs::Vector: A vector of graphs representing the plants and their environment.intergraph_connections::Vector: A vector of pairs between 2 indexes of above graphs and how they are linked.return_id_conversions::Bool: Should the function return a dictionary mapping the newly defined node ids to the original nodes?
Alternatives
Other graph implementations can also be used by extending the following functions:
PlantModules.PlantCoupling — Type
PlantCouplingA container for the coupling of plant structure and function. Used in generate_system.
Fields
module_coupling::Dict: Coupling between functional and structural modules.connecting_modules::Dict{Tuple{Symbol, Symbol}, Function}: TheSystemto use for edges between specified nodes.connecting_eqs::Function: A function returning a vector of equations linking a node and all its edges.
PlantModules.PlantParameters — Type
PlantParametersA container for functional parameters. Used in generate_system.
Fields
default_values::Dict{Symbol, <:Any}: The model-wide default values of parameters and initial values.module_defaults::Dict{Symbol, Dict}: Module-specific default values of parameters and initial values.connection_values::Dict{Tuple{Symbol, Symbol}, Dict}: Connection-specific values of parameters and initial values.
Shapes
PlantModules.ModuleShape — Type
ModuleShapeAn abstract type representing the physical shape of a structural module, used by the hydraulic functional module.
Functions
The functional modules implemented in this package expect the following functions to be defined for the shape MyShape with dimensions the vector D:
getdimensionality(m::MyShape): Return how many dimensions define the shape.volume(m::MyShape, D): Calculate the volume of the shape.cross_area(m::MyShape, D): Calculate the cross-sectional area of the shape.surface_area(m::MyShape, D): Calculate the surface area of the shape.
PlantModules.Sphere — Type
Sphere <: ModuleShapeA spherical compartment shape, defined by a single dimension: the radius.
PlantModules.Cylinder — Type
Cylinder <: ModuleShapeA cylindrical compartment shape, defined by two dimensions: the radius and the length.
PlantModules.Cuboid — Type
Cuboid <: ModuleShapeA cuboidal compartment shape, defined by three dimensions: the length, the width and the thickness.
Graph functions
PlantModules.getnodes — Function
getnodes(graph)Returns a Vector containing all nodes of the given graph.
PlantModules.getneighbors — Function
getneighbors(node, graph)Returns a Vector containing the neighbours of the given node.
PlantModules.getattributes — Function
getattributes(node)Returns a Dict containing the functional variable names and values of the given node.
PlantModules.getstructmod — Function
getstructmod(node)Returns the structural module corresponding with the node as a Symbol.
PlantModules.getid — Function
getid(node)Returns the id of the node as an Int.
PlantModules.getroot — Function
getroot(graph)Returns the root node of the graph.
PlantModules.getvariables — Function
getvariables(sol::ODESolution, graph; varname = missing, structmod = missing)Return the Numeric representation of one or more variables from a graph, optionally filtered by structural module.
PlantModules.getchildren — Function
getchildren(node, graph)Returns the child nodes of a node.
PlantModules.getparent — Function
getparent(node, graph)Returns the parent node of a node.
Shape functions
PlantModules.getdimensionality — Function
getdimensionality(s::ModuleShape)Return the number of dimensions that define shape s.
PlantModules.correctdimensionality — Function
correctdimensionality(s::ModuleShape, var)Correct the dimensions of a variable var to match the number of dimensions of shape s.
If var is a scalar, return a vector of the length matching s with the value of var used for every dimension. If var is an array, either return the same vector if the dimensions match or throw an error if they do not.
PlantModules.volume — Function
volume(s::ModuleShape, ::AbstractArray)Calculate the volume of a given shape.
volume(::Sphere, D::AbstractArray)Calculate the volume of a sphere.
volume(::Cylinder, D::AbstractArray)Calculate the volume of a cylinder. Dimensions are assumed to be in the order: radius, length.
volume(::Cuboid, D::AbstractArray)Calculate the volume of a cuboid.
PlantModules.cross_area — Function
cross_area(s::ModuleShape, ::AbstractArray)Calculate the cross-sectional area of a given shape.
cross_area(::Sphere, D::AbstractArray)Calculate the cross-sectional area of a sphere, defined as the area of a circle with the same radius.
cross_area(::Cylinder, D::AbstractArray)Calculate the cross-sectional area of a cylinder, defined as its base area. Dimensions are assumed to be in the order: radius, length.
cross_area(::Cuboid, D::AbstractArray)Calculate the cross-sectional area of a cuboid, defined as the product of its first two dimensions.
PlantModules.surface_area — Function
surface_area(s::ModuleShape, ::AbstractArray)Calculate the surface area of a given shape.
surface_area(::Sphere, D::AbstractArray)Calculate the surface area of a sphere.
surface_area(::Cylinder, D::AbstractArray)Calculate the surface area of a cylinder. Dimensions are assumed to be in the order: radius, length.
surface_area(::Cuboid, D::AbstractArray)Calculate the surface area of a cuboid.
Smooth functions
PlantModules.logsumexp — Function
logsumexp(xs::AbstractArray; α = 1.0)Return the smoothed maximum of an array, where α controls the steepness of the smoothing.
logsumexp(x; α = 1.0)Return the smoothed maximum of the argument and zero.
PlantModules.smooth_daynight — Function
smooth_daynight(t, t_sunrise, t_sunset, ymin = 0, ymax = 1)Return a value that smoothly switches between ymax at day and ymin at night.
Node modules
PlantModules.hydraulic_module — Function
hydraulic_module(; name, shape, ϕ_D, E_D, Γ, T, D, Ψ, M)Return a ModelingToolkit System describing the turgor-driven growth of a plant compartment.
This module still requires a module describing the osmotically active metabolite content M.
Inputs
Parameters
shape: The shape, defined as an instance ofPlantModules.ModuleShape.ϕ_D: The dimensional extensibility [1 / MPa / h], must be a vector with a value for every dimension of the compartment's shape.E_D: The dimensional elastic modulus [MPa], must be a vector with a value for every dimension of the compartment's shape.Γ: The yield turgor pressure [MPa].T: The temperature [K].
Initial values
D: The dimensions [cm], must be a vector with a value for every dimension of the compartment's shape.Ψ: The total water potential [MPa].M: The osmotically active metabolite concentration [mol/cm^3].h: The height above a chosen reference level [cm].
PlantModules.environmental_module — Function
environmental_module(; name, T, W_max, W_r)Return a ModelingToolkit System describing a non-growing water reservoir.
This module still requires a module describing the total water potential Ψ.
Inputs
Parameters
T: The temperature [K].W_max: The water capacity of the compartment [g].
Initial values
W_r: The relative water content, equal to the ratio of the current water contentWover the water capacityW_max[g/g].
PlantModules.constant_carbon_module — Function
constant_carbon_module(; name, M)Return a ModelingToolkit System describing a constant concentration of osmotically active metabolite content.
Inputs
Initial values
M: The osmotically active metabolite concentration [mol/cm^3].
PlantModules.simple_photosynthesis_module — Function
simple_photosynthesis_module(; name, M, shape)Return a ModelingToolkit System describing a concentration of osmotically active metabolite content increasing during day and decreasing in function of the current concentration.
Inputs
Parameters
shape: The shape, defined as an instance ofPlantModules.ModuleShape.t_sunrise: The time of sunrise [h].t_sunset: The time of sunset [h].A_max: The maximum carbon assimilation rate [mol / cm^2 / h].M_c: The rate of carbon consumption [1 / h].
Initial values
M: The osmotically active metabolite concentration [mol/cm^3].
PlantModules.Ψ_soil_module — Function
Ψ_soil_module(; name)Return a ModelingToolkit System describing an empirical relationship between the total water potential of the soil and its relative water content.
Inputs
None.
PlantModules.Ψ_air_module — Function
Ψ_air_module(; name, T)Return a ModelingToolkit System describing the relationship between the total water potential of the air and its relative water content.
Inputs
Parameters
T: The temperature [K].
PlantModules.K_module — Function
K_module(; name, K_s, shape::ModuleShape)Return a ModelingToolkit System describing the hydraulic conductance of a compartment as the product of its specific hydraulic conductance and an area of the compartment.
Inputs
Parameters
shape: The shape, defined as an instance ofPlantModules.ModuleShape.K_s: The specific hydraulic conductivity, defined per unit area of the cross section [g / h / MPa / cm^2].
PlantModules.constant_K_module — Function
constant_K_module(; name, K_s, shape::ModuleShape)Return a ModelingToolkit System describing the hydraulic conductance of a compartment as a constant.
Inputs
Parameters
K: The hydraulic conductivity [g / h / MPa].
Edge modules
PlantModules.hydraulic_connection — Function
hydraulic_connection(; name)Returns a ModelingToolkit System describing a water flow connection between two hydraulics-based compartments.
This module assumes the compartments have a specified hydraulic conductivities.
Inputs
None.
PlantModules.constant_hydraulic_connection — Function
constant_hydraulic_connection(; name, K)Returns a ModelingToolkit System describing a water flow connection between two hydraulics-based functional modules.
This module specifies a constant hydraulic conductivity between the compartments.
Inputs
Parameters
K: The hydraulic conductivity [g / h / MPa].
PlantModules.daynight_hydraulic_connection — Function
daynight_hydraulic_connection(; name, t_sunrise, t_sunset, η_night)Returns a ModelingToolkit System describing a water flow connection between two hydraulics-based compartments that decreases at night.
This module assumes the compartments have a specified hydraulic conductivities.
Inputs
Parameters
t_sunrise: The time of sunrise [h].t_sunset: The time of sunset [h].η_night: The ratio of the hydraulic conductivity at night over the default hydraulic conducivity.
Graph reading and converting
PlantModules.readXEG — Function
readXEG(file::String)Reads in the graph from a given XEG format file.
PlantModules.convert_to_MTG — Function
convert_to_MTG(graph)Convert a graph to MultiScaleTreeGraph.jl format. Requires definition of standard graph functions and tree graph functions (see graph_functions.jl)
PlantModules.convert_to_PG — Function
convert_to_PG(graph)Convert a graph to PlantGraphs.jl format. Requires definition of standard graph functions and tree graph functions (see graph_functions.jl)
System remaking
PlantModules.remake_graphsystem — Function
remake_graphsystem(prob::AbstractSciMLProblem, sys::System, structure, varnames, subsystem_types, value)Remake the given prob, changing the values of subsystem variables to a specified value. Only variables of given names and subsystem types are changed.
Inputs
prob::AbstractSciMLProblem: A SciML problem.sys::System: The ModelingToolkit.jl system corresponding to the given problem.structure: A graph representing the subsystem structure of the system. PlantModules' graph functions must be extended for the graph type. See alsoPlantStructure.varnames: The name(s) of the desired variable.subsystem_types: The desired type(s) of subsystem. For node modules, this corresponds to a node or a structural module. For edge modules (or connection modules), this corresponds to a connection, being a 2-tuple of node(s) and structural module(s).value: The new variable value.
PlantModules.remake_graphsystem! — Function
remake_graphsystem!(prob::AbstractSciMLProblem, sys::System, structure, varnames::Symbol, subsystem_types, value)Mutating version of remake_graphsystem.
PlantModules.get_subsystem_variables — Function
get_subsystem_variables(sys::System, structure, varname::Symbol, subsystem_type)Get the Symbolics representation of all variables (unknowns or parameters) of a system with a given subsystem structure, filtered by variable name and type of subsystem. See remake_graphsystem for more information about the inputs.
Plotting
PlantModules.plotstructure — Function
plotstructure(plantstructure::PlantStructure)Visualise the structure of a plant system.
This function is a thin wrapper around Plots.graphplot with some keyword arguments specified for plant structures.
PlantModules.plotgraph — Function
plotgraph(sol::ODESolution, graph; structmod, varname, kwargs...)Return a plot for every functional variable for every node of the given graph for the given solution sol. Optionally, the user can give the name of a functional variable to only return a plot of this variable, give the name of a structural module to limit considered nodes to those of this type, or both.
PlantModules.plotnode — Function
plotnode(sol::ODESolution, node; varname::Symbol)Return a plot for every functional variable of the given node for the given solution sol. Optionally, the user can give the name of a functional variable to only return a plot of this variable.