Exemplo n.º 1
0
std::unique_ptr<MeshBase>
ImageSubdomainGenerator::generate()
{
  std::unique_ptr<MeshBase> mesh = std::move(_input);

  // Initialize the ImageSampler
  setupImageSampler(*mesh);

  // Loop over the elements and sample the image at the element centroid and use the value for the
  // subdomain id
  for (auto & elem : mesh->active_element_ptr_range())
  {
    subdomain_id_type id = static_cast<subdomain_id_type>(round(sample(elem->centroid())));
    elem->subdomain_id() = id;
  }

  return dynamic_pointer_cast<MeshBase>(mesh);
}
Exemplo n.º 2
0
void
ImageSubdomain::modify()
{
  // Check that we have access to the mesh
  if (!_mesh_ptr)
    mooseError("_mesh_ptr must be initialized before calling SubdomainBoundingBox::modify()");

  // Initialize the ImageSampler
  setupImageSampler(*_mesh_ptr);

  // Reference the the libMesh::MeshBase
  MeshBase & mesh = _mesh_ptr->getMesh();

  // Loop over the elements and sample the image at the element centroid and use the value for the subdomain id
  for (MeshBase::element_iterator el = mesh.active_elements_begin(); el != mesh.active_elements_end(); ++el)
  {
    SubdomainID id = static_cast<SubdomainID>(round(sample((*el)->centroid())));
    (*el)->subdomain_id() = id;
  }
}