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

Construct the shell mesh in fenics

+2 votes

Hi, all:

I wonder if I could construct a cylindrical shell mesh in the fenics by its own meshtools, like the figure belowcylindrical shell mesh, or I need to construct my own?

asked Feb 12, 2017 by linyx FEniCS Novice (210 points)

2 Answers

+2 votes
 
Best answer

Here is one way to generate it:

from numpy import *
from dolfin import *

# Parameters
height = 50
radius = 0.1 

# Mesh parameters
nh = 100
nr = 20 

# Generate suitable ranges for parameters
u_range = arange(nr, dtype='d')/nr*2*pi
v_range = (arange(nh, dtype='d'))/(nh - 1)*height

# Create the mesh
mesh = Mesh()
editor = MeshEditor()
editor.open(mesh, "triangle", 2, 3)

# Create a list to store the vertices
editor.init_vertices(nh*nr)

# Populate the list of vertices
j = 0
for v in v_range:
    for u in u_range:
        editor.add_vertex(j,  cos(u)*radius, \
                              sin(u)*radius, \
                              v)
        j = j + 1


# Create a list to store the cells
editor.init_cells(nr*(nh-1)*2)

# Populate the list of cells
k = 0
for i in range(nh - 1):
    for j in range(nr - 1):
        editor.add_cell(k    , i*nr + j, (i + 1)*nr + j + 1, i*nr + j + 1) 
        editor.add_cell(k + 1, i*nr + j, (i + 1)*nr + j    , (i + 1)*nr + j + 1)
        k = k + 2

# Close the geometry
for j in range(nh-1):
    editor.add_cell(k    , nr*j+nr-1, nr*j, nr*(j+1))
    editor.add_cell(k + 1, nr*j+nr-1, nr*(j+1)+nr-1, nr*(j+1))
    k = k + 2

plot(mesh)
interactive()
answered Feb 20, 2017 by str FEniCS User (1,600 points)
selected Jun 19, 2017 by linyx
+1 vote

You might be able to do what you want with mshr. See for instance the extrude.py demo. Something like the following will create a cylinder:

from dolfin import *                                                 
import mshr                                                          

g2d = mshr.Circle(Point(0,0), 1) - mshr.Circle(Point(0,0), 0.9)      

# Any simple 2D geometry can be extruded to 3D                       
g3d = mshr.Extrude2D(g2d,                                            
                     5) # The z "thickness"                          

m = mshr.generate_mesh(g3d, 15)                                      
plot(m, interactive=True)                                            
answered Feb 13, 2017 by johannr FEniCS Expert (17,350 points)

Thanks for your reply.

But I need "zero" thickness, which a typical shell element should have, is there any closed circle line mesh, so that I could extrude as well?

...