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);

            }

        }
예제 #2
0
        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);
            }
        }