Пример #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());
                    }
                }
            }
        }
Пример #2
0
        private void OnDoPhenology(object sender, EventArgs e)
        {
            if (PlantIsAlive)
            {
                // If this is the first time through here then setup some variables.
                if (Phases == null || Phases.Count == 0)
                {
                    OnSimulationCommencing(null, null);
                }

                CurrentlyOnFirstDayOfPhase = "";
                if (JustInitialised)
                {
                    CurrentlyOnFirstDayOfPhase = Phases[0].Start;
                    JustInitialised            = false;
                }
                double FractionOfDayLeftOver = CurrentPhase.DoTimeStep(1.0);

                if (FractionOfDayLeftOver > 0)
                {
                    // Transition to the next phase.
                    if (CurrentPhaseIndex + 1 >= Phases.Count)
                    {
                        throw new Exception("Cannot transition to the next phase. No more phases exist");
                    }

                    if (CurrentPhase is EmergingPhase)
                    {
                        Emerged = true;
                    }

                    CurrentPhase = Phases[CurrentPhaseIndex + 1];
                    if (GrowthStage != null)
                    {
                        GrowthStage.Invoke();
                    }


                    // Tell the new phase to use the fraction of day left.
                    FractionOfDayLeftOver = CurrentPhase.AddTT(FractionOfDayLeftOver);
                    Stage = CurrentPhaseIndex + 1;
                }
                else
                {
                    Stage = (CurrentPhaseIndex + 1) + CurrentPhase.FractionComplete;
                }

                _AccumulatedTT += CurrentPhase.TTForToday;

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

                Util.Debug("Phenology.CurrentPhaseName=%s", CurrentPhase.Name.ToLower());
                Util.Debug("Phenology.CurrentStage=%f", Stage);
            }
        }
Пример #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);
                }

                // 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());
                    }
                }
            }
        }
Пример #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);
                }
                // If this is the first time through here then setup some variables.
                if (Phases == null || Phases.Count == 0)
                {
                    OnSimulationCommencing(null, null);
                }

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

                double FractionOfDayLeftOver = CurrentPhase.DoTimeStep(1.0);

                if (FractionOfDayLeftOver > 0)
                {
                    while (FractionOfDayLeftOver > 0) // Transition to the next phase.
                    {
                        if (CurrentPhaseIndex + 1 >= Phases.Count)
                        {
                            throw new Exception("Cannot transition to the next phase. No more phases exist");
                        }

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

                        if ((CurrentPhase is EmergingPhase) || (CurrentPhase is BuddingPhase))
                        {
                            Plant.SendEmergingEvent();
                            Emerged = true;
                        }

                        CurrentPhase = Phases[CurrentPhaseIndex + 1];
                        if (GrowthStage != null)
                        {
                            GrowthStage.Invoke();
                        }

                        // 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 - PhaseIndexOffset;
                    }
                }
                else
                {
                    Stage = (CurrentPhaseIndex + 1) + CurrentPhase.FractionComplete - PhaseIndexOffset;
                }

                AccumulatedTT += CurrentPhase.TTForToday;

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

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

                Util.Debug("Phenology.CurrentPhaseName=%s", CurrentPhase.Name.ToLower());
                Util.Debug("Phenology.CurrentStage=%f", Stage);
            }
        }
Пример #5
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());
                    }
                }
            }
        }
Пример #6
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());
                }
            }
        }