1 #include <libmesh/libmesh.h> 2 #include <libmesh/mesh.h> 3 #include <libmesh/elem.h> 4 #include <libmesh/mesh_generation.h> 5 #include <libmesh/mesh_refinement.h> 7 #include <libmesh/exodusII_io.h> 27 CPPUNIT_TEST( testExtraIntegersEdge2 );
28 CPPUNIT_TEST( testExtraIntegersTri6 );
30 #ifdef LIBMESH_HAVE_EXODUS_API 31 CPPUNIT_TEST( testExtraIntegersExodusReading );
33 #if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_ENABLE_EXCEPTIONS) 34 CPPUNIT_TEST( testBadExtraIntegersExodusReading );
37 #ifdef LIBMESH_HAVE_XDR 38 CPPUNIT_TEST( testExtraIntegersCheckpointEdge3 );
39 CPPUNIT_TEST( testExtraIntegersCheckpointHex8 );
42 CPPUNIT_TEST_SUITE_END();
46 std::array<unsigned int, 6>
57 const std::unique_ptr<Elem> test_elem =
Elem::build(elem_type);
58 const unsigned int ymax = test_elem->dim() > 1;
59 const unsigned int zmax = test_elem->dim() > 2;
60 const unsigned int ny = ymax * n_elem_per_side;
61 const unsigned int nz = zmax * n_elem_per_side;
71 return {{i1, r1, ni1, ni2, nr1, nr2}};
75 void test_and_set_initial_data
78 const unsigned int i1 = ini[0],
83 for (
const auto & elem :
mesh.element_ptr_range())
85 const unsigned int expected_extra_ints =
87 CPPUNIT_ASSERT_EQUAL(elem->n_extra_integers(), expected_extra_ints);
89 elem->set_extra_integer(i1,
dof_id_type(std::round(elem->point(0)(0)*100)));
90 CPPUNIT_ASSERT_EQUAL(elem->get_extra_integer(i1),
92 elem->set_extra_datum<
Real>(r1, elem->point(0)(0)*1000);
93 CPPUNIT_ASSERT_EQUAL(elem->get_extra_datum<
Real>(r1), elem->point(0)(0)*1000);
96 for (
const auto & node :
mesh.node_ptr_range())
98 const unsigned int expected_extra_ints =
100 CPPUNIT_ASSERT_EQUAL(node->n_extra_integers(), expected_extra_ints);
103 node->set_extra_datum<
Real>(nr1, (*node)(0)*1000);
104 CPPUNIT_ASSERT_EQUAL(node->get_extra_datum<
Real>(nr1), (*node)(0)*1000);
114 for (
const auto & elem :
mesh.element_ptr_range())
116 const Elem * top_parent = elem;
117 #ifdef LIBMESH_ENABLE_AMR 122 for (
auto & node : elem->node_ref_range())
124 const unsigned int expected_extra_ints =
126 CPPUNIT_ASSERT_EQUAL(node.n_extra_integers(), expected_extra_ints);
129 const unsigned int expected_extra_ints =
131 CPPUNIT_ASSERT_EQUAL(elem->n_extra_integers(), expected_extra_ints);
132 CPPUNIT_ASSERT_EQUAL(elem->get_extra_integer(i1),
142 std::array<unsigned int, 6> ini = build_mesh(
mesh, elem_type, n_elem_per_side);
143 const unsigned int i1 = ini[0],
147 test_and_set_initial_data(
mesh, ini);
159 test_final_integers(
mesh, i1);
164 test_final_integers(
mesh, i1);
168 test_final_integers(
mesh, i1);
171 #ifdef LIBMESH_ENABLE_AMR 175 test_final_integers(
mesh, i1);
182 #ifdef LIBMESH_HAVE_XDR 183 const std::string xdr_filename =
"test_helper.xdr";
190 mesh2.
read(xdr_filename);
191 test_final_integers(mesh2, i1);
201 std::array<unsigned int, 6> ini = build_mesh(
mesh, elem_type, n_elem_per_side);
202 const unsigned int i1 = ini[0], ni1 = ini[2], ni2 = ini[3];
204 test_and_set_initial_data(
mesh, ini);
206 const std::string filename =
207 std::string(
"extra_integers.cp") + (binary ?
"r" :
"a");
215 mesh2.
read(filename);
223 test_final_integers(mesh2, i1);
225 #ifdef LIBMESH_HAVE_XDR 232 const std::string xdr_filename =
233 std::string(
"extra_integers.xd") + (binary ?
"r" :
"a");
242 mesh3.
read(xdr_filename);
265 test_final_integers(mesh3, i1);
270 for (
const auto & elem : mesh3.element_ptr_range())
272 auto r1_actual = elem->get_extra_datum<
Real>(ini[1]);
273 CPPUNIT_ASSERT_EQUAL(r1_actual, elem->point(0)(0)*1000);
278 for (
const auto & node : mesh3.node_ptr_range())
280 auto nr1_actual = node->get_extra_datum<
Real>(ini[4]);
281 CPPUNIT_ASSERT_EQUAL((*node)(0)*1000, nr1_actual);
290 auto nr2_actual = node->get_extra_integer(ini[5]);
293 #endif // LIBMESH_HAVE_XDR 309 #ifdef LIBMESH_HAVE_EXODUS_API 318 std::vector<std::ptrdiff_t> material_id = {0, -1, 2,
321 const std::string filename =
"meshes/good_32bit_elem_integers.e";
324 exreader.
read(filename);
334 CPPUNIT_ASSERT_EQUAL(
int(elem_num_map.size()), 9);
335 CPPUNIT_ASSERT_EQUAL(
int(node_num_map.size()), 16);
336 for (
int i=0; i != 9; ++i)
337 CPPUNIT_ASSERT_EQUAL(elem_num_map[i], i+1);
338 for (
int i=0; i != 16; ++i)
339 CPPUNIT_ASSERT_EQUAL(node_num_map[i], i+1);
348 if (material_id[i] == -1)
356 #if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_ENABLE_EXCEPTIONS) 370 const std::string filename =
"meshes/bad_64bit_elem_integers.e";
373 CPPUNIT_ASSERT_THROW_MESSAGE(
"Bad elem integer not detected",
374 exreader.
read(filename),
bool has_node_integer(std::string_view name) const
ElemType
Defines an enum for geometric element types.
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use...
libMesh::Parallel::Communicator * TestCommWorld
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
const Elem * top_parent() const
unsigned int add_elem_integer(std::string name, bool allocate_data=true, dof_id_type default_value=DofObject::invalid_id)
Register an integer datum (of type dof_id_type) to be added to each element in the mesh...
bool has_elem_integer(std::string_view name) const
This is the base class from which all geometric element types are derived.
const std::vector< int > & get_node_num_map() const
Identical to the behavior of get_elem_num_map(), but for the node_num_map instead.
The libMesh namespace provides an interface to certain functionality in the library.
virtual void all_first_order()=0
Converts a mesh with higher-order elements into a mesh with linear elements.
virtual void partition(const unsigned int n_parts)
Call the default partitioner (currently metis_partition()).
unsigned int get_elem_integer_index(std::string_view name) const
Implements (adaptive) mesh refinement algorithms for a MeshBase.
void set_extra_integer_vars(const std::vector< std::string > &extra_integer_vars)
Set the elemental variables in the Exodus file to be read into extra element integers.
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
unsigned int add_elem_datum(const std::string &name, bool allocate_data=true, const T *default_value=nullptr)
Register a datum (of type T) to be added to each element in the mesh.
virtual void read(const std::string &name) override
This method implements reading a mesh from a specified file.
unsigned int add_node_datum(const std::string &name, bool allocate_data=true, const T *default_value=nullptr)
Register a datum (of type T) to be added to each node in the mesh.
virtual void write(const std::string &name) const =0
const std::vector< int > & get_elem_num_map() const
Returns a const reference to the elem_num_map, which is a vector that is created when a Mesh is read ...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
void all_second_order(const bool full_ordered=true)
Calls the range-based version of this function with a range consisting of all elements in the mesh...
unsigned int add_node_integer(std::string name, bool allocate_data=true, dof_id_type default_value=DofObject::invalid_id)
Register an integer datum (of type dof_id_type) to be added to each node in the mesh.
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false) override
Reads the file specified by name.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
const Point & point(const unsigned int i) const
dof_id_type get_extra_integer(const unsigned int index) const
Gets the value on this object of the extra integer associated with index, which should have been obta...
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.