libMesh
Loading...
Searching...
No Matches
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/nemesis_io.h"
5#include "libmesh/replicated_mesh.h"
6#include "libmesh/mesh_generation.h"
7#include "libmesh/parallel.h" // set_union
8#include "libmesh/string_to_enum.h"
9#include "libmesh/boundary_info.h"
10
11#include "test_comm.h"
12#include "libmesh_cppunit.h"
13
14
15// Bring in everything from the libMesh namespace
16using namespace libMesh;
17
18class WriteEdgesetData : public CppUnit::TestCase
19{
23public:
25
26#if LIBMESH_DIM > 1
27#ifdef LIBMESH_HAVE_EXODUS_API
29#endif // #ifdef LIBMESH_HAVE_EXODUS_API
30#ifdef LIBMESH_HAVE_NEMESIS_API
31 // CPPUNIT_TEST(testWriteNemesis); // Not yet implemented
32#endif
33#endif
34
36
37 template <typename IOClass>
38 void testWriteImpl(const std::string & filename)
39 {
41
43 5, 5, 5,
44 0., 1.,
45 0., 1.,
46 0., 1.,
47 HEX8);
48
49 // Add named edgesets containing the "front" and "back" edges of
50 // the cube.
52
53 std::vector<BoundaryInfo::BCTuple> bc_tuples =
54 bi.build_side_list();
55
56 for (const auto & t : bc_tuples)
57 {
58 dof_id_type elem_id = std::get<0>(t);
59 boundary_id_type b_id = std::get<2>(t);
60
61 // Side 0 corresponds to the "back" sideset, with edges {0,1,2,3}
62 // Side 5 corresponds to the "front" sideset, with edges {4,5,6,7}
63 // If we are on either of those sides, add all the corresponding edges.
64 if (b_id == 0)
65 for (unsigned short edge=0; edge<4; ++edge)
66 bi.add_edge(elem_id, edge, b_id);
67
68 if (b_id == 5)
69 for (unsigned short edge=8; edge<12; ++edge)
70 bi.add_edge(elem_id, edge, b_id);
71 }
72
73 // Name the edgesets
74 bi.edgeset_name(0) = "back_edgeset";
75 bi.edgeset_name(5) = "front_edgeset";
76
77 // We write the file in the requested format.
78 {
79 IOClass writer(mesh);
80 writer.write(filename);
81 }
82
83 // Make sure that the writing is done before the reading starts.
84 TestCommWorld->barrier();
85
86 // Now read it back in
87 ReplicatedMesh read_mesh(*TestCommWorld);
88 IOClass reader(read_mesh);
89 reader.read(filename);
90
91 // Assert that we got back out what we put in.
92 BoundaryInfo & read_bi = read_mesh.get_boundary_info();
93 CPPUNIT_ASSERT(read_bi.edgeset_name(0) == "back_edgeset");
94 CPPUNIT_ASSERT(read_bi.edgeset_name(5) == "front_edgeset");
95 CPPUNIT_ASSERT(read_bi.n_edge_conds() == 200);
96 CPPUNIT_ASSERT(read_bi.get_edge_boundary_ids().size() == 2);
97
98 // Make sure that we have the expected amount of edges in each edgeset.
99 std::map<boundary_id_type, unsigned int> counts;
100 std::vector<BoundaryInfo::BCTuple> edge_tuples = bi.build_edge_list();
101 for (const auto & t : edge_tuples)
102 counts[std::get<2>(t)]++;
103 CPPUNIT_ASSERT(counts[0] == 100);
104 CPPUNIT_ASSERT(counts[5] == 100);
105 }
106
108 {
109 LOG_UNIT_TEST;
110
111 testWriteImpl<ExodusII_IO>("write_edgeset_data.e");
112 }
113
115 {
116 // LOG_UNIT_TEST;
117
118 // FIXME: Not yet implemented
119 // testWriteImpl<Nemesis_IO>("write_edgeset_data.n");
120 }
121};
122
LIBMESH_CPPUNIT_TEST_SUITE(WriteEdgesetData)
This test ensures you can write both vector and scalar variables.
CPPUNIT_TEST(testWriteExodus)
void testWriteImpl(const std::string &filename)
The BoundaryInfo class contains information relevant to boundary conditions including storing faces,...
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.
std::vector< BCTuple > build_side_list(BCTupleSortBy sort_by=BCTupleSortBy::ELEM_ID) const
std::size_t n_edge_conds() const
const std::set< boundary_id_type > & get_edge_boundary_ids() const
std::string & edgeset_name(boundary_id_type id)
std::vector< BCTuple > build_edge_list() const
Create a list of (element_id, edge_id, boundary_id) tuples for all relevant edges.
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition mesh_base.h:170
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Communicator * TestCommWorld
MeshBase & mesh
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.
The libMesh namespace provides an interface to certain functionality in the library.
int8_t boundary_id_type
Definition id_types.h:51
uint8_t dof_id_type
Definition id_types.h:67
CPPUNIT_TEST_SUITE_REGISTRATION(WriteEdgesetData)