1- #include "../geom/elem_test .h"
1+ #include "mesh_elem_test .h"
22
33#ifdef LIBMESH_HAVE_EXODUS_API
44
1010using namespace libMesh ;
1111
1212template < ElemType elem_type >
13- class ExodusTest : public PerElemTest < elem_type > {
14-
15- private :
16-
17- bool meshes_equal_enough (Mesh & other_mesh )
18- {
19- // We'll need to fix up processor_id() and unique_id() values
20- // before we can operator== these meshes. But worse: our gold
21- // meshes might have been numbered differently to our generated
22- // meshes. Some of our generated mesh options practically
23- // *require* renumbering (e.g. after interior HEX20 nodes are
24- // deleted, ExodusII still wants to see a contiguous numbering),
25- // but ReplicatedMesh and DistributedMesh renumber differently.
26- //
27- // So, let's renumber too.
28-
29- MeshSerializer serialthis (* this -> _mesh );
30- MeshSerializer serialother (other_mesh );
31-
32- const dof_id_type max_elem_id = this -> _mesh -> max_elem_id ();
33- const dof_id_type max_node_id = this -> _mesh -> max_node_id ();
34-
35- CPPUNIT_ASSERT_EQUAL (max_elem_id , other_mesh .max_elem_id ());
36- CPPUNIT_ASSERT_EQUAL (max_node_id , other_mesh .max_node_id ());
37-
38- auto locator = other_mesh .sub_point_locator ();
39-
40- for (Elem * e1 : this -> _mesh -> element_ptr_range ())
41- {
42- const Elem * e2c = (* locator )(e1 -> vertex_average ());
43- CPPUNIT_ASSERT (e2c );
44- Elem & e2 = other_mesh .elem_ref (e2c -> id ());
45- e1 -> processor_id () = 0 ;
46- e2 .processor_id () = 0 ;
47-
48- const dof_id_type e1_id = e1 -> id ();
49- const dof_id_type e2_id = e2 .id ();
50- // Do a swap if necessary, using a free temporary id
51- if (e1_id != e2_id )
52- {
53- other_mesh .renumber_elem (e1_id , max_elem_id );
54- other_mesh .renumber_elem (e2_id , e1_id );
55- other_mesh .renumber_elem (max_elem_id , e2_id );
56- }
57-
58- #ifdef LIBMESH_ENABLE_UNIQUE_ID
59- e2 .set_unique_id (e1 -> unique_id ());
60- #endif
61- }
62-
63- for (Node * n1 : this -> _mesh -> node_ptr_range ())
64- {
65- const Elem * e1c = (* locator )(* n1 );
66- Node * n2 = nullptr ;
67- for (const Node & n : e1c -> node_ref_range ())
68- {
69- #ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
70- const Point diff = Point (* n1 )- Point (n );
71-
72- // We're testing against ExodusII input, and if we're in
73- // triple or quadruple precision that means our lovely
74- // higher-precision node coordinates got truncated to double
75- // to be written. We need to adjust ours or they won't
76- // satisfy operator== later.
77-
78- // We're *also* testing against gold files that were
79- // calculated at double precision, so just casting a higher
80- // precision calculation to double won't give the exact same
81- // result, we have to account for error.
82- if (diff .norm () < 1e-15 )
83- for (auto d : make_range (LIBMESH_DIM ))
84- (* n1 )(d ) = double (n (d ));
85- #endif
86- if (Point (* n1 ) == Point (n ))
87- n2 = other_mesh .node_ptr (n .id ());
88- }
89- CPPUNIT_ASSERT (n2 );
90- n1 -> processor_id () = 0 ;
91- n2 -> processor_id () = 0 ;
92-
93- const dof_id_type n1_id = n1 -> id ();
94- const dof_id_type n2_id = n2 -> id ();
95- // Do a swap if necessary, using a free temporary id
96- if (n1_id != n2_id )
97- {
98- other_mesh .renumber_node (n1_id ,max_node_id );
99- other_mesh .renumber_node (n2_id ,n1_id );
100- other_mesh .renumber_node (max_node_id , n2_id );
101- }
102-
103- #ifdef LIBMESH_ENABLE_UNIQUE_ID
104- n2 -> set_unique_id (n1 -> unique_id ());
105- #endif
106- }
107-
108- #ifdef LIBMESH_ENABLE_UNIQUE_ID
109- other_mesh .set_next_unique_id (this -> _mesh -> parallel_max_unique_id ());
110- this -> _mesh -> set_next_unique_id (this -> _mesh -> parallel_max_unique_id ());
111- #endif
112-
113- return * this -> _mesh == other_mesh ;
114- }
115-
13+ class ExodusTest : public MeshPerElemTest < elem_type >
14+ {
11615public :
11716
11817 void test_read_gold ()
@@ -129,7 +28,7 @@ public:
12928 MeshCommunication ().broadcast (input_mesh );
13029 input_mesh .prepare_for_use ();
13130
132- CPPUNIT_ASSERT (this -> meshes_equal_enough (input_mesh ));
31+ CPPUNIT_ASSERT (this -> meshes_equal_enough (input_mesh , true ));
13332 }
13433
13534 void test_write ()
@@ -161,7 +60,7 @@ public:
16160 MeshCommunication ().broadcast (input_mesh );
16261 input_mesh .prepare_for_use ();
16362
164- CPPUNIT_ASSERT (this -> meshes_equal_enough (input_mesh ));
63+ CPPUNIT_ASSERT (this -> meshes_equal_enough (input_mesh , true ));
16564 }
16665};
16766
0 commit comments