public override void Initialize(IArgument[] properties)
        {
            SendEvent(new Event(EventType.Informative, this, "Started initialization.."));
            Dictionary<string, string> arguments = new Dictionary<string, string>();
            for (int i = 0; i < properties.Length; i++)
            {
                arguments.Add(properties[i].Key, properties[i].Value);
            }
            filename = arguments["Filename"];
            outputFilename = arguments["OutputFilename"];

            tsGroup = TimeSeriesGroupFactory.Create(filename);

            foreach (BaseTimeSeries baseTimeSeries in tsGroup.Items)
            {
                HydroNumerics.OpenMI.Sdk.Backbone.Dimension dimention = new HydroNumerics.OpenMI.Sdk.Backbone.Dimension();
                dimention.AmountOfSubstance = baseTimeSeries.Unit.Dimension.AmountOfSubstance;
                dimention.Currency = baseTimeSeries.Unit.Dimension.Currency;
                dimention.ElectricCurrent = baseTimeSeries.Unit.Dimension.ElectricCurrent;
                dimention.Length = baseTimeSeries.Unit.Dimension.Length;
                dimention.LuminousIntensity = baseTimeSeries.Unit.Dimension.LuminousIntensity;
                dimention.Mass = baseTimeSeries.Unit.Dimension.Mass;
                dimention.Time = baseTimeSeries.Unit.Dimension.Time;

                HydroNumerics.OpenMI.Sdk.Backbone.Unit unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit();
                unit.ID = baseTimeSeries.Unit.ID;
                unit.Description = baseTimeSeries.Unit.Description;
                unit.ConversionFactorToSI = baseTimeSeries.Unit.ConversionFactorToSI;
                unit.OffSetToSI = baseTimeSeries.Unit.OffSetToSI;

                TsQuantity quantity = new TsQuantity();
                quantity.ID = baseTimeSeries.Name;
                quantity.Description = baseTimeSeries.Description;
                quantity.Dimension = dimention;
                quantity.Unit = unit;
                quantity.BaseTimeSeries = baseTimeSeries;

                ElementSet elementSet = new ElementSet();
                elementSet.ID = "IDBased";
                elementSet.Description = "IDBased";
                elementSet.ElementType = global::OpenMI.Standard.ElementType.IDBased;
                elementSet.SpatialReference = new SpatialReference("Undefined");
                Element element = new Element();
                element.ID = "IDBased";
                elementSet.AddElement(element);

                OutputExchangeItem outputExchangeItem = new OutputExchangeItem();
                outputExchangeItem.Quantity = quantity;
                outputExchangeItem.ElementSet = elementSet;
                this.AddOutputExchangeItem(outputExchangeItem);

                InputExchangeItem inputExchangeItem = new InputExchangeItem();
                inputExchangeItem.Quantity = quantity;
                inputExchangeItem.ElementSet = elementSet;
                this.AddInputExchangeItem(inputExchangeItem);
            }

            initializeWasInvoked = true;
            SendEvent(new Event(EventType.Informative, this, "Completed initialization"));
        }
Пример #2
0
 public void Power()
 {
     Dimension dimension;
     dimension = new Dimension();
     dimension.SetPower(DimensionBase.Length, 3);
     dimension.SetPower(DimensionBase.Time, -1);
     Assert.AreEqual(3, dimension.GetPower(DimensionBase.Length));
     Assert.AreEqual(-1, dimension.GetPower(DimensionBase.Time));
 }
Пример #3
0
		public void Equals ()
		{
			Dimension dimension = new Dimension();
			dimension.SetPower(DimensionBase.Length,3);
			dimension.SetPower(DimensionBase.Time,-1);

			Assert.IsTrue(dimension.Equals(this.dimension));
			dimension.SetPower(DimensionBase.Length,2);
			Assert.IsFalse(dimension.Equals(this.dimension));

			Assert.IsFalse(dimension.Equals("string"));
		}
Пример #4
0
        public void Equals()
        {
            Dimension dimension = new Dimension();
            dimension.SetPower(DimensionBase.Length, 3);
            dimension.SetPower(DimensionBase.Time, -1);

            Dimension dimension2 = new Dimension();
            dimension2.SetPower(DimensionBase.Length, 3);
            dimension2.SetPower(DimensionBase.Time, -1);

            Assert.IsTrue(Dimension.DescribesSameAs(dimension, dimension2));
            dimension.SetPower(DimensionBase.Length, 2);
            Assert.IsFalse(Dimension.DescribesSameAs(dimension, dimension2));

            Assert.IsFalse(dimension.Equals("string"));
        }
Пример #5
0
		public void Init()
		{
			dimension = new Dimension();
			dimension.SetPower(DimensionBase.Length,3);
			dimension.SetPower(DimensionBase.Time,-1);
		}
        public override void Initialize(IArgument[] properties)
        {
            SendEvent(new Event(EventType.Informative, this, "Started initialization.."));
            Dictionary <string, string> arguments = new Dictionary <string, string>();

            for (int i = 0; i < properties.Length; i++)
            {
                arguments.Add(properties[i].Key, properties[i].Value);
            }
            filename       = arguments["Filename"];
            outputFilename = arguments["OutputFilename"];

            tsGroup = TimeSeriesGroupFactory.Create(filename);

            foreach (BaseTimeSeries baseTimeSeries in tsGroup.Items)
            {
                HydroNumerics.OpenMI.Sdk.Backbone.Dimension dimention = new HydroNumerics.OpenMI.Sdk.Backbone.Dimension();
                dimention.AmountOfSubstance = baseTimeSeries.Unit.Dimension.AmountOfSubstance;
                dimention.Currency          = baseTimeSeries.Unit.Dimension.Currency;
                dimention.ElectricCurrent   = baseTimeSeries.Unit.Dimension.ElectricCurrent;
                dimention.Length            = baseTimeSeries.Unit.Dimension.Length;
                dimention.LuminousIntensity = baseTimeSeries.Unit.Dimension.LuminousIntensity;
                dimention.Mass = baseTimeSeries.Unit.Dimension.Mass;
                dimention.Time = baseTimeSeries.Unit.Dimension.Time;

                HydroNumerics.OpenMI.Sdk.Backbone.Unit unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit();
                unit.ID                   = baseTimeSeries.Unit.ID;
                unit.Description          = baseTimeSeries.Unit.Description;
                unit.ConversionFactorToSI = baseTimeSeries.Unit.ConversionFactorToSI;
                unit.OffSetToSI           = baseTimeSeries.Unit.OffSetToSI;

                TsQuantity quantity = new TsQuantity();
                quantity.ID             = baseTimeSeries.Name;
                quantity.Description    = baseTimeSeries.Description;
                quantity.Dimension      = dimention;
                quantity.Unit           = unit;
                quantity.BaseTimeSeries = baseTimeSeries;

                ElementSet elementSet = new ElementSet();
                elementSet.ID               = "IDBased";
                elementSet.Description      = "IDBased";
                elementSet.ElementType      = global::OpenMI.Standard.ElementType.IDBased;
                elementSet.SpatialReference = new SpatialReference("Undefined");
                Element element = new Element();
                element.ID = "IDBased";
                elementSet.AddElement(element);

                OutputExchangeItem outputExchangeItem = new OutputExchangeItem();
                outputExchangeItem.Quantity   = quantity;
                outputExchangeItem.ElementSet = elementSet;
                this.AddOutputExchangeItem(outputExchangeItem);

                InputExchangeItem inputExchangeItem = new InputExchangeItem();
                inputExchangeItem.Quantity   = quantity;
                inputExchangeItem.ElementSet = elementSet;
                this.AddInputExchangeItem(inputExchangeItem);
            }

            initializeWasInvoked = true;
            SendEvent(new Event(EventType.Informative, this, "Completed initialization"));
        }
Пример #7
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;
		}
Пример #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 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;



    }
Пример #10
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;
		}
Пример #11
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);
			
			
		}
Пример #12
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);
            //    }
            //}

        }