I am starting a fun learning project that will help you to understand better what is a mesh set and how to create one from scratch with Python! You will learn:
- What a mesh set is composed of
- How to generate nodes
- How to use Delaunay triangulation to generate elements
- How to write all of that to a mesh file
Here’s the video:
The final code is available here:
https://github.com/CyprienRusu/Feaforall/tree/master/Simple_Mesh
The plate with a hole post I am mentioning in the video is here:
There is plenty of room for improvement here and if you have some ideas on how to make it better, please let me know!
Cyprien “Getting Meshed Today” Rusu
Angus Ramsay says
Hi Cyprien, Nice to see how one might use Python to generate meshes but, and I guess you’ll agree, the result is rather distorted. Far better for this sort of problem to use a structured mesh of quadrilaterals which would give almost square elements around the hole and alleviate the distortion issue. Might be interesting to compare the stresses from the two approaches in terms of the stress concentration factor.
Regards,
Angus.
Cyprien says
Yes, I agree with you! That’s actually what I am saying in the video too… I was a bit short in time to find a better solution for now, but will definitely work on it ;-)
I plan also to compare the stresses like you mention !
Armando de la Rocha, P.E. says
It looks like a fun project and good way to learn the topic.
Regards,
Juan S says
Hello there,
I’ve been coding in Python for some time but nothing related with FEA. This post has motivated me to make a try. My first tries were with matplotlib.tri and then with Triangle ( https://rufat.be/triangle/ ). I couldn’t get satisfactory results with those packages so finally I decided to try a package called pygmsh and it worked really well.
Here is my code:
##Before run this code you need to install gmsh and pygmsh with pip
##pip install gmsh
##pip install pygmsh
# Import pygmsh
import pygmsh as pg
# Data
L = 0.1
h = 0.05
r = 0.02
# Create geometry with opencascade (occ)
with pg.occ.Geometry() as geom:
characteristic_length_min=0.01,
characteristic_length_max=0.01,
# Create a rectangle
rectangle = geom.add_rectangle([0.0, 0.0, 0.0], L, h)
# Create a disk
disk = geom.add_disk([0.0, 0.0, 0.0], r)
# Create union difference between rectangle and disk
union = geom.boolean_difference(rectangle, disk)
# Generate mesh
mesh = geom.generate_mesh()
# Write a file with mesh data called ‘test.vtk’. (Can be opened with Paraview)
mesh.write(‘test.vtk’)
# Write a file with mesh data called ‘test.msh’. (Can be opened with a text editor)
pg.write(‘test.msh’)
Regards,
Juan
Cyprien says
Thank you Juan for sharing your code here!
That’s awesome, I’ll try it out