[关闭]
@daidezhi 2016-08-15T10:42:40.000000Z 字数 23473 阅读 2327

Gmsh tutorial

CFD Gmsh Mesh


1. t1.geo

  1. /*********************************************************************
  2. *
  3. * Gmsh tutorial 1
  4. *
  5. * Variables, elementary entities (points, lines, surfaces), physical
  6. * entities (points, lines, surfaces)
  7. *
  8. *********************************************************************/
  9. // The simplest construction in Gmsh's scripting language is the
  10. // `affectation'. The following command defines a new variable `lc':
  11. lc = 1e-2;
  12. // This variable can then be used in the definition of Gmsh's simplest
  13. // `elementary entity', a `Point'. A Point is defined by a list of four numbers:
  14. // three coordinates (X, Y and Z), and a characteristic length (lc) that sets
  15. // the target element size at the point:
  16. Point(1) = {0, 0, 0, lc};
  17. // The distribution of the mesh element sizes is then obtained by interpolation
  18. // of these characteristic lengths throughout the geometry. Another method to
  19. // specify characteristic lengths is to use a background mesh (see `t7.geo' and
  20. // `bgmesh.pos').
  21. // We can then define some additional points as well as our first curve. Curves
  22. // are Gmsh's second type of elementery entities, and, amongst curves, straight
  23. // lines are the simplest. A straight line is defined by a list of point
  24. // numbers. In the commands below, for example, the line 1 starts at point 1 and
  25. // ends at point 2:
  26. Point(2) = {.1, 0, 0, lc} ;
  27. Point(3) = {.1, .3, 0, lc} ;
  28. Point(4) = {0, .3, 0, lc} ;
  29. Line(1) = {1,2} ;
  30. Line(2) = {3,2} ;
  31. Line(3) = {3,4} ;
  32. Line(4) = {4,1} ;
  33. // The third elementary entity is the surface. In order to define a simple
  34. // rectangular surface from the four lines defined above, a line loop has first
  35. // to be defined. A line loop is a list of connected lines, a sign being
  36. // associated with each line (depending on the orientation of the line):
  37. Line Loop(5) = {4,1,-2,3} ;
  38. // We can then define the surface as a list of line loops (only one here, since
  39. // there are no holes--see `t4.geo'):
  40. Plane Surface(6) = {5} ;
  41. // At this level, Gmsh knows everything to display the rectangular surface 6 and
  42. // to mesh it. An optional step is needed if we want to associate specific
  43. // region numbers to the various elements in the mesh (e.g. to the line segments
  44. // discretizing lines 1 to 4 or to the triangles discretizing surface 6). This
  45. // is achieved by the definition of `physical entities'. Physical entities will
  46. // group elements belonging to several elementary entities by giving them a
  47. // common number (a region number).
  48. // We can for example group the points 1 and 2 into the physical entity 1:
  49. Physical Point(1) = {1,2} ;
  50. // Consequently, two punctual elements will be saved in the output mesh file,
  51. // both with the region number 1. The mechanism is identical for line or surface
  52. // elements:
  53. MY_LINE = 2;
  54. Physical Line(MY_LINE) = {1,2} ;
  55. Physical Line("My second line (automatic physical id)") = {3} ;
  56. Physical Line("My third line (physical id 5)", 5) = {4} ;
  57. Physical Surface("My surface") = {6} ;
  58. // All the line elements created during the meshing of lines 1 and 2 will be
  59. // saved in the output mesh file with the physical id 2. The elements from line
  60. // 3 will be saved in the output mesh file with an automatic physical id,
  61. // associated with the label "My second line (automatic physical id)". The
  62. // elements from line 4 will be saved with physical id 5, associated with the
  63. // label "My third line (physical id 5)". And finally, all the triangular
  64. // elements resulting from the discretization of surface 6 will be given an
  65. // automatic physical id associated with the label "My surface").
  66. // Note that if no physical entities are defined, then all the elements in the
  67. // mesh will be saved "as is", with their default orientation.

t1


2. t2.geo

  1. /*********************************************************************
  2. *
  3. * Gmsh tutorial 2
  4. *
  5. * Includes, geometrical transformations, extruded geometries,
  6. * elementary entities (volumes), physical entities (volumes)
  7. *
  8. *********************************************************************/
  9. // We first include the previous tutorial file, in order to use it as a basis
  10. // for this one:
  11. Include "t1.geo";
  12. // We can then add new points and lines in the same way as we did in `t1.geo':
  13. Point(5) = {0, .4, 0, lc};
  14. Line(5) = {4, 5};
  15. // But Gmsh also provides tools to tranform (translate, rotate, etc.)
  16. // elementary entities or copies of elementary entities. For example, the point
  17. // 3 can be moved by 0.05 units to the left with:
  18. Translate {-0.05, 0, 0} { Point{3}; }
  19. // The resulting point can also be duplicated and translated by 0.1 along the y
  20. // axis:
  21. Translate {0, 0.1, 0} { Duplicata{ Point{3}; } }
  22. // This command created a new point with an automatically assigned id. This id
  23. // can be obtained using the graphical user interface by hovering the mouse over
  24. // it and looking at the bottom of the graphic window: in this case, the new
  25. // point has id "6". Point 6 can then be used to create new entities, e.g.:
  26. Line(7) = {3, 6};
  27. Line(8) = {6, 5};
  28. Line Loop(10) = {5,-8,-7,3};
  29. Plane Surface(11) = {10};
  30. // Using the graphical user interface to obtain the ids of newly created
  31. // entities can sometimes be cumbersome. It can then be advantageous to use the
  32. // return value of the transformation commands directly. For example, the
  33. // Translate command returns a list containing the ids of the translated
  34. // entities. For example, we can translate copies of the two surfaces 6 and 11
  35. // to the right with the following command:
  36. my_new_surfs[] = Translate {0.12, 0, 0} { Duplicata{ Surface{6, 11}; } };
  37. // my_new_surfs[] (note the square brackets) denotes a list, which in this case
  38. // contains the ids of the two new surfaces (check `Tools->Message console' to
  39. // see the message):
  40. Printf("New surfaces '%g' and '%g'", my_new_surfs[0], my_new_surfs[1]);
  41. // In Gmsh lists use square brackets for their definition (mylist[] = {1,2,3};)
  42. // as well as to access their elements (myotherlist[] = {mylist[0],
  43. // mylist[2]};). Note that list indexing starts at 0.
  44. // Volumes are the fourth type of elementary entities in Gmsh. In the same way
  45. // one defines line loops to build surfaces, one has to define surface loops
  46. // (i.e. `shells') to build volumes. The following volume does not have holes
  47. // and thus consists of a single surface loop:
  48. Point(100) = {0., 0.3, 0.13, lc}; Point(101) = {0.08, 0.3, 0.1, lc};
  49. Point(102) = {0.08, 0.4, 0.1, lc}; Point(103) = {0., 0.4, 0.13, lc};
  50. Line(110) = {4, 100}; Line(111) = {3, 101};
  51. Line(112) = {6, 102}; Line(113) = {5, 103};
  52. Line(114) = {103, 100}; Line(115) = {100, 101};
  53. Line(116) = {101, 102}; Line(117) = {102, 103};
  54. Line Loop(118) = {115, -111, 3, 110}; Plane Surface(119) = {118};
  55. Line Loop(120) = {111, 116, -112, -7}; Plane Surface(121) = {120};
  56. Line Loop(122) = {112, 117, -113, -8}; Plane Surface(123) = {122};
  57. Line Loop(124) = {114, -110, 5, 113}; Plane Surface(125) = {124};
  58. Line Loop(126) = {115, 116, 117, 114}; Plane Surface(127) = {126};
  59. Surface Loop(128) = {127, 119, 121, 123, 125, 11};
  60. Volume(129) = {128};
  61. // When a volume can be extruded from a surface, it is usually easier to use the
  62. // Extrude command directly instead of creating all the points, lines and
  63. // surfaces by hand. For example, the following command extrudes the surface 11
  64. // along the z axis and automatically creates a new volume (as well as all the
  65. // needed points, lines and surfaces):
  66. Extrude {0, 0, 0.12} { Surface{my_new_surfs[1]}; }
  67. // The following command permits to manually assign a characteristic length to
  68. // some of the new points:
  69. Characteristic Length {103, 105, 109, 102, 28, 24, 6, 5} = lc * 3;
  70. // Note that, if the transformation tools are handy to create complex
  71. // geometries, it is also sometimes useful to generate the `flat' geometry, with
  72. // an explicit list of all elementary entities. This can be achieved by
  73. // selecting the `File->Save as->Gmsh unrolled geometry' menu or by typing
  74. //
  75. // > gmsh t2.geo -0
  76. //
  77. // on the command line.
  78. // To save all the tetrahedra discretizing the volumes 129 and 130 with a common
  79. // region number, we finally define a physical volume:
  80. Physical Volume ("The volume", 1) = {129,130};

t2


3. t3.geo

  1. /*********************************************************************
  2. *
  3. * Gmsh tutorial 3
  4. *
  5. * Extruded meshes, parameters, options
  6. *
  7. *********************************************************************/
  8. Geometry.OldNewReg = 1;
  9. // Again, we start by including the first tutorial:
  10. Include "t1.geo";
  11. // As in `t2.geo', we plan to perform an extrusion along the z axis. But here,
  12. // instead of only extruding the geometry, we also want to extrude the 2D
  13. // mesh. This is done with the same `Extrude' command, but by specifying element
  14. // 'Layers' (2 layers in this case, the first one with 8 subdivisions and the
  15. // second one with 2 subdivisions, both with a height of h/2):
  16. h = 0.1;
  17. Extrude {0,0,h} {
  18. Surface{6}; Layers{ {8,2}, {0.5,1} };
  19. }
  20. // The extrusion can also be performed with a rotation instead of a translation,
  21. // and the resulting mesh can be recombined into prisms (we use only one layer
  22. // here, with 7 subdivisions). All rotations are specified by an axis direction
  23. // ({0,1,0}), an axis point ({-0.1,0,0.1}) and a rotation angle (-Pi/2):
  24. Extrude { {0,1,0} , {-0.1,0,0.1} , -Pi/2 } {
  25. Surface{28}; Layers{7}; Recombine;
  26. }
  27. // Note that a translation ({-2*h,0,0}) and a rotation ({1,0,0}, {0,0.15,0.25},
  28. // Pi/2) can also be combined. Here the angle is specified as a 'parameter',
  29. // using the 'DefineConstant' syntax. This parameter can be modified
  30. // insteractively in the GUI, and can be exchanged with other codes using the
  31. // ONELAB framework:
  32. DefineConstant[ angle = {90, Min 0, Max 120, Step 1,
  33. Name "Parameters/Twisting angle"} ];
  34. out[] = Extrude { {-2*h,0,0}, {1,0,0} , {0,0.15,0.25} , angle * Pi / 180 } {
  35. Surface{50}; Layers{10}; Recombine;
  36. };
  37. // In this last extrusion command we retrieved the volume number programatically
  38. // by using the return value (a list) of the Extrude command. This list contains
  39. // the "top" of the extruded surface (in out[0]), the newly created volume (in
  40. // out[1]) and the ids of the lateral surfaces (in out[2], out[3], ...)
  41. // We can then define a new physical volume to save all the tetrahedra with a
  42. // common region number (101):
  43. Physical Volume(101) = {1, 2, out[1]};
  44. // Let us now change some options... Since all interactive options are
  45. // accessible in Gmsh's scripting language, we can for example make point tags
  46. // visible or redefine some colors directly in the input file:
  47. Geometry.PointNumbers = 1;
  48. Geometry.Color.Points = Orange;
  49. General.Color.Text = White;
  50. Mesh.Color.Points = {255,0,0};
  51. // Note that all colors can be defined literally or numerically, i.e.
  52. // `Mesh.Color.Points = Red' is equivalent to `Mesh.Color.Points = {255,0,0}';
  53. // and also note that, as with user-defined variables, the options can be used
  54. // either as right or left hand sides, so that the following command will set
  55. // the surface color to the same color as the points:
  56. Geometry.Color.Surfaces = Geometry.Color.Points;
  57. // You can use the `Help->Current options' menu to see the current values of all
  58. // options. To save all the options in a file, use `File->Save as->Gmsh
  59. // options'. To associate the current options with the current file use
  60. // `File->Save Options->For Current File'. To save the current options for all
  61. // future Gmsh sessions use `File->Save Options->As default'.

t3


4. t4.geo

  1. /*********************************************************************
  2. *
  3. * Gmsh tutorial 4
  4. *
  5. * Built-in functions, surface holes, annotations, mesh colors
  6. *
  7. *********************************************************************/
  8. // As usual, we start by defining some variables:
  9. cm = 1e-02;
  10. e1 = 4.5 * cm; e2 = 6 * cm / 2; e3 = 5 * cm / 2;
  11. h1 = 5 * cm; h2 = 10 * cm; h3 = 5 * cm; h4 = 2 * cm; h5 = 4.5 * cm;
  12. R1 = 1 * cm; R2 = 1.5 * cm; r = 1 * cm;
  13. Lc1 = 0.01;
  14. Lc2 = 0.003;
  15. // We can use all the usual mathematical functions (note the capitalized first
  16. // letters), plus some useful functions like Hypot(a, b) := Sqrt(a^2 + b^2):
  17. ccos = (-h5*R1 + e2 * Hypot(h5, Hypot(e2, R1))) / (h5^2 + e2^2);
  18. ssin = Sqrt(1 - ccos^2);
  19. // Then we define some points and some lines using these variables:
  20. Point(1) = {-e1-e2, 0 , 0, Lc1}; Point(2) = {-e1-e2, h1 , 0, Lc1};
  21. Point(3) = {-e3-r , h1 , 0, Lc2}; Point(4) = {-e3-r , h1+r , 0, Lc2};
  22. Point(5) = {-e3 , h1+r , 0, Lc2}; Point(6) = {-e3 , h1+h2, 0, Lc1};
  23. Point(7) = { e3 , h1+h2, 0, Lc1}; Point(8) = { e3 , h1+r , 0, Lc2};
  24. Point(9) = { e3+r , h1+r , 0, Lc2}; Point(10)= { e3+r , h1 , 0, Lc2};
  25. Point(11)= { e1+e2, h1 , 0, Lc1}; Point(12)= { e1+e2, 0 , 0, Lc1};
  26. Point(13)= { e2 , 0 , 0, Lc1};
  27. Point(14)= { R1 / ssin, h5+R1*ccos, 0, Lc2};
  28. Point(15)= { 0 , h5 , 0, Lc2};
  29. Point(16)= {-R1 / ssin, h5+R1*ccos, 0, Lc2};
  30. Point(17)= {-e2 , 0.0 , 0, Lc1};
  31. Point(18)= {-R2 , h1+h3 , 0, Lc2}; Point(19)= {-R2 , h1+h3+h4, 0, Lc2};
  32. Point(20)= { 0 , h1+h3+h4, 0, Lc2}; Point(21)= { R2 , h1+h3+h4, 0, Lc2};
  33. Point(22)= { R2 , h1+h3 , 0, Lc2}; Point(23)= { 0 , h1+h3 , 0, Lc2};
  34. Point(24)= { 0, h1+h3+h4+R2, 0, Lc2}; Point(25)= { 0, h1+h3-R2, 0, Lc2};
  35. Line(1) = {1 , 17};
  36. Line(2) = {17, 16};
  37. // Gmsh provides other curve primitives than stright lines: splines, B-splines,
  38. // circle arcs, ellipse arcs, etc. Here we define a new circle arc, starting at
  39. // point 14 and ending at point 16, with the circle's center being the point 15:
  40. Circle(3) = {14,15,16};
  41. // Note that, in Gmsh, circle arcs should always be smaller than Pi. We can then
  42. // define additional lines and circles, as well as a new surface:
  43. Line(4) = {14,13}; Line(5) = {13,12}; Line(6) = {12,11};
  44. Line(7) = {11,10}; Circle(8) = {8,9,10}; Line(9) = {8,7};
  45. Line(10) = {7,6}; Line(11) = {6,5}; Circle(12) = {3,4,5};
  46. Line(13) = {3,2}; Line(14) = {2,1}; Line(15) = {18,19};
  47. Circle(16) = {21,20,24}; Circle(17) = {24,20,19};
  48. Circle(18) = {18,23,25}; Circle(19) = {25,23,22};
  49. Line(20) = {21,22};
  50. Line Loop(21) = {17,-15,18,19,-20,16};
  51. Plane Surface(22) = {21};
  52. // But we still need to define the exterior surface. Since this surface has a
  53. // hole, its definition now requires two lines loops:
  54. Line Loop(23) = {11,-12,13,14,1,2,-3,4,5,6,7,-8,9,10};
  55. Plane Surface(24) = {23,21};
  56. // As a general rule, if a surface has N holes, it is defined by N+1 line loops:
  57. // the first loop defines the exterior boundary; the other loops define the
  58. // boundaries of the holes.
  59. // Finally, we can add some comments by embedding a post-processing view
  60. // containing some strings:
  61. View "comments" {
  62. // Add a text string in window coordinates, 10 pixels from the left and 10
  63. // pixels from the bottom, using the StrCat function to concatenate strings:
  64. T2(10, -10, 0){ StrCat("Created on ", Today, " with Gmsh") };
  65. // Add a text string in model coordinates centered at (X,Y,Z) = (0, 0.11, 0):
  66. T3(0, 0.11, 0, TextAttributes("Align", "Center", "Font", "Helvetica")){ "Hole" };
  67. // If a string starts with `file://', the rest is interpreted as an image
  68. // file. For 3D annotations, the size in model coordinates can be specified
  69. // after a `@' symbol in the form `widthxheight' (if one of `width' or
  70. // `height' is zero, natural scaling is used; if both are zero, original image
  71. // dimensions in pixels are used):
  72. T3(0, 0.09, 0, TextAttributes("Align", "Center")){ "file://image.png@0.01x0" };
  73. // The 3D orientation of the image can be specified by proving the direction
  74. // of the bottom and left edge of the image in model space:
  75. T3(-0.01, 0.09, 0, 0){ "file://image.png@0.01x0,0,0,1,0,1,0" };
  76. // The image can also be drawn in "billboard" mode, i.e. always parallel to
  77. // the camera, by using the `#' symbol:
  78. T3(0, 0.12, 0, TextAttributes("Align", "Center")){ "file://image.png@0.01x0#" };
  79. // The size of 2D annotations is given directly in pixels:
  80. T2(350, -7, 0){ "file://image.png@20x0" };
  81. };
  82. // Views and geometrical entities can be made to respond to double-click events:
  83. View[0].DoubleClickedCommand = "Printf('View[0] has been double-clicked!');";
  84. Geometry.DoubleClickedLineCommand = "Printf('Line %g has been double-clicked!',
  85. Geometry.DoubleClickedEntityTag);";
  86. // We can also change the color of some mesh entities:
  87. Color Grey50{ Surface{ 22 }; }
  88. Color Purple{ Surface{ 24 }; }
  89. Color Red{ Line{ 1:14 }; }
  90. Color Yellow{ Line{ 15:20 }; }

t4


5. t5.geo

  1. /*********************************************************************
  2. *
  3. * Gmsh tutorial 5
  4. *
  5. * Characteristic lengths, arrays of variables, macros, loops
  6. *
  7. *********************************************************************/
  8. // We start by defining some target mesh sizes:
  9. lcar1 = .1;
  10. lcar2 = .0005;
  11. lcar3 = .055;
  12. // If we wanted to change these mesh sizes globally (without changing the above
  13. // definitions), we could give a global scaling factor for all characteristic
  14. // lengths on the command line with the `-clscale' option (or with
  15. // `Mesh.CharacteristicLengthFactor' in an option file). For example, with:
  16. //
  17. // > gmsh t5.geo -clscale 1
  18. //
  19. // this input file produces a mesh of approximately 1,300 nodes and 11,000
  20. // tetrahedra. With
  21. //
  22. // > gmsh t5.geo -clscale 0.2
  23. //
  24. // the mesh counts approximately 350,000 nodes and 2.1 million tetrahedra. You
  25. // can check mesh statistics in the graphical user interface with the
  26. // `Tools->Statistics' menu.
  27. // We proceed by defining some elementary entities describing a truncated cube:
  28. Point(1) = {0.5,0.5,0.5,lcar2}; Point(2) = {0.5,0.5,0,lcar1};
  29. Point(3) = {0,0.5,0.5,lcar1}; Point(4) = {0,0,0.5,lcar1};
  30. Point(5) = {0.5,0,0.5,lcar1}; Point(6) = {0.5,0,0,lcar1};
  31. Point(7) = {0,0.5,0,lcar1}; Point(8) = {0,1,0,lcar1};
  32. Point(9) = {1,1,0,lcar1}; Point(10) = {0,0,1,lcar1};
  33. Point(11) = {0,1,1,lcar1}; Point(12) = {1,1,1,lcar1};
  34. Point(13) = {1,0,1,lcar1}; Point(14) = {1,0,0,lcar1};
  35. Line(1) = {8,9}; Line(2) = {9,12}; Line(3) = {12,11};
  36. Line(4) = {11,8}; Line(5) = {9,14}; Line(6) = {14,13};
  37. Line(7) = {13,12}; Line(8) = {11,10}; Line(9) = {10,13};
  38. Line(10) = {10,4}; Line(11) = {4,5}; Line(12) = {5,6};
  39. Line(13) = {6,2}; Line(14) = {2,1}; Line(15) = {1,3};
  40. Line(16) = {3,7}; Line(17) = {7,2}; Line(18) = {3,4};
  41. Line(19) = {5,1}; Line(20) = {7,8}; Line(21) = {6,14};
  42. Line Loop(22) = {-11,-19,-15,-18}; Plane Surface(23) = {22};
  43. Line Loop(24) = {16,17,14,15}; Plane Surface(25) = {24};
  44. Line Loop(26) = {-17,20,1,5,-21,13}; Plane Surface(27) = {26};
  45. Line Loop(28) = {-4,-1,-2,-3}; Plane Surface(29) = {28};
  46. Line Loop(30) = {-7,2,-5,-6}; Plane Surface(31) = {30};
  47. Line Loop(32) = {6,-9,10,11,12,21}; Plane Surface(33) = {32};
  48. Line Loop(34) = {7,3,8,9}; Plane Surface(35) = {34};
  49. Line Loop(36) = {-10,18,-16,-20,4,-8}; Plane Surface(37) = {36};
  50. Line Loop(38) = {-14,-13,-12,19}; Plane Surface(39) = {38};
  51. // Instead of using included files, we now use a user-defined macro in order
  52. // to carve some holes in the cube:
  53. Macro CheeseHole
  54. // In the following commands we use the reserved variable name `newp', which
  55. // automatically selects a new point number. This number is chosen as the
  56. // highest current point number, plus one. (Note that, analogously to `newp',
  57. // the variables `newl', `news', `newv' and `newreg' select the highest number
  58. // amongst currently defined curves, surfaces, volumes and `any entities other
  59. // than points', respectively.)
  60. p1 = newp; Point(p1) = {x, y, z, lcar3} ;
  61. p2 = newp; Point(p2) = {x+r,y, z, lcar3} ;
  62. p3 = newp; Point(p3) = {x, y+r,z, lcar3} ;
  63. p4 = newp; Point(p4) = {x, y, z+r,lcar3} ;
  64. p5 = newp; Point(p5) = {x-r,y, z, lcar3} ;
  65. p6 = newp; Point(p6) = {x, y-r,z, lcar3} ;
  66. p7 = newp; Point(p7) = {x, y, z-r,lcar3} ;
  67. c1 = newreg; Circle(c1) = {p2,p1,p7}; c2 = newreg; Circle(c2) = {p7,p1,p5};
  68. c3 = newreg; Circle(c3) = {p5,p1,p4}; c4 = newreg; Circle(c4) = {p4,p1,p2};
  69. c5 = newreg; Circle(c5) = {p2,p1,p3}; c6 = newreg; Circle(c6) = {p3,p1,p5};
  70. c7 = newreg; Circle(c7) = {p5,p1,p6}; c8 = newreg; Circle(c8) = {p6,p1,p2};
  71. c9 = newreg; Circle(c9) = {p7,p1,p3}; c10 = newreg; Circle(c10) = {p3,p1,p4};
  72. c11 = newreg; Circle(c11) = {p4,p1,p6}; c12 = newreg; Circle(c12) = {p6,p1,p7};
  73. // We need non-plane surfaces to define the spherical holes. Here we use ruled
  74. // surfaces, which can have 3 or 4 sides:
  75. l1 = newreg; Line Loop(l1) = {c5,c10,c4}; Ruled Surface(newreg) = {l1};
  76. l2 = newreg; Line Loop(l2) = {c9,-c5,c1}; Ruled Surface(newreg) = {l2};
  77. l3 = newreg; Line Loop(l3) = {c12,-c8,-c1}; Ruled Surface(newreg) = {l3};
  78. l4 = newreg; Line Loop(l4) = {c8,-c4,c11}; Ruled Surface(newreg) = {l4};
  79. l5 = newreg; Line Loop(l5) = {-c10,c6,c3}; Ruled Surface(newreg) = {l5};
  80. l6 = newreg; Line Loop(l6) = {-c11,-c3,c7}; Ruled Surface(newreg) = {l6};
  81. l7 = newreg; Line Loop(l7) = {-c2,-c7,-c12};Ruled Surface(newreg) = {l7};
  82. l8 = newreg; Line Loop(l8) = {-c6,-c9,c2}; Ruled Surface(newreg) = {l8};
  83. // We then store the surface loops identification numbers in a list for later
  84. // reference (we will need these to define the final volume):
  85. theloops[t] = newreg ;
  86. Surface Loop(theloops[t]) = {l8+1,l5+1,l1+1,l2+1,l3+1,l7+1,l6+1,l4+1};
  87. thehole = newreg ;
  88. Volume(thehole) = theloops[t] ;
  89. Return
  90. // We can use a `For' loop to generate five holes in the cube:
  91. x = 0 ; y = 0.75 ; z = 0 ; r = 0.09 ;
  92. For t In {1:5}
  93. x += 0.166 ;
  94. z += 0.166 ;
  95. // We call the `CheeseHole' macro:
  96. Call CheeseHole ;
  97. // We define a physical volume for each hole:
  98. Physical Volume (t) = thehole ;
  99. // We also print some variables on the terminal (note that, since all
  100. // variables are treated internally as floating point numbers, the format
  101. // string should only contain valid floating point format specifiers like
  102. // `%g', `%f', '%e', etc.):
  103. Printf("Hole %g (center = {%g,%g,%g}, radius = %g) has number %g!",
  104. t, x, y, z, r, thehole) ;
  105. EndFor
  106. // We can then define the surface loop for the exterior surface of the cube:
  107. theloops[0] = newreg ;
  108. Surface Loop(theloops[0]) = {35,31,29,37,33,23,39,25,27} ;
  109. // The volume of the cube, without the 5 holes, is now defined by 6 surface
  110. // loops: the first surface loop defines the exterior surface; the surface loops
  111. // other than the first one define holes. (Again, to reference an array of
  112. // variables, its identifier is followed by square brackets):
  113. Volume(186) = {theloops[]} ;
  114. // We finally define a physical volume for the elements discretizing the cube,
  115. // without the holes (whose elements were already tagged with numbers 1 to 5 in
  116. // the `For' loop):
  117. Physical Volume (10) = 186 ;
  118. // We could make only part of the model visible to only mesh this subset:
  119. //
  120. // Hide "*";
  121. // Recursive Show { Volume{129}; }
  122. // Mesh.MeshOnlyVisible=1;

6. t6.geo

  1. /*********************************************************************
  2. *
  3. * Gmsh tutorial 6
  4. *
  5. * Transfinite meshes
  6. *
  7. *********************************************************************/
  8. // Let's use the geometry from the first tutorial as a basis for this one
  9. Include "t1.geo";
  10. // Delete the left line and create replace it with 3 new ones
  11. Delete{ Surface{6}; Line{4}; }
  12. p1 = newp; Point(p1) = {-0.05, 0.05, 0, lc};
  13. p2 = newp; Point(p2) = {-0.05, 0.1, 0, lc};
  14. l1 = newl; Line(l1) = {1, p1};
  15. l2 = newl; Line(l2) = {p1, p2};
  16. l3 = newl; Line(l3) = {p2, 4};
  17. // Create surface
  18. Line Loop(1) = {2, -1, l1, l2, l3, -3};
  19. Plane Surface(1) = {-1};
  20. // Put 20 points with a refinement toward the extremities on curve 2
  21. Transfinite Line{2} = 20 Using Bump 0.05;
  22. // Put 20 points total on combination of curves l1, l2 and l3 (beware that the
  23. // points p1 and p2 are shared by the curves, so we do not create 6 + 6 + 10 =
  24. // 22 points, but 20!)
  25. Transfinite Line{l1} = 6;
  26. Transfinite Line{l2} = 6;
  27. Transfinite Line{l3} = 10;
  28. // Put 30 points following a geometric progression on curve 1 (reversed) and on
  29. // curve 3
  30. Transfinite Line{-1,3} = 30 Using Progression 1.2;
  31. // Define the Surface as transfinite, by specifying the four corners of the
  32. // transfinite interpolation
  33. Transfinite Surface{1} = {1,2,3,4};
  34. // (Note that the list on the right hand side refers to points, not curves. When
  35. // the surface has only 3 or 4 points on its boundary the list can be
  36. // omitted. The way triangles are generated can be controlled by appending
  37. // "Left", "Right" or "Alternate" after the list.)
  38. // Recombine the triangles into quads
  39. Recombine Surface{1};
  40. // Apply an elliptic smoother to the grid
  41. Mesh.Smoothing = 100;
  42. Physical Surface(1) = 1;
  43. // When the surface has only 3 or 4 control points, the transfinite constraint
  44. // can be applied automatically (without specifying the corners explictly).
  45. Point(7) = {0.2, 0.2, 0, 1.0};
  46. Point(8) = {0.2, 0.1, 0, 1.0};
  47. Point(9) = {-0, 0.3, 0, 1.0};
  48. Point(10) = {0.25, 0.2, 0, 1.0};
  49. Point(11) = {0.3, 0.1, 0, 1.0};
  50. Line(10) = {8, 11};
  51. Line(11) = {11, 10};
  52. Line(12) = {10, 7};
  53. Line(13) = {7, 8};
  54. Line Loop(14) = {13, 10, 11, 12};
  55. Plane Surface(15) = {14};
  56. Transfinite Line {10:13} = 10;
  57. Transfinite Surface{15};

t6


7. t7.geo

  1. /*********************************************************************
  2. *
  3. * Gmsh tutorial 7
  4. *
  5. * Background mesh
  6. *
  7. *********************************************************************/
  8. // Characteristic lengths can be specified very accuractely by providing a
  9. // background mesh, i.e., a post-processing view that contains the target mesh
  10. // sizes.
  11. // Merge the first tutorial
  12. Merge "t1.geo";
  13. // Merge a post-processing view containing the target mesh sizes
  14. Merge "bgmesh.pos";
  15. // Apply the view as the current background mesh
  16. Background Mesh View[0];

t7


10. t10.geo

  1. /*********************************************************************
  2. *
  3. * Gmsh tutorial 10
  4. *
  5. * General mesh size fields
  6. *
  7. *********************************************************************/
  8. // In addition to specifying target mesh sizes at the points of the
  9. // geometry (see t1) or using a background mesh (see t7), you can use
  10. // general mesh size "Fields".
  11. // Let's create a simple rectangular geometry
  12. lc = .15;
  13. Point(1) = {0.0,0.0,0,lc}; Point(2) = {1,0.0,0,lc};
  14. Point(3) = {1,1,0,lc}; Point(4) = {0,1,0,lc};
  15. Point(5) = {0.2,.5,0,lc};
  16. Line(1) = {1,2}; Line(2) = {2,3}; Line(3) = {3,4}; Line(4) = {4,1};
  17. Line Loop(5) = {1,2,3,4}; Plane Surface(6) = {5};
  18. // Say we would like to obtain mesh elements with size lc/30 near line 1 and
  19. // point 5, and size lc elsewhere. To achieve this, we can use two fields:
  20. // "Attractor", and "Threshold". We first define an Attractor field (Field[1])
  21. // on points 5 and on line 1. This field returns the distance to point 5 and to
  22. // (100 equidistant points on) line 1.
  23. Field[1] = Attractor;
  24. Field[1].NodesList = {5};
  25. Field[1].NNodesByEdge = 100;
  26. Field[1].EdgesList = {2};
  27. // We then define a Threshold field, which uses the return value of the
  28. // Attractor Field[1] in order to define a simple change in element size around
  29. // the attractors (i.e., around point 5 and line 1)
  30. //
  31. // LcMax - /------------------
  32. // /
  33. // /
  34. // /
  35. // LcMin -o----------------/
  36. // | | |
  37. // Attractor DistMin DistMax
  38. Field[2] = Threshold;
  39. Field[2].IField = 1;
  40. Field[2].LcMin = lc / 30;
  41. Field[2].LcMax = lc;
  42. Field[2].DistMin = 0.15;
  43. Field[2].DistMax = 0.5;
  44. // Say we want to modulate the mesh element sizes using a mathematical function
  45. // of the spatial coordinates. We can do this with the MathEval field:
  46. Field[3] = MathEval;
  47. Field[3].F = "Cos(4*3.14*x) * Sin(4*3.14*y) / 10 + 0.101";
  48. // We could also combine MathEval with values coming from other fields. For
  49. // example, let's define an Attractor around point 1
  50. Field[4] = Attractor;
  51. Field[4].NodesList = {1};
  52. // We can then create a MathEval field with a function that depends on the
  53. // return value of the Attractr Field[4], i.e., depending on the distance to
  54. // point 1 (here using a cubic law, with minumum element size = lc / 100)
  55. Field[5] = MathEval;
  56. Field[5].F = Sprintf("F4^3 + %g", lc / 100);
  57. // We could also use a Box field to impose a step change in element sizes inside
  58. // a box
  59. Field[6] = Box;
  60. Field[6].VIn = lc / 15;
  61. Field[6].VOut = lc;
  62. Field[6].XMin = 0.3;
  63. Field[6].XMax = 0.6;
  64. Field[6].YMin = 0.3;
  65. Field[6].YMax = 0.6;
  66. // Many other types of fields are available: see the reference manual for a
  67. // complete list. You can also create fields directly in the graphical user
  68. // interface by selecting Define->Fields in the Mesh module.
  69. // Finally, let's use the minimum of all the fields as the background mesh field
  70. Field[7] = Min;
  71. Field[7].FieldsList = {2, 3, 5, 6};
  72. Background Field = 7;
  73. // If the boundary mesh size was too small, we could ask not to extend the
  74. // elements sizes from the boundary inside the domain:
  75. // Mesh.CharacteristicLengthExtendFromBoundary = 0;

t10


x. t[x].geo

  1. to be continued...
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注