next up previous contents index
Next: Holes Up: The Module esys.pycad Previous: Introduction   Contents   Index

The Unit Square

So the simplest geometry is the unit square. First we generate the corner points
\begin{python}
from esys.pycad import *
p0=Point(0.,0.,0.)
p1=Point(1.,0.,0.)
p2=Point(1.,1.,0.)
p3=Point(0.,1.,0.)
\end{python}
which are then linked to define the edges of the square
\begin{python}
l01=Line(p0,p1)
l12=Line(p1,p2)
l23=Line(p2,p3)
l30=Line(p3,p0)
\end{python}
The lines are put together to form a loop
\begin{python}
c=CurveLoop(l01,l12,l23,l30)
\end{python}
The orientation of the line defining the CurveLoop is important. It is assumed that the surrounded area is to the left when moving along the lines from their starting points towards the end points. Moreover, the line need to form a closed loop.

We use the CurveLoop to define a surface
\begin{python}
s=PlaneSurface(c)
\end{python}
Notice there is difference between the CurveLoop defining the boundary of the surface and the actually surface PlaneSurface. This difference becomes clearer in the next example with a hole. The direction of the lines is important. New we are ready to define the geometry which described by an instance of Design class:
\begin{python}
d=Design(dim=2,element_size=0.05)
\end{python}
Here we use the two dimensional domain with a local element size in the finite element mesh of $ 0.05$ . We then add the surface s to the geometry
\begin{python}
d.addItems(s)
\end{python}
This will automatically import all items used to construct s into the Design d. Now we are ready to construct a esys.finley FEM mesh and then write it to the file quad.fly:
\begin{python}
from esys.finley import MakeDomain
dom=MakeDomain(d)
dom.write(''quad.fly'')
\end{python}
In some cases it is useful to access the script used to generate the geometry. You can specify a specific name for the script file. In our case we use
\begin{python}
d.setScriptFileName(''quad.geo'')
\end{python}
It is also useful to check error messages generated during the mesh generation process. Gmsh[19] writes messages to the .gmsh-errors in your home directory.

If we put everything together we get the script
\begin{python}
from esys.pycad import *
from esys.pycad.gmsh import Design
from ...
...l30)
d.addItems(pl1, pl2)
dom=MakeDomain(d)
dom.write(''quad.fly'')
\end{python}
This example is included with the software in quad.py in the example directory.

There are three extra statements which we have not discussed yet: By default the mesh used to subdivide 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 lines on the top and the bottom with the name ``top_and_bottom`` and the lines on the left and right hand side with the name ``sides`` using PropertySet objects. The labeling is convenient when using tagging , see Chapter 3.

Figure 5.1: Trapozid with triangle Hole.
\includegraphics[width=100mm]{figures/quad}

If you have Gmsh[19] installed you can run the example and view the geometry and mesh with:
\begin{python}
run-escript quad.py
gmsh quad.geo
gmsh quad.msh
\end{python}
You can access error messages from Gmsh[19] in the .gmsh-errors in your home directory. See Figure 5.1 for a result.

In most cases it is best practice to generate the mesh and to solve the mathematical model in to different scripts. In our example you can read the esys.finley mesh into your simulation code[*] using
\begin{python}
from finley import ReadMesh
mesh=ReadMesh(''quad.fly'')
\end{python}
Note that the underlying mesh generation software will not accept all the geometries you can create with esys.pycad. For example, esys.pycad will happily allow you to create a 2-D Design that is a closed loop with some additional points or lines lying outside of the enclosed area, but Gmsh[19] will fail to create a mesh for it.

Figure 5.2: Trapozid with triangle Hole.
\includegraphics[width=100mm]{figures/trap}


next up previous contents index
Next: Holes Up: The Module esys.pycad Previous: Introduction   Contents   Index
esys@esscc.uq.edu.au