/[escript]/trunk/doc/user/pycad.tex
ViewVC logotype

Contents of /trunk/doc/user/pycad.tex

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3321 - (show annotations)
Thu Oct 28 05:02:41 2010 UTC (8 years, 2 months ago) by gross
File MIME type: application/x-tex
File size: 33174 byte(s)
a problem with surface orientation fixed.
1
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % Copyright (c) 2003-2010 by University of Queensland
5 % Earth Systems Science Computational Center (ESSCC)
6 % http://www.uq.edu.au/esscc
7 %
8 % Primary Business: Queensland, Australia
9 % Licensed under the Open Software License version 3.0
10 % http://www.opensource.org/licenses/osl-3.0.php
11 %
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13
14 \chapter{The \pycad Module}\label{PYCAD CHAP}
15
16 \section{Introduction}
17
18 \pycad provides a simple way to build a mesh for your finite element
19 simulation. You begin by building what we call a \class{Design} using
20 primitive geometric objects, and then to go on to build a mesh from
21 this. The final step of generating the mesh from a \class{Design}
22 uses freely available mesh generation software, such as \gmshextern.
23
24 A \class{Design} is built by defining points, which are used to specify
25 the corners of geometric objects and the vertices of curves. Using
26 points you construct more interesting objects such as lines,
27 rectangles, and arcs. By adding many of these objects into what we
28 call a \class{Design}, you can build meshes for arbitrarily complex 2-D
29 and 3-D structures.
30
31 \section{The Unit Square}
32 So the simplest geometry is the unit square. First we generate the
33 corner points
34 \begin{python}
35 from esys.pycad import *
36 p0=Point(0.,0.,0.)
37 p1=Point(1.,0.,0.)
38 p2=Point(1.,1.,0.)
39 p3=Point(0.,1.,0.)
40 \end{python}
41 which are then linked to define the edges of the square
42 \begin{python}
43 l01=Line(p0,p1)
44 l12=Line(p1,p2)
45 l23=Line(p2,p3)
46 l30=Line(p3,p0)
47 \end{python}
48 The lines are put together to form a loop
49 \begin{python}
50 c=CurveLoop(l01,l12,l23,l30)
51 \end{python}
52 The orientation of the line defining the \class{CurveLoop} is important. It is assumed that the surrounded
53 area is to the left when moving along the lines from their starting points towards the end points. Moreover,
54 the line need to form a closed loop.
55
56 We use the \class{CurveLoop} to define a surface
57 \begin{python}
58 s=PlaneSurface(c)
59 \end{python}
60 Notice there is difference between the \class{CurveLoop} defining the boundary
61 of the surface and the actually surface \class{PlaneSurface}. This difference becomes clearer in the next example with a hole. The direction of the lines is important.
62 New we are ready to define the geometry which described by an instance of \class{Design} class:
63 \begin{python}
64 d=Design(dim=2,element_size=0.05)
65 \end{python}
66 Here we use the two dimensional domain with a local element size in the finite element mesh of $0.05$.
67 We then add the surface \code{s} to the geometry
68 \begin{python}
69 d.addItems(s)
70 \end{python}
71 This will automatically import all items used to construct \code{s} into the \class{Design} \code{d}.
72 Now we are ready to construct a \finley FEM mesh and then write it to the file \file{quad.fly}:
73 \begin{python}
74 from esys.finley import MakeDomain
75 dom=MakeDomain(d)
76 dom.write("quad.fly")
77 \end{python}
78 In some cases it is useful to access the script used to generate the geometry. You can specify a specific name
79 for the script file. In our case we use
80 \begin{python}
81 d.setScriptFileName("quad.geo")
82 \end{python}
83 It is also useful to check error messages generated during the mesh generation process. \gmshextern writes
84 messages to the \file{.gmsh-errors} in your home directory.
85
86 If we put everything together we get the script
87 \begin{python}
88 from esys.pycad import *
89 from esys.pycad.gmsh import Design
90 from esys.finley import MakeDomain
91 p0=Point(0.,0.,0.)
92 p1=Point(1.,0.,0.)
93 p2=Point(1.,1.,0.)
94 p3=Point(0.,1.,0.)
95 l01=Line(p0,p1)
96 l12=Line(p1,p2)
97 l23=Line(p2,p3)
98 l30=Line(p3,p0)
99 c=CurveLoop(l01,l12,l23,l30)
100 s=PlaneSurface(c)
101 d=Design(dim=2,element_size=0.05)
102 d.setScriptFileName("quad.geo")
103 d.addItems(s)
104 pl1=PropertySet("sides",l01,l23)
105 pl2=PropertySet("top_and_bottom",l12,l30)
106 d.addItems(pl1, pl2)
107 dom=MakeDomain(d)
108 dom.write("quad.fly")
109 \end{python}
110 This example is included with the software in
111 \file{quad.py} in the \ExampleDirectory.
112
113 There are three extra statements which we have not discussed yet: By default the mesh used to subdivide
114 the boundary are not written into the mesh file mainly to reduce the size of the data file. One need to explicitly add the lines to the \Design which should be present in the mesh data. Here we additionally labeled the
115 lines on the top and the bottom with the name ``top_and_bottom`` and the lines on the left and right hand side
116 with the name ``sides`` using \class{PropertySet} objects. The labeling is convenient
117 when using tagging \index{tagging}, see Chapter~\ref{ESCRIPT CHAP}.
118
119 \begin{figure}
120 % \centerline{\includegraphics{quad}}
121 % \centerline{\includegraphics[width=\figwidth]{quad}}
122 \caption{Trapozid with triangle Hole.}
123 \label{fig:PYCAD 0}
124 \end{figure}
125
126 If you have \gmshextern installed you can run the example and view the geometry and mesh with:
127 \begin{python}
128 run-escript quad.py
129 gmsh quad.geo
130 gmsh quad.msh
131 \end{python}
132 You can access error messages from \gmshextern in the \file{.gmsh-errors} in your home directory.
133 See Figure~\ref{fig:PYCAD 0} for a result.
134
135 In most cases it is best practice to generate the mesh and to solve the mathematical
136 model in to different scripts. In our example you can read the \finley mesh into your simulation
137 code\footnote{\gmshextern files can be directly read using the \function{ReadGmsh}, see Chapter~\ref{CHAPTER ON FINLEY}} using
138 \begin{python}
139 from finley import ReadMesh
140 mesh=ReadMesh("quad.fly")
141 \end{python}
142 Note that the underlying mesh generation software will not accept all
143 the geometries you can create. For example, \pycad
144 will happily allow you to create a 2-D \class{Design} that is a
145 closed loop with some additional points or lines lying outside of the
146 enclosed area, but \gmshextern will fail to create a mesh for it.
147
148 \begin{figure}
149 % \centerline{\includegraphics[width=\figwidth]{trap}}
150 \caption{Trapozid with triangle Hole.}
151 \label{fig:PYCAD 1}
152 \end{figure}
153
154
155 \section{Holes}
156 The example included below shows how to use \pycad to create a 2-D mesh
157 in the shape of a trapezoid with a cut-out area, see Figure~\ref{fig:PYCAD 1}:
158 \begin{python}
159 from esys.pycad import *
160 from esys.pycad.gmsh import Design
161 from esys.finley import MakeDomain
162
163 # A trapezoid
164 p0=Point(0.0, 0.0, 0.0)
165 p1=Point(1.0, 0.0, 0.0)
166 p2=Point(1.0, 0.5, 0.0)
167 p3=Point(0.0, 1.0, 0.0)
168 l01=Line(p0, p1)
169 l12=Line(p1, p2)
170 l23=Line(p2, p3)
171 l30=Line(p3, p0)
172 c=CurveLoop(l01, l12, l23, l30)
173
174 # A small triangular cutout
175 x0=Point(0.1, 0.1, 0.0)
176 x1=Point(0.5, 0.1, 0.0)
177 x2=Point(0.5, 0.2, 0.0)
178 x01=Line(x0, x1)
179 x12=Line(x1, x2)
180 x20=Line(x2, x0)
181 cutout=CurveLoop(x01, x12, x20)
182
183 # Create the surface with cutout
184 s=PlaneSurface(c, holes=[cutout])
185
186 # Create a Design which can make the mesh
187 d=Design(dim=2, element_size=0.05)
188
189 # Add the trapezoid with cutout
190 d.addItems(s)
191
192 # Create the geometry, mesh and Escript domain
193 d.setScriptFileName("trapezoid.geo")
194 d.setMeshFileName("trapezoid.msh")
195 domain=MakeDomain(d)
196 # write mesh to a finley file:
197 domain.write("trapezoid.fly")
198 \end{python}
199 This example is included with the software in
200 \file{trapezoid.py} in the \ExampleDirectory.
201
202 A \code{CurveLoop} is used to connect several lines into a single curve.
203 It is used in the example above to create the trapezoidal outline for the grid
204 and also for the triangular cutout area.
205 You can use any number of lines when creating a \class{CurveLoop}, but
206 the end of one line must be identical to the start of the next.
207
208
209 \begin{figure}
210 % \centerline{\includegraphics[width=\figwidth]{brick}}
211 \caption{Three dimensional Block.}
212 \label{fig:PYCAD 2}
213 \end{figure}
214
215 \section{A 3D example}
216 In this section we discuss the definition of 3D geometries. The example is the unit cube, see Figure~\ref{fig:PYCAD 2}. First we generate the vertices of the cube:
217 \begin{python}
218 from esys.pycad import *
219 p0=Point(0.,0.,0.)
220 p1=Point(1.,0.,0.)
221 p2=Point(0.,1.,0.)
222 p3=Point(1.,1.,0.)
223 p4=Point(0.,0.,1.)
224 p5=Point(1.,0.,1.)
225 p6=Point(0.,1.,1.)
226 p7=Point(1.,1.,1.)
227 \end{python}
228 We connect the points to form the bottom and top surfaces of the cube:
229 \begin{python}
230 l01=Line(p0,p1)
231 l13=Line(p1,p3)
232 l32=Line(p3,p2)
233 l20=Line(p2,p0)
234 bottom=PlaneSurface(-CurveLoop(l01,l13,l32,l20))
235 \end{python}
236 Similar to the definition of a \code{CurvedLoop} the orientation of the surfaces \code{SurfaceLoop} is relevant. In fact the surface normal direction defined by the the right hand rule needs to point outwards as indicated by the surface normals in
237 Figure~\ref{fig:PYCAD 2}. As the \code{bottom} face is directed upwards it is inserted with the minus sign
238 into the \code{SurfaceLoop} in order to adjust the orientation of the surface.
239 Similarly we set
240 \begin{python}
241 l45=Line(p4,p5)
242 l57=Line(p5,p7)
243 l76=Line(p7,p6)
244 l64=Line(p6,p4)
245 top=PlaneSurface(CurveLoop(l45,l57,l76,l64))
246 \end{python}
247 To form the front face we introduce the two additional lines connecting the left and right front
248 points of the the \code{top} and \code{bottom} face:
249 \begin{python}
250 l15=Line(p1,p5)
251 l40=Line(p4,p0)
252 \end{python}
253 To form the front face we encounter the problem as the line \code{l45} used to define the
254 \code{top} face is pointing the wrong direction. In \pycad you can reversing direction of an
255 object by changing its sign. So we write \code{-l45} to indicate that the direction is to be reversed. With this notation we can write
256 \begin{python}
257 front=PlaneSurface(CurveLoop(l01,l15,-l45,l40))
258 \end{python}
259 Keep in mind that if you use \code{Line(p4,p5)} instead \code{-l45} both objects are treated as different although the connecting the same points with a straight line in the same direction. The resulting geometry would include an opening along the \code{p4}--\code{p5} connection. This will lead to an inconsistent mesh and may result in a failure of the volumetric mesh generator. Similarly we can define the other sides of the cube:
260 \begin{python}
261 l37=Line(p3,p7)
262 l62=Line(p6,p2)
263 back=PlaneSurface(CurveLoop(l32,-l62,-l76,-l37))
264 left=PlaneSurface(CurveLoop(-l40,-l64,l62,l20))
265 right=PlaneSurface(CurveLoop(-l15,l13,l37,-l57))
266 \end{python}
267 We can now put the six surfaces together to form a \class{SurfaceLoop} defining the
268 boundary of the volume of the cube:
269 \begin{python}
270 sl=SurfaceLoop(top,bottom,front,back,left,right)
271 v=Volume(sl)
272 \end{python}
273 As in the 2D case, the \class{Design} class is used to define the geometry:
274 \begin{python}
275 from esys.pycad.gmsh import Design
276 from esys.finley import MakeDomain
277
278 des=Design(dim=3, element_size = 0.1, keep_files=True)
279 des.setScriptFileName("brick.geo")
280 des.addItems(v, top, bottom, back, front, left , right)
281
282 dom=MakeDomain(des)
283 dom.write("brick.fly")
284 \end{python}
285 Note that the \finley mesh file \file{brick.fly} will contain the
286 triangles used to define the surfaces as they are added to the \class{Design}.
287 The example script of the cube is included with the software in
288 \file{brick.py} in the \ExampleDirectory.
289
290 \section{Alternative File Formats}
291 \code{pycad} supports other file formats in including
292 I-DEAS universal file, VRML, Nastran and STL. The following example shows how
293 to generate the STL file \file{brick.stl}:
294 \begin{python}
295 from esys.pycad.gmsh import Design
296
297 des=Design(dim=3, element_size = 0.1, keep_files=True)
298 des.addItems(v, top, bottom, back, front, left , right)
299
300 des.setFileFormat(des.STL)
301 des.setMeshFileName("brick.stl")
302 des.generate()
303 \end{python}
304 The example script of the cube is included with the software in
305 \file{brick_stl.py} in the \ExampleDirectory.
306
307
308 \begin{figure}
309 % \centerline{\includegraphics[width=\figwidth]{refine1}}
310 \caption{Local refinement at the origin by
311 \var{local_scale=0.01}
312 with \var{element_size=0.3} and number of elements on the top set to 10.}
313 \label{fig:PYCAD 5}
314 \end{figure}
315
316 \section{Element Sizes}
317 The element size used globally is defined by the
318 \code{element_size} argument of the \class{Design}. The mesh generator
319 will try to use this mesh size everywhere in the geometry. In some cases it can be
320 desirable to use locally a finer mesh. A local refinement can be defined at each
321 \class{Point}:
322 \begin{python}
323 p0=Point(0.,0.,0.,local_scale=0.01)
324 \end{python}
325 Here the mesh generator will create a mesh with an element size which is by the factor \code{0.01}
326 times smaller than the global mesh size \code{element_size=0.3}, see Figure~\ref{fig:PYCAD 5}. The point where a refinement is defined must be a point of curve used to define the geometry.
327
328 Alternatively, one can define a mesh size along a curve by defining the number of elements to be used to subdivide the curve. For instance, to use $20$ element on line \code{l23} on uses:
329 \begin{python}
330 l23=Line(p2, p3)
331 l23.setElementDistribution(20)
332 \end{python}
333 Setting the number of elements on a curve overwrites the global mesh size \code{element_size}. The result is shown in Figure~\ref{fig:PYCAD 5}.
334
335 \section{\pycad Classes}
336 %\declaremodule{extension}{esys.pycad}
337 %\modulesynopsis{Python geometry description and meshing interface}
338
339 \subsection{Primitives}
340
341 Some of the most commonly-used objects in \pycad are listed here. For a more complete
342 list see the full API documentation.
343
344
345 \begin{classdesc}{Point}{x=0.,y=0.,z=0.\optional{,local_scale=1.}}
346 Create a point with from coordinates with local characteristic length \var{local_scale}
347 \end{classdesc}
348
349 \begin{classdesc}{CurveLoop}{list}
350 Create a closed curve from the \code{list}. of
351 \class{Line}, \class{Arc}, \class{Spline}, \class{BSpline},
352 \class{BrezierSpline}.
353 \end{classdesc}
354
355 \begin{classdesc}{SurfaceLoop}{list}
356 Create a loop of \class{PlaneSurface} or \class{RuledSurface}, which defines the shell of a volume.
357 \end{classdesc}
358
359 \subsubsection{Lines}
360 \begin{classdesc}{Line}{point1, point2}
361 Create a line with between starting and ending points.
362 \end{classdesc}
363 \begin{methoddesc}[Line]{setElementDistribution}{n\optional{,progression=1\optional{,createBump=\False}}}
364 Defines the number of elements on the line. If set it overwrites the local length setting which would be applied. The progression factor \var{progression} defines the change of element size between neighboured elements. If \var{createBump} is set
365 progression is applied towards the centre of the line.
366 \end{methoddesc}
367 \begin{methoddesc}[Line]{resetElementDistribution}{}
368 removes a previously set element distribution from the line.
369 \end{methoddesc}
370 \begin{methoddesc}[Line]{getElemenofDistribution}{}
371 Returns the element distribution as tuple of
372 number of elements, progression factor and bump flag. If
373 no element distribution is set None is returned.
374 \end{methoddesc}
375
376 \subsubsection{Splines}
377 \begin{classdesc}{Spline}{point0, point1, ...}
378 A spline curve defined by a list of points \var{point0}, \var{point1},....
379 \end{classdesc}
380 \begin{methoddesc}[Spline]{setElementDistribution}{n\optional{,progression=1\optional{,createBump=\False}}}
381 Defines the number of elements on the line. If set it overwrites the local length setting which would be applied. The progression factor \var{progression} defines the change of element size between neighboured elements. If \var{createBump} is set
382 progression is applied towards the centre of the line.
383 \end{methoddesc}
384 \begin{methoddesc}[Spline]{resetElementDistribution}{}
385 removes a previously set element distribution from the line.
386 \end{methoddesc}
387 \begin{methoddesc}[Spline]{getElemenofDistribution}{}
388 Returns the element distribution as tuple of
389 number of elements, progression factor and bump flag. If
390 no element distribution is set None is returned.
391 \end{methoddesc}
392
393 \subsubsection{BSplines}
394 \begin{classdesc}{BSpline}{point0, point1, ...}
395 A B-spline curve defined by a list of points \var{point0}, \var{point1},....
396 \end{classdesc}
397 \begin{methoddesc}[BSpline]{setElementDistribution}{n\optional{,progression=1\optional{,createBump=\False}}}
398 Defines the number of elements on the line. If set it overwrites the local length setting which would be applied. The progression factor \var{progression} defines the change of element size between neighboured elements. If \var{createBump} is set
399 progression is applied towards the centre of the line.
400 \end{methoddesc}
401 \begin{methoddesc}[BSpline]{resetElementDistribution}{}
402 removes a previously set element distribution from the line.
403 \end{methoddesc}
404 \begin{methoddesc}[BSpline]{getElemenofDistribution}{}
405 Returns the element distribution as tuple of
406 number of elements, progression factor and bump flag. If
407 no element distribution is set None is returned.
408 \end{methoddesc}
409
410 \subsubsection{Brezier Curves}
411 \begin{classdesc}{BezierCurve}{point0, point1, ...}
412 A Brezier spline curve defined by a list of points \var{point0}, \var{point1},....
413 \end{classdesc}
414 \begin{methoddesc}[BezierCurve]{setElementDistribution}{n\optional{,progression=1\optional{,createBump=\False}}}
415 Defines the number of elements on the line. If set it overwrites the local length setting which would be applied. The progression factor \var{progression} defines the change of element size between neighboured elements. If \var{createBump} is set
416 progression is applied towards the centre of the line.
417 \end{methoddesc}
418 \begin{methoddesc}[BezierCurve]{resetElementDistribution}{}
419 removes a previously set element distribution from the line.
420 \end{methoddesc}
421 \begin{methoddesc}[BezierCurve]{getElemenofDistribution}{}
422 Returns the element distribution as tuple of
423 number of elements, progression factor and bump flag. If
424 no element distribution is set None is returned.
425 \end{methoddesc}
426
427 \subsubsection{Arcs}
428 \begin{classdesc}{Arc}{centre_point, start_point, end_point}
429 Create an arc by specifying a centre for a circle and start and end points. An arc may subtend an angle of at most $\pi$ radians.
430 \end{classdesc}
431 \begin{methoddesc}[Arc]{setElementDistribution}{n\optional{,progression=1\optional{,createBump=\False}}}
432 Defines the number of elements on the line. If set it overwrites the local length setting which would be applied. The progression factor \var{progression} defines the change of element size between neighboured elements. If \var{createBump} is set
433 progression is applied towards the centre of the line.
434 \end{methoddesc}
435 \begin{methoddesc}[Arc]{resetElementDistribution}{}
436 removes a previously set element distribution from the line.
437 \end{methoddesc}
438 \begin{methoddesc}[Arc]{getElemenofDistribution}{}
439 Returns the element distribution as tuple of
440 number of elements, progression factor and bump flag. If
441 no element distribution is set None is returned.
442 \end{methoddesc}
443
444
445
446 \subsubsection{Plain surfaces}
447 \begin{classdesc}{PlaneSurface}{loop, \optional{holes=[list]}}
448 Create a plane surface from a \class{CurveLoop}, which may have one or more holes
449 described by \var{list} of \class{CurveLoop}.
450 \end{classdesc}
451 \begin{methoddesc}[PlaneSurface]{setElementDistribution}{n\optional{,progression=1\optional{,createBump=\False}}}
452 Defines the number of elements on all lines.
453 \end{methoddesc}
454
455 \begin{methoddesc}[PlaneSurface]{setRecombination}{\optional{max_deviation=45 * \var{DEG} }}
456 the mesh generator will try to recombine triangular elements
457 into quadrilateral elements. \var{max_deviation} (in radians) defines the
458 maximum deviation of any angle in the quadrilaterals from the right angle.
459 Set \var{max_deviation}=\var{None} to remove recombination.
460 \end{methoddesc}
461 \begin{methoddesc}[PlaneSurface]{setTransfiniteMeshing}{\optional{orientation="Left"}}
462 applies 2D transfinite meshing to the surface.
463 \var{orientation} defines the orientation of triangles. Allowed values
464 are \var{``Left''}, \var{``Right''} or \var{``Alternate''}. The
465 boundary of the surface must be defined by three or four lines where an
466 element distribution must be defined on all faces where opposite
467 faces uses the same element distribution. No holes must be present.
468 \end{methoddesc}
469
470
471
472 \subsubsection{Ruled Surfaces}
473 \begin{classdesc}{RuledSurface}{list}
474 Create a surface that can be interpolated using transfinite interpolation.
475 \var{list} gives a list of three or four lines defining the boundary of the
476 surface.
477 \end{classdesc}
478
479 \begin{methoddesc}[RuledSurface]{setRecombination}{\optional{max_deviation=45 * \var{DEG} }}
480 the mesh generator will try to recombine triangular elements
481 into quadrilateral elements. \var{max_deviation} (in radians) defines the
482 maximum deviation of any angle in the quadrilaterals from the right angle.
483 Set \var{max_deviation}=\var{None} to remove recombination.
484 \end{methoddesc}
485
486 \begin{methoddesc}[RuledSurface]{setTransfiniteMeshing}{\optional{orientation="Left"}}
487 applies 2D transfinite meshing to the surface.
488 \var{orientation} defines the orientation of triangles. Allowed values
489 are \var{``Left''}, \var{``Right''} or \var{``Alternate''}. The
490 boundary of the surface must be defined by three or four lines where an
491 element distribution must be defined on all faces where opposite
492 faces uses the same element distribution. No holes must be present.
493 \end{methoddesc}
494
495 \begin{methoddesc}[RuledSurface]{setElementDistribution}{n\optional{,progression=1\optional{,createBump=\False}}}
496 Defines the number of elements on all lines.
497 \end{methoddesc}
498
499 \subsubsection{Volumes}
500
501 \begin{classdesc}{Volume}{loop, \optional{holes=[list]}}
502 Create a volume given a \class{SurfaceLoop}, which may have one or more holes
503 define by the list of \class{SurfaceLoop}.
504 \end{classdesc}
505
506 \begin{methoddesc}[Volume]{setElementDistribution}{n\optional{,progression=1\optional{,createBump=\False}}}
507 Defines the number of elements on all lines.
508 \end{methoddesc}
509
510 \begin{methoddesc}[Volume]{setRecombination}{\optional{max_deviation=45 * \var{DEG} }}
511 the mesh generator will try to recombine triangular elements
512 into quadrilateral elements. These meshes are then used to generate the volume mesh if possible.
513 Together with transfinite meshing one can construct rectanglar meshes.
514 \var{max_deviation} (in radians) defines the maximum deviation of any angle in the quadrilaterals from the right angle.
515 Set \var{max_deviation}=\var{None} to remove recombination.
516 \end{methoddesc}
517
518 \begin{methoddesc}[Volume]{setTransfiniteMeshing}{\optional{orientation="Left"}}
519 applies transfinite meshing to the volume and all surfaces (if \var{orientation} is not equal to \var{None})
520 \var{orientation} defines the orientation of triangles. Allowed values
521 are \var{``Left''}, \var{``Right''} or \var{``Alternate''}. The
522 boundary of the surface must be defined by three or four lines where an
523 element distribution must be defined on all faces where opposite
524 faces uses the same element distribution.
525 If \var{orientation} is equal to \var{None} transfinite meshing is not switched on for the surfaces but needs
526 to be set by the user. No holes must be present.
527 \textbf{Warning: The functionality of transfinite meshing without recombination is not entirely clear in \gmshextern.
528 So please apply this method with care.}
529 \end{methoddesc}
530
531
532 %============================================================================================================
533 \subsection{Transformations}
534
535 Sometimes it's convenient to create an object and then make copies at
536 different orientations and in different sizes. Transformations are
537 used to move geometrical objects in the 3-dimensional space and to
538 resize them.
539
540 \begin{classdesc}{Translation}{\optional{b=[0,0,0]}}
541 defines a translation $x \to x+b$. \var{b} can be any object that can be converted
542 into a \numpy object of shape $(3,)$.
543 \end{classdesc}
544
545 \begin{classdesc}{Rotation}{\optional{axis=[1,1,1], \optional{ point = [0,0,0], \optional{angle=0*RAD} } } }
546 defines a rotation by \var{angle} around axis through point \var{point} and direction \var{axis}.
547 \var{axis} and \var{point} can be any object that can be converted
548 into a \numpy object of shape $(3,)$.
549 \var{axis} does not have to be normalised but must have positive length. The right hand rule~\cite{RIGHTHANDRULE}
550 applies.
551 \end{classdesc}
552
553
554 \begin{classdesc}{Dilation}{\optional{factor=1., \optional{centre=[0,0,0]}}}
555 defines a dilation by the expansion/contraction \var{factor} with
556 \var{centre} as the dilation centre.
557 \var{centre} can be any object that can be converted
558 into a \numpy object of shape $(3,)$.
559 \end{classdesc}
560
561 \begin{classdesc}{Reflection}{\optional{normal=[1,1,1], \optional{offset=0}}}
562 defines a reflection on a plane defined in normal form $n^t x = d$
563 where $n$ is the surface normal \var{normal} and $d$ is the plane \var{offset}.
564 \var{normal} can be any object that can be converted
565 into a \numpy object of shape $(3,)$.
566 \var{normal} does not have to be normalised but must have positive length.
567 \end{classdesc}
568
569 \begin{datadesc}{DEG}
570 A constant to convert from degrees to an internal angle representation in radians. For instance use \code{90*DEG} for $90$ degrees.
571 \end{datadesc}
572
573 \subsection{Properties}
574
575 If you are building a larger geometry you may find it convenient to
576 create it in smaller pieces and then assemble them into the whole.
577 Property sets make this easy, and they allow you to name the smaller
578 pieces for convenience.
579
580 Property sets are used to bundle a set of geometrical objects in a
581 group. The group is identified by a name. Typically a property set
582 is used to mark subregions with share the same material properties or
583 to mark portions of the boundary. For efficiency, the \Design class
584 object assigns a integer to each of its property sets, a so-called tag
585 \index{tag}. The appropriate tag is attached to the elements at
586 generation time.
587
588 See the file \code{pycad/examples/quad.py} for an example using a {\it PropertySet}.
589
590
591 \begin{classdesc}{PropertySet}{name,*items}
592 defines a group geometrical objects which can be accessed through a \var{name}
593 The objects in the tuple \var{items} mast all be \ManifoldOneD, \ManifoldTwoD or \ManifoldThreeD objects.
594 \end{classdesc}
595
596
597 \begin{methoddesc}[PropertySet]{getManifoldClass}{}
598 returns the manifold class \ManifoldOneD, \ManifoldTwoD or \ManifoldThreeD expected from the items
599 in the property set.
600 \end{methoddesc}
601
602 \begin{methoddesc}[PropertySet]{getDim}{}
603 returns the spatial dimension of the items
604 in the property set.
605 \end{methoddesc}
606
607 \begin{methoddesc}[PropertySet]{getName}{}
608 returns the name of the set
609 \end{methoddesc}
610
611 \begin{methoddesc}[PropertySet]{setName}{name}
612 sets the name. This name should be unique within a \Design.
613 \end{methoddesc}
614
615 \begin{methoddesc}[PropertySet]{addItem}{*items}
616 adds a tuple of items. They need to be objects of class \ManifoldOneD, \ManifoldTwoD or \ManifoldThreeD.
617 \end{methoddesc}
618
619 \begin{methoddesc}[PropertySet]{getItems}{}
620 returns the list of items
621 \end{methoddesc}
622
623 \begin{methoddesc}[PropertySet]{clearItems}{}
624 clears the list of items
625 \end{methoddesc}
626
627 \begin{methoddesc}[PropertySet]{getTag}{}
628 returns the tag used for this property set
629 \end{methoddesc}
630
631 \section{Interface to the mesh generation software}
632 %\declaremodule{extension}{esys.pycad.gmsh}
633 %\modulesynopsis{Python geometry description and meshing interface}
634
635 The class and methods described here provide an interface to the mesh
636 generation software, which is currently \gmshextern. This interface could be
637 adopted to triangle or another mesh generation package if this is
638 deemed to be desirable in the future.
639
640 \begin{classdesc}{Design}{
641 \optional{dim=3, \optional{element_size=1., \optional{order=1, \optional{keep_files=False}}}}}
642 The \class{Design} describes the geometry defined by primitives to be meshed.
643 The \var{dim} specifies the spatial dimension. The argument \var{element_size} defines the global
644 element size which is multiplied by the local scale to set the element size at each \Point.
645 The argument \var{order} defines the element order to be used. If \var{keep_files} is set to
646 \True temporary files a kept otherwise they are removed when the instance of the class is deleted.
647 \end{classdesc}
648
649
650 \begin{memberdesc}[Design]{GMSH}
651 gmsh file format~\cite{GMSH}.
652 \end{memberdesc}
653
654 \begin{memberdesc}[Design]{IDEAS}
655 I-DEAS universal file format~\cite{IDEAS}.
656 \end{memberdesc}
657
658 \begin{memberdesc}[Design]{VRML}
659 VRML file format, \cite{VRML}.
660 \end{memberdesc}
661
662 \begin{memberdesc}[Design]{STL}
663 STL file format~\cite{STL}.
664 \end{memberdesc}
665 \begin{memberdesc}[Design]{NASTRAN}
666 NASTRAN bulk data format~\cite{NASTRAN}.
667 \end{memberdesc}
668
669 \begin{memberdesc}[Design]{MEDIT}
670 Medit file format~\cite{MEDIT}.
671 \end{memberdesc}
672
673 \begin{memberdesc}[Design]{CGNS}
674 CGNS file format~\cite{CGNS}.
675 \end{memberdesc}
676
677 \begin{memberdesc}[Design]{PLOT3D}
678 Plot3D file format~\cite{PLOT3D}.
679 \end{memberdesc}
680
681
682 \begin{memberdesc}[Design]{DIFFPACK}
683 Diffpack 3D file format~\cite{DIFFPACK}.
684 \end{memberdesc}
685
686 \begin{memberdesc}[Design]{DELAUNAY}
687 the Delauny triangulator, see \gmshextern,~\cite{TETGEN}.
688 \end{memberdesc}
689
690 \begin{memberdesc}[Design]{MESHADAPT}
691 the gmsh triangulator, see \gmshextern.
692 \end{memberdesc}
693
694 \begin{memberdesc}[Design]{FRONTAL}
695 the NETGEN~\cite{NETGEN} triangulator.
696 \end{memberdesc}
697
698 \begin{methoddesc}[Design]{generate}{}
699 generates the mesh file. The data are are written to the file \var{Design.getMeshFileName}.
700 \end{methoddesc}
701
702
703 \begin{methoddesc}[Design]{setDim}{\optional{dim=3}}
704 sets the spatial dimension which needs to be $1$, $2$ or $3$.
705 \end{methoddesc}
706
707 \begin{methoddesc}[Design]{getDim}{}
708 returns the spatial dimension.
709 \end{methoddesc}
710
711 \begin{methoddesc}[Design]{setElementOrder}{\optional{order=1}}
712 sets the element order which needs to be $1$ or $2$.
713 \end{methoddesc}
714
715 \begin{methoddesc}[Design]{getElementOrder}{}
716 returns the element order.
717 \end{methoddesc}
718
719 \begin{methoddesc}[Design]{setElementSize}{\optional{element_size=1}}
720 set the global element size. The local element size at a point is defined as
721 the global element size multiplied by the local scale. The element size must be positive.
722 \end{methoddesc}
723
724
725 \begin{methoddesc}[Design]{getElementSize}{}
726 returns the global element size.
727 \end{methoddesc}
728
729
730
731 \begin{methoddesc}[Design]{setKeepFilesOn}{}
732 work files are kept at the end of the generation.
733 \end{methoddesc}
734
735 \begin{methoddesc}[Design]{setKeepFilesOff}{}
736 work files are deleted at the end of the generation.
737 \end{methoddesc}
738
739 \begin{methoddesc}[Design]{keepFiles}{}
740 returns \True if work files are kept. Otherwise \False is returned.
741 \end{methoddesc}
742
743 \begin{methoddesc}[Design]{setScriptFileName}{\optional{name=None}}
744 set the file name for the gmsh input script. if no name is given a name with extension "geo" is generated.
745 \end{methoddesc}
746
747 \begin{methoddesc}[Design]{getScriptFileName}{}
748 returns the name of the file for the gmsh script.
749 \end{methoddesc}
750
751
752 \begin{methoddesc}[Design]{setMeshFileName}{\optional{name=None}}
753 sets the name for the mesh file. if no name is given a name is generated.
754 The format is set by \\ \var{Design.setFileFormat}.
755 \end{methoddesc}
756
757 \begin{methoddesc}[Design]{getMeshFileName}{}
758 returns the name of the mesh file
759 \end{methoddesc}
760
761
762 \begin{methoddesc}[Design]{addItems}{*items}
763 adds the tuple of var{items}. An item can be any primitive or a \class{PropertySet}.
764 \warning{If a \PropertySet is added as an item added object that are not
765 part of a \PropertySet are not considered in the messing.
766 }
767 \end{methoddesc}
768
769 \begin{methoddesc}[Design]{getItems}{}
770 returns a list of the items
771 \end{methoddesc}
772
773 \begin{methoddesc}[Design]{clearItems}{}
774 resets the items in design
775 \end{methoddesc}
776
777 \begin{methoddesc}[Design]{getMeshHandler}{}
778 returns a handle to the mesh. The call of this method generates the mesh from the geometry and
779 returns a mechanism to access the mesh data. In the current implementation this
780 method returns a file name for a file containing the mesh data.
781 \end{methoddesc}
782
783 \begin{methoddesc}[Design]{getScriptString}{}
784 returns the gmsh script to generate the mesh as a string.
785 \end{methoddesc}
786
787 \begin{methoddesc}[Design]{getCommandString}{}
788 returns the gmsh command used to generate the mesh as string.
789 \end{methoddesc}
790
791 \begin{methoddesc}[Design]{setOptions}{
792 \optional{optimize_quality=\True
793 \optional{, smoothing=1
794 \optional{, curvature_based_element_size=\False\\
795 \optional{, algorithm2D=\var{Design.MESHADAPT}
796 \optional{, algorithm3D=\var{Design.FRONTAL}\\
797 \optional{, generate_hexahedra=False}}}}}}}
798 sets options for the mesh generator. \var{algorithm2D} sets the 2D meshing algorithm to be used.
799 The algorithm needs to be \var{Design.DELAUNAY}
800 \var{Design.FRONTAL}
801 or \var{Design.MESHADAPT}. By default \var{Design.MESHADAPT} is used.
802 \var{algorithm3D} sets the 3D meshing algorithm to be used.
803 The algorithm needs to be \var{Design.DELAUNAY}
804 or \var{Design.FRONTAL}
805 . By default \var{Design.FRONTAL} is used.
806 \var{optimize_quality}=\True invokes an optimization of the mesh quality.
807 \var{smoothing} sets the number of smoothing steps to be applied to the mesh.
808 \var{curvature_based_element_size}=\True switches on curvature based definition of element size.
809 \var{generate_hexahedra}=\True switches on the usage of quadrilateral/hexahedra elements.
810 \end{methoddesc}
811
812 \begin{methoddesc}[Design]{getTagMap}{}
813 returns a \class{TagMap} to map the name \class{PropertySet} in the class to tag numbers generated by gmsh.
814 \end{methoddesc}
815
816 \begin{methoddesc}[Design]{setFileFormat}{\optional{format=\var{Design.GMSH}}}
817 set the file format. \var{format} must be one of the values:\\
818 \var{Design.GMSH} \\
819 \var{Design.IDEAS}\\
820 \var{Design.VRML}\\
821 \var{Design.STL}\\
822 \var{Design.NASTRAN}\\
823 \var{Design.MEDIT}\\
824 \var{Design.CGNS}\\
825 \var{Design.PLOT3D}\\
826 \var{Design.DIFFPACK}.
827 \end{methoddesc}
828
829 \begin{methoddesc}[Design]{getFileFormat}{}
830 returns the file format.
831 \end{methoddesc}

  ViewVC Help
Powered by ViewVC 1.1.26