Exemple #1
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();
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        public void ReadXml(XmlReader reader)
        {
            XDocument doc = XDocument.Load(reader);

            //Get the list of models
            XElement projectElement = doc.Element("Project");

            //Set the project properties
            CreatedBy = XMLUtilities.readXMLAttribute(projectElement.Attribute("CreatedBy"));
            DateTime?createdDate = DateUtilities.TryParseDate(XMLUtilities.readXMLAttribute(projectElement.Attribute("CreationDate")).Split(new char[] { ' ' })[0], "dd/MM/yyyy");

            CreatedDate    = createdDate == null ? new DateTime(1, 1, 1) : createdDate.Value;
            ContactDetails = XMLUtilities.readXMLAttribute(projectElement.Attribute("ContactDetails"));
            ModifiedBy     = XMLUtilities.readXMLAttribute(projectElement.Attribute("ModifiedBy"));

            Name = projectElement.Element("Name").Value.ToString();

            //Read all of the climate data models
            List <XElement> ClimateDatalements = new List <XElement>(projectElement.Elements("ClimateData").Elements("DataFile"));

            //Read all of the models
            List <XElement> TemplateElements = new List <XElement>(projectElement.Elements().Where(x => x.Name.ToString().Contains("Templates")));
            List <XElement> TypeElements     = new List <XElement>();

            foreach (XElement te in TemplateElements)
            {
                foreach (XElement xe in te.Elements())
                {
                    TypeElements.Add(xe);
                }
            }
            //Read all of the simualtions
            SimulationElements = new List <XElement>();

            foreach (XElement simChild in projectElement.Elements("Simulations").Elements())
            {
                if (simChild.Name.ToString() == "SimulationObject")
                {
                    SimulationElements.Add(simChild);
                }
                else if (simChild.Name.ToString() == "Folder")
                {
                    SimulationElements.AddRange(simChild.Elements("SimulationObject"));
                }
            }

            InputDataModels = new List <InputModel>();

            //Create input models from the xml elements
            foreach (XElement xe in TypeElements)
            {
                InputDataModels.Add(RawInputModelFactory.GenerateRawInputModel(xe));
            }

            //Create the Climate models - these aren't deserialised so don't come out of the factory
            foreach (XElement xe in ClimateDatalements)
            {
                ClimateInputModel cim = new ClimateInputModel();
                cim.FileName = xe.Attribute("href").Value.ToString();
                InputDataModels.Add(cim);
            }

            //Initialise the models
            foreach (InputModel im in InputDataModels)
            {
                im.Init();
            }

            //Create the simualtions
            foreach (XElement xe in SimulationElements)
            {
                Simulations.Add(SimulationFactory.GenerateSimulationXML(this, xe, InputDataModels));
            }

            //Just one for testing
            //Simulations = new List<Simulation>();
            //Simulations.Add(SimulationFactory.GenerateSimulationXML(SimulationElements[0], InputDataModels));

            OutputDataElements = OutputModelController.GetProjectOutputs(this);
        }
Exemple #3
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;
        }