Example #1
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);
		}
Example #2
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]);
		}
        public void ExpectedException_2_Vertices_in_PointElement()
        {
            try
            {
                //Two Vertices in point element error
                ElementSet elementSet = new ElementSet("test", "test", ElementType.XYPoint, new SpatialReference("DummyID"));
                HydroNumerics.OpenMI.Sdk.Backbone.Element e1 = new HydroNumerics.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);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.GetType() == typeof(Exception));
            }
        }
        public void ExpectedException_0_Length_in_PolylineElement()
        {
            try
            {
                //One Vertex in polyline element error
                ElementSet elementSet = new ElementSet("test", "test", ElementType.XYPolyLine, new SpatialReference("DummyID"));
                HydroNumerics.OpenMI.Sdk.Backbone.Element e1 = new HydroNumerics.OpenMI.Sdk.Backbone.Element("e1");
                e1.AddVertex(new Vertex(1, 1, 1));
                e1.AddVertex(new Vertex(1, 1, 1));

                elementSet.AddElement(e1);

                ElementSetChecker.CheckElementSet(elementSet);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.GetType() == typeof(Exception));
            }
        }
		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);	
		}
		public void ExpectedException_2_Vertices_in_PointElement()
		{
            try
            {
                //Two Vertices in point element error
                ElementSet elementSet = new ElementSet("test", "test", ElementType.XYPoint, new SpatialReference("DummyID"));
                HydroNumerics.OpenMI.Sdk.Backbone.Element e1 = new HydroNumerics.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);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.GetType() == typeof(Exception));
            }
		
		}
        public void MyTestInitialize()
        {
            elementSet = new ElementSet("ElementSet", "ElementSetID", ElementType.Polygon);

            element1 = new Element("element1");
            element1.AddVertex(new Coordinate(1.0, 2.0, 3.0));
            element1.AddVertex(new Coordinate(2.0, 3.0, 4.0));
            element1.AddVertex(new Coordinate(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 Coordinate(6.0, 7.0, 8.0));
            element2.AddVertex(new Coordinate(9.0, 10.0, 11.0));
            element2.AddVertex(new Coordinate(12.0, 13.0, 14.0));
            int[] index2 = { 6, 7, 8, 9 };
            element2.AddFace(index2);
            elementSet.AddElement(element2);
        }
        public void ExpectedException_WrongOrderingOfPoint_in_PolygonElement()
        {
            try
            {
                //Wrong ordering of vertices in polygon element error
                ElementSet elementSet = new ElementSet("test", "test", ElementType.XYPolygon, new SpatialReference("DummyID"));
                HydroNumerics.OpenMI.Sdk.Backbone.Element e1 = new HydroNumerics.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);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.GetType() == typeof(Exception));
            }
        }
    public void ExpectedException_1_Vertex_in_PolylineElement()
    {
        try
        {
            //One Vertex in polyline element error
            ElementSet elementSet = new ElementSet("test", "test", ElementType.XYPolyLine, new SpatialReference("DummyID"));
            HydroNumerics.OpenMI.Sdk.Backbone.Element e1 = new HydroNumerics.OpenMI.Sdk.Backbone.Element("e1");
            e1.AddVertex(new Vertex(1, 1, 1));

            elementSet.AddElement(e1);

            ElementSetChecker.CheckElementSet(elementSet);
        }
        catch (Exception ex)
        {
            Assert.IsTrue(ex.GetType() == typeof(Exception));
        }
    }
Example #10
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="source">The element set to copy</param>
        public ElementSet(IElementSet source)
        {
            _description = source.Description;
            _caption = source.Caption;
            _elementType = source.ElementType;
            _spatialReferenceWKT = source.SpatialReferenceSystemWkt;

            for (int i = 0; i < source.ElementCount; i++)
            {
                Element element = new Element(source.GetElementId(i).Id);
                for (int j = 0; j < source.GetVertexCount(i); j++)
                {
                    Coordinate vertex = new Coordinate(source.GetVertexXCoordinate(i, j),
                                                       source.GetVertexYCoordinate(i, j),
                                                       source.GetVertexZCoordinate(i, j));
                    element.AddVertex(vertex);
                }
                elements.Add(element);
            }
        }
Example #11
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="source">The element set to copy</param>
        public ElementSet(IElementSet source)
        {
            _description         = source.Description;
            _caption             = source.Caption;
            _elementType         = source.ElementType;
            _spatialReferenceWKT = source.SpatialReferenceSystemWkt;

            for (int i = 0; i < source.ElementCount; i++)
            {
                Element element = new Element(source.GetElementId(i).Id);
                for (int j = 0; j < source.GetVertexCount(i); j++)
                {
                    Coordinate vertex = new Coordinate(source.GetVertexXCoordinate(i, j),
                                                       source.GetVertexYCoordinate(i, j),
                                                       source.GetVertexZCoordinate(i, j));
                    element.AddVertex(vertex);
                }
                elements.Add(element);
            }
        }
Example #12
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);
			}
		}
Example #13
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);
            }
        }
		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));
		}
Example #15
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"));


		}
		public void Validate()
		{
			ILinkableComponent upperRiver = new RiverModelLC();
			ILinkableComponent lowerRiver = new RiverModelLC();
			HydroNumerics.OpenMI.Sdk.Wrapper.UnitTest.Trigger trigger     = new HydroNumerics.OpenMI.Sdk.Wrapper.UnitTest.Trigger();

			// The ModelID is passes in ordet to make it easier to debug, otherwise you cannot se the difference between the two istances of RiverModelLC
			Argument[] upperRiverArguments = new Argument[1];
			upperRiverArguments[0] = new Argument("ModelID","upperRiverModel",true,"argument");
			upperRiver.Initialize(upperRiverArguments);

			// The ModelID is passes in ordet to make it easier to debug, otherwise you cannot se the difference between the two istances of RiverModelLC
			Argument[] lowerRiverArguments = new Argument[1];
			lowerRiverArguments[0] = new Argument("ModelID","lowerRiverModel",true,"argument");
			lowerRiver.Initialize(lowerRiverArguments);
			trigger.Initialize(new Argument[0]);

			Assert.AreEqual("upperRiverModel",upperRiver.ModelID);
			Assert.AreEqual("lowerRiverModel",lowerRiver.ModelID);

			Dimension wrongDimension = new Dimension();
			wrongDimension.SetPower(DimensionBase.Mass,1);
			Quantity wrongQuantity = new Quantity(new Unit("dummy",0.0,0.0,"dummy"),"test","qid",global::OpenMI.Standard.ValueType.Vector,wrongDimension);
			ElementSet wrongElementSet = new ElementSet("Wrong ElementSet","BadID",ElementType.XYPolyLine,new SpatialReference("no ref"));
			Element element = new Element("dum Element");
			element.AddVertex(new Vertex(4,5,0));
			wrongElementSet.AddElement(element);

			Link link = new Link();
			link.ID = "RiverToRiverLink";
			link.SourceComponent  = upperRiver;
			link.SourceElementSet = upperRiver.GetOutputExchangeItem(2).ElementSet; //last branch in the river
			link.SourceQuantity   = upperRiver.GetOutputExchangeItem(2).Quantity;
			link.TargetComponent  = lowerRiver;
			link.TargetElementSet = lowerRiver.GetInputExchangeItem(0).ElementSet;  //first node in the river
			link.TargetQuantity   = wrongQuantity;
//			link.AddDataOperation(upperRiver.GetOutputExchangeItem(6).GetDataOperation(0)); // bad data Operation

			Link triggerLink = new Link();

			triggerLink.ID				 = "TriggerLink";
			triggerLink.SourceComponent  = lowerRiver;
			triggerLink.SourceElementSet = wrongElementSet;
			triggerLink.SourceQuantity   = wrongQuantity;
			triggerLink.TargetComponent  = trigger;
			triggerLink.TargetElementSet = trigger.GetInputExchangeItem(0).ElementSet;
			triggerLink.TargetQuantity   = trigger.GetInputExchangeItem(0).Quantity;
		
			upperRiver.AddLink(link);
			lowerRiver.AddLink(link);

			lowerRiver.AddLink(triggerLink);
			trigger.AddLink(triggerLink);

			bool isSilent = false;
			if (!isSilent)
			{
				Console.WriteLine(lowerRiver.Validate());

				foreach (string str in ((RiverModelLC) upperRiver).ValidationErrorMessages)
				{
					Console.WriteLine("Error upperRiver: " + str);
				}
				foreach (string str in ((RiverModelLC) lowerRiver).ValidationErrorMessages)
				{
					Console.WriteLine("Error lowerRiver: " + str);
				}
				foreach (string str in ((RiverModelLC) upperRiver).ValidationWarningMessages)
				{
					Console.WriteLine("Warning upperRiver: " + str);
				}
				foreach (string str in ((RiverModelLC) lowerRiver).ValidationWarningMessages)
				{
					Console.WriteLine("Warning lowerRiver: " + str);
				}
			}

			Assert.AreEqual(0,((RiverModelLC) upperRiver).ValidationErrorMessages.Count);
			Assert.AreEqual(4,((RiverModelLC) lowerRiver).ValidationErrorMessages.Count);

			Assert.AreEqual(0,((RiverModelLC) upperRiver).ValidationWarningMessages.Count);
			Assert.AreEqual(2,((RiverModelLC) lowerRiver).ValidationWarningMessages.Count);
			
			
		}
        public void EqualsSpatialReference()
        {
            ElementSet elementSet1 = new ElementSet("ElementSet", "ElementSetID", ElementType.Polygon);
            element1 = new Element("element1");
            element1.AddVertex(new Coordinate(1.0, 2.0, 3.0));
            element1.AddVertex(new Coordinate(2.0, 3.0, 4.0));
            element1.AddVertex(new Coordinate(4.0, 5.0, 6.0));
            elementSet1.AddElement(element1);

            element2 = new Element("element2");
            element2.AddVertex(new Coordinate(6.0, 7.0, 8.0));
            element2.AddVertex(new Coordinate(9.0, 10.0, 11.0));
            element2.AddVertex(new Coordinate(12.0, 13.0, 14.0));
            elementSet1.AddElement(element2);

            elementSet1.SpatialReferenceSystemWkt = "PROJCS[\"Mercator Spheric\", GEOGCS[\"WGS84based_GCS\", DATUM[\"WGS84based_Datum\", SPHEROID[\"WGS84based_Sphere\", 6378137, 0], TOWGS84[0, 0, 0, 0, 0, 0, 0]], PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH]]";

            Assert.IsFalse(elementSet.Equals(elementSet1));
        }
		public void ExpectexException_UpdateMappingMatrix_ElementChecker()
		{
            try
            {
                //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);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.GetType() == typeof(Exception));
            }

		}
        [TestMethod()] // 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]);
		}
        [TestMethod()] // 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");
		}
        [TestMethod()] // testing the Initialise method
    public void UpdateMappingMatrix_LinePolygon()
    {
      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.XYLine, 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");
    }
		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 if (ElementSetID == "2 element XYline ElementSet")
      {
        ElementSet lineElementSet = new ElementSet("2 element XYline ElementSet", "2 element XYline ElementSet", ElementType.XYLine, 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");
			
			}
		}
        [TestMethod()] // 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));
		}
Example #24
0
		public void Initialize(System.Collections.Hashtable properties)
		{
			double ox = 2.0;
			double oy = 2.0;
			double dx = 4.0;
			double dy = 4.0;

			// -- Populate Input Exchange Items ---
			Element element0 = new Element("element:0");
			element0.AddVertex(new Vertex(ox      ,oy        ,0));
			element0.AddVertex(new Vertex(ox+dx   ,oy        ,0));
			element0.AddVertex(new Vertex(ox+dx   ,oy+dy     ,0));
			element0.AddVertex(new Vertex(ox      ,oy+dy     ,0));

			Element element1 = new Element("element:1");
			element1.AddVertex(new Vertex(ox + dx ,oy        ,0));
			element1.AddVertex(new Vertex(ox+2*dx ,oy        ,0));
			element1.AddVertex(new Vertex(ox+2*dx ,oy+dy     ,0));
			element1.AddVertex(new Vertex(ox+dx   ,oy+dy     ,0));

			Element element2 = new Element("element:2");
			element2.AddVertex(new Vertex(ox      ,oy+dy       ,0));
			element2.AddVertex(new Vertex(ox+dx   ,oy+dy       ,0));
			element2.AddVertex(new Vertex(ox+dx   ,oy+2*dy     ,0));
			element2.AddVertex(new Vertex(ox      ,oy+2*dy     ,0));

			Element element3 = new Element("element:3");
			element3.AddVertex(new Vertex(ox + dx ,oy+dy       ,0));
			element3.AddVertex(new Vertex(ox+2*dx ,oy+dy       ,0));
			element3.AddVertex(new Vertex(ox+2*dx ,oy+2*dy     ,0));
			element3.AddVertex(new Vertex(ox+dx   ,oy+2*dy     ,0));

			ElementSet elementSet = new ElementSet("RegularGrid","RegularGrid",ElementType.XYPolygon,new SpatialReference(" "));
			elementSet.AddElement(element0);
			elementSet.AddElement(element1);
			elementSet.AddElement(element2);
			elementSet.AddElement(element3);

			Quantity storageQuantity = new Quantity(new Unit("Storage",1.0,0.0,"Storage"),"Storage","Storage",global::OpenMI.Standard.ValueType.Scalar,new Dimension());
			InputExchangeItem inputExchangeItem = new InputExchangeItem();
			inputExchangeItem.ElementSet = elementSet;
			inputExchangeItem.Quantity   = storageQuantity;
			_inputExchangeItems.Add(inputExchangeItem);

			OutputExchangeItem outputExchangeItem = new OutputExchangeItem();
			outputExchangeItem.ElementSet = elementSet;
			outputExchangeItem.Quantity   = storageQuantity;
			_outputExchangeItems.Add(outputExchangeItem);

		}
        public void EqualsVertices()
        {
            ElementSet elementSet1 = new ElementSet("ElementSet", "ElementSetID", ElementType.Polygon);
            element1 = new Element("element1");
            element1.AddVertex(new Coordinate(1.1, 2.0, 3.0));
            element1.AddVertex(new Coordinate(2.0, 3.0, 4.0));
            element1.AddVertex(new Coordinate(4.0, 5.0, 6.0));
            elementSet1.AddElement(element1);
            element2 = new Element("element2");
            element2.AddVertex(new Coordinate(6.0, 7.0, 8.0));
            element2.AddVertex(new Coordinate(9.0, 10.0, 11.0));
            element2.AddVertex(new Coordinate(12.0, 13.0, 14.0));
            elementSet1.AddElement(element2);

            Assert.IsFalse(elementSet.Equals(elementSet1));
        }
Example #26
0
        public void Initialize(System.Collections.Hashtable properties)
        {

            if (!properties.Contains("InputFilename"))
            {
                throw new Exception("Missing key \"InputFilename\" in parameter to method HydroNumerics.HydroNet.OpenMI.EngineWrapper.Initialize(...)");
            }

            if (!properties.Contains("TimestepLength"))
            {
                throw new Exception("Missing key \"TimestepLength\" in parameter to method HydroNumerics.HydroNet.OpenMI.EngineWrapper.Initialize(...)");
            }


            inputFilename = (string)properties["InputFilename"];

            double dt = Convert.ToDouble((string)properties["TimestepLength"]);
            timestepLength = System.TimeSpan.FromSeconds(dt);

            
            // because the OpenMI configuration editor works makes paths relative to locations of OMI files or the configuration editor itselves, thigs may go wrong.
            // In order to overcome this problem, the full path for the input file is saves, so when the Finish method is invoked, the output is save to the input file again and not
            // a file at some random location :-). See below
            System.IO.FileInfo fileInfo = new System.IO.FileInfo(inputFilename);
            inputFilename = fileInfo.FullName;

            model = HydroNumerics.HydroNet.Core.ModelFactory.GetModel(inputFilename);
            model.Initialize();
            //model = ModelFactory.GetModel(inputFilename);


            foreach (var wb in model._waterBodies)
            {
              //Build exchangeitems from groundwater boundaries
              foreach (var gwb in wb.GroundwaterBoundaries)
              {
                GroundWaterBoundary GWB = gwb as GroundWaterBoundary;
                if (GWB != null)
                {
                  ElementSet elementSet = new ElementSet();
                  elementSet.ID = GWB.Name;
                  elementSet.Description = "Location: " + GWB.Name;
                  elementSet.SpatialReference = new SpatialReference("Undefined");
                  Element element = new Element();
                  element.ID = GWB.Name;

                  elementSet.ElementType = ElementType.XYPolygon;
                  foreach (XYPoint xyPoint in ((XYPolygon)GWB.ContactGeometry).Points)
                  {
                    element.AddVertex(new Vertex(xyPoint.X, xyPoint.Y, 0));
                  }

                  elementSet.AddElement(element);

                  //Head
                  HydroNumerics.OpenMI.Sdk.Backbone.Dimension dimension = new HydroNumerics.OpenMI.Sdk.Backbone.Dimension();
                  dimension.Length = 1;

                  HydroNumerics.OpenMI.Sdk.Backbone.Unit unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit();
                  unit.ID = "m";
                  unit.Description = "meter";
                  unit.ConversionFactorToSI = 1;
                  unit.OffSetToSI = 0;

                  Quantity quantity = new Quantity();
                  quantity.ID = "Head";
                  quantity.Description = "Head at:" + GWB.Name;
                  quantity.Dimension = dimension;
                  quantity.Unit = unit;
                  
                  InputExchangeItem inputExchangeItem = new InputExchangeItem();
                  inputExchangeItem.Quantity = quantity;
                  inputExchangeItem.ElementSet = elementSet;
                  inputExchangeItems.Add(inputExchangeItem);

                  HeadBoundaries.Add(GWB.Name, GWB);

                  //Leakage
                  Quantity leakage = new Quantity("Leakage");
                  leakage.Description = "Leakage at:" + GWB.Name;
                  var leakageDimension = new HydroNumerics.OpenMI.Sdk.Backbone.Dimension();
                  leakageDimension.Length = 3;
                  leakageDimension.Time = -1;
                  leakage.Dimension = leakageDimension;
                  leakage.Unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit("m3/s", 1, 0);

                  OutputExchangeItem outputitem = new OutputExchangeItem();
                  outputitem.Quantity = leakage;
                  outputitem.ElementSet = elementSet;
                  outputExchangeItems.Add(outputitem);
                  LeakageBoundaries.Add(GWB.Name, GWB);

                }
              }

              foreach (var S in wb.Sources)
              {
                ElementSet elementSet = new ElementSet();
                elementSet.ID = S.Name;
                elementSet.Description = "Location: " + S.Name;
                elementSet.SpatialReference = new SpatialReference("Undefined");
                Element element = new Element();
                element.ID = S.Name;

                elementSet.ElementType = ElementType.IDBased;


                //Flow
                Quantity leakage = new Quantity("Flow");
                leakage.Description = "Flow at:" + S.Name;
                var leakageDimension = new HydroNumerics.OpenMI.Sdk.Backbone.Dimension();
                leakageDimension.Length = 3;
                leakageDimension.Time = -1;
                leakage.Dimension = leakageDimension;
                leakage.Unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit("m3/s", 1, 0);

                InputExchangeItem outputitem = new InputExchangeItem();
                outputitem.Quantity = leakage;
                outputitem.ElementSet = elementSet;
                inputExchangeItems.Add(outputitem);
                FlowBoundaries.Add(S.Name, (SinkSourceBoundary)S);
                


              }
            }

            

            //foreach (var exchangeItem in model.ExchangeItems)
            //{
            //    HydroNumerics.OpenMI.Sdk.Backbone.Dimension dimention = new HydroNumerics.OpenMI.Sdk.Backbone.Dimension();
            //    dimention.AmountOfSubstance = exchangeItem.Unit.Dimension.AmountOfSubstance;
            //    dimention.Currency = exchangeItem.Unit.Dimension.Currency;
            //    dimention.ElectricCurrent = exchangeItem.Unit.Dimension.ElectricCurrent;
            //    dimention.Length = exchangeItem.Unit.Dimension.AmountOfSubstance;
            //    dimention.LuminousIntensity = exchangeItem.Unit.Dimension.Length;
            //    dimention.Mass = exchangeItem.Unit.Dimension.LuminousIntensity;
            //    dimention.AmountOfSubstance = exchangeItem.Unit.Dimension.Mass;
            //    dimention.Time = exchangeItem.Unit.Dimension.Time;

            //    HydroNumerics.OpenMI.Sdk.Backbone.Unit unit = new HydroNumerics.OpenMI.Sdk.Backbone.Unit();
            //    unit.ID = exchangeItem.Unit.ID;
            //    unit.Description = exchangeItem.Unit.Description;
            //    unit.ConversionFactorToSI = exchangeItem.Unit.ConversionFactorToSI;
            //    unit.OffSetToSI = unit.OffSetToSI;
                                
            //    Quantity quantity = new Quantity();
            //    quantity.ID = exchangeItem.Quantity;
            //    quantity.Description = exchangeItem.Description;
            //    quantity.Dimension = dimention;
            //    quantity.Unit = unit;

            //    ElementSet elementSet = new ElementSet();
            //    elementSet.ID = exchangeItem.Location;
            //    elementSet.Description = "Location: " + exchangeItem.Location;
            //    elementSet.SpatialReference = new SpatialReference("Undefined");
            //    Element element = new Element();
            //    element.ID = exchangeItem.Location;

            //    if (exchangeItem.Geometry is XYPolygon)
            //    {
            //        elementSet.ElementType = ElementType.XYPolygon;
            //        foreach (XYPoint xyPoint in ((XYPolygon)exchangeItem.Geometry).Points)
            //        {
            //            element.AddVertex(new Vertex(xyPoint.X, xyPoint.Y, 0));
            //        }
            //    }
            //    else if (exchangeItem.Geometry is XYPoint)
            //    {
            //        throw new NotImplementedException();
            //    }
            //    else if (exchangeItem.Geometry is XYPolyline)
            //    {
            //        throw new NotImplementedException();
            //    }
            //    else
            //    {
            //        elementSet.ElementType = global::OpenMI.Standard.ElementType.IDBased;
            //    }
                
                
            //    elementSet.AddElement(element);


            //    if (exchangeItem.IsOutput)
            //    {
            //        OutputExchangeItem outputExchangeItem = new OutputExchangeItem();
            //        outputExchangeItem.Quantity = quantity;
            //        outputExchangeItem.ElementSet = elementSet;
            //        outputExchangeItems.Add(outputExchangeItem);
            //    }
            //    if (exchangeItem.IsInput)
            //    {
            //        InputExchangeItem inputExchangeItem = new InputExchangeItem();
            //        inputExchangeItem.Quantity = quantity;
            //        inputExchangeItem.ElementSet = elementSet;
            //        inputExchangeItems.Add(inputExchangeItem);
            //    }
            //}

        }
    public void ExpectedException_Crossing_lines_in_PolygonElement()
    {
        try
        {
            //Crossing lines in polygon element error
            ElementSet elementSet = new ElementSet("test", "test", ElementType.XYPolygon, new SpatialReference("DummyID"));
            HydroNumerics.OpenMI.Sdk.Backbone.Element e1 = new HydroNumerics.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);
        }
        catch (Exception ex)
        {
            Assert.IsTrue(ex.GetType() == typeof(Exception));
        }
    }
		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;
		}