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(); }
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(); }