示例#1
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);
            }
        }
示例#2
0
    /// <summary>
    /// Perform our daily timestep function. Get the current phase to do its
    /// development for the day. If TT is leftover after Phase is progressed,
    /// and the timestep for the subsequent phase is calculated using leftover TT
    /// </summary>
    public void DoTimeStep()
    {
        // If this is the first time through here then setup some variables.
        if (Phases == null || Phases.Count == 0)
        {
            OnInitialised();
        }

        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");
            }

            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;
        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);
                }
                // 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);
            }
        }