Beispiel #1
0
        private void OnDoPhenology(object sender, EventArgs e)
        {
            if (PlantIsAlive)
            {
                if (thermalTime.Value() < 0)
                {
                    throw new Exception("Negative Thermal Time, check the set up of the ThermalTime Function in" + this);
                }

                // Calculate progression through current phase
                double propOfDayToUse = 1;
                bool   incrementPhase = CurrentPhase.DoTimeStep(ref propOfDayToUse);

                //sorghum resets the stage variable to 0 on the day the phase changes
                //it will resume again normally the day after
                double resetSorghumStage = SorghumFlag != null && incrementPhase ? 0.0 : 1.0;

                while (incrementPhase)
                {
                    if ((CurrentPhase is EmergingPhase) || (CurrentPhase.End == structure?.LeafInitialisationStage))
                    {
                        Emerged = true;
                    }

                    stagesPassedToday.Add(CurrentPhase.End);
                    if (currentPhaseIndex + 1 >= phases.Count)
                    {
                        throw new Exception("Cannot transition to the next phase. No more phases exist");
                    }

                    currentPhaseIndex = currentPhaseIndex + 1;

                    PhaseChangedType PhaseChangedData = new PhaseChangedType();
                    PhaseChangedData.StageName = CurrentPhase.Start;
                    PhaseChanged?.Invoke(plant, PhaseChangedData);

                    if (SorghumFlag != null && CurrentPhase is EmergingPhase)
                    {
                        propOfDayToUse = 0.0;
                    }
                    incrementPhase = CurrentPhase.DoTimeStep(ref propOfDayToUse);
                }

                AccumulatedTT += thermalTime.Value();
                if (Emerged)
                {
                    AccumulatedEmergedTT += thermalTime.Value();
                }

                Stage = (currentPhaseIndex + 1) + resetSorghumStage * CurrentPhase.FractionComplete;

                if (plant != null)
                {
                    if (plant.IsAlive && PostPhenology != null)
                    {
                        PostPhenology.Invoke(this, new EventArgs());
                    }
                }
            }
        }
Beispiel #2
0
        private void OnDoPhenology(object sender, EventArgs e)
        {
            if (PlantIsAlive)
            {
                if (thermalTime.Value() < 0)
                {
                    throw new Exception("Negative Thermal Time, check the set up of the ThermalTime Function in" + this);
                }

                // Calculate progression through current phase
                double propOfDayToUse = 1;
                bool   incrementPhase = CurrentPhase.DoTimeStep(ref propOfDayToUse);
                AccumulateTT(CurrentPhase.TTForTimeStep);

                while (incrementPhase)
                {
                    if ((CurrentPhase is EmergingPhase) || (CurrentPhase is BuddingPhase))
                    {
                        Emerged = true;
                    }

                    stagesPassedToday.Add(CurrentPhase.End);
                    if (currentPhaseIndex + 1 >= phases.Count)
                    {
                        throw new Exception("Cannot transition to the next phase. No more phases exist");
                    }

                    currentPhaseIndex = currentPhaseIndex + 1;

                    PhaseChangedType PhaseChangedData = new PhaseChangedType();
                    PhaseChangedData.StageName = CurrentPhase.Start;
                    PhaseChanged?.Invoke(plant, PhaseChangedData);

                    incrementPhase = CurrentPhase.DoTimeStep(ref propOfDayToUse);
                    AccumulateTT(CurrentPhase.TTForTimeStep);
                }

                Stage = (currentPhaseIndex + 1) + CurrentPhase.FractionComplete;

                if (plant != null)
                {
                    if (plant.IsAlive && PostPhenology != null)
                    {
                        PostPhenology.Invoke(this, new EventArgs());
                    }
                }
            }
        }
Beispiel #3
0
        private void OnDoPhenology(object sender, EventArgs e)
        {
            if (PlantIsAlive)
            {
                if (ThermalTime.Value() < 0)
                {
                    throw new Exception("Negative Thermal Time, check the set up of the ThermalTime Function in" + this);
                }
                // If this is the first time through here then setup some variables.

                if (CurrentlyOnFirstDayOfPhase[0] == "")
                {
                    if (JustInitialised)
                    {
                        CurrentlyOnFirstDayOfPhase[0] = phases[0].Start;
                        JustInitialised = false;
                    }
                }

                // Calculate how much of todays progress will not be consumed by current phase
                double FractionOfDayLeftOver = CurrentPhase.DoTimeStep(1.0);

                // If it is more than zero then we need to transition phases
                if (FractionOfDayLeftOver > 0)
                {
                    while (FractionOfDayLeftOver > 0)// It is possible more than one phase will be passed in a day so keep doing this until complete.
                    {
                        if (CurrentPhaseIndex + 1 >= phases.Count)
                        {
                            throw new Exception("Cannot transition to the next phase. No more phases exist");
                        }

                        if (Stage >= 1)
                        {
                            Germinated = true;
                        }

                        CurrentPhase = phases[CurrentPhaseIndex + 1];

                        // run the next phase with the left over time step from the phase we have just completed
                        FractionOfDayLeftOver = CurrentPhase.DoTimeStep(FractionOfDayLeftOver);

                        Stage = (CurrentPhaseIndex + 1) + CurrentPhase.FractionComplete;
                    }
                }
                else
                {
                    Stage = (CurrentPhaseIndex + 1) + CurrentPhase.FractionComplete;
                }

                AccumulatedTT += CurrentPhase.TTForToday;

                if (Emerged)
                {
                    AccumulatedEmergedTT += CurrentPhase.TTForToday;
                }

                if (Plant != null)
                {
                    if (Plant.IsAlive && PostPhenology != null)
                    {
                        PostPhenology.Invoke(this, new EventArgs());
                    }
                }
            }
        }
Beispiel #4
0
        private void OnDoPhenology(object sender, EventArgs e)
        {
            if (PlantIsAlive)
            {
                if (thermalTime.Value() < 0)
                {
                    throw new Exception("Negative Thermal Time, check the set up of the ThermalTime Function in" + this);
                }

                // Calculate progression through current phase
                double propOfDayToUse = 1;
                bool   incrementPhase = CurrentPhase.DoTimeStep(ref propOfDayToUse);

                //sorghum resets the stage variable to 0 on the day the phase changes
                //it will resume again normally the day after
                double resetSorghumStage = SorghumFlag != null && incrementPhase ? 0.0 : 1.0;

                while (incrementPhase)
                {
                    if ((CurrentPhase is EmergingPhase) || (CurrentPhase.End == structure?.LeafInitialisationStage) || (CurrentPhase is DAWSPhase))
                    {
                        Emerged = true;
                    }

                    stagesPassedToday.Add(CurrentPhase.End);
                    if (currentPhaseIndex + 1 >= phases.Count)
                    {
                        throw new Exception("Cannot transition to the next phase. No more phases exist");
                    }

                    currentPhaseIndex = currentPhaseIndex + 1;

                    PhaseChangedType PhaseChangedData = new PhaseChangedType();
                    PhaseChangedData.StageName = CurrentPhase.Start;
                    PhaseChanged?.Invoke(plant, PhaseChangedData);

                    if (SorghumFlag != null && CurrentPhase is EmergingPhase)
                    {
                        // void accumulate(...)
                        double dltPhase     = 1.0 + Stage % 1.0;
                        double newStage     = Math.Floor(Stage) + dltPhase;
                        double dltStage     = newStage - Stage;
                        double pIndex       = Stage;
                        double dltIndex     = dltStage;
                        double indexDevel   = pIndex - Math.Floor(pIndex) + dltIndex;
                        double portionInOld = 1 - APSIM.Shared.Utilities.MathUtilities.Divide(indexDevel - 1, dltIndex, 0);
                        propOfDayToUse = 1 - portionInOld;
                    }
                    incrementPhase = CurrentPhase.DoTimeStep(ref propOfDayToUse);
                    if (SorghumFlag != null && CurrentStageName == "Emergence")
                    {
                        AccumulatedEmergedTT -= (1 - propOfDayToUse) * thermalTime.Value();
                    }
                }

                AccumulatedTT += thermalTime.Value();
                if (Emerged)
                {
                    AccumulatedEmergedTT += thermalTime.Value();
                }

                Stage = (currentPhaseIndex + 1) + resetSorghumStage * CurrentPhase.FractionComplete;

                if (plant != null && plant.IsAlive && PostPhenology != null)
                {
                    PostPhenology.Invoke(this, new EventArgs());
                }
            }
        }