コード例 #1
0
        public void InitialiseAs3rdParty(FileInfo assembly, string type)
        {
            _assembly   = assembly;
            _is3rdParty = true;

            // 3rd party factory

            if (!_assembly.Exists)
            {
                throw new ArgumentException("Cannot find adapter factory " + _assembly.FullName);
            }

            Assembly ass = System.Reflection.Assembly.LoadFile(_assembly.FullName);

            if (ass == null)
            {
                throw new ArgumentException("Cannot load adapter factory " + _assembly.FullName);
            }

            _type = ass.GetType(type, true, true);

            _factory = (IAdaptedOutputFactory)Activator.CreateInstance(_type);

            if (_factory == null)
            {
                throw new ArgumentException("Cannot create adapter factory "
                                            + _assembly.FullName + ": " + _type);
            }
        }
コード例 #2
0
        public void CreateTestData()
        {
            waterLevelQuantity = new Quantity(
                new Unit(PredefinedUnits.CubicMeterPerSecond), "Flow", "Flow");

            xyPolygon = new ElementSet("one polygon, 5 points", "xyPolygon", ElementType.Polygon);

            Element p0 = new Element("p0");

            p0.AddVertex(new Coordinate(7.5, 10, 0));
            p0.AddVertex(new Coordinate(15, 20, 0));
            p0.AddVertex(new Coordinate(10, 30, 0));
            p0.AddVertex(new Coordinate(5, 30, 0));
            p0.AddVertex(new Coordinate(0, 20, 0));
            xyPolygon.AddElement(p0);

            xyPolylineA = new ElementSet("3 points polyline", "xyPolylineA", ElementType.PolyLine);

            Element l0 = new Element("PL_0");
            Element l1 = new Element("PL_1");

            Coordinate v0 = new Coordinate(0, 20, 0);
            Coordinate v1 = new Coordinate(0, 10, 0);
            Coordinate v2 = new Coordinate(0, 0, 0);

            l0.AddVertex(v0);
            l0.AddVertex(v2);

            l1.AddVertex(v1);
            l1.AddVertex(v2);

            xyPolylineA.AddElement(l0);
            xyPolylineA.AddElement(l1);

            xyPointA = new ElementSet("4 points elementset A", "pointsA", ElementType.Point);
            Element e0 = new Element("Pnt_0");
            Element e1 = new Element("Pnt_1");
            Element e2 = new Element("Pnt_2");
            Element e3 = new Element("Pnt_3");

            e0.AddVertex(new Coordinate(0, 100, 0));
            e1.AddVertex(new Coordinate(0, 0, 0));
            e2.AddVertex(new Coordinate(100, 0, 0));
            e3.AddVertex(new Coordinate(100, 100, 0));
            xyPointA.AddElement(e0);
            xyPointA.AddElement(e1);
            xyPointA.AddElement(e2);
            xyPointA.AddElement(e3);

            xyPointB = new ElementSet("4 points elementset B", "pointsB", ElementType.Point);
            e0       = new Element("e0");
            e1       = new Element("e1");
            e0.AddVertex(new Coordinate(25, 25, 0));
            e1.AddVertex(new Coordinate(25, 75, 0));
            xyPointB.AddElement(e0);
            xyPointB.AddElement(e1);

            adaptedOutputFactory = new SpatialAdaptedOutputFactory("Oatc Spatial Adapted Output Factory");
        }
コード例 #3
0
ファイル: RiverModelTest.cs プロジェクト: muguangyuze/OpenMI
        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();
        }
コード例 #4
0
        private static void ConnectItemsWithTimeInterpolator(ITimeSpaceComponent sourceComponentInstance,
                                                             string outputItemId,
                                                             ITimeSpaceComponent targetComponentInstance, string inputItemId)
        {
            ITimeSpaceOutput      output = FindOutputItem(sourceComponentInstance, outputItemId);
            ITimeSpaceInput       input  = FindInputItem(targetComponentInstance, inputItemId);
            IAdaptedOutputFactory derivedOutputFactory = sourceComponentInstance.AdaptedOutputFactories[0];

            IIdentifiable[]    derivedOutputIdentifiers = derivedOutputFactory.GetAvailableAdaptedOutputIds(output, input);
            IBaseAdaptedOutput timeInterpolator         = derivedOutputFactory.CreateAdaptedOutput(derivedOutputIdentifiers[0], output, input);
        }
コード例 #5
0
        public void InitialiseAsNative(string id, IBaseLinkableComponent source)
        {
            _id           = id;
            _modelCaption = source.Caption;
            _is3rdParty   = false;

            foreach (IAdaptedOutputFactory factory in source.AdaptedOutputFactories)
            {
                if (factory.Id == id)
                {
                    _type     = factory.GetType();
                    _assembly = new FileInfo(_type.Assembly.Location);
                    _factory  = factory;
                    return;
                }
            }

            throw new ArgumentException(string.Format(
                                            "Cannot find adapter factory \"{0}\" in model \"{1}\"", id, source.Caption));
        }
コード例 #6
0
        public static IBaseAdaptedOutput ConnectItemsUsingAdaptedOutput(ITimeSpaceComponent sourceComponentInstance, ITimeSpaceOutput output, ITimeSpaceInput input, string adaptedOutputId)
        {
            IAdaptedOutputFactory adaptedOutputFactory = sourceComponentInstance.AdaptedOutputFactories[0];

            IIdentifiable[] adaptedOutputIds        = adaptedOutputFactory.GetAvailableAdaptedOutputIds(output, input);
            IIdentifiable   adaptedOutputIdentifier = null;

            foreach (IIdentifiable identifier in adaptedOutputIds)
            {
                if (identifier.Id.StartsWith(adaptedOutputId))
                {
                    adaptedOutputIdentifier = identifier;
                }
            }
            if (adaptedOutputIdentifier == null)
            {
                throw new Exception("AdaptedOutput with name \"" + adaptedOutputId + "\" not found");
            }
            IBaseAdaptedOutput timeExtrapolator = adaptedOutputFactory.CreateAdaptedOutput(adaptedOutputIdentifier,
                                                                                           output, input);

            return(timeExtrapolator);
        }
コード例 #7
0
 public AdaptedOutputFactory(IAdaptedOutputFactory factory)
     : base(factory)
 {
     _factory = factory;
 }
コード例 #8
0
ファイル: RiverModelTest.cs プロジェクト: muguangyuze/OpenMI
        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();
        }
コード例 #9
0
ファイル: RiverModelTest.cs プロジェクト: muguangyuze/OpenMI
        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();
        }
コード例 #10
0
ファイル: RiverModelTest.cs プロジェクト: muguangyuze/OpenMI
        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();
        }
コード例 #11
0
ファイル: RiverModelTest.cs プロジェクト: muguangyuze/OpenMI
        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();
        }