Ejemplo n.º 1
0
        public void WiggleNode()
        {
            int nodesPerDimension = 2;
            var rectangle         = GridShapes.Rectangle(2, 2);

            MultidimensionalArray nodes = MultidimensionalArray.Create(nodesPerDimension * nodesPerDimension, 2);

            for (int i = 0; i < nodesPerDimension; ++i)
            {
                for (int j = 0; j < nodesPerDimension; ++j)
                {
                    nodes[i * nodesPerDimension + j, 0] = 2.0 / (nodesPerDimension - 1) * i - 1.0;
                    nodes[i * nodesPerDimension + j, 1] = 2.0 / (nodesPerDimension - 1) * j - 1.0;
                }
            }

            int    wiggles   = 100;
            double range     = 1e-8;
            double increment = range / wiggles;

            nodes[0, 0] -= range / 2.0;

            for (int i = 0; i < wiggles + 1; ++i)
            {
                IGrid grid = VoronoiGrid2D.Polygonal(nodes, rectangle, 0, 0);
                nodes[0, 0] += increment;
            }

            //Plotter.Plot(grid);
        }
Ejemplo n.º 2
0
        public void Shift()
        {
            double offset = 1e-7;
            MultidimensionalArray nodes = MultidimensionalArray.Create(6, 2);

            nodes.SetRowPt(0, new Vector(0.5 + offset, 0.5));
            nodes.SetRowPt(1, new Vector(-0.5 + offset, 0.5));
            nodes.SetRowPt(2, new Vector(0.5 - offset, -0.5));
            nodes.SetRowPt(3, new Vector(-0.5 - offset, -0.5));
            nodes.SetRowPt(4, new Vector(0, -0.5));
            nodes.SetRowPt(5, new Vector(0, 0.5));

            // ### Grid
            byte[] tags = { 1, 181, 1, 181 };
            SortedList <byte, string> tagNames = new SortedList <byte, string>(2)
            {
                { 1, "AdiabaticSlipWall" },
                { 181, "Periodic-X" }
            };
            var gridBoundary = new VoronoiBoundary
            {
                Polygon      = GridShapes.Rectangle(2, 2),
                EdgeTags     = tags,
                EdgeTagNames = tagNames
            };

            VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0);
        }
Ejemplo n.º 3
0
        public void PeriodicPairCheckerBoard()
        {
            // ### Grid
            byte[] tags = { 1, 181, 1, 181 };
            SortedList <byte, string> tagNames = new SortedList <byte, string>(2)
            {
                { 1, "AdiabaticSlipWall" },
                { 181, "Periodic-X" }
            };
            var gridBoundary = new VoronoiBoundary
            {
                Polygon      = GridShapes.Rectangle(1, 0.5),
                EdgeTags     = tags,
                EdgeTagNames = tagNames
            };

            double[] xTics = GenericBlas.Linspace(-0.5, 0.5, 3);
            double[] yTics = GenericBlas.Linspace(-0.25, 0.25, 5);
            for (int i = 0; i < yTics.Length; ++i)
            {
                yTics[i] *= -1;
            }
            MultidimensionalArray nodes = Checkerize(xTics, yTics);

            VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0);

            Plotter.Plot(grid);
        }
Ejemplo n.º 4
0
        public void PeriodicPairSkewCheckerBoard()
        {
            byte[] tags = { 1, 181, 1, 181 };
            SortedList <byte, string> tagNames = new SortedList <byte, string>(2)
            {
                { 181, "Periodic-X" },
                { 1, "Dirichlet" }
            };

            VoronoiBoundary gridBoundary = new VoronoiBoundary
            {
                Polygon      = GridShapes.Rectangle(2, 2),
                EdgeTags     = tags,
                EdgeTagNames = tagNames
            };

            MultidimensionalArray nodes = MultidimensionalArray.Create(6, 2);

            nodes.SetRow(0, new double[] { -0.71, 0.7 });
            nodes.SetRow(1, new double[] { 0.8, 0.7 });
            nodes.SetRow(2, new double[] { 0, 0.5 });
            nodes.SetRow(3, new double[] { -0.7, -0.7 });
            nodes.SetRow(4, new double[] { 0.7, -0.7 });
            nodes.SetRow(5, new double[] { 0, -0.5 });

            VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0);
        }
Ejemplo n.º 5
0
        public void AllPeriodicBoundariesOutside()
        {
            byte[] tags = { 182, 181, 182, 181 };
            SortedList <byte, string> tagNames = new SortedList <byte, string>(2)
            {
                { 181, "Periodic-X" },
                { 182, "Periodic-Y" }
            };

            VoronoiBoundary gridBoundary = new VoronoiBoundary
            {
                Polygon      = GridShapes.Rectangle(2, 2),
                EdgeTags     = tags,
                EdgeTagNames = tagNames
            };

            MultidimensionalArray nodes = MultidimensionalArray.Create(6, 2);

            nodes.SetRow(0, new double[] { -1.1, 1.1 });
            nodes.SetRow(1, new double[] { 0.6, 1.4 });
            nodes.SetRow(2, new double[] { 0, 0 });
            nodes.SetRow(3, new double[] { 1, -0.9 });
            nodes.SetRow(4, new double[] { -0.9, -1.2 });
            nodes.SetRow(5, new double[] { -1.1, 0.2 });

            VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 10, 0);
        }
Ejemplo n.º 6
0
        public void LShapePeriodicBoundaries()
        {
            byte[] tags = { 1, 1, 181, 1, 1, 181 };
            SortedList <byte, string> tagNames = new SortedList <byte, string>(2)
            {
                { 1, "Dirichlet" },
                { 181, "Periodic" }
            };

            MultidimensionalArray nodes = MultidimensionalArray.Create(6, 2);

            nodes.SetRow(0, new double[] { -0.5, 0.5 });
            nodes.SetRow(1, new double[] { -0.8, -0.4 });
            nodes.SetRow(2, new double[] { 0, 0 });
            nodes.SetRow(3, new double[] { 0.8, 0.8 });
            nodes.SetRow(4, new double[] { 0.9, 0.2 });
            nodes.SetRow(5, new double[] { 0.5, -0.6 });

            VoronoiBoundary gridBoundary = new VoronoiBoundary
            {
                Polygon      = GridShapes.LShape(),
                EdgeTags     = tags,
                EdgeTagNames = tagNames
            };

            VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 1);
        }
Ejemplo n.º 7
0
        public void SetBoundaryTags()
        {
            byte[] tags = { 1, 1, 1, 1 };
            SortedList <byte, string> tagNames = new SortedList <byte, string>(1);

            tagNames.Add(1, "A");

            VoronoiBoundary rectangle = new VoronoiBoundary
            {
                Polygon      = GridShapes.Rectangle(2, 2),
                EdgeTags     = tags,
                EdgeTagNames = tagNames
            };

            MultidimensionalArray nodes = MultidimensionalArray.Create(5, 2);

            nodes.SetRow(0, new double[] { -0.5, 0.5 });
            nodes.SetRow(1, new double[] { -0.8, -0.4 });
            nodes.SetRow(2, new double[] { 0, 0 });
            nodes.SetRow(3, new double[] { 0.8, 0.4 });
            nodes.SetRow(4, new double[] { 0.5, -0.5 });

            VoronoiGrid grid           = VoronoiGrid2D.Polygonal(nodes, rectangle, 10, 0);
            bool        tagsAreCorrect = CheckAllBoundaryTagsAre(1, grid.iGridData);

            Assert.IsTrue(tagsAreCorrect);
        }
Ejemplo n.º 8
0
        public void Large()
        {
            var rectangle = GridShapes.Rectangle(2, 2);

            VoronoiGrid grid = VoronoiGrid2D.Polygonal(rectangle, 0, 10000);

            Plotter.Plot(grid);
        }
Ejemplo n.º 9
0
        public void CornerSpeziale()
        {
            MultidimensionalArray nodes1 = MultidimensionalArray.Create(3, 2);

            nodes1.SetRowPt(0, new Vector(-1, 1));
            nodes1.SetRowPt(1, new Vector(1, 1));
            nodes1.SetRowPt(2, new Vector(-1, -1));
            VoronoiGrid grid1 = VoronoiGrid2D.Polygonal(nodes1, GridShapes.Rectangle(2, 2), 0, 0);
        }
Ejemplo n.º 10
0
        public void SomeEdgesOnBoundary()
        {
            MultidimensionalArray nodes1 = MultidimensionalArray.Create(4, 2);

            nodes1.SetRowPt(0, new Vector(0, 2));
            nodes1.SetRowPt(1, new Vector(0, 0));
            nodes1.SetRowPt(2, new Vector(-1, 0));
            nodes1.SetRowPt(3, new Vector(-1, -1));
            VoronoiGrid grid1 = VoronoiGrid2D.Polygonal(nodes1, GridShapes.Rectangle(2, 2), 0, 0);
        }
Ejemplo n.º 11
0
        public void LShapedGrid()
        {
            var LShapePolygon = GridShapes.LShape();

            int[] NodeSeedsNumbers = { 20 };
            for (int i = 0; i < NodeSeedsNumbers.Length; ++i)
            {
                int   ammountOfNodeSeeds = NodeSeedsNumbers[i];
                IGrid grid = VoronoiGrid2D.Polygonal(LShapePolygon, 5, ammountOfNodeSeeds);
            }
        }
Ejemplo n.º 12
0
        public void FiveNodesInRectangle()
        {
            var rectangle = GridShapes.Rectangle(2, 2);
            MultidimensionalArray nodes = MultidimensionalArray.Create(5, 2);

            nodes.SetRow(0, new double[] { -0.5, 0.5 });
            nodes.SetRow(1, new double[] { -0.8, -0.4 });
            nodes.SetRow(2, new double[] { 0, 0 });
            nodes.SetRow(3, new double[] { 0.8, 0.4 });
            nodes.SetRow(4, new double[] { 0.5, -0.5 });

            IGrid grid = VoronoiGrid2D.Polygonal(nodes, rectangle, 10, 0);
        }
Ejemplo n.º 13
0
        public void OnlyEdgesOnBoundary()
        {
            MultidimensionalArray nodes1 = MultidimensionalArray.Create(8, 2);

            nodes1.SetRowPt(0, new Vector(0, 1.5));
            nodes1.SetRowPt(1, new Vector(-0.5, 0));
            nodes1.SetRowPt(2, new Vector(0, -0.5));
            nodes1.SetRowPt(3, new Vector(0.5, 0));
            nodes1.SetRowPt(4, new Vector(0, 0.5));
            nodes1.SetRowPt(5, new Vector(1.5, 0));
            nodes1.SetRowPt(6, new Vector(-1.5, 0));
            nodes1.SetRowPt(7, new Vector(0, -1.5));
            VoronoiGrid grid1 = VoronoiGrid2D.Polygonal(nodes1, GridShapes.Rectangle(2, 2), 0, 1);
        }
Ejemplo n.º 14
0
        public void Remap()
        {
            byte[] tags = { 1, 181, 1, 181 };
            SortedList <byte, string> tagNames = new SortedList <byte, string>(2)
            {
                { 181, "Periodic-X" },
                { 1, "bondary" }
            };

            VoronoiBoundary gridBoundary = new VoronoiBoundary
            {
                Polygon      = GridShapes.Rectangle(2, 2),
                EdgeTags     = tags,
                EdgeTagNames = tagNames
            };

            double[] positions = new double[]
            {
                -0.64874644688322713,
                0.83818004313993111,
                -0.39475947428553138,
                0.23663302374998896,
                0.58922918492853482,
                0.83854511946848365,
                -0.811382461267156,
                -0.4159610860057516,
                -0.19666215667077264,
                -0.24376388607043981,
                0.3385324063754323,
                0.086134041417832763,
                0.80498108279434089,
                0.22350558445791927,
                -0.68131747598283521,
                -0.87257764806623139,
                0.48863086193005234,
                -0.51183362983054159,
                0.99309783411349173,
                -0.10141430352239808,
            };
            MultidimensionalArray nodes = MultidimensionalArray.CreateWrapper(positions, 10, 2);

            for (int i = 0; i < 10; ++i)
            {
                nodes[i, 0] += 0.01;
            }

            VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0);

            Plotter.Plot(grid);
        }
Ejemplo n.º 15
0
        public void EquidistandGrid()
        {
            double offset = 1e-7;
            MultidimensionalArray nodes = MultidimensionalArray.Create(4, 2);

            nodes.SetRowPt(0, new Vector(0.5 + offset, 0.5));
            nodes.SetRowPt(1, new Vector(-0.5 + offset, 0.5));
            nodes.SetRowPt(2, new Vector(0.5, -0.5));
            nodes.SetRowPt(3, new Vector(-0.5, -0.5));

            VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, GridShapes.Rectangle(2, 2), 0, 1);

            Plotter.Plot(grid);
        }
Ejemplo n.º 16
0
        public void FShape()
        {
            byte[] tags = { 1, 181, 1, 1, 1, 182, 1, 1, 181, 1, 1, 182, 1, 1 };
            SortedList <byte, string> tagNames = new SortedList <byte, string>(2)
            {
                { 1, "Dirichlet" },
                { 181, "Periodic" }
            };

            VoronoiBoundary gridBoundary = new VoronoiBoundary
            {
                Polygon      = GridShapes.FShape(),
                EdgeTags     = tags,
                EdgeTagNames = tagNames
            };

            VoronoiGrid grid = VoronoiGrid2D.Polygonal(gridBoundary, 40, 500);
        }
Ejemplo n.º 17
0
        public void EquidistandGridLarge()
        {
            int nodesX    = 101;
            int nodesY    = 51;
            var rectangle = GridShapes.Rectangle(1, 0.5);

            MultidimensionalArray nodes = MultidimensionalArray.Create(nodesX * nodesY, 2);

            for (int i = 0; i < nodesX; ++i)
            {
                for (int j = 0; j < nodesY; ++j)
                {
                    nodes[i * nodesY + j, 0] = 1.0 / (nodesX - 1) * i - 0.5;
                    nodes[i * nodesY + j, 1] = 0.5 / (nodesY - 1) * j - 0.25;
                }
            }
            IGrid grid = VoronoiGrid2D.Polygonal(nodes, rectangle, 0, 0);
            //Plotter.Plot(grid);
        }
Ejemplo n.º 18
0
        public void VertexMerge()
        {
            var rectangle = GridShapes.Rectangle(3, 3);

            MultidimensionalArray nodes = MultidimensionalArray.Create(5, 2);

            nodes.SetRowPt(0, OnCircle(0));
            nodes.SetRowPt(1, OnCircle(0.5));
            nodes.SetRowPt(2, OnCircle(1));
            nodes.SetRowPt(3, OnCircle(2));
            nodes.SetRowPt(4, OnCircle(3));

            IGrid grid = VoronoiGrid2D.Polygonal(nodes, rectangle, 0, 0);

            Vector OnCircle(double radian)
            {
                return(new Vector(Math.Cos(radian), Math.Sin(radian)));
            }
        }
Ejemplo n.º 19
0
        public void MapMultipleCellsPeriodic()
        {
            byte[] tags = { 1, 181, 1, 181 };
            SortedList <byte, string> tagNames = new SortedList <byte, string>(2)
            {
                { 181, "Periodic-X" },
                { 1, "Dirichlet" }
            };
            VoronoiBoundary gridBoundary = new VoronoiBoundary
            {
                Polygon      = GridShapes.Rectangle(2, 2),
                EdgeTags     = tags,
                EdgeTagNames = tagNames,
                BoundingBox  = GridShapes.Rectangle(2, 2)
            };
            NodeTrackingVoronoiMesher mesher = new NodeTrackingVoronoiMesher(
                new VoronoiMesher <TrackableNode> .Settings()
            {
                Boundary = gridBoundary,
                NumberOfLloydIterations = 0,
            });
            int numberOfNodes           = 200;
            MultidimensionalArray array = MultidimensionalArray.Create(numberOfNodes, 2);
            Random random = new Random(0);

            for (int i = 0; i < numberOfNodes; ++i)
            {
                array[i, 0] = 2.0 * random.NextDouble() - 1.0;
                array[i, 1] = 2.0 * random.NextDouble() - 1.0;
            }
            VoronoiNodes      nodes  = new VoronoiNodes(array);
            MappedVoronoiGrid grid   = mesher.CreateGrid(nodes, 0);
            bool mapsNodesOntoItself = IsPermutation(grid.InputNodesToResultNodes, nodes, grid.Result.Nodes);

            Assert.IsTrue(mapsNodesOntoItself);
            MappedVoronoiGrid grid2 = mesher.CreateGrid(grid.Result.Nodes, 0);

            mapsNodesOntoItself = IsPermutation(grid2.InputNodesToResultNodes, grid.Result.Nodes, grid2.Result.Nodes);
            Assert.IsTrue(mapsNodesOntoItself);
        }
Ejemplo n.º 20
0
        public void MapOneCellPeriodic()
        {
            byte[] tags = { 1, 181, 1, 181 };
            SortedList <byte, string> tagNames = new SortedList <byte, string>(2)
            {
                { 181, "Periodic-X" },
                { 1, "Dirichlet" }
            };
            VoronoiBoundary gridBoundary = new VoronoiBoundary
            {
                Polygon      = GridShapes.Rectangle(2, 2),
                EdgeTags     = tags,
                EdgeTagNames = tagNames,
                BoundingBox  = GridShapes.Rectangle(2, 2),
            };
            NodeTrackingVoronoiMesher mesher = new NodeTrackingVoronoiMesher(
                new VoronoiMesher <TrackableNode> .Settings()
            {
                Boundary = gridBoundary,
                NumberOfLloydIterations = 0,
            });
            MultidimensionalArray array = MultidimensionalArray.Create(8, 2);

            array.SetRow(0, new double[] { -0.9, 0.7 });
            array.SetRow(1, new double[] { -0.8, -0.4 });
            array.SetRow(2, new double[] { 0, 0.5 });
            array.SetRow(3, new double[] { 0.05, 0 });
            array.SetRow(4, new double[] { 0.1, -0.5 });
            array.SetRow(5, new double[] { 0.8, 0.8 });
            array.SetRow(6, new double[] { 1.2, 0.2 });
            array.SetRow(7, new double[] { 0.5, -0.6 });

            VoronoiNodes      nodes = new VoronoiNodes(array);
            MappedVoronoiGrid grid  = mesher.CreateGrid(nodes, 0);

            Assert.IsTrue((
                              grid.Result.Nodes.Nodes[grid.InputNodesToResultNodes.GetMapping(0)].Position
                              - new Vector(-0.9, 0.7)).Abs() < 1e-12);
        }
Ejemplo n.º 21
0
        public void PeriodicBoundaryPairBoundaryOnEdge()
        {
            byte[] tags = { 1, 181, 1, 181 };
            SortedList <byte, string> tagNames = new SortedList <byte, string>(2)
            {
                { 181, "Periodic-X" },
                { 1, "Dirichlet" }
            };
            MultidimensionalArray nodes = MultidimensionalArray.Create(6, 2);

            nodes.SetRowPt(0, new Vector(-0.8, 0.6));
            nodes.SetRowPt(1, new Vector(-0.8, -0.6));
            nodes.SetRowPt(2, new Vector(-0.2, 0.0));
            nodes.SetRowPt(3, new Vector(0.2, 0.0));
            nodes.SetRowPt(4, new Vector(0.8, 0.6));
            nodes.SetRowPt(5, new Vector(0.8, -0.6));
            VoronoiBoundary gridBoundary = new VoronoiBoundary
            {
                Polygon      = GridShapes.Rectangle(2, 2),
                EdgeTags     = tags,
                EdgeTagNames = tagNames
            };
            VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0);
        }
Ejemplo n.º 22
0
        public void PeriodicBoundaryPairLarge()
        {
            byte[] tags = { 1, 181, 1, 181 };
            SortedList <byte, string> tagNames = new SortedList <byte, string>(2)
            {
                { 181, "Periodic-X" },
                { 1, "Dirichlet" }
            };
            VoronoiBoundary gridBoundary = new VoronoiBoundary
            {
                Polygon      = GridShapes.Rectangle(8, 8),
                EdgeTags     = tags,
                EdgeTagNames = tagNames
            };

            Random random = new Random(10);
            MultidimensionalArray nodes = default(MultidimensionalArray);

            for (int i = 0; i < 10; i += 1)
            {
                Console.WriteLine($"Roll number{i}");
                nodes       = RandomNodesInSquare(4.09, 4.0, 300, random);
                nodes[0, 0] = -1 + 1e-5;
                nodes[0, 1] = 1 - 1e-5;
                try
                {
                    VoronoiGrid garid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            //VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0);
            //Plotter.Plot(grid);
        }
Ejemplo n.º 23
0
        public void AllPeriodicBoundariesLarge()
        {
            byte[] tags = { 182, 181, 182, 181 };
            SortedList <byte, string> tagNames = new SortedList <byte, string>(2)
            {
                { 181, "Periodic-X" },
                { 182, "Periodic-Y" }
            };

            VoronoiBoundary gridBoundary = new VoronoiBoundary
            {
                Polygon      = GridShapes.Rectangle(2, 2),
                EdgeTags     = tags,
                EdgeTagNames = tagNames
            };
            Random random = new Random(1);
            MultidimensionalArray nodes = default(MultidimensionalArray);

            for (int i = 0; i < 48; ++i)
            {
                Console.WriteLine($"Roll number {i}");
                nodes       = RandomNodesInSquare(1.0, 1.0, 300, random);
                nodes[0, 0] = -1 + 1e-6;
                nodes[0, 1] = 1 - 1e-6;
                try
                {
                    //VoronoiGrid garid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0);
                    //Plotter.Plot(grid);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0);
        }