calfem mesh module manual

28
CALFEM meshing module Division of Structural Mechanics & Division of Solid Mechanics Lund Institute of Technology 0–1

Upload: johan-lorentzon

Post on 02-Apr-2015

1.011 views

Category:

Documents


20 download

DESCRIPTION

This is an unofficial release of the manual for Mesh module for CALFEM, uploaded with permission by Per Erik Austrell and Kent Persson at LTH. The author is Johan Lorentzon. The source of the matlab code can be found in the trunk of the CALFEM development section at sourgeforge. The mesh generation is at current version restricted to 2D but applications has been made for 3D as well. The mesh package handle unstructured and structured grid generation, flexible manipulations as smoothing, mesh quality improving, rotating, scaling and translating the mesh allows the user to create complicated mesh structures of high quality with minimal effort. This manual present the basic part of the code with only few advanced example. In future release, 3D applications, with focus on adaptation, quality mesh will be the main topic, with extensive applications and example routines.

TRANSCRIPT

Page 1: CALFEM Mesh module Manual

CALFEM meshing module

Division of Structural Mechanics & Division of Solid Mechanics

Lund Institute of Technology

0 – 1

Page 2: CALFEM Mesh module Manual

Introduction

The functions in this module makes it possible to generate a two dimensional mesh withsmall effort. It also allows extraction and manipulation of the mesh with operations suchas degree of freedom extraction, mesh merging, conversion between quadrilateral and tri-angular elements, improvement and control of mesh quality etc.

Mesh properties

Meshing involves the division of a physical domain, into smaller domains - elements -described by nodes. The connection to the physical space is achieved trough the globalnodal coordinate matrix Coord. This matrix is a list of global coordinates for each node inthe mesh. In each node a certain number of degrees of freedom are present. A key featurethat characterize the mesh is the connectivity matrix, the global degree of freedom matrixEdof associating the degrees of freedom of each element to the global degree of freedommatrix Dof . The later being a list of global nodal degrees of freedom.

Figure 1: Example of nodal coordinates, and degrees of freedom, elements using triangularelements and two degrees of freedom per node.

For the mesh in Figure 1, the matrices mentioned are as follows:

Coord =

0. 0.1. 0.0. 1.1. 1.0. 2.1. 2.

Dof =

9 1011 125 67 81 23 4

Edof =

1 3 4 1 2 5 62 5 6 7 8 3 43 9 10 7 8 5 64 9 10 11 12 7 8

0 – 1 Introduction

Page 3: CALFEM Mesh module Manual

Mesh generation

The mesh geometry

In order to generate these matrices for a large number of elements, the physical domain tobe meshed has to be defined systematically. In this module the mesh geometry is definedusing the basic concepts of vertices, segments, and surfaces.

A vertex is a corner point of a (sub)domain. Two consecutive vertices define a segmentand several enclosing consecutive segments of a given convex (sub)domain defines a surface.A physical domain is divided into surfaces with shared corner points. This surface do-main description is also known as conform multi-block method. Consider the example in

0 0.5 1 1.5 2 2.5 3 3.5 4

−0.5

0

0.5

1

1.5

2

2.5

1

2

1(5)

2(15)

3(5)

4(5)

5(5)

6(15)

7(5)

1

2 3

45

6

Figure 2: A surface description of a domain. The domain is divided into two surfaces usingseven segments and six vertices.

Figure 2 showing a domain with two surfaces, seven segments and six vertices (surfacenumbers are shown in a square and segment numbers are shown underlined). The basicmesh geometry for this case is defined by the matrices

Vertices =

0. 2.4. 2.4. 0.3. 0.3. 1.0. 1.

Segments =

6 11 22 33 44 55 65 2

Surfaces =

[7 6 1 24 5 7 3

](1)

Introduction 0 – 2

Page 4: CALFEM Mesh module Manual

The vertices matrix is a coordinate list. The numbers (followed by a dot) on each row arethe coordinates of the vertices, numbered in the order shown in Figure 2. The segmentmatrix is a vertices list, with the vertex numbers of the segments on each row. Finally, thesurface matrix is a segment list with rows containing segment numbers for each surface.

The mesh generation

There are two possibilities when meshing a particular domain. The mesh can either be of astructured kind with a pre defined number and location of elements, using the strMeshgenfunction or it can be of an unstructured kind, using the unstrMeshgen function.

Using the strMeshgen function with the surface defined domain, the matrices in (1),as input variables and also specifying 15 elements on segment 1, 5 elements on segment2, etc, yields the mesh in Figure 3. The unstructured meshing approach is conducted in

0 0.5 1 1.5 2 2.5 3 3.5 4

−0.5

0

0.5

1

1.5

2

2.5

x

y

Figure 3: Structured mesh from two surfaces with triangular elements.

a similar fashion. The figure 4 illustrates a boundary defined domain. The matrices in(1) are (accordingly) slightly changed, meaning that segment 7 is dropped in the segmentsmatrix and that the surface matrix will be reading,

Surfaces =[

1 2 3 4 5 6]. (2)

Using the unstrMeshgen function with the modified geometry matrices and an informationabout the approximate element size generates the mesh shown in Figure 5

0 – 3 Introduction

Page 5: CALFEM Mesh module Manual

0 0.5 1 1.5 2 2.5 3 3.5 4

−0.5

0

0.5

1

1.5

2

2.5

1

2 3

4

5

6

7

81

2 3 4

5

67

8

Figure 4: one surface description of a domain.

0 0.5 1 1.5 2 2.5 3 3.5 4

−0.5

0

0.5

1

1.5

2

2.5

x

y

Figure 5: unstructured mesh with triangular elements with one surface.

Introduction 0 – 4

Page 6: CALFEM Mesh module Manual

More meshing tools

Functions for displaying basic mesh geometry, extracting degrees of freedom, manipulatingthe mesh, etc are described next.

Basic mesh geometry display

The geometric representation of basic mesh data such as the matrices given in (1), canbe displayed by the function geomdraw2. Using this function with the matrices in (1) asinput, together with information on how many elements there should be on each segmentfor the purpose of estimate the number of element for given geometry, displays a geometryplot according to Figure 2. The number refer to the index in each matrices and to beused with the extraction functions described below. Figure 6 illustrate the geomdraw2 ona triangle domain.

0.2 0.4 0.6 0.8 1

1

1(5)

2(5)

3(5)

2

3

4

−1 −0.5 0 0.5 1

−1

−0.5

0

0.5

1

1.5

2

x

y

Figure 6: Illustration of using mesh of a triangle to generate a half circle using stitchMesh.The geomdraw2 (left) displays the input given strMeshgen and by apply stitchMesh twiceon the triangle to generate the half circle (right).

Curved segments

The structured meshing is a four/eight point mapping from a computational domain on thephysical domain. The four point assumes straight segments while eight points associatesto each segment an additional point added to the point list, and a curve is interpolatedfrom these three points. The number of the point is added to a separate list, the segmentproperty list. Figure 6 illustrates the curved segments of a hole in a square shape and thesurface description used for this.

0 – 5 Introduction

Page 7: CALFEM Mesh module Manual

Extraction functions

The vertices mentioned earlier are examples of points needed in order to define the mesh.However, these are only a subset of the point list generally needed in a finite elementcalculation. Loading points, constraint points etc also have to be defined and included inthe point list.

Knowing particular degrees of freedom at various points, segments, and surfaces andalso knowing element numbers at surfaces in the mesh are essential in finite element anal-ysis. For example if a point load should be applied at a specific point, this point has tobe defined as a fixed point in the mesh and the degrees of freedom at that node has to beknown for the load application. Another example, if a boundary condition is to be appliedat a part of the boundary in a particular direction, these degrees of freedom need to beknown and extracted from a pre defined segment associated with that part of the boundary.Or if a model contain more than one material definition, the mesh has to be characterizedwith different surfaces for each material. The element numbers of these elements need to beextracted, thus making it possible to assign a certain material property to these elements.These are a few example of what a meshing tool should provide in order to avoid the verytedious work of finding the correct degree of freedom in a long list of numbers.

The meshing tools available for these operations are the extraction functions workingon points, segments, and surfaces. The functions are extrPoint, extrSeg, and extrSurf.The output from the two first functions are the degrees of freedom of specified points andsegments respectively. The second also yields the point numbers of the segments. Thethird function yields the element numbers and the point numbers of specified surfaces.

Mesh manipulation functions

Apart from the extraction functions there are also functions for mesh manipulation, such asthe mergeMesh, refineMesh, convertMesh, stitchMesh and so forth. Using these it is possibleto merge two meshes, refine a mesh by element division, and convert between triangularand quadrilateral elements. Figure 6 illustrates the stitchMesh. Moreover, functions forimproving mesh quality ie correctMesh and smoothMesh, are also available.

Other mesh functions

All information about the mesh geometry and its properties are stored in a mesh data baseusing the structured variable concept in MATLAB. This makes it possible to transfer allinformation about the mesh using only one variable. Knowledge of structured variablesis not necessary in order to use the mesh functions in this module. However, informationin terms of the matrices discussed previously can be derived from the data base using thefunction DBextract. Finally there is a function for estimating the quality of generatedmeshes. The checkMesh function delivers an objective measure of the mesh quality calledthe q-factor and calculates the area of each element.

Introduction 0 – 6

Page 8: CALFEM Mesh module Manual

Manual pages

The functions available are described in detail in this section. Further information as func-tional dependencies within the package is obtained by typing at command prompt helpfunction name. A general feature for all but geomdraw2 is the place holder meshdb vari-able that can replace input and output.

Meshing Functions

geomdraw2 show mesh geometry and basic mesh datastrMeshgen structured mesh generationunstrMeshgen unstructured mesh generation

mergeMesh merge meshesstitchMesh stitch meshes togetherrefineMesh refines the mesh by midpoint section methodconvertMesh conversion between triangular and quadrilateral meshcorrectMesh correct for quadrilaterals/triangle improper elements to improve

qualitysmoothMesh smooth the mesh to improve quality

extrPoint extract dofs at selected pointsextrSeg extract dofs, and points at selected segmentsextrSurf extract element numbers, and segments of a selected surface

DBextract extract coord, edof, dofs from mesh data base

checkMesh compute area of domain, quality of element/nodes (q factor)

NOTE:

Before generating the mesh, use geomdraw2 to validate that the proper settings aredone.

0 – 1 Manual pages

Page 9: CALFEM Mesh module Manual

geomdraw2 Manual pages

Purpose:

Displays the basic geometry for the mesh in order to establish correct basic propertiesfor the strMeshgen and unstrMeshgen.

Syntax:

[ totarea noelements] = geomdraw2(vertices,segments, surfaces,segp,mp)

Description:

The physical domain is characterized by specification of (convex) (sub)domain, sur-face. The surface(s) is defined by listing it’s consecutive enclosing segments, listedin a matrix similar to Edof , denoted here as surfaces. The coordinates of verticesis in a format similar to Coord, the vertices in segments is specified by the row indexof the starting and the end vertex in the vertex list,

vertices =

x1 y1

x2 y2

x3 y3...

...xn vn

segments =

vertex1 vertex2

vertex2 vertex3

vertex3 vertex4...

...vertexm−1 vertexm

The surface element topology matrix by row wise specify each elements segmentsindex,

surfaces =

segment1 segment2 ... segmentn...

......

...segmentk−n segmentk−n+1 ... segmentk

The segment property list, segpr, contains the properties associated with each seg-ment, where bias and curve row is optional,

segpr =

seed1 seed2 . . . seedk

curve1 curve2 . . . curvek

bias1 bias2 . . . biask

The seed is the number cells on interior segment, the curve is the index of the vertexassociated to each segment used for the interpolation and thus gives three pointsrepresentation, where 0 index indicates linear segment. The bias is an asymmetricdistribution of the points on the segment, range (−1, 1) where positive is clusteringat end point.

The mp describes the mesh properties, which affects the Edof and Coord, for theboundary domain specification mp = [dpn nen], where dpn is the degrees of freedomper node and nen the number of element nodes. The output totarea and noelementsgives the area of the domain respective estimated number of elements from meshgeneration.

Manual pages 0 – 2

Page 10: CALFEM Mesh module Manual

Manual pages strMeshgen

Purpose:

Generates a structured mesh.

Syntax:

[coord edof dofs meshdb]=strMeshgen(vertices,segments,surfaces,segp,mp)[meshdb]=strMeshgen(vertices,segments,surfaces,segp,mp)

Description:

The mesh is generated by mapping a regular grid into specified sub domain. Theprocedure in dividing the domain restrict the segpr. Therefore seed assumes thesame seed value for all triangular surfaces, while quadrilaterals same seed on oppositesegments of the surface. The bias works only for quadrilateral surfaces. If higherorder surfaces than quadrilateral is used, the seed is the mean value of the seedvector. See coordxtr for further details of the definitions of edof , dofs, coord andgeomdraw2 for vertices, segments, surfaces, mp and segpr. meshdb is a placeholder of all relevant data for the mesh.

Example:

The example from figure 1 in introduction,

vertices=[0 0;1 0;1 1;0 1];

segments=[1 2;2 3; 3 4; 4 1];

surfaces=[1 2 3 4];segpr=[ 1 2 1 2];mp=[2 3];

db=strMeshgen(vertices,segments,surfaces,segpr,mp);

See also:

geomdraw2, DBextract

0 – 3 Manual pages

Page 11: CALFEM Mesh module Manual

unstrMeshgen Manual pages

Purpose:

Generate unstructured mesh using randomized incremental triangulation algorithmwith delaunay condition enforced.

Syntax:

[coord edof dofs meshdb]=unstrMeshgen(vertices,segments,surfaces,segp,mp)[meshdb]=unstrMeshgen(vertices,segments,surfaces,segp,mp)

Description:

The delaunay mesh is a mesh satisfy the condition that given any triangle elementin mesh, its circumcircle contain no interior nodes of the mesh. For quadrilateralelement input (nen = 4) the mesh is computed by obtaining the triangular meshfor the twice of the element area and then apply convertMesh to obtain the finalmesh. See coordxtr for further details of the definitions of edof , dofs, coord andgeomdraw2 for vertices, segments, surfaces, mp and segpr.

Example:

Unstructured mesh generation of domain presented in Figure 2,

vertices=[0 1;0 2;4 2;4 0; 3 0; 3 1 ];

segments=[ 1 2;2 3;3 4;4 5;5 6; 6 1];

surfaces=[1 2 3 4 5 6];seed=[5 15 8 5 5 10];

mp=[ 2 3 ];

db=unstrMeshgen(vertices,segments,surfaces,seed,mp);

See also:

geomdraw2, convertMesh

Manual pages 0 – 4

Page 12: CALFEM Mesh module Manual

Manual pages mergeMesh

Purpose:

Is used to merge two meshes.

Syntax:

[ coord edofs dofs meshdb ] = mergeMesh(coord1,edofs1,dofs1,coord2,edofs2,dofs2)[ meshdb ] = mergeMesh(meshdb1,meshdb2)

Description:

The boundary vertices are identified and the global topology matrix for nodes, globalcoordinates are remapped to the unique points in the mesh. See coordxtr for furtherdetails of the definitions of edof , dofs, coord.

Example:

An alternative mesh generation of Figure 3,

quadl=[0 1;0 2; 4 2;3 1];

quadr=[3 1;3 0;4 0; 4 2];

segments=[1 2;2 3;3 4;4 1];

surface=[ 1 2 3 4];mp=[2 4];

seedl=[ 5 15 5 15];seedr=[ 5 5 5 5];

dbl=strMeshgen(quadl,segments,surface,seedl,mp);

dbr=strMeshgen(quadr,segments,surface,seedr,mp);

db=mergeMesh(dbl,dbr);

Note:

Using extract function upon merged mesh may require a redefinition of vertices andsegments.

See also:

stitchMesh,

0 – 5 Manual pages

Page 13: CALFEM Mesh module Manual

refineMesh Manual pages

Purpose:

Is used to refine the mesh by subdivision each element.

Syntax:

[ coord edofs dofs meshdb ] = refineMesh(coord,edofs,dofs)[ meshdb ] = refineMesh(meshdb)

Description:

The mesh elements are divided into four sub elements, by adding vertices on themidpoint of each segments and one in the interior. See coordxtr for further detailsof the definitions of edof , dofs, coord.

Example:

A modification of mesh generation from input for figure 5,

vertices=[0 1;0 2;4 2;4 0; 3 0; 3 1 ];

segments=[ 1 2;2 3;3 4;4 5;5 6; 6 1];

surfaces=[1 2 3 4 5 6];seed=[5 10 8 5 5 8];

mp=[ 2 3 ];

db=unstrMeshgen(vertices,segments,surfaces,seed,mp);

db=refineMesh(db);

Note:

This routine is the fastest meshing routine in this package, recommended to be usedwhenever convergence study is performed.

See also:

convertMesh

Manual pages 0 – 6

Page 14: CALFEM Mesh module Manual

Manual pages smoothMesh

Purpose:

Improve the quality of mesh by redistribute position of interior nodes, called smooth-ing.

Syntax:

[ coord disp meshdb ] = smoothMesh(coord,edofs,dofs)[ meshdb ] = smoothMesh(meshdb)

Description:

The smoothing is performed by average over nodes from the surrounding neighbourcells. See coordxtr for further details of the definitions of edof , dofs, coord andgeomdraw2 for vertices and segments.

Example:

A modification of mesh generation from input for Figure 5,

vertices=[0 1;0 2;4 2;4 0; 3 0; 3 1 ];

segments=[ 1 2;2 3;3 4;4 5;5 6; 6 1];

surfaces=[1 2 3 4 5 6];seed=[5 10 8 5 5 8];

mp=[ 2 3 ];

smoothMesh(unstrMeshgen(vertices,segments,surfaces,seed,mp));

See also:

convertMesh

0 – 7 Manual pages

Page 15: CALFEM Mesh module Manual

convertMesh Manual pages

Purpose:

A routine to convert between quadrilateral and triangular mesh.

Syntax:

[ coord edofs dofs meshdb ] = convertMesh(coord,edofs)[ meshdb ] = convertMesh(meshdb)

Description:

The conversion from quadrilateral mesh into triangular is performed by dividingthe quadrilateral by the edge of shortest distance between diagonal vertex. Theconversion from triangular into quadrilateral are performed by collapsing eligibletriangles and remaining triangles are divided into three sub quadrilaterals by addinga point in the center of the element. This routine work as a refineMesh followedby correctMesh. See coordxtr for further details of the definitions of edof , dofs,coord and geomdraw2 for vertices and segments.

Example:

A modification of mesh generation from input for figure 5,

vertices=[0 1;0 2;4 2;4 0; 3 0; 3 1 ];

segments=[ 1 2;2 3;3 4;4 5;5 6; 6 1];

surfaces=[1 2 3 4 5 6];seed=[5 10 8 5 5 8];

mp=[ 2 4 ];

db=convertMesh(unstrMeshgen(vertices,segments,surfaces,seed,mp));

Note:

By repeating this operation the command act as a refinement on the mesh withthe important difference to refineMesh that edge flipping is allowed (i.e. delaunaycondition ) to alter and hence the function correct low quality mesh and improvingthe q factor.

See also:

refineMesh

Manual pages 0 – 8

Page 16: CALFEM Mesh module Manual

Manual pages extrSeg

Purpose:

To extract dofs and vertex row index to vertices from the mesh along a given segmentlist.

Syntax:

[ dof vertex ] = extrSeg(segidx,segments,segpr,vertices,dofs,coord,ndof,d))[ dof vertex ] = extrSeg(segidx,segments,vertices,dofs,coord,ndof,d))[ dof vertex ] = extrSeg(segidx,meshdb,ndof)

Description:

The list of segments row indices is matched to vertices over mesh along a search stripeof width d. Identical numbers are removed from the list and it is returned sorted.See coordxtr for further details of the definitions of dofs, coord and geomdraw2 forvertices and segments.

Example:

Figure 3 revisited, dof’s for segment 1 and 2 are extracted,

vertices=[0 1;0 2;4 2;4 0; 3 0; 3 1 ];

segments=[ 1 2;2 3;3 4;4 5;5 6; 6 1];

surfaces=[1 2 3 4 5 6];seed=[5 10 8 5 5 8];

db=strMeshgen(vertices,segments,surfaces,seed,mp);

dofs=extrSeg([1 2],db)

Note:

The segments can be redefined after mesh generation, segments in this context isdifferentiated from the previous defined by allowing any line segment between anyvertices and vertices list can be any coordinate list. Note that if curve is used thensegpr must be inserted as well. The ndof tells which global degree of freedom of thenode to be chosen, if omitted all to given node is listed.

See also:

extrPoint, extrSurf

0 – 9 Manual pages

Page 17: CALFEM Mesh module Manual

extrPoint Manual pages

Purpose:

To extract dofs and vertex row index from the mesh at vertices defined.

Syntax:

[ dof vertex ] = extrPoint(vertidx,vertices,coord,dofs,ndof)[ dof vertex ] = extrPoint(vertidx,meshdb,ndof)

Description:

The vertex row index list vertidx is matched to vertices over mesh. The ndof tellswhich global degree of freedom of the node to be chosen, if omitted all to givennode is listed. See coordxtr for further details of the definitions of dofs, coord andgeomdraw2 for vertices.

Example:

Figure 3 revisited, dof’s for vertex 1 and 2 are extracted,

vertices=[0 1;0 2;4 2;4 0; 3 0; 3 1 ];

segments=[ 1 2;2 3;3 4;4 5;5 6; 6 1];

surfaces=[1 2 3 4 5 6];seed=[5 10 8 5 5 8];

mp=[ 2 4 ];

db=unstrMeshgen(vertices,segments,surfaces,seed,mp);

dofs=extrPoint([1 2],db)

Note:

The vertices can even be interior points, in other words, vertices is differentiatedfrom the previous defined by allowing any point.

See also:

extrSeg,extrSurf

Manual pages 0 – 10

Page 18: CALFEM Mesh module Manual

Manual pages extrSurf

Purpose:

extracts row index of edof and row index for Coord for given surface row index.

Syntax:

[ el np ] = extrSurf(meshdb,surfidx)

Description:

Given row index list of surfaces, surfidx, the associated row index list el for edofsand nodes np in coord extracted.

Example:

The geometry of Figure 1 revisited,

vertices=[0 0;1 0;1 2;0 2];

segments=[1 2;2 3;3 4;4 1];

surface=[ 1 2 3 4];mp=[2 3];seed=[1 2 1 2];

db=strMeshgen(vertices,segments,surface,seed,mp);

el=extrSurf(db,[1])

0 – 11 Manual pages

Page 19: CALFEM Mesh module Manual

DBextract Manual pages

Purpose:

To extract coord,edofs,dofs and nen from meshdata db or any other specified tagname.

Syntax:

[ coord edofs dofs nen] = DBextract(meshdb)[ var ] = DBextract(meshdb,’var’)

Description:

The use of datatype struct as place holder of data is a convenient object, the actualinformation about its contents can be further pursued in the help files. See coordxtrfor further details of the definitions of edof , dofs, coord.

Example:

The geometry of Figure 1 revisited,

vertices=[0 0;1 0; 1 1; 0 1];

segments=[1 2;2 3;3 1;3 4; 4 1];

surface=[ 1 2 3; 4 5 3];mp=[2 3];seed=[ 1 1 1 1 1];

db=strMeshgen(vertices,segments,surface,seed,mp);

db=stitchMesh(db,1,db,4);

[coord edof dofs]=DBextract(db)

Tip:

In command prompt, type the variable name meshdb to list its contents.

Manual pages 0 – 12

Page 20: CALFEM Mesh module Manual

Manual pages correctMesh

Purpose:

To improve the quality of the mesh.

Syntax:

[ coord edofs dof disp meshdb ] = correctMesh(coord,edof,dofs,sel,disp)[ meshdb ] = correctMesh(meshdb)

Description:

The sel list is a sub set of the row index list to edofs to which quality is improved.For the triangle mesh delaunay condition is enforced, see unstrMeshgen, and forquadrilateral illegal elements such as non-convex is fixed. See coordxtr for furtherdetails of the definitions of edof , dofs, coord

Example:

vertices=[0 0;1 0; 1 1; 0 1];

segments=[1 2;2 3;3 1;3 4; 4 3];

surface=[ 1 2 3; 4 5 3];mp=[2 3];seed=[ 2 2 2 2 2];

db=correctMesh(refineMesh(strMeshgen(vertices,segments,surface,seed,mp)));

Tip:

sel from extractBoundarydofs provides the non-convex elements for quadrilaterals.

See also:

extractBoundaryDofs

0 – 13 Manual pages

Page 21: CALFEM Mesh module Manual

checkMesh Manual pages

Purpose:

Compute the quality of the mesh.

Syntax:

[ qe qn J] = checkMesh(coord,edof,dofsPerNode)[ qe qn J] = checkMesh(meshdb)

Description:

Computes the q factor for given mesh and the Jacobian of each element. The qefactor is a element property, the qn factor for the nodes are the averaged q factorover all surrounding elements. The J gives the area of the domain. See coordxtr forfurther details of the definitions of edof and coord

Example:

vertices=[0 0;1 0; 1 1; 0 1];

segments=[1 2;2 3;3 1;3 4; 4 3];

surface=[ 1 2 3; 4 5 3];mp=[2 3];seed=[ 2 2 2 2 2];

db=strMeshgen(vertices,segments,surface,seed,mp);

[ qe qn J]=checkMesh(db);

Manual pages 0 – 14

Page 22: CALFEM Mesh module Manual

Manual pages stitchMesh

Purpose:

Merge two mesh by joining two segments by translation, rotation and scaling.

Syntax:

[ qe qn J] = stitchMesh(meshdb1,SegID1,meshdb2,SegID2)[ qe qn J] = checkMesh(meshdb)

Description:

The mesh meshdb1 is translated from starting point for segment SegID1 to thestarting point of segment SegID2 for meshdb2, then scaled and rotated to align withmeshdb2, finally the mesh is merged by mergeMesh.

Example:

The mesh generation of figure 6,

vertices=[0 0;cos(pi/3) sin(pi/3);1 0;cos(pi/6) sin(pi/6)];

segments=[ 2 3; 3 1; 1 2];

surfaces=[1 2 3];

segpr=[5 5 5;4 0 0];

db=strMeshgen(vertices,segments,surfaces,segpr,[2 3]);

db=stitchMesh(stitchMesh(db,3,db,2),2,db,3);

See also:

translateMesh,rotateMesh,scaleMesh

0 – 15 Manual pages

Page 23: CALFEM Mesh module Manual

Examples

L-shape console

For the figure 2, surface domain description, the following input defines two surfaces definedby

% surface domain description

Vertices=[ 0 2 ;4 2 ;4 0;3 0;3 1;0 1];

Segments=[6 1 :1 2 ;2 3;3 4;4 5; 5 6;5 2];

Surfaces=[ 7 6 1 2 ;4 5 7 3];

At this point one can either use strMeshgen leading to figure 3 or unstrMeshgen whichgives the result in figure 8, which can be compared to figure 4.

% define dpn and nen

mp=[2 3];

Segpr=ones(1,size(segments,1))*5;Segpr([2 6])=15;

db=unstrMeshgen(vertices,segments,surfaces,Segpr,mp);

% smooth mesh extract data

[coord edof dof nen]=DBextract(smoothMesh(db));

% plot the mesh

figure;

[ex ey]=coordxtr(edof,coord,dof,nen);

eldraw2(ex,ey,[1 4 1]);

The smoothing smoothMesh was combined with the DBextract in one command, this cangenerally be achieved for all commands apart from geomdraw2 .

0 0.5 1 1.5 2 2.5 3 3.5 4

−0.5

0

0.5

1

1.5

2

2.5

x

y

Figure 7: A surface description of a domain. The domain is divided into two surfaces usingseven segments and six vertices.

0 – 1 Examples

Page 24: CALFEM Mesh module Manual

A square shape with hole

w=sqrt(2)/6;

vertices = [ 0 0 ; 1/3 0 ; 2/3 0 ; 1 0 ; ...

0 1/3 ; 1/3 1/3 ; 2/3 1/3 ; 1 1/3 ; ...

0 2/3 ; 1/3 2/3 ; 2/3 2/3 ; 1 2/3 ; ...

0 1 ; 1/3 1 ; 2/3 1; 1 1 ; ...

1/2 (1/2-w) ; (1/2+w) 1/2; 1/2 (1/2+w) ; (1/2-w) 1/2];

% define segments

segments =[ 1 2; 2 3; 3 4; 1 5; 2 6; 3 7; 4 8; ...

5 6; 6 7; 7 8; 5 9; 6 10; 7 11; 8 12; ...

9 10; 10 11; 11 12;9 13; 10 14; 11 15; 12 16; ...

13 14; 14 15; 15 16];

% define surfaces

surfaces=[ 1 5 8 4 ; 2 6 9 5 ; 3 7 10 6;8 12 15 11; ...

10 14 17 13; 15 19 22 18;16 20 23 19;17 21 24 20];

% assign seed, curve

seed=ones(1,24)*4;curve=zeros(1,24);

curve([ 9 13 16 12])=[ 17 18 19 20];segpr=[seed;curve];

% mesh properties

mp=[ 2 3];

db=smoothMesh(convertMesh(strMeshgen(vertices,segments,surfaces,segpr,mp)));

% plot mesh

[coord edof dof nen]=DBextract(db);

[ex ey]=coordxtr(edof,coord,dof,nen);eldraw2(ex,ey,[1 4 1]);

0 0.2 0.4 0.6 0.8 10

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

x

y

Figure 8: A surface description of a domain with a hole, figure 6. The domain is dividedinto 8 surfaces using and triangulated followed by conversion to quadrilateral elements,convertMesh.

The above is essential the same as previous section but with convertMesh added to illustratefurther the convenience by using nested calls.

Examples 0 – 2

Page 25: CALFEM Mesh module Manual

Extraction and meshdb manipulation

This section serves the purpose to illustrate that vertices and segments can be redefinedany time after the mesh generation arbitrary. By using the mesh data db from example”A square with hole” together with redefinition of vertices and segments, stitchMesh underthe mesh/utilities allows more complex regions to be build,

% stitch segments listed ROI

db.vertices=[1 0 ; 1 1;0 0; 0 1];db.segments=[1 2;4 3];

db=stitchMesh(db,2,stitchMesh(db,2,stitchMesh(db,2,db,1),1),1);

db.segments=[1 2;4 3];db.vertices=[0 0; 4 0; 0 1; 4 1];

db=stitchMesh(db,2,db,1);

% plot the mesh

[coord edof dof nen]=DBextract(dbmerged);

[ex ey]=coordxtr(edof,coord,dof,nen);

eldraw2(ex,ey,[1 4 1]);

0 0.5 1 1.5 2 2.5 3 3.5 4

−0.5

0

0.5

1

1.5

2

2.5

x

y

Figure 9: A illustration of the use with stitchMesh from figure 8.

0 – 3 Examples

Page 26: CALFEM Mesh module Manual

Now we seek the dof’s in a direction not defined in geometry for db, on the line betweenthe point (0, 1) and (1/2, 1). To achieve this, the recreate vertices and segments is redefinedand extrSeg is called.

>> db.vertices=[ 0 1; 1/2 1];

>> db.segments=[ 1 2];

>> extrSeg(1,db,2)

ans =

212

214

216

218

220

256

258

Examples 0 – 4

Page 27: CALFEM Mesh module Manual

Quality improvement of mesh

This module offers two functions to improve the quality of the mesh, with q-factor (q)as a measure, one by adjusting the coordinates (smoothMesh), another by rearrange thetopology (correctMesh). By starting from section ”L-shaped console”,

>> db1=smoothMesh(correctMesh(smoothMesh(db)));

>> db1=checkMesh(db1);db=checkMesh(db);

>> subplot(221);hist(db.q);

>> subplot(222);hist(db1.q);

>> subplot(223);[ex ey]=coordxtr(db.edofs,db.coords,db.dofs,db.nen);eldraw2(ex,ey,[1 4 1]);

>> subplot(224);[ex ey]=coordxtr(db1.edofs,db1.coords,db1.dofs,db1.nen);eldraw2(ex,ey,[1 4 1]);

The figure 10 show the improvement, this is a significant result and altogether an usefultool in creating high quality mesh.

0.4 0.6 0.8 10

10

20

30

40

0.4 0.6 0.8 10

20

40

60

80

0 1 2 3 4

0

1

2

x

y

0 1 2 3 4

0

1

2

x

y

Figure 10: Improvement of mesh from ”L-shaped console” section, using checkMesh,correctMesh and smoothMesh.

0 – 5 Examples

Page 28: CALFEM Mesh module Manual

Advanced example using vertices2segment

To gain further insight in how to use the mesh generator to generate input, the section ”Asquare with a hole” is remade using the vertices2segment from mesh/dependicies.

% a square in a hole revisit

vertices=[0 0; 1 0; 1 1; 0 1];

segments=[1 2;2 3;3 4;4 1];

surfaces=[ 1 2 3 4];

% this is a surface topology with vertices as reference

mp=[ 1 4];

segpr=[ 3 3 3 3];

% generate topology, vsurface

db=strMeshgen(vertices,segments,surfaces,segpr,mp);

% create the hole

db.edofs(5,:)=[];

% generate surfaces and segments with segment ased surface topology

[surfaces segments]=vertices2segment(db.edofs(:,2:end));

% add vertices which defines the curvature and iso8

w=sqrt(2)/6;

db.coords=[db.coords; 1/2 (1/2-w) ; (1/2+w) 1/2; 1/2 (1/2+w) ; (1/2-w) 1/2];

% prior define the curve segment, use geomdraw2 to identify the index!

seed=ones(1,size(segments,1))*4;curve=zeros(1,size(segments,1));

curve([ 7 18 12 23])=[ 20 17 19 18];segpr=[seed;curve];

% generate the mesh

mp=[ 2 3];

db=smoothMesh(convertMesh(strMeshgen(db.coords,segments,surfaces,segpr,mp)));

This generates the same mesh as ”a square with hole”. Enjoy!

Examples 0 – 6