Skip to content

Commit

Permalink
Added gmsh tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
wallytutor committed May 14, 2024
1 parent 1648a0c commit 7a05bd7
Show file tree
Hide file tree
Showing 24 changed files with 60,354 additions and 0 deletions.
93 changes: 93 additions & 0 deletions apps/Gmsh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Gmsh

The original files were copied from `share/doc/gmsh/tutorials` directory from
Gmsh installation directory. During the course of the tutorials I have edited
and most likely cleaned-up/minified the files because that is part of my
learning methodology.

## Topics

1. [Geometry basics, elementary entities, physical groups](t1.geo)

1. [Transformations, extruded geometries, volumes](t2.geo)
- Getting coordinates of points
- How to export an unrolled geometry file

1. [Extruded meshes, ONELAB parameters, options](t3.geo)
- Extrusion with default kernel is limited to `Pi` radians
- OpenCASCADE kernel allows for any size of rotation
- Defining constants with ONELAB
- ONELAB parameters can be overridden through CLI `-setnumber <var> <val>`
- Setting general parameters in scripts

1. [Built-in functions, holes in surfaces, annotations, entity colors](t4.geo)
- As for rotation, circle arcs are also limited in default kernel
- A surface with `N` holes needs `N+1` curve loops to be defined
- The first curve loop defines the external shell of the surface
- A `View` can be created for annotations, *i.e.* for presentations
- Click capture may be useful for getting surfaces in complex geometries

1. [Mesh sizes, macros, loops, holes in volumes](t5.geo)
- Scaling of all mesh dimensions can be done with `-clscale <val>`

1. [Transfinite meshes, deleting entities](t6.geo)
- Use `Delete` for removing `Surface` and `Curve` entities
- With `Transfinite Curve` specify the number of grid points over a curve
- Transfinite of more than 4 points need 4 corners to be provided manually
- Use `Mesh.Smoothing` to apply smoothing for a more regular mesh

1. [Background meshes](t7.geo)
- Mesh sizes can be specified accurately by providing a background mesh
- Background meshes *BM* are composed, *e.g* of scalar triangles `ST`
- If the *BM* is based on an actual mesh, create `NewModel` (see comment)

1. [Post-processing, image export and animations](t8.geo)
- In Gmsh a `View` is a post-processing dataset maniputation
- For large datasets do not use *parsed* format, but MSH instead
- Text in 2D and 3D are created with `T2` and `T3` (also see t4.geo)
- It is possible to export animations directly from *time steps*

1. [Plugins](t9.geo)
- Interesting maniputation but need to check how to get any data

1. [Mesh size fields](t10.geo)
- Combining `Distance` and `Threshold` we can refine mesh near features
- Using `Mesh.Algorithm = 5;` is recommended for complex gradients of mesh

1. [Unstructured quadrangular meshes](t11.geo)
- Recombination of all surfaces with `Recombine Surface {:};`
- Alternativelly one can use `Mesh.RecombineAll` flag
- `Mesh.Algorithm = 8;` allows mostly right triangles
- Algorithm can be controlled through `Mesh.RecombinationAlgorithm`

1. [Cross-patch meshing with compounds](t12.geo)
- Curves and surfaces can be enforced to be meshed as a whole.
- Limited to simple shapes, for more complex the next see the tutorials.

1. [Remeshing an STL file without an underlying CAD model](t13.geo)

1. [Homology and cohomology computation](t14.geo)

1. [Embedded points, lines and surfaces](t15.geo)

1. [Constructive Solid Geometry, OpenCASCADE geometry kernel](t16.geo)

1. [Anisotropic background mesh](t17.geo)

1. [Periodic meshes](t18.geo)

1. [Thrusections, fillets, pipes, mesh size from curvature](t19.geo)

1. [STEP import and manipulation, geometry partitioning](t20.geo)

1. [Mesh partitioning](t21.geo)

## Projects

- [x] Conceive a reasonably complex mesh with boundary layers
- [ ] Use a STL file exported from external CAD/Blender for 3D meshing
- [ ] Create a progressive tutorial with all learned resources but for a fixed geometry

## Useful links

- [Tutorial by SAE Miller](https://www.youtube.com/playlist?list=PLbiOzt50Bx-l2QyX5ZBv9pgDtIei-CYs_)
54 changes: 54 additions & 0 deletions apps/Gmsh/project1/ex01-boundary-layer.geo
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Experimentation with boundary layer.
SetFactory("OpenCASCADE");
General.Axes = 3;

Point(1) = {0.00, 0.00, 0};
Point(2) = {2.00, 0.20, 0};
Point(3) = {2.00, 0.80, 0};
Point(4) = {0.00, 1.00, 0};

Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};
Circle(5) = {0.5, 0.5, 0, 0.1, 0, 2*Pi};

Curve Loop(1) = {1, 2, 3, 4};
Curve Loop(2) = {5};
Plane Surface(1) = {1, 2};

Transfinite Curve {1, 3} = 30;
Transfinite Curve {2, 4} = 30;
Transfinite Curve {5} = 30;
Recombine Surface {1};

Field[0] = BoundaryLayer;
Field[0].CurvesList = {1, 3, 5};
Field[0].PointsList = {1, 2, 3, 4};
Field[0].AnisoMax = 1.0e+10;
Field[0].Quads = 1;
Field[0].IntersectMetrics = 1;
Field[0].Ratio = 1.2;
Field[0].Size = 0.005;
Field[0].SizeFar = 0.05;
Field[0].Thickness = 0.05;
BoundaryLayer Field = 0;

Mesh.Algorithm = 8;
Mesh.MeshSizeMax = 0.05;
Mesh.MeshSizeFromPoints = 0;
Mesh.MeshSizeExtendFromBoundary = 1;
Mesh.MeshSizeFromCurvature = 0;
Mesh.Smoothing = 100;

Mesh 2;
RefineMesh;

// Other fields from BoundaryLayer:
// Field[0].Beta = 1.01;
// Field[0].BetaLaw = 0;
// Field[0].NbLayers = 5;
// Field[0].ExcludedSurfacesList = {};
// Field[0].FanPointsList = {};
// Field[0].FanPointsSizesList = {};
// Field[0].SizesList = {};
127 changes: 127 additions & 0 deletions apps/Gmsh/project1/ex02-internal-flaps.geo
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// Experimentation with internal flaps.
SetFactory("OpenCASCADE");
General.Axes = 3;

Point(1) = {0.00, 0.00, 0};
Point(2) = {2.00, 0.25, 0};
Point(3) = {2.00, 0.75, 0};
Point(4) = {0.00, 1.00, 0};

Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};
Circle(5) = {0.5, 0.5, 0, 0.1, 0, 2*Pi};

c0 = newl; Curve Loop(c0) = {1, 2, 3, 4};
c1 = newl; Curve Loop(c1) = {5};
theloops[0] = c0;
theloops[1] = c1;

FIRSTLAYER = 0.001;
MAXSIZE = 0.015;

NEXTFIELD = 0;
NEXTFLAP = #theloops[];

Macro AddInternalFlap
// Arguments:
// - xc : (x, y) coordinates of central point [m] (0, 1)
// - dims : thickness, width [m] (2, 3)
// - angle : clockwise angle with horizontal [°] (4)
xc[] = {pars[0], pars[1]};
dims[] = {pars[2], pars[3]};
angle = pars[4];

theta = Pi/2 * (1 - angle/90);
gamma = Pi/2 - theta;

reccord = 0.5 * Hypot(dims[0], dims[1]);
alpha = theta + Atan(dims[1] / dims[0]);

x0[] = {xc[0] - reccord * Cos(alpha), xc[1] - reccord * Sin(alpha)};
x1[] = {x0[0] + dims[0] * Cos(theta), x0[1] + dims[0] * Sin(theta)};
x2[] = {x1[0] - dims[1] * Cos(gamma), x1[1] + dims[1] * Sin(gamma)};
x3[] = {x2[0] - dims[0] * Cos(theta), x2[1] - dims[0] * Sin(theta)};

Printf("*** Flap No. %d", NEXTFLAP);
Printf("Center ---> (%.3f, %.3f)", xc[0], xc[1]);
Printf(" x0 ---> (%.3f, %.3f)", x0[0], x0[1]);
Printf(" x1 ---> (%.3f, %.3f)", x1[0], x1[1]);
Printf(" x2 ---> (%.3f, %.3f)", x2[0], x2[1]);
Printf(" x3 ---> (%.3f, %.3f)", x3[0], x3[1]);

p0 = newp; Point(p0) = {x0[0], x0[1], 0};
p1 = newp; Point(p1) = {x1[0], x1[1], 0};
p2 = newp; Point(p2) = {x2[0], x2[1], 0};
p3 = newp; Point(p3) = {x3[0], x3[1], 0};

l0 = newl; Line(l0) = {p0, p1};
l1 = newl; Line(l1) = {p1, p2};
l2 = newl; Line(l2) = {p2, p3};
l3 = newl; Line(l3) = {p3, p0};

ck = newl; Curve Loop(ck) = {l0, l1, l2, l3};
theloops[NEXTFLAP++] = ck;

idf = NEXTFIELD++;
Field[idf] = BoundaryLayer;
Field[idf].CurvesList = {l0, l1, l2, l3};
Field[idf].AnisoMax = 1.0e+10;
Field[idf].Quads = 1;
Field[idf].IntersectMetrics = 1;
Field[idf].Ratio = 1.2;
Field[idf].Size = 4*FIRSTLAYER;
Field[idf].SizeFar = MAXSIZE;
Field[idf].Thickness = 40*FIRSTLAYER;

BoundaryLayer Field = idf+0;
Return

pars[] = {1.0, 0.5, 0.1, 0.50, 90.0};
Call AddInternalFlap;

pars[] = {1.5, 0.5, 0.1, 0.40, 90.0};
Call AddInternalFlap;

Plane Surface(1) = {theloops[]};

Transfinite Curve {1, 3} = 90;
Transfinite Curve {2, 4} = 50;
Transfinite Curve {5} = 20;
Recombine Surface {1};

Field[666] = BoundaryLayer;
Field[666].CurvesList = {1, 3, 5};
Field[666].PointsList = {1, 2, 3, 4};
Field[666].AnisoMax = 1.0;
Field[666].Quads = 1;
Field[666].IntersectMetrics = 1;
Field[666].Ratio = 1.2;
Field[666].Size = FIRSTLAYER;
Field[666].SizeFar = MAXSIZE;
Field[666].Thickness = 60*FIRSTLAYER;
BoundaryLayer Field = 666;

Extrude {0, 0, 0.1} { Surface{1}; Layers{1}; Recombine; }

Physical Volume("volume") = {1};
Physical Surface("frontAndBack") = {1, 15};
Physical Surface("inlet") = {5};
Physical Surface("outlet") = {3};
Physical Surface("shell") = {2, 4};
Physical Surface("cylinder") = {6};
Physical Surface("flap1") = {7, 8, 9, 10};
Physical Surface("flap2") = {11, 12, 13, 14};

Mesh.Algorithm = 8;
Mesh.MeshSizeMax = MAXSIZE;
Mesh.MeshSizeFromPoints = 0;
Mesh.MeshSizeExtendFromBoundary = 1;
Mesh.MeshSizeFromCurvature = 0;
Mesh.Smoothing = 100;
// Mesh.SaveAll = 1;
// Mesh.MshFileVersion = 2.2;
// Mesh 3;

// Save "geometry.msh2";
Loading

0 comments on commit 7a05bd7

Please sign in to comment.