Exemple #1
0
        public void Links_EnsureLinkByPathWorks()
        {
            ModelWithLinkByPath modelWithLinkByPath = new UnitTests.ModelWithLinkByPath();

            // Create a simulation
            Simulation simulation = new Simulation();

            simulation.Children.Add(new Clock());
            simulation.Children.Add(new MockSummary());
            simulation.Children.Add(new Zone()
            {
                Name = "zone1"
            });
            simulation.Children.Add(new Zone()
            {
                Name = "zone2"
            });
            simulation.Children[2].Children.Add(modelWithLinkByPath); // added to zone1
            MockIrrigation irrig1 = new MockIrrigation()
            {
                Name = "irrig1"
            };
            MockIrrigation irrig2 = new MockIrrigation()
            {
                Name = "irrig2"
            };

            simulation.Children[3].Children.Add(irrig1); // added to zone2
            simulation.Children[3].Children.Add(irrig2); // added to zone2

            Simulations engine = Simulations.Create(new Model[] { simulation, new DataStore() });

            engine.Links.Resolve(simulation);

            Assert.AreEqual(modelWithLinkByPath.irrigation1, irrig1);
            Assert.AreEqual(modelWithLinkByPath.irrigation2, irrig2);
        }
Exemple #2
0
        public void TestRunoff()
        {
            SoilModel soil = new SoilModel();

            APSIM.Shared.Soils.Soil soilProperties = Setup();
            APSIMReadySoil.Create(soilProperties);

            MockWeather weather = new MockWeather();
            weather.Rain = 100;

            MockIrrigation irrigation = new MockIrrigation();
            irrigation.IrrigationApplied = 0;

            MockSurfaceOrganicMatter surfaceOrganicMatter = new MockSurfaceOrganicMatter();
            surfaceOrganicMatter.Cover = 0.1;

            CNReductionForCover reductionForCover = new CNReductionForCover();
            List<ICanopy> canopies = new List<ICanopy>();

            CNReductionForTillage reductionForTillage = new CNReductionForTillage();

            RunoffModel runoff = new RunoffModel();
            runoff.CN2Bare = 70;

            // setup links
            SetLink(soil, "properties", soilProperties);
            SetLink(soil, "runoffModel", runoff);
            SetLink(soil, "weather", weather);
            SetLink(soil, "irrigation", irrigation);
            SetLink(runoff, "soil", soil);
            SetLink(runoff, "reductionForCover", reductionForCover);
            SetLink(runoff, "reductionForTillage", reductionForTillage);
            SetLink(reductionForCover, "surfaceOrganicMatter", surfaceOrganicMatter);
            SetLink(reductionForCover, "canopies", canopies);
            SetLink(reductionForTillage, "weather", weather);

            // Empty profile.
            soil.Water = MathUtilities.Multiply(soilProperties.Water.LL15, soilProperties.Water.Thickness);

            // Profile is empty - should be small amount of runoff.
            Assert.IsTrue(MathUtilities.FloatsAreEqual(runoff.Value, 5.60815));

            // Full profile - should be a lot more runoff.
            soil.Water = MathUtilities.Multiply(soilProperties.Water.DUL, soilProperties.Water.Thickness);
            Assert.IsTrue(MathUtilities.FloatsAreEqual(runoff.Value, 58.23552));

            // Test CN reduction due to canopy. Tests the Curve Number vs Cover graph.
            // Cover is 10%, reduction is 2.5
            surfaceOrganicMatter.Cover = 0.1;
            Assert.IsTrue(MathUtilities.FloatsAreEqual(reductionForCover.Value, 2.49999));

            // Cover is 80%, reduction is 20
            surfaceOrganicMatter.Cover = 0.8;
            Assert.IsTrue(MathUtilities.FloatsAreEqual(reductionForCover.Value, 20.0));

            // Test Runoff vs Rainfall graph i.e. effect of different curve numbers.
            surfaceOrganicMatter.Cover = 0.0;
            runoff.CN2Bare = 60;
            Assert.IsTrue(MathUtilities.FloatsAreEqual(runoff.Value, 48.18584));

            runoff.CN2Bare = 75;
            Assert.IsTrue(MathUtilities.FloatsAreEqual(runoff.Value, 68.16430));

            runoff.CN2Bare = 85;
            Assert.IsTrue(MathUtilities.FloatsAreEqual(runoff.Value, 81.15006));
        }
Exemple #3
0
        public void TestRunoff()
        {
            SoilModel soil = new SoilModel();

            APSIM.Shared.Soils.Soil soilProperties = Setup();
            APSIMReadySoil.Create(soilProperties);

            MockWeather weather = new MockWeather();

            weather.Rain = 100;

            MockIrrigation irrigation = new MockIrrigation();

            irrigation.IrrigationApplied = 0;

            MockSurfaceOrganicMatter surfaceOrganicMatter = new MockSurfaceOrganicMatter();

            surfaceOrganicMatter.Cover = 0.1;

            CNReductionForCover reductionForCover = new CNReductionForCover();
            List <ICanopy>      canopies          = new List <ICanopy>();

            CNReductionForTillage reductionForTillage = new CNReductionForTillage();

            RunoffModel runoff = new RunoffModel();

            runoff.CN2Bare = 70;

            // setup links
            SetLink(soil, "properties", soilProperties);
            SetLink(soil, "runoffModel", runoff);
            SetLink(soil, "weather", weather);
            SetLink(soil, "irrigation", irrigation);
            SetLink(runoff, "soil", soil);
            SetLink(runoff, "reductionForCover", reductionForCover);
            SetLink(runoff, "reductionForTillage", reductionForTillage);
            SetLink(reductionForCover, "surfaceOrganicMatter", surfaceOrganicMatter);
            SetLink(reductionForCover, "canopies", canopies);
            SetLink(reductionForTillage, "weather", weather);

            // Empty profile.
            soil.Water = MathUtilities.Multiply(soilProperties.Water.LL15, soilProperties.Water.Thickness);

            // Profile is empty - should be small amount of runoff.
            Assert.IsTrue(MathUtilities.FloatsAreEqual(runoff.Value, 5.60815));

            // Full profile - should be a lot more runoff.
            soil.Water = MathUtilities.Multiply(soilProperties.Water.DUL, soilProperties.Water.Thickness);
            Assert.IsTrue(MathUtilities.FloatsAreEqual(runoff.Value, 58.23552));

            // Test CN reduction due to canopy. Tests the Curve Number vs Cover graph.
            // Cover is 10%, reduction is 2.5
            surfaceOrganicMatter.Cover = 0.1;
            Assert.IsTrue(MathUtilities.FloatsAreEqual(reductionForCover.Value, 2.49999));

            // Cover is 80%, reduction is 20
            surfaceOrganicMatter.Cover = 0.8;
            Assert.IsTrue(MathUtilities.FloatsAreEqual(reductionForCover.Value, 20.0));

            // Test Runoff vs Rainfall graph i.e. effect of different curve numbers.
            surfaceOrganicMatter.Cover = 0.0;
            runoff.CN2Bare             = 60;
            Assert.IsTrue(MathUtilities.FloatsAreEqual(runoff.Value, 48.18584));

            runoff.CN2Bare = 75;
            Assert.IsTrue(MathUtilities.FloatsAreEqual(runoff.Value, 68.16430));

            runoff.CN2Bare = 85;
            Assert.IsTrue(MathUtilities.FloatsAreEqual(runoff.Value, 81.15006));
        }