コード例 #1
0
        public void Links_EnsureOldStyleLinkWorks()
        {
            // Create a tree with a root node for our models.
            ModelWrapper models = new ModelWrapper();

            // Create some models.
            ModelWrapper simulations = models.Add(new Simulations());

            ModelWrapper simulation = simulations.Add(new Simulation());

            Clock clock = new Clock();

            clock.StartDate = new DateTime(2015, 1, 1);
            clock.EndDate   = new DateTime(2015, 12, 31);
            simulation.Add(clock);

            MockSummary summary = new MockSummary();

            simulation.Add(summary);
            simulation.Add(new Zone());
            simulation.Add(new Zone());

            ModelWithLinks links = new ModelWithLinks();

            simulation.Add(links);

            Links linksAlgorithm = new Links();

            linksAlgorithm.Resolve(simulations);

            Assert.AreEqual(links.zones.Length, 2);
            Assert.NotNull(links.zones[0]);
            Assert.NotNull(links.zones[1]);
        }
コード例 #2
0
ファイル: LinksTests.cs プロジェクト: gc13141112/ApsimX
        public void Links_EnsureIFunctionLinksCorrectly()
        {
            // Create a tree with a root node for our models.
            ModelWrapper models = new ModelWrapper();

            // Create some models.
            Simulation   simulationModel  = new Simulation();
            Simulations  simulationsModel = Simulations.Create(new Model[] { simulationModel });
            ModelWrapper simulations      = models.Add(simulationsModel);
            ModelWrapper simulation       = simulations.Add(simulationModel);

            Clock clock = new Clock();

            clock.StartDate = new DateTime(2015, 1, 1);
            clock.EndDate   = new DateTime(2015, 12, 31);
            simulation.Add(clock);

            MockSummary summary = new MockSummary();

            simulation.Add(summary);
            simulation.Add(new Zone());
            simulation.Add(new Zone());

            ModelWrapper links = simulation.Add(new ModelWithIFunctions());

            simulation.Add(links);

            links.Add(new IFunctionProxy()
            {
                value = 1
            }).Name = "model1";
            links.Add(new IFunctionProxy()
            {
                value = 2
            }).Name = "model2";
            links.Add(new IFunctionProxy()
            {
                value = 3
            }).Name = "model3";

            Links linksAlgorithm = new Links();

            linksAlgorithm.Resolve(simulations);

            Assert.AreEqual((links.Model as ModelWithIFunctions).model2.Value(), 2);
        }
コード例 #3
0
        public void Fertiliser_EnsureApplyWorks()
        {
            // Create a tree with a root node for our models.
            Simulation simulation = new Simulation();

            Clock clock = new Clock();

            clock.StartDate = new DateTime(2015, 1, 1);
            clock.EndDate   = new DateTime(2015, 1, 1);
            simulation.Children.Add(clock);

            MockSummary summary = new MockSummary();

            simulation.Children.Add(summary);

            MockSoil soil = new MockSoil();

            soil.Thickness = new double[] { 100, 100, 100 };
            soil.NO3       = new double[] { 1, 2, 3 };
            simulation.Children.Add(soil);

            Fertiliser fertiliser = new Fertiliser();

            fertiliser.Name = "Fertilise";
            simulation.Children.Add(fertiliser);

            Operations operations         = new Operations();
            Operation  fertiliseOperation = new Operation();

            fertiliseOperation.Date   = "1-jan";
            fertiliseOperation.Action = "[Fertilise].Apply(Amount: 100, Type:Fertiliser.Types.NO3N, Depth:300)";
            operations.Schedule       = new List <Operation>();
            operations.Schedule.Add(fertiliseOperation);
            simulation.Children.Add(operations);

            simulation.Children.Add(new SoluteManager());

            ISimulationEngine simulationEngine = Simulations.Create(new Model[] { simulation });

            simulationEngine.Run(simulation, doClone: false);

            Assert.AreEqual(soil.NO3, new double[] { 1, 2, 103 });
            Assert.AreEqual(MockSummary.messages[0], "100 kg/ha of NO3N added at depth 300 layer 3");
        }
コード例 #4
0
ファイル: TestLinks.cs プロジェクト: hol353/ApsimX
        public void EnsureDynamicPropertyLinksCorrectly()
        {
            // Create a tree with a root node for our models.
            ModelWrapper models = new ModelWrapper();

            // Create some models.
            ModelWrapper simulations = models.Add(new Simulations());

            ModelWrapper simulation = simulations.Add(new Simulation());

            Clock clock = new Clock();
            clock.StartDate = new DateTime(2015, 1, 1);
            clock.EndDate = new DateTime(2015, 12, 31);
            simulation.Add(clock);

            MockSummary summary = new MockSummary();
            simulation.Add(summary);
            simulation.Add(new Zone());
            simulation.Add(new Zone());

            ModelWithDynamicProperty modelWithDynamicProperty = new ModelWithDynamicProperty();
            modelWithDynamicProperty.xname = "Clock.StartDate";
            simulation.Add(modelWithDynamicProperty);

            Links.Resolve(simulation);

            Assert.IsNotNull(modelWithDynamicProperty);
            Assert.AreEqual(modelWithDynamicProperty.x.Get(), clock.StartDate);
        }
コード例 #5
0
ファイル: TestLinks.cs プロジェクト: hol353/ApsimX
        public void Link()
        {
            // Create a tree with a root node for our models.
            ModelWrapper models = new ModelWrapper();

            // Create some models.
            ModelWrapper simulations = models.Add(new Simulations());

            ModelWrapper simulation = simulations.Add(new Simulation());

            Clock clock = new Clock();
            clock.StartDate = new DateTime(2015, 1, 1);
            clock.EndDate = new DateTime(2015, 12, 31);
            simulation.Add(clock);

            MockSummary summary = new MockSummary();
            simulation.Add(summary);
            simulation.Add(new Zone());
            simulation.Add(new Zone());

            ModelWithLinks links = new ModelWithLinks();
            simulation.Add(links);

            Links.Resolve(simulations);

            Assert.AreEqual(links.zones.Length, 3);
            Assert.NotNull(links.zones[0]);
            Assert.NotNull(links.zones[1]);
        }
コード例 #6
0
ファイル: TestLinks.cs プロジェクト: hol353/ApsimX
        public void EnsureModelNodeLinksCorrectly()
        {
            // Create a tree with a root node for our models.
            ModelWrapper models = new ModelWrapper();

            // Create some models.
            ModelWrapper simulations = models.Add(new Simulations());

            ModelWrapper simulation = simulations.Add(new Simulation());

            Clock clock = new Clock();
            clock.StartDate = new DateTime(2015, 1, 1);
            clock.EndDate = new DateTime(2015, 12, 31);
            simulation.Add(clock);

            MockSummary summary = new MockSummary();
            simulation.Add(summary);
            simulation.Add(new Zone());
            simulation.Add(new Zone());

            ModelWithModelNodeLink modelWithModelNode = new ModelWithModelNodeLink();
            simulation.Add(modelWithModelNode);

            Links.Resolve(simulations);

            Assert.IsNotNull(modelWithModelNode.model);
        }
コード例 #7
0
ファイル: TestLinks.cs プロジェクト: hol353/ApsimX
        public void EnsureIFunctionLinksCorrectly()
        {
            // Create a tree with a root node for our models.
            ModelWrapper models = new ModelWrapper();

            // Create some models.
            ModelWrapper simulations = models.Add(new Simulations());

            ModelWrapper simulation = simulations.Add(new Simulation());

            Clock clock = new Clock();
            clock.StartDate = new DateTime(2015, 1, 1);
            clock.EndDate = new DateTime(2015, 12, 31);
            simulation.Add(clock);

            MockSummary summary = new MockSummary();
            simulation.Add(summary);
            simulation.Add(new Zone());
            simulation.Add(new Zone());

            ModelWithIFunctions links = new ModelWithIFunctions();
            simulation.Add(links);

            simulation.Add(new IFunctionProxy() { value = 1 }).Name = "model1";
            simulation.Add(new IFunctionProxy() { value = 2 }).Name = "model2";
            simulation.Add(new IFunctionProxy() { value = 3 }).Name = "model3";

            Links.Resolve(simulations);

            Assert.AreEqual(links.model2.Value, 2);
        }