public override IOutputExchangeItem GetOutputExchangeItem(int outputExchangeItemIndex)
		{
			Quantity quantity = new Quantity(new Unit("literprSecond",0.001,0,"lprsec"),"flow","flow", global::OpenMI.Standard.ValueType.Scalar,new Dimension());
			ElementSet elementSet = new ElementSet("oo","ID",ElementType.IDBased,new SpatialReference("no"));
			Element element = new Element("ElementID");
			elementSet.AddElement(element);
			OutputExchangeItem outputExchangeItem = new OutputExchangeItem();
			outputExchangeItem.ElementSet = elementSet;
			outputExchangeItem.Quantity   = quantity;

			return outputExchangeItem;
		}
		public void Init()
		{
			eventSent = false;
			testComponent1 = new TestComponent();

			testComponent2 = new TestComponent2();

			Link link1 = new Link();
			link1.ID ="Link1";
			link1.SourceComponent = testComponent1;
			link1.TargetComponent = testComponent2;
			Link link2 = new Link();
			link2.ID ="Link2";
			link2.SourceComponent = testComponent2;
			link2.TargetComponent = testComponent1;
			Link link3 = new Link();
			link3.ID = "Link3";
			link3.SourceComponent = link3.TargetComponent = testComponent1;

			testComponent1.AddLink(link1);
			testComponent1.AddLink(link2);
			testComponent1.AddLink(link3);
			testComponent2.AddLink(link1);
			testComponent2.AddLink(link2);
			testComponent1.RemoveLink("Link3");

			testComponent1.Subscribe(this,EventType.Informative);

			Quantity q = new Quantity("Q");
			ElementSet elementSet = new ElementSet();
			elementSet.ID = "ES";

			InputExchangeItem inputExchangeItem = new InputExchangeItem();
			inputExchangeItem.Quantity = q;
			inputExchangeItem.ElementSet = elementSet;
			testComponent1.AddInputExchangeItem(inputExchangeItem);

			OutputExchangeItem outputExchangeItem = new OutputExchangeItem();
			outputExchangeItem.Quantity = new Quantity("Q2");
			ElementSet elementSet2 = new ElementSet();
			elementSet2.ID = "ES2";
			outputExchangeItem.ElementSet = elementSet;
			testComponent1.AddOutputExchangeItem(outputExchangeItem);
		}
    public override void Initialize()
    {

      Dictionary<string, string> argumentsDictionary = new Dictionary<string, string>();

      //TODO: Check that you can assume that e.g. a configuration editor will populate the Argumenst, based on data from the OMI file
      foreach (IArgument argument in this.Arguments)
      {
        argumentsDictionary.Add(argument.Id, argument.ValueAsString);
      }
      filename = argumentsDictionary["Filename"];
      //outputFilename = argumentsDictionary["OutputFilename"];

      timeSeriesGroup = TimeSeriesGroupFactory.Create(filename);

      Outputs = new List<IBaseOutput>();


      foreach (var ts in timeSeriesGroup.Items)
      {
        Dimension dimention = new Dimension();
        dimention.SetPower(DimensionBase.AmountOfSubstance, ts.Unit.Dimension.AmountOfSubstance);
        dimention.SetPower(DimensionBase.Currency, ts.Unit.Dimension.Currency);
        dimention.SetPower(DimensionBase.ElectricCurrent, ts.Unit.Dimension.ElectricCurrent);
        dimention.SetPower(DimensionBase.Length, ts.Unit.Dimension.Length);
        dimention.SetPower(DimensionBase.LuminousIntensity, ts.Unit.Dimension.LuminousIntensity);
        dimention.SetPower(DimensionBase.Mass, ts.Unit.Dimension.Mass);
        dimention.SetPower(DimensionBase.Time, ts.Unit.Dimension.Time);

        Unit unit = new Unit(ts.Unit.ID);
        unit.Description = ts.Unit.Description;
        unit.ConversionFactorToSI = ts.Unit.ConversionFactorToSI;
        unit.OffSetToSI = ts.Unit.OffSetToSI;
        unit.Dimension = dimention;

        Quantity quantity = new Quantity();
        quantity.Caption = ts.Name;
        quantity.Description = ts.Description;
        quantity.Unit = unit;

        ElementSet elementSet = new ElementSet("IDBased");
        elementSet.Description = "IDBased";
        elementSet.ElementType = global::OpenMI.Standard2.TimeSpace.ElementType.IdBased;
        Element element = new Element();
        element.Caption = "IDBased";
        elementSet.AddElement(element);



        Output o = new Output(ts.Name, quantity, elementSet);

        o.TimeSet = new TimeSet();
        o.Values = new HydroNumerics.OpenMI.Sdk.Backbone.Generic.TimeSpaceValueSet<double>();

        if (ts is TimespanSeries)
        {
          foreach (var tsi in ((TimespanSeries)ts).Items)
          {
            o.TimeSet.Times.Add(new HydroNumerics.OpenMI.Sdk.Backbone.Time(ts.StartTime, ts.EndTime));
            o.Values.Values2D.Add(new List<double> { tsi.Value });
          }
        }
        else
        {
          foreach (var tsi in ((TimestampSeries)ts).Items)
          {
            o.TimeSet.Times.Add(new HydroNumerics.OpenMI.Sdk.Backbone.Time(ts.StartTime));
            o.Values.Values2D.Add(new List<double> { tsi.Value });
          }
        }

        Outputs.Add(o);
      }

      Caption = timeSeriesGroup.Name;
      Description = timeSeriesGroup.Name;



    }
예제 #4
0
		public void Equals()
		{
			Quantity quantity2 = new Quantity(new Unit("UnitID",1.0,0.0,"Description"),"Description",
                "ID", global::OpenMI.Standard.ValueType.Scalar, new Dimension());

			Assert.IsTrue(quantity.Equals(quantity2));

			Assert.IsFalse(quantity.Equals(null));
			Assert.IsFalse(quantity.Equals("string"));

		}
예제 #5
0
		public void Constructor()
		{
			Quantity quantity2 = new Quantity(quantity);
			Assert.AreEqual(quantity,quantity2);
		}
예제 #6
0
		public void Init()
		{
			quantity = new Quantity(new Unit("UnitID",1.0,0.0,"Description"),"Description",
				"ID",global::OpenMI.Standard.ValueType.Scalar,new Dimension());
		}
예제 #7
0
		public void EqualsValueType()
		{
			Quantity quantity2 = new Quantity(new Unit("UnitID",1.0,0.0,"Description"),"Description",
                "ID", global::OpenMI.Standard.ValueType.Vector, new Dimension());

			Assert.IsFalse(quantity.Equals(quantity2));
		}
예제 #8
0
        public void Initialize(System.Collections.Hashtable properties)
        {

            if (!properties.Contains("InputFilename"))
            {
                throw new Exception("Missing key \"InputFilename\" in parameter to method HydroNumerics.HydroNet.OpenMI.EngineWrapper.Initialize(...)");
            }

            if (!properties.Contains("TimestepLength"))
            {
                throw new Exception("Missing key \"TimestepLength\" in parameter to method HydroNumerics.HydroNet.OpenMI.EngineWrapper.Initialize(...)");
            }


            inputFilename = (string)properties["InputFilename"];

            double dt = Convert.ToDouble((string)properties["TimestepLength"]);
            timestepLength = System.TimeSpan.FromSeconds(dt);

            
            // because the OpenMI configuration editor works makes paths relative to locations of OMI files or the configuration editor itselves, thigs may go wrong.
            // In order to overcome this problem, the full path for the input file is saves, so when the Finish method is invoked, the output is save to the input file again and not
            // a file at some random location :-). See below
            System.IO.FileInfo fileInfo = new System.IO.FileInfo(inputFilename);
            inputFilename = fileInfo.FullName;

            model = HydroNumerics.HydroNet.Core.ModelFactory.GetModel(inputFilename);
            model.Initialize();
            //model = ModelFactory.GetModel(inputFilename);


            foreach (var wb in model._waterBodies)
            {
              //Build exchangeitems from groundwater boundaries
              foreach (var gwb in wb.GroundwaterBoundaries)
              {
                GroundWaterBoundary GWB = gwb as GroundWaterBoundary;
                if (GWB != null)
                {
                  ElementSet elementSet = new ElementSet();
                  elementSet.ID = GWB.Name;
                  elementSet.Description = "Location: " + GWB.Name;
                  elementSet.SpatialReference = new SpatialReference("Undefined");
                  Element element = new Element();
                  element.ID = GWB.Name;

                  elementSet.ElementType = ElementType.XYPolygon;
                  foreach (XYPoint xyPoint in ((XYPolygon)GWB.ContactGeometry).Points)
                  {
                    element.AddVertex(new Vertex(xyPoint.X, xyPoint.Y, 0));
                  }

                  elementSet.AddElement(element);

                  //Head
                  HydroNumerics.OpenMI.Sdk.Backbone.Dimension dimension = new HydroNumerics.OpenMI.Sdk.Backbone.Dimension();
                  dimension.Length = 1;

                  HydroNumerics.OpenMI.Sdk.Backbone.Unit unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit();
                  unit.ID = "m";
                  unit.Description = "meter";
                  unit.ConversionFactorToSI = 1;
                  unit.OffSetToSI = 0;

                  Quantity quantity = new Quantity();
                  quantity.ID = "Head";
                  quantity.Description = "Head at:" + GWB.Name;
                  quantity.Dimension = dimension;
                  quantity.Unit = unit;
                  
                  InputExchangeItem inputExchangeItem = new InputExchangeItem();
                  inputExchangeItem.Quantity = quantity;
                  inputExchangeItem.ElementSet = elementSet;
                  inputExchangeItems.Add(inputExchangeItem);

                  HeadBoundaries.Add(GWB.Name, GWB);

                  //Leakage
                  Quantity leakage = new Quantity("Leakage");
                  leakage.Description = "Leakage at:" + GWB.Name;
                  var leakageDimension = new HydroNumerics.OpenMI.Sdk.Backbone.Dimension();
                  leakageDimension.Length = 3;
                  leakageDimension.Time = -1;
                  leakage.Dimension = leakageDimension;
                  leakage.Unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit("m3/s", 1, 0);

                  OutputExchangeItem outputitem = new OutputExchangeItem();
                  outputitem.Quantity = leakage;
                  outputitem.ElementSet = elementSet;
                  outputExchangeItems.Add(outputitem);
                  LeakageBoundaries.Add(GWB.Name, GWB);

                }
              }

              foreach (var S in wb.Sources)
              {
                ElementSet elementSet = new ElementSet();
                elementSet.ID = S.Name;
                elementSet.Description = "Location: " + S.Name;
                elementSet.SpatialReference = new SpatialReference("Undefined");
                Element element = new Element();
                element.ID = S.Name;

                elementSet.ElementType = ElementType.IDBased;


                //Flow
                Quantity leakage = new Quantity("Flow");
                leakage.Description = "Flow at:" + S.Name;
                var leakageDimension = new HydroNumerics.OpenMI.Sdk.Backbone.Dimension();
                leakageDimension.Length = 3;
                leakageDimension.Time = -1;
                leakage.Dimension = leakageDimension;
                leakage.Unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit("m3/s", 1, 0);

                InputExchangeItem outputitem = new InputExchangeItem();
                outputitem.Quantity = leakage;
                outputitem.ElementSet = elementSet;
                inputExchangeItems.Add(outputitem);
                FlowBoundaries.Add(S.Name, (SinkSourceBoundary)S);
                


              }
            }

            

            //foreach (var exchangeItem in model.ExchangeItems)
            //{
            //    HydroNumerics.OpenMI.Sdk.Backbone.Dimension dimention = new HydroNumerics.OpenMI.Sdk.Backbone.Dimension();
            //    dimention.AmountOfSubstance = exchangeItem.Unit.Dimension.AmountOfSubstance;
            //    dimention.Currency = exchangeItem.Unit.Dimension.Currency;
            //    dimention.ElectricCurrent = exchangeItem.Unit.Dimension.ElectricCurrent;
            //    dimention.Length = exchangeItem.Unit.Dimension.AmountOfSubstance;
            //    dimention.LuminousIntensity = exchangeItem.Unit.Dimension.Length;
            //    dimention.Mass = exchangeItem.Unit.Dimension.LuminousIntensity;
            //    dimention.AmountOfSubstance = exchangeItem.Unit.Dimension.Mass;
            //    dimention.Time = exchangeItem.Unit.Dimension.Time;

            //    HydroNumerics.OpenMI.Sdk.Backbone.Unit unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit();
            //    unit.ID = exchangeItem.Unit.ID;
            //    unit.Description = exchangeItem.Unit.Description;
            //    unit.ConversionFactorToSI = exchangeItem.Unit.ConversionFactorToSI;
            //    unit.OffSetToSI = unit.OffSetToSI;
                                
            //    Quantity quantity = new Quantity();
            //    quantity.ID = exchangeItem.Quantity;
            //    quantity.Description = exchangeItem.Description;
            //    quantity.Dimension = dimention;
            //    quantity.Unit = unit;

            //    ElementSet elementSet = new ElementSet();
            //    elementSet.ID = exchangeItem.Location;
            //    elementSet.Description = "Location: " + exchangeItem.Location;
            //    elementSet.SpatialReference = new SpatialReference("Undefined");
            //    Element element = new Element();
            //    element.ID = exchangeItem.Location;

            //    if (exchangeItem.Geometry is XYPolygon)
            //    {
            //        elementSet.ElementType = ElementType.XYPolygon;
            //        foreach (XYPoint xyPoint in ((XYPolygon)exchangeItem.Geometry).Points)
            //        {
            //            element.AddVertex(new Vertex(xyPoint.X, xyPoint.Y, 0));
            //        }
            //    }
            //    else if (exchangeItem.Geometry is XYPoint)
            //    {
            //        throw new NotImplementedException();
            //    }
            //    else if (exchangeItem.Geometry is XYPolyline)
            //    {
            //        throw new NotImplementedException();
            //    }
            //    else
            //    {
            //        elementSet.ElementType = global::OpenMI.Standard.ElementType.IDBased;
            //    }
                
                
            //    elementSet.AddElement(element);


            //    if (exchangeItem.IsOutput)
            //    {
            //        OutputExchangeItem outputExchangeItem = new OutputExchangeItem();
            //        outputExchangeItem.Quantity = quantity;
            //        outputExchangeItem.ElementSet = elementSet;
            //        outputExchangeItems.Add(outputExchangeItem);
            //    }
            //    if (exchangeItem.IsInput)
            //    {
            //        InputExchangeItem inputExchangeItem = new InputExchangeItem();
            //        inputExchangeItem.Quantity = quantity;
            //        inputExchangeItem.ElementSet = elementSet;
            //        inputExchangeItems.Add(inputExchangeItem);
            //    }
            //}

        }
        public void Initialize(System.Collections.Hashtable properties)
        {
            currentTimestep = 0;
            simulationStart = new DateTime(2001,1,1);
            dt = 172800; //timestep length (2 days)
            nt = 80; // number of timesteps
            nx = 2; //number of grid cells in x-direction
            ny = 2; //number of grid cells in y-direction
            grid = new RegularGrid(10, 10, 1000, nx, ny, 0);
            groundwaterHeads = new TimeSeriesGroup();
            infiltrations = new TimeSeriesGroup();
            

            for (int i = 0; i < nx * ny; i++)
            {
                groundwaterHeads.Items.Add(new TimestampSeries("GwHead" + i.ToString(), simulationStart, nt, dt, TimestepUnit.Seconds, 4.9, new HydroNumerics.Core.Unit("meters",1.0,0.0)));
                infiltrations.Items.Add(new TimestampSeries("Infiltration" + i.ToString(), simulationStart, nt, dt, TimestepUnit.Seconds, -9999.9999, new HydroNumerics.Core.Unit("flow",1.0,0.0)));
            }

            Quantity infiltQuantity = new Quantity();
            infiltQuantity.Unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit("level", 1.0,0.0); 
            infiltQuantity.ID = "Infiltration";
            infiltQuantity.Description = "infiltration";
            infiltQuantity.ValueType = global::OpenMI.Standard.ValueType.Scalar;
            InputExchangeItem infiltExItem = new InputExchangeItem();
            infiltExItem.Quantity = infiltQuantity;
            infiltExItem.ElementSet = grid;
            inputExchangeItems = new List<InputExchangeItem>();
            inputExchangeItems.Add(infiltExItem);
           
            Quantity headQuantity = new Quantity();
            headQuantity.Description = "Groundwater head";
            headQuantity.ID = "Head";
            headQuantity.Unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit("meters",1,0);
            headQuantity.ValueType = global::OpenMI.Standard.ValueType.Scalar;
            OutputExchangeItem headOutItem = new OutputExchangeItem();
            headOutItem.Quantity = headQuantity;
            headOutItem.ElementSet = grid;
            outputExchangeItems = new List<OutputExchangeItem>();
            outputExchangeItems.Add(headOutItem);
        }
예제 #10
0
		public void Validate()
		{
			ILinkableComponent upperRiver = new RiverModelLC();
			ILinkableComponent lowerRiver = new RiverModelLC();
			HydroNumerics.OpenMI.Sdk.Wrapper.UnitTest.Trigger trigger     = new HydroNumerics.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);

			Dimension wrongDimension = new Dimension();
			wrongDimension.SetPower(DimensionBase.Mass,1);
			Quantity wrongQuantity = new Quantity(new Unit("dummy",0.0,0.0,"dummy"),"test","qid",global::OpenMI.Standard.ValueType.Vector,wrongDimension);
			ElementSet wrongElementSet = new ElementSet("Wrong ElementSet","BadID",ElementType.XYPolyLine,new SpatialReference("no ref"));
			Element element = new Element("dum Element");
			element.AddVertex(new Vertex(4,5,0));
			wrongElementSet.AddElement(element);

			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   = wrongQuantity;
//			link.AddDataOperation(upperRiver.GetOutputExchangeItem(6).GetDataOperation(0)); // bad data Operation

			Link triggerLink = new Link();

			triggerLink.ID				 = "TriggerLink";
			triggerLink.SourceComponent  = lowerRiver;
			triggerLink.SourceElementSet = wrongElementSet;
			triggerLink.SourceQuantity   = wrongQuantity;
			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);

			bool isSilent = false;
			if (!isSilent)
			{
				Console.WriteLine(lowerRiver.Validate());

				foreach (string str in ((RiverModelLC) upperRiver).ValidationErrorMessages)
				{
					Console.WriteLine("Error upperRiver: " + str);
				}
				foreach (string str in ((RiverModelLC) lowerRiver).ValidationErrorMessages)
				{
					Console.WriteLine("Error lowerRiver: " + str);
				}
				foreach (string str in ((RiverModelLC) upperRiver).ValidationWarningMessages)
				{
					Console.WriteLine("Warning upperRiver: " + str);
				}
				foreach (string str in ((RiverModelLC) lowerRiver).ValidationWarningMessages)
				{
					Console.WriteLine("Warning lowerRiver: " + str);
				}
			}

			Assert.AreEqual(0,((RiverModelLC) upperRiver).ValidationErrorMessages.Count);
			Assert.AreEqual(4,((RiverModelLC) lowerRiver).ValidationErrorMessages.Count);

			Assert.AreEqual(0,((RiverModelLC) upperRiver).ValidationWarningMessages.Count);
			Assert.AreEqual(2,((RiverModelLC) lowerRiver).ValidationWarningMessages.Count);
			
			
		}
		public void ExchangeItems()
		{
			Assert.AreEqual(1,testComponent1.InputExchangeItemCount);
			Assert.AreEqual(1,testComponent1.OutputExchangeItemCount);
			Quantity q = new Quantity("Q");

			ElementSet elementSet = new ElementSet();
			elementSet.ID = "ES";

			InputExchangeItem inputExchangeItem = new InputExchangeItem();
			inputExchangeItem.Quantity = q;
			inputExchangeItem.ElementSet = elementSet;
		    Assert.AreEqual(testComponent1.GetInputExchangeItem(0),inputExchangeItem);

			OutputExchangeItem outputExchangeItem = new OutputExchangeItem();
			outputExchangeItem.Quantity = new Quantity("Q2");
			ElementSet elementSet2 = new ElementSet();
			elementSet2.ID = "ES2";
			outputExchangeItem.ElementSet = elementSet;
			Assert.AreEqual(testComponent1.GetOutputExchangeItem(0),outputExchangeItem);
		}
        public void GetValues_AsAcceptor()
        {
            filename = "HydroNumerics.Time.OpenMI.UnitTest.LinkableTimeSeriesGroupTest.GetValues_AsAcceptor.xts";
            string acceptorOutputFilename = "HydroNumerics.Time.OpenMI.UnitTest.LinkableTimeSeriesGroupTest.GetValues_AsAcceptor.out.xts";

            TimespanSeries timespanSeries = new TimespanSeries("Flow", new System.DateTime(2010, 1, 1), 10, 2, TimestepUnit.Days, 10.2);
            timespanSeries.Unit = new HydroNumerics.Core.Unit("Liters pr. sec", 0.001, 0.0, "Liters pr second");
            timespanSeries.Unit.Dimension.Length = 3;
            timespanSeries.Unit.Dimension.Time = -1;
            timespanSeries.Description = "Measured Flow";
            TimestampSeries timestampSeries = new TimestampSeries("Water Level", new System.DateTime(2010, 1, 1), 6, 2, TimestepUnit.Days, 12.2);
            timestampSeries.Unit = new HydroNumerics.Core.Unit("cm", 0.01, 0.0, "centimeters");
            timestampSeries.Unit.Dimension.Length = 1;
            timestampSeries.Description = "Measured Head";

            TimeSeriesGroup tsg = new TimeSeriesGroup();
            tsg.Name = "Acceptor";
            tsg.Items.Add(timespanSeries);
            tsg.Items.Add(timestampSeries);
            tsg.Save(filename);

            Argument filenameArgument = new Argument("Filename", filename, true, "someDescription");
            Argument outputFilenameArgument = new Argument("OutputFilename", acceptorOutputFilename, true, "someDescription");
            Argument[] acceptorArguments = new Argument[2] { filenameArgument, outputFilenameArgument };

            LinkableTimeSeriesGroup acceptorTs = new LinkableTimeSeriesGroup();
            acceptorTs.Initialize(acceptorArguments);
            acceptorTs.WriteOmiFile(filename);

            LinkableTimeSeriesGroup linkableTimeSeriesGroup = new LinkableTimeSeriesGroup();
            linkableTimeSeriesGroup.Initialize(arguments);


            Link ts2tsLink1 = new Link();
            ts2tsLink1.SourceComponent = linkableTimeSeriesGroup;
            ts2tsLink1.TargetComponent = acceptorTs;
            ts2tsLink1.SourceQuantity = linkableTimeSeriesGroup.GetOutputExchangeItem(0).Quantity;
            ts2tsLink1.SourceElementSet = linkableTimeSeriesGroup.GetOutputExchangeItem(0).ElementSet;
            ts2tsLink1.TargetQuantity = acceptorTs.GetInputExchangeItem(0).Quantity;
            ts2tsLink1.TargetElementSet = acceptorTs.GetInputExchangeItem(0).ElementSet;
            ts2tsLink1.ID = "ts2ts1";
            linkableTimeSeriesGroup.AddLink(ts2tsLink1);
            acceptorTs.AddLink(ts2tsLink1);

            Link ts2tsLink2 = new Link();
            ts2tsLink2.SourceComponent = linkableTimeSeriesGroup;
            ts2tsLink2.TargetComponent = acceptorTs;
            ts2tsLink2.SourceQuantity = linkableTimeSeriesGroup.GetOutputExchangeItem(1).Quantity;
            ts2tsLink2.SourceElementSet = linkableTimeSeriesGroup.GetOutputExchangeItem(1).ElementSet;
            ts2tsLink2.TargetQuantity = acceptorTs.GetInputExchangeItem(1).Quantity;
            ts2tsLink2.TargetElementSet = acceptorTs.GetInputExchangeItem(1).ElementSet;
            ts2tsLink2.ID = "ts2ts2";
            linkableTimeSeriesGroup.AddLink(ts2tsLink2);
            acceptorTs.AddLink(ts2tsLink2);


            //setting up the work arround type of trigger
            InputExchangeItem targetExchangeItem = new InputExchangeItem();
            Quantity targetQuantity = new Quantity();
            targetQuantity.ID = "Water Level";
            targetQuantity.Unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit("meter", 1, 0, "meter");
            ElementSet targetElementSet = new ElementSet("inputLocation", "Location", ElementType.IDBased, new SpatialReference(""));

            Link triggerLink = new Link();
            triggerLink.SourceComponent = acceptorTs;
            triggerLink.TargetComponent = null;
            triggerLink.SourceQuantity = acceptorTs.GetOutputExchangeItem(0).Quantity;
            triggerLink.SourceElementSet = acceptorTs.GetOutputExchangeItem(0).ElementSet;
            triggerLink.TargetQuantity = targetQuantity;
            triggerLink.TargetElementSet = targetElementSet;
            triggerLink.ID = "TriggerLink";

            acceptorTs.AddLink(triggerLink);

            TimespanSeries tss1 = (TimespanSeries)acceptorTs.TimeSeriesGroup.Items[0];
            TimestampSeries tss2 = (TimestampSeries)acceptorTs.TimeSeriesGroup.Items[1];
            Assert.AreEqual(10.2, tss1.Items[0].Value);
            Assert.AreEqual(12.2, tss2.Items[0].Value);

            acceptorTs.GetValues(new TimeStamp(new System.DateTime(2010, 1, 3)), triggerLink.ID);

            Assert.AreEqual(4.3, tss1.Items[0].Value);
            Assert.AreEqual(6.3, tss2.Items[0].Value);

            linkableTimeSeriesGroup.Finish(); //save file
            acceptorTs.Finish(); //save file

        }
        public void GetValues_AsProvider()
        {
            LinkableTimeSeriesGroup linkableTimeSeriesGroup = new LinkableTimeSeriesGroup();
            linkableTimeSeriesGroup.Initialize(arguments);

            InputExchangeItem targetExchangeItem = new InputExchangeItem();
            Quantity targetQuantity = new Quantity();
            targetQuantity.ID = "Water Level";
            targetQuantity.Unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit("meter", 1, 0, "meter");
            ElementSet targetElementSet = new ElementSet("inputLocation", "Location", ElementType.IDBased, new SpatialReference(""));
            targetElementSet.AddElement(new Element("E1"));

            Link link = new Link();
            link.SourceComponent = linkableTimeSeriesGroup;
            link.SourceQuantity = linkableTimeSeriesGroup.GetOutputExchangeItem(1).Quantity;
            link.SourceElementSet = linkableTimeSeriesGroup.GetOutputExchangeItem(1).ElementSet;
            link.TargetComponent = null;
            link.TargetQuantity = targetQuantity;
            link.TargetElementSet = targetElementSet;
            link.ID = "Link001";

            linkableTimeSeriesGroup.AddLink(link);
            linkableTimeSeriesGroup.Prepare();

            IValueSet valueSet = linkableTimeSeriesGroup.GetValues(new TimeStamp(new System.DateTime(2010, 1, 5)), "Link001");
            Assert.AreEqual(0.063, ((IScalarSet)valueSet).GetScalar(0)); 

            linkableTimeSeriesGroup.Finish();
            linkableTimeSeriesGroup.Dispose();
        }
예제 #14
0
		public void Initialize(System.Collections.Hashtable properties)
		{
			double ox = 2.0;
			double oy = 2.0;
			double dx = 4.0;
			double dy = 4.0;

			// -- Populate Input Exchange Items ---
			Element element0 = new Element("element:0");
			element0.AddVertex(new Vertex(ox      ,oy        ,0));
			element0.AddVertex(new Vertex(ox+dx   ,oy        ,0));
			element0.AddVertex(new Vertex(ox+dx   ,oy+dy     ,0));
			element0.AddVertex(new Vertex(ox      ,oy+dy     ,0));

			Element element1 = new Element("element:1");
			element1.AddVertex(new Vertex(ox + dx ,oy        ,0));
			element1.AddVertex(new Vertex(ox+2*dx ,oy        ,0));
			element1.AddVertex(new Vertex(ox+2*dx ,oy+dy     ,0));
			element1.AddVertex(new Vertex(ox+dx   ,oy+dy     ,0));

			Element element2 = new Element("element:2");
			element2.AddVertex(new Vertex(ox      ,oy+dy       ,0));
			element2.AddVertex(new Vertex(ox+dx   ,oy+dy       ,0));
			element2.AddVertex(new Vertex(ox+dx   ,oy+2*dy     ,0));
			element2.AddVertex(new Vertex(ox      ,oy+2*dy     ,0));

			Element element3 = new Element("element:3");
			element3.AddVertex(new Vertex(ox + dx ,oy+dy       ,0));
			element3.AddVertex(new Vertex(ox+2*dx ,oy+dy       ,0));
			element3.AddVertex(new Vertex(ox+2*dx ,oy+2*dy     ,0));
			element3.AddVertex(new Vertex(ox+dx   ,oy+2*dy     ,0));

			ElementSet elementSet = new ElementSet("RegularGrid","RegularGrid",ElementType.XYPolygon,new SpatialReference(" "));
			elementSet.AddElement(element0);
			elementSet.AddElement(element1);
			elementSet.AddElement(element2);
			elementSet.AddElement(element3);

			Quantity storageQuantity = new Quantity(new Unit("Storage",1.0,0.0,"Storage"),"Storage","Storage",global::OpenMI.Standard.ValueType.Scalar,new Dimension());
			InputExchangeItem inputExchangeItem = new InputExchangeItem();
			inputExchangeItem.ElementSet = elementSet;
			inputExchangeItem.Quantity   = storageQuantity;
			_inputExchangeItems.Add(inputExchangeItem);

			OutputExchangeItem outputExchangeItem = new OutputExchangeItem();
			outputExchangeItem.ElementSet = elementSet;
			outputExchangeItem.Quantity   = storageQuantity;
			_outputExchangeItems.Add(outputExchangeItem);

		}
예제 #15
0
		public void Initialize(System.Collections.Hashtable properties)
		{

			if (properties.ContainsKey("ModelID"))
			{
				_modelID = (string) properties["ModelID"];
			}

			if (properties.ContainsKey("TimeStepLength"))
			{
				_timeStepLength = Convert.ToDouble((string) properties["TimeStepLength"]);
			}

			// -- create a flow quanitity --
			Dimension flowDimension = new Dimension();
			flowDimension.SetPower(DimensionBase.Length,3);
			flowDimension.SetPower(DimensionBase.Time,-1);
			Unit literPrSecUnit = new Unit("LiterPrSecond",0.001,0,"Liters pr Second");
			Quantity flowQuantity = new Quantity(literPrSecUnit,"Flow","Flow",global::OpenMI.Standard.ValueType.Scalar,flowDimension);

			// -- create leakage quantity --
			Quantity leakageQuantity = new Quantity(literPrSecUnit,"Leakage","Leakage",global::OpenMI.Standard.ValueType.Scalar,flowDimension);

			// -- create and populate elementset to represente the whole river network --
			ElementSet fullRiverElementSet = new ElementSet("WholeRiver","WholeRiver",ElementType.XYPolyLine,new SpatialReference("no reference"));
			for (int i = 0; i < _numberOfNodes -1; i++)
			{
				Element element = new Element();
				element.ID = "Branch:" + i.ToString();
				element.AddVertex(new Vertex(_xCoordinate[i],_yCoordinate[i],-999));
				element.AddVertex(new Vertex(_xCoordinate[i+1],_yCoordinate[i+1],-999));
				fullRiverElementSet.AddElement(element);
			}

			// --- populate input exchange items for flow to individual nodes ---
			for ( int i = 0; i < _numberOfNodes; i++)
			{
				Element element = new Element();
				element.ID = "Node:" + i.ToString();
				ElementSet elementSet = new ElementSet("Individual nodes","Node:" + i.ToString(), ElementType.IDBased,new SpatialReference("no reference"));
				elementSet.AddElement(element);
				InputExchangeItem inputExchangeItem = new InputExchangeItem();
				inputExchangeItem.ElementSet = elementSet;
				inputExchangeItem.Quantity = flowQuantity;
				
				_inputExchangeItems.Add(inputExchangeItem);
			}

			// --- Populate input exchange item for flow to the whole georeferenced river ---
			InputExchangeItem wholeRiverInputExchangeItem = new InputExchangeItem();
			wholeRiverInputExchangeItem.ElementSet = fullRiverElementSet;
			wholeRiverInputExchangeItem.Quantity   = flowQuantity;
			_inputExchangeItems.Add(wholeRiverInputExchangeItem);

			// --- Populate output exchange items for flow in river branches ---
			for (int i = 0; i < _numberOfNodes - 1; i++)
			{
				Element element = new Element();
				element.ID = "Branch:" + i.ToString();
				ElementSet elementSet = new ElementSet("Individual nodes","Branch:" + i.ToString(),ElementType.IDBased,new SpatialReference("no reference"));
				elementSet.AddElement(element);
			    OutputExchangeItem outputExchangeItem = new OutputExchangeItem();
				outputExchangeItem.ElementSet = elementSet;
				outputExchangeItem.Quantity = flowQuantity;
				
				_outputExchangeItems.Add(outputExchangeItem);
			}

			// --- polulate output exchange items for leakage for individual branches --
			for (int i = 0; i < _numberOfNodes - 1; i++)
			{
				Element element = new Element();
				element.ID = "Branch:" + i.ToString();
				ElementSet elementSet = new ElementSet("Individual nodes","Branch:" + i.ToString(),ElementType.IDBased,new SpatialReference("no reference"));
				elementSet.AddElement(element);
				OutputExchangeItem outputExchangeItem = new OutputExchangeItem();
				outputExchangeItem.ElementSet = elementSet;
				outputExchangeItem.Quantity = leakageQuantity;
				_outputExchangeItems.Add(outputExchangeItem);
			}

			// --- Populate output exchange item for leakage from the whole georeferenced river ---
			OutputExchangeItem wholeRiverOutputExchangeItem = new OutputExchangeItem();
			wholeRiverOutputExchangeItem.ElementSet = fullRiverElementSet;
			wholeRiverOutputExchangeItem.Quantity   = leakageQuantity;
			_outputExchangeItems.Add(wholeRiverOutputExchangeItem);

			// --- populate with initial state variables ---
			for (int i = 0; i < _numberOfNodes -1; i++)
			{
				_flow[i] = 7;
			}

			_currentTimeStepNumber = 1;
			_initializeMethodWasInvoked = true;
		}
예제 #16
0
		public   IInputExchangeItem GetInputExchangeItem(int index)
		{
			
			// -- create a flow quanitity --
			Dimension flowDimension = new Dimension();
			flowDimension.SetPower(DimensionBase.Length,3);
			flowDimension.SetPower(DimensionBase.Time,-1);
			Unit literPrSecUnit = new Unit("LiterPrSecond",0.001,0,"Liters pr Second");
			Quantity flowQuantity = new Quantity(literPrSecUnit,"Flow","Flow",global::OpenMI.Standard.ValueType.Scalar,flowDimension);

			Element element = new Element();
			element.ID = "DummyElement";
			ElementSet elementSet = new ElementSet("Dummy ElementSet","DummyElementSet",ElementType.IDBased,new SpatialReference("no reference"));
			elementSet.AddElement(element);

			InputExchangeItem inputExchangeItem = new InputExchangeItem();
			inputExchangeItem.ElementSet = elementSet;
			inputExchangeItem.Quantity   = flowQuantity;

			return inputExchangeItem;
		}
예제 #17
0
		public void Initialize(System.Collections.Hashtable properties)
		{

			_dt           = 1.0;
			_dx           = 0.0;
			_initialValue = 100;

			if (properties.ContainsKey("modelID"))
			{
				_modelID = (string) properties["ModelID"];
			}

			if (properties.ContainsKey("dt"))
			{
				_dt = (double) properties["dt"];
			}

			if (properties.ContainsKey("dx"))
			{
				_dx = (double) properties["dx"];
			}
			
			_values = new double[3];

			for (int i = 0; i < _values.Length; i++)
			{
				_values[i] = _initialValue;
			}

			_startTime   = 4000;
			_currentTime = _startTime;

			Element element = new Element("ElementID");
			ElementSet elementSet = new ElementSet("Description","ID",ElementType.IDBased,new SpatialReference(" no "));
			elementSet.AddElement(element);
			Quantity quantity = new Quantity(new Unit("Flow",1,0,"flow"),"Flow","ID",global::OpenMI.Standard.ValueType.Scalar,new Dimension());

			_outputExchangeItem = new OutputExchangeItem();
			_inputExchangeItem  = new InputExchangeItem();

			_outputExchangeItem.Quantity   = quantity;
			_outputExchangeItem.ElementSet = elementSet;

			_inputExchangeItem.Quantity    = quantity;
			_inputExchangeItem.ElementSet  = elementSet;
		}