Ejemplo n.º 1
0
        public void GetValuesFromTimeSeries()
        {
            ITimeSpaceComponent timeSeries = new TimeSeriesComponent();

            // initialize model
            timeSeries.Initialize();

            ITimeSpaceOutput output = (ITimeSpaceOutput)timeSeries.Outputs[0];

            // specify query times
            Time   startTime = new Time(new DateTime(2005, 1, 1, 0, 0, 0));
            double firstTriggerGetValuesTime  = startTime.StampAsModifiedJulianDay;
            double secondTriggerGetValuesTime = firstTriggerGetValuesTime + 12.1;
            double thirdTriggerGetValuesTime  = firstTriggerGetValuesTime + 16.7;

            // get values for specified query times - initial time, will return initial value
            queryItem1.TimeSet.SetSingleTimeStamp(firstTriggerGetValuesTime);
            ITimeSpaceValueSet values = output.GetValues(queryItem1);

            Assert.AreEqual(1, values.GetValue(0, 0), "value for first query time");

            // 12.1 days from 01-01
            queryItem1.TimeSet.SetSingleTimeStamp(secondTriggerGetValuesTime);
            values = output.GetValues(queryItem1);
            Assert.AreEqual(13, values.GetValue(0, 0), "value for second query time");

            // 16.7 days from 01-01
            queryItem1.TimeSet.SetSingleTimeStamp(thirdTriggerGetValuesTime);
            values = output.GetValues(queryItem1);
            Assert.AreEqual(17, values.GetValue(0, 0), "value for third query time");
        }
Ejemplo n.º 2
0
        private void RunGetValues2BTest(bool inputTimesAsSpans)
        {
            ITimeSpaceComponent timeSeries = new TimeSeriesComponent();
            ITimeSpaceComponent upperRiver = CreateRiverModel();
            ITimeSpaceComponent lowerRiver = CreateRiverModel();

            timeSeries.Initialize();

            IArgument flowAsStampsArgument = new ArgumentBool("flowItemsAsSpan", inputTimesAsSpans);

            // The ModelID is passed in order to make it easier to debug, otherwise you cannot se the difference between the two istances of RiverModelLC
            List <IArgument> upperRiverArguments = CreateRiverModelArguments(upperRiver);

            upperRiverArguments.Add(Argument.Create("ModelID", "upperRiverModel", true, "argument"));
            upperRiverArguments.Add(flowAsStampsArgument);
            upperRiver.Initialize(upperRiverArguments);

            // The ModelID is passed in order to make it easier to debug, otherwise you cannot se the difference between the two istances of RiverModelLC
            List <IArgument> lowerRiverArguments = CreateRiverModelArguments(lowerRiver);

            lowerRiverArguments.Add(Argument.Create("ModelID", "lowerRiverModel", true, "argument"));
            lowerRiverArguments.Add(flowAsStampsArgument);
            lowerRiver.Initialize(lowerRiverArguments);

            Assert.AreEqual("upperRiverModel", upperRiver.Id);
            Assert.AreEqual("lowerRiverModel", lowerRiver.Id);

            // Link upper river inflow to timeseries
            IBaseInput  upperRiverInput  = upperRiver.Inputs[0];
            IBaseOutput timeSeriesOutput = timeSeries.Outputs[0];

            timeSeriesOutput.AddConsumer(upperRiverInput);

            // Link upper river outflow to lower river inflow
            IBaseOutput upperRiverOutput = upperRiver.Outputs[2];
            IBaseInput  lowerRiverInput  = lowerRiver.Inputs[0];

            upperRiverOutput.AddConsumer(lowerRiverInput);

            // Link some lower river output item to the 'triggering' query item
            // Put a time interpolator in between, to take care that any required time stamp can be provided
            ITimeSpaceOutput      flowOnBranch         = UTHelper.FindOutputItem(lowerRiver, "Branch:2:Flow");
            IAdaptedOutputFactory adaptedOutputFactory = lowerRiver.AdaptedOutputFactories[0];

            IIdentifiable[]         adaptedOutputIds = adaptedOutputFactory.GetAvailableAdaptedOutputIds(flowOnBranch, _queryItem1);
            ITimeSpaceAdaptedOutput adaptedOutput    = (ITimeSpaceAdaptedOutput)
                                                       adaptedOutputFactory.CreateAdaptedOutput(adaptedOutputIds[0], flowOnBranch, _queryItem1);

            adaptedOutput.AddConsumer(_queryItem1);

            // Connections have been established, validate the models
            timeSeries.Validate();
            Assert.IsTrue(timeSeries.Status == LinkableComponentStatus.Valid);
            timeSeries.Prepare();

            lowerRiver.Validate();
            Assert.IsTrue(lowerRiver.Status == LinkableComponentStatus.Valid);
            lowerRiver.Prepare();
            Assert.IsTrue(lowerRiver.Status == LinkableComponentStatus.Updated);

            upperRiver.Validate();
            Assert.IsTrue(upperRiver.Status == LinkableComponentStatus.Valid);
            upperRiver.Prepare();
            Assert.IsTrue(upperRiver.Status == LinkableComponentStatus.Updated);

            // specify query times
            double startTime = ((LinkableEngine)lowerRiver).CurrentTime.StampAsModifiedJulianDay;
            double firstTriggerGetValuesTime  = startTime + 12.5;
            double secondTriggerGetValuesTime = startTime + 16.2;

            // check initial values
            Assert.AreEqual(1, flowOnBranch.Values.Values2D[0].Count, "#values for " + flowOnBranch.Id);
            Assert.AreEqual(7.0, (double)flowOnBranch.Values.GetValue(0, 0), "Value[0] as property");

            // get values for specified query times, 12.5 days after 01-01 (13 L/s inflow from timeseries)
            // Upper river provides 35/4 (runoff) + 13/8) to lower river
            // Lower river last branch flow: 35/4 (own runoff) + 35/4/8 (upper runoff) + 13/8/8 (upper inflow) = 315/32 + 13/64
            _queryItem1.TimeSet.SetSingleTimeStamp(firstTriggerGetValuesTime);
            ITimeSpaceValueSet values = adaptedOutput.GetValues(_queryItem1);

            if (inputTimesAsSpans)
            {
                Assert.AreEqual(315.0 / 32.0 + 13.0 / 64.0, values.GetValue(0, 0), "value for second query time");
            }
            else
            {
                double vala = 315.0 / 32.0 + 13.0 / 64.0; // value at 12/01
                double valb = 315.0 / 32.0 + 14.0 / 64.0; // value at 13/01
                double val  = 0.5 * vala + 0.5 * valb;    // interpolate
                Assert.AreEqual(val, values.GetValue(0, 0), "value for second query time");
            }

            // get values for specified query times, 16.2 days after 01-01 (17 L/s inflow from timeseries)
            // Upper river provides 35/4 (runoff) + 17/8) to lower river
            // Lower river last branch flow: 35/4 (own runoff) + 35/4/8 (upper runoff) + 17/8/8 (upper inflow) = 315/32 + 17/64
            _queryItem1.TimeSet.SetSingleTimeStamp(secondTriggerGetValuesTime);
            values = adaptedOutput.GetValues(_queryItem1);
            if (inputTimesAsSpans)
            {
                Assert.AreEqual(315.0 / 32.0 + 17.0 / 64.0, values.GetValue(0, 0), "value for third query time");
            }
            else
            {
                double vala = 315.0 / 32.0 + 17.0 / 64.0; // value at 16/01
                double valb = 315.0 / 32.0 + 18.0 / 64.0; // value at 17/01
                double val  = 0.8 * vala + 0.2 * valb;    // interpolate
                Assert.AreEqual(val, (double)values.GetValue(0, 0), 1e-10, "value for third query time");
            }

            timeSeries.Finish();
            upperRiver.Finish();
            lowerRiver.Finish();
        }
Ejemplo n.º 3
0
        private void RunGetValues2CTest(bool inputTimesAsSpans, bool storeValuesInItems)
        {
            ITimeSpaceComponent timeSeries = new TimeSeriesComponent();
            ITimeSpaceComponent upperRiver = CreateRiverModel();
            ITimeSpaceComponent lowerRiver = CreateRiverModel();

            _flowItemsAsSpan = true;

            timeSeries.Initialize();

            IArgument flowAsStampsArgument = new ArgumentBool("flowItemsAsSpan", inputTimesAsSpans);
            IArgument storeInItemsArgument = new ArgumentBool("storeValuesInExchangeItems", storeValuesInItems);

            // The ModelID is passed in order to make it easier to debug, otherwise you cannot se the difference between the two istances of RiverModelLC
            List <IArgument> upperRiverArguments = CreateRiverModelArguments(upperRiver);

            upperRiverArguments.Add(Argument.Create("ModelID", "upperRiverModel", true, "argument"));
            upperRiverArguments.Add(flowAsStampsArgument);
            upperRiverArguments.Add(Argument.Create("TimeStepLength", 21600));
            upperRiverArguments.Add(storeInItemsArgument);
            upperRiver.Arguments.ApplyArguments(upperRiverArguments);
            upperRiver.Initialize();

            // The ModelID is passed in order to make it easier to debug, otherwise you cannot se the difference between the two istances of RiverModelLC
            List <IArgument> lowerRiverArguments = CreateRiverModelArguments(lowerRiver);

            lowerRiverArguments.Add(Argument.Create("ModelID", "lowerRiverModel", true, "argument"));
            lowerRiverArguments.Add(flowAsStampsArgument);
            lowerRiverArguments.Add(Argument.Create("TimeStepLength", 86400));
            lowerRiverArguments.Add(storeInItemsArgument);
            lowerRiver.Arguments.ApplyArguments(lowerRiverArguments);
            lowerRiver.Initialize();

            Assert.AreEqual("upperRiverModel", upperRiver.Id);
            Assert.AreEqual("lowerRiverModel", lowerRiver.Id);

            // Link upper river outflow to lower river inflow
            IBaseInput  upperRiverInput  = upperRiver.Inputs[0];
            IBaseOutput timeSeriesOutput = timeSeries.Outputs[0];

            timeSeriesOutput.AddConsumer(upperRiverInput);

            // Link upper river outflow to lower river inflow
            // Put a time interpolator in between, to handle the non equal time steps
            IBaseOutput           upperRiverOutput     = upperRiver.Outputs[2];
            IBaseInput            lowerRiverInput      = lowerRiver.Inputs[0];
            IAdaptedOutputFactory adaptedOutputFactory = upperRiver.AdaptedOutputFactories[0];

            IIdentifiable[]         adaptedOutputIds = adaptedOutputFactory.GetAvailableAdaptedOutputIds(upperRiverOutput, lowerRiverInput);
            ITimeSpaceAdaptedOutput adaptedOutput    = (ITimeSpaceAdaptedOutput)
                                                       adaptedOutputFactory.CreateAdaptedOutput(adaptedOutputIds[0], upperRiverOutput, lowerRiverInput);

            adaptedOutput.AddConsumer(lowerRiverInput);

            // Link some lower river output item to the 'triggering' query item
            // Put a time interpolator in between, to take care that any required time stamp can be provided
            ITimeSpaceOutput flowOnBranch = UTHelper.FindOutputItem(lowerRiver, "Branch:2:Flow");

            adaptedOutputFactory = lowerRiver.AdaptedOutputFactories[0];
            adaptedOutputIds     = adaptedOutputFactory.GetAvailableAdaptedOutputIds(flowOnBranch, _queryItem1);
            adaptedOutput        = (ITimeSpaceAdaptedOutput)
                                   adaptedOutputFactory.CreateAdaptedOutput(adaptedOutputIds[0], flowOnBranch, _queryItem1);

            adaptedOutput.AddConsumer(_queryItem1);

            // Connections have been established, validate the models
            timeSeries.Validate();
            Assert.IsTrue(timeSeries.Status == LinkableComponentStatus.Valid);
            timeSeries.Prepare();

            lowerRiver.Validate();
            Assert.IsTrue(lowerRiver.Status == LinkableComponentStatus.Valid);
            lowerRiver.Prepare();
            Assert.IsTrue(lowerRiver.Status == LinkableComponentStatus.Updated);

            upperRiver.Validate();
            Assert.IsTrue(upperRiver.Status == LinkableComponentStatus.Valid);
            upperRiver.Prepare();
            Assert.IsTrue(upperRiver.Status == LinkableComponentStatus.Updated);

            // specify query times
            double startTime = ((LinkableEngine)lowerRiver).CurrentTime.StampAsModifiedJulianDay;
            double firstTriggerGetValuesTime  = startTime + 12.5;
            double secondTriggerGetValuesTime = startTime + 16.2;

            // check initial values
            Assert.AreEqual(1, flowOnBranch.Values.Values2D[0].Count, "#values for " + flowOnBranch.Id);
            Assert.AreEqual(7.0, (double)flowOnBranch.Values.GetValue(0, 0), "Value[0] as property");

            // get values for specified query times
            _queryItem1.TimeSet.SetSingleTimeStamp(firstTriggerGetValuesTime);
            ITimeSpaceValueSet values = adaptedOutput.GetValues(_queryItem1);

            if (inputTimesAsSpans)
            {
                Assert.AreEqual(315.0 / 32.0 + 13.0 / 64.0, values.GetValue(0, 0), "value for second query time");
            }
            else
            {
                Assert.AreEqual(10.0546875, values.GetValue(0, 0), "value for second query time");
            }

            _queryItem1.TimeSet.SetSingleTimeStamp(secondTriggerGetValuesTime);
            values = adaptedOutput.GetValues(_queryItem1);
            if (inputTimesAsSpans)
            {
                Assert.AreEqual(315.0 / 32.0 + 17.0 / 64.0, values.GetValue(0, 0), "value for second query time");
            }
            else
            {
                Assert.AreEqual(10.112499999999955, values.GetValue(0, 0), "value for third query time");
            }

            timeSeries.Finish();
            upperRiver.Finish();
            lowerRiver.Finish();
        }
Ejemplo n.º 4
0
        public void GetValues1B()
        {
            ITimeSpaceComponent timeSeries   = new TimeSeriesComponent();
            LinkableEngine      riverModelLE = CreateRiverModel();
            ITimeSpaceComponent riverModelLC = riverModelLE;

            // initialize model
            timeSeries.Initialize();

            List <IArgument> riverArguments = CreateRiverModelArguments(riverModelLC);

            riverArguments.Add(Argument.Create("ModelID", "upperRiverModel", true, "argument"));
            riverArguments.Add(new ArgumentBool("flowItemsAsSpan", true));
            riverArguments.Add(Argument.Create("TimeStepLength", 3600));

            riverModelLC.Arguments.ApplyArguments(riverArguments);
            riverModelLC.Initialize();

            // Connect time series component and river
            IBaseOutput tsOutput   = timeSeries.Outputs[0];
            IBaseInput  riverInput = riverModelLC.Inputs[0];

            tsOutput.AddConsumer(riverInput);

            // Connect tigger to river
            ITimeSpaceOutput      output = (ITimeSpaceOutput)riverModelLC.Outputs[2];
            IAdaptedOutputFactory adaptedOutputFactory = riverModelLC.AdaptedOutputFactories[0];

            IIdentifiable[]         adaptedOutputIds = adaptedOutputFactory.GetAvailableAdaptedOutputIds(output, _queryItem1);
            ITimeSpaceAdaptedOutput adaptedOutput    = (ITimeSpaceAdaptedOutput)
                                                       adaptedOutputFactory.CreateAdaptedOutput(adaptedOutputIds[0], output, _queryItem1);

            adaptedOutput.AddConsumer(_queryItem1);

            // Validate and prepare
            riverModelLC.Validate();
            Assert.IsTrue(riverModelLC.Status == LinkableComponentStatus.Valid);
            riverModelLC.Prepare();
            Assert.IsTrue(riverModelLC.Status == LinkableComponentStatus.Updated);

            // specify query times
            double firstTriggerGetValuesTime  = riverModelLE.CurrentTime.StampAsModifiedJulianDay;
            double secondTriggerGetValuesTime = firstTriggerGetValuesTime + 12.1;
            double thirdTriggerGetValuesTime  = firstTriggerGetValuesTime + 16.7;

            // check initial values
            Assert.AreEqual(1, output.Values.Values2D[0].Count, "#values for " + output.Id);
            Assert.AreEqual(7.0, (double)output.Values.GetValue(0, 0), "Value[0] as property");

            // get values for specified query times - initial time, will return initial value
            _queryItem1.TimeSet.SetSingleTimeStamp(firstTriggerGetValuesTime);
            ITimeSpaceValueSet values = adaptedOutput.GetValues(_queryItem1);

            Assert.AreEqual(7.0, values.GetValue(0, 0), "value for first query time");

            // 12.1 days from 01-01, 10 L/s runoff + 13 L/s inflow on first node
            _queryItem1.TimeSet.SetSingleTimeStamp(secondTriggerGetValuesTime);
            values = adaptedOutput.GetValues(_queryItem1);
            Assert.AreEqual(35.0 / 4.0 + 13.0 / 8.0, values.GetValue(0, 0), "value for second query time");

            // 16.7 days from 01-01, 10 L/s runoff + 17 L/s inflow on first node
            _queryItem1.TimeSet.SetSingleTimeStamp(thirdTriggerGetValuesTime);
            values = adaptedOutput.GetValues(_queryItem1);
            Assert.AreEqual(35.0 / 4.0 + 17.0 / 8.0, values.GetValue(0, 0), "value for third query time");

            riverModelLC.Finish();
        }