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 UpdatePullDrivenBWithTimeExtrapolator() { const bool useTimeExtrapolator = true; ICollection <ITimeSpaceComponent> components = RainRrCfCompositions.CreateCompositionB(useTimeExtrapolator); RunPullDriven(components); }
//private static void RunLoopDriven(IEnumerable<ITimeSpaceComponent> components) //{ // bool atLeastOneComponentFinished = false; // foreach (ITimeSpaceComponent component in components) // { // component.CascadingUpdateCallsDisabled = true; // } // const int maxNumLoopCalls = 10000; // int numLoopCalls = 0; // while (!atLeastOneComponentFinished && numLoopCalls < maxNumLoopCalls) // { // foreach (ITimeSpaceComponent component in components) // { // component.Update(); // } // // check if components are finished // atLeastOneComponentFinished = CheckIfComponentsAreFinished(components); // numLoopCalls++; // } // if (numLoopCalls == maxNumLoopCalls) // { // throw new Exception(_MaxLoopCallsExceeded); // } //} private static void RunPullDriven(IEnumerable <ITimeSpaceComponent> components) { ITimeSpaceComponent componentAtEndOfChain = RainRrCfCompositions.FindComponent(components, RainRrCfCompositions.channelFlowId); while (!(componentAtEndOfChain.Status == LinkableComponentStatus.Done || componentAtEndOfChain.Status == LinkableComponentStatus.Failed)) { componentAtEndOfChain.Update(); } }
public void UpdatePullDrivenB() { const bool useTimeExtrapolator = false; ICollection <ITimeSpaceComponent> components = RainRrCfCompositions.CreateCompositionB(useTimeExtrapolator); try { RunPullDriven(components); } catch (Exception e) { Assert.IsTrue(e.Message.StartsWith("Could not update engine") && e.Message.EndsWith("Use a Time Extrapolator."), "Check expected exception"); } }
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 void UpdatePullDrivenA() { ICollection <ITimeSpaceComponent> components = RainRrCfCompositions.CreateCompositionA(); RunPullDriven(components); }