Featured

Rotationally symmetric geometries

To obtain a torus we define a circle around the point \( \texttt{(0,R)} \). This is done by defining a set of control points which are the used to define splines. These points and splines are then added to the SplineCurve2d using the functions AddPoint and AddSegment.

spline = SplineCurve2d() # create a 2d spline
R = 1                    # define the major radius
r = 0.2                  # define the minor radius
eps = r*1e-2

# define the control points
pnts = [ (0,R-r), (-r+eps,R-r+eps), (-r,R),
         (-r+eps,R+r-eps), (0,R+r), (r-eps,R+r-eps), (r,R), (r-eps,R-r+eps) ]
# define the splines using the control points
segs = [ (0,1,2), (2,3,4), (4,5,6), (6,7,0) ]

# add the points and segments to the spline
for pnt in pnts:
    spline.AddPoint (*pnt)

for seg in segs:
    spline.AddSegment (*seg)
The torus is then generated by rotating the two dimensional spline around the axis defined by the points \( \texttt{(-1,0,0)} \) and \( \texttt{(1,0,0)} \).
rev = Revolution ( Pnt(-1,0,0), Pnt(1,0,0), spline)
Finally we have to generate a CSG object and add the just defined torus.
geo = CSGeometry()
geo.Add (rev.col([1,0,0]))
geo.Draw()
Now we can generate a mesh for our torus.
mesh = geo.GenerateMesh(maxh=0.5, optsteps2d=3)
To curve the mesh we have to convert it to a NGSolve mesh. This can be done the following way.
mesh = Mesh(mesh)
mesh.Curve(3)	

Attachments
torus.py [934B]
Uploaded Wednesday, 11 January 2017 by Christoph Wintersteiger