5
$\begingroup$

I want to write a 2D FEA code for my course project and I need to import a mesh (2d, simple quad/tri) on a simple geometry such as a L shaped plate or with a square/circular hole in it, something like that.

As I want to write my own code, I need to read the mesh file in my code hence looking for a simple format which specifies element connectivity and help identify boundary nodes (to apply boundary conditions).

It will be really great if you can point out some easy to use/understand tool for this purpose with good documentation on mesh format.

Thank you, Pranav

Edit:

The GMSH is perfectly suited for the use I intended.

Older Edit:

I found this tentative workaround for the problem but is certainly not a solution:

The important part of the file is the information of nodes on corresponding boundaries. I'm using ANSYS DesignModeler and Static structural module in ANSYS Workbench. I'm creating the geometry in DesignModeler and meshing it in ANSYS Meshing which is inside static structural module. You can specify boundaries using Named Selection so that you can apply loads later. After generating the mesh, you can export the input file for an older ANSYS APDL from Tools menu which export a ASCII ".dat" file which has the mesh information and all the problem setup. I removed all unnecessary details to get following results. Now I can easily write a function to read this file.

#Nodes
        1    0.000000000E+000    1.000000000E+001    0.000000000E+000
        2    0.000000000E+000    0.000000000E+000    0.000000000E+000
        3    0.000000000E+000    8.888888889E+000    0.000000000E+000
        4    0.000000000E+000    7.777777778E+000    0.000000000E+000
        5    0.000000000E+000    6.666666667E+000    0.000000000E+000
        6    0.000000000E+000    5.555555556E+000    0.000000000E+000
        7    0.000000000E+000    4.444444444E+000    0.000000000E+000
        8    0.000000000E+000    3.333333333E+000    0.000000000E+000
        9    0.000000000E+000    2.222222222E+000    0.000000000E+000
       10    0.000000000E+000    1.111111111E+000    0.000000000E+000
       11    5.000000000E+000    0.000000000E+000    0.000000000E+000
       12    1.000000000E+000    0.000000000E+000    0.000000000E+000
       13    2.000000000E+000    0.000000000E+000    0.000000000E+000
       14    3.000000000E+000    0.000000000E+000    0.000000000E+000
       15    4.000000000E+000    0.000000000E+000    0.000000000E+000
       16    5.000000000E+000    5.000000000E+000    0.000000000E+000
       17    5.000000000E+000    1.000000000E+000    0.000000000E+000
       18    5.000000000E+000    2.000000000E+000    0.000000000E+000
       19    5.000000000E+000    3.000000000E+000    0.000000000E+000
       20    5.000000000E+000    4.000000000E+000    0.000000000E+000
       21    1.000000000E+001    5.000000000E+000    0.000000000E+000
       22    6.000000000E+000    5.000000000E+000    0.000000000E+000
       23    7.000000000E+000    5.000000000E+000    0.000000000E+000
       24    8.000000000E+000    5.000000000E+000    0.000000000E+000
       25    9.000000000E+000    5.000000000E+000    0.000000000E+000
       26    1.000000000E+001    1.000000000E+001    0.000000000E+000
       27    1.000000000E+001    6.000000000E+000    0.000000000E+000
       28    1.000000000E+001    7.000000000E+000    0.000000000E+000
       29    1.000000000E+001    8.000000000E+000    0.000000000E+000
       30    1.000000000E+001    9.000000000E+000    0.000000000E+000
       31    8.888888889E+000    1.000000000E+001    0.000000000E+000
       32    7.777777778E+000    1.000000000E+001    0.000000000E+000
       33    6.666666667E+000    1.000000000E+001    0.000000000E+000
       34    5.555555556E+000    1.000000000E+001    0.000000000E+000
       35    4.444444444E+000    1.000000000E+001    0.000000000E+000
       36    3.333333333E+000    1.000000000E+001    0.000000000E+000
       37    2.222222222E+000    1.000000000E+001    0.000000000E+000
       38    1.111111111E+000    1.000000000E+001    0.000000000E+000
       39    3.100885795E+000    6.940821089E+000    0.000000000E+000
       40    3.883906237E+000    7.027860768E+000    0.000000000E+000
       41    3.017869238E+000    6.161626033E+000    0.000000000E+000
       42    4.850074589E+000    7.040770750E+000    0.000000000E+000
       43    5.864808320E+000    7.043474312E+000    0.000000000E+000
       44    6.897973722E+000    7.037079226E+000    0.000000000E+000
       45    4.014156390E+000    6.025411191E+000    0.000000000E+000
       46    2.984856810E+000    5.187710894E+000    0.000000000E+000
       47    2.963924128E+000    4.159491948E+000    0.000000000E+000
       48    2.954305198E+000    3.113634563E+000    0.000000000E+000
       49    2.966833201E+000    2.070582688E+000    0.000000000E+000
       50    1.954872141E+000    3.206756202E+000    0.000000000E+000
       51    1.964133590E+000    4.280955357E+000    0.000000000E+000
       52    1.987442885E+000    5.363330639E+000    0.000000000E+000
       53    2.037966141E+000    6.460608169E+000    0.000000000E+000
       54    2.369722555E+000    7.667980533E+000    0.000000000E+000
       55    3.585407332E+000    7.997051341E+000    0.000000000E+000
       56    4.672581651E+000    8.037841747E+000    0.000000000E+000
       57    5.733421173E+000    8.044844080E+000    0.000000000E+000
       58    6.801325531E+000    8.036846126E+000    0.000000000E+000
       59    7.868898928E+000    8.028595372E+000    0.000000000E+000
       60    7.925684523E+000    7.023684703E+000    0.000000000E+000
       61    1.963418650E+000    2.132912786E+000    0.000000000E+000
       62    4.968222423E+000    6.024805920E+000    0.000000000E+000
       63    5.950275027E+000    6.023627968E+000    0.000000000E+000
       64    6.960337601E+000    6.022422539E+000    0.000000000E+000
       65    7.971188476E+000    6.011697947E+000    0.000000000E+000
       66    8.927457869E+000    8.014515675E+000    0.000000000E+000
       67    8.961487394E+000    7.010908471E+000    0.000000000E+000
       68    2.983632029E+000    1.037919977E+000    0.000000000E+000
       69    1.984671847E+000    1.070964476E+000    0.000000000E+000
       70    9.864873052E-001    1.087871232E+000    0.000000000E+000
       71    9.783216106E-001    2.183930277E+000    0.000000000E+000
       72    9.782477164E-001    3.284728024E+000    0.000000000E+000
       73    9.781132470E-001    4.382433521E+000    0.000000000E+000
       74    9.974305756E-001    5.503140644E+000    0.000000000E+000
       75    1.072256462E+000    6.644678490E+000    0.000000000E+000
       76    1.150918303E+000    7.757754861E+000    0.000000000E+000
       77    1.153760333E+000    8.870140771E+000    0.000000000E+000
       78    2.272715412E+000    8.874785514E+000    0.000000000E+000
       79    3.378616377E+000    8.955660205E+000    0.000000000E+000
       80    4.521905029E+000    9.017703001E+000    0.000000000E+000
       81    5.627472506E+000    9.027073068E+000    0.000000000E+000
       82    6.720590452E+000    9.025172424E+000    0.000000000E+000
       83    7.808554241E+000    9.018864371E+000    0.000000000E+000
       84    8.908424832E+000    9.011734730E+000    0.000000000E+000
       85    8.986541286E+000    6.005180504E+000    0.000000000E+000
       86    3.993993695E+000    5.054644401E+000    0.000000000E+000
       87    3.975665129E+000    4.060554879E+000    0.000000000E+000
       88    3.974355784E+000    3.051025159E+000    0.000000000E+000
       89    3.980336212E+000    2.026422574E+000    0.000000000E+000
       90    3.990475831E+000    1.010320637E+000    0.000000000E+000
-1

#Elements
        1       39       54       53       41
        2       39       40       55       54
        3       41       45       40       39
        4       45       62       42       40
        5       41       46       86       45
        6       40       42       56       55
        7       53       52       46       41
        8       42       43       57       56
        9       42       62       63       43
       10       43       44       58       57
       11       43       63       64       44
       12       44       60       59       58
       13       44       64       65       60
       14       86       16       62       45
       15       52       51       47       46
       16       47       87       86       46
       17       51       50       48       47
       18       48       88       87       47
       19       50       61       49       48
       20       49       89       88       48
       21       49       68       90       89
       22       61       69       68       49
       23       50       72       71       61
       24       51       73       72       50
       25       52       74       73       51
       26       53       75       74       52
       27       54       76       75       53
       28       54       78       77       76
       29       55       79       78       54
       30       56       80       79       55
       31       57       81       80       56
       32       58       82       81       57
       33       59       83       82       58
       34       59       66       84       83
       35       60       67       66       59
       36       65       85       67       60
       37       71       70       69       61
       38       62       16       22       63
       39       63       22       23       64
       40       64       23       24       65
       41       65       24       25       85
       42       66       29       30       84
       43       67       28       29       66
       44       85       27       28       67
       45       68       14       15       90
       46       69       13       14       68
       47       70       12       13       69
       48       70       10        2       12
       49       71        9       10       70
       50       72        8        9       71
       51       73        7        8       72
       52       74        6        7       73
       53       75        5        6       74
       54       76        4        5       75
       55       77        3        4       76
       56       77       38        1        3
       57       78       37       38       77
       58       79       36       37       78
       59       80       35       36       79
       60       81       34       35       80
       61       82       33       34       81
       62       83       32       33       82
       63       84       31       32       83
       64       84       30       26       31
       65       85       25       21       27
       66       87       20       16       86
       67       88       19       20       87
       68       89       18       19       88
       69       90       17       18       89
       70       90       15       11       17
-1

#NamedSelection
BOTTOM  NODE     6
         2        11        12        13        14        15


#NamedSelection
TOP    NODE       10
         1        26        31        32        33        34        35        36
        37        38

#NamedSelection
RIGHT_SIDE  NODE      6
        21        26        27        28        29        30


#End
$\endgroup$
10
$\begingroup$

I would recommend gmsh. I have just started working with this program actually only a few days ago. But it is straight-forward to use. You can create various 2D and even 3D-geometries and it offers a ton of information, boundary nodes, etc..

Here is a link to the website: http://geuz.org/gmsh/

They have many useful references, there is a manual of course and also a mailing list archive that I have to be somewhat useful.

Basically as I understand, you can use the program in a CAD-Like way, i.e. drawing points, lines. Or you can program the information in by hand. I have taking the programming route.

Here is another good reference to get started: https://github.com/FluidityProject/fluidity/wiki/Gmsh-tutorial

Update: Alright, well the node locations and element information can be found in a .txt file by doing the following. Once gmsh is up and running, with a .msh file open(I'm using 2.8.4) go to the Geometry tab and then Edit file. This opens a .txt with the information.

I have yet to figure out how to interpret the element information.

Good luck!

$\endgroup$
  • $\begingroup$ Hi, thank you for recommending gmesh...how do you identify boundary nodes? I tried to identify lines in "Physical Group" under "Geometry" but I could not see them in the mesh file. I could see only node list and element list. It will be really helpful if you can help. Thanks! $\endgroup$ – Pranav Nov 22 '14 at 23:10
  • $\begingroup$ I am honestly not sure. I am new to gmsh as well. I will try to figure this out. $\endgroup$ – wgwz Nov 23 '14 at 0:58
  • $\begingroup$ You can see physical groups in the file. They are listed as some of the properties each node/element has. $\endgroup$ – nicoguaro Nov 23 '14 at 18:58
  • 3
    $\begingroup$ I have an example (hand-written) .geo input file into a previous answer about mesh generation. It should show you some basic functionality of gmsh. scicomp.stackexchange.com/questions/11590/… $\endgroup$ – Tyler Olsen Nov 24 '14 at 21:22
  • 1
    $\begingroup$ If you look in the ascii file format specification for the gmsh's .msh files, you will see that each element has a set of "tags" associated with it. The physical number of the element is stored as the first tag (I believe, just experiment with it on a small mesh). This indicates that all nodes in that element belong to that Physical entity. It isn't too hard to write a function to parse their text files, especially in a high-level language like python or matlab. geuz.org/gmsh/doc/texinfo/gmsh.html#File-formats $\endgroup$ – Tyler Olsen Nov 27 '14 at 8:26
4
$\begingroup$

If you have access to MATLAB, you might consider using PDE Toolbox to generate your geometry and mesh:

http://www.mathworks.com/help/pde/index.html

It is very easy to generate simple geometries like the ones you describe by doing boolean operations on primitive shapes. The output mesh is described by three MATLAB arrays: node locations, element connectivity, and a matrix of boundary edges.

http://www.mathworks.com/help/pde/ug/initmesh.html

$\endgroup$
2
$\begingroup$

Another option not mentioned yet is NetGen:

http://www.hpfem.jku.at/netgen/

http://sourceforge.net/projects/netgen-mesher/

It supports CSG (constructive solid geometry) and can output 2D and 3D meshes. A number of output formats are supported and described in the documentation PDF.

$\endgroup$
0
$\begingroup$

If available to you, Mathematica version 10 offers a PDE solving framework based on the finite element method which is build in. There are tutorials about mesh generation and visualization. The concept is based on two functions ToBoundaryMesh and ToElementMesh both generating the ElementMesh data structure. This data structure can then be queried for connectivity, boundary elements. Here is a simple manual example:

Needs["NDSolve`FEM`"]
mesh = ToElementMesh[
  "Coordinates" -> {{1.293, 0.228}, {1., 0.}, {0.94, 0.342}, {1.293, 
     0.}, {1.215, 0.442}, {2., 0.}, {1.879, 0.684}}, 
  "MeshElements" -> {TriangleElement[{{1, 3, 2}, {1, 2, 4}, {1, 4, 
       6}, {1, 6, 7}, {1, 7, 5}, {1, 5, 3}}]}]

Visualize a wireframe:

mesh["Wireframe"]

enter image description here

Compute the element connectivity:

mesh["ElementConnectivity"]
{{{0, 2, 6}, {0, 3, 1}, {0, 4, 2}, {0, 5, 3}, {0, 6, 4}, {0, 1, 5}}}

Get the points on the boundary:

mesh["PointElements"]
{PointElement[{{2}, {3}, {4}, {5}, {6}, {7}}]}

Boolean operations are available as well as are many other things. For example you may tag elements with markers, for example to group different material or boundaries together.

If you like to work with meshes on an even lower level, then there are interfaces to the mesh generators Triangle via TriangleLink and TetGen via TetGenLink

If you want to double check your implementation you could make use of the Finite Element Programming functionality.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.