libMesh
exodus_test.C
Go to the documentation of this file.
1 #include "mesh_elem_test.h"
2 
3 #ifdef LIBMESH_HAVE_EXODUS_API
4 
5 #include "libmesh/enum_to_string.h"
6 #include "libmesh/exodusII_io.h"
7 #include "libmesh/mesh_communication.h"
8 #include "libmesh/mesh_serializer.h"
9 
10 using namespace libMesh;
11 
12 template <ElemType elem_type>
13 class ExodusTest : public MeshPerElemTest<elem_type>
14 {
15 public:
16 
18  {
19  LOG_UNIT_TEST;
20 
21  Mesh input_mesh(*TestCommWorld);
22 
23  ExodusII_IO exii(input_mesh);
24  if (input_mesh.processor_id() == 0)
25  exii.read("meshes/exodus_elements/read_exodus_" +
26  Utility::enum_to_string(elem_type) + ".e");
27 
28  MeshCommunication().broadcast(input_mesh);
29  input_mesh.prepare_for_use();
30 
31  CPPUNIT_ASSERT(this->meshes_equal_enough(input_mesh, true));
32  }
33 
34  void test_write()
35  {
36  LOG_UNIT_TEST;
37 
38  // This is a *buffered* write; we use scope to make sure the
39  // ExodusII_IO 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  ExodusII_IO exii(*this->_mesh);
44 
45  // We still default to 32-char names for backwards
46  // compatibility, but we're writing a mesh with extra-long names
47  // in it for testing, so we manually enable longer names.
48  exii.set_max_name_length(80);
49 
50  exii.write("write_exodus_" +
51  Utility::enum_to_string(elem_type) + ".e");
52  }
53 
54  Mesh input_mesh(*TestCommWorld);
55  ExodusII_IO exii_input(input_mesh);
56  if (input_mesh.processor_id() == 0)
57  exii_input.read("write_exodus_" +
58  Utility::enum_to_string(elem_type) + ".e");
59 
60  MeshCommunication().broadcast(input_mesh);
61  input_mesh.prepare_for_use();
62 
63  CPPUNIT_ASSERT(this->meshes_equal_enough(input_mesh, true));
64  }
65 };
66 
67 #define EXODUSTEST \
68  CPPUNIT_TEST( test_read_gold ); \
69  CPPUNIT_TEST( test_write );
70 
71 #define INSTANTIATE_EXODUSTEST(elemtype) \
72  class ExodusTest_##elemtype : public ExodusTest<elemtype> { \
73  public: \
74  ExodusTest_##elemtype() : \
75  ExodusTest<elemtype>() { \
76  if (unitlog->summarized_logs_enabled()) \
77  this->libmesh_suite_name = "ExodusTest"; \
78  else \
79  this->libmesh_suite_name = "ExodusTest_" #elemtype; \
80  } \
81  CPPUNIT_TEST_SUITE( ExodusTest_##elemtype ); \
82  EXODUSTEST; \
83  CPPUNIT_TEST_SUITE_END(); \
84  }; \
85  \
86  CPPUNIT_TEST_SUITE_REGISTRATION( ExodusTest_##elemtype )
87 
91 
92 #if LIBMESH_DIM > 1
97 
104 #endif // LIBMESH_DIM > 1
105 
106 #if LIBMESH_DIM > 2
110 
114 
120 
121 // These tests use PointLocator, which uses contains_point(), which
122 // uses inverse_map(), which doesn't play nicely on Pyramids unless we
123 // have exceptions support
124 #ifdef LIBMESH_ENABLE_EXCEPTIONS
129 #endif
130 #endif // LIBMESH_DIM > 2
131 
132 #endif // LIBMESH_HAVE_EXODUS_API
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:218
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:50
void set_max_name_length(unsigned int max_length)
For backwards compatibility, libMesh currently truncates names in ExodusII output to the old default ...
Definition: exodusII_io.C:2430
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.
This is the MeshCommunication class.
void test_read_gold()
Definition: exodus_test.C:17
virtual void read(const std::string &name) override
This method implements reading a mesh from a specified file.
Definition: exodusII_io.C:246
std::string enum_to_string(const T e)
virtual void write(const std::string &fname) override
This method implements writing a mesh to a specified file.
Definition: exodusII_io.C:2197
void broadcast(MeshBase &) const
Finds all the processors that may contain elements that neighbor my elements.
INSTANTIATE_EXODUSTEST(EDGE2)
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
processor_id_type processor_id() const
void test_write()
Definition: exodus_test.C:34