Sunteți pe pagina 1din 28

CALFEM meshing module

Division of Structural Mechanics & Division of Solid Mechanics

Lund Institute of Technology

0–1
Introduction
The functions in this module makes it possible to generate a two dimensional mesh with
small effort. It also allows extraction and manipulation of the mesh with operations such
as 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 global
nodal coordinate matrix Coord. This matrix is a list of global coordinates for each node in
the mesh. In each node a certain number of degrees of freedom are present. A key feature
that characterize the mesh is the connectivity matrix, the global degree of freedom matrix
Edof associating the degrees of freedom of each element to the global degree of freedom
matrix Dof . The later being a list of global nodal degrees of freedom.

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

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


   
0. 0. 9 10
    
 1. 0.   11 12 
 1 3 4 1 2 5 6
     
 0. 1.   5 6  2 5 6 7 8 3 4
Coord = 


 Dof = 

 Edof = 



 1. 1.   7 8   3 9 10 7 8 5 6 
   
 0. 2.   1 2  4 9 10 11 12 7 8
1. 2. 3 4

0–1 Introduction
Mesh generation
The mesh geometry
In order to generate these matrices for a large number of elements, the physical domain to
be meshed has to be defined systematically. In this module the mesh geometry is defined
using the basic concepts of vertices, segments, and surfaces.

A vertex is a corner point of a (sub)domain. Two consecutive vertices define a segment


and several enclosing consecutive segments of a given convex (sub)domain defines a surf ace.
A physical domain is divided into surf aces with shared corner points. This surface do-
main description is also known as conform multi-block method. Consider the example in

2.5

22 2(15) 3

1.5 1(5) 1 7(5)

11 6(15) 6 3(5)

2
0.5 5(5)

0 5 4(5) 4

−0.5
0 0.5 1 1.5 2 2.5 3 3.5 4

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

Figure 2 showing a domain with two surfaces, seven segments and six vertices (surface
numbers are shown in a square and segment numbers are shown underlined). The basic
mesh geometry for this case is defined by the matrices
 
  6 1
0. 2.  
  

1 2 

 4. 2.    " #
   2 3 
 4. 0.    7 6 1 2
Vertices = 


 Segments =  3 4  Surfaces = (1)
 3. 0.  


 4 5 7 3
   4 5 
 3. 1.   
 5 6 
0. 1.
5 2

Introduction 0–2
The vertices matrix is a coordinate list. The numbers (followed by a dot) on each row are
the coordinates of the vertices, numbered in the order shown in Figure 2. The segment
matrix is a vertices list, with the vertex numbers of the segments on each row. Finally, the
surface 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 a
structured kind with a pre defined number and location of elements, using the strMeshgen
function 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 segment
2, etc, yields the mesh in Figure 3. The unstructured meshing approach is conducted in

2.5

1.5

1
y

0.5

−0.5
0 0.5 1 1.5 2 2.5 3 3.5 4
x

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 segments
matrix and that the surface matrix will be reading,
h i
Surfaces = 1 2 3 4 5 6 . (2)

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

0–3 Introduction
2.5

22 2 3 3 4

1.5 1 4

11 8 8 5

0.5 7 5

0 7 6 6

−0.5
0 0.5 1 1.5 2 2.5 3 3.5 4

Figure 4: one surface description of a domain.

2.5

1.5

1
y

0.5

−0.5
0 0.5 1 1.5 2 2.5 3 3.5 4
x

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

Introduction 0–4
More meshing tools
Functions for displaying basic mesh geometry, extracting degrees of freedom, manipulating
the mesh, etc are described next.

Basic mesh geometry display


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

1.5
2

4
3(5) 1(5) 0.5
y

1
0

2(5) 3
−0.5

−1

0.2 0.4 0.6 0.8 1 −1 −0.5 0 0.5 1


x

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

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

0–5 Introduction
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 element
calculation. Loading points, constraint points etc also have to be defined and included in
the point list.
Knowing particular degrees of freedom at various points, segments, and surfaces and
also 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 to
be defined as a fixed point in the mesh and the degrees of freedom at that node has to be
known for the load application. Another example, if a boundary condition is to be applied
at a part of the boundary in a particular direction, these degrees of freedom need to be
known 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 characterized
with different surfaces for each material. The element numbers of these elements need to be
extracted, 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 very
tedious 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 working
on 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 and
segments respectively. The second also yields the point numbers of the segments. The
third 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 as
the mergeMesh, refineMesh, convertMesh, stitchMesh and so forth. Using these it is possible
to merge two meshes, refine a mesh by element division, and convert between triangular
and quadrilateral elements. Figure 6 illustrates the stitchMesh. Moreover, functions for
improving 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 base
using the structured variable concept in MATLAB. This makes it possible to transfer all
information about the mesh using only one variable. Knowledge of structured variables
is not necessary in order to use the mesh functions in this module. However, information
in terms of the matrices discussed previously can be derived from the data base using the
function DBextract. Finally there is a function for estimating the quality of generated
meshes. The checkMesh function delivers an objective measure of the mesh quality called
the q-factor and calculates the area of each element.

Introduction 0–6
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 help
function 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 data


strMeshgen structured mesh generation
unstrMeshgen unstructured mesh generation

mergeMesh merge meshes


stitchMesh stitch meshes together
refineMesh refines the mesh by midpoint section method
convertMesh conversion between triangular and quadrilateral mesh
correctMesh correct for quadrilaterals/triangle improper elements to improve
quality
smoothMesh smooth the mesh to improve quality

extrPoint extract dofs at selected points


extrSeg extract dofs, and points at selected segments
extrSurf 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 are
done.

0–1 Manual pages


geomdraw2 Manual pages

Purpose:
Displays the basic geometry for the mesh in order to establish correct basic properties
for 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, listed
in a matrix similar to Edof , denoted here as surf aces. The coordinates of vertices
is in a format similar to Coord, the vertices in segments is specified by the row index
of the starting and the end vertex in the vertex list,
   
x1 y1 vertex1 vertex2
   


x2 y2 


vertex2 vertex3 

vertices = 
 x3 y3  segments = 
 vertex3 vertex4 

 .. ..   .. .. 
 . .   . . 
   
xn v n vertexm−1 vertexm
The surface element topology matrix by row wise specify each elements segments
index,
 
segment1 segment2 ... segmentn
 . . .. .. 

surfaces =  .. .. . . 

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,
 
seed1 seed2 . . . seedk
segpr =  
 curve1 curve2 . . . curvek 
bias1 bias2 . . . biask
The seed is the number cells on interior segment, the curve is the index of the vertex
associated to each segment used for the interpolation and thus gives three points
representation, where 0 index indicates linear segment. The bias is an asymmetric
distribution of the points on the segment, range (−1, 1) where positive is clustering
at end point.
The mp describes the mesh properties, which affects the Edof and Coord, for the
boundary domain specification mp = [dpn nen], where dpn is the degrees of freedom
per node and nen the number of element nodes. The output totarea and noelements
gives the area of the domain respective estimated number of elements from mesh
generation.

Manual pages 0–2


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. The
procedure in dividing the domain restrict the segpr. Therefore seed assumes the
same seed value for all triangular surfaces, while quadrilaterals same seed on opposite
segments of the surface. The bias works only for quadrilateral surfaces. If higher
order surfaces than quadrilateral is used, the seed is the mean value of the seed
vector. See coordxtr for further details of the definitions of edof , dof s, coord and
geomdraw2 for vertices, segments, surf aces, mp and segpr. meshdb is a place
holder 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


unstrMeshgen Manual pages

Purpose:
Generate unstructured mesh using randomized incremental triangulation algorithm
with 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 element
in mesh, its circumcircle contain no interior nodes of the mesh. For quadrilateral
element input (nen = 4) the mesh is computed by obtaining the triangular mesh
for the twice of the element area and then apply convertM esh to obtain the final
mesh. See coordxtr for further details of the definitions of edof , dof s, coord and
geomdraw2 for vertices, segments, surf aces, 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


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, global
coordinates are remapped to the unique points in the mesh. See coordxtr for further
details of the definitions of edof , dof s, 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 and
segments.

See also:
stitchMesh,

0–5 Manual pages


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 the
midpoint of each segments and one in the interior. See coordxtr for further details
of the definitions of edof , dof s, 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 used
whenever convergence study is performed.

See also:
convertMesh

Manual pages 0–6


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 neighbour
cells. See coordxtr for further details of the definitions of edof , dof s, 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 3 ];
smoothMesh(unstrMeshgen(vertices,segments,surfaces,seed,mp));

See also:
convertMesh

0–7 Manual pages


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 dividing
the quadrilateral by the edge of shortest distance between diagonal vertex. The
conversion from triangular into quadrilateral are performed by collapsing eligible
triangles and remaining triangles are divided into three sub quadrilaterals by adding
a point in the center of the element. This routine work as a ref ineM esh followed
by correctM esh. See coordxtr for further details of the definitions of edof , dof s,
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 with
the important difference to ref ineM esh that edge flipping is allowed (i.e. delaunay
condition ) to alter and hence the function correct low quality mesh and improving
the q factor.

See also:
refineMesh

Manual pages 0–8


Manual pages extrSeg

Purpose:
To extract dofs and vertex row index to vertices from the mesh along a given segment
list.

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 stripe
of width d. Identical numbers are removed from the list and it is returned sorted.
See coordxtr for further details of the definitions of dof s, coord and geomdraw2 for
vertices 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 is
differentiated from the previous defined by allowing any line segment between any
vertices and vertices list can be any coordinate list. Note that if curve is used then
segpr must be inserted as well. The ndof tells which global degree of freedom of the
node to be chosen, if omitted all to given node is listed.

See also:
extrPoint, extrSurf

0–9 Manual pages


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 tells
which global degree of freedom of the node to be chosen, if omitted all to given
node is listed. See coordxtr for further details of the definitions of dof s, coord and
geomdraw2 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 differentiated
from the previous defined by allowing any point.

See also:
extrSeg,extrSurf

Manual pages 0 – 10
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 surf aces, surf idx, the associated row index list el for edof s
and 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
DBextract Manual pages

Purpose:
To extract coord,edofs,dofs and nen from meshdata db or any other specified tag
name.

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 actual
information about its contents can be further pursued in the help files. See coordxtr
for further details of the definitions of edof , dof s, 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
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 edof s to which quality is improved.
For the triangle mesh delaunay condition is enforced, see unstrM eshgen, and for
quadrilateral illegal elements such as non-convex is fixed. See coordxtr for further
details of the definitions of edof , dof s, 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 extractBoundarydof s provides the non-convex elements for quadrilaterals.

See also:
extractBoundaryDofs

0 – 13 Manual pages
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 qe
factor is a element property, the qn factor for the nodes are the averaged q factor
over all surrounding elements. The J gives the area of the domain. See coordxtr for
further 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
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 the
starting point of segment SegID2 for meshdb2 , then scaled and rotated to align with
meshdb2 , finally the mesh is merged by mergeM esh.

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
Examples
L-shape console
For the figure 2, surface domain description, the following input defines two surfaces defined
by

% 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 which
gives 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 can
generally be achieved for all commands apart from geomdraw2 .

2.5

1.5

1
y

0.5

−0.5
0 0.5 1 1.5 2 2.5 3 3.5 4
x

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

0–1 Examples
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.9

0.8

0.7

0.6

0.5
y

0.4

0.3

0.2

0.1

0
0 0.2 0.4 0.6 0.8 1
x

Figure 8: A surface description of a domain with a hole, figure 6. The domain is divided
into 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 illustrate
further the convenience by using nested calls.

Examples 0–2
Extraction and meshdb manipulation
This section serves the purpose to illustrate that vertices and segments can be redefined
any 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 under
the 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]);

2.5

1.5

1
y

0.5

−0.5
0 0.5 1 1.5 2 2.5 3 3.5 4
x

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

0–3 Examples
Now we seek the dof’s in a direction not defined in geometry for db, on the line between
the point (0, 1) and (1/2, 1). To achieve this, the recreate vertices and segments is redefined
and 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
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 (smoothM esh), another by rearrange the
topology (correctM esh). 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
>> subplot(224);[ex ey]=coordxtr(db1.edofs,db1.coords,db1.dofs,db1.nen);eldraw2(ex,ey,

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

40 80

30 60

20 40

10 20

0 0
0.4 0.6 0.8 1 0.4 0.6 0.8 1

2 2

1 1
y

0 0

0 1 2 3 4 0 1 2 3 4
x x

Figure 10: Improvement of mesh from ”L-shaped console” section, using checkM esh,
correctM esh and smoothM esh.

0–5 Examples
Advanced example using vertices2segment
To gain further insight in how to use the mesh generator to generate input, the section ”A
square 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

S-ar putea să vă placă și