Beispiel #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");
        }
Beispiel #2
0
        public void GetValuesExtrapolateTest()
        {
            string dataFileRoot = @"..\..\..\..\..\Examples\AsciiFileReader\Data\";

            AsciiFileDataComponent ascii = new AsciiFileDataComponent();

            IArgument[] arguments = new IArgument[2];
            arguments[0] = Argument.Create("File1", dataFileRoot + "FlowDataId.txt", false, "Name of first file to load");
            arguments[1] = Argument.Create("File2", dataFileRoot + "WaterlevelDataPoints.txt", false, "Name of second file to load");
            ascii.ApplyArguments(arguments);
            ascii.Initialize();

            Assert.AreEqual(2, ascii.Outputs.Count);

            ITimeSpaceOutput flowOutput  = (ITimeSpaceOutput)ascii.Outputs[0];
            ITimeSpaceOutput levelOutput = (ITimeSpaceOutput)ascii.Outputs[1];

            Time   startTime       = new Time(new DateTime(2005, 1, 1, 0, 0, 0));
            double startTimeMjd    = startTime.StampAsModifiedJulianDay;
            double afterEndTimeMjd = startTimeMjd + 4;


            double[] expectedFlows  = new double[] { 11, 15.6, 21.3 };
            double[] expectedLevels = new double[] { 1, 5.6, 8.3 };


            // TODO: Make it extrapolate instead!
            _queryItem1.TimeSet.SetSingleTimeStamp(afterEndTimeMjd);
            ITimeSpaceValueSet flows  = flowOutput.GetValues(_queryItem1);
            ITimeSpaceValueSet levels = levelOutput.GetValues(_queryItem1);

            Assert.AreEqual(expectedFlows, flows.Values2D[0]);
            Assert.AreEqual(expectedLevels, levels.Values2D[0]);
        }
        public void GetValuesOnCfOutputItem()
        {
            // create the component
            // connect query and output item
            // take care that component becomes valid and produces initial output for connected items
            ITimeSpaceComponent cf             = RainRrCfComponents.CreateChannelFlowInstance("CF-2");
            ITimeSpaceOutput    selectedOutput = RainRrCfCompositions.FindOutputItem(cf, "node-4.discharge");

            selectedOutput.AddConsumer(_dischargeQueryItem);
            cf.Validate();

            // check initial values
            Assert.AreEqual(7000.0, (double)selectedOutput.Values.Values2D[0][0], "Value[0] as property");

            // set query time for getting values
            _dischargeQueryItem.TimeSet.SetSingleTimeStamp(new DateTime(2009, 3, 28, 12, 0, 0));
            ITimeSpaceValueSet values = selectedOutput.GetValues(_dischargeQueryItem);

            Assert.IsNotNull(values, "values != null");
            Assert.AreEqual(7001.5, (double)values.Values2D[0][0], "value[0] from GetValues 1");

            _dischargeQueryItem.TimeSet.SetSingleTimeStamp(new DateTime(2009, 3, 29, 0, 0, 0));
            values = selectedOutput.GetValues(_dischargeQueryItem);
            Assert.IsNotNull(values, "values != null");
            Assert.AreEqual(7002.0, (double)values.Values2D[0][0], "value[0] from GetValues 1");

            try
            {
                _dischargeQueryItem.TimeSet.SetSingleTimeStamp(new DateTime(2009, 3, 30, 0, 0, 0));
                selectedOutput.GetValues(_dischargeQueryItem);
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.Message.StartsWith("Could not update engine \""));
            }
        }
 public virtual ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
 {
     return(_adaptee.GetValues(querySpecifier));
 }
 public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
 {
     return(_tsadaptee.GetValues(querySpecifier).MultiplyElementValues(_factors));
 }
Beispiel #6
0
    public void GetValuesFromGwModel()
    {
      Quantity dischargeQuantity = new Quantity(new Unit(PredefinedUnits.CubicMeterPerSecond), null, "Discharge");
      Quantity waterlevelQuantity = new Quantity(new Unit(PredefinedUnits.Meter), null, "Water Level");

      ElementSet idBasedElementSetA = new ElementSet(null, "ElmSet-A", ElementType.IdBased);
      idBasedElementSetA.AddElement(new Element("elm-1"));

      Input queryItem1 = new Input("discharge, to be retrieved from some output item", dischargeQuantity, idBasedElementSetA);
      queryItem1.TimeSet = new TimeSet();

      Input queryItem2 = new Input("water level, to be retrieved from some output item", waterlevelQuantity, idBasedElementSetA);
      queryItem2.TimeSet = new TimeSet();

      // Connect query item(s) to output item(s)
      // Take care that component becomes valid (and has produced initial output for connected items)

      ITimeSpaceComponent gwModel = new GWModelLC();
      gwModel.Initialize();

      ITimeSpaceOutput storageOnGrid = UTHelper.FindOutputItem(gwModel, "Grid.Storage");
      storageOnGrid.AddConsumer(queryItem1);
      gwModel.Validate();
      Assert.IsTrue(gwModel.Status == LinkableComponentStatus.Valid);
      gwModel.Prepare();
      Assert.IsTrue(gwModel.Status == LinkableComponentStatus.Updated);

      // check initial values
      Assert.AreEqual(4, ValueSet.GetElementCount(storageOnGrid.Values), "#values for " + storageOnGrid.Id);
      Assert.AreEqual(0.0, (double)storageOnGrid.Values.GetValue(0, 0), "Value[0] as property");

      // get values for specified query times
      queryItem1.TimeSet.SetSingleTimeStamp(new DateTime(2005, 1, 3, 0, 0, 0));
      ITimeSpaceValueSet values = storageOnGrid.GetValues(queryItem1);
      Assert.IsNotNull(values, "values != null");
      Assert.AreEqual(0.0, (double)values.GetValue(0, 0), "value[0] from GetValues 1");

      // set next query time
      queryItem1.TimeSet.SetSingleTimeStamp(new DateTime(2005, 2, 4, 0, 0, 0));
      values = storageOnGrid.GetValues(queryItem1);
      Assert.IsNotNull(values, "values != null");
      Assert.AreEqual(0.0, (double)values.GetValue(0, 0), "value[0] from GetValues 1");

      // ask for same time again
      values = storageOnGrid.GetValues(queryItem1);
      Assert.IsNotNull(values, "values != null");
      Assert.AreEqual(0.0, (double)values.GetValue(0, 0), "value[0] from GetValues 1");

      try
      {
        // set query time back in time
        queryItem1.TimeSet.SetSingleTimeStamp(new DateTime(2005, 2, 3, 0, 0, 0));
        storageOnGrid.GetValues(queryItem1);
      }
      catch (Exception e)
      {
        Assert.IsTrue(e.Message.StartsWith("Could not update engine \""));
      }

      try
      {
        // set query time beyond time horizon
        queryItem1.TimeSet.SetSingleTimeStamp(new DateTime(2005, 2, 28, 0, 0, 0));
        storageOnGrid.GetValues(queryItem1);
      }
      catch (Exception e)
      {
        Assert.IsTrue(e.Message.StartsWith("Could not update engine \""));
      }
    }
Beispiel #7
0
    public void InputOutputTests()
    {
      GWModelLC gwlc = new GWModelLC();
      IBaseLinkableComponent lc = gwlc;

      List<IArgument> arguments = CreateTestArguments();
      lc.Initialize(arguments);

      IElementSet elementSet = ((ITimeSpaceExchangeItem)lc.Inputs[2]).ElementSet();

      Quantity dischargeQuantity = new Quantity(new Unit(PredefinedUnits.CubicMeterPerSecond), null, "Discharge");
      Quantity waterlevelQuantity = new Quantity(new Unit(PredefinedUnits.Meter), null, "Water Level");

      ElementSet idBasedElementSetA = new ElementSet(null, "ElmSet-A", ElementType.IdBased);
      idBasedElementSetA.AddElement(new Element("elm-1"));

      Input waterLevelTriggerInput = new Input("Water level, to be retrieved from some output item", waterlevelQuantity, elementSet);
      waterLevelTriggerInput.TimeSet = new TimeSet();

      SimpleOutput dischargeOutput = new SimpleOutput("Discharge, to be sent to GW model", dischargeQuantity, elementSet);
      dischargeOutput.ConstOutput = 6;
      dischargeOutput.TimeSet = new TimeSet();

      ITimeSpaceInput gwInflow = UTHelper.FindInputItem(lc, "Grid.Inflow");
      ITimeSpaceOutput gwLevel = UTHelper.FindOutputItem(lc, "Grid.gwLevel");

      // Connect discharge
      gwInflow.Provider = dischargeOutput;
      dischargeOutput.AddConsumer(gwInflow);

      // Connect triggering input
      gwLevel.AddConsumer(waterLevelTriggerInput);

      lc.Validate();
      lc.Prepare();

      // specify query times
      double firstTriggerGetValuesTime = gwLevel.TimeSet.Times[0].StampAsModifiedJulianDay;
      double secondTriggerGetValuesTime = firstTriggerGetValuesTime + 3;
      double thirdTriggerGetValuesTime = firstTriggerGetValuesTime + 5;

      // check initial values
      Assert.AreEqual(8, gwLevel.Values.Values2D[0].Count);
      Assert.AreEqual(-10, (double)gwLevel.Values.GetValue(0, 0));

      ITimeSpaceValueSet values;

      // get values for initial time, therefor intial values
      waterLevelTriggerInput.TimeSet.SetSingleTime(new Time(firstTriggerGetValuesTime));
      values = gwLevel.GetValues(waterLevelTriggerInput);
      Assert.AreEqual(-10, values.GetValue(0, 0), "value for first query time");

      // get values for second query time: -10 : base gw level.
      // 10 : storageHeight is multiplied by a factor of 10
      // 3 days, 6 constant inflow, 3600*24 seconds in a day, 1000 L/M3, (100 x 200) grid cell size 
      waterLevelTriggerInput.TimeSet.SetSingleTime(new Time(secondTriggerGetValuesTime));
      values = gwLevel.GetValues(waterLevelTriggerInput);
      Assert.AreEqual(-10.0 + 10 * 3 * 6.0 * 60 * 60 * 24 / 1000 / (100 * 200), values.GetValue(0, 0), "value for first query time");

      // get values for second query time:
      // 10 : storageHeight is multiplied by a factor of 10
      // 5 days, 6 constant inflow, 3600*24 seconds in a day, 1000 L/M3, (100 x 200) grid cell size 
      waterLevelTriggerInput.TimeSet.SetSingleTime(new Time(thirdTriggerGetValuesTime));
      values = gwLevel.GetValues(waterLevelTriggerInput);
      Assert.AreEqual(-10.0 + 10 * 5 * 6.0 * 60 * 60 * 24 / 1000 / (100 * 200), values.GetValue(0, 0), "value for first query time");

      lc.Finish();

    }
Beispiel #8
0
        protected internal override void Update()
        {
            if (_providers.Count > 0)
            {
                ITime inputTime = GetInputTime();
                if (inputTime == null)
                {
                    return;
                }

                TimeSet.SetSingleTime(inputTime);

                // the set of values that is set to the engine
                ITimeSpaceValueSet values = null;

                // Loop through all providers
                for (int i = 0; i < _providers.Count; i++)
                {
                    ITimeSpaceOutput provider = _providers[i];

                    // Create the values variable for the first provider
                    // and add the result from the remaining providers to this
                    if (i == 0)
                    {
                        values = provider.GetValues(this);
                    }
                    else
                    {
                        ITimeSpaceValueSet addValues = provider.GetValues(this);

                        // Add the addValues to the values
                        int times = values.TimesCount();
                        int elmts = values.ElementCount();

                        if (addValues.TimesCount() != times ||
                            addValues.ElementCount() != elmts)
                        {
                            throw new Exception("Size of inputs differs, valuesets can not be added");
                        }

                        for (int j = 0; j < times; j++)
                        {
                            for (int k = 0; k < elmts; k++)
                            {
                                // would be really nice if the value set was templated (to avoid casting)
                                values.Values2D[j][k] = ((double)values.Values2D[j][k]) + ((double)addValues.Values2D[j][k]);
                            }
                        }
                    }
                }
                ITimeSpaceValueSet incomingValues = values;


                if (StoreValuesInExchangeItem)
                {
                    _values = incomingValues;
                    _linkableEngine.InputItemsToBeProcessed.Add(this);
                    HasBeenProcessed = false;
                }
                else
                {
                    // Here we do not add this input item to the list of InputItemsToBeProcessed, we process immediately
                    SetValuesToEngine(incomingValues);
                    HasBeenProcessed = true;
                }
            }
            else
            {
                throw new Exception("Trying to update an input item without a provider.");
            }
        }
Beispiel #9
0
        public void GetValuesTest()
        {
            string dataFileRoot = @"..\..\..\..\..\Examples\AsciiFileReader\Data\";

            AsciiFileDataComponent ascii = new AsciiFileDataComponent();

            IArgument[] arguments = new IArgument[3];
            arguments[0]    = Argument.Create("File1", dataFileRoot + "FlowDataId.txt", false, "Name of first file to load");
            arguments[1]    = Argument.Create("File2", dataFileRoot + "WaterlevelDataPoints.txt", false, "Name of second file to load");
            arguments[2]    = Argument.Create("File3", dataFileRoot + "RainDataGrid.txt", false, "Name of third file to load");
            ascii.Arguments = arguments;
            ascii.ApplyArguments(arguments);
            ascii.Initialize();

            Assert.AreEqual(3, ascii.Outputs.Count);

            ITimeSpaceOutput flowOutput  = (ITimeSpaceOutput)ascii.Outputs[0];
            ITimeSpaceOutput levelOutput = (ITimeSpaceOutput)ascii.Outputs[1];
            ITimeSpaceOutput rainOutput  = (ITimeSpaceOutput)ascii.Outputs[2];

            Assert.IsNotNull(flowOutput.ValueDefinition as IQuantity);
            Assert.AreEqual("Flow", flowOutput.ValueDefinition.Caption);

            Assert.IsNotNull(levelOutput.ValueDefinition as IQuantity);
            Assert.AreEqual("WaterLevel", levelOutput.ValueDefinition.Caption);


            Time   startTime          = new Time(new DateTime(2005, 1, 1, 0, 0, 0));
            double startTimeMjd       = startTime.StampAsModifiedJulianDay;
            double midTimeMjd         = startTimeMjd + 1.3;
            double endTimeMjd         = startTimeMjd + 3;
            double beforeStartTimeMjd = startTimeMjd - 1;
            double afterEndTimeMjd    = startTimeMjd + 4;


            double[] expectedFlows  = new double[] { 15.4, 18.2, 22.4 };
            double[] expectedLevels = new double[] { 5.4, 8.2, 9.4 };
            double[] expectedRain   = new double[] { 15.4, 18.2, 22.4, 22.4 };

            _queryItem1.TimeSet.SetSingleTimeStamp(startTimeMjd);
            ITimeSpaceValueSet flows  = flowOutput.GetValues(_queryItem1);
            ITimeSpaceValueSet levels = levelOutput.GetValues(_queryItem1);
            ITimeSpaceValueSet rain   = rainOutput.GetValues(_queryItem1);

            Assert.AreEqual(expectedFlows, flows.Values2D[0]);
            Assert.AreEqual(expectedLevels, levels.Values2D[0]);
            Assert.AreEqual(expectedRain, rain.Values2D[0]);

            _queryItem1.TimeSet.SetSingleTimeStamp(beforeStartTimeMjd);
            flows  = flowOutput.GetValues(_queryItem1);
            levels = levelOutput.GetValues(_queryItem1);
            rain   = rainOutput.GetValues(_queryItem1);
            Assert.AreEqual(expectedFlows, flows.Values2D[0]);
            Assert.AreEqual(expectedLevels, levels.Values2D[0]);
            Assert.AreEqual(expectedRain, rain.Values2D[0]);

            expectedFlows  = new double[] { 0.6 * 13.8 + 0.4 * 13.9, 0.6 * 18.2 + 0.4 * 18, 0.6 * 23.5 + 0.4 * 23.6 };
            expectedLevels = new double[] { 0.6 * 3.8 + 0.4 * 3.9, 0.6 * 8.2 + 0.4 * 8, 0.6 * 10.5 + 0.4 * 10.6 };
            expectedRain   = new double[] { 0.6 * 13.8 + 0.4 * 13.9, 0.6 * 18.2 + 0.4 * 18, 0.6 * 23.5 + 0.4 * 23.6, 0.6 * 23.5 + 0.4 * 23.6 };

            _queryItem1.TimeSet.SetSingleTimeStamp(midTimeMjd);
            flows  = flowOutput.GetValues(_queryItem1);
            levels = levelOutput.GetValues(_queryItem1);
            rain   = rainOutput.GetValues(_queryItem1);
            AssertAreEqual(expectedFlows, (IList <double>)flows.Values2D[0], 1e-8);
            AssertAreEqual(expectedLevels, (IList <double>)levels.Values2D[0], 1e-8);
            AssertAreEqual(expectedRain, (IList <double>)rain.Values2D[0], 1e-8);

            expectedFlows  = new double[] { 11, 15.6, 21.3 };
            expectedLevels = new double[] { 1, 5.6, 8.3 };
            expectedRain   = new double[] { 11, 15.6, 21.3, 21.3 };

            _queryItem1.TimeSet.SetSingleTimeStamp(endTimeMjd);
            flows  = flowOutput.GetValues(_queryItem1);
            levels = levelOutput.GetValues(_queryItem1);
            rain   = rainOutput.GetValues(_queryItem1);
            Assert.AreEqual(expectedFlows, flows.Values2D[0]);
            Assert.AreEqual(expectedLevels, levels.Values2D[0]);
            Assert.AreEqual(expectedRain, rain.Values2D[0]);

            Console.Out.WriteLine("done!");
        }
Beispiel #10
0
        public void GetValues()
        {
            // Connect query item(s) to output item(s)
            // Take care that component becomes valid (and has produced initial output for connected items)

            ITimeSpaceComponent riverModel = CreateRiverModel();
            List <IArgument>    arguments  = CreateRiverModelArguments(riverModel);

            arguments.Add(new ArgumentBool("flowItemsAsSpan", _flowItemsAsSpan));
            riverModel.Arguments.ApplyArguments(arguments);
            riverModel.Initialize();

            ITimeSpaceOutput flowOnBranch = UTHelper.FindOutputItem(riverModel, "Branch:2:Flow");

            flowOnBranch.AddConsumer(_queryItem1);
            riverModel.Validate();
            Assert.IsTrue(riverModel.Status == LinkableComponentStatus.Valid);
            riverModel.Prepare();
            Assert.IsTrue(riverModel.Status == LinkableComponentStatus.Updated);

            // check initial values
            Assert.AreEqual(1, ValueSet.GetElementCount(flowOnBranch.Values), "#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(new DateTime(2005, 1, 3, 0, 0, 0));
            ITimeSpaceValueSet values = flowOnBranch.GetValues(_queryItem1);

            Assert.IsNotNull(values, "values != null");
            double flow3 = 35.0 / 4.0; // = 10 * (1.0 / 2.0 + 1.0 / 4.0 + 1.0 / 8.0) = 8.75

            Assert.AreEqual(flow3, (double)values.GetValue(0, 0), "value[0] from GetValues 1");

            // set next query time
            _queryItem1.TimeSet.SetSingleTimeStamp(new DateTime(2005, 2, 4, 0, 0, 0));
            values = flowOnBranch.GetValues(_queryItem1);
            Assert.IsNotNull(values, "values != null");
            flow3 = 10 * (1.0 / 2.0 + 1.0 / 4.0 + 1.0 / 8.0); // = 8.75
            Assert.AreEqual(flow3, (double)values.GetValue(0, 0), "value[0] from GetValues 1");

            // ask for same time again
            values = flowOnBranch.GetValues(_queryItem1);
            Assert.IsNotNull(values, "values != null");
            Assert.AreEqual(flow3, (double)values.GetValue(0, 0), "value[0] from GetValues 1");

            try
            {
                // set query time back in time
                _queryItem1.TimeSet.SetSingleTimeStamp(new DateTime(2005, 2, 3, 0, 0, 0));
                flowOnBranch.GetValues(_queryItem1);
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.Message.StartsWith("Could not update engine \""));
            }

            try
            {
                // set query time beyond time horizon
                _queryItem1.TimeSet.SetSingleTimeStamp(new DateTime(2005, 2, 28, 0, 0, 0));
                flowOnBranch.GetValues(_queryItem1);
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.Message.StartsWith("Could not update engine \""));
            }
        }