private static void Main(string[] args) { Gmsh.Initialize(); Gmsh.Option.SetNumber("General.Terminal", 1); Gmsh.Model.Add("t11"); int p1 = geo.AddPoint(-1.25, -.5, 0); int p2 = geo.AddPoint(1.25, -.5, 0); int p3 = geo.AddPoint(1.25, 1.25, 0); int p4 = geo.AddPoint(-1.25, 1.25, 0); int l1 = geo.AddLine(p1, p2); int l2 = geo.AddLine(p2, p3); int l3 = geo.AddLine(p3, p4); int l4 = geo.AddLine(p4, p1); int cl = geo.AddCurveLoop(new[] { l1, l2, l3, l4 }); int pl = geo.AddPlaneSurface(new[] { cl }); geo.Synchronize(); f.Add("MathEval", 1); f.SetString(1, "F", "0.01*(1.0+30.*(y-x*x)*(y-x*x) + (1-x)*(1-x))"); f.SetAsBackgroundMesh(1); Gmsh.Model.Mesh.SetRecombine(2, pl); Gmsh.Model.Mesh.Generate(2); Gmsh.Fltk.Run(); Gmsh.Finalize(); }
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(); }
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(); }
private static void Main(string[] args) { Gmsh.Initialize(); Gmsh.Option.SetNumber("General.Terminal", 1); Gmsh.Model.Add("t2"); double lc = 1E-2; Gmsh.Model.Geo.AddPoint(0, 0, 0, lc, 1); Gmsh.Model.Geo.AddPoint(0.1, 0, 0, lc, 2); Gmsh.Model.Geo.AddPoint(0.1, 0.3, 0, lc, 3); Gmsh.Model.Geo.AddPoint(0, 0.3, 0, lc, 4); Gmsh.Model.Geo.AddLine(1, 2, 1); Gmsh.Model.Geo.AddLine(3, 2, 2); Gmsh.Model.Geo.AddLine(3, 4, 3); Gmsh.Model.Geo.AddLine(4, 1, 4); Gmsh.Model.Geo.AddCurveLoop(new[] { 4, 1, -2, 3 }, 1); Gmsh.Model.Geo.AddPlaneSurface(new[] { 1 }, 1); Gmsh.Model.AddPhysicalGroup(1, new[] { 1, 2, 4 }, 5); int ps = Gmsh.Model.AddPhysicalGroup(2, new[] { 1 }); Gmsh.Model.SetPhysicalName(2, ps, "My surface"); // We can then add new points and curves in the same way as we did in "t1" Gmsh.Model.Geo.AddPoint(0, 0.4, 0, lc, 5); Gmsh.Model.Geo.AddLine(4, 5, 5); Gmsh.Model.Geo.Translate(new[] { (0, 5) }, -0.02, 0, 0);
private static void Main(string[] args) { Gmsh.Initialize(); Gmsh.Option.SetNumber("General.Terminal", 1); Gmsh.Model.Add("t3"); // Copied from t1... double lc = 1E-2; Gmsh.Model.Geo.AddPoint(0, 0, 0, lc, 1); Gmsh.Model.Geo.AddPoint(0.1, 0, 0, lc, 2); Gmsh.Model.Geo.AddPoint(0.1, 0.3, 0, lc, 3); var p4 = Gmsh.Model.Geo.AddPoint(0, 0.3, 0, lc); Gmsh.Model.Geo.AddLine(1, 2, 1); Gmsh.Model.Geo.AddLine(3, 2, 2); Gmsh.Model.Geo.AddLine(3, p4, 3); Gmsh.Model.Geo.AddLine(4, 1, p4); Gmsh.Model.Geo.AddCurveLoop(new int[] { 4, 1, -2, 3 }, 1); Gmsh.Model.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"); // As in `t2', we plan to perform an extrusion along the z axis. But // here, instead of only extruding the geometry, we also want to extrude the // 2D mesh. This is done with the same `extrude()' function, but by specifying // element 'Layers' (2 layers in this case, the first one with 8 subdivisions // and the second one with 2 subdivisions, both with a height of h/2). The // number of elements for each layer and the (end) height of each layer are // specified in two vectors: double h = 0.1, angle = 90; Gmsh.Model.Geo.Extrude(new[] { (2, 1) }, 0, 0, h, out (int, int)[] ov, new[] { 8, 2 }, new[] { 0.5, 1 });
private static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine($"Usage: {args[0]} file"); return; } Gmsh.Initialize(); Gmsh.Option.SetNumber("General.Terminal", 1); //in the MSH format: `t1.exe file.msh' Gmsh.Open(args[0]); var name = Gmsh.Model.GetCurrent(); Console.WriteLine($"Model {name} ({Gmsh.Model.GetDimension()}D)"); var entities = Gmsh.Model.GetEntities(); for (int i = 0; i < entities.Length; i++) { int dim = entities[i].Item1, tag = entities[i].Item2; Gmsh.Model.Mesh.GetNodes(out var nodeTags, out var nodeCoords, out var nodeParams, dim, tag); Gmsh.Model.Mesh.GetElements(out var elemTypes, out var elemTags, out var elemNodeTags, dim, tag); var type = Gmsh.Model.GetType(dim, tag); name = Gmsh.Model.GetEntitiesName(dim, tag); Console.WriteLine($"Entity {name} ({dim},{tag}) of type {type}"); var boundary = Gmsh.Model.GetBoundary(new[] { (dim, tag) });
private static void Main(string[] args) { Gmsh.Initialize(); Gmsh.Option.SetNumber("General.Terminal", 1); Gmsh.Model.Add("t13"); try { Gmsh.Merge("t13_data.stl"); } catch { Gmsh.Logger.Write("Could not load STL mesh: bye!"); Gmsh.Finalize(); return; } double angle = 40; // For complex geometries, patches can be too complex, too elongated or too // large to be parametrized; setting the following option will force the // creation of patches that are amenable to reparametrization: bool forceParametrizablePatches = false; // For open surfaces include the boundary edges in the classification process: bool includeBoundary = true; // Force curves to be split on given angle: double curveAngle = 180; Gmsh.Model.Mesh.ClassifySurfaces(angle * Math.PI / 180, includeBoundary, forceParametrizablePatches, curveAngle * Math.PI / 180); Gmsh.Model.Mesh.CreateGeometry(); var s = Gmsh.Model.GetEntities(2); var sl = s.Select(ss => ss.Item2).ToArray(); var l = Gmsh.Model.Geo.AddSurfaceLoop(sl); Gmsh.Model.Geo.AddVolume(new[] { l }); Gmsh.Model.Geo.Synchronize(); bool funny = true; // false; int ff = f.Add("MathEval"); if (funny) { f.SetString(ff, "F", "2*Sin((x+y)/5) + 3"); } else { f.SetString(ff, "F", "4"); } f.SetAsBackgroundMesh(ff); Gmsh.Model.Mesh.Generate(3); Gmsh.Fltk.Run(); Gmsh.Finalize(); }
private static void Main(string[] args) { Gmsh.Initialize(); Gmsh.Option.SetNumber("General.Terminal", 1); Gmsh.Model.Add("t18"); Gmsh.Model.Occ.AddBox(0, 0, 0, 1, 1, 1, 1); Gmsh.Model.Occ.Synchronize(); var @out = Gmsh.Model.GetEntities(0); Gmsh.Model.Mesh.SetSize(@out, 0.1); Gmsh.Model.Mesh.SetSize(new[] { (0, 1) }, 0.02);
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(); }
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(); }
private static void Main(string[] args) { Gmsh.Initialize(); Gmsh.Option.SetNumber("General.Terminal", 1); Gmsh.Model.Add("t14"); double ms = 0.5; // mesh characteristic length double h = 2; geo.AddPoint(0, 0, 0, ms, 1); geo.AddPoint(10, 0, 0, ms, 2); geo.AddPoint(10, 10, 0, ms, 3); geo.AddPoint(0, 10, 0, ms, 4); geo.AddPoint(4, 4, 0, ms, 5); geo.AddPoint(6, 4, 0, ms, 6); geo.AddPoint(6, 6, 0, ms, 7); geo.AddPoint(4, 6, 0, ms, 8); geo.AddPoint(2, 0, 0, ms, 9); geo.AddPoint(8, 0, 0, ms, 10); geo.AddPoint(2, 10, 0, ms, 11); geo.AddPoint(8, 10, 0, ms, 12); geo.AddLine(1, 9, 1); geo.AddLine(9, 10, 2); geo.AddLine(10, 2, 3); geo.AddLine(2, 3, 4); geo.AddLine(3, 12, 5); geo.AddLine(12, 11, 6); geo.AddLine(11, 4, 7); geo.AddLine(4, 1, 8); geo.AddLine(5, 6, 9); geo.AddLine(6, 7, 10); geo.AddLine(7, 8, 11); geo.AddLine(8, 5, 12); geo.AddCurveLoop(new[] { 6, 7, 8, 1, 2, 3, 4, 5 }, 13); geo.AddCurveLoop(new[] { 11, 12, 9, 10 }, 14); geo.AddPlaneSurface(new[] { 13, 14 }, 15); geo.Extrude(new[] { (2, 15) }, 0, 0, h, out (int, int)[] e);
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(); }
private static void Main(string[] args) { Gmsh.Initialize(); Gmsh.Option.SetNumber("General.Terminal", 1); Gmsh.Model.Add("t16"); Gmsh.Logger.Start(); try { Gmsh.Model.Occ.AddBox(0, 0, 0, 1, 1, 1, 1); Gmsh.Model.Occ.AddBox(0, 0, 0, 0.5, 0.5, 0.5, 2); } catch { Gmsh.Logger.Write("Could not create OpenCASCADE shapes: bye!"); return; } Gmsh.Model.Occ.Cut(new[] { (3, 1) }, new[] { (3, 2) }, out var ov, out var ovv, 3);
private static void Main(string[] args) { Gmsh.Initialize(); Gmsh.Option.SetNumber("General.Terminal", 1); Gmsh.Model.Add("t6"); double 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 = Gmsh.Model.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[] { 4, 1, -2, 3 }, 1); geo.AddPlaneSurface(new[] { 1 }, 1); geo.Remove(new[] { (2, 1), (1, 4) });
private static void Main(string[] args) { Gmsh.Initialize(); Gmsh.Option.SetNumber("General.Terminal", 1); Gmsh.Model.Add("t4"); double cm = 1E-2; double e1 = 4.5 * cm, e2 = 6 * cm / 2, e3 = 5 * cm / 2; double h1 = 5 * cm, h2 = 10 * cm, h3 = 5 * cm, h4 = 2 * cm, h5 = 4.5 * cm; double R1 = 1 * cm, R2 = 1.5 * cm, r = 1 * cm; double Lc1 = 0.01; double Lc2 = 0.003; double ccos = (-h5 * R1 + e2 * hypot(h5, hypot(e2, R1))) / (h5 * h5 + e2 * e2); double ssin = Math.Sqrt(1 - ccos * ccos); geo.AddPoint(-e1 - e2, 0, 0, Lc1, 1); geo.AddPoint(-e1 - e2, h1, 0, Lc1, 2); geo.AddPoint(-e3 - r, h1, 0, Lc2, 3); geo.AddPoint(-e3 - r, h1 + r, 0, Lc2, 4); geo.AddPoint(-e3, h1 + r, 0, Lc2, 5); geo.AddPoint(-e3, h1 + h2, 0, Lc1, 6); geo.AddPoint(e3, h1 + h2, 0, Lc1, 7); geo.AddPoint(e3, h1 + r, 0, Lc2, 8); geo.AddPoint(e3 + r, h1 + r, 0, Lc2, 9); geo.AddPoint(e3 + r, h1, 0, Lc2, 10); geo.AddPoint(e1 + e2, h1, 0, Lc1, 11); geo.AddPoint(e1 + e2, 0, 0, Lc1, 12); geo.AddPoint(e2, 0, 0, Lc1, 13); geo.AddPoint(R1 / ssin, h5 + R1 * ccos, 0, Lc2, 14); geo.AddPoint(0, h5, 0, Lc2, 15); geo.AddPoint(-R1 / ssin, h5 + R1 * ccos, 0, Lc2, 16); geo.AddPoint(-e2, 0.0, 0, Lc1, 17); geo.AddPoint(-R2, h1 + h3, 0, Lc2, 18); geo.AddPoint(-R2, h1 + h3 + h4, 0, Lc2, 19); geo.AddPoint(0, h1 + h3 + h4, 0, Lc2, 20); geo.AddPoint(R2, h1 + h3 + h4, 0, Lc2, 21); geo.AddPoint(R2, h1 + h3, 0, Lc2, 22); geo.AddPoint(0, h1 + h3, 0, Lc2, 23); geo.AddPoint(0, h1 + h3 + h4 + R2, 0, Lc2, 24); geo.AddPoint(0, h1 + h3 - R2, 0, Lc2, 25); geo.AddLine(1, 17, 1); geo.AddLine(17, 16, 2); geo.AddCircleArc(14, 15, 16, 3); geo.AddLine(14, 13, 4); geo.AddLine(13, 12, 5); geo.AddLine(12, 11, 6); geo.AddLine(11, 10, 7); geo.AddCircleArc(8, 9, 10, 8); geo.AddLine(8, 7, 9); geo.AddLine(7, 6, 10); geo.AddLine(6, 5, 11); geo.AddCircleArc(3, 4, 5, 12); geo.AddLine(3, 2, 13); geo.AddLine(2, 1, 14); geo.AddLine(18, 19, 15); geo.AddCircleArc(21, 20, 24, 16); geo.AddCircleArc(24, 20, 19, 17); geo.AddCircleArc(18, 23, 25, 18); geo.AddCircleArc(25, 23, 22, 19); geo.AddLine(21, 22, 20); geo.AddCurveLoop(new[] { 17, -15, 18, 19, -20, 16 }, 21); geo.AddPlaneSurface(new[] { 21 }, 22); // But we still need to define the exterior surface. Since this surface has a // hole, its definition now requires two curves loops: geo.AddCurveLoop(new[] { 11, -12, 13, 14, 1, 2, -3, 4, 5, 6, 7, -8, 9, 10 }, 23); geo.AddPlaneSurface(new[] { 23, 21 }, 24); geo.Synchronize(); //int v = Gmsh.View.Add("comments"); //Gmsh.View.AddListDataString(v, new[] { 10, -10.0 }, new[] { "Created with Gmsh" }); //Gmsh.View.AddListDataString(v, new[] { 0, 0.09, 0 }, new[] { "file://../[email protected]" }, new[] { "Align", "Center" }); //Gmsh.View.AddListDataString(v, new[] { -0.01, 0.09,0 }, new[] { "file://../[email protected],0,0,1,0,1,0" }); //Gmsh.View.AddListDataString(v, new[] { 0, 0.12, 0 }, new[] { "file://../[email protected]#" }, new[] { "Align", "Center" }); //Gmsh.View.AddListDataString(v, new[] { 150, -7.0 }, new[] { "file://../t4_image.png@20x0" }); //Gmsh.Option.SetString("View[0].DoubleClickedCommand","Printf('View[0] has been double-clicked!');"); //Gmsh.Option.SetString("Geometry.DoubleClickedLineCommand", @"Printf('Curve %g has been double-clicked!', "+ // "Geometry.DoubleClickedEntityTag);"); Gmsh.Model.SetColor(new[] { (2, 22) }, 127, 127, 127); // Gray50
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(); }
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(); }
private static void Main(string[] args) { Gmsh.Initialize(); Gmsh.Option.SetNumber("General.Terminal", 1); Gmsh.Model.Add("t6"); 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(); try { Gmsh.Merge("view1.pos"); Gmsh.Merge("view1.pos"); Gmsh.Merge("view4.pos"); // contains 2 views inside } catch { Gmsh.Logger.Write("Could not load post-processing views: bye!"); Gmsh.Finalize(); return; } opt.SetNumber("General.Trackball", 0); opt.SetNumber("General.RotationX", 0); opt.SetNumber("General.RotationY", 0); opt.SetNumber("General.RotationZ", 0); opt.SetColor("General.Background", Color.White); opt.SetColor("General.Foreground", Color.Black); opt.SetColor("General.Text", Color.Black); opt.SetNumber("General.Orthographic", 0); opt.SetNumber("General.Axes", 0); opt.SetNumber("General.SmallAxes", 0); Gmsh.Fltk.Initialize(); opt.SetNumber("View[0].IntervalsType", 2); opt.SetNumber("View[0].OffsetZ", 0.05); opt.SetNumber("View[0].RaiseZ", 0); opt.SetNumber("View[0].Light", 1); opt.SetNumber("View[0].ShowScale", 0); opt.SetNumber("View[0].SmoothNormals", 1); opt.SetNumber("View[1].IntervalsType", 1); opt.SetNumber("View[1].NbIso", 10); opt.SetNumber("View[1].ShowScale", 0); opt.SetString("View[2].Name", "Test..."); opt.SetNumber("View[2].Axes", 1); opt.SetNumber("View[2].IntervalsType", 2); opt.SetNumber("View[2].Type", 2); opt.SetNumber("View[2].IntervalsType", 2); opt.SetNumber("View[2].AutoPosition", 0); opt.SetNumber("View[2].PositionX", 85); opt.SetNumber("View[2].PositionY", 50); opt.SetNumber("View[2].Width", 200); opt.SetNumber("View[2].Height", 130); opt.SetNumber("View[3].Visible", 0); int t = 0; // Initial step for (int num = 1; num <= 3; num++) { var nbt = opt.GetNumber("View[0].NbTimeStep"); t = (t < nbt - 1) ? t + 1 : 0; // Set time step opt.SetNumber("View[0].TimeStep", t); opt.SetNumber("View[1].TimeStep", t); opt.SetNumber("View[2].TimeStep", t); opt.SetNumber("View[3].TimeStep", t); var max = opt.GetNumber("View[0].Max"); opt.SetNumber("View[0].RaiseZ", 0.01 / max * t); if (num == 3) { var mw = opt.GetNumber("General.MenuWidth"); opt.SetNumber("General.GraphicsWidth", mw + 640); opt.SetNumber("General.GraphicsHeight", 480); } int frames = 50; for (int num2 = 1; num2 <= frames; num2++) { var rotx = opt.GetNumber("General.RotationX"); opt.SetNumber("General.RotationX", rotx + 10); opt.SetNumber("General.RotationY", (rotx + 10) / 3.0); var rotz = opt.GetNumber("General.RotationZ"); opt.SetNumber("General.RotationZ", rotz + 0.1); Gmsh.Graphics.Draw(); if (num == 3) { // Uncomment the following lines to save each frame to an image file // gmsh::write("t2-" + std::to_string(num2) + ".gif"); // gmsh::write("t2-" + std::to_string(num2) + ".ppm"); // gmsh::write("t2-" + std::to_string(num2) + ".jpg"); } } if (num == 3) { // Here we could make a system call to generate a movie... } } Gmsh.Fltk.Run(); Gmsh.Finalize(); }