Ejemplo n.º 1
0
        public void Equals()
        {
            Element element1 = new Element("ElementID");

            element1.AddVertex(new Vertex(3.0,4.0,5.0));
            element1.AddVertex(new Vertex(4.0,5.0,6.0));
            element1.AddVertex(new Vertex(5.0,6.0,7.0));

            Element element2 = new Element("ElementID");

            element2.AddVertex(new Vertex(3.0,4.0,5.0));
            element2.AddVertex(new Vertex(4.0,5.0,6.0));

            Assert.IsFalse(element1.Equals(element2));

            element2.AddVertex(new Vertex(5.0,6.0,7.0));

            Assert.IsTrue(element1.Equals(element2));

            element1.ID = "ElementID1";

            Assert.IsFalse(element1.Equals(element2));

            Assert.IsFalse(element1.Equals(null));
            Assert.IsFalse(element1.Equals("string"));
        }
Ejemplo n.º 2
0
		public void Faces()
		{
			int[] index = {1,2,3,4,5};
			Element element = new Element();
			element.AddFace(index);
			Assert.AreEqual(1,element.FaceCount);
			Assert.AreEqual(index,element.GetFaceVertexIndices(0));
		}
Ejemplo n.º 3
0
    public void ExpectedException_1_Vertex_in_PolylineElement()
    {			
      //One Vertex in polyline element error
      ElementSet elementSet = new ElementSet("test","test",ElementType.XYPolyLine,new SpatialReference("DummyID"));
      Oatc.OpenMI.Sdk.Backbone.Element e1 = new Oatc.OpenMI.Sdk.Backbone.Element("e1");
      e1.AddVertex(new Vertex(1,1,1));
									
      elementSet.AddElement(e1);

      ElementSetChecker.CheckElementSet(elementSet);
    }
Ejemplo n.º 4
0
		public void Constructor()
		{
			Element element = new Element("ElementID");
			element.AddVertex(new Vertex(3.0,4.0,5.0));
			element.AddVertex(new Vertex(4.0,5.0,6.0));
			element.AddVertex(new Vertex(5.0,6.0,7.0));
			Assert.AreEqual("ElementID",element.ID);

			Element element2 = new Element(element);

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

			return outputExchangeItem;
		}
        public void ExpectedException_1_Vertex_in_PolylineElement()
        {
            //One Vertex in polyline element error
            ElementSet elementSet = new ElementSet("test", "test", ElementType.XYPolyLine, new SpatialReference("DummyID"));

            Oatc.OpenMI.Sdk.Backbone.Element e1 = new Oatc.OpenMI.Sdk.Backbone.Element("e1");
            e1.AddVertex(new Vertex(1, 1, 1));

            elementSet.AddElement(e1);

            ElementSetChecker.CheckElementSet(elementSet);
        }
Ejemplo n.º 7
0
        public void ExpectedException_1_Vertex_in_PolylineElement()
        {
            //One Coordinate in polyline element error
            ElementSet elementSet = new ElementSet("test", "test", ElementType.PolyLine);

            Oatc.OpenMI.Sdk.Backbone.Element e1 = new Oatc.OpenMI.Sdk.Backbone.Element("e1");
            e1.AddVertex(new Coordinate(1, 1, 1));

            elementSet.AddElement(e1);

            ElementSetChecker.CheckElementSet(elementSet);
        }
Ejemplo n.º 8
0
		public void ExpectedException_2_Vertices_in_PointElement()
		{			
			//Two Vertices in point element error
			ElementSet elementSet = new ElementSet("test","test",ElementType.XYPoint,new SpatialReference("DummyID"));
			Oatc.OpenMI.Sdk.Backbone.Element e1 = new Oatc.OpenMI.Sdk.Backbone.Element("e1");
			e1.AddVertex(new Vertex(1,1,1));
			e1.AddVertex(new Vertex(2,2,2)); //here the error is introduced on purpose
						
			elementSet.AddElement(e1);

			ElementSetChecker.CheckElementSet(elementSet);
		
		}
Ejemplo n.º 9
0
		public void Vertices()
		{
			Element element = new Element();

			element.AddVertex(new Vertex(3.0,4.0,5.0));
			element.AddVertex(new Vertex(4.0,5.0,6.0));
			element.AddVertex(new Vertex(5.0,6.0,7.0));

			Assert.AreEqual(3,element.VertexCount);
			Assert.AreEqual(new Vertex(3.0,4.0,5.0),element.Vertices[0]);
			Assert.AreEqual(new Vertex(4.0,5.0,6.0),element.Vertices[1]);
			Assert.AreEqual(new Vertex(5.0,6.0,7.0),element.Vertices[2]);
		}
Ejemplo n.º 10
0
        public void ExpectedException_2_Vertices_in_PointElement()
        {
            //Two Vertices in point element error
            ElementSet elementSet = new ElementSet("test", "test", ElementType.XYPoint, new SpatialReference("DummyID"));

            Oatc.OpenMI.Sdk.Backbone.Element e1 = new Oatc.OpenMI.Sdk.Backbone.Element("e1");
            e1.AddVertex(new Vertex(1, 1, 1));
            e1.AddVertex(new Vertex(2, 2, 2));           //here the error is introduced on purpose

            elementSet.AddElement(e1);

            ElementSetChecker.CheckElementSet(elementSet);
        }
Ejemplo n.º 11
0
        public void ExpectedException_2_Vertices_in_PolygonElement()
        {
            //Two Vertices in polygon element error
            ElementSet elementSet = new ElementSet("test", "test", ElementType.Polygon);

            Oatc.OpenMI.Sdk.Backbone.Element e1 = new Oatc.OpenMI.Sdk.Backbone.Element("e1");
            e1.AddVertex(new Coordinate(1, 1, 1));
            e1.AddVertex(new Coordinate(2, 2, 2));

            elementSet.AddElement(e1);

            ElementSetChecker.CheckElementSet(elementSet);
        }
Ejemplo n.º 12
0
        public void ExpectedException_WrongOrderingOfPoint_in_PolygonElement()
        {
            //Wrong ordering of vertices in polygon element error
            ElementSet elementSet = new ElementSet("test", "test", ElementType.XYPolygon, new SpatialReference("DummyID"));

            Oatc.OpenMI.Sdk.Backbone.Element e1 = new Oatc.OpenMI.Sdk.Backbone.Element("e1");
            e1.AddVertex(new Vertex(0, 0, 0));
            e1.AddVertex(new Vertex(0, 1, 0));
            e1.AddVertex(new Vertex(1, 1, 0));
            e1.AddVertex(new Vertex(1, 0, 0));

            elementSet.AddElement(e1);

            ElementSetChecker.CheckElementSet(elementSet);
        }
Ejemplo n.º 13
0
        public void ExpectedException_WrongOrderingOfPoint_in_PolygonElement()
        {
            //Wrong ordering of vertices in polygon element error
            ElementSet elementSet = new ElementSet("test", "test", ElementType.Polygon);

            Oatc.OpenMI.Sdk.Backbone.Element e1 = new Oatc.OpenMI.Sdk.Backbone.Element("e1");
            e1.AddVertex(new Coordinate(0, 0, 0));
            e1.AddVertex(new Coordinate(0, 1, 0));
            e1.AddVertex(new Coordinate(1, 1, 0));
            e1.AddVertex(new Coordinate(1, 0, 0));

            elementSet.AddElement(e1);

            ElementSetChecker.CheckElementSet(elementSet);
        }
Ejemplo n.º 14
0
        public void ExpectedException_Crossing_lines_in_PolygonElement()
        {
            //Crossing lines in polygon element error
            ElementSet elementSet = new ElementSet("test", "test", ElementType.XYPolygon, new SpatialReference("DummyID"));

            Oatc.OpenMI.Sdk.Backbone.Element e1 = new Oatc.OpenMI.Sdk.Backbone.Element("e1");
            e1.AddVertex(new Vertex(0, 1, 0));
            e1.AddVertex(new Vertex(0, 0, 0));
            e1.AddVertex(new Vertex(1, 0, 0));
            e1.AddVertex(new Vertex(0.9, 1.1, 0));
            e1.AddVertex(new Vertex(1.1, 0.9, 0));

            elementSet.AddElement(e1);

            ElementSetChecker.CheckElementSet(elementSet);
        }
Ejemplo n.º 15
0
        public void ExpectedException_Crossing_lines_in_PolygonElement()
        {
            //Crossing lines in polygon element error
            ElementSet elementSet = new ElementSet("test", "test", ElementType.Polygon);

            Oatc.OpenMI.Sdk.Backbone.Element e1 = new Oatc.OpenMI.Sdk.Backbone.Element("e1");
            e1.AddVertex(new Coordinate(0, 1, 0));
            e1.AddVertex(new Coordinate(0, 0, 0));
            e1.AddVertex(new Coordinate(1, 0, 0));
            e1.AddVertex(new Coordinate(0.9, 1.1, 0));
            e1.AddVertex(new Coordinate(1.1, 0.9, 0));

            elementSet.AddElement(e1);

            ElementSetChecker.CheckElementSet(elementSet);
        }
Ejemplo n.º 16
0
		public void Init() 
		{
			elementSet = new ElementSet("ElementSet","ElementSetID",
				ElementType.XYPolygon,new SpatialReference("ReferenceID"));
			element1 = new Element("element1");
			element1.AddVertex(new Vertex(1.0,2.0,3.0));
			element1.AddVertex(new Vertex(2.0,3.0,4.0));
			element1.AddVertex(new Vertex(4.0,5.0,6.0));
			int[] index = {1,2,3,4,5};
			element1.AddFace(index);
			elementSet.AddElement(element1);
			element2 = new Element("element2");
			element2.AddVertex(new Vertex(6.0,7.0,8.0));
			element2.AddVertex(new Vertex(9.0,10.0,11.0));
			element2.AddVertex(new Vertex(12.0,13.0,14.0));
			int[] index2 = {6,7,8,9};
			element2.AddFace(index2);
			elementSet.AddElement(element2);	
		}
Ejemplo n.º 17
0
		/// <summary>
		/// Copy constructor
		/// </summary>
		/// <param name="source">The element set to copy</param>
		public ElementSet(IElementSet source)
		{
			_description = source.Description;
			_id = source.ID;
			_elementType = source.ElementType;
		    _spatialReference = source.SpatialReference;

			for (int i=0;i<source.ElementCount;i++) 
			{
				Element element = new Element(source.GetElementID(i));
				for (int j=0;j<source.GetVertexCount(i);j++) 
				{
					double x = source.GetXCoordinate(i,j);
					double y = source.GetYCoordinate(i,j);
					double z = source.GetZCoordinate(i,j);

					element.AddVertex(new Vertex(x,y,z));
				}
				_elements.Add(element);
			}
		}
        private Element[] readElements(XmlNode aNode)
        {
            var elements = new List<Element>();
            foreach (XmlNode node in aNode.ChildNodes)
            {
                if (node.Name == "Element")
                {
                    var id = Utils.findChildNodeValue(node, "ID");
                    var x = Utils.findChildNodeValue(node, "X");
                    var y = Utils.findChildNodeValue(node, "Y");

                    // create a vertex
                    var vertex = new Vertex();
                    vertex.x = Double.Parse(x);
                    vertex.y = Double.Parse(y);

                    // create the vertices
                    var vertices = new Vertex[1];
                    vertices[0] = vertex;

                    // create an element
                    var element = new Element();
                    element.ID = id;
                    element.Vertices = vertices;

                    // save the element
                    elements.Add(element);
                }
            }

            var elementArray = new Element[elements.Count];
            for (var i = 0; i < elements.Count; i++)
                elementArray[i] = elements[i];

            return elementArray;
        }
        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.º 20
0
		[Test] // testing the Initialise method
		public void UpdateMappingMatrix_PolygonPolygon()
		{
			Vertex v1_0_10  = new Vertex(0,10,0);
			Vertex v1_0_0   = new Vertex(0,0,0);
			Vertex v1_10_0  = new Vertex(10,0,0);
			Vertex v1_10_10 = new Vertex(10,10,0);
			Vertex v1_20_0  = new Vertex(20,0,0);
			Vertex v1_20_10 = new Vertex(20,10,0);
			Vertex v1_5_9   = new Vertex(5,9,0);
			Vertex v1_5_1   = new Vertex(5,1,0);
			Vertex v1_15_5  = new Vertex(15,5,0);

			Element LeftSquare  = new Element("LeftSquare");
			LeftSquare.AddVertex(v1_0_10);
			LeftSquare.AddVertex(v1_0_0);
			LeftSquare.AddVertex(v1_10_0);
			LeftSquare.AddVertex(v1_10_10);
      
			Element RightSquare = new Element("RightSquare");
			RightSquare.AddVertex(v1_10_10);
			RightSquare.AddVertex(v1_10_0);
			RightSquare.AddVertex(v1_20_0);
			RightSquare.AddVertex(v1_20_10);

			Element Triangle    = new Element("Triangle");
			Triangle.AddVertex(v1_5_9);
			Triangle.AddVertex(v1_5_1);
			Triangle.AddVertex(v1_15_5);

			ElementSet TwoSquareElementSet      = new ElementSet("TwoSquareElementSet","TwoSquareElementSet",ElementType.XYPolygon,new SpatialReference("ref"));
			ElementSet TriangleElementSet       = new ElementSet("TriangleElementSet","TriangleElementSet",ElementType.XYPolygon,new SpatialReference("ref"));
			TwoSquareElementSet.AddElement(LeftSquare);
			TwoSquareElementSet.AddElement(RightSquare);
			TriangleElementSet.AddElement(Triangle);
      
			ElementMapper elementMapper = new ElementMapper();
			ArrayList methodDescriptions = elementMapper.GetAvailableMethods(TwoSquareElementSet.ElementType, TriangleElementSet.ElementType);
			elementMapper.Initialise(methodDescriptions[0].ToString(), TriangleElementSet,  TwoSquareElementSet);
			Assert.AreEqual(1, elementMapper.GetValueFromMappingMatrix(0, 0),"Test1");
			Assert.AreEqual(1, elementMapper.GetValueFromMappingMatrix(1, 0),"Test2");
      
			elementMapper.Initialise(methodDescriptions[0].ToString(), TwoSquareElementSet, TriangleElementSet);
			Assert.AreEqual(0.75, elementMapper.GetValueFromMappingMatrix(0, 0),0.000000001,"Test3");
			Assert.AreEqual(0.25, elementMapper.GetValueFromMappingMatrix(0, 1),"Test4");
	      
			elementMapper.Initialise(methodDescriptions[1].ToString(), TriangleElementSet,  TwoSquareElementSet);
			Assert.AreEqual(0.3, elementMapper.GetValueFromMappingMatrix(0, 0),"Test5");
			Assert.AreEqual(0.1, elementMapper.GetValueFromMappingMatrix(1, 0),"Test6");
	    
			elementMapper.Initialise(methodDescriptions[1].ToString(), TwoSquareElementSet, TriangleElementSet);
			Assert.AreEqual(0.75, elementMapper.GetValueFromMappingMatrix(0, 0),0.0000000001,"Test7");
			Assert.AreEqual(0.25, elementMapper.GetValueFromMappingMatrix(0, 1),"Test8");
      
			Vertex v2_0_2 = new Vertex(0,2,0);
			Vertex v2_0_0 = new Vertex(0,0,0);
			Vertex v2_2_0 = new Vertex(2,0,0);
			Vertex v2_1_2 = new Vertex(1,2,0);
			Vertex v2_1_0 = new Vertex(1,0,0);
			Vertex v2_3_0 = new Vertex(3,0,0);

			Element LeftTriangle2  = new Element("LeftTriangle");
			LeftTriangle2.AddVertex(v2_0_2);
			LeftTriangle2.AddVertex(v2_0_0);
			LeftTriangle2.AddVertex(v2_2_0);

			Element RightTriangle2  = new Element("RightTriangle");
			RightTriangle2.AddVertex(v2_1_2);
			RightTriangle2.AddVertex(v2_1_0);
			RightTriangle2.AddVertex(v2_3_0);
      
			ElementSet LeftTriangleElementSet2      = new ElementSet("TwoSquareElementSet","TwoSquareElementSet",ElementType.XYPolygon,new SpatialReference("ref"));
			ElementSet RightTriangleElementSet2       = new ElementSet("TriangleElementSet","TriangleElementSet",ElementType.XYPolygon,new SpatialReference("ref"));
			LeftTriangleElementSet2.AddElement(LeftTriangle2);
			RightTriangleElementSet2.AddElement(RightTriangle2);

      
			elementMapper.Initialise(methodDescriptions[0].ToString(), LeftTriangleElementSet2, RightTriangleElementSet2);
			Assert.AreEqual(1, elementMapper.GetValueFromMappingMatrix(0, 0),"Test9");

			elementMapper.Initialise(methodDescriptions[0].ToString(), RightTriangleElementSet2, LeftTriangleElementSet2);
			Assert.AreEqual(1, elementMapper.GetValueFromMappingMatrix(0, 0),"Test10");
      
			elementMapper.Initialise(methodDescriptions[1].ToString(), LeftTriangleElementSet2, RightTriangleElementSet2);
			Assert.AreEqual(0.25, elementMapper.GetValueFromMappingMatrix(0, 0),"Test11");

			elementMapper.Initialise(methodDescriptions[1].ToString(), RightTriangleElementSet2, LeftTriangleElementSet2);
			Assert.AreEqual(0.25, elementMapper.GetValueFromMappingMatrix(0, 0),"Test12");
      
			Vertex v3_0_2 = new Vertex(0,2,0);
			Vertex v3_0_0 = new Vertex(0,0,0);
			Vertex v3_2_0 = new Vertex(2,0,0);
			Vertex v3_1_2 = new Vertex(1,2,0);
			Vertex v3_1_0 = new Vertex(1,0,0);
			Vertex v3_3_2 = new Vertex(3,2,0);
    
			Element LeftTriangle3  = new Element("LeftTriangle");
			LeftTriangle3.AddVertex(v3_0_2);
			LeftTriangle3.AddVertex(v3_0_0);
			LeftTriangle3.AddVertex(v3_2_0);

			Element RightTriangle3  = new Element("RightTriangle");
			RightTriangle3.AddVertex(v3_1_2);
			RightTriangle3.AddVertex(v3_1_0);
			RightTriangle3.AddVertex(v3_3_2);
      
			ElementSet LeftTriangleElementSet3      = new ElementSet("TwoSquareElementSet","TwoSquareElementSet",ElementType.XYPolygon,new SpatialReference("ref"));
			ElementSet RightTriangleElementSet3       = new ElementSet("TriangleElementSet","TriangleElementSet",ElementType.XYPolygon,new SpatialReference("ref"));
			LeftTriangleElementSet3.AddElement(LeftTriangle3);
			RightTriangleElementSet3.AddElement(RightTriangle3);

			elementMapper.Initialise(methodDescriptions[0].ToString(), LeftTriangleElementSet3, RightTriangleElementSet3);
			Assert.AreEqual(1, elementMapper.GetValueFromMappingMatrix(0, 0),"Test13");

			elementMapper.Initialise(methodDescriptions[0].ToString(), RightTriangleElementSet3, LeftTriangleElementSet3);
			Assert.AreEqual(1, elementMapper.GetValueFromMappingMatrix(0, 0),"Test14");
      
			elementMapper.Initialise(methodDescriptions[1].ToString(), LeftTriangleElementSet3, RightTriangleElementSet3);
			Assert.AreEqual(0.125, elementMapper.GetValueFromMappingMatrix(0, 0),"Test15");

			elementMapper.Initialise(methodDescriptions[1].ToString(), RightTriangleElementSet3, LeftTriangleElementSet3);
			Assert.AreEqual(0.125, elementMapper.GetValueFromMappingMatrix(0, 0),"Test16");
		}
Ejemplo n.º 21
0
		[Test] // testing the Initialise method
		public void UpdateMappingMatrix_PolylinePolygon()
		{
			ElementSet twoSquaresGrid = new ElementSet("TwoSquaresGrid","TwoSquaresGrid",ElementType.XYPolygon,new SpatialReference("ref"));
  		
			Element e1 = new Element("e1");
			Element e2 = new Element("e2");
  		
			e1.AddVertex(new Vertex(1,1,0));
			e1.AddVertex(new Vertex(3,1,0));
			e1.AddVertex(new Vertex(3,3,0));
			e1.AddVertex(new Vertex(1,3,0));

			e2.AddVertex(new Vertex(3,1,0));
			e2.AddVertex(new Vertex(5,1,0));
			e2.AddVertex(new Vertex(5,3,0));
			e2.AddVertex(new Vertex(3,3,0));

			twoSquaresGrid.AddElement(e1);
			twoSquaresGrid.AddElement(e2);

			ElementSet twoLines = new ElementSet("TwoLines","TwoLines",ElementType.XYPolyLine,new SpatialReference("ref"));

			Element l1 = new Element("l1");
			Element l2 = new Element("l2");

			l1.AddVertex(new Vertex(0,2.5,0));
			l1.AddVertex(new Vertex(2,2.5,0));
			l2.AddVertex(new Vertex(2,2.5,0));
			l2.AddVertex(new Vertex(4,1.5,0));

			twoLines.AddElement(l1);
			twoLines.AddElement(l2);
      
			// Line to Polygon
			ElementMapper elementMapper = new ElementMapper();
			ArrayList methodDescriptions = elementMapper.GetAvailableMethods(twoLines.ElementType, twoSquaresGrid.ElementType);
			elementMapper.Initialise(methodDescriptions[0].ToString(), twoLines,twoSquaresGrid);
			Assert.AreEqual(1/(1+Math.Sqrt(1+Math.Pow(0.5,2))),elementMapper.GetValueFromMappingMatrix(0,0),"Test1");
			Assert.AreEqual(1-1/(1+Math.Sqrt(1+Math.Pow(0.5,2))),elementMapper.GetValueFromMappingMatrix(0,1),"Test2");
			Assert.AreEqual(0.0,elementMapper.GetValueFromMappingMatrix(1,0),"Test3");
			Assert.AreEqual(1,elementMapper.GetValueFromMappingMatrix(1,1),"Test4");

			elementMapper.Initialise(methodDescriptions[1].ToString(), twoLines,twoSquaresGrid);
			Assert.AreEqual(0.5,elementMapper.GetValueFromMappingMatrix(0,0),"Test5");
			Assert.AreEqual(0.5,elementMapper.GetValueFromMappingMatrix(0,1),"Test6");
			Assert.AreEqual(0.0,elementMapper.GetValueFromMappingMatrix(1,0),"Test7");
			Assert.AreEqual(0.5,elementMapper.GetValueFromMappingMatrix(1,1),"Test8");
      
			// Polygon To PolyLine
			methodDescriptions = elementMapper.GetAvailableMethods(twoSquaresGrid.ElementType, twoLines.ElementType);
			elementMapper.Initialise(methodDescriptions[0].ToString(), twoSquaresGrid, twoLines);
			Assert.AreEqual(1.0,elementMapper.GetValueFromMappingMatrix(0,0),"Test9");
			Assert.AreEqual(0.0,elementMapper.GetValueFromMappingMatrix(0,1),"Test10");
			Assert.AreEqual(0.5,elementMapper.GetValueFromMappingMatrix(1,0),"Test11");
			Assert.AreEqual(0.5,elementMapper.GetValueFromMappingMatrix(1,1),"Test12");

			elementMapper.Initialise(methodDescriptions[1].ToString(), twoSquaresGrid, twoLines);
			Assert.AreEqual(0.5,elementMapper.GetValueFromMappingMatrix(0,0),"Test13");
			Assert.AreEqual(0.0,elementMapper.GetValueFromMappingMatrix(0,1),"Test14");
			Assert.AreEqual(0.5,elementMapper.GetValueFromMappingMatrix(1,0),"Test15");
			Assert.AreEqual(0.5,elementMapper.GetValueFromMappingMatrix(1,1),"Test16");
		}
Ejemplo n.º 22
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;
        }
Ejemplo n.º 23
0
		/// <summary>
		/// Adds an element
		/// </summary>
		/// <param name="element">The element to add</param>
		public virtual void AddElement (Element element)
		{
			_elements.Add(element);
		}
Ejemplo n.º 24
0
		public void ExpectexException_UpdateMappingMatrix_ElementChecker()
		{
			//Two Vertices in point element error
			ElementSet elementSet = new ElementSet("test","test",ElementType.XYPoint,new SpatialReference("DummyID"));
			Element e1 = new Element("e1");
			e1.AddVertex(new Vertex(1,1,1));
			e1.AddVertex(new Vertex(2,2,2)); //here the error is introduced on purpose
						
			elementSet.AddElement(e1);
			
			ElementMapper elementMapper = new ElementMapper();
			string method = (string) elementMapper.GetAvailableMethods(ElementType.XYPolyLine,ElementType.XYPolygon)[0];
			elementMapper.UpdateMappingMatrix(method,elementSet,elementSet);
		}
Ejemplo n.º 25
0
		public void EqualsVertices()
		{
			ElementSet elementSet1 = new ElementSet("ElementSet","ElementSetID",
				ElementType.XYPolygon,new SpatialReference("ReferenceID"));
			element1 = new Element("element1");
			element1.AddVertex(new Vertex(1.1,2.0,3.0));
			element1.AddVertex(new Vertex(2.0,3.0,4.0));
			element1.AddVertex(new Vertex(4.0,5.0,6.0));
			elementSet1.AddElement(element1);
			element2 = new Element("element2");
			element2.AddVertex(new Vertex(6.0,7.0,8.0));
			element2.AddVertex(new Vertex(9.0,10.0,11.0));
			element2.AddVertex(new Vertex(12.0,13.0,14.0));
			elementSet1.AddElement(element2);


			Assert.IsFalse(elementSet.Equals(elementSet1));
		}
Ejemplo n.º 26
0
    public void ExpectedException_Crossing_lines_in_PolygonElement()
    {
      //Crossing lines in polygon element error
      ElementSet elementSet = new ElementSet("test","test",ElementType.XYPolygon,new SpatialReference("DummyID"));
      Oatc.OpenMI.Sdk.Backbone.Element e1 = new Oatc.OpenMI.Sdk.Backbone.Element("e1");
      e1.AddVertex(new Vertex(0,1,0));
      e1.AddVertex(new Vertex(0,0,0));
      e1.AddVertex(new Vertex(1,0,0));
      e1.AddVertex(new Vertex(0.9,1.1,0));
      e1.AddVertex(new Vertex(1.1,0.9,0));
      						
      elementSet.AddElement(e1);

      ElementSetChecker.CheckElementSet(elementSet);		
    }
Ejemplo n.º 27
0
		/// <summary>
		/// Copy constructor
		/// </summary>
		/// <param name="source">The element to copy</param>
		public Element(Element source)
		{
			ID = source.ID;
			Vertices = source.Vertices;
		}
Ejemplo n.º 28
0
    public void ExpectedException_WrongOrderingOfPoint_in_PolygonElement()
    {
      //Wrong ordering of vertices in polygon element error
      ElementSet elementSet = new ElementSet("test","test",ElementType.XYPolygon,new SpatialReference("DummyID"));
      Oatc.OpenMI.Sdk.Backbone.Element e1 = new Oatc.OpenMI.Sdk.Backbone.Element("e1");
      e1.AddVertex(new Vertex(0,0,0));
      e1.AddVertex(new Vertex(0,1,0));
      e1.AddVertex(new Vertex(1,1,0));
			e1.AddVertex(new Vertex(1,0,0));						
      
      elementSet.AddElement(e1);

      ElementSetChecker.CheckElementSet(elementSet);		
    }
        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);

                    }

                }
            }




        }
        /// <summary>
        ///     This method adds vertices to the omiElementSet. It provides the spatial representation for
        ///     the element set. The vertices are extracted from the components input xml file.
        /// </summary>
        /// <param name="omiElementSet">the components element set object</param>
        /// <param name="xmlFilePath">path to an xml file, spatially defining the elementset</param>
        /// <returns>the elementset with vertices added to it from the shapefile</returns>
        public ElementSet AddElementsFromXmlFile(ElementSet omiElementSet, string xmlFilePath)
        {
            // we want to look through the given xml file to find the element
            // set that corresponds to the element set that we were given, and
            // then add the vertices from the file into the element set.

            // read the xml document
            var doc = new XmlDocument();
            doc.Load(xmlFilePath);

            // get the list of element sets
            var elementSets = doc.SelectNodes("/ElementSets");

            // look through each element set
            foreach (XmlNode node in elementSets)
            {
                // get the element set node
                var elementSetNode = node.SelectSingleNode("ElementSet");

                // read the properties
                var id = elementSetNode.SelectSingleNode("ID").FirstChild.Value;
                var description = elementSetNode.SelectSingleNode("Description").FirstChild.Value;
                var version = Convert.ToInt32(elementSetNode.SelectSingleNode("Version").FirstChild.Value);
                var elementType = getXmlElementType(elementSetNode.SelectSingleNode("Kind").FirstChild.Value);

                // see if this is the one we're looking for
                if (id == omiElementSet.ID)
                {
                    // read the elements
                    var elementNodes = elementSetNode.SelectNodes("Elements/Element");

                    // read each element
                    foreach (XmlNode elementNode in elementNodes)
                    {
                        var e = new Element();

                        e.ID = elementNode.SelectSingleNode("ID").FirstChild.Value;

                        var xString = elementNode.SelectSingleNode("X").FirstChild.Value;
                        var yString = elementNode.SelectSingleNode("Y").FirstChild.Value;

                        var v = new Vertex();
                        v.x = Double.Parse(xString);
                        v.y = Double.Parse(yString);
                        e.AddVertex(v);

                        omiElementSet.AddElement(e);
                    }

                    // we found the one we're looking for, so we can stop
                    break;
                }
            }

            return omiElementSet;
        }
Ejemplo n.º 31
0
        public void Initialize(System.Collections.Hashtable properties)
        {
            _dt           = 1.0;
            _dx           = 0.0;
            _initialValue = 100;

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

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

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

            _values = new double[3];

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

            _startTime   = 4000;
            _currentTime = _startTime;

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

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

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

            _inputExchangeItem.Quantity    = quantity;
            _inputExchangeItem.ElementSet  = elementSet;
        }
Ejemplo n.º 32
0
		[Test] // testing the Initialise method
		public void MapValues()
		{
			ElementSet gridElementSet = new ElementSet("RegularGrid","RegularGrid",ElementType.XYPolygon, new SpatialReference("ref"));
			ElementSet fourPointsElementSet = new ElementSet("4 points","4P",ElementType.XYPoint,new SpatialReference("DummyID")); 

			Vertex v_0_20  = new Vertex(0,20,0);
			Vertex v_0_10  = new Vertex(0,10,0);
			Vertex v_0_0   = new Vertex(0, 0,0);
			Vertex v_0_15  = new Vertex(0,15,0);
			Vertex v_5_15  = new Vertex(5,15,0);
			Vertex v_10_20 = new Vertex(10,20,0);
			Vertex v_10_15 = new Vertex(10,15,0);
			Vertex v_10_10 = new Vertex(10,10,0);
			Vertex v_10_0  = new Vertex(10, 0,0);
			Vertex v_15_15 = new Vertex(15,15,0);
			Vertex v_15_5  = new Vertex(15,5,0);
			Vertex v_20_20 = new Vertex(20,20,0);
			Vertex v_20_10 = new Vertex(20,10,0);

			Element square1 = new Element("square1");
			Element square2 = new Element("square2");
			Element square3 = new Element("square3");

			square1.AddVertex(v_0_20);
			square1.AddVertex(v_0_10);
			square1.AddVertex(v_10_10);
			square1.AddVertex(v_10_20);

			square2.AddVertex(v_10_20);
			square2.AddVertex(v_10_10);
			square2.AddVertex(v_20_10);
			square2.AddVertex(v_20_20);

			square3.AddVertex(v_0_10);
			square3.AddVertex(v_0_0);
			square3.AddVertex(v_10_0);
			square3.AddVertex(v_10_10);

			gridElementSet.AddElement(square1);
			gridElementSet.AddElement(square2);
			gridElementSet.AddElement(square3);

			Element point_5_15  = new Element("point 5, 15");
			Element point_10_15 = new Element("point 10, 15");
			Element point_15_15 = new Element("point 15, 15");
			Element point_15_5  = new Element("point 15, 5");

			point_5_15.AddVertex(v_5_15);
			point_10_15.AddVertex(v_10_15);
			point_15_15.AddVertex(v_15_15);
			point_15_5.AddVertex(v_15_5);

			fourPointsElementSet.AddElement(point_5_15);
			fourPointsElementSet.AddElement(point_10_15);
			fourPointsElementSet.AddElement(point_15_15);
			fourPointsElementSet.AddElement(point_15_5);
			ScalarSet fourPointsScalarSet = new ScalarSet();
			ScalarSet gridScalarSet = new ScalarSet();      
      
			ElementMapper elementMapper = new ElementMapper();
      
			// point to polygon  
      
			ArrayList methodDescriptions = elementMapper.GetAvailableMethods(fourPointsElementSet.ElementType, gridElementSet.ElementType);
			elementMapper.Initialise(methodDescriptions[0].ToString(), fourPointsElementSet, gridElementSet);
			fourPointsScalarSet.data = new double[4] { 0, 10, 20, 30 };
			gridScalarSet = (ScalarSet)elementMapper.MapValues(fourPointsScalarSet);
			Assert.AreEqual(5, gridScalarSet.data[0]);
			Assert.AreEqual(20, gridScalarSet.data[1]);
			Assert.AreEqual(0, gridScalarSet.data[2]);
			// polygon to point
			methodDescriptions = elementMapper.GetAvailableMethods(gridElementSet.ElementType, fourPointsElementSet.ElementType);
			elementMapper.Initialise(methodDescriptions[0].ToString(), gridElementSet, fourPointsElementSet);
			fourPointsScalarSet = (ScalarSet)elementMapper.MapValues(gridScalarSet);
			Assert.AreEqual(5, fourPointsScalarSet.data[0]);
			Assert.AreEqual(5, fourPointsScalarSet.data[1]);
			Assert.AreEqual(20, fourPointsScalarSet.data[2]);
			Assert.AreEqual(0, fourPointsScalarSet.data[3]);
		}
Ejemplo n.º 33
0
		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);
			
			
		}
Ejemplo n.º 34
0
		private ElementSet CreateElementSet(string ElementSetID)
		{
			if (ElementSetID == "4 Points")
			{
				ElementSet fourPointsElementSet = new ElementSet("4 points","4 Points",ElementType.XYPoint,new SpatialReference("DummyID")); 
		
				Element e0 = new Element("e0"); 
				Element e1 = new Element("e1"); 
				Element e2 = new Element("e2");
				Element e3 = new Element("e3"); 
		
				e0.AddVertex(new Vertex( 0,100,0));
				e1.AddVertex(new Vertex( 0,0,0));
				e2.AddVertex(new Vertex( 100,0,0));
				e3.AddVertex(new Vertex(100,100,0));

				fourPointsElementSet.AddElement(e0);
				fourPointsElementSet.AddElement(e1);
				fourPointsElementSet.AddElement(e2);
				fourPointsElementSet.AddElement(e3);

				return fourPointsElementSet;
			}
			else if (ElementSetID == "2 Points")
			{
				ElementSet twoPointsElementSet = new ElementSet("2 points","2 Points",ElementType.XYPoint,new SpatialReference("dumID")); 

				Element k0 = new Element("k0"); 
				Element k1 = new Element("k1"); 

				k0.AddVertex(new Vertex( 0,75,0));
				k1.AddVertex(new Vertex( 200, 50, 0));

				twoPointsElementSet.AddElement(k0);
				twoPointsElementSet.AddElement(k1);

				return twoPointsElementSet;

			}
			else if (ElementSetID == "4 Other Points")
			{
				ElementSet fourPointsElementSet = new ElementSet("4 Other points","4 Other Points",ElementType.XYPoint,new SpatialReference("DummyID")); 
		
				Element e0 = new Element("e0"); 
				Element e1 = new Element("e1"); 
				Element e2 = new Element("e2");
				Element e3 = new Element("e3"); 
		
				e0.AddVertex(new Vertex( 0,15,0));
				e1.AddVertex(new Vertex( 5,15,0));
				e2.AddVertex(new Vertex( 0,10,0));
				e3.AddVertex(new Vertex(10,10,0));

				fourPointsElementSet.AddElement(e0);
				fourPointsElementSet.AddElement(e1);
				fourPointsElementSet.AddElement(e2);
				fourPointsElementSet.AddElement(e3);

				return fourPointsElementSet;
			}
			else if(ElementSetID == "3 points polyline")
			{
				ElementSet lineElementSet = new ElementSet("3 points polyline","3 points polyline",ElementType.XYPolyLine,new SpatialReference("dumID")); 

				Element l0 = new Element("k0"); 
				Element l1 = new Element("k1");
 
				Vertex v0 = new Vertex(0 ,20, 0);
				Vertex v1 = new Vertex(0 ,10, 0);
				Vertex v2 = new Vertex(0 , 0, 0);

				l0.AddVertex(v0);
				l0.AddVertex(v2);

				l1.AddVertex(v1);
				l1.AddVertex(v2);

				lineElementSet.AddElement(l0);
				lineElementSet.AddElement(l1);
				return lineElementSet;
			}
			else
			{
				throw new Exception("Cound not find specified elementset");
			
			}
		}
Ejemplo n.º 35
0
		[Test] // testing the Initialise method
		public void UpdateMappingMatrix_PointPolygon()
		{
			ElementSet gridElementSet = new ElementSet("gridElm","G1",ElementType.XYPolygon, new SpatialReference("ref"));
			ElementSet fourPointsElementSet = new ElementSet("4 points","4P",ElementType.XYPoint,new SpatialReference("DummyID")); 

			Vertex v_0_20  = new Vertex(0,20,0);
			Vertex v_0_10  = new Vertex(0,10,0);
			Vertex v_0_0   = new Vertex(0, 0,0);
			Vertex v_0_15  = new Vertex(0,15,0);
			Vertex v_5_15  = new Vertex(5,15,0);
			Vertex v_10_20 = new Vertex(10,20,0);
			Vertex v_10_15 = new Vertex(10,15,0);
			Vertex v_10_10 = new Vertex(10,10,0);
			Vertex v_10_0  = new Vertex(10, 0,0);
			Vertex v_15_15 = new Vertex(15,15,0);
			Vertex v_15_5  = new Vertex(15,5,0);
			Vertex v_20_20 = new Vertex(20,20,0);
			Vertex v_20_10 = new Vertex(20,10,0);

			Element square1 = new Element("square1");
			Element square2 = new Element("square2");
			Element square3 = new Element("square3");

			square1.AddVertex(v_0_20);
			square1.AddVertex(v_0_10);
			square1.AddVertex(v_10_10);
			square1.AddVertex(v_10_20);

			square2.AddVertex(v_10_20);
			square2.AddVertex(v_10_10);
			square2.AddVertex(v_20_10);
			square2.AddVertex(v_20_20);

			square3.AddVertex(v_0_10);
			square3.AddVertex(v_0_0);
			square3.AddVertex(v_10_0);
			square3.AddVertex(v_10_10);

			gridElementSet.AddElement(square1);
			gridElementSet.AddElement(square2);
			gridElementSet.AddElement(square3);

			Element point_5_15  = new Element("point 5, 15");
			Element point_10_15 = new Element("point 10, 15");
			Element point_15_15 = new Element("point 15, 15");
			Element point_15_5  = new Element("point 15, 5");

			point_5_15.AddVertex(v_5_15);
			point_10_15.AddVertex(v_10_15);
			point_15_15.AddVertex(v_15_15);
			point_15_5.AddVertex(v_15_5);

			fourPointsElementSet.AddElement(point_5_15);
			fourPointsElementSet.AddElement(point_10_15);
			fourPointsElementSet.AddElement(point_15_15);
			fourPointsElementSet.AddElement(point_15_5);
        
			ElementMapper elementMapper = new ElementMapper();
      
			// point to polygon
      
			ArrayList methodDescriptions = elementMapper.GetAvailableMethods(fourPointsElementSet.ElementType, gridElementSet.ElementType);
			elementMapper.Initialise(methodDescriptions[0].ToString(), fourPointsElementSet, gridElementSet);
			Assert.AreEqual(0.5, elementMapper.GetValueFromMappingMatrix(0, 0));
			Assert.AreEqual(0.5, elementMapper.GetValueFromMappingMatrix(0, 1));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(0, 2));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(0, 3));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(1, 0));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(1, 1));
			Assert.AreEqual(1, elementMapper.GetValueFromMappingMatrix(1, 2));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(1, 3));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(2, 0));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(2, 1));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(2, 2));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(2, 3));

			// polygon to point
			methodDescriptions = elementMapper.GetAvailableMethods(gridElementSet.ElementType, fourPointsElementSet.ElementType);
			elementMapper.Initialise(methodDescriptions[0].ToString(), gridElementSet, fourPointsElementSet);
			Assert.AreEqual(1, elementMapper.GetValueFromMappingMatrix(0, 0));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(0, 1));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(0, 2));
			Assert.AreEqual(1, elementMapper.GetValueFromMappingMatrix(1, 0));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(1, 1));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(1, 2));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(2, 0));
			Assert.AreEqual(1, elementMapper.GetValueFromMappingMatrix(2, 1));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(2, 2));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(3, 0));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(3, 1));
			Assert.AreEqual(0, elementMapper.GetValueFromMappingMatrix(3, 2));
		}
Ejemplo n.º 36
0
		public void ID()
		{
			Element element = new Element();
			element.ID = "ElementID";
			Assert.AreEqual("ElementID",element.ID);
		}
Ejemplo n.º 37
0
        //part of System.Collections
        public void Initialize(Hashtable properties)
        {
            _inputExchangeItems = new ArrayList();
            _outputExchangeItems = new ArrayList();
            _elementSets = new Hashtable();
            _elementScopes = new Hashtable();
            FilePath = ((string)properties["FilePath"]);

            InitializeDaisy((string)properties["FilePath"]);
            ModelDescription = ((string)GetDescription());

            for (int i = 0; i < _daisyEngine.ScopeSize(); i++)
            {
                Scope scope = _daisyEngine.GetScope(i);

                // Attribut column?
                if (!scope.HasString("column"))
                    continue;

                // Create element.
                string columnID = scope.String("column");
                Element element = new Element (columnID);
                _elementScopes[element] = scope;
                if (_daisyEngine.HasColumn(columnID))
                {
                    Column column = _daisyEngine.GetColumn(columnID);
                    for (uint ii = 0; ii < column.LocationSize(); ii++)
                    {
                        double x = column.LocationX(ii);
                        double y = column.LocationY(ii);
                        double z = 0.0;
                        element.AddVertex(new Vertex(x, y, z));
                    }
                }

                // Add exchange items.
                for (uint j = 0; j < scope.NumberSize(); j++)
                {
                    string name = scope.NumberName(j);
                    ElementSet elementSet;

                    // Find or create element set.
                    if (_elementSets.Contains(name))
                    {
                        elementSet = (ElementSet)_elementSets[name];
                        elementSet.Description += " " + columnID;
                        // TODO: We should test the type matches here.
                    }
                    else
                    {
                        switch (element.VertexCount)
                        {
                            case 0:
                                // ID based
                                elementSet = new ElementSet(columnID, name, ElementType.XYPoint, new SpatialReference(""));
                                break;
                            case 1:
                                // Point based
                                elementSet = new ElementSet(columnID, name, ElementType.XYPoint, new SpatialReference(""));
                                break;
                            case 2:
                                // Error
                                throw new ApplicationException("Error: Column must not contain exactly two (X Y)-points!");
                            default:
                                // Polygon
                                elementSet = new ElementSet(columnID, name, ElementType.XYPolygon, new SpatialReference(""));
                                break;
                        }
                        _elementSets[name] = elementSet;
                        string dim = scope.Dimension(name);
                        string description = scope.Description(name);

                        Quantity quantity = Quantity(dim, description, name);
                        if (scope.Writeable())
                        {
                            InputExchangeItem input = new InputExchangeItem();
                            input.Quantity = quantity;
                            input.ElementSet = elementSet;
                            _inputExchangeItems.Add(input);
                        }
                        else
                        {
                            OutputExchangeItem output = new OutputExchangeItem();
                            output.Quantity = quantity;
                            output.ElementSet = elementSet;
                            _outputExchangeItems.Add(output);
                        }
                    }

                    // Add it.
                    elementSet.AddElement(element);
                }
            }
        }
        /// <summary>
        ///     This method adds vertices to the omiElementSet.  It provides the spatial representation for
        ///     the element set.  The vertices are extracted from the components input shapefile.
        /// </summary>
        /// <param name="omiElementSet">the components element set object</param>
        /// <param name="shapefilePath">path to a shapefile, spatially defining the elementset</param>
        /// <returns>the elementset with vertices added to it from the shapefile</returns>
        public ElementSet AddElementsFromShapefile(ElementSet omiElementSet, string shapefilePath)
        {
            //this uses the free SharpMap API for reading a shapefile
            var myLayer = new VectorLayer("elements_layer");
            myLayer.DataSource = new ShapeFile(shapefilePath);
            myLayer.DataSource.Open();

            //set spatial reference from shapefile
            var sprf = new SpatialReference();
            sprf.ID = myLayer.DataSource.SRID.ToString();
            omiElementSet.SpatialReference = sprf;

            //add elements to elementset from shapefile
            for (uint i = 0; i < myLayer.DataSource.GetFeatureCount(); ++i)
            {
                var feat = myLayer.DataSource.GetFeature(i);
                var GeometryType = Convert.ToString(
                    feat.Geometry.AsText().Substring(
                        0, feat.Geometry.AsText().IndexOf(' ')));

                var e = new Element();

                if (feat.Table.Columns.IndexOf("HydroCode") != -1)
                    e.ID = feat.ItemArray[feat.Table.Columns.IndexOf("HydroCode")].ToString();

                if (GeometryType == "POINT")
                {
                    omiElementSet.ElementType = ElementType.XYPoint;
                    var p = (Point)feat.Geometry;
                    var v = new Vertex();
                    v.x = p.X;
                    v.y = p.Y;
                    e.AddVertex(v);
                }
                if (GeometryType == "POLYGON")
                {
                    omiElementSet.ElementType = ElementType.XYPolygon;
                    var p = (Polygon)feat.Geometry;
                    var lr = p.ExteriorRing;

                    //Only loop until lr.Vertices.Count-2 b/c the first element is the same
                    // as the last element within the exterior ring.  This will thrown an error
                    // within the OATC element mapper, when trying to map elements.  Also this
                    // loop arranges the vertices of the exterior ring in counter clockwise order
                    // as needed for the element mapping.
                    for (var j = lr.Vertices.Count - 2; j >= 0; j--)
                    {
                        var v = new Vertex();
                        v.x = lr.Vertices[j].X;
                        v.y = lr.Vertices[j].Y;
                        e.AddVertex(v);
                    }
                }
                if (GeometryType == "LINESTRING")
                {
                    omiElementSet.ElementType = ElementType.XYPolyLine;
                    var ls = (LineString)feat.Geometry;
                    //Point endpt = ls.EndPoint;
                    //Point startpt = ls.StartPoint;
                    for (var j = 0; j < ls.Vertices.Count; j++)
                    {
                        var v = new Vertex();
                        v.x = ls.Vertices[j].X;
                        v.y = ls.Vertices[j].Y;
                        e.AddVertex(v);
                    }
                }
                omiElementSet.AddElement(e);
            }
            return omiElementSet;
        }