pythonmeshcadfinite-element-analysisfreecad

How to auto-generate mesh from .step file using GMSH or similar?


I need to produce simulation data for randomly generated cantilever beams, and save their maximum deflection given a load, and/or perform frequency-response analysis. To do this the body needs to be meshed as an FEM mesh. Hence, I would like to write a script that generates a mesh file (.msh) from that single-body .step file.

Desired Pipeline: Input: single-body .step file of a cantilever beam with an arbitrary cross-section Output: .msh file of the meshed body


Solution

  • See the solution below:

    Merge "test.step";
    
    Mesh.Algorithm3D = 1;
    // 1=Delaunay, 4=Frontal, 5=Frontal Delaunay, 6=Frontal Hex, 7=MMG3D, 9=R-tree
    // default = 1
    
    //Mesh  2;  // surface
    Mesh  3;  // volume
    
    Mesh.Format = 2;
    // 1=msh, 2=unv, 10=automatic, 19=vrml, 27=stl, 30=mesh, 31=bdf, 32=cgns, 33=med, 40=ply2
    // default = 10
    
    Mesh.SaveAll = 1;
    // Ignore Physical definitions and save all elements
    
    Save "mymesh.msh";