Creating subdomains in mshr with an stl file

I’m trying to explore different workflows for running a simulation. In this case I want to bypass the gmsh step by directly importing and mesh my 3D geometry using mshr. Here is a simple code I wrote to successfully read and mesh the .stl file

#include <dolfin.h>
#include <mshr.h>

using namespace dolfin;

int main(int argc, char **argv)
{
    auto geom = std::make_shared<mshr::Surface3D>("../test.stl");
    
    std::shared_ptr<dolfin::Mesh> mesh; 
    mesh = mshr::generate_mesh(geom, 100);

    MeshFunction<std::size_t>
        meshfile(mesh, mesh->topology().dim());

    // Output cell distribution to VTK file
    File file("mesh.pvd");
    file << meshfile;
}

my issue now is how do I define subdomains using mshr. In gmsh I just select faces and mark them as physical regions, is there an equivalent way of doing that in mshr?

I would not recommend using mshr as it is no longer developed, as you can see from the Changelog, and there are very few demos on how to use it. You could have a look at files such as this: https://bitbucket.org/fenics-project/mshr/raw/8895485f2ec5e0378405a614d89ea1651281e364/3rdparty/CGAL/demo/Polyhedron/Plugins/Mesh_3/Polyhedron_demo_mesh_3_labeled_mesh_domain_3.h

Thanks for the fast response.

Now I’m wondering if this thing I’m trying to do is normal at all.

Have you seen anyone trying to do this?

I have not seen it done with mshr (most people use mshr for semi-simple geometries, Where one can use geometrical subdomain markers).

There is STL support in Gmsh. I would Also recommend writing/reading meshes in the xdmf format, as it is more suitable for parallel computing. See this Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio or this Converter from GMSH to XDMF (with physical groups) post.

Yes that is my usual workflow. generating .step file in OnShape -> meshing & naming subdomains in gmsh -> write .xdmf using meshio -> simulate using dolfin

my intent was to somehow bypass all those gmsh and meshio bits. But it seems like this experiment is a failure!

Thanks for your time @dokken.