// [Ignore ("This test fails when dt = 1 hour but works for dt = 0.5 day")] public void GetValues2C() { // This test is a variation of GetValues 2B. What makes this test different is that the the two // connected river models are not using the same timesteps. // This test will test: // - is the buffer working correcly with respect to interpolations and buffering // - is the buffer working correctly with respect to clearing the buffer. try { ILinkableComponent timeSeries = new TimeSeriesComponent(); ILinkableComponent upperRiver = new RiverModelLC(); ILinkableComponent lowerRiver = new RiverModelLC(); Oatc.OpenMI.Sdk.Wrapper.UnitTest.Trigger trigger = new Oatc.OpenMI.Sdk.Wrapper.UnitTest.Trigger(); timeSeries.Initialize(new Argument[0]); // The ModelID is passes in ordet to make it easier to debug, otherwise you cannot se the difference between the two istances of RiverModelLC Argument[] upperRiverArguments = new Argument[2]; upperRiverArguments[0] = new Argument("ModelID","upperRiverModel",true,"argument"); upperRiverArguments[1] = new Argument("TimeStepLength","21600",true,"A time step length of 1 day"); upperRiver.Initialize(upperRiverArguments); // The ModelID is passes in ordet to make it easier to debug, otherwise you cannot se the difference between the two istances of RiverModelLC Argument[] lowerRiverArguments = new Argument[2]; lowerRiverArguments[0] = new Argument("ModelID","lowerRiverModel",true,"argument"); lowerRiverArguments[1] = new Argument("TimeStepLength","86400",true,"xx"); lowerRiver.Initialize(lowerRiverArguments); trigger.Initialize(new Argument[0]); Assert.AreEqual("upperRiverModel",upperRiver.ModelID); Assert.AreEqual("lowerRiverModel",lowerRiver.ModelID); Link timeSeriesToUpperRiverLink = new Link(); timeSeriesToUpperRiverLink.ID = "timeSeriesToUpperRiverLink"; timeSeriesToUpperRiverLink.SourceComponent = timeSeries; timeSeriesToUpperRiverLink.SourceElementSet = timeSeries.GetOutputExchangeItem(0).ElementSet; //last branch in the river timeSeriesToUpperRiverLink.SourceQuantity = timeSeries.GetOutputExchangeItem(0).Quantity; timeSeriesToUpperRiverLink.TargetComponent = upperRiver; timeSeriesToUpperRiverLink.TargetElementSet = upperRiver.GetInputExchangeItem(0).ElementSet; //first node in the river timeSeriesToUpperRiverLink.TargetQuantity = upperRiver.GetInputExchangeItem(0).Quantity; Link link = new Link(); link.ID = "RiverToRiverLink"; link.SourceComponent = upperRiver; link.SourceElementSet = upperRiver.GetOutputExchangeItem(2).ElementSet; //last branch in the river link.SourceQuantity = upperRiver.GetOutputExchangeItem(2).Quantity; link.TargetComponent = lowerRiver; link.TargetElementSet = lowerRiver.GetInputExchangeItem(0).ElementSet; //first node in the river link.TargetQuantity = lowerRiver.GetInputExchangeItem(0).Quantity; Link triggerLink = new Link(); triggerLink.ID = "TriggerLink"; triggerLink.SourceComponent = lowerRiver; triggerLink.SourceElementSet = lowerRiver.GetOutputExchangeItem(2).ElementSet; triggerLink.SourceQuantity = lowerRiver.GetOutputExchangeItem(2).Quantity; triggerLink.TargetComponent = trigger; triggerLink.TargetElementSet = trigger.GetInputExchangeItem(0).ElementSet; triggerLink.TargetQuantity = trigger.GetInputExchangeItem(0).Quantity; timeSeries.AddLink(timeSeriesToUpperRiverLink); upperRiver.AddLink(timeSeriesToUpperRiverLink); upperRiver.AddLink(link); lowerRiver.AddLink(link); lowerRiver.AddLink(triggerLink); trigger.AddLink(triggerLink); timeSeries.Prepare(); upperRiver.Prepare(); lowerRiver.Prepare(); trigger.Prepare(); double firstTriggerGetValuesTime = lowerRiver.TimeHorizon.Start.ModifiedJulianDay; TimeStamp[] triggerTimes = new TimeStamp[2]; triggerTimes[0] = new TimeStamp(firstTriggerGetValuesTime + 12.5); triggerTimes[1] = new TimeStamp(firstTriggerGetValuesTime + 16.2); trigger.Run(triggerTimes); double x1 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(0)).GetScalar(0); Assert.AreEqual(315.0/32.0 + 13.0/64.0,x1); double x2 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(1)).GetScalar(0); Assert.AreEqual(315.0/32.0 + 17.0/64.0,x2); Assert.AreEqual(10,((RiverModelLC) upperRiver)._maxBufferSize); //Test that the buffer is cleared upperRiver.Finish(); lowerRiver.Finish(); upperRiver.Dispose(); lowerRiver.Dispose(); } catch (System.Exception e) { ExceptionHandler.WriteException(e); throw (e); } }
public void GetValues2A() { // == Running with two instances of riverModelLC == // // - The Two river are running with the same timestepping. // // - The link is ID Based link with flow from last branch of the source river to the top // node of the target river. // // - The time argument in the GetValues from rive to river is of type ITimeSpan // //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. try { ILinkableComponent upperRiver = new RiverModelLC(); ILinkableComponent lowerRiver = new RiverModelLC(); Oatc.OpenMI.Sdk.Wrapper.UnitTest.Trigger trigger = new Oatc.OpenMI.Sdk.Wrapper.UnitTest.Trigger(); // The ModelID is passes in ordet to make it easier to debug, otherwise you cannot se the difference between the two istances of RiverModelLC Argument[] upperRiverArguments = new Argument[1]; upperRiverArguments[0] = new Argument("ModelID","upperRiverModel",true,"argument"); upperRiver.Initialize(upperRiverArguments); // The ModelID is passes in ordet to make it easier to debug, otherwise you cannot se the difference between the two istances of RiverModelLC Argument[] lowerRiverArguments = new Argument[1]; lowerRiverArguments[0] = new Argument("ModelID","lowerRiverModel",true,"argument"); lowerRiver.Initialize(lowerRiverArguments); trigger.Initialize(new Argument[0]); Assert.AreEqual("upperRiverModel",upperRiver.ModelID); Assert.AreEqual("lowerRiverModel",lowerRiver.ModelID); Link link = new Link(); link.ID = "RiverToRiverLink"; link.SourceComponent = upperRiver; link.SourceElementSet = upperRiver.GetOutputExchangeItem(2).ElementSet; //last branch in the river link.SourceQuantity = upperRiver.GetOutputExchangeItem(2).Quantity; link.TargetComponent = lowerRiver; link.TargetElementSet = lowerRiver.GetInputExchangeItem(0).ElementSet; //first node in the river link.TargetQuantity = lowerRiver.GetInputExchangeItem(0).Quantity; Link triggerLink = new Link(); triggerLink.ID = "TriggerLink"; triggerLink.SourceComponent = lowerRiver; triggerLink.SourceElementSet = lowerRiver.GetOutputExchangeItem(2).ElementSet; triggerLink.SourceQuantity = lowerRiver.GetOutputExchangeItem(2).Quantity; triggerLink.TargetComponent = trigger; triggerLink.TargetElementSet = trigger.GetInputExchangeItem(0).ElementSet; triggerLink.TargetQuantity = trigger.GetInputExchangeItem(0).Quantity; upperRiver.AddLink(link); lowerRiver.AddLink(link); lowerRiver.AddLink(triggerLink); trigger.AddLink(triggerLink); upperRiver.Prepare(); lowerRiver.Prepare(); trigger.Prepare(); double firstTriggerGetValuesTime = lowerRiver.TimeHorizon.Start.ModifiedJulianDay; TimeStamp[] triggerTimes = new TimeStamp[2]; triggerTimes[0] = new TimeStamp(firstTriggerGetValuesTime + 3); triggerTimes[1] = new TimeStamp(firstTriggerGetValuesTime + 4.3); trigger.Run(triggerTimes); double x1 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(0)).GetScalar(0); Assert.AreEqual(315.0/32.0,x1); double x2 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(1)).GetScalar(0); Assert.AreEqual(315.0/32.0,x2); upperRiver.Finish(); lowerRiver.Finish(); upperRiver.Dispose(); lowerRiver.Dispose(); } catch (System.Exception e) { ExceptionHandler.WriteException(e); throw (e); } }
public void GetValues2B() { // This is a variation of GetValues2A. In this test the timeSeries is linked ID based to the // top node of the upperRiver. The last upperRiver branch of the upperRiver is ID based connected // to the top node of the lowerRiver. The last branch in the lowerRiver is linked to the trigger. // The timeSeries provides data that changes over time. This is what makes this test different from // GetValues2A, where everytning is the same for every time step. try { ILinkableComponent timeSeries = new TimeSeriesComponent(); ILinkableComponent upperRiver = new RiverModelLC(); ILinkableComponent lowerRiver = new RiverModelLC(); Oatc.OpenMI.Sdk.Wrapper.UnitTest.Trigger trigger = new Oatc.OpenMI.Sdk.Wrapper.UnitTest.Trigger(); timeSeries.Initialize(new Argument[0]); // The ModelID is passes in ordet to make it easier to debug, otherwise you cannot se the difference between the two istances of RiverModelLC Argument[] upperRiverArguments = new Argument[1]; upperRiverArguments[0] = new Argument("ModelID","upperRiverModel",true,"argument"); upperRiver.Initialize(upperRiverArguments); // The ModelID is passes in ordet to make it easier to debug, otherwise you cannot se the difference between the two istances of RiverModelLC Argument[] lowerRiverArguments = new Argument[1]; lowerRiverArguments[0] = new Argument("ModelID","lowerRiverModel",true,"argument"); lowerRiver.Initialize(lowerRiverArguments); trigger.Initialize(new Argument[0]); Assert.AreEqual("upperRiverModel",upperRiver.ModelID); Assert.AreEqual("lowerRiverModel",lowerRiver.ModelID); Link timeSeriesToUpperRiverLink = new Link(); timeSeriesToUpperRiverLink.ID = "timeSeriesToUpperRiverLink"; timeSeriesToUpperRiverLink.SourceComponent = timeSeries; timeSeriesToUpperRiverLink.SourceElementSet = timeSeries.GetOutputExchangeItem(0).ElementSet; //last branch in the river timeSeriesToUpperRiverLink.SourceQuantity = timeSeries.GetOutputExchangeItem(0).Quantity; timeSeriesToUpperRiverLink.TargetComponent = upperRiver; timeSeriesToUpperRiverLink.TargetElementSet = upperRiver.GetInputExchangeItem(0).ElementSet; //first node in the river timeSeriesToUpperRiverLink.TargetQuantity = upperRiver.GetInputExchangeItem(0).Quantity; Link link = new Link(); link.ID = "RiverToRiverLink"; link.SourceComponent = upperRiver; link.SourceElementSet = upperRiver.GetOutputExchangeItem(2).ElementSet; //last branch in the river link.SourceQuantity = upperRiver.GetOutputExchangeItem(2).Quantity; link.TargetComponent = lowerRiver; link.TargetElementSet = lowerRiver.GetInputExchangeItem(0).ElementSet; //first node in the river link.TargetQuantity = lowerRiver.GetInputExchangeItem(0).Quantity; Link triggerLink = new Link(); triggerLink.ID = "TriggerLink"; triggerLink.SourceComponent = lowerRiver; triggerLink.SourceElementSet = lowerRiver.GetOutputExchangeItem(2).ElementSet; triggerLink.SourceQuantity = lowerRiver.GetOutputExchangeItem(2).Quantity; triggerLink.TargetComponent = trigger; triggerLink.TargetElementSet = trigger.GetInputExchangeItem(0).ElementSet; triggerLink.TargetQuantity = trigger.GetInputExchangeItem(0).Quantity; timeSeries.AddLink(timeSeriesToUpperRiverLink); upperRiver.AddLink(timeSeriesToUpperRiverLink); upperRiver.AddLink(link); lowerRiver.AddLink(link); lowerRiver.AddLink(triggerLink); trigger.AddLink(triggerLink); timeSeries.Prepare(); upperRiver.Prepare(); lowerRiver.Prepare(); trigger.Prepare(); double firstTriggerGetValuesTime = lowerRiver.TimeHorizon.Start.ModifiedJulianDay; TimeStamp[] triggerTimes = new TimeStamp[2]; triggerTimes[0] = new TimeStamp(firstTriggerGetValuesTime + 12.5); triggerTimes[1] = new TimeStamp(firstTriggerGetValuesTime + 16.2); trigger.Run(triggerTimes); double x1 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(0)).GetScalar(0); Assert.AreEqual(315.0/32.0 + 13.0/64.0,x1); double x2 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(1)).GetScalar(0); Assert.AreEqual(315.0/32.0 + 17.0/64.0,x2); upperRiver.Finish(); lowerRiver.Finish(); upperRiver.Dispose(); lowerRiver.Dispose(); } catch (System.Exception e) { ExceptionHandler.WriteException(e); throw (e); } }
public void RestoreState() { // This test is based on GetValues2C try { ILinkableComponent timeSeries = new TimeSeriesComponent(); ILinkableComponent upperRiver = new RiverModelLC(); ILinkableComponent lowerRiver = new RiverModelLC(); Oatc.OpenMI.Sdk.Wrapper.UnitTest.Trigger trigger = new Oatc.OpenMI.Sdk.Wrapper.UnitTest.Trigger(); timeSeries.Initialize(new Argument[0]); // The ModelID is passes in ordet to make it easier to debug, otherwise you cannot se the difference between the two istances of RiverModelLC Argument[] upperRiverArguments = new Argument[2]; upperRiverArguments[0] = new Argument("ModelID","upperRiverModel",true,"argument"); upperRiverArguments[1] = new Argument("TimeStepLength","21600",true,"xx"); upperRiver.Initialize(upperRiverArguments); // The ModelID is passes in ordet to make it easier to debug, otherwise you cannot se the difference between the two istances of RiverModelLC Argument[] lowerRiverArguments = new Argument[2]; lowerRiverArguments[0] = new Argument("ModelID","lowerRiverModel",true,"argument"); lowerRiverArguments[1] = new Argument("TimeStepLength","86400",true,"xx"); lowerRiver.Initialize(lowerRiverArguments); trigger.Initialize(new Argument[0]); Assert.AreEqual("upperRiverModel",upperRiver.ModelID); Assert.AreEqual("lowerRiverModel",lowerRiver.ModelID); Link timeSeriesToUpperRiverLink = new Link(); timeSeriesToUpperRiverLink.ID = "timeSeriesToUpperRiverLink"; timeSeriesToUpperRiverLink.SourceComponent = timeSeries; timeSeriesToUpperRiverLink.SourceElementSet = timeSeries.GetOutputExchangeItem(0).ElementSet; //last branch in the river timeSeriesToUpperRiverLink.SourceQuantity = timeSeries.GetOutputExchangeItem(0).Quantity; timeSeriesToUpperRiverLink.TargetComponent = upperRiver; timeSeriesToUpperRiverLink.TargetElementSet = upperRiver.GetInputExchangeItem(0).ElementSet; //first node in the river timeSeriesToUpperRiverLink.TargetQuantity = upperRiver.GetInputExchangeItem(0).Quantity; Link link = new Link(); link.ID = "RiverToRiverLink"; link.SourceComponent = upperRiver; link.SourceElementSet = upperRiver.GetOutputExchangeItem(2).ElementSet; //last branch in the river link.SourceQuantity = upperRiver.GetOutputExchangeItem(2).Quantity; link.TargetComponent = lowerRiver; link.TargetElementSet = lowerRiver.GetInputExchangeItem(0).ElementSet; //first node in the river link.TargetQuantity = lowerRiver.GetInputExchangeItem(0).Quantity; Link triggerLink = new Link(); triggerLink.ID = "TriggerLink"; triggerLink.SourceComponent = lowerRiver; triggerLink.SourceElementSet = lowerRiver.GetOutputExchangeItem(2).ElementSet; triggerLink.SourceQuantity = lowerRiver.GetOutputExchangeItem(2).Quantity; triggerLink.TargetComponent = trigger; triggerLink.TargetElementSet = trigger.GetInputExchangeItem(0).ElementSet; triggerLink.TargetQuantity = trigger.GetInputExchangeItem(0).Quantity; timeSeries.AddLink(timeSeriesToUpperRiverLink); upperRiver.AddLink(timeSeriesToUpperRiverLink); upperRiver.AddLink(link); lowerRiver.AddLink(link); lowerRiver.AddLink(triggerLink); trigger.AddLink(triggerLink); timeSeries.Prepare(); upperRiver.Prepare(); lowerRiver.Prepare(); trigger.Prepare(); // double firstTriggerGetValuesTime = lowerRiver.TimeHorizon.Start.ModifiedJulianDay; // TimeStamp[] triggerTimes = new TimeStamp[2]; // triggerTimes[0] = new TimeStamp(firstTriggerGetValuesTime + 12.5); // triggerTimes[1] = new TimeStamp(firstTriggerGetValuesTime + 16.2); double t = lowerRiver.TimeHorizon.Start.ModifiedJulianDay; Assert.AreEqual(315.0/32.0 + 13.0/64.0, ((ScalarSet)lowerRiver.GetValues(new TimeStamp(t+12.5),"TriggerLink")).GetScalar(0)); string lowerRiverStateID = ((IManageState) lowerRiver).KeepCurrentState(); string upperRiverStateID = ((IManageState) upperRiver).KeepCurrentState(); Assert.AreEqual(315.0/32.0 + 17.0/64.0, ((ScalarSet)lowerRiver.GetValues(new TimeStamp(t+16.2),"TriggerLink")).GetScalar(0)); ((IManageState) lowerRiver).RestoreState(lowerRiverStateID); ((IManageState) upperRiver).RestoreState(upperRiverStateID); lowerRiver.GetValues(new TimeStamp(t + 14.0),"TriggerLink"); Assert.AreEqual(315.0/32.0 + 17.0/64.0, ((ScalarSet)lowerRiver.GetValues(new TimeStamp(t+16.2),"TriggerLink")).GetScalar(0)); // double x1 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(0)).GetScalar(0); // Assert.AreEqual(315.0/32.0 + 13.0/64.0,x1); // // double x2 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(1)).GetScalar(0); // Assert.AreEqual(315.0/32.0 + 17.0/64.0,x2); // // Assert.AreEqual(2,((RiverModelLC) upperRiver)._maxBufferSize); //Test that the buffer is cleared upperRiver.Finish(); lowerRiver.Finish(); upperRiver.Dispose(); lowerRiver.Dispose(); } catch (System.Exception e) { ExceptionHandler.WriteException(e); throw (e); } }