1# ElmerIce meshing tools
2
3This directory contains meshing tools designed to facilitate the mesh generation of real system
4and the interaction with GIS sofwares.
5
6An example demonstrating the use of *Contour2geo.py* and *MeshToShp.py* can be found
7[here](https://cloud.univ-grenoble-alpes.fr/index.php/s/nFZEEKDDcTg8DD3)
8
9
10## Contour2geo.py
11
12**USAGE :**
13
14```
15python Contour2geo.py -r res [-h] [-i <inputfile>] [-o <outputfile>] [--spline] ')
16```
17
18Generate a [Gmsh](https://gmsh.info) geometry file (.geo) from a closed contour.
19
20The countour can be provided as :
21
22- an ASCII file with x,y cordinates.
23
24- a shapefile: either a single polygon or a collection of polylines.
25
26By default the contour is a Gmsh *compound line*, i.e. the mesh will exactly follow the contour nodes.
27In case of a very complex curved contour it might be interesting to *simplify* the contour, to avoid over-refinement.
28
29*Splines* can be used with the argument **--spline**, but it may be less accurate to really track the countour and may leed to loops.
30
31The mandatory *-r* argument prescribe the uniform mesh resolution. The mesh size is prescribed at the boundary nodes
32and by prescribing a uniform background field.
33
34Once created the .geo can be edited to change the default values (see Gmsh documentation).
35
36Mesh your file using:
37```
38## basic gmsh
39gmsh -2 [-format msh2] <outputfile>
40## convert to Elmer mesh
41ElmerGrid 14 2 [msh filename] -autoclean
42```
43
44If the input file contains only one feature (ASCII file or shapefile with 1 polygon or 1 polyline), there will be only
45one boundary condition type. Otherwise (in case of several polylines) each feature will be attributed
46a *physical* identification.
47
48If there is several polylines they must form an ordered closed countour.
49If the attribute *BC* (integer) is present, the program will use this attribute *BC* to order the lines as shown in the picture:
50![](images/Example.png "See line orientation and order of the BC attribute")
51
52In general, the workflow in a GIS sofware will be as follow:
53
54- Create a polygon feature of you domain
55- Convert the *polygon* to *lines*
56- Split the lines where you want to define different boundary conditions
57- Check that all the lines have the same orientation (you can reverse the orientation of the lines)
58- Enventualy create the attribute BC (integer) and give the value so that the *BC* form a continuous closed contour
59
60
61
62## MeshToShp.py
63
64**USAGE :**
65
66```
67python MeshToShp.py  [-h] -d <inputdir>
68```
69
70Generate shapefiles for the boundaries (polyline) and elements (polygons)
71from a serial 2D Elmer mesh stored under *<inputdir>*
72
73Shapefiles are stored under a new directory *<inputdir>_shp*.
74
75Attributes are:
76
77- *BodyId* or *BCId*: the *body* or *BC* identification
78- *etype* : the element type
79- *enum* : the element number
80
81
82## External resssources:
83
84- [QGIS gmsh plugin](https://plugins.qgis.org/plugins/gmsh)
85