This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to convert 2D mesh geometry into 3D?

0 votes

I'm trying to rotate a 2D mesh (generated from Rectangle) around the x-axis, but rotate complains that it can only rotate around z. Is there an easy way to convert its dimension from 2 to 3? I've tried editing/replacing the mesh.coordinates() directly, but this causes a seg fault.

asked Oct 21, 2013 by asherp FEniCS Novice (340 points)

For those wondering, it looks easier to construct the plane with the desired normal using netgen, currently in the development version of FEnics.

This is not an answer but a comment. Please make it a comment or simply edit your question accordingly.

1 Answer

+1 vote
 
Best answer

I was just trying to do this to plot a parametric 2D surface in 3D, and found the following useful:

Googling fenics embedded mesh gave some test source code to create meshes with the right topology using the BoundaryMesh constructor:
https://github.com/FEniCS/dolfin/blob/master/test/unit/fem/python/Form.py

So I can create a 3D throw-away mesh and extract a useful
surface.

Benjamin Kehlet (benjamik) wrote some nice example code for generating meshes from CSG entities using CGAL:
https://answers.launchpad.net/fenics/+question/214429
He referenced the manual at: http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Mesh_3/Chapter_main.html

c = Cone(Point(0, 0, -1), Point(0, 0, 1), .5, 1.0)
def setparams(): # optional
  generator = CSGCGALMeshGenerator3D(c)
  generator.parameters["cell_size"] = 0.1
m = Mesh(c, 16)

So the full source is here:

def CutMesh(mesh, theTest):
    class TheCut(SubDomain):
        def inside(self, x, on_boundary):
            return theTest(x)
    cut = TheCut()

    # Initialize mesh function for interior domains
    subdomains = CellFunction('size_t', mesh)
    subdomains.set_all(0)
    cut.mark(subdomains, 1)

    return SubMesh(mesh, subdomains, 1)

def embeddedDisk(rmax, res, h): # res = int(2/h) works well.
   C = 2*pi*rmax
   cyl = Cylinder(Point(0,0,1), Point(0,0,0), rmax, int(0.5*C/h))
   mesh = Mesh(cyl, res)
   omega = BoundaryMesh(mesh, "exterior")
   disk = CutMesh(omega, lambda x: abs(x[2]-0.0) < 1e-8)

   return disk
answered Dec 6, 2013 by David M. Rogers FEniCS Novice (460 points)
selected Dec 6, 2013 by asherp

Thanks! I was having problems getting the developer version installed and had basically given up. I was going to try constructing a mesh in Open-dx and importing (if that's still supported). It is kindof strange how awkward this is.

...