MOAB: Mesh Oriented datABase  (version 5.5.0)
test_determinism.cpp
Go to the documentation of this file.
1 /**
2  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3  * storing and accessing finite element mesh data.
4  *
5  * Copyright 2004 Sandia Corporation. Under the terms of Contract
6  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7  * retains certain rights in this software.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  */
15 
16 #ifdef WIN32
17 #ifdef _DEBUG
18 // turn off warnings that say they debugging identifier has been truncated
19 // this warning comes up when using some STL containers
20 #pragma warning( disable : 4786 )
21 #endif
22 #endif
23 
24 #include <iostream>
25 #include "moab/Core.hpp"
26 #include "TestUtil.hpp"
27 
28 #ifndef IS_BUILDING_MB
29 #define IS_BUILDING_MB
30 #endif
31 
32 #include "Internals.hpp"
33 #include "TestUtil.hpp"
34 
35 using namespace moab;
36 
37 int main()
38 {
39  Interface* iface0 = new Core;
40  Interface* iface1 = new Core;
41 
42  std::string filename = TestDir + "unittest/tet_brick.vtk";
43 
44  ErrorCode err;
45  err = iface0->load_file( filename.c_str() );CHECK_ERR( err );
46  err = iface1->load_file( filename.c_str() );CHECK_ERR( err );
47 
48  Range tets0, verts0, edges0, edges1, tris0, tris1;
49  err = iface0->get_entities_by_dimension( 0, 3, tets0 );CHECK_ERR( err );
50  err = iface0->get_adjacencies( tets0, 1, true, edges0, Interface::UNION );CHECK_ERR( err );
51  err = iface1->get_adjacencies( tets0, 1, true, edges1, Interface::UNION );CHECK_ERR( err );
52  CHECK_EQUAL( edges0, edges1 );
53  err = iface0->get_adjacencies( tets0, 2, true, tris0, Interface::UNION );CHECK_ERR( err );
54  err = iface1->get_adjacencies( tets0, 2, true, tris1, Interface::UNION );CHECK_ERR( err );
55  CHECK_EQUAL( tris0, tris1 );
56 
57  std::vector< EntityHandle > conn_squence;
58 
59  // At that point iface0 and iface1 should have the same entity handler
60  // associated with entities, so we can use one or another, no difference.
61 
62  int repeat = 0;
63  for( ; repeat != 3; repeat++ )
64  {
65 
66  std::vector< EntityHandle > conn_seq;
67 
68  Range to_delete;
69  // Build range of quad to delete form iface0
70  int ii = 0;
71  for( Range::iterator qit = tets0.begin(); qit != tets0.end(); qit++, ii++ )
72  {
73  if( ii % 3 )
74  {
75  to_delete.insert( *qit );
76  const EntityHandle* conn;
77  int number_nodes = 0;
78  iface0->get_connectivity( *qit, conn, number_nodes );
79  conn_seq.insert( conn_seq.end(), conn, &conn[number_nodes] );
80  }
81  }
82  // Buidl tange of edges to delete from iface1
83  // Create gaps in sequence, to be filled later on.
84  for( Range::iterator eit = edges1.begin(); eit != edges1.end(); eit++, ii++ )
85  {
86  if( ii % 3 )
87  {
88  to_delete.insert( *eit );
89  }
90  }
91  for( Range::iterator eit = tris1.begin(); eit != tris1.end(); eit++, ii++ )
92  {
93  if( ii % 3 )
94  {
95  to_delete.insert( *eit );
96  }
97  }
98 
99  err = iface0->delete_entities( to_delete );
100  err = iface1->delete_entities( to_delete );
101 
102  for( unsigned qq = 0; qq != conn_seq.size() / 4; qq++ )
103  {
104  EntityHandle q0, q1;
105  err = iface1->create_element( MBTET, &conn_seq[4 * qq], 4, q1 );CHECK_ERR( err );
106  err = iface0->create_element( MBTET, &conn_seq[4 * qq], 4, q0 );CHECK_ERR( err );
107  CHECK( q0 == q1 );
108  }
109 
110  tets0.clear();
111  err = iface0->get_entities_by_dimension( 0, 3, tets0 );CHECK_ERR( err );
112  Range tets1;
113  err = iface1->get_entities_by_dimension( 0, 3, tets1 );CHECK_ERR( err );
114  CHECK_EQUAL( tets0, tets1 );
115 
116  // Finally check adjacency, this finally check if code is deterministic
117  for( Range::iterator tit = tets1.begin(); tit != tets1.end(); tit++ )
118  {
119  std::vector< EntityHandle > adj0, adj1;
120  err = iface0->get_adjacencies( &*tit, 1, 1, true, adj0 );CHECK_ERR( err );
121  err = iface1->get_adjacencies( &*tit, 1, 1, true, adj1 );CHECK_ERR( err );
122  CHECK_EQUAL( adj0, adj1 );
123  }
124  for( Range::iterator tit = tets1.begin(); tit != tets1.end(); tit++ )
125  {
126  std::vector< EntityHandle > adj0, adj1;
127  err = iface0->get_adjacencies( &*tit, 1, 2, true, adj0 );CHECK_ERR( err );
128  err = iface1->get_adjacencies( &*tit, 1, 2, true, adj1 );CHECK_ERR( err );
129  CHECK_EQUAL( adj0, adj1 );
130  }
131  }
132 
133  delete iface0;
134  delete iface1;
135 
136  return 0;
137 }