libMesh
Loading...
Searching...
No Matches
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
10using namespace libMesh;
11
12class MeshSubdomainIDTest : public CppUnit::TestCase
13{
18public:
20
23
25
26public:
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
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
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
CPPUNIT_TEST(testMultiple)
CPPUNIT_TEST(testUnpartitioned)
LIBMESH_CPPUNIT_TEST_SUITE(MeshSubdomainIDTest)
The goal of this test is to verify proper operation of the MeshBase::subdomain_ids() method.
This is the base class from which all geometric element types are derived.
Definition elem.h:96
virtual Node *& set_node(const unsigned int i)
Definition elem.h:2567
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition elem.C:442
static constexpr subdomain_id_type invalid_subdomain_id
A static integral constant representing an invalid subdomain id.
Definition elem.h:246
virtual const Node * node_ptr(const dof_id_type i) const =0
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,...
Definition mesh_base.C:1126
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.
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
subdomain_id_type n_subdomains() const
Definition mesh_base.C:1190
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
Communicator * TestCommWorld
MeshBase & mesh
CPPUNIT_TEST_SUITE_REGISTRATION(MeshSubdomainIDTest)
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.
The libMesh namespace provides an interface to certain functionality in the library.
TestClass subdomain_id_type
Based on the 4-byte comment warning above, this probably doesn't work with exodusII at all....
Definition id_types.h:43
uint8_t dof_id_type
Definition id_types.h:67