Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9434 Accumulate Function Resetting at Harvest #9496

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Models/Functions/AccumulateByNumericPhase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ private void OnCut(object sender, EventArgs e)
/// <summary>Called when [cut].</summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
[EventSubscribe("Harvesting")]
private void OnHarvest(object sender, EventArgs e)
[EventSubscribe("PostHarvesting")]
private void OnPostHarvesting(object sender, EventArgs e)
{
AccumulatedValue -= FractionRemovedOnHarvest * AccumulatedValue;
}
Expand Down
4 changes: 2 additions & 2 deletions Models/Functions/AccumulateFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ private void OnCut(object sender, EventArgs e)
/// <summary>Called when harvest.</summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
[EventSubscribe("Harvesting")]
private void OnHarvest(object sender, EventArgs e)
[EventSubscribe("PostHarvesting")]
private void OnPostHarvesting(object sender, EventArgs e)
{
AccumulatedValue -= FractionRemovedOnHarvest * AccumulatedValue;
}
Expand Down
11 changes: 9 additions & 2 deletions Models/PMF/BiomassArbitration/Organ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ namespace Models.PMF

public class Organ : Model, IOrgan, IHasDamageableBiomass
{
///0. Redundant satisification of IOrgan
///--------------------------------------------------------------------------------------------------
/// <summary>Harvest the organ.</summary>
/// <returns>The amount of biomass (live+dead) removed from the plant (g/m2).</returns>
public double Harvest()
Expand Down Expand Up @@ -388,6 +386,15 @@ protected void OnPlantSowing(object sender, SowingParameters data)
}
}

/// <summary>Called when crop is harvested</summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
[EventSubscribe("PostHarvesting")]
protected void OnPostHarvesting(object sender, EventArgs e)
{
Harvest();
}

/// <summary>
/// set initial biomass for organ
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions Models/PMF/Organs/GenericOrgan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -563,5 +563,14 @@ protected void OnPlantEnding(object sender, EventArgs e)

Clear();
}

/// <summary>Called when crop is harvested</summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
[EventSubscribe("PostHarvesting")]
protected void OnPostHarvesting(object sender, EventArgs e)
{
Harvest();
}
}
}
9 changes: 9 additions & 0 deletions Models/PMF/Organs/HIReproductiveOrgan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ private void OnPlantEnding(object sender, EventArgs e)
Clear();
}

/// <summary>Called when crop is harvested</summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
[EventSubscribe("PostHarvesting")]
protected void OnPostHarvesting(object sender, EventArgs e)
{
Harvest();
}

/// <summary>Gets the hi.</summary>
/// <value>The hi.</value>
public double HI
Expand Down
9 changes: 9 additions & 0 deletions Models/PMF/Organs/Leaf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,15 @@ private void OnHarvesting(object sender, EventArgs e)
CohortsAtInitialisation = 0;
}

/// <summary>Called when crop is harvested</summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
[EventSubscribe("PostHarvesting")]
protected void OnPostHarvesting(object sender, EventArgs e)
{
Harvest();
}

/// <summary>Called when [do daily initialisation].</summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
Expand Down
9 changes: 9 additions & 0 deletions Models/PMF/Organs/Nodule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -581,5 +581,14 @@ protected void OnPlantEnding(object sender, EventArgs e)
Clear();
}

/// <summary>Called when crop is harvested</summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
[EventSubscribe("PostHarvesting")]
protected void OnPostHarvesting(object sender, EventArgs e)
{
Harvest();
}

}
}
9 changes: 9 additions & 0 deletions Models/PMF/Organs/PerennialLeaf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,15 @@ protected void OnPlantEnding(object sender, EventArgs e)
Clear();
}

/// <summary>Called when crop is harvested</summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
[EventSubscribe("PostHarvesting")]
protected void OnPostHarvesting(object sender, EventArgs e)
{
Harvest();
}

/// <summary>Called when [phase changed].</summary>
/// <param name="phaseChange">The phase change.</param>
/// <param name="sender">Sender plant.</param>
Expand Down
10 changes: 10 additions & 0 deletions Models/PMF/Organs/ReproductiveOrgan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,16 @@ private void OnDoActualPlantGrowth(object sender, EventArgs e)
if (Phenology.OnStartDayOf(RipeStage))
_ReadyForHarvest = true;
}

/// <summary>Called when crop is harvested</summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
[EventSubscribe("PostHarvesting")]
protected void OnPostHarvesting(object sender, EventArgs e)
{
Harvest();
}

/// <summary>Sets the dry matter potential allocation.</summary>
public void SetDryMatterPotentialAllocation(BiomassPoolType dryMatter)
{
Expand Down
9 changes: 8 additions & 1 deletion Models/PMF/Organs/Root.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,13 @@ private void OnPlantEnding(object sender, EventArgs e)
Clear();
}


/// <summary>Called when crop is harvested</summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
[EventSubscribe("PostHarvesting")]
protected void OnPostHarvesting(object sender, EventArgs e)
{
Harvest();
}
}
}
9 changes: 9 additions & 0 deletions Models/PMF/Organs/SimpleLeaf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,15 @@ protected void OnPlantEnding(object sender, EventArgs e)
Clear();
}

/// <summary>Called when crop is harvested</summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
[EventSubscribe("PostHarvesting")]
protected void OnPostHarvesting(object sender, EventArgs e)
{
Harvest();
}

/// <summary>Remove biomass from organ.</summary>
/// <param name="liveToRemove">Fraction of live biomass to remove from simulation (0-1).</param>
/// <param name="deadToRemove">Fraction of dead biomass to remove from simulation (0-1).</param>
Expand Down
9 changes: 9 additions & 0 deletions Models/PMF/Organs/SorghumLeaf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,5 +1351,14 @@ private void DoPlantEnding(object sender, EventArgs e)
Clear();
}

/// <summary>Called when crop is harvested</summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
[EventSubscribe("PostHarvesting")]
protected void OnPostHarvesting(object sender, EventArgs e)
{
Harvest();
}

}
}
7 changes: 4 additions & 3 deletions Models/PMF/Plant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@ public double LAI
public event EventHandler Sowing;
/// <summary>Occurs when a plant is sown.</summary>
public event EventHandler<SowingParameters> PlantSowing;
/// <summary>Occurs when a plant is about to be harvested.</summary>
/// <summary>Occurs when a plant is about to be harvested so that values can be reported.</summary>
public event EventHandler Harvesting;
/// <summary>Occurs when a plant is harvested, this event should trigger functions that remove biomass from organs and reset values</summary>
public event EventHandler PostHarvesting;
/// <summary>Occurs when a plant is ended via EndCrop.</summary>
public event EventHandler PlantEnding;
/// <summary>Occurs when a plant is about to flower</summary>
Expand Down Expand Up @@ -368,8 +370,7 @@ public void Harvest(bool removeBiomassFromOrgans = true)
Phenology.SetToEndStage();
Harvesting?.Invoke(this, EventArgs.Empty);
if (removeBiomassFromOrgans)
foreach (var organ in Organs)
organ.Harvest();
PostHarvesting?.Invoke(this, EventArgs.Empty);
}

/// <summary>End the crop.</summary>
Expand Down