libMesh
xdrio_test.C
Go to the documentation of this file.
1 #include "mesh_elem_test.h"
2 
3 #include "libmesh/enum_to_string.h"
4 #include "libmesh/mesh_communication.h"
5 #include "libmesh/xdr_io.h"
6 
7 using namespace libMesh;
8 
9 template <ElemType elem_type>
10 class XdrIOTest : public MeshPerElemTest<elem_type> {
11 
12 public:
13 
14  void test_read_gold(bool binary)
15  {
16  LOG_UNIT_TEST;
17 
18  Mesh input_mesh(*TestCommWorld);
19 
20  XdrIO xdr_io(input_mesh);
21  xdr_io.binary() = binary;
22  xdr_io.read("meshes/xdrio_elements/read_xdrio_" +
23  Utility::enum_to_string(elem_type) +
24  (binary ? ".xdr" : ".xda"));
25 
26  input_mesh.prepare_for_use();
27 
28  CPPUNIT_ASSERT(this->meshes_equal_enough(input_mesh, false));
29  }
30 
31  void test_read_gold_xda() { this->test_read_gold(false); }
32  void test_read_gold_xdr() { this->test_read_gold(true); }
33 
34  void test_write(bool binary)
35  {
36  LOG_UNIT_TEST;
37 
38  // This is a *buffered* write; we use scope to make sure the
39  // XdrIO object gets destructed (and thus is guaranteed to
40  // finish writing and close the file) before we try to read what
41  // was written.
42  {
43  XdrIO xdr_io(*this->_mesh);
44  xdr_io.binary() = binary;
45  xdr_io.write("write_xdrio_" +
46  Utility::enum_to_string(elem_type) +
47  (binary ? ".xdr" : ".xda"));
48  }
49 
50  Mesh input_mesh(*TestCommWorld);
51  XdrIO xdr_io_input(input_mesh);
52  xdr_io_input.binary() = binary;
53  xdr_io_input.read("write_xdrio_" +
54  Utility::enum_to_string(elem_type) +
55  (binary ? ".xdr" : ".xda"));
56 
57  MeshCommunication().broadcast(input_mesh);
58  input_mesh.prepare_for_use();
59 
60  CPPUNIT_ASSERT(this->meshes_equal_enough(input_mesh, false));
61  }
62 
63  void test_write_xda() { this->test_write(false); }
64  void test_write_xdr() { this->test_write(true); }
65 
66 };
67 
68 #if LIBMESH_HAVE_XDR
69 #define XDRIOTEST \
70  CPPUNIT_TEST( test_read_gold_xda ); \
71  CPPUNIT_TEST( test_read_gold_xdr ); \
72  CPPUNIT_TEST( test_write_xda ); \
73  CPPUNIT_TEST( test_write_xdr );
74 #else
75 #define XDRIOTEST \
76  CPPUNIT_TEST( test_read_gold_xda ); \
77  CPPUNIT_TEST( test_write_xda );
78 #endif
79 
80 #define INSTANTIATE_XDRIOTEST(elemtype) \
81  class XdrIOTest_##elemtype : public XdrIOTest<elemtype> { \
82  public: \
83  XdrIOTest_##elemtype() : \
84  XdrIOTest<elemtype>() { \
85  if (unitlog->summarized_logs_enabled()) \
86  this->libmesh_suite_name = "XdrIOTest"; \
87  else \
88  this->libmesh_suite_name = "XdrIOTest_" #elemtype; \
89  } \
90  CPPUNIT_TEST_SUITE( XdrIOTest_##elemtype ); \
91  XDRIOTEST; \
92  CPPUNIT_TEST_SUITE_END(); \
93  }; \
94  \
95  CPPUNIT_TEST_SUITE_REGISTRATION( XdrIOTest_##elemtype )
96 
100 
101 #if LIBMESH_DIM > 1
106 
113 #endif // LIBMESH_DIM > 1
114 
115 #if LIBMESH_DIM > 2
119 
123 
129 
130 // These tests use PointLocator, which uses contains_point(), which
131 // uses inverse_map(), which doesn't play nicely on Pyramids unless we
132 // have exceptions support
133 #ifdef LIBMESH_ENABLE_EXCEPTIONS
138 #endif
139 #endif // LIBMESH_DIM > 2
void test_write_xdr()
Definition: xdrio_test.C:64
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:218
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly created (or read) mesh for use.
Definition: mesh_base.C:824
The libMesh namespace provides an interface to certain functionality in the library.
void test_write_xda()
Definition: xdrio_test.C:63
MeshIO class used for writing XDR (eXternal Data Representation) and XDA mesh files.
Definition: xdr_io.h:51
INSTANTIATE_XDRIOTEST(EDGE2)
This is the MeshCommunication class.
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file.
Definition: xdr_io.C:127
void test_write(bool binary)
Definition: xdrio_test.C:34
std::string enum_to_string(const T e)
void test_read_gold_xdr()
Definition: xdrio_test.C:32
void broadcast(MeshBase &) const
Finds all the processors that may contain elements that neighbor my elements.
bool binary() const
Get/Set the flag indicating if we should read/write binary.
Definition: xdr_io.h:103
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
void test_read_gold(bool binary)
Definition: xdrio_test.C:14
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file.
Definition: xdr_io.C:1436
void test_read_gold_xda()
Definition: xdrio_test.C:31