Beispiel #1
0
        public void IsPointInPolygon()
        {
            XYPolygon xypolygon = new XYPolygon();

            xypolygon.Points.Add(new XYPoint(1, 1));
            xypolygon.Points.Add(new XYPoint(9, 1));
            xypolygon.Points.Add(new XYPoint(5, 5));
            xypolygon.Points.Add(new XYPoint(5, 3));
            xypolygon.Points.Add(new XYPoint(3, 3));
            xypolygon.Points.Add(new XYPoint(3, 8));
            xypolygon.Points.Add(new XYPoint(9, 8));
            xypolygon.Points.Add(new XYPoint(9, 11));
            xypolygon.Points.Add(new XYPoint(1, 11));

            Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(2, 2, xypolygon));
            Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(2, 4, xypolygon));
            Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(2, 10, xypolygon));
            Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(7, 10, xypolygon));
            Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(4, 2, xypolygon));
            Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(7, 2, xypolygon));
            Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(6, 3.5, xypolygon));
            Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(7.5, 2, xypolygon));

            Assert.AreEqual(false, XYGeometryTools.IsPointInPolygon(0, 0, xypolygon));
            Assert.AreEqual(false, XYGeometryTools.IsPointInPolygon(4, 4, xypolygon));
            Assert.AreEqual(false, XYGeometryTools.IsPointInPolygon(4, 5, xypolygon));
            Assert.AreEqual(false, XYGeometryTools.IsPointInPolygon(10, 8, xypolygon));
            Assert.AreEqual(false, XYGeometryTools.IsPointInPolygon(9, 12, xypolygon));

            Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(new XYPoint(7.5, 2), xypolygon));
            Assert.AreEqual(false, XYGeometryTools.IsPointInPolygon(new XYPoint(0, 0), xypolygon));
        }
Beispiel #2
0
 public Lake(string name, XYPolygon surface)
     : base(name)
 {
     SurfaceArea = surface;
     Depth       = 1;
     Initialize();
 }
Beispiel #3
0
        public static ModelVisual3D Representation3D(this XYPolygon Poly, IXYPoint refpoint, double height)
        {
            MeshBuilder mb  = new MeshBuilder();
            var         pts = new Point3DCollection();

            foreach (var p in Poly.Points)
            {
                pts.Add(new Point3D(refpoint.X - p.X, refpoint.Y - p.Y, height));
            }

            // POLYGONS (flat and convex)
            var poly3D = new Polygon3D(pts);
            // Transform the polygon to 2D
            var poly2D = poly3D.Flatten();
            // Triangulate
            var tri = poly2D.Triangulate();

            if (tri != null)
            {
                // Add the triangle indices with the 3D points
                mb.Append(pts, tri);
            }

            var m = MaterialHelper.CreateMaterial(Colors.DimGray, 0.5);

            var mv3D = new ModelVisual3D();

            mv3D.Content = new GeometryModel3D(mb.ToMesh(), m);
            return(mv3D);
        }
Beispiel #4
0
        public IWaterPacket GetSourceWater(DateTime Start, TimeSpan TimeStep)
        {
            foreach (var kvp in _concentrations)
            {
                ((WaterPacket)WaterSample).SetConcentration(kvp.Key, kvp.Value.GetSiValue(Start, Start.Add(TimeStep)));
            }

            if (OverrideFlowRate.HasValue)
            {
                _currentFlowRate = OverrideFlowRate.Value;
            }
            else if (TS != null)
            {
                _currentFlowRate = TS.GetSiValue(Start, Start.Add(TimeStep));
            }

            double _routedFlow = _currentFlowRate * TimeStep.TotalSeconds;

            //Could be a point
            XYPolygon geom = ContactGeometry as XYPolygon;

            if (geom != null)
            {
                _routedFlow *= geom.GetArea();
            }

            return(WaterSample.DeepClone(_routedFlow));
        }
        public void PointSearchTest()
        {
            ElementSet elmtSet             = ReadMesh(@"..\..\Spatial\Data\oresund.mesh");
            XYElementSearchTree <int> tree = XYElementSearchTree <int> .BuildSearchTree(elmtSet);

            // Point in element 746 (has index 745)
            XYPoint           point           = new XYPoint(355273.227764, 6201136.0892);
            XYExtent          pointExtent     = XYExtentUtil.GetExtent(point);
            ICollection <int> pointCandidates = tree.FindElements(pointExtent);

            Assert.Contains(745, (ICollection)pointCandidates);
            XYPolygon elmt745 = ElementMapper.CreateFromXYPolygon(elmtSet, 745);

            Assert.IsTrue(XYGeometryTools.IsPointInPolygon(point.X, point.Y, elmt745));

            // Point in element 3583 (has index 3582)
            XYPoint           point2           = new XYPoint(354683.522377, 6167696.720773);
            XYExtent          point2Extent     = XYExtentUtil.GetExtent(point2);
            ICollection <int> point2Candidates = tree.FindElements(point2Extent);

            Assert.Contains(3582, (ICollection)point2Candidates);
            XYPolygon elmt3582 = ElementMapper.CreateFromXYPolygon(elmtSet, 3582);

            Assert.IsTrue(XYGeometryTools.IsPointInPolygon(point2.X, point2.Y, elmt3582));

            // Node 2001 is part of 7 elements
            XYPoint           pointNode2001           = new XYPoint(355451.29058143805, 6167084.759883712);
            XYExtent          pointNode2001Extent     = XYExtentUtil.GetExtent(pointNode2001);
            ICollection <int> pointNode2001Candidates = tree.FindElements(pointNode2001Extent);

            Assert.AreEqual(7, pointNode2001Candidates.Count);
        }
Beispiel #6
0
        public void GetPolygonsTest()
        {
            var m = new HydroNumerics.MikeSheTools.Core.Model(@"E:\dhi\data\dkm\dk2\result\DK2_v3_gvf_PT_100p_24hr.she");

            var precip = new HydroNumerics.MikeSheTools.DFS.DFS2(m.Input.MIKESHE_FLOWMODEL.Climate.PrecipitationRate.FULLY_DISTRIBUTED.DFS_2D_DATA_FILE.FILE_NAME);

            var actual = XYPolygon.GetPolygons(precip);

            System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.Add("ID", typeof(int));

            int k = 0;

            using (HydroNumerics.Geometry.Shapes.ShapeWriter sw = new Geometry.Shapes.ShapeWriter(@"d:\temp\out.shp"))
            {
                for (int i = 0; i < precip.NumberOfColumns; i++)
                {
                    for (int j = 0; j < precip.NumberOfRows; j++)
                    {
                        var drow = dt.NewRow();
                        drow[0] = k;
                        sw.Write(new GeoRefData()
                        {
                            Geometry = actual[i, j], Data = drow
                        });
                        k++;
                    }
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// 3D UZ !!!!
        /// Creates a dictionary with key equal to the model state index and the value the spatial information of that state index.
        /// </summary>
        /// <param name="gType">The geometric type of the exchange itme (2d or 3d)</param>
        /// <param name="baseOut">The exchange item base output</param>
        /// <param name="elementID">the string id of the exchange item.</param>
        /// <returns></returns>
        private IDictionary <int, ISpatialDefine> GetModelCoordinates3DUZ(GeometryTypes gType, IBaseOutput baseOut, string elementID)
        {
            IDictionary <int, ISpatialDefine> modelEntities = new Dictionary <int, ISpatialDefine>();
            int n;

            try
            {
                WMEngine.GetElementCount(elementID);
                n = baseOut.ElementSet().ElementCount;
            }
            catch
            {
                Console.WriteLine("\nElement {0} does not found in the model\n", elementID);
                throw new Exception("\nProblem in Model Instance - unable to find exchange item\n");
            }

            // Determines the number of layers in the UZ Grid.
            int numLayersInGrid = Convert.ToInt32(Math.Round((double)base.WMEngine.UzGrid.ElementCount / (double)base.WMEngine.UzGrid.BaseGrid.ElementCount));

            for (int i = 0; i < n; i++)
            {
                XYPolygon modelpolygon = ElementMapper.CreateXYPolygon(baseOut.ElementSet(), i);
                int       zLayer       = Convert.ToInt32(i % numLayersInGrid);

                // Points in Polygon are defined as LL, LR, UR, UL  (l/l = lower/left, u = upper, r = right )
                // Finds the mid x and mid y point in the polygon (assuming rectangular grid)
                IXYLayerPoint min = new XYLayerPoint(modelpolygon.GetX(0), modelpolygon.GetY(0), zLayer);
                IXYLayerPoint max = new XYLayerPoint(modelpolygon.GetX(1), modelpolygon.GetY(3), zLayer);

                modelEntities.Add(i, new SpatialDefine(min, max, GeometryTypes.Geometry3DUZ));
            }

            return(modelEntities);
        }
Beispiel #8
0
 public GroundWaterBoundary(IWaterBody connection, double hydraulicConductivity, double distance, double groundwaterHead, XYPolygon ContactPolygon) : this()
 {
     Connection            = connection;
     HydraulicConductivity = hydraulicConductivity;
     Distance        = distance;
     GroundwaterHead = groundwaterHead;
     ContactGeometry = ContactPolygon;
 }
Beispiel #9
0
        public void Protected_TriangleIntersectionArea()
        {
            XYPolygon t1 = new XYPolygon();

            t1.Points.Add(new XYPoint(0.0, 0.5));
            t1.Points.Add(new XYPoint(6.0, 0.5));
            t1.Points.Add(new XYPoint(1.0, 7.0));

            XYPolygon t2 = new XYPolygon();

            t2.Points.Add(new XYPoint(1, 1));
            t2.Points.Add(new XYPoint(5, 1));
            t2.Points.Add(new XYPoint(1, 5));

            XYPolygon t3 = new XYPolygon();

            t3.Points.Add(new XYPoint(1, 1));
            t3.Points.Add(new XYPoint(3, 1));
            t3.Points.Add(new XYPoint(1, 3));

            XYPolygon t4 = new XYPolygon();

            t4.Points.Add(new XYPoint(1, 2));
            t4.Points.Add(new XYPoint(3, 2));
            t4.Points.Add(new XYPoint(3, 4));

            XYPolygon t5 = new XYPolygon();

            t5.Points.Add(new XYPoint(6.5, 3.5));
            t5.Points.Add(new XYPoint(9.5, 3.4));
            t5.Points.Add(new XYPoint(7, 5));

            XYPolygon t6 = new XYPolygon();

            t6.Points.Add(new XYPoint(-2, 0));
            t6.Points.Add(new XYPoint(3, 0));
            t6.Points.Add(new XYPoint(3, 2));

            //t2 is fully inside t1
            Assert.AreEqual(8, AXYGeometryTools.ATriangleIntersectionArea(t2, t1), "t2, t1");
            Assert.AreEqual(8, AXYGeometryTools.ATriangleIntersectionArea(t1, t2), "t1, t2");

            // t4 is partly inside t2
            Assert.AreEqual((double)7 / (double)4, AXYGeometryTools.ATriangleIntersectionArea(t2, t4), "t2, t4");
            Assert.AreEqual((double)7 / (double)4, AXYGeometryTools.ATriangleIntersectionArea(t4, t2), "t4, t2");

            // t3 is inside t2 but is sharing two edges
            Assert.AreEqual(2, AXYGeometryTools.ATriangleIntersectionArea(t2, t3), "t2, t3");
            Assert.AreEqual(2, AXYGeometryTools.ATriangleIntersectionArea(t3, t2), "t3, t2");

            // t1 and t5 has no overlap
            Assert.AreEqual(0, AXYGeometryTools.ATriangleIntersectionArea(t1, t5), "t1, t5");
            Assert.AreEqual(0, AXYGeometryTools.ATriangleIntersectionArea(t5, t1), "t5, t1");

            // two times t6
            Assert.AreEqual(t6.GetArea(), AXYGeometryTools.ATriangleIntersectionArea(t6, t6), "t6, t6");
        }
Beispiel #10
0
        public SiteViewModel(GeoRefData Area, IWellCollection Wells)
        {
            area       = Area;
            site       = area.Geometry as XYPolygon;
            this.Wells = Wells;

            DisplayName = Area.Data[0].ToString();
            Samples     = new ObservableCollection <Sample>();
        }
Beispiel #11
0
        /// <summary>
        /// Use this constructor to create an empty lake. Should only be used for unit testing
        /// </summary>
        /// <param name="VolumeOfLakeWater"></param>
        public Lake(string name, double VolumeOfLakeWater) : base(name)
        {
            SurfaceArea = XYPolygon.GetSquare(VolumeOfLakeWater);
            Depth       = 1;

            //Only used in unit test. Otherwise it should be set through the state
            CurrentStoredWater = new WaterPacket(0);
            Initialize();
        }
        public void GetSourceWaterTest()
        {
            SinkSourceBoundary target = new SinkSourceBoundary(200);

            target.ContactGeometry = XYPolygon.GetSquare(1);

            IWaterPacket actual = target.GetSourceWater(DateTime.Now, new TimeSpan(1, 0, 0));

            Assert.AreEqual(200 * 3600, actual.Volume);
        }
Beispiel #13
0
        public static XYExtent GetExtent(XYPolygon polygon)
        {
            XYExtent res = new XYExtent();

            foreach (XYPoint point in polygon.Points)
            {
                res.Include(point.X, point.Y);
            }
            return(res);
        }
Beispiel #14
0
        public void ContainsTest()
        {
            XYPolygon target = XYPolygon.GetSquare(25);
            IXYPoint  p      = new XYPoint(3, 3);


            Assert.AreEqual(true, target.Contains(p));
            Assert.AreEqual(false, target.Contains(new XYPoint(3, 6)));
            Assert.IsTrue(target.Contains(new XYPoint(0.1, 0.1)));
        }
        public void GetSinkVolumesTest()
        {
            SinkSourceBoundary target = new SinkSourceBoundary(-200);

            target.ContactGeometry = XYPolygon.GetSquare(1);
            target.WaterSample     = new WaterPacket(1);

            double actual = target.GetSinkVolume(DateTime.Now, new TimeSpan(1, 0, 0));

            Assert.AreEqual(200 * 3600, actual, 0.000001);
        }
Beispiel #16
0
 public static bool IsPointInPolygon(double x, double y, XYPolygon polygon)
 {
     if (x > polygon.GetX(0) && x < polygon.GetX(1) &&
         y > polygon.GetY(0) && y < polygon.GetY(2))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #17
0
        public void EvaporationRateBoundaryTest()
        {
            EvaporationRateBoundary evp = new EvaporationRateBoundary(23);

            evp.ContactGeometry = XYPolygon.GetSquare(2);
            evp.Name            = "Test";
            EvaporationRateBoundary evp2 = (EvaporationRateBoundary)ReadWrite(evp);

            Assert.AreEqual(evp.Name, evp2.Name);
            Assert.AreEqual(((XYPolygon)evp.ContactGeometry).GetArea(), ((XYPolygon)evp.ContactGeometry).GetArea());
            Assert.AreEqual(evp.GetSinkVolume(DateTime.Now, TimeSpan.FromDays(1.5)), evp2.GetSinkVolume(DateTime.Now, TimeSpan.FromDays(1.5)));
        }
Beispiel #18
0
        public void GetTriangulation()
        {
            XYPolygon p1 = new XYPolygon();

            p1.Points.Add(new XYPoint(0, 3));
            p1.Points.Add(new XYPoint(3, 0));
            p1.Points.Add(new XYPoint(8, 0));
            p1.Points.Add(new XYPoint(8, 2));
            p1.Points.Add(new XYPoint(3, 1));
            p1.Points.Add(new XYPoint(3, 3));
            p1.Points.Add(new XYPoint(8, 3));
            p1.Points.Add(new XYPoint(4, 7));
            ArrayList triangleList = p1.GetTriangulation();
            XYPolygon refTriangle1 = new XYPolygon();

            refTriangle1.Points.Add(new XYPoint(3, 0));
            refTriangle1.Points.Add(new XYPoint(8, 0));
            refTriangle1.Points.Add(new XYPoint(8, 2));
            XYPolygon refTriangle2 = new XYPolygon();

            refTriangle2.Points.Add(new XYPoint(3, 0));
            refTriangle2.Points.Add(new XYPoint(8, 2));
            refTriangle2.Points.Add(new XYPoint(3, 1));
            XYPolygon refTriangle3 = new XYPolygon();

            refTriangle3.Points.Add(new XYPoint(0, 3));
            refTriangle3.Points.Add(new XYPoint(3, 0));
            refTriangle3.Points.Add(new XYPoint(3, 1));
            XYPolygon refTriangle4 = new XYPolygon();

            refTriangle4.Points.Add(new XYPoint(0, 3));
            refTriangle4.Points.Add(new XYPoint(3, 1));
            refTriangle4.Points.Add(new XYPoint(3, 3));
            XYPolygon refTriangle5 = new XYPolygon();

            refTriangle5.Points.Add(new XYPoint(4, 7));
            refTriangle5.Points.Add(new XYPoint(0, 3));
            refTriangle5.Points.Add(new XYPoint(3, 3));
            XYPolygon refTriangle6 = new XYPolygon();

            refTriangle6.Points.Add(new XYPoint(3, 3));
            refTriangle6.Points.Add(new XYPoint(8, 3));
            refTriangle6.Points.Add(new XYPoint(4, 7));
            Assert.AreEqual(refTriangle1, triangleList[0]);
            Assert.AreEqual(refTriangle2, triangleList[1]);
            Assert.AreEqual(refTriangle3, triangleList[2]);
            Assert.AreEqual(refTriangle4, triangleList[3]);
            Assert.AreEqual(refTriangle5, triangleList[4]);
            Assert.AreEqual(refTriangle6, triangleList[5]);
        }
Beispiel #19
0
        public void GroundwaterBoundaryTest()
        {
            Stream stream = new Stream("S", 1, 1, 1);

            stream.WaterLevel = 2;
            GroundWaterBoundary gwb = new GroundWaterBoundary(stream, 2, 4, 5, XYPolygon.GetSquare(23));

            gwb.WaterSample = new WaterPacket(1);

            GroundWaterBoundary gwb2 = (GroundWaterBoundary)ReadWrite(gwb);

            Assert.AreEqual(gwb.IsSource(DateTime.Now), gwb2.IsSource(DateTime.Now));
            WaterEquals(gwb.GetSourceWater(DateTime.Now, TimeSpan.FromDays(1)), gwb2.GetSourceWater(DateTime.Now, TimeSpan.FromDays(1)));
        }
Beispiel #20
0
        public void CalculateSharedArea()
        {
            XYPolygon p1 = new XYPolygon();

            p1.Points.Add(new XYPoint(0, 3));
            p1.Points.Add(new XYPoint(3, 0));
            p1.Points.Add(new XYPoint(8, 0));
            p1.Points.Add(new XYPoint(8, 2));
            p1.Points.Add(new XYPoint(3, 1));
            p1.Points.Add(new XYPoint(3, 3));
            p1.Points.Add(new XYPoint(8, 3));
            p1.Points.Add(new XYPoint(4, 7));

            XYPolygon p2 = new XYPolygon();

            p2.Points.Add(new XYPoint(3, 3));
            p2.Points.Add(new XYPoint(4, 3));
            p2.Points.Add(new XYPoint(4, 4));
            p2.Points.Add(new XYPoint(3, 4));

            XYPolygon p3 = new XYPolygon();

            p3.Points.Add(new XYPoint(0, 0));
            p3.Points.Add(new XYPoint(8, 0));
            p3.Points.Add(new XYPoint(8, 8));
            p3.Points.Add(new XYPoint(0, 8));

            XYPolygon p4 = new XYPolygon();

            p4.Points.Add(new XYPoint(-2, 0));
            p4.Points.Add(new XYPoint(3, 0));
            p4.Points.Add(new XYPoint(3, 2));
            p4.Points.Add(new XYPoint(0, 2));
            p4.Points.Add(new XYPoint(0, 5));
            p4.Points.Add(new XYPoint(4, 5));
            p4.Points.Add(new XYPoint(4, 7));
            p4.Points.Add(new XYPoint(-2, 7));

            Assert.AreEqual(p1.GetArea(), XYGeometryTools.CalculateSharedArea(p1, p1), 1e-12, "Test1 - Polygon1 in Polygon1");
            Assert.AreEqual(p2.GetArea(), XYGeometryTools.CalculateSharedArea(p2, p2), 1e-12, "Test2 - Polygon1 in Polygon1");
            Assert.AreEqual(p4.GetArea(), XYGeometryTools.CalculateSharedArea(p4, p4), 1e-12, "Test3 - Polygon1 in Polygon1");
            Assert.AreEqual(p2.GetArea(), XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12, "Test4 - Polygon2 in Polygon1");
            Assert.AreEqual(p1.GetArea(), XYGeometryTools.CalculateSharedArea(p1, p3), 1e-12, "Test5 - Polygon1 in Polygon2");
            Assert.AreEqual(4, XYGeometryTools.CalculateSharedArea(p1, p4), 1e-12, "Test6 - Polygon1 in Polygon3");
        }
Beispiel #21
0
        public void LakeTest()
        {
            Lake l = new Lake("L", 10000);

            l.ID = 3;

            GroundWaterBoundary gwb = new GroundWaterBoundary(l, 2, 4, 5, XYPolygon.GetSquare(23));

            gwb.WaterSample = new WaterPacket(1);
            l.GroundwaterBoundaries.Add(gwb);

            Lake l2 = (Lake)ReadWrite(l);

            Assert.AreEqual(l.Volume, l2.Volume);
            Assert.AreEqual(l.ID, l2.ID);
            Assert.AreEqual(l.Area, l2.Area);

            Assert.AreEqual(l.GroundwaterBoundaries.Count, l2.GroundwaterBoundaries.Count);
        }
Beispiel #22
0
        public void GetArea()
        {
            // -- Rectangle --
            XYPolygon xypolygon = new XYPolygon();

            xypolygon.Points.Add(new XYPoint(1, 1));
            xypolygon.Points.Add(new XYPoint(9, 1));
            xypolygon.Points.Add(new XYPoint(9, 6));
            xypolygon.Points.Add(new XYPoint(1, 6));
            Assert.AreEqual((double)40, xypolygon.GetArea());

            // -- Triangle --
            XYPolygon xypolygon2 = new XYPolygon();

            xypolygon2.Points.Add(new XYPoint(1, 1));
            xypolygon2.Points.Add(new XYPoint(9, 1));
            xypolygon2.Points.Add(new XYPoint(9, 6));
            Assert.AreEqual((double)20, xypolygon2.GetArea());

            // -- concave --
            XYPolygon xypolygon3 = new XYPolygon();

            xypolygon3.Points.Add(new XYPoint(1, 1));
            xypolygon3.Points.Add(new XYPoint(5, 3));
            xypolygon3.Points.Add(new XYPoint(9, 1));
            xypolygon3.Points.Add(new XYPoint(9, 6));
            xypolygon3.Points.Add(new XYPoint(1, 6));
            Assert.AreEqual((double)32, xypolygon3.GetArea());

            // -- concave --
            XYPolygon xypolygon4 = new XYPolygon();

            xypolygon4.Points.Add(new XYPoint(1, 1));
            xypolygon4.Points.Add(new XYPoint(9, 1));
            xypolygon4.Points.Add(new XYPoint(5, 5));
            xypolygon4.Points.Add(new XYPoint(5, 3));
            xypolygon4.Points.Add(new XYPoint(3, 3));
            xypolygon4.Points.Add(new XYPoint(3, 8));
            xypolygon4.Points.Add(new XYPoint(9, 8));
            xypolygon4.Points.Add(new XYPoint(9, 11));
            xypolygon4.Points.Add(new XYPoint(1, 11));
            Assert.AreEqual((double)50, xypolygon4.GetArea());
        }
Beispiel #23
0
        public void RoutingOfGroundwaterTest()
        {
            Lake S = new Lake("L", 100);

            S.SetState("Initial", DateTime.Now, new WaterPacket(100));

            Lake storage = new Lake("Storage", 10000);

            S.AddDownStreamWaterBody(storage);

            TimeSpan ts = new TimeSpan(1, 0, 0);

            int          Id       = 2;
            IWaterPacket expected = new WaterPacket(Id, 200);
            IWaterPacket actual;

            S.WaterLevel = 8;
            GroundWaterBoundary b = new GroundWaterBoundary(S, 0.001, 100, 10, XYPolygon.GetSquare(2.5));

            b.WaterSample = expected;
            S.GroundwaterBoundaries.Add(b);
            S.Update(S.CurrentTime.Add(ts));

            actual = storage.CurrentStoredWater;
            double ExpectedVolume = b.GetSourceWater(DateTime.Now, ts).Volume;

            Assert.AreEqual(expected.Composition.Keys.First(), actual.Composition.Keys.First());
            Assert.AreEqual(ExpectedVolume, actual.Volume, 0.000001);

            S.Update(S.CurrentTime.Add(new TimeSpan(2, 0, 0)));

            actual = storage.CurrentStoredWater;
            Assert.AreEqual(expected.Composition.Keys.First(), actual.Composition.Keys.First());
            Assert.AreEqual(0.54, actual.Volume, 0.000001);

            S.AddWaterPacket(DateTime.Now, DateTime.Now, expected);
            S.Update(S.CurrentTime.Add(new TimeSpan(2, 0, 0)));
            actual = storage.CurrentStoredWater;

            Assert.AreEqual(200.9, actual.Volume, 0.000001);
        }
Beispiel #24
0
        public void TestMethod1()
        {
            Lake L = new Lake("Deep lake", XYPolygon.GetSquare(10000));

            L.Depth = 4;
            L.Output.LogAllChemicals = true;

            Lake L2 = new Lake("Shallow lake", XYPolygon.GetSquare(40000));

            L2.Depth = 1;
            L2.Output.LogAllChemicals = true;

            SinkSourceBoundary flow = new SinkSourceBoundary(L.Volume / (15.0 * 86400.0));

            L.Sources.Add(flow);
            L2.Sources.Add(flow);

            Chemical    rn          = ChemicalFactory.Instance.GetChemical(ChemicalNames.Radon);
            Chemical    cl          = ChemicalFactory.Instance.GetChemical(ChemicalNames.Cl);
            WaterPacket groundwater = new WaterPacket(1);

            groundwater.SetConcentration(rn, 200);
            groundwater.SetConcentration(cl, 200);
            SinkSourceBoundary gwflow = new SinkSourceBoundary(L.Volume / (15.0 * 86400.0));

            gwflow.WaterSample = groundwater;

            L.Sources.Add(gwflow);
            L2.Sources.Add(gwflow);

            Model M = new Model();

            M.WaterBodies.Add(L);
            M.WaterBodies.Add(L2);

            DateTime start = new DateTime(2010, 1, 1);

            M.SetState("Initial", start, new WaterPacket(1));
            M.MoveInTime(new DateTime(2010, 12, 31), TimeSpan.FromDays(5));
            M.Save(@"..\..\..\TestData\Radon.xml");
        }
Beispiel #25
0
        public void Protected_IsPointInPolygonOrOnEdge()
        {
            XYPolygon p1 = new XYPolygon();

            p1.Points.Add(new XYPoint(0, 3));
            p1.Points.Add(new XYPoint(3, 0));
            p1.Points.Add(new XYPoint(8, 0));
            p1.Points.Add(new XYPoint(8, 2));
            p1.Points.Add(new XYPoint(3, 1));
            p1.Points.Add(new XYPoint(3, 3));
            p1.Points.Add(new XYPoint(8, 3));
            p1.Points.Add(new XYPoint(4, 7));
            Assert.AreEqual(true, AXYGeometryTools.AIsPointInPolygonOrOnEdge(0, 3, p1), "Test1");
            Assert.AreEqual(true, AXYGeometryTools.AIsPointInPolygonOrOnEdge(1, 3, p1), "Test2");
            Assert.AreEqual(false, AXYGeometryTools.AIsPointInPolygonOrOnEdge(1, 5, p1), "Test3");
            Assert.AreEqual(true, AXYGeometryTools.AIsPointInPolygonOrOnEdge(3, 2, p1), "Test4");
            Assert.AreEqual(true, AXYGeometryTools.AIsPointInPolygonOrOnEdge(3, 3, p1), "Test5");
            Assert.AreEqual(true, AXYGeometryTools.AIsPointInPolygonOrOnEdge(6, 1, p1), "Test6");
            Assert.AreEqual(false, AXYGeometryTools.AIsPointInPolygonOrOnEdge(6, 2, p1), "Test7");
            Assert.AreEqual(false, AXYGeometryTools.AIsPointInPolygonOrOnEdge(6, 7, p1), "Test8");
        }
Beispiel #26
0
        public void ContainsTest()
        {
            XYPolygon inner = new XYPolygon();

            inner.Points.Add(new XYPoint(0, 0));
            inner.Points.Add(new XYPoint(0, 1));
            inner.Points.Add(new XYPoint(1, 1));
            inner.Points.Add(new XYPoint(1, 0));

            Assert.IsTrue(inner.Contains(0.5, 0.5));

            Assert.IsTrue(0 > inner.GetArea());

            XYPolygon outer = new XYPolygon();

            outer.Points.Add(new XYPoint(0, 0));
            outer.Points.Add(new XYPoint(1, 0));
            outer.Points.Add(new XYPoint(1, 1));
            outer.Points.Add(new XYPoint(0, 1));
            Assert.IsTrue(outer.Contains(0.5, 0.5));

            Assert.IsTrue(0 < outer.GetArea());
        }
Beispiel #27
0
        public void RoutingOfGroundwaterTest()
        {
            Stream S = new Stream("S", 100, 1, 1);

            S.SetState("Initial", DateTime.Now, new WaterPacket(100));

            TimeSpan ts = new TimeSpan(0, 1, 0);

            int          Id       = 2;
            IWaterPacket expected = new WaterPacket(Id, 200);
            IWaterPacket actual;

            S.WaterLevel = 8;
            GroundWaterBoundary b = new GroundWaterBoundary(S, 0.001, 10, 100, XYPolygon.GetSquare(250));

            b.WaterSample = expected;
            S.GroundwaterBoundaries.Add(b);
            S.Update(S.CurrentTime.Add(ts));

            actual = S.CurrentStoredWater;
            double ExpectedVolume = b.GetSourceWater(DateTime.Now, ts).Volume;

            Assert.AreEqual(expected.Composition.Keys.First(), actual.Composition.Keys.First());
            Assert.AreEqual(100, actual.Volume, 0.000001);

            S.Update(S.CurrentTime.Add(ts));

            actual = S.CurrentStoredWater;
            Assert.AreEqual(expected.Composition.Keys.First(), actual.Composition.Keys.First());
            Assert.AreEqual(100, actual.Volume, 0.000001);

            S.AddWaterPacket(DateTime.Now, DateTime.Now, expected);
            S.Update(S.CurrentTime.Add(ts));
            actual = S.CurrentStoredWater;

            Assert.AreEqual(100, actual.Volume, 0.000001);
        }
Beispiel #28
0
        public void GetLine()
        {
            // -- Triangle --
            XYPolygon xypolygon = new XYPolygon();

            xypolygon.Points.Add(new XYPoint(1, 2));
            xypolygon.Points.Add(new XYPoint(4, 3));
            xypolygon.Points.Add(new XYPoint(2, 5));

            Assert.AreEqual(new XYLine(1, 2, 4, 3), xypolygon.GetLine(0));
            Assert.AreEqual(new XYLine(4, 3, 2, 5), xypolygon.GetLine(1));
            Assert.AreEqual(new XYLine(2, 5, 1, 2), xypolygon.GetLine(2));


            // -- concave polygon --
            XYPolygon xypolygon4 = new XYPolygon();

            xypolygon4.Points.Add(new XYPoint(1, 1));
            xypolygon4.Points.Add(new XYPoint(9, 1));
            xypolygon4.Points.Add(new XYPoint(5, 5));
            xypolygon4.Points.Add(new XYPoint(5, 3));
            xypolygon4.Points.Add(new XYPoint(3, 3));
            xypolygon4.Points.Add(new XYPoint(3, 8));
            xypolygon4.Points.Add(new XYPoint(9, 8));
            xypolygon4.Points.Add(new XYPoint(9, 11));
            xypolygon4.Points.Add(new XYPoint(1, 11));

            Assert.AreEqual(new XYLine(1, 1, 9, 1), xypolygon4.GetLine(0));
            Assert.AreEqual(new XYLine(9, 1, 5, 5), xypolygon4.GetLine(1));
            Assert.AreEqual(new XYLine(5, 5, 5, 3), xypolygon4.GetLine(2));
            Assert.AreEqual(new XYLine(5, 3, 3, 3), xypolygon4.GetLine(3));
            Assert.AreEqual(new XYLine(3, 3, 3, 8), xypolygon4.GetLine(4));
            Assert.AreEqual(new XYLine(3, 8, 9, 8), xypolygon4.GetLine(5));
            Assert.AreEqual(new XYLine(9, 8, 9, 11), xypolygon4.GetLine(6));
            Assert.AreEqual(new XYLine(9, 11, 1, 11), xypolygon4.GetLine(7));
            Assert.AreEqual(new XYLine(1, 11, 1, 1), xypolygon4.GetLine(8));
        }
Beispiel #29
0
        /// <summary>
        /// 3D SZ !!!!
        /// Creates a dictionary with key equal to the model state index and the value the spatial information of that state index.
        /// </summary>
        /// <param name="gType">The geometric type of the exchange itme (2d or 3d)</param>
        /// <param name="baseOut">The exchange item base output</param>
        /// <param name="elementID">the string id of the exchange item.</param>
        /// <returns></returns>
        private IDictionary <int, ISpatialDefine> GetModelCoordinates3DSZ(GeometryTypes gType, IBaseOutput baseOut, string elementID)
        {
            //Run Only once - because it's slow
            if (_modelEntities == null)
            {
                _modelEntities = new Dictionary <int, ISpatialDefine>();
                int n;

                try
                {
                    WMEngine.GetElementCount(elementID);
                    n = baseOut.ElementSet().ElementCount;
                }
                catch
                {
                    Console.WriteLine("\nElement {0} does not found in the model\n", elementID);
                    throw new Exception("\nProblem in Model Instance - unable to find exchange item\n");
                }

                //int numBaseGrid = Convert.ToInt32(Math.Floor((double)n / (double)_mshe.WMEngine.NumberOfSZLayers));

                for (int i = 0; i < n; i++)
                {
                    XYPolygon modelpolygon = ElementMapper.CreateXYPolygon(baseOut.ElementSet(), i);
                    int       zLayer       = Convert.ToInt32(i % base.WMEngine.NumberOfSZLayers);

                    // Points in Polygon are defined as LL, LR, UR, UL  (l/l = lower/left, u = upper, r = right )
                    // Finds the mid x and mid y point in the polygon (assuming rectangular grid)
                    IXYLayerPoint min = new XYLayerPoint(modelpolygon.GetX(0), modelpolygon.GetY(0), zLayer);
                    IXYLayerPoint max = new XYLayerPoint(modelpolygon.GetX(1), modelpolygon.GetY(3), zLayer);

                    _modelEntities.Add(i, new SpatialDefine(min, max, GeometryTypes.Geometry3DSZ));
                }
            }
            return(_modelEntities);
        }
Beispiel #30
0
        public void Protected_CalculateLengthOfLineInsidePolygon()
        {
            XYPolygon xypolygon = new XYPolygon();

            xypolygon.Points.Add(new XYPoint(1, 1));
            xypolygon.Points.Add(new XYPoint(9, 1));
            xypolygon.Points.Add(new XYPoint(5, 5));
            xypolygon.Points.Add(new XYPoint(5, 3));
            xypolygon.Points.Add(new XYPoint(3, 3));
            xypolygon.Points.Add(new XYPoint(3, 8));
            xypolygon.Points.Add(new XYPoint(9, 8));
            xypolygon.Points.Add(new XYPoint(9, 11));
            xypolygon.Points.Add(new XYPoint(1, 11));

            Assert.AreEqual(0, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 12, 11, 12), xypolygon), "Test1");
            Assert.AreEqual(4, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 11, 11, 11), xypolygon), "Test2");
            Assert.AreEqual(8, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 10, 11, 10), xypolygon), "Test3");
            Assert.AreEqual(8, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 9, 11, 9), xypolygon), "Test4");

            Assert.AreEqual(5, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 8, 11, 8), xypolygon), "Test5");
            Assert.AreEqual(2, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 7, 11, 7), xypolygon), "Test6");
            Assert.AreEqual(2, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 5, 11, 5), xypolygon), "Test7");
            Assert.AreEqual(3, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 4, 11, 4), xypolygon), "Test8");

            Assert.AreEqual(3, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 4, 11, 4), xypolygon), "Test9");
            Assert.AreEqual(5, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 3, 11, 3), xypolygon), "Test10");
            Assert.AreEqual(7, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 2, 11, 2), xypolygon), "Test11");
            Assert.AreEqual(4, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 1, 11, 1), xypolygon), "Test12");
            Assert.AreEqual(0, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 0, 11, 0), xypolygon), "Test13");

            Assert.AreEqual(10, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(2, 12, 2, 0), xypolygon), "Test14");
            Assert.AreEqual(6, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(6, 12, 6, 0), xypolygon), "Test15");
            Assert.AreEqual(Math.Sqrt(8) + 1.5 * Math.Sqrt(0.5), AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(1, 0.5, 10, 9.5), xypolygon), "Test16");
            Assert.AreEqual(1, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 4, 2, 4), xypolygon), "Test17");
            Assert.AreEqual(5, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(4, 12, 4, 0), xypolygon), "Test18");
        }