public void TestArrayRangeWithStartAndEndSpecification() { var mod = new MockModel() { Z = new double[] { 1, 2, 3 } }; simulation.Children.Add(mod); simulation.Children.Remove(storage); var datastore = new DataStore(); simulation.Children.Add(datastore); Apsim.InitialiseModel(simulation); Apsim.InitialiseModel(simulation); report.VariableNames = new string[] { "[MockModel].Z[2:3]" }; Assert.IsNull(runner.Run()); datastore.Writer.Stop(); var data = datastore.Reader.GetData("Report"); var columnNames = DataTableUtilities.GetColumnNames(data); Assert.IsFalse(columnNames.Contains("MockModel.Z(0)")); Assert.IsFalse(columnNames.Contains("MockModel.Z(1)")); Assert.IsTrue(columnNames.Contains("MockModel.Z(2)")); Assert.IsTrue(columnNames.Contains("MockModel.Z(3)")); Assert.IsFalse(columnNames.Contains("MockModel.Z(4)")); Assert.AreEqual(DataTableUtilities.GetColumnAsDoubles(data, "MockModel.Z(2)"), new double[] { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }); Assert.AreEqual(DataTableUtilities.GetColumnAsDoubles(data, "MockModel.Z(3)"), new double[] { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }); }
public void TestGroupBySpecification() { report.EventNames = new string[] { "[Clock].EndOfSimulation" }; report.GroupByVariableName = "[Mock].A"; var model = new MockModelValuesChangeDaily (aDailyValues: new double[] { 1, 1, 1, 2, 2, 2, 3, 3, 3, 3 }, bDailyValues: new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }) { Name = "Mock" }; simulation.Children.Add(model); Apsim.InitialiseModel(simulation); report.VariableNames = new string[] { "[Clock].Today", "sum of [Mock].B from [Clock].StartOfSimulation to [Clock].EndOfSimulation as SumA" }; Assert.IsNull(runner.Run()); Assert.AreEqual(storage.Get <double>("SumA"), new double[] { 6, 15, 34 }); Assert.AreEqual(storage.Get <DateTime>("Clock.Today"), new DateTime[] { new DateTime(2017, 1, 3), new DateTime(2017, 1, 6), new DateTime(2017, 1, 10) }); }
public void Setup() { simulation = new Simulation() { Children = new List <Model>() { new MockStorage(), new MockSummary(), new Clock() { StartDate = new DateTime(2017, 1, 1), EndDate = new DateTime(2017, 1, 10) }, new Report() { VariableNames = new string[] { }, EventNames = new string[] { "[Clock].EndOfDay" }, } } }; Apsim.InitialiseModel(simulation); runner = new Runner(simulation); storage = simulation.Children[0] as MockStorage; clock = simulation.Children[2] as Clock; report = simulation.Children[3] as Report; }
public void TestArraySpecification() { var model = new MockModel() { Z = new double[] { 1, 2, 3 } }; simulation.Children.Add(model); Apsim.InitialiseModel(simulation); report.VariableNames = new string[] { "[MockModel].Z[3]" }; Assert.IsNull(runner.Run()); Assert.AreEqual(storage.Get <double>("MockModel.Z(3)"), new double[] { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }); }
public void Setup() { storage = new MockStorage(); clock = new Clock() { StartDate = new DateTime(2017, 1, 1), EndDate = new DateTime(2017, 1, 10) }; report = new Report() { VariableNames = new string[] { }, EventNames = new string[] { "[Clock].EndOfDay" }, }; simulation = new Simulation() { Children = new List <Model>() { storage, clock, report, new MockSummary() } }; Apsim.InitialiseModel(simulation); runner = new Runner(simulation); }
public void LayerStructureIsUsedForMapping() { var soil = new Soil { Children = new List <IModel>() { new Physical() { Thickness = new double[] { 100, 300, 300 }, BD = new double[] { 1.36, 1.216, 1.24 }, AirDry = new double[] { 0.135, 0.214, 0.261 }, LL15 = new double[] { 0.27, 0.267, 0.261 }, DUL = new double[] { 0.365, 0.461, 0.43 }, SAT = new double[] { 0.400, 0.481, 0.45 }, Children = new List <IModel>() { new SoilCrop { Name = "WheatSoil", KL = new double[] { 0.06, 0.060, 0.060 }, LL = new double[] { 0.27, 0.267, 0.261 } } } }, new Models.WaterModel.WaterBalance(), new CERESSoilTemperature(), new Organic { Thickness = new double[] { 100, 300 }, Carbon = new double[] { 2, 1 } }, new Chemical { Thickness = new double[] { 100, 200 }, NO3N = new double[] { 27, 6 }, CL = new double[] { 38, double.NaN } }, new Sample { Thickness = new double[] { 500 }, SW = new double[] { 0.103 }, OC = new double[] { 1.35 }, SWUnits = Sample.SWUnitsEnum.Gravimetric }, new Sample { Thickness = new double[] { 1000 }, OC = new double[] { 1.35 }, SWUnits = Sample.SWUnitsEnum.Volumetric }, new LayerStructure { Thickness = new double[] { 100, 300 } } } }; Apsim.InitialiseModel(soil); SoilStandardiser.Standardise(soil); var water = soil.Children[0] as Physical; var soilOrganicMatter = soil.Children[3] as Organic; var sample = soil.Children[5] as Sample; // Make sure layer structures have been standardised. var targetThickness = new double[] { 100, 300 }; Assert.AreEqual(water.Thickness, targetThickness); Assert.AreEqual(soilOrganicMatter.Thickness, targetThickness); Assert.AreEqual(sample.Thickness, targetThickness); // Make sure sample units are volumetric. Assert.AreEqual(sample.SWUnits, Sample.SWUnitsEnum.Volumetric); }
public void InitialConditionsIsCreated() { var soil = new Soil { Children = new List <IModel>() { new Physical() { Thickness = new double[] { 100, 200 }, BD = new double[] { 1.36, 1.216 }, AirDry = new double[] { 0.135, 0.214 }, LL15 = new double[] { 0.27, 0.267 }, DUL = new double[] { 0.365, 0.461 }, SAT = new double[] { 0.400, 0.481 }, }, new Models.WaterModel.WaterBalance(), new CERESSoilTemperature(), new Organic { Thickness = new double[] { 100, 200 }, Carbon = new double[] { 2, 1 }, FBiom = new double[] { 1, 2 } }, new Chemical { Thickness = new double[] { 50, 50 }, NO3N = new double[] { 27, 16 }, NH4N = new double[] { 2, double.NaN }, PH = new double[] { 6.8, 6.9 }, EC = new double[] { 100, 200 } }, new Sample { Thickness = new double[] { 100, 200 }, SW = new double[] { 0.1, 0.2 }, OC = new double[] { double.NaN, 0.9 }, SWUnits = Sample.SWUnitsEnum.Volumetric }, new Sample { Thickness = new double[] { 100, 200 }, PH = new double[] { 6.4, double.NaN }, } } }; Apsim.InitialiseModel(soil); SoilStandardiser.Standardise(soil); var initial = soil.Children[5] as Sample; var analysis = soil.Children[4] as Chemical; Assert.AreEqual(Apsim.Children(soil, typeof(Sample)).Count, 1); Assert.AreEqual(initial.Name, "Initial"); Assert.AreEqual(initial.SW, new double[] { 0.1, 0.2 }); Assert.AreEqual(initial.NO3N, new double[] { 29.240000000000002, 2.432 }); // kg/ha Assert.AreEqual(initial.NH4N, new double[] { 1.4960000000000002, 0.4864 }); // kg/ha Assert.AreEqual(initial.OC, new double[] { 2.0, 0.9 }); Assert.AreEqual(initial.PH, new double[] { 6.4, 6.9 }); Assert.AreEqual(initial.EC, new double[] { 150, 200 }); var soilOrganicMatter = soil.Children[3] as Organic; Assert.IsNull(soilOrganicMatter.Carbon); Assert.NotNull(analysis); }
public void TestTablesModified() { IModel sim1 = new Simulation() { Name = "sim1", Children = new List <IModel>() { new Report() { Name = "Report1", VariableNames = new[] { "[Clock].Today" }, EventNames = new[] { "[Clock].DoReport" }, }, new MockSummary(), new Clock() { StartDate = new DateTime(2020, 1, 1), EndDate = new DateTime(2020, 1, 2), }, } }; IModel sim2 = Apsim.Clone(sim1); sim2.Name = "sim2"; sim2.Children[0].Name = "Report2"; TestPostSim testPostSim = new TestPostSim(); sim1.Children.Add(testPostSim); Simulations sims = Simulations.Create(new[] { sim1, sim2, new DataStore() }); Apsim.InitialiseModel(sims); Runner runner = new Runner(sims, simulationNamesToRun: new[] { "sim1" }); List <Exception> errors = runner.Run(); if (errors != null && errors.Count > 0) { throw errors[0]; } List <string> tablesMod = new List <string>() { "_Factors", "Report1", "_Simulations", "_Checkpoints", }; Assert.AreEqual(tablesMod.OrderBy(x => x), testPostSim.TablesModified.OrderBy(x => x)); runner = new Runner(sims, simulationNamesToRun: new[] { "sim2" }); errors = runner.Run(); if (errors != null && errors.Count > 0) { throw errors[0]; } tablesMod = new List <string>() { "_Factors", "Report2", "_Simulations", "_Checkpoints", }; Assert.AreEqual(tablesMod.OrderBy(x => x), testPostSim.TablesModified.OrderBy(x => x)); // Now run both sims runner = new Runner(sims); errors = runner.Run(); if (errors != null && errors.Count > 0) { throw errors[0]; } tablesMod = new List <string>() { "_Factors", "Report2", "Report1", "_Simulations", "_Checkpoints", }; Assert.AreEqual(tablesMod.OrderBy(x => x), testPostSim.TablesModified.OrderBy(x => x)); }