public void GetValuesOnTimeExtrapolator() { // 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-2.waterlevel"); cf.Validate(); ITimeSpaceAdaptedOutput timeExtrapolator = (ITimeSpaceAdaptedOutput)RainRrCfCompositions.ConnectItemsUsingAdaptedOutput(cf, selectedOutput, _waterlevQueryItem, RainRrCfCompositions.timeExtrapolatorId); // set query time for getting values _dischargeQueryItem.TimeSet.SetSingleTimeStamp(new DateTime(2009, 3, 28, 12, 0, 0)); ITimeSpaceValueSet values = timeExtrapolator.GetValues(_dischargeQueryItem); Assert.IsNotNull(values, "values != null"); Assert.AreEqual(4001.5, (double)values.Values2D[0][0], "value[0] from GetValues 1"); _dischargeQueryItem.TimeSet.SetSingleTimeStamp(new DateTime(2009, 3, 29, 0, 0, 0)); values = timeExtrapolator.GetValues(_dischargeQueryItem); Assert.IsNotNull(values, "values != null"); Assert.AreEqual(4002.0, (double)values.Values2D[0][0], "value[0] from GetValues 1"); _dischargeQueryItem.TimeSet.SetSingleTimeStamp(new DateTime(2009, 3, 30, 0, 0, 0)); timeExtrapolator.GetValues(_dischargeQueryItem); Assert.AreEqual(4002.0, (double)values.Values2D[0][0], "value[0] from GetValues 1"); }
public void Polygon2PointAdaptedOutputGetValues2Consumers() { Output adaptee = new Output(xyPolygon.Caption + ".Flow") { SpatialDefinition = xyPolygon, ValueDefinition = waterLevelQuantity }; ITimeSpaceInput consumerA = new Input(xyPointA.Caption + ".Flow") { SpatialDefinition = xyPointA, ValueDefinition = waterLevelQuantity }; IIdentifiable selectedAvailableAdaptedOutputId = adaptedOutputFactory.GetAvailableAdaptedOutputIds(adaptee, consumerA)[1]; ITimeSpaceAdaptedOutput adaptedOutput = (ITimeSpaceAdaptedOutput)adaptedOutputFactory.CreateAdaptedOutput(selectedAvailableAdaptedOutputId, adaptee, consumerA); adaptedOutput.AddConsumer(consumerA); IList <IList> values2D = new List <IList>(); values2D.Add(new List <double> { 0.444 }); adaptee.Values = new ValueSet(values2D); ITimeSpaceValueSet adaptedValuesA = adaptedOutput.GetValues(consumerA); Assert.AreEqual(1, ValueSet.GetTimesCount(adaptedValuesA), "adaptedValuesA.TimesCount"); Assert.AreEqual(consumerA.ElementSet().ElementCount, ValueSet.GetElementCount(adaptedValuesA), "adaptedValuesA.ElementCount"); }
public void CreatePolygon2PointAdaptedOutput2Consumers() { ITimeSpaceOutput adaptee = new Output(xyPolygon.Caption + ".Flow") { SpatialDefinition = xyPolygon, ValueDefinition = waterLevelQuantity }; ITimeSpaceInput consumerA = new Input(xyPointA.Caption + ".Flow") { SpatialDefinition = xyPointA, ValueDefinition = waterLevelQuantity }; ITimeSpaceInput consumerB = new Input(xyPointB.Caption + ".Flow") { SpatialDefinition = xyPointB, ValueDefinition = waterLevelQuantity }; ITimeSpaceInput consumer = consumerB; IIdentifiable selectedAvailableAdaptedOutputId = adaptedOutputFactory.GetAvailableAdaptedOutputIds(adaptee, consumer)[1]; ITimeSpaceAdaptedOutput adaptedOutput = (ITimeSpaceAdaptedOutput)adaptedOutputFactory.CreateAdaptedOutput(selectedAvailableAdaptedOutputId, adaptee, consumer); adaptedOutput.AddConsumer(consumer); Assert.IsTrue(adaptedOutput.ElementSet().ElementType == ElementType.Point, "Consumer's ElementSet TYPE"); Assert.AreEqual(2, adaptedOutput.ElementSet().ElementCount, "ElementSet of consumer"); Assert.IsTrue(adaptedOutput.ValueDefinition == adaptee.ValueDefinition, "Adaptee's ValueDefinition"); }
public IBaseAdaptedOutput CreateAdaptedOutput(IIdentifiable adaptedOutputId, IBaseOutput adaptee, IBaseInput target) { ITimeSpaceAdaptedOutput adaptedOutput = adaptedOutputId as ITimeSpaceAdaptedOutput; if (adaptedOutput == null) { throw new ArgumentException("Adapted output id does no come from this factory", "adaptedOutputId"); } return(adaptedOutput); }
public void GetValues1A() { LinkableEngine riverModelLE = CreateRiverModel(); ITimeSpaceComponent riverModelLC = riverModelLE; // initialize model List <IArgument> riverArguments = CreateRiverModelArguments(riverModelLC); riverArguments.Add(Argument.Create("ModelID", "RiverModel", true, "argument")); riverArguments.Add(Argument.Create("TimeStepLength", 3600)); riverModelLC.Arguments.ApplyArguments(riverArguments); riverModelLC.Initialize(); // Link output and trigger with a time buffer 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); 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 + 2; double thirdTriggerGetValuesTime = firstTriggerGetValuesTime + 4.3; // 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 _queryItem1.TimeSet.SetSingleTimeStamp(firstTriggerGetValuesTime); ITimeSpaceValueSet values = adaptedOutput.GetValues(_queryItem1); Assert.AreEqual(7.0, values.GetValue(0, 0), "value for first query time"); // only runoff inflow, 10 L/s _queryItem1.TimeSet.SetSingleTimeStamp(secondTriggerGetValuesTime); values = adaptedOutput.GetValues(_queryItem1); Assert.AreEqual(35.0 / 4.0, values.GetValue(0, 0), "value for second query time"); // still only runoff inflow, 10 L/s _queryItem1.TimeSet.SetSingleTimeStamp(thirdTriggerGetValuesTime); values = adaptedOutput.GetValues(_queryItem1); Assert.AreEqual(35.0 / 4.0, values.GetValue(0, 0), "value for third query time"); riverModelLC.Finish(); }
public AdaptedOutput(ITimeSpaceAdaptedOutput adaptedOutput) : base(adaptedOutput) { if (adaptedOutput.Adaptee != null) { deriver = new Output((ITimeSpaceOutput)adaptedOutput.Adaptee); } _arguments = new Argument[adaptedOutput.Arguments.Count]; for (int n = 0; n < adaptedOutput.Arguments.Count; ++n) { _arguments[n] = new Argument(adaptedOutput.Arguments[n]); } }
public void CreatePolygon2PolylineAdaptedOutput() { ITimeSpaceOutput adaptee = new Output(xyPolygon.Caption + ".Flow") { SpatialDefinition = xyPolygon, ValueDefinition = waterLevelQuantity }; ITimeSpaceInput consumer = new Input(xyPolylineA.Caption + ".Flow") { SpatialDefinition = xyPolylineA, ValueDefinition = waterLevelQuantity }; IIdentifiable selectedAvailableAdaptedOutputId = adaptedOutputFactory.GetAvailableAdaptedOutputIds(adaptee, consumer)[1]; ITimeSpaceAdaptedOutput adaptedOutput = (ITimeSpaceAdaptedOutput)adaptedOutputFactory.CreateAdaptedOutput(selectedAvailableAdaptedOutputId, adaptee, consumer); adaptedOutput.AddConsumer(consumer); Assert.IsTrue(adaptedOutput.ElementSet() == consumer.ElementSet(), "Consumer's ElementSet"); Assert.IsTrue(adaptedOutput.ValueDefinition == adaptee.ValueDefinition, "Adaptee's ValueDefinition"); }
public static ITimeSpaceAdaptedOutput CreateAdaptedOutputMethod(IIdentifiable adaptedOutputId, IBaseOutput adaptee, IElementSet targetElmtSet) { SpatialMethod method = FindSMethod(adaptedOutputId); ITimeSpaceAdaptedOutput adaptedOutput = null; if (method.ElementMapperMethod != ElementMapperMethod.None) { if (targetElmtSet == null) { throw new ArgumentException("Target not defined or spatial definition is not an element set. Can not create adaptor"); } adaptedOutput = new ElementMapperAdaptedOutput(adaptedOutputId, (ITimeSpaceOutput)adaptee, targetElmtSet); } else { if (string.Equals(_ElementOperationPrefix + "200", adaptedOutputId.Id, StringComparison.OrdinalIgnoreCase)) { adaptedOutput = new ElementLineLengthOperationAdaptor(adaptedOutputId.Id, (ITimeSpaceOutput)adaptee); } else if (string.Equals(_ElementOperationPrefix + "300", adaptedOutputId.Id, StringComparison.OrdinalIgnoreCase)) { adaptedOutput = new ElementAreaOperationAdaptor(adaptedOutputId.Id, (ITimeSpaceOutput)adaptee); } } if (adaptedOutput == null) { throw new ArgumentException("Adapted output id could not be found", "adaptedOutputId"); } // Connect adaptor and adaptee if (!adaptee.AdaptedOutputs.Contains(adaptedOutput)) { adaptee.AddAdaptedOutput(adaptedOutput); } return(adaptedOutput); }
static void SetArguments(oprConnectionDecoratorArgument[] arguments, ITimeSpaceAdaptedOutput iDecorator) { if (arguments == null || arguments.Length < 1) { return; } Dictionary <string, IArgument> args = new Dictionary <string, IArgument>(iDecorator.Arguments.Count); foreach (IArgument arg in iDecorator.Arguments) { args.Add(arg.Id, arg); } foreach (oprConnectionDecoratorArgument arg in arguments) { if (args.ContainsKey(arg.id)) { args[arg.id].ValueAsString = arg.value; } } }
/// <summary> /// Connect the output defined by the <paramref name="outputId"/> with the input /// defined by the <paramref name="inputId"/>, and put the adaptors /// listed by the id's <paramref name="adaptorIds"/> in between. /// <para> /// If any of the adaptors needs custom parameters, this method can not be used. /// </para> /// </summary> /// <param name="outputComponent">Component that has the output</param> /// <param name="outputId">Id of output</param> /// <param name="inputComponent">Component that has the input</param> /// <param name="inputId">Id of input</param> /// <param name="adaptorIds">Id of adaptors. They must be available from the output component</param> /// <param name="scale">If scale is different from 0, a linear operation adaptor is also added.</param> public static void Connect(ITimeSpaceComponent outputComponent, string outputId, ITimeSpaceComponent inputComponent, string inputId, IList <string> adaptorIds, double scale) { ITimeSpaceInput input = inputComponent.FindInputItem(inputId); ITimeSpaceOutput output = outputComponent.FindOutputItem(outputId); // End point of connection ITimeSpaceOutput leaf = output; // Add all adaptors foreach (string adaptorID in adaptorIds) { ITimeSpaceAdaptedOutput adaptor = outputComponent.FindAdaptor(adaptorID, leaf, input); if (adaptor == null) { throw new Exception("Coult not find output adaptor with id: " + adaptorID); } adaptor.Initialize(); leaf = adaptor; } // Add a linear conversion adaptor if (scale != 0) { ITimeSpaceAdaptedOutput adaptor = outputComponent.FindAdaptor("LinearOperation", leaf, input); if (adaptor == null) { throw new Exception("Coult not find output linear conversion adaptor"); } adaptor.Arguments[0].Value = scale; adaptor.Initialize(); leaf = adaptor; } // Connect leaf adaptor/output to input leaf.AddConsumer(input); }
public UIAdaptedOutputItem(UIAdaptedFactory factory, IIdentifiable decoratorId, ITimeSpaceAdaptedOutput item, UIOutputItem parent) : base(item, parent) { _factory = factory; _decoratorId = decoratorId; }
void SetValidAdatedOutputs(TreeNode outputSender = null) { UIInputItem input = null; UIOutputItem output = null; if (outputSender != null && outputSender.Tag is UIOutputItem) { output = outputSender.Tag as UIOutputItem; } else { SetErrorText("No output item has been selected"); } List <UIInputItem> checkedInputs = GetDownStreamCheckedItems <UIInputItem>(treeViewTargets.Nodes); if (checkedInputs.Count != 1) { SetErrorText("More than one input item has been selected"); } else { input = checkedInputs[0]; } if (input == null) { listBoxAdaptedOutputs.DataSource = null; return; } if (output == null) { listBoxAdaptedOutputs.DataSource = null; return; } List <UIAdaptedOutputItem> ids = new List <UIAdaptedOutputItem>(); foreach (UIAdaptedFactory factory in externalFactories) { IIdentifiable[] idf = factory.GetAvailableAdaptedOutputIds(output, input); foreach (IIdentifiable f in idf) { ITimeSpaceAdaptedOutput adpout = (ITimeSpaceAdaptedOutput)factory.CreateAdaptedOutput(f, output, input); UIAdaptedOutputItem uiadpout = new UIAdaptedOutputItem(factory, f, adpout, output); ids.Add(uiadpout); } } foreach (IAdaptedOutputFactory factory in connection.SourceModel.LinkableComponent.AdaptedOutputFactories) { UIAdaptedFactory fac = new UIAdaptedFactory(); fac.InitialiseAsNative(factory.Id, connection.SourceModel.LinkableComponent); IIdentifiable[] idf = factory.GetAvailableAdaptedOutputIds(output, input); foreach (IIdentifiable f in idf) { UIAdaptedFactory tempFac = new UIAdaptedFactory(); tempFac.InitialiseAsNative(factory.Id, connection.SourceModel.LinkableComponent); ITimeSpaceAdaptedOutput adpout = (ITimeSpaceAdaptedOutput)factory.CreateAdaptedOutput(f, output, input); UIAdaptedOutputItem uiadpout = new UIAdaptedOutputItem(tempFac, f, adpout, output); ids.Add(uiadpout); } } foreach (TreeNode node in outputSender.Nodes) { if (node.Tag != null && node.Tag is UIAdaptedOutputItem) { UIAdaptedOutputItem item = (UIAdaptedOutputItem)node.Tag; for (int i = 0; i < ids.Count; i++) { if (item.Id == ids[i].Id) { ids.RemoveAt(i); break; } } } } listBoxAdaptedOutputs.DataSource = ids; listBoxAdaptedOutputs.DisplayMember = "Caption"; }
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(); }
public void GetValues2A() { //TODO: 1: The RiverModelEngine should change the inflow over time. As it is now the inflow is the same // in all time steps. Another idea would be to have a output exchange item that hold the accumulated // inflow, this could be useful when testing the manage state interface. // // 2: Make this test run with the two river using different timesteps and with the source river // starting ealier that the target river. // // 3: In this test also events could be tested. Simply test if all the required events are // thrown during the simulations. ITimeSpaceComponent upperRiver = CreateRiverModel(); ITimeSpaceComponent lowerRiver = CreateRiverModel(); // 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(new ArgumentBool("flowItemsAsSpan", false)); 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(new ArgumentBool("flowItemsAsSpan", false)); lowerRiver.Initialize(lowerRiverArguments); Assert.AreEqual("upperRiverModel", upperRiver.Id); Assert.AreEqual("lowerRiverModel", lowerRiver.Id); // 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 and prepare the models 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); // 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"); // specify query times double firstTriggerGetValuesTime = ((LinkableEngine)lowerRiver).CurrentTime.StampAsModifiedJulianDay; double secondTriggerGetValuesTime = firstTriggerGetValuesTime + 3; double thirdTriggerGetValuesTime = firstTriggerGetValuesTime + 4.3; // 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, same as initial time, therefor intial values _queryItem1.TimeSet.SetSingleTimeStamp(firstTriggerGetValuesTime); ITimeSpaceValueSet values = adaptedOutput.GetValues(_queryItem1); Assert.AreEqual(7.0, values.GetValue(0, 0), "value for first query time"); // upper river provides 35/4 inflow to lower river. Lower river last branch flow: // 35/4 (from own runoff) + 35/4/8 (from first node inflow) = 315/32 _queryItem1.TimeSet.SetSingleTimeStamp(secondTriggerGetValuesTime); values = adaptedOutput.GetValues(_queryItem1); Assert.AreEqual(315.0 / 32.0, values.GetValue(0, 0), "value for second query time"); // upper river provides 35/4 inflow to lower river. Lower river last branch flow: // 35/4 (from own runoff) + 35/4/8 (from first node inflow) = 315/32 _queryItem1.TimeSet.SetSingleTimeStamp(thirdTriggerGetValuesTime); values = adaptedOutput.GetValues(_queryItem1); Assert.AreEqual(315.0 / 32.0, values.GetValue(0, 0), "value for third query time"); upperRiver.Finish(); lowerRiver.Finish(); }
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(); }