Using different element id in a single mesh

52 views
Skip to first unread message

hoover.a...@gmail.com

unread,
Jan 29, 2025, 1:52:35 PMJan 29
to IBAMR Users
Hi all,

I'd like to have apply a stress or force to certain parts of a mesh at different points of a simulation. The mesh I'm using was designed so as to have different element IDs for different regions. I would like to use the same general stress/force function for different parts of the mesh, using the id to distinguish the different mesh parts.

In a previous post, I asked about doing a similar process for one mesh that was copied and translated and used the element id to distinguish between different meshes:

int elid= elem->subdomain_id();

 In that process I designated elem->subdomain_id() in the following manner:

        int num_parts = 9;
        vector<shared_ptr<Mesh>> mesh_shared_ptr_vec(num_parts);
        vector<MeshBase*> meshes(num_parts);
        for (int part = 0; part < num_parts; ++part)
        {
          mesh_shared_ptr_vec[part] = make_shared<Mesh>(init.comm(), NDIM);
          mesh_shared_ptr_vec[part]->read(mesh_filename);
          mesh_shared_ptr_vec[part]->prepare_for_use();

          // the IBFE interface still takes in raw pointers, so we need to get it from the
          // shared_ptr:
          meshes[part]=  mesh_shared_ptr_vec[part].get();
         
        }
        for (int part = 0; part < num_parts; ++part)
        {
          MeshBase* mesh = meshes[part];
          for (auto& elem : mesh->element_ptr_range())
          {
            elem->subdomain_id() = part;
          }
        }

If now I have a single mesh, with different element IDs from the meshing process, would I need to designate these mesh ids? Do I need to register stress/forcing functions for each id? The main difference is navigating a mesh with multiple parts rather than a vector of meshes  Thanks for any advice.

-Alex

hoover.a...@gmail.com

unread,
Jan 29, 2025, 1:59:19 PMJan 29
to IBAMR Users

hoover.a...@gmail.com

unread,
Feb 25, 2025, 1:57:33 PMFeb 25
to IBAMR Users
Hello,

Returning for a bit of hope on more guidance. I have a single mesh with different element IDs for different parts of the mesh.  I do not want to have separate files per element ID. Below is code that will not work because I cannot reference the different element IDs to describe what forces are acting on it.

        Mesh mesh(init.comm(), NDIM);
        const string mesh_filename = input_db->getStringWithDefault("MESH_FILENAME","template.msh");
        mesh.read(mesh_filename);
        mesh.prepare_for_use();

I have looked through examples and what I mostly see are using 'vector<MeshBase*>' and then inputting a different mesh for each of the indices of the mesh vector. I would like to have a vector entry for each element ID so I can set different equations for each of the parts.

Best,
Alex

Boyce Griffith

unread,
Sep 6, 2025, 7:38:08 PMSep 6
to IBAMR Users

On Feb 25, 2025, at 10:57 AM, hoover.a...@gmail.com <hoover.a...@gmail.com> wrote:

Hello,

Returning for a bit of hope on more guidance. I have a single mesh with different element IDs for different parts of the mesh.  I do not want to have separate files per element ID. Below is code that will not work because I cannot reference the different element IDs to describe what forces are acting on it.

        Mesh mesh(init.comm(), NDIM);
        const string mesh_filename = input_db->getStringWithDefault("MESH_FILENAME","template.msh");
        mesh.read(mesh_filename);
        mesh.prepare_for_use();

I have looked through examples and what I mostly see are using 'vector<MeshBase*>' and then inputting a different mesh for each of the indices of the mesh vector. I would like to have a vector entry for each element ID so I can set different equations for each of the parts.

Did you get this sorted out? What you want to do is to look up the element ID when evaluating the force / stress and then choose the formulation accordingly. Each element knows its subdomain ID — you can access via elem->subdomain_id().

— Boyce

-- 
You received this message because you are subscribed to the Google Groups "IBAMR Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ibamr-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ibamr-users/7d795fda-eb5f-4a2e-a44f-7d687842b8e8n%40googlegroups.com.

hoover.a...@gmail.com

unread,
Sep 9, 2025, 12:49:20 PMSep 9
to IBAMR Users
Yes! Here is how I got this to work:

stress_function(
    TensorValue<double>& PP,
    const TensorValue<double>& FF,
    const libMesh::Point& X,
    const libMesh::Point& s,
  Elem* const elem,
  const std::vector<const std::vector<double>*>& /*var_data*/,
  const std::vector<const std::vector<VectorValue<double> >*>& /*grad_var_data*/,
  double time,
  void* ctx)
{
 

  // dereference the pointer to get the part number:
  int part_num = elem->subdomain_id();

  double phi=0.0;
  if(part_num==2){
    phi=.25*PI*p_phase;
  }
  if(part_num==3){
    phi=.50*PI*p_phase;
  }
....

Boyce Griffith

unread,
Sep 9, 2025, 1:04:37 PMSep 9
to IBAMR Users
Reply all
Reply to author
Forward
0 new messages