Ejemplo n.º 1
0
        public void Initialize(IArgument[] properties)
        {
            //get the number of elements from the omi file
            //int _numElements = -1;
            //foreach (Argument property in properties)
            //{
            //    if(property.Key == "ElementCount")
            //        _numElements = Convert.ToInt32(property.Value);
            //}

            //if (_numElements == -1)
            //    throw new Exception("Invalid ElementCount, please fix in *.omi file");

            //create output exchange item (so that this component can be linked to others)
            Quantity quantity = new Quantity();

            Oatc.OpenMI.Sdk.Backbone.Unit unit    = new Oatc.OpenMI.Sdk.Backbone.Unit();
            Dimension          dimension          = new Dimension();
            ElementSet         elementset         = new ElementSet();
            OutputExchangeItem outputexchangeitem = new OutputExchangeItem();

            quantity.ID          = "Input Generator";
            quantity.Description = "Supplies random numbers as input values";
            quantity.ValueType   = global::OpenMI.Standard.ValueType.Scalar;
            unit.ID = "any units";

            quantity.Unit          = unit;
            quantity.Dimension     = dimension;
            elementset.ID          = "any elementset";
            elementset.Description = "AllSites";

            elementset.ElementType = ElementType.IDBased;

            string beginDateTimeString = "1/1/1900 12:00:00 AM";
            string endDateTimeString   = "1/1/2500 12:00:00 AM";

            DateTime beginDateTime = Convert.ToDateTime(beginDateTimeString);
            DateTime endDateTime   = Convert.ToDateTime(endDateTimeString);

            _earliestInputTime = CalendarConverter.Gregorian2ModifiedJulian(beginDateTime);
            _latestInputTime   = CalendarConverter.Gregorian2ModifiedJulian(endDateTime);


            outputexchangeitem.Quantity   = quantity;
            outputexchangeitem.ElementSet = elementset;
            if (outputexchangeitem != null)
            {
                _outputExchangeItems.Add(outputexchangeitem);
            }
        }
Ejemplo n.º 2
0
        public Quantity Quantity(string dimension, string description, string name)
        {
            for (int i = 0; i < dimtab.Length; i++)
            {
                if (dimtab[i].dimension != dimension)
                    continue;
                Dimension unit_dimension = new Dimension();
                unit_dimension.SetPower(DimensionBase.Length, dimtab[i].length);
                unit_dimension.SetPower(DimensionBase.Mass, dimtab[i].mass);
                unit_dimension.SetPower(DimensionBase.Time, dimtab[i].time);
                unit_dimension.SetPower(DimensionBase.Temperature, dimtab[i].temperature);
                unit_dimension.SetPower(DimensionBase.AmountOfSubstance, dimtab[i].AmountOfSubstance);

                double factor = dimtab[i].factor;
                double offset = dimtab[i].offset;
                string dimDescription = dimtab[i].description;
                Unit unit = new Unit(dimension, factor, offset, dimDescription);
                return new Quantity(unit, description, name, global::OpenMI.Standard.ValueType.Scalar, unit_dimension);
            }
            return new Quantity(new Unit(dimension, 1.0, 0, "Unrecognized dimension"), description, name, global::OpenMI.Standard.ValueType.Scalar, new Dimension());
        }
        private static Unit readUnit(XmlNode aNode)
        {
            var unit = new Unit();
            unit.ID = Utils.findChildNodeValue(aNode, "ID");

            if (Utils.findChildNode(aNode, "Description", false) != null)
                unit.Description = Utils.findChildNodeValue(aNode, "Description");

            if (Utils.findChildNode(aNode, "ConversionFactorToSI", false) != null)
                unit.ConversionFactorToSI = Double.Parse(Utils.findChildNodeValue(aNode, "ConversionFactorToSI"));

            if (Utils.findChildNode(aNode, "OffSetToSI", false) != null)
                unit.OffSetToSI = Double.Parse(Utils.findChildNodeValue(aNode, "OffSetToSI"));
            return unit;
        }
        private static Quantity readQuantity(XmlNode aNode)
        {
            var quantity = new Quantity();

            // required
            quantity.ID = Utils.findChildNodeValue(aNode, "ID");

            // optional
            if (Utils.findChildNode(aNode, "Description", false) != null)
                quantity.Description = Utils.findChildNodeValue(aNode, "Description");
            else
                quantity.Description = "";

            if (Utils.findChildNode(aNode, "ValueType", false) != null)
                quantity.ValueType = getValueType(Utils.findChildNodeValue(aNode, "ValueType"));
            else
                quantity.ValueType = ValueType.Scalar;

            if (Utils.findChildNode(aNode, "Dimensions", false) != null)
                quantity.Dimension = readDimension(Utils.findChildNode(aNode, "Dimensions"));
            else
            {
                var dimension = new Dimension();
                dimension.SetPower(DimensionBase.Length, 1);
                quantity.Dimension = dimension;
            }

            if (Utils.findChildNode(aNode, "Unit", false) != null)
                quantity.Unit = readUnit(Utils.findChildNode(aNode, "Unit"));
            else
            {
                var unit = new Unit();
                unit.ID = "DefaultUnit";
                unit.Description = "Default Unit";
                unit.ConversionFactorToSI = 1.0;
                unit.OffSetToSI = 0.0;
                quantity.Unit = unit;
            }

            return quantity;
        }
Ejemplo n.º 5
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;
        }
        public void Initialize(System.Collections.Hashtable properties)
        {

            getValuesWatch = new Stopwatch();
            setValuesWatch = new Stopwatch();
            performStepWatch = new Stopwatch();

            //List of exchange Items
            inputExchangeItems = new List<InputExchangeItem>();
            outputExchangeItems = new List<OutputExchangeItem>();

            //Initializes Engine
            mohidLandEngine = new MohidLandEngineDotNetAccess();
            mohidLandEngine.Initialize(properties["FilePath"].ToString());


            //
            //Dimensions
            //
            Dimension dimFlow = new Dimension();
            dimFlow.SetPower(DimensionBase.Length, 3);
            dimFlow.SetPower(DimensionBase.Time, -1);

            Dimension dimWaterlevel = new Dimension();
            dimWaterlevel.SetPower(DimensionBase.Length, 1);

            Dimension dimWaterColumn = new Dimension();
            dimWaterColumn.SetPower(DimensionBase.Length, 1);

            Dimension dimConcentration = new Dimension();
            dimConcentration.SetPower(DimensionBase.Mass, 1);
            dimConcentration.SetPower(DimensionBase.Length, -3);

            //
            //Units
            //
            Unit unitFlow = new Unit("m3/sec", 1, 0, "cubic meter per second");
            Unit unitWaterLevel = new Unit("m", 1, 0, "meters above mean sea level");
            Unit unitWaterColumn = new Unit("m", 1, 0, "meters above ground");
            Unit unitConcentration = new Unit("mg/l", 1, 0, "miligram per liter");

            //
            //Quantities
            //
            qtdOutflow = new Quantity(unitFlow, "Flow discharge at the outlet", "Outlet Flow", ValueType.Scalar, dimFlow);
            qtdOutletLevel = new Quantity(unitWaterLevel, "Waterlevel at the outlet", "OutletLevel",
                                                   ValueType.Scalar, dimWaterlevel);
            qtdWaterColumn = new Quantity(unitWaterColumn, "Ponded Water Column", "WaterColumn",
                                                   ValueType.Scalar, dimWaterColumn);
            qtdDischarges = new Quantity(unitFlow, "Distributed discharges (sewer sinks)", "Discharges", ValueType.Scalar,
                                                  dimFlow);

            qtdFlowToStorm = new Quantity(unitFlow, "Flow from the network to the storm water system (inlets)",
                                          "Storm Water Out Flow", ValueType.Scalar, dimFlow);

            qtdFlowFromStrom = new Quantity(unitFlow, "Flow from the storm water system to the network (discharges)",
                              "Storm Water In Flow", ValueType.Scalar, dimFlow);

            //
            //Spatial Reference
            //
            SpatialReference spatialReference = new SpatialReference("spatial reference");

            //
            //Element Sets
            //

            //Model Grid
            ElementSet modelGrid = new ElementSet("Model Grid Points of all Compute Points", "Model Grid",
                                       ElementType.XYPolygon, spatialReference);

            //Output exchange items - properties in each grid cell (surface only)
            numberOfWaterPoints = 0;
            for (int j = 1; j <= mohidLandEngine.GetJUB(horizontalGridInstanceID); j++)
            {
                for (int i = 1; i <= mohidLandEngine.GetIUB(horizontalGridInstanceID); i++)
                {
                    if (mohidLandEngine.IsWaterPoint(horizontalMapInstanceID, i, j))
                    {
                        String name = "i=" + i.ToString() + "/j=" + j.ToString();

                        double[] xCoords = new double[5];
                        double[] yCoords = new double[5];
                        mohidLandEngine.GetGridCellCoordinates(horizontalGridInstanceID, i, j, ref xCoords, ref yCoords);

                        Element element = new Element(name);
                        element.AddVertex(new Vertex(xCoords[0], yCoords[0], 0));
                        element.AddVertex(new Vertex(xCoords[1], yCoords[1], 0));
                        element.AddVertex(new Vertex(xCoords[2], yCoords[2], 0));
                        element.AddVertex(new Vertex(xCoords[3], yCoords[3], 0));

                        modelGrid.AddElement(element);

                        numberOfWaterPoints++;

                    }
                }
            }

            //Outlet Node
            ElementSet outletNode = new ElementSet("Outlet node", "Outlet", ElementType.XYPoint, spatialReference);
            Element outletElement = new Element("Outlet");
            int outletNodeID = mohidLandEngine.GetOutletNodeID(drainageNetworkInstanceID);
            outletElement.AddVertex(new Vertex(mohidLandEngine.GetXCoordinate(drainageNetworkInstanceID, outletNodeID),
                                               mohidLandEngine.GetYCoordinate(drainageNetworkInstanceID, outletNodeID),
                                               0));
            outletNode.AddElement(outletElement);

            //Outflow to Storm Water Model
            ElementSet stormWaterOutflowNodes = new ElementSet("Nodes which provide flow to the Storm Water System",
                                                          "Storm Water Inlets", ElementType.XYPoint, spatialReference);
            int numberOfOutflowNodes = mohidLandEngine.GetNumberOfStormWaterOutFlowNodes(drainageNetworkInstanceID);
            int[] outflowNodeIDs = new int[numberOfOutflowNodes];
            mohidLandEngine.GetStormWaterOutflowIDs(drainageNetworkInstanceID, numberOfOutflowNodes, ref outflowNodeIDs);
            for (int i = 1; i <= numberOfOutflowNodes; i++)
            {
                int nodeID = outflowNodeIDs[i - 1];

                Element element = new Element(nodeID.ToString());
                element.AddVertex(new Vertex(mohidLandEngine.GetXCoordinate(drainageNetworkInstanceID, nodeID),
                                             mohidLandEngine.GetYCoordinate(drainageNetworkInstanceID, nodeID),
                                             0));
                stormWaterOutflowNodes.AddElement(element);
            }

            //Inflow from Storm Water Model
            ElementSet stormWaterInflowNodes = new ElementSet("Nodes which receive flow to the Storm Water System",
                                                          "Storm Water Outlets", ElementType.XYPoint, spatialReference);
            int numberOfInflowNodes = mohidLandEngine.GetNumberOfStormWaterInFlowNodes(drainageNetworkInstanceID);
            if (numberOfInflowNodes > 0)
            {
                int[] inflowNodeIDs = new int[numberOfInflowNodes];
                mohidLandEngine.GetStormWaterInflowIDs(drainageNetworkInstanceID, numberOfOutflowNodes,
                                                       ref inflowNodeIDs);
                for (int i = 1; i <= numberOfInflowNodes; i++)
                {
                    int nodeID = inflowNodeIDs[i - 1];

                    Element element = new Element(nodeID.ToString());
                    element.AddVertex(new Vertex(mohidLandEngine.GetXCoordinate(drainageNetworkInstanceID, nodeID),
                                                 mohidLandEngine.GetYCoordinate(drainageNetworkInstanceID, nodeID),
                                                 0));
                    stormWaterInflowNodes.AddElement(element);
                }
            }


            //
            //Output Exchange Items
            //

            //Flow at the outlet
            OutputExchangeItem outletFlow = new OutputExchangeItem();
            outletFlow.Quantity = qtdOutflow;
            outletFlow.ElementSet = outletNode;
            outputExchangeItems.Add(outletFlow);

            //Overland water column
            OutputExchangeItem overlandWaterColumn = new OutputExchangeItem();
            overlandWaterColumn.Quantity = qtdWaterColumn;
            overlandWaterColumn.ElementSet = modelGrid;
            outputExchangeItems.Add(overlandWaterColumn);

            //Flow to the Storm Water Model
            if (stormWaterOutflowNodes.ElementCount > 0)
            {
                OutputExchangeItem stormWaterOutFlow = new OutputExchangeItem();
                stormWaterOutFlow.Quantity = qtdFlowToStorm;
                stormWaterOutFlow.ElementSet = stormWaterOutflowNodes;
                outputExchangeItems.Add(stormWaterOutFlow);
            }

            //
            //Input Exchange Items
            //

            //Water level at the outlet
            InputExchangeItem outletLevel = new InputExchangeItem();
            outletLevel.Quantity = qtdOutletLevel;
            outletLevel.ElementSet = outletNode;
            inputExchangeItems.Add(outletLevel);

            //Distributed discharges
            InputExchangeItem dischargeInflow = new InputExchangeItem();
            dischargeInflow.Quantity = qtdDischarges;
            dischargeInflow.ElementSet = modelGrid;
            inputExchangeItems.Add(dischargeInflow);

            //Flow from the Storm Water Model
            if (stormWaterInflowNodes.ElementCount > 0)
            {
                InputExchangeItem stormWaterInFlow = new InputExchangeItem();
                stormWaterInFlow.Quantity = qtdFlowFromStrom;
                stormWaterInFlow.ElementSet = stormWaterInflowNodes;
                inputExchangeItems.Add(stormWaterInFlow);
            }

            //
            //Properties
            //

            //Properties input / output exchange items
            for (int i = 1; i <= mohidLandEngine.GetNumberOfProperties(drainageNetworkInstanceID); i++)
            {
                int propertyIDNumber = mohidLandEngine.GetPropertyIDNumber(drainageNetworkInstanceID, i);
                string propertyName = mohidLandEngine.GetPropertyNameByIDNumber(propertyIDNumber);

                Quantity concentrationQuantity = new Quantity(unitConcentration, "Concentration of " + propertyName,
                                                              propertyIDNumber.ToString(), ValueType.Scalar, dimConcentration);

                OutputExchangeItem outletConc = new OutputExchangeItem();
                outletConc.Quantity = concentrationQuantity;
                outletConc.ElementSet = outletNode;

                outputExchangeItems.Add(outletConc);


                InputExchangeItem boundaryConc = new InputExchangeItem();
                boundaryConc.Quantity = concentrationQuantity;
                boundaryConc.ElementSet = outletNode;

                inputExchangeItems.Add(boundaryConc);

            }

        }
Ejemplo n.º 7
0
		public void Equals()
		{
			Unit unit1 = new Unit("ID",3.4,6.7,"description");
			Assert.IsTrue(unit.Equals(unit1));
			unit1 = new Unit("ID1",3.4,6.7,"description");
			Assert.IsFalse(unit.Equals(unit1));
			unit1 = new Unit("ID",3.5,6.7,"description");
			Assert.IsFalse(unit.Equals(unit1));
			unit1 = new Unit("ID",3.4,6.8,"description");
			Assert.IsFalse(unit.Equals(unit1));
			unit1 = new Unit("ID",3.4,6.7,"description1");
			Assert.IsFalse(unit.Equals(unit1));

			Assert.IsFalse(unit.Equals(null));
			Assert.IsFalse(unit.Equals("string"));
		}
Ejemplo n.º 8
0
		public void Constructor()
		{
			Unit unit2 = new Unit(unit);

			Assert.AreEqual(unit,unit2);
		}
Ejemplo n.º 9
0
		public void Init()
		{
			unit = new Unit("ID",3.4,6.7,"description");
		}
        public void Initialize(System.Collections.Hashtable properties)
        {
            //List of exchange Items
            inputExchangeItems = new List<InputExchangeItem>();
            outputExchangeItems = new List<OutputExchangeItem>();

            //Initializes Engine
            MohidWaterEngine = new MohidWaterEngineDotNetAccess();
            MohidWaterEngine.Initialize(properties["FilePath"].ToString());

            //
            //Dimensions
            //
            Dimension dimFlow = new Dimension();
            dimFlow.SetPower(DimensionBase.Length, 3);
            dimFlow.SetPower(DimensionBase.Time, -1);

            Dimension dimWaterlevel = new Dimension();
            dimWaterlevel.SetPower(DimensionBase.Length, 1);

            Dimension dimConcentration = new Dimension();
            dimConcentration.SetPower(DimensionBase.Mass, 1);
            dimConcentration.SetPower(DimensionBase.Length, -3);

            //
            //Units
            //
            Unit unitFlow = new Unit("m3/sec", 1, 0, "cubic meter per second");
            Unit unitWaterLevel = new Unit("m", 1, 0, "sea water level");
            Unit unitConcentration = new Unit("mg/l", 1, 0, "miligram per liter");

            //
            //Quantities
            //
            qtdDischargeFlow = new Quantity(unitFlow, "Input Discharge Flow", "Discharge Flow",
                                            global::OpenMI.Standard.ValueType.Scalar, dimFlow);
            qtdWaterLevel = new Quantity(unitWaterLevel, "Waterlevel of the water surface", "Waterlevel",
                                         global::OpenMI.Standard.ValueType.Scalar, dimWaterlevel);

            //
            //Spatial Reference
            //
            SpatialReference spatialReference = new SpatialReference("spatial reference");

            //
            //Element Sets
            //

            //Model Grid
            ElementSet modelGrid = new ElementSet("Model Grid Points of all Compute Points", "Model Grid",
                                                  ElementType.XYPolygon, spatialReference);

            //Output exchange items - properties in each grid cell (surface only)
            numberOfWaterPoints = 0;
            for (int i = 1; i <= MohidWaterEngine.GetIUB(horizontalGridInstanceID); i++)
            {
                for (int j = 1; j <= MohidWaterEngine.GetJUB(horizontalGridInstanceID); j++)
                {
                    if (MohidWaterEngine.IsWaterPoint(horizontalMapInstanceID, i, j))
                    {
                        String name = "i=" + i.ToString() + "/j=" + j.ToString();

                        double[] xCoords = new double[5];
                        double[] yCoords = new double[5];
                        MohidWaterEngine.GetGridCellCoordinates(horizontalGridInstanceID, i, j, ref xCoords, ref yCoords);

                        Element element = new Element(name);
                        element.AddVertex(new Vertex(xCoords[0], yCoords[0], 0));
                        element.AddVertex(new Vertex(xCoords[1], yCoords[1], 0));
                        element.AddVertex(new Vertex(xCoords[2], yCoords[2], 0));
                        element.AddVertex(new Vertex(xCoords[3], yCoords[3], 0));

                        modelGrid.AddElement(element);

                        numberOfWaterPoints++;

                    }
                }
            }

            //allocates waterlevels1D
            modelGridValues1D = new double[numberOfWaterPoints];

            //Discharge Points
            ElementSet dischargePoints = new ElementSet("Discharge Points", "Discharge Points", ElementType.XYPoint,
                                                        spatialReference);

            //Flow input exchange to discharges configured as OpenMI Discharges
            for (int i = 1; i <= MohidWaterEngine.GetNumberOfDischarges(dischargeInstanceID); i++)
            {
                if (MohidWaterEngine.GetDischargeType(dischargeInstanceID, i) == 4)
                {
                    Element dischargeElement = new Element(MohidWaterEngine.GetDischargeName(dischargeInstanceID, i));
                    dischargeElement.AddVertex(
                        new Vertex(MohidWaterEngine.GetDischargeXCoordinate(dischargeInstanceID, i),
                                   MohidWaterEngine.GetDischargeYCoordinate(dischargeInstanceID, i), 0));
                    dischargePoints.AddElement(dischargeElement);
                }
            }

            //
            //Output Exchange Items
            //

            //Water Level of the Hydrodynamic model
            OutputExchangeItem waterlevel = new OutputExchangeItem();
            waterlevel.Quantity = qtdWaterLevel;
            waterlevel.ElementSet = modelGrid;
            outputExchangeItems.Add(waterlevel);


            //Properties of the Water properties model
            for (int idx = 1; idx <= MohidWaterEngine.GetNumberOfProperties(waterPropertiesInstanceID); idx++)
            {

                int propertyID = MohidWaterEngine.GetPropertyIDNumber(waterPropertiesInstanceID, idx);
                string propertyName = MohidWaterEngine.GetPropertyNameByIDNumber(propertyID);

                Quantity concentrationQuantity = new Quantity(unitConcentration, "Concentration of " + propertyName, propertyID.ToString(),
                                                              ValueType.Scalar, dimConcentration);

                qtdProperties.Add(concentrationQuantity);

                OutputExchangeItem concExchangeItem = new OutputExchangeItem();
                concExchangeItem.Quantity = concentrationQuantity;
                concExchangeItem.ElementSet = modelGrid;

                outputExchangeItems.Add(concExchangeItem);
            }


            //Flow input exchange to discharges configured as OpenMI Discharges
            for (int i = 1; i <= MohidWaterEngine.GetNumberOfDischarges(dischargeInstanceID); i++)
            {
                if (MohidWaterEngine.GetDischargeType(dischargeInstanceID, i) == 4)
                {

                    String pointName = MohidWaterEngine.GetDischargeName(dischargeInstanceID, i);

                    ElementSet dischargePoint = new ElementSet("Discharge Point of MOHID Water", i.ToString(), ElementType.XYPoint, spatialReference);

                    InputExchangeItem inputDischarge = new InputExchangeItem();
                    inputDischarge.Quantity = qtdDischargeFlow;

                    Element element = new Element("Point: " + pointName);
                    element.AddVertex(new Vertex(MohidWaterEngine.GetDischargeXCoordinate(dischargeInstanceID, i), MohidWaterEngine.GetDischargeYCoordinate(dischargeInstanceID, i), 0));
                    dischargePoint.AddElement(element);

                    inputDischarge.ElementSet = dischargePoint;

                    inputExchangeItems.Add(inputDischarge);


                    for (int idx = 1; idx <= MohidWaterEngine.GetNumberOfDischargeProperties(dischargeInstanceID, i); idx++)
                    {
                        int propertyID = MohidWaterEngine.GetDischargePropertyID(dischargeInstanceID, i, idx);

                        string propertyName = MohidWaterEngine.GetPropertyNameByIDNumber(propertyID);

                        Quantity concentrationQuantity = new Quantity(unitConcentration, propertyName, propertyID.ToString(), global::OpenMI.Standard.ValueType.Scalar, dimConcentration);

                        InputExchangeItem inputExchangeItem = new InputExchangeItem();
                        inputExchangeItem.ElementSet = dischargePoint;
                        inputExchangeItem.Quantity = concentrationQuantity;

                        inputExchangeItems.Add(inputExchangeItem);

                    }

                }
            }




        }
        private void CreateExchangeItemsFromXMLNode(XmlNode ExchangeItem, string Identifier)
        {
            //Create Dimensions
            var omiDimensions = new Dimension();
            var dimensions = ExchangeItem.SelectNodes("//Dimensions/Dimension"); // You can filter elements here using XPath
            if (dimensions != null)
            {
                foreach (XmlNode dimension in dimensions)
                {
                    if (dimension["Base"].InnerText == "Length")
                    {
                        omiDimensions.SetPower(DimensionBase.Length, Convert.ToDouble(dimension["Power"].InnerText));
                    }
                    else if (dimension["Base"].InnerText == "Time")
                    {
                        omiDimensions.SetPower(DimensionBase.Time, Convert.ToDouble(dimension["Power"].InnerText));
                    }
                    else if (dimension["Base"].InnerText == "AmountOfSubstance")
                    {
                        omiDimensions.SetPower(DimensionBase.AmountOfSubstance, Convert.ToDouble(dimension["Power"].InnerText));
                    }
                    else if (dimension["Base"].InnerText == "Currency")
                    {
                        omiDimensions.SetPower(DimensionBase.Currency, Convert.ToDouble(dimension["Power"].InnerText));
                    }
                    else if (dimension["Base"].InnerText == "ElectricCurrent")
                    {
                        omiDimensions.SetPower(DimensionBase.ElectricCurrent, Convert.ToDouble(dimension["Power"].InnerText));
                    }
                    else if (dimension["Base"].InnerText == "LuminousIntensity")
                    {
                        omiDimensions.SetPower(DimensionBase.LuminousIntensity, Convert.ToDouble(dimension["Power"].InnerText));
                    }
                    else if (dimension["Base"].InnerText == "Mass")
                    {
                        omiDimensions.SetPower(DimensionBase.Mass, Convert.ToDouble(dimension["Power"].InnerText));
                    }
                    else if (dimension["Base"].InnerText == "Temperature")
                    {
                        omiDimensions.SetPower(DimensionBase.Temperature, Convert.ToDouble(dimension["Power"].InnerText));
                    }
                }
            }

            //Create Units
            _omiUnits = new Unit();
            var units = ExchangeItem.SelectSingleNode("Quantity/Unit");
            if (units != null)
            {
                _omiUnits.ID = units["ID"].InnerText;
                if (units["Description"] != null) _omiUnits.Description = units["Description"].InnerText;
                if (units["ConversionFactorToSI"] != null) _omiUnits.ConversionFactorToSI = Convert.ToDouble(units["ConversionFactorToSI"].InnerText);
                if (units["OffSetToSI"] != null) _omiUnits.OffSetToSI = Convert.ToDouble(units["OffSetToSI"].InnerText);
            }

            //Create Quantity
            var omiQuantity = new Quantity();
            var quantity = ExchangeItem.SelectSingleNode("Quantity");
            omiQuantity.ID = quantity["ID"].InnerText;
            if (quantity["Description"] != null) omiQuantity.Description = quantity["Description"].InnerText;
            omiQuantity.Dimension = omiDimensions;
            omiQuantity.Unit = _omiUnits;
            omiQuantity.ValueType = ValueType.Scalar;
            if (quantity["ValueType"] != null)
            {
                if (quantity["ValueType"].InnerText == "Scalar")
                {
                    omiQuantity.ValueType = ValueType.Scalar;
                }
                else if (quantity["ValueType"].InnerText == "Vector")
                {
                    omiQuantity.ValueType = ValueType.Vector;
                }
            }

            //Create Element Set
            var omiElementSet = new ElementSet();
            var elementSet = ExchangeItem.SelectSingleNode("ElementSet");
            omiElementSet.ID = elementSet["ID"].InnerText;
            if (elementSet["Description"] != null) omiElementSet.Description = elementSet["Description"].InnerText;

            try
            {
                //add elements from shapefile to element set
                var utils = new Utilities();
                _shapefilepath = elementSet["ShapefilePath"].InnerText;
                omiElementSet = utils.AddElementsFromShapefile(omiElementSet, _shapefilepath);
            }
            catch (Exception)
            {
                Debug.WriteLine("An Element Set has not been declared using AddElementsFromShapefile");
            }

            try
            {
                // add elements from xml file to element set
                var utils = new Utilities();
                _xmlFilePath = elementSet["XmlFilePath"].InnerText;
                omiElementSet = utils.AddElementsFromXmlFile(omiElementSet, _xmlFilePath);
            }
            catch (Exception)
            {
                Debug.WriteLine("An Element Set has not been declared using AddElementsFromXmlFile");
            }

            if (Identifier == "OutputExchangeItem")
            {
                //create exchange item
                var omiOutputExchangeItem = new OutputExchangeItem();
                omiOutputExchangeItem.Quantity = omiQuantity;
                omiOutputExchangeItem.ElementSet = omiElementSet;

                //add the output exchange item to the list of output exchange items for the component
                _outputs.Add(omiOutputExchangeItem);
                if (!_quantities.ContainsKey(omiQuantity.ID)) _quantities.Add(omiQuantity.ID, omiQuantity);
                if (!_elementSets.ContainsKey(omiElementSet.ID)) _elementSets.Add(omiElementSet.ID, omiElementSet);
            }
            else if (Identifier == "InputExchangeItem")
            {
                //create exchange item
                var omiInputExchangeItem = new InputExchangeItem();
                omiInputExchangeItem.Quantity = omiQuantity;
                omiInputExchangeItem.ElementSet = omiElementSet;

                //add the output exchange item to the list of output exchange items for the component
                _inputs.Add(omiInputExchangeItem);
                if (!_quantities.ContainsKey(omiQuantity.ID)) _quantities.Add(omiQuantity.ID, omiQuantity);
                if (!_elementSets.ContainsKey(omiElementSet.ID)) _elementSets.Add(omiElementSet.ID, omiElementSet);
            }
        }
Ejemplo n.º 12
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;
		}