Пример #1
0
        private static void Main(string[] args)
        {
            Gmsh.Initialize();
            Gmsh.Option.SetNumber("General.Terminal", 1);
            Gmsh.Model.Add("t1");
            var lc = 1E-2;

            geo.AddPoint(0, 0, 0, lc, 1);
            geo.AddPoint(0.1, 0, 0, lc, 2);
            geo.AddPoint(0.1, 0.3, 0, lc, 3);
            var p4 = geo.AddPoint(0, 0.3, 0, lc);

            geo.AddLine(1, 2, 1);
            geo.AddLine(3, 2, 2);
            geo.AddLine(3, p4, 3);
            geo.AddLine(4, 1, p4);

            geo.AddCurveLoop(new int[] { 4, 1, -2, 3 }, 1);
            geo.AddPlaneSurface(new int[] { 1 }, 1);
            Gmsh.Model.AddPhysicalGroup(1, new int[] { 1, 2, 4 }, 5);
            var ps = Gmsh.Model.AddPhysicalGroup(2, new int[] { 1 });

            Gmsh.Model.SetPhysicalName(2, ps, "My surface");
            geo.Synchronize();
            Gmsh.Model.Mesh.Generate(2);

            Gmsh.Write("t1.msh");
            Gmsh.Finalize();
        }
Пример #2
0
        private static void Main(string[] args)
        {
            Gmsh.Initialize();
            Gmsh.Option.SetNumber("General.Terminal", 1);

            Gmsh.Model.Add("t17");

            Gmsh.Model.Occ.AddRectangle(-1, -1, 0, 2, 2);
            Gmsh.Model.Occ.Synchronize();

            try
            {
                Gmsh.Merge("t17_bgmesh.pos");
            }
            catch
            {
                Gmsh.Logger.Write("Could not load background mesh: bye!");
                Gmsh.Finalize();
                return;
            }
            int bg_field = Gmsh.Model.Mesh.Field.Add("PostView");

            Gmsh.Model.Mesh.Field.SetAsBackgroundMesh(bg_field);

            Gmsh.Option.SetNumber("Mesh.SmoothRatio", 3);
            Gmsh.Option.SetNumber("Mesh.AnisoMax", 1000);
            Gmsh.Option.SetNumber("Mesh.Algorithm", 7);

            Gmsh.Model.Mesh.Generate(2);
            Gmsh.Write("t17.msh");
            Gmsh.Finalize();
        }
Пример #3
0
        private static void Main(string[] args)
        {
            Gmsh.Initialize();
            Gmsh.Option.SetNumber("General.Terminal", 1);
            Gmsh.Model.Add("t10");

            double lc = .15;

            geo.AddPoint(0.0, 0.0, 0, lc, 1);
            geo.AddPoint(1, 0.0, 0, lc, 2);
            geo.AddPoint(1, 1, 0, lc, 3);
            geo.AddPoint(0, 1, 0, lc, 4);
            geo.AddPoint(0.2, .5, 0, lc, 5);

            geo.AddLine(1, 2, 1);
            geo.AddLine(2, 3, 2);
            geo.AddLine(3, 4, 3);
            geo.AddLine(4, 1, 4);

            geo.AddCurveLoop(new[] { 1, 2, 3, 4 }, 5);
            geo.AddPlaneSurface(new[] { 5 }, 6);

            geo.Synchronize();

            f.Add("Distance", 1);
            f.SetNumbers(1, "NodesList", new[] { 5.0 });
            f.SetNumber(1, "NNodesByEdge", 100);
            f.SetNumbers(1, "EdgesList", new[] { 2.0 });

            f.Add("Threshold", 2);
            f.SetNumber(2, "IField", 1);
            f.SetNumber(2, "LcMin", lc / 30);
            f.SetNumber(2, "LcMax", lc);
            f.SetNumber(2, "DistMin", 0.15);
            f.SetNumber(2, "DistMax", 0.5);

            f.Add("Min", 7);
            f.SetNumbers(7, "FieldsList", new[] { 2.0, 3, 5, 6 });

            f.SetAsBackgroundMesh(7);

            opt.SetNumber("Mesh.CharacteristicLengthExtendFromBoundary", 0);
            opt.SetNumber("Mesh.CharacteristicLengthFromPoints", 0);
            opt.SetNumber("Mesh.CharacteristicLengthFromCurvature", 0);

            Gmsh.Model.Mesh.Generate(2);
            Gmsh.Write("t10.msh");
            Gmsh.Finalize();
        }
Пример #4
0
        private static void Main(string[] args)
        {
            Gmsh.Initialize();
            Gmsh.Option.SetNumber("General.Terminal", 1);
            Gmsh.Model.Add("t12");

            double lc = 0.1;

            geo.AddPoint(0, 0, 0, lc, 1);
            geo.AddPoint(1, 0, 0, lc, 2);
            geo.AddPoint(1, 1, 0.5, lc, 3);
            geo.AddPoint(0, 1, 0.4, lc, 4);
            geo.AddPoint(0.3, 0.2, 0, lc, 5);
            geo.AddPoint(0, 0.01, 0.01, lc, 6);
            geo.AddPoint(0, 0.02, 0.02, lc, 7);
            geo.AddPoint(1, 0.05, 0.02, lc, 8);
            geo.AddPoint(1, 0.32, 0.02, lc, 9);

            geo.AddLine(1, 2, 1);
            geo.AddLine(2, 8, 2);
            geo.AddLine(8, 9, 3);
            geo.AddLine(9, 3, 4);
            geo.AddLine(3, 4, 5);
            geo.AddLine(4, 7, 6);
            geo.AddLine(7, 6, 7);
            geo.AddLine(6, 1, 8);
            geo.AddSpline(new[] { 7, 5, 9 }, 9);
            geo.AddLine(6, 8, 10);

            geo.AddCurveLoop(new[] { 5, 6, 9, 4 }, 11);
            geo.AddSurfaceFilling(new[] { 11 }, 1);

            geo.AddCurveLoop(new[] { -9, 3, 10, 7 }, 13);
            geo.AddSurfaceFilling(new[] { 13 }, 5);

            geo.AddCurveLoop(new[] { -10, 2, 1, 8 }, 15);
            geo.AddSurfaceFilling(new[] { 15 }, 10);

            geo.Synchronize();

            Gmsh.Model.Mesh.SetCompound(1, new[] { 2, 3, 4 });
            Gmsh.Model.Mesh.SetCompound(1, new[] { 6, 7, 8 });
            Gmsh.Model.Mesh.SetCompound(2, new[] { 1, 5, 10 });
            Gmsh.Model.Mesh.Generate(2);
            Gmsh.Write("t12.msh");
            Gmsh.Finalize();
        }
Пример #5
0
        private static void Main(string[] args)
        {
            Gmsh.Initialize();
            Gmsh.Option.SetNumber("General.Terminal", 1);
            try
            {
                Gmsh.Merge("t7_bgmesh.pos");
            }
            catch
            {
                Gmsh.Logger.Write("Could not load background mesh: bye!");
                Gmsh.Finalize();
                return;
            }

            Gmsh.Model.Add("t7");

            double lc = 1e-2;

            geo.AddPoint(0, 0, 0, lc, 1);
            geo.AddPoint(.1, 0, 0, lc, 2);
            geo.AddPoint(.1, .3, 0, lc, 3);
            geo.AddPoint(0, .3, 0, lc, 4);
            geo.AddLine(1, 2, 1);
            geo.AddLine(3, 2, 2);
            geo.AddLine(3, 4, 3);
            geo.AddLine(4, 1, 4);
            geo.AddCurveLoop(new[] { 4, 1, -2, 3 }, 1);
            geo.AddPlaneSurface(new[] { 1 }, 1);
            geo.Synchronize();

            int bg_field = Gmsh.Model.Mesh.Field.Add("PostView");

            Gmsh.Model.Mesh.Field.SetAsBackgroundMesh(bg_field);

            Gmsh.Option.SetNumber("Mesh.CharacteristicLengthExtendFromBoundary", 0);
            Gmsh.Option.SetNumber("Mesh.CharacteristicLengthFromPoints", 0);
            Gmsh.Option.SetNumber("Mesh.CharacteristicLengthFromCurvature", 0);

            Gmsh.Model.Mesh.Generate(2);
            Gmsh.Write("t7.msh");
            Gmsh.Finalize();
        }
Пример #6
0
        private static void Main(string[] args)
        {
            Gmsh.Initialize();
            Gmsh.Option.SetNumber("General.Terminal", 1);
            double lcar1 = .1;
            double lcar2 = .0005;
            double lcar3 = .055;

            geo.AddPoint(0.5, 0.5, 0.5, lcar2, 1);
            geo.AddPoint(0.5, 0.5, 0, lcar1, 2);
            geo.AddPoint(0, 0.5, 0.5, lcar1, 3);
            geo.AddPoint(0, 0, 0.5, lcar1, 4);
            geo.AddPoint(0.5, 0, 0.5, lcar1, 5);
            geo.AddPoint(0.5, 0, 0, lcar1, 6);
            geo.AddPoint(0, 0.5, 0, lcar1, 7);
            geo.AddPoint(0, 1, 0, lcar1, 8);
            geo.AddPoint(1, 1, 0, lcar1, 9);
            geo.AddPoint(0, 0, 1, lcar1, 10);
            geo.AddPoint(0, 1, 1, lcar1, 11);
            geo.AddPoint(1, 1, 1, lcar1, 12);
            geo.AddPoint(1, 0, 1, lcar1, 13);
            geo.AddPoint(1, 0, 0, lcar1, 14);

            geo.AddLine(8, 9, 1);
            geo.AddLine(9, 12, 2);
            geo.AddLine(12, 11, 3);
            geo.AddLine(11, 8, 4);
            geo.AddLine(9, 14, 5);
            geo.AddLine(14, 13, 6);
            geo.AddLine(13, 12, 7);
            geo.AddLine(11, 10, 8);
            geo.AddLine(10, 13, 9);
            geo.AddLine(10, 4, 10);
            geo.AddLine(4, 5, 11);
            geo.AddLine(5, 6, 12);
            geo.AddLine(6, 2, 13);
            geo.AddLine(2, 1, 14);
            geo.AddLine(1, 3, 15);
            geo.AddLine(3, 7, 16);
            geo.AddLine(7, 2, 17);
            geo.AddLine(3, 4, 18);
            geo.AddLine(5, 1, 19);
            geo.AddLine(7, 8, 20);
            geo.AddLine(6, 14, 21);

            geo.AddCurveLoop(new[] { -11, -19, -15, -18 }, 22);
            geo.AddPlaneSurface(new[] { 22 }, 23);
            geo.AddCurveLoop(new[] { 16, 17, 14, 15 }, 24);
            geo.AddPlaneSurface(new[] { 24 }, 25);
            geo.AddCurveLoop(new[] { -17, 20, 1, 5, -21, 13 }, 26);
            geo.AddPlaneSurface(new[] { 26 }, 27);
            geo.AddCurveLoop(new[] { -4, -1, -2, -3 }, 28);
            geo.AddPlaneSurface(new[] { 28 }, 29);
            geo.AddCurveLoop(new[] { -7, 2, -5, -6 }, 30);
            geo.AddPlaneSurface(new[] { 30 }, 31);
            geo.AddCurveLoop(new[] { 6, -9, 10, 11, 12, 21 }, 32);
            geo.AddPlaneSurface(new[] { 32 }, 33);
            geo.AddCurveLoop(new[] { 7, 3, 8, 9 }, 34);
            geo.AddPlaneSurface(new[] { 34 }, 35);
            geo.AddCurveLoop(new[] { -10, 18, -16, -20, 4, -8 }, 36);
            geo.AddPlaneSurface(new[] { 36 }, 37);
            geo.AddCurveLoop(new[] { -14, -13, -12, 19 }, 38);
            geo.AddPlaneSurface(new[] { 38 }, 39);

            List <int> shells  = new List <int>();
            List <int> volumes = new List <int>();
            int        sl      = geo.AddSurfaceLoop(new[] { 35, 31, 29, 37, 33, 23, 39, 25, 27 });

            shells.Add(sl);
            // We create five holes in the cube:
            double x = 0, y = 0.75, z = 0, r = 0.09;

            for (int t = 1; t <= 5; t++)
            {
                x += 0.166;
                z += 0.166;
                CheeseHole(x, y, z, r, lcar3, shells, volumes);
                Gmsh.Model.AddPhysicalGroup(3, new[] { volumes.Last() }, t);
                Console.WriteLine($"Hole {t} (center = {{{x},{y},{z}}}, radius = {r}) has number {volumes.Last()}!");
            }

            var ve = geo.AddVolume(shells.ToArray());

            Gmsh.Model.AddPhysicalGroup(3, new[] { ve }, 10);
            geo.Synchronize();
            Gmsh.Option.SetNumber("Mesh.Algorithm", 6);
            Gmsh.Model.Mesh.SetAlgorithm(2, 33, 1);
            Gmsh.Model.Mesh.Generate(3);
            Gmsh.Write("t5.msh");
            Gmsh.Finalize();
        }
Пример #7
0
        private static void Main(string[] args)
        {
            Gmsh.Initialize();
            Gmsh.Option.SetNumber("General.Terminal", 1);
            Gmsh.Model.Add("x2");

            long N   = 100;
            var  tag = new Func <long, long, long>((i, j) => (N + 1) * i + j + 1);

            var nodes  = new List <long>();
            var tris   = new List <long>();
            var lin    = new List <long> [4];
            var coords = new List <double>();
            var pnt    = new[] { tag(0, 0), tag(N, 0), tag(N, N), tag(0, N) };

            for (int i = 0; i < N + 1; i++)
            {
                for (int j = 0; j < N + 1; j++)
                {
                    nodes.Add(tag(i, j));
                    coords.AddRange(new[] { (double)i / N, (double)j / N,
                                            0.05 * Math.Sin(10 * (double)(i + j) / N) });
                    if (i > 0 && j > 0)
                    {
                        tris.AddRange(new[] { tag(i - 1, j - 1), tag(i, j - 1), tag(i - 1, j) });
                        tris.AddRange(new[] { tag(i, j - 1), tag(i, j), tag(i - 1, j) });
                    }
                    if ((i == 0 || i == N) && j > 0)
                    {
                        var s = i == 0 ? 3 : 1;
                        lin[s] = new List <long>(new[] { tag(i, j - 1), tag(i, j) });
                    }
                    if ((j == 0 || j == N) && i > 0)
                    {
                        var s = (j == 0) ? 0 : 2;
                        lin[s] = new List <long>(new[] { tag(i - 1, j), tag(i, j) });
                    }
                }
            }
            for (int i = 0; i < 4; i++)
            {
                Gmsh.Model.AddDiscreteEntity(0, i + 1);
            }
            Gmsh.Model.SetCoordinates(1, 0, 0, coords[Convert.ToInt32(3 * tag(0, 0) - 1)]);
            Gmsh.Model.SetCoordinates(2, 1, 0, coords[Convert.ToInt32(3 * tag(N, 0) - 1)]);
            Gmsh.Model.SetCoordinates(3, 1, 1, coords[Convert.ToInt32(3 * tag(N, N) - 1)]);
            Gmsh.Model.SetCoordinates(4, 0, 1, coords[Convert.ToInt32(3 * tag(0, N) - 1)]);

            for (int i = 0; i < 4; i++)
            {
                Gmsh.Model.AddDiscreteEntity(1, i + 1, new[] { i + 1, (i < 3) ? (i + 2) : 1 });
            }
            Gmsh.Model.AddDiscreteEntity(2, 1, new[] { 1, 2, -3, -4 });

            Gmsh.Model.Mesh.AddNodes(2, 1, nodes.ToArray(), coords.ToArray());

            for (int i = 0; i < 4; i++)
            {
                Gmsh.Model.Mesh.AddElementsByType(i + 1, 15, new long[] { }, new long[] { pnt[i] });
                Gmsh.Model.Mesh.AddElementsByType(i + 1, 1, new long[] { }, lin[i].ToArray());
            }
            Gmsh.Model.Mesh.AddElementsByType(1, 2, new long[] { }, tris.ToArray());
            Gmsh.Model.Mesh.ReclassifyNodes();
            Gmsh.Model.Mesh.CreateGeometry();

            int p1  = Gmsh.Model.Geo.AddPoint(0, 0, -0.5);
            int p2  = Gmsh.Model.Geo.AddPoint(1, 0, -0.5);
            int p3  = Gmsh.Model.Geo.AddPoint(1, 1, -0.5);
            int p4  = Gmsh.Model.Geo.AddPoint(0, 1, -0.5);
            int c1  = Gmsh.Model.Geo.AddLine(p1, p2);
            int c2  = Gmsh.Model.Geo.AddLine(p2, p3);
            int c3  = Gmsh.Model.Geo.AddLine(p3, p4);
            int c4  = Gmsh.Model.Geo.AddLine(p4, p1);
            int c10 = Gmsh.Model.Geo.AddLine(p1, 1);
            int c11 = Gmsh.Model.Geo.AddLine(p2, 2);
            int c12 = Gmsh.Model.Geo.AddLine(p3, 3);
            int c13 = Gmsh.Model.Geo.AddLine(p4, 4);
            int ll1 = Gmsh.Model.Geo.AddCurveLoop(new[] { c1, c2, c3, c4 });
            int s1  = Gmsh.Model.Geo.AddPlaneSurface(new[] { ll1 });
            int ll3 = Gmsh.Model.Geo.AddCurveLoop(new[] { c1, c11, -1, -c10 });
            int s3  = Gmsh.Model.Geo.AddPlaneSurface(new[] { ll3 });
            int ll4 = Gmsh.Model.Geo.AddCurveLoop(new[] { c2, c12, -2, -c11 });
            int s4  = Gmsh.Model.Geo.AddPlaneSurface(new[] { ll4 });
            int ll5 = Gmsh.Model.Geo.AddCurveLoop(new[] { c3, c13, 3, -c12 });
            int s5  = Gmsh.Model.Geo.AddPlaneSurface(new[] { ll5 });
            int ll6 = Gmsh.Model.Geo.AddCurveLoop(new[] { c4, c10, 4, -c13 });
            int s6  = Gmsh.Model.Geo.AddPlaneSurface(new[] { ll6 });
            int sl1 = Gmsh.Model.Geo.AddSurfaceLoop(new[] { s1, s3, s4, s5, s6, 1 });
            int v1  = Gmsh.Model.Geo.AddVolume(new[] { sl1 });

            Gmsh.Model.Geo.Synchronize();
            bool transfinite = true;

            if (transfinite)
            {
                int NN  = 30;
                var tmp = Gmsh.Model.GetEntities(1);
                for (int i = 0; i < tmp.Length; i++)
                {
                    Gmsh.Model.Mesh.SetTransfiniteCurve(tmp[i].Item2, NN);
                }
                tmp = Gmsh.Model.GetEntities(2);
                for (int i = 0; i < tmp.Length; i++)
                {
                    Gmsh.Model.Mesh.SetTransfiniteSurface(tmp[i].Item2);
                    Gmsh.Model.Mesh.SetRecombine(tmp[i].Item1, tmp[i].Item2);
                    Gmsh.Model.Mesh.SetSmoothing(tmp[i].Item1, tmp[i].Item2, 100);
                }
                Gmsh.Model.Mesh.SetTransfiniteVolume(v1);
            }
            else
            {
                Gmsh.Option.SetNumber("Mesh.CharacteristicLengthMin", 0.05);
                Gmsh.Option.SetNumber("Mesh.CharacteristicLengthMax", 0.05);
            }
            Gmsh.Model.Mesh.Generate(3);
            Gmsh.Write("x2.msh");
            Gmsh.Finalize();
        }