How to make a 3D Cylinder Mesh?

I want to generate a cylindrical shape in FEniCS, but have been unable to find documentation or example codes that would allow me to make this. Previous code does not work in the newer versions of FEniCS. I am running FEniCS through docker. I don’t have any code to show because I am a complete newbie and don’t really know where else to ask for help.


Consider this:

from dolfin import *
from mshr import *

#Making a cylindrical geometry
cylinder = Cylinder(Point(0, 0, -1), Point(0, 0, 1), 0.5, 0.5)
geometry = cylinder

# Making Mesh (40 corresponds to the mesh density)
mesh = generate_mesh(geometry, 40)

# Save the mesh
File("cylinder.pvd") << mesh

Here is the mesh:


Hi Leo! Thank you! This worked on my computer! Any idea on how to make shapes contract on FEniCS? I want to compress and stretch the cylinder. Any help would be greatly appreciated!

You can adjust the dimensions like:

cylinder = Cylinder('coordinate of center of the top circle', 'coordinate of center of the bottom circle', 'radius of the circle at the top', 'radius of the circle at the bottom')

Then you can compress and stretch it. For more information please have a look at this