/[escript]/branches/stage3.1/doc/user/pycad.tex
ViewVC logotype

Contents of /branches/stage3.1/doc/user/pycad.tex

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2945 - (show annotations)
Wed Feb 24 00:17:46 2010 UTC (8 years, 11 months ago) by jfenwick
File MIME type: application/x-tex
File size: 32674 byte(s)
Bringing release stage up to trunk version 2944

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

  ViewVC Help
Powered by ViewVC 1.1.26