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; }
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()); }
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; }
private static Dimension readDimension(XmlNode aNode) { var dimension = new Dimension(); foreach (XmlNode node in aNode.ChildNodes) { if (node.Name == "Dimension") { // note that this just returns the first one right now var b = Utils.findChildNodeValue(node, "Base"); var power = Utils.findChildNodeValue(node, "Power"); dimension.SetPower(getDimensionBase(b), Int32.Parse(power)); break; } } return dimension; }
public void Validate() { ILinkableComponent upperRiver = new RiverModelLC(); ILinkableComponent lowerRiver = new RiverModelLC(); Oatc.OpenMI.Sdk.Wrapper.UnitTest.Trigger trigger = new Oatc.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 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); } }
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); } }
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; }