libMesh
write_edgeset_data.C
Go to the documentation of this file.
1 // Basic include files
2 #include "libmesh/equation_systems.h"
3 #include "libmesh/exodusII_io.h"
4 #include "libmesh/replicated_mesh.h"
5 #include "libmesh/mesh_generation.h"
6 #include "libmesh/parallel.h" // set_union
7 #include "libmesh/string_to_enum.h"
8 #include "libmesh/boundary_info.h"
9 
10 #include "test_comm.h"
11 #include "libmesh_cppunit.h"
12 
13 
14 // Bring in everything from the libMesh namespace
15 using namespace libMesh;
16 
17 class WriteEdgesetData : public CppUnit::TestCase
18 {
22 public:
23  CPPUNIT_TEST_SUITE(WriteEdgesetData);
24 
25 #if LIBMESH_DIM > 1
26  CPPUNIT_TEST(testWrite);
27 #endif
28 
29  CPPUNIT_TEST_SUITE_END();
30 
31  void testWrite()
32  {
34 
36  5, 5, 5,
37  0., 1.,
38  0., 1.,
39  0., 1.,
40  HEX8);
41 
42  // Add named edgesets containing the "front" and "back" edges of
43  // the cube.
45 
46  std::vector<BoundaryInfo::BCTuple> bc_tuples =
47  bi.build_side_list();
48 
49  for (const auto & t : bc_tuples)
50  {
51  dof_id_type elem_id = std::get<0>(t);
52  boundary_id_type b_id = std::get<2>(t);
53 
54  // Side 0 corresponds to the "back" sideset, with edges {0,1,2,3}
55  // Side 5 corresponds to the "front" sideset, with edges {4,5,6,7}
56  // If we are on either of those sides, add all the corresponding edges.
57  if (b_id == 0)
58  for (unsigned short edge=0; edge<4; ++edge)
59  bi.add_edge(elem_id, edge, b_id);
60 
61  if (b_id == 5)
62  for (unsigned short edge=8; edge<12; ++edge)
63  bi.add_edge(elem_id, edge, b_id);
64  }
65 
66  // Name the edgesets
67  bi.edgeset_name(0) = "back_edgeset";
68  bi.edgeset_name(5) = "front_edgeset";
69 
70 #ifdef LIBMESH_HAVE_EXODUS_API
71 
72  // We write the file in the ExodusII format.
73  {
74  ExodusII_IO writer(mesh);
75  writer.write("write_edgeset_data.e");
76  }
77 
78  // Make sure that the writing is done before the reading starts.
79  TestCommWorld->barrier();
80 
81  // Now read it back in
82  ReplicatedMesh read_mesh(*TestCommWorld);
83  ExodusII_IO reader(read_mesh);
84  reader.read("write_edgeset_data.e");
85 
86  // Assert that we got back out what we put in.
87  BoundaryInfo & read_bi = read_mesh.get_boundary_info();
88  CPPUNIT_ASSERT(read_bi.edgeset_name(0) == "back_edgeset");
89  CPPUNIT_ASSERT(read_bi.edgeset_name(5) == "front_edgeset");
90  CPPUNIT_ASSERT(read_bi.n_edge_conds() == 200);
91  CPPUNIT_ASSERT(read_bi.get_edge_boundary_ids().size() == 2);
92 
93  // Make sure that we have the expected amount of edges in each edgeset.
94  std::map<boundary_id_type, unsigned int> counts;
95  std::vector<BoundaryInfo::BCTuple> edge_tuples = bi.build_edge_list();
96  for (const auto & t : edge_tuples)
97  counts[std::get<2>(t)]++;
98  CPPUNIT_ASSERT(counts[0] == 100);
99  CPPUNIT_ASSERT(counts[5] == 100);
100 
101 #endif // #ifdef LIBMESH_HAVE_EXODUS_API
102  }
103 };
104 
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::BoundaryInfo
The BoundaryInfo class contains information relevant to boundary conditions including storing faces,...
Definition: boundary_info.h:57
libMesh::MeshBase::get_boundary_info
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition: mesh_base.h:132
libMesh::HEX8
Definition: enum_elem_type.h:47
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::MeshTools::Generation::build_cube
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
Definition: mesh_generation.C:298
libMesh::BoundaryInfo::n_edge_conds
std::size_t n_edge_conds() const
Definition: boundary_info.C:1636
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::ExodusII_IO
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:51
libMesh::boundary_id_type
int8_t boundary_id_type
Definition: id_types.h:51
libMesh::BoundaryInfo::edgeset_name
std::string & edgeset_name(boundary_id_type id)
Definition: boundary_info.C:2374
libMesh::BoundaryInfo::build_side_list
void build_side_list(std::vector< dof_id_type > &element_id_list, std::vector< unsigned short int > &side_list, std::vector< boundary_id_type > &bc_id_list) const
Creates a list of element numbers, sides, and ids for those sides.
Definition: boundary_info.C:1976
libMesh::ReplicatedMesh
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Definition: replicated_mesh.h:47
CPPUNIT_TEST_SUITE_REGISTRATION
CPPUNIT_TEST_SUITE_REGISTRATION(WriteEdgesetData)
libMesh::BoundaryInfo::build_edge_list
void build_edge_list(std::vector< dof_id_type > &element_id_list, std::vector< unsigned short int > &edge_list, std::vector< boundary_id_type > &bc_id_list) const
Creates a list of element numbers, edges, and boundary ids for those edges.
Definition: boundary_info.C:2091
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
WriteEdgesetData
Definition: write_edgeset_data.C:17
libmesh_cppunit.h
libMesh::BoundaryInfo::add_edge
void add_edge(const dof_id_type elem, const unsigned short int edge, const boundary_id_type id)
Add edge edge of element number elem with boundary id id to the boundary information data structure.
Definition: boundary_info.C:707
libMesh::BoundaryInfo::get_edge_boundary_ids
const std::set< boundary_id_type > & get_edge_boundary_ids() const
Definition: boundary_info.h:803
libMesh::ExodusII_IO::write
virtual void write(const std::string &fname) override
This method implements writing a mesh to a specified file.
Definition: exodusII_io.C:1338
test_comm.h
libMesh::ExodusII_IO::read
virtual void read(const std::string &name) override
This method implements reading a mesh from a specified file.
Definition: exodusII_io.C:143
WriteEdgesetData::testWrite
void testWrite()
Definition: write_edgeset_data.C:31