示例#1
0
        public void UseCase01()
        {
            // This is the test for use case one descripbed in the OpenMI Guidelines for model migration
            // In this test a test model will provide inflow to the top node and to the node downstream
            // to the top node. The trigger will get flow from the most downstream branch.
            try
            {
                ILinkableComponent simpleRiver;
                simpleRiver = new Oatc.OpenMI.Examples.ModelComponents.SimpleRiver.Wrapper.SimpleRiverOpenMIComponent();
                Argument[] arguments = new Argument[1];
                arguments[0] = new Argument("FilePath", @"..\..\", true, "description");

                ILinkableComponent testRiver = new TestRiverLC();
                Oatc.OpenMI.Examples.TriggerComponents.SimpleTrigger.Trigger trigger = new Oatc.OpenMI.Examples.TriggerComponents.SimpleTrigger.Trigger();

                simpleRiver.Initialize(arguments);
                testRiver.Initialize(new Argument[0]);
                trigger.Initialize(new Argument[0]);

                Link testRiverToSimpleRiverLinkTopNode =
                    new Link(testRiver,                                       //source LinkableComponent
                             testRiver.GetOutputExchangeItem(0).ElementSet,   //source ElementSet
                             testRiver.GetOutputExchangeItem(0).Quantity,     //source Quantity
                             simpleRiver,                                     //Target LinkableComponent
                             simpleRiver.GetInputExchangeItem(3).ElementSet,  //target ElementSet
                             simpleRiver.GetInputExchangeItem(3).Quantity,    //target Quantity
                             "testRiverToSimpleRiverLink");                   //linkID

                Link testRiverToSimpleRiverLinkNode1 =
                    new Link(testRiver,                                                           //source LinkableComponent
                             testRiver.GetOutputExchangeItem(0).ElementSet,                       //source ElementSet
                             testRiver.GetOutputExchangeItem(0).Quantity,                         //source Quantity
                             simpleRiver,                                                         //Target LinkableComponent
                             simpleRiver.GetInputExchangeItem(4).ElementSet,                      //target ElementSet
                             simpleRiver.GetInputExchangeItem(4).Quantity,                        //target Quantity
                             "testRiverToSimpleRiverLink");                                       //linkID

                Link simpleRiverToTriggerLink =
                    new Link(simpleRiver,
                             simpleRiver.GetOutputExchangeItem(2).ElementSet,
                             simpleRiver.GetOutputExchangeItem(2).Quantity, trigger,
                             simpleRiver.GetOutputExchangeItem(2).ElementSet,
                             simpleRiver.GetOutputExchangeItem(2).Quantity,
                             "ID2");

                testRiver.AddLink(testRiverToSimpleRiverLinkTopNode);
                simpleRiver.AddLink(testRiverToSimpleRiverLinkTopNode);

                testRiver.AddLink(testRiverToSimpleRiverLinkNode1);
                simpleRiver.AddLink(testRiverToSimpleRiverLinkNode1);

                simpleRiver.AddLink(simpleRiverToTriggerLink);
                trigger.AddLink(simpleRiverToTriggerLink);

                IListener eventListener = new Oatc.OpenMI.Examples.EventListeners.SimpleEventListener.EventListener();
                for (int i = 0; i < eventListener.GetAcceptedEventTypeCount(); i++)
                {
                    for (int n = 0; n < simpleRiver.GetPublishedEventTypeCount(); n++)
                    {
                        if (eventListener.GetAcceptedEventType(i) == simpleRiver.GetPublishedEventType(n))
                        {
                            simpleRiver.Subscribe(eventListener, eventListener.GetAcceptedEventType(i));
                        }
                    }
                    for (int n = 0; n < testRiver.GetPublishedEventTypeCount(); n++)
                    {
                        if (eventListener.GetAcceptedEventType(i) == testRiver.GetPublishedEventType(n))
                        {
                            testRiver.Subscribe(eventListener, eventListener.GetAcceptedEventType(i));
                        }
                    }
                }

                simpleRiver.Prepare();
                testRiver.Prepare();
                trigger.Prepare();

                double startTime = simpleRiver.TimeHorizon.Start.ModifiedJulianDay;

                Oatc.OpenMI.Sdk.Backbone.TimeStamp[] times = new Oatc.OpenMI.Sdk.Backbone.TimeStamp[5];
                times[0] = new TimeStamp(startTime + 1);
                times[1] = new TimeStamp(startTime + 2);
                times[2] = new TimeStamp(startTime + 3);
                times[3] = new TimeStamp(startTime + 4);
                times[4] = new TimeStamp(startTime + 5);

                trigger.Run(times);

                Assert.AreEqual(3.8, ((ScalarSet)trigger.ResultsBuffer.GetValuesAt(0)).data[0]);
                Assert.AreEqual(7.6, ((ScalarSet)trigger.ResultsBuffer.GetValuesAt(1)).data[0]);                 //ts1
                Assert.AreEqual(9.1, ((ScalarSet)trigger.ResultsBuffer.GetValuesAt(2)).data[0]);
                Assert.AreEqual(10.6, ((ScalarSet)trigger.ResultsBuffer.GetValuesAt(3)).data[0]);                //ts2
                Assert.AreEqual(12.1, ((ScalarSet)trigger.ResultsBuffer.GetValuesAt(4)).data[0]);

                simpleRiver.Finish();
                testRiver.Finish();
                trigger.Finish();
            }
            catch (System.Exception e)
            {
                Oatc.OpenMI.Examples.ExeptionHandlers.SimpleExceptionHandler.ExceptionHandler.WriteException(e);
                throw (e);
            }
        }
示例#2
0
        public void UseCase02()
        {
            try
            {
                ILinkableComponent simpleRiver;
                simpleRiver = new Oatc.OpenMI.Examples.ModelComponents.SimpleRiver.Wrapper.SimpleRiverOpenMIComponent();
                Argument[] arguments = new Argument[1];
                arguments[0] = new Argument("FilePath", @"..\..\", true, "description");

                ILinkableComponent runoffLC = new RunoffDataLC();
                Oatc.OpenMI.Examples.TriggerComponents.SimpleTrigger.Trigger trigger = new Oatc.OpenMI.Examples.TriggerComponents.SimpleTrigger.Trigger();

                simpleRiver.Initialize(arguments);
                runoffLC.Initialize(new Argument[0]);
                trigger.Initialize(new Argument[0]);

                // --- DataOperations -----
                int dataOperationCount = runoffLC.GetOutputExchangeItem(0).DataOperationCount;
                int dataoperationIndex = -999;
                for (int i = 0; i < dataOperationCount; i++)
                {
                    for (int n = 0; n < runoffLC.GetOutputExchangeItem(0).GetDataOperation(i).ArgumentCount; n++)
                    {
                        if (runoffLC.GetOutputExchangeItem(0).GetDataOperation(i).GetArgument(n).Value == "Weighted Mean")
                        {
                            dataoperationIndex = i;
                        }
                    }
                }
                IDataOperation dataOperation = runoffLC.GetOutputExchangeItem(0).GetDataOperation(dataoperationIndex);

                ArrayList dataOperations = new ArrayList();
                dataOperations.Add(dataOperation);

                //-- Create links --
                Link runoffLCToSimpleRiverLink =
                    new Link(runoffLC,                                                            //source LinkableComponent
                             runoffLC.GetOutputExchangeItem(0).ElementSet,                        //source ElementSet
                             runoffLC.GetOutputExchangeItem(0).Quantity,                          //source Quantity
                             simpleRiver,                                                         //Target LinkableComponent
                             simpleRiver.GetInputExchangeItem(7).ElementSet,                      //target ElementSet
                             simpleRiver.GetInputExchangeItem(7).Quantity,                        //target Quantity
                             "runoffLCToSimpleRiverLink",                                         //linkID
                             "runoffLCToSimpleRiverLink Description",                             //link description
                             dataOperations);                                                     //dataOperations


                Link simpleRiverToTriggerLink =
                    new Link(simpleRiver,
                             simpleRiver.GetOutputExchangeItem(2).ElementSet,
                             simpleRiver.GetOutputExchangeItem(2).Quantity, trigger,
                             simpleRiver.GetOutputExchangeItem(2).ElementSet,
                             simpleRiver.GetOutputExchangeItem(2).Quantity,
                             "ID2");

                runoffLC.AddLink(runoffLCToSimpleRiverLink);
                simpleRiver.AddLink(runoffLCToSimpleRiverLink);

                simpleRiver.AddLink(simpleRiverToTriggerLink);
                trigger.AddLink(simpleRiverToTriggerLink);

                IListener eventListener = new Oatc.OpenMI.Examples.EventListeners.SimpleEventListener.EventListener();
                for (int i = 0; i < eventListener.GetAcceptedEventTypeCount(); i++)
                {
                    for (int n = 0; n < simpleRiver.GetPublishedEventTypeCount(); n++)
                    {
                        if (eventListener.GetAcceptedEventType(i) == simpleRiver.GetPublishedEventType(n))
                        {
                            simpleRiver.Subscribe(eventListener, eventListener.GetAcceptedEventType(i));
                        }
                    }
                    for (int n = 0; n < runoffLC.GetPublishedEventTypeCount(); n++)
                    {
                        if (eventListener.GetAcceptedEventType(i) == runoffLC.GetPublishedEventType(n))
                        {
                            runoffLC.Subscribe(eventListener, eventListener.GetAcceptedEventType(i));
                        }
                    }
                }

                simpleRiver.Prepare();
                runoffLC.Prepare();
                trigger.Prepare();

                double startTime = simpleRiver.TimeHorizon.Start.ModifiedJulianDay;

                Oatc.OpenMI.Sdk.Backbone.TimeStamp[] times = new Oatc.OpenMI.Sdk.Backbone.TimeStamp[5];
                times[0] = new TimeStamp(startTime + 1);
                times[1] = new TimeStamp(startTime + 2);
                times[2] = new TimeStamp(startTime + 3);
                times[3] = new TimeStamp(startTime + 4);
                times[4] = new TimeStamp(startTime + 5);

                trigger.Run(times);

//				Assert.AreEqual(3.8,((ScalarSet) trigger.ResultsBuffer.GetValuesAt(0)).data[0]);
                Assert.AreEqual(5.6 + 3 + 4.0 / 3.0, ((ScalarSet)trigger.ResultsBuffer.GetValuesAt(1)).data[0]);              //ts1
//				Assert.AreEqual(9.1,((ScalarSet) trigger.ResultsBuffer.GetValuesAt(2)).data[0]);
                Assert.AreEqual(8.6 + 3 + 4.0 / 3.0, ((ScalarSet)trigger.ResultsBuffer.GetValuesAt(3)).data[0]);              //ts2
//				Assert.AreEqual(12.1,((ScalarSet) trigger.ResultsBuffer.GetValuesAt(4)).data[0]);

                simpleRiver.Finish();
                runoffLC.Finish();
                trigger.Finish();
            }
            catch (System.Exception e)
            {
                Oatc.OpenMI.Examples.ExeptionHandlers.SimpleExceptionHandler.ExceptionHandler.WriteException(e);
                throw (e);
            }
        }