Skip to content
Snippets Groups Projects
Commit d42adbbd authored by Kottelenberg, David's avatar Kottelenberg, David
Browse files

Fixed a bug in source calculation. Cleaned up some of the code.

parent a7c3c774
No related branches found
No related tags found
No related merge requests found
......@@ -65,76 +65,52 @@ module Plant
abstract type PhotosynthesisOrgan <: GrowingOrgan end # Organs that can photosynthesize
@with_kw mutable struct OrganInfo
BB::BranchBase
Species::Int64
PlantNumber::Int64
Order::Int64
BB::BranchBase # Every organ belongs to a specific branch which has a branch base object that stores variables of that branch
Species::Int64 # Species number to which organ belongs
PlantNumber::Int64 # Plant number to which organ belongs
Order::Int64 # Order, nr of branches removed from main stem (0: main stem)
Age::Int64 = 0
AgeDD::Float64 = 0.0
Age::Int64 = 0 # Age in days
AgeDD::Float64 = 0.0 # Age in degree days
end
@with_kw mutable struct GrowthVars
PotentialBiomass::Float64
GrowthDuration::Float64
MaxGrowthAge::Float64
GrowthRespiration::Float64
MaxSinkStrength::Float64
Biomass::Float64 = 0.0
Growth::Float64 = 0.0
SinkStrength::Float64 = 0.0
AssimilatesAvailable::Float64 = 0.0
AssimilatesAllocated::Float64 = 0.0
Area::Float64 = 0.0
PotentialBiomass::Float64 # Potential maximum biomass of organ
GrowthDuration::Float64 # Duration of organ growth (days)
MaxGrowthAge::Float64 # Age of organ at which organ growth is highest
GrowthRespiration::Float64 # Growth respiration of organ (fraction of biomass)
MaxSinkStrength::Float64 # Maximum possible sink strength of organ
Biomass::Float64 = 0.0 # Biomass of organ (g)
Growth::Float64 = 0.0 # Growth rate of organ at current time point
SinkStrength::Float64 = 0.0 # Sink strength of organ at current time point
AssimilatesAvailable::Float64 = 0.0 # Amount of assimilates that are available for organ growth at this time step (mg)
AssimilatesAllocated::Float64 = 0.0 # Amount of assimilates that are allocated for organ growth at this time step (mg)
Area::Float64 = 0.0 # Area of organ
end
@with_kw mutable struct PhotosynthesisVars
Assimilated::Float64 = 0.0
Assimilated::Float64 = 0.0 # Amount of CO2 acquired at current time point (mol CO2)
end
# Define internode
@with_kw mutable struct Internode <: PhotosynthesisOrgan
OI::OrganInfo
GV::GrowthVars
PV::PhotosynthesisVars
#BB::BranchBase # Every internode belongs to a specific branch which has a branch base object that stores variables of that branch
#Species::Int64 # Species number to which internode belongs
#PlantNumber::Int64 # Plant number to which internode belongs
#Order::Int64 # Order of internode, nr of branches removed from main stem (0: main stem)
OI::OrganInfo # Object containing general organ information
GV::GrowthVars # Object containing growth variables
PV::PhotosynthesisVars # Object containing photosynthesis variables
SIL::Float64 # Specific internode length: ratio of internode length per biomass (mm/mg) // Parameter
#PotentialBiomass::Float64 # Potential maximum biomass of internode // Parameter
#GrowthDuration::Float64 # Duration of internode growth (days) // Parameter
#MaxGrowthAge::Float64 # Age of internode at which internode growth is highest // Parameter
#GrowthRespiration::Float64 # Growth respiration of internode (fraction of biomass) // Parameter
#MaxSinkStrength::Float64 # Maximum possible sink strength of internode
#Age::Int64 = 0 # Age of internode in days
#AgeDD::Float64 = 0.0 # Age of internode in degree days
Length::Float64 = 0.0 # Length of internode
Width::Float64 = 0.0 # Width of internode
#Biomass::Float64 = 0.0 # Biomass of internode (g)
#Growth::Float64 = 0.0 # Growth rate of internode at current time point
#SinkStrength::Float64 = 0.0 # Sink strength of internode at current time point
#AssimilatesAvailable::Float64 = 0.0 # Amount of assimilates that are available for internode growth at this time step (mg)
#AssimilatesAllocated::Float64 = 0.0 # Amount of assimilates that are allocated for internode growth at this time step (mg)
#Area::Float64 = 0.0 # Area of internode
#Assimilated::Float64 = 0.0 # Amount of CO2 acquired at current time point (mol CO2)
Width::Float64 = 0.0 # Width of internode
end
# Define meristem, the organ that is the source of phytomer creation
@with_kw mutable struct Meristem <: Organ
OI::OrganInfo
#BB::BranchBase # Every meristem belongs to a specific branch which has a branch base object that stores variables of that branch
#Species::Int64 # Species number to which meristem belongs
#PlantNumber::Int64 # Plant number to which meristem belongs
OI::OrganInfo # Object containing general organ information
Phyllotaxis::Float64 # Phyllotaxis for phytomer construction (degrees) // Parameter
#Order::Int64 # Order of meristem, nr of branches removed from main stem (0: main stem)
Rank::Int64 # Phytomer rank of meristem
ParentRank::Int64 = 0 # Rank of parent phytomer
#Age::Int64 = 0 # Age of meristem in days
#AgeDD::Float64 = 0.0 # Age of meristem in degree days
Dormant::Bool = true # Whether the meristem can develop
Dominance::Float64 = 0.0 # Dominance of the meristem, deciding factor in branching
PhytomerNumber::Int64 = 0 # Number of phytomers from meristem to base
......@@ -142,30 +118,12 @@ module Plant
# Define leaf
@with_kw mutable struct Leaf <: PhotosynthesisOrgan
OI::OrganInfo
GV::GrowthVars
PV::PhotosynthesisVars
#BB::BranchBase # Every leaf belongs to a specific branch which has a branch base object that stores variables of that branch
#Species::Int64 # Species number to which leaf belongs
#PlantNumber::Int64 # Plant number to which leaf belongs
#Order::Int64 # Order of leaf, nr of branches removed from main stem (0: main stem)
OI::OrganInfo # Object containing general organ information
GV::GrowthVars # Object containing growth variables
PV::PhotosynthesisVars # Object containing photosynthesis variables
Angle::Float64 # Angle of leaf insertion at phytomer construction // Parameter?
#PotentialBiomass::Float64 # Potential maximum biomass of leaf // Parameter
#GrowthDuration::Float64 # Duration of leaf growth (days) // Parameter
#MaxGrowthAge::Float64 # Age of leaf at which leaf growth is highest // Parameter
#GrowthRespiration::Float64 # Growth respiration of leaf (fraction of biomass) // Parameter
#MaxSinkStrength::Float64 # Maximum possible sink strength of leaf
#Age::Int64 = 0 # Age of leaf in days
#AgeDD::Float64 = 0.0 # Age of leaf in degree days
Size::Float64 = 0.0 # Size of leaf
#Biomass::Float64 = 0.0 # Biomass of leaf (g)
#Growth::Float64 = 0.0 # Growth rate of leaf at current time point
#SinkStrength::Float64 = 0.0 # Sink strength of leaf at current time point
#AssimilatesAvailable::Float64 = 0.0 # Amount of assimilates that are available for leaf growth at this time step (mg)
#AssimilatesAllocated::Float64 = 0.0 # Amount of assimilates that are allocated for leaf growth at this time step (mg)
#Area::Float64 = 0.0 # Area of leaf
#Assimilated::Float64 = 0.0 # Amount of CO2 acquired at current time point (mol CO2)
end
@with_kw mutable struct Seed <: VPL.Node
......@@ -174,12 +132,7 @@ module Plant
Endosperm::Float64 # Biomass in seed (mg)
end
##
##
## TRY MACROS. SEE BOOKMARK
##
##
# Add methods for getproperty function such that the composite fields can be accessed directly
function Base.getproperty(O::Organ, S::Symbol)
if hasfield(OrganInfo, S)
return getfield(O.OI, S)
......@@ -192,22 +145,6 @@ module Plant
end
end
#=function Base.getproperty(GO::GrowingOrgan, S::Symbol)
if hasfield(GrowthVars, S)
return getfield(GO.GV, S)
else
return getfield(GO, S)
end
end
function Base.getproperty(PO::PhotosynthesisOrgan, S::Symbol)
if hasfield(PhotosynthesisVars, S)
return getfield(PO.PV, S)
else
return getfield(PO, S)
end
end
=#
function Base.setproperty!(O::Organ, S::Symbol, X)
if hasfield(OrganInfo, S)
return setfield!(O.OI, S, X)
......@@ -220,23 +157,6 @@ module Plant
end
end
#=function Base.setproperty!(GO::GrowingOrgan, S::Symbol, X)
if hasfield(GrowthVars, S)
return setfield!(GO.GV, S, X)
else
return setfield!(GO, S, X)
end
end
function Base.setproperty!(PO::PhotosynthesisOrgan, S::Symbol, X)
if hasfield(PhotosynthesisVars, S)
return setfield!(PO.PV, S, X)
else
return setfield!(PO, S, X)
end
end
=#
# Define organ creation functions
function createInternode(MR, BB, Order)
Species = data(MR).Species
......@@ -332,10 +252,10 @@ module Plant
Leaves = apply(Plant, getLeaf)
SourceStrength::Float64 = 0.0
if length(Internodes) > 0
SourceStrength += sum([x.SinkStrength for x in Internodes])
SourceStrength += sum([x.Assimilated for x in Internodes])
end
if length(Leaves) > 0
SourceStrength += sum([x.SinkStrength for x in Leaves])
SourceStrength += sum([x.Assimilated for x in Leaves])
end
PB.Substrates = max(((SourceStrength * MassCO2 * 0.001) - (PB.Respiration * PB.Biomass)) * ConversionCO2 + PB.ReservePool, 0)
if length(Internodes) + length(Leaves) > 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment