2 #include "libmesh/equation_systems.h" 3 #include "libmesh/exodusII_io.h" 4 #include "libmesh/nemesis_io.h" 5 #include "libmesh/mesh.h" 6 #include "libmesh/mesh_generation.h" 7 #include "libmesh/parallel.h" 8 #include "libmesh/replicated_mesh.h" 9 #include "libmesh/string_to_enum.h" 10 #include "libmesh/boundary_info.h" 11 #include "libmesh/utility.h" 12 #include "libmesh/elem.h" 27 #ifdef LIBMESH_HAVE_EXODUS_API 28 CPPUNIT_TEST(testWriteExodus);
29 #endif // #ifdef LIBMESH_HAVE_EXODUS_API 30 #ifdef LIBMESH_HAVE_NEMESIS_API 35 CPPUNIT_TEST_SUITE_END();
38 const Point & centroid,
39 unsigned int elemset_index,
42 const Elem * elem = pl(centroid);
49 CPPUNIT_ASSERT_EQUAL(expected_elemset_code, elem->
get_extra_integer(elemset_index));
83 pl->enable_out_of_mesh_mode();
86 checkByCentroid(*pl,
Point(0.4, -0.4, 0), elemset_index, 0);
87 checkByCentroid(*pl,
Point(0.8, 0, 0), elemset_index, 0);
88 checkByCentroid(*pl,
Point(0.4, -0.8, 0), elemset_index, 1);
89 checkByCentroid(*pl,
Point(0.8, 0.8, 0), elemset_index, 1);
90 checkByCentroid(*pl,
Point(0.8, -0.4, 0), elemset_index, 2);
91 checkByCentroid(*pl,
Point(-0.8, 0.4, 0), elemset_index, 2);
94 template <
typename IOClass>
113 unsigned int elemset_index =
128 std::set<dof_id_type> set1 = {3, 8, 14, 24};
129 std::set<dof_id_type> set2 = {3, 9, 15, 24};
132 for (
const auto & elem :
mesh.element_ptr_range())
135 in1 = set1.count(elem->id()),
136 in2 = set2.count(elem->id());
146 elem->set_extra_integer(elemset_index, val);
165 std::vector<std::string> var_names = {
"var1",
"var2",
"var3"};
166 std::vector<std::set<elemset_id_type>> elemset_ids =
172 std::vector<std::map<std::pair<dof_id_type, elemset_id_type>,
Real>> elemset_vals(var_names.size());
175 std::set<elemset_id_type> id_set_to_fill;
177 for (
const auto & elem :
mesh.element_ptr_range())
183 in1 = id_set_to_fill.count(1),
184 in2 = id_set_to_fill.count(2);
188 elemset_vals[0].emplace( std::make_pair(elem->id(), 1), 1.0);
192 elemset_vals[1].emplace( std::make_pair(elem->id(), 2), 2.0);
196 for (
const auto &
id : id_set_to_fill)
197 elemset_vals[2].emplace( std::make_pair(elem->id(), id), 3.0);
201 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(8), elemset_vals[2].size());
225 IOClass writer(
mesh);
226 writer.write(filename);
227 writer.write_elemset_data(1, var_names, elemset_ids, elemset_vals);
237 read_mesh.allow_renumbering(
false);
239 IOClass reader(read_mesh);
241 reader.read(filename);
245 read_mesh.prepare_for_use();
248 checkElemsetCodes(read_mesh);
253 std::vector<std::string> read_in_var_names;
254 std::vector<std::set<elemset_id_type>> read_in_elemset_ids;
255 std::vector<std::map<std::pair<dof_id_type, elemset_id_type>,
Real>> read_in_elemset_vals;
256 reader.read_elemset_data(1, read_in_var_names, read_in_elemset_ids, read_in_elemset_vals);
262 CPPUNIT_ASSERT(read_in_var_names == var_names);
263 CPPUNIT_ASSERT(read_in_elemset_ids == elemset_ids);
264 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(8), read_in_elemset_vals[2].size());
265 CPPUNIT_ASSERT(read_in_elemset_vals == elemset_vals);
268 std::map<std::pair<dof_id_type, elemset_id_type>,
unsigned int> elemset_array_indices;
269 reader.get_elemset_data_indices(elemset_array_indices);
273 std::vector<dof_id_type> elem_els1 = {4, 9, 15, 25};
274 std::vector<dof_id_type> elem_els2 = {4, 10, 16, 25};
277 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(i),
278 elemset_array_indices[std::make_pair(elem_els1[i] - 1,
281 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(i),
282 elemset_array_indices[std::make_pair(elem_els2[i] - 1,
285 #ifdef LIBMESH_HAVE_XDR 295 read_mesh.write(
"write_elemset_data.xda");
305 read_mesh2.
read(
"write_elemset_data.xda");
306 checkElemsetCodes(read_mesh2);
308 #endif // LIBMESH_HAVE_XDR 315 testWriteImpl<ExodusII_IO>(
"write_elemset_data.e");
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
std::unique_ptr< PointLocatorBase > sub_point_locator() const
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
CPPUNIT_TEST_SUITE_REGISTRATION(WriteElemsetData)
void checkElemsetCodes(const MeshBase &mesh)
void checkByCentroid(const PointLocatorBase &pl, const Point ¢roid, unsigned int elemset_index, dof_id_type expected_elemset_code)
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...
void add_elemset_code(dof_id_type code, MeshBase::elemset_type id_set)
Tabulate a user-defined "code" for elements which belong to the element sets specified in id_set...
bool has_elem_integer(std::string_view name) const
This is the base class from which all geometric element types are derived.
The libMesh namespace provides an interface to certain functionality in the library.
dof_id_type get_elemset_code(const MeshBase::elemset_type &id_set) const
This is the MeshBase class.
void get_elemsets(dof_id_type elemset_code, MeshBase::elemset_type &id_set_to_fill) const
Look up the element sets for a given elemset code and vice-versa.
void testWriteImpl(const std::string &filename)
unsigned int get_elem_integer_index(std::string_view name) const
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
This is the base class for point locators.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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.
A Point defines a location in LIBMESH_DIM dimensional Real space.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
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...