Exemplo n.º 1
0
 /// <summary>
 /// /
 /// </summary>
 public override void SetStartOfDayParameters()
 {
     try
     {
         if (SoilController != null)
         {
             SoilController.SetStartOfDayParameters();
         }
         if (IrrigationController != null)
         {
             IrrigationController.SetStartOfDayParameters();
         }
         if (VegetationController != null)
         {
             VegetationController.SetStartOfDayParameters();
         }
         if (TillageController != null)
         {
             TillageController.SetStartOfDayParameters();
         }
     }
     catch (Exception e)
     {
         ControlError = "SetStartOfDayParameters";
         throw new Exception(e.Message);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        public void Run()
        {
            ResetToDefault();

            SoilController.InitialiseSoilParameters();

            //Initialse the controllers
            foreach (HLController controller in ActiveControlllers)
            {
                controller.Initialise();
            }


            while (Today <= EndDate)
            {
                this.SimulateDay();

                //Write output and go to next day
                OutputModelController.WriteDailyData();
                Today += new TimeSpan(1, 0, 0, 0);
            }

            //Output all of the summary data
            //OutputModelController.WriteToFile(false);

            //OutputModelController.Finalise();



            //Do any necessary cleaup or output

            //OutputModelController.Finalise();
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool SimulateDay()
        {
            bool result = true;

            try
            {
                ControlError = "";
                if (!FReset)
                {
                    ClimateController.Simulate();
                }
                if (!FReset)
                {
                    AdjustKeyDatesForYear();
                }
                if (!FReset)
                {
                    SetStartOfDayParameters();
                }
                if (!FReset)
                {
                    ApplyResetsIfAny();
                }
                if (!FReset)
                {
                    TryModelIrrigation();
                }
                if (!FReset)
                {
                    SoilController.TryModelSoilCracking();
                }
                if (!FReset)
                {
                    SoilController.CalculateRunoff();
                }

                if (!FReset)
                {
                    SoilController.CalculatSoilEvaporation();
                }
                //
                //if (!FReset) SoilController.UpdateWaterBalance();
                //
                if (!FReset)
                {
                    TryModelVegetation();
                }
                if (!FReset)
                {
                    SoilController.UpdateWaterBalance();
                }
                if (!FReset)
                {
                    TryModelTillage();
                }
                if (!FReset)
                {
                    SoilController.CalculateResidue();
                }
                if (!FReset)
                {
                    SoilController.CalculateErosion();
                }
                if (!FReset)
                {
                    TryModelRingTank();
                }
                if (!FReset)
                {
                    TryModelPesticide();
                }
                if (!FReset)
                {
                    TryModelPhosphorus();
                }
                if (!FReset)
                {
                    TryModelNitrate();
                }
                if (!FReset)
                {
                    TryModelSolutes();
                }
                if (!FReset)
                {
                    SoilController.TryModelLateralFlow();
                }
                if (!FReset)
                {
                    UpdateCropWaterBalance();
                }
                if (!FReset)
                {
                    SoilController.UpdateFallowWaterBalance();
                }
                if (!FReset)
                {
                    SoilController.UpdateTotalWaterBalance();
                }
                if (!FReset)
                {
                    TryUpdateRingTankWaterBalance();
                }
                //if (!FReset) SoilController.UpdateMonthlyStatistics();
                if (!FReset)
                {
                    SoilController.CalculateVolumeBalanceError();
                }
                if (!FReset)
                {
                    ExportDailyOutputs();
                }
                if (!FReset)
                {
                    ResetAnyParametersIfRequired();
                }
            }
            catch (Exception e)
            {
                result = false;

                List <string> Text = new List <string>();
                if (Today > new DateTime(1800, 1, 1) && Today < new DateTime(2100, 1, 1))
                {
                    //Text.Add("There was an error in the simulation on day " + (seriesindex + 1).ToString() + " (" + Today.ToString("dd/mm/yyyy") + ")");
                    Text.Add("There was an error in the simulation on day " + " (" + Today.ToString("dd/mm/yyyy") + ")");
                }
                if (ControlError.Length > 0)
                {
                    Text.Add("The error occurred in the function called " + ControlError);
                }
                if (Text.Count > 0 && Text.Count < 3)
                {
                    //throw (new Exception(String.Join("\n", Text.ToArray(), e.Message))); //mtError
                }
                else
                {
                    throw (new Exception("Error Simulating Day", new Exception(e.Message)));
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputDataModels"></param>
        public Simulation(Project Project, List <InputModel> inputDataModels, int startYear = 0, int endYear = 0) : this()
        {
            this.Project = Project;

            StartYear = startYear;
            EndYear   = EndYear;

            ErrorList = new List <string>();
            ZerosList = new List <string>();

            CanLog = false;

            RunSilent          = false;
            Force2011CurveNoFn = false;

            //Simulation has to have a Climate, Soil, Vegetion Controllers/Models
            ClimateController    = new ClimateController(this, new List <InputModel>(inputDataModels.Where(x => x.GetType() == typeof(ClimateInputModel))));
            VegetationController = new VegetationController(this, new List <InputModel>(inputDataModels.Where(x => x.GetType().BaseType == (typeof(VegInputModel)))));
            SoilController       = new SoilController(this, new List <InputModel>(inputDataModels.Where(x => x.GetType() == typeof(SoilInputModel))));

            //Optional Controllers/Models
            IrrigationController = FindInputModels(inputDataModels, typeof(IrrigationInputModel)) == null ? null : new IrrigationController(this, FindInputModels(inputDataModels, typeof(IrrigationInputModel)));
            TillageController    = FindInputModels(inputDataModels, typeof(TillageInputModel)) == null ? null : new TillageController(this, FindInputModels(inputDataModels, typeof(TillageInputModel)));
            PesticideController  = FindInputModels(inputDataModels, typeof(PesticideInputModel)) == null ? null : new PesticideController(this, FindInputModels(inputDataModels, typeof(PesticideInputModel)));
            PhosphorusController = FindInputModels(inputDataModels, typeof(PhosphorusInputModel)) == null ? null : new PhosphorusController(this, FindInputModels(inputDataModels, typeof(PhosphorusInputModel)));
            NitrateController    = FindInputModels(inputDataModels, typeof(NitrateInputModel)) == null ? null : new NitrateController(this, FindInputModels(inputDataModels, typeof(NitrateInputModel)));
            SolutesController    = FindInputModels(inputDataModels, typeof(SolutesInputModel)) == null ? null : new SolutesController(this, FindInputModels(inputDataModels, typeof(SolutesInputModel)));
            //ModelOptionsController = FindInputModels(inputDataModels, typeof(ModelOptionsInputModel)) == null ? null : new ModelOptionsController(this, FindInputModels(inputDataModels, typeof(ModelOptionsInputModel)));
            //There is no XML definition found yet
            ModelOptionsController = new ModelOptionsController(this);

            //Add the non-null controllers to the activecontroller list
            List <PropertyInfo> controllers = new List <PropertyInfo>(this.GetType().GetProperties().Where(
                                                                          x => x.PropertyType.BaseType == typeof(HLController) || x.PropertyType.BaseType == typeof(HLObjectController)));

            ActiveControlllers = new List <HLController>();

            ActiveControlllers.Add(this);

            foreach (PropertyInfo p in controllers)
            {
                if (p.GetValue(this) != null)
                {
                    ActiveControlllers.Add((HLController)p.GetValue(this));
                }
            }

            //Instantiate the output controller
            //This is now done in the Project as it has the relevant path and setup information
            OutputModelController = new OutputModelController(this);

            //Set the start date and end dates
            if (StartYear == 0)
            {
                StartDate = new DateTime(ClimateController.InputModel.StartDate.Value.Ticks);
            }
            else
            {
                StartDate = new DateTime(StartYear, 1, 1);
            }

            if (EndYear == 0)
            {
                EndDate = new DateTime(ClimateController.InputModel.EndDate.Value.Ticks);
            }
            else
            {
                EndDate = new DateTime(EndYear, 12, 31);
            }

            Today = StartDate;
        }