libMesh
mesh_subdomain_id.C
Go to the documentation of this file.
1 #include <libmesh/libmesh.h>
2 #include <libmesh/elem.h>
3 #include <libmesh/mesh.h>
4 #include <libmesh/mesh_generation.h>
5 
6 #include "test_comm.h"
7 #include "libmesh_cppunit.h"
8 
9 
10 using namespace libMesh;
11 
12 class MeshSubdomainIDTest : public CppUnit::TestCase
13 {
18 public:
19  LIBMESH_CPPUNIT_TEST_SUITE( MeshSubdomainIDTest );
20 
21  CPPUNIT_TEST( testUnpartitioned );
22  CPPUNIT_TEST( testMultiple );
23 
24  CPPUNIT_TEST_SUITE_END();
25 
26 public:
27  void setUp() {}
28 
29  void tearDown() {}
30 
32  {
33  LOG_UNIT_TEST;
34 
35  std::unique_ptr<UnstructuredMesh> mesh = std::make_unique<Mesh>(*TestCommWorld);
36 
37  mesh->add_point(Point(0, 0, 0), 0);
38  mesh->add_point(Point(1, 0, 0), 1);
39 
40  Elem * elem = mesh.add_elem(Elem::build(EDGE2));
41  elem->set_node(0, mesh.node_ptr(0));
42  elem->set_node(1, mesh.node_ptr(1));
43 
44  std::set<subdomain_id_type> ids;
45  mesh->subdomain_ids(ids);
46 
47  CPPUNIT_ASSERT_EQUAL(mesh->n_subdomains(), (subdomain_id_type)1);
48  CPPUNIT_ASSERT_EQUAL(ids.size(), (std::size_t)1);
49  CPPUNIT_ASSERT_EQUAL(*ids.begin(), (subdomain_id_type)0);
50  }
51 
52  void testMultiple()
53  {
54  LOG_UNIT_TEST;
55 
56  std::unique_ptr<UnstructuredMesh> mesh = std::make_unique<Mesh>(*TestCommWorld);
57 
59 
60  std::set<subdomain_id_type> actual_ids;
61  for (auto & elem : mesh->active_element_ptr_range())
62  {
63  CPPUNIT_ASSERT(elem->id() < static_cast<dof_id_type>(Elem::invalid_subdomain_id));
64  actual_ids.insert((subdomain_id_type)elem->id());
65  elem->subdomain_id() = (subdomain_id_type)elem->id();
66  }
67 
68  std::set<subdomain_id_type> ids;
69  mesh->subdomain_ids(ids);
70 
71  CPPUNIT_ASSERT_EQUAL(ids.size(), actual_ids.size());
72  for (auto id : ids)
73  CPPUNIT_ASSERT(actual_ids.count(id));
74  }
75 };
76 
77 
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:2558
CPPUNIT_TEST_SUITE_REGISTRATION(MeshSubdomainIDTest)
TestClass subdomain_id_type
Based on the 4-byte comment warning above, this probably doesn&#39;t work with exodusII at all...
Definition: id_types.h:43
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
MeshBase & mesh
The libMesh namespace provides an interface to certain functionality in the library.
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
static const subdomain_id_type invalid_subdomain_id
A static integral constant representing an invalid subdomain id.
Definition: elem.h:251
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition: elem.C:444
void subdomain_ids(std::set< subdomain_id_type > &ids, const bool global=true) const
Constructs a list of all subdomain identifiers in the local mesh if global == false, and in the global mesh if global == true (default).
Definition: mesh_base.C:959
subdomain_id_type n_subdomains() const
Definition: mesh_base.C:997
void build_line(UnstructuredMesh &mesh, const unsigned int nx, const Real xmin=0., const Real xmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 1D meshes.
virtual const Node * node_ptr(const dof_id_type i) const =0
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
uint8_t dof_id_type
Definition: id_types.h:67