MOAB: Mesh Oriented datABase  (version 5.4.1)
test_determinism.cpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
00016 #ifdef WIN32
00017 #ifdef _DEBUG
00018 // turn off warnings that say they debugging identifier has been truncated
00019 // this warning comes up when using some STL containers
00020 #pragma warning( disable : 4786 )
00021 #endif
00022 #endif
00023 
00024 #include <iostream>
00025 #include "moab/Core.hpp"
00026 #include "TestUtil.hpp"
00027 
00028 #ifndef IS_BUILDING_MB
00029 #define IS_BUILDING_MB
00030 #endif
00031 
00032 #include "Internals.hpp"
00033 #include "TestUtil.hpp"
00034 
00035 using namespace moab;
00036 
00037 int main()
00038 {
00039     Interface* iface0 = new Core;
00040     Interface* iface1 = new Core;
00041 
00042     std::string filename = TestDir + "unittest/tet_brick.vtk";
00043 
00044     ErrorCode err;
00045     err = iface0->load_file( filename.c_str() );CHECK_ERR( err );
00046     err = iface1->load_file( filename.c_str() );CHECK_ERR( err );
00047 
00048     Range tets0, verts0, edges0, edges1, tris0, tris1;
00049     err = iface0->get_entities_by_dimension( 0, 3, tets0 );CHECK_ERR( err );
00050     err = iface0->get_adjacencies( tets0, 1, true, edges0, Interface::UNION );CHECK_ERR( err );
00051     err = iface1->get_adjacencies( tets0, 1, true, edges1, Interface::UNION );CHECK_ERR( err );
00052     CHECK_EQUAL( edges0, edges1 );
00053     err = iface0->get_adjacencies( tets0, 2, true, tris0, Interface::UNION );CHECK_ERR( err );
00054     err = iface1->get_adjacencies( tets0, 2, true, tris1, Interface::UNION );CHECK_ERR( err );
00055     CHECK_EQUAL( tris0, tris1 );
00056 
00057     std::vector< EntityHandle > conn_squence;
00058 
00059     // At that point iface0 and iface1 should have the same entity handler
00060     // associated with entities, so we can use one or another, no difference.
00061 
00062     int repeat = 0;
00063     for( ; repeat != 3; repeat++ )
00064     {
00065 
00066         std::vector< EntityHandle > conn_seq;
00067 
00068         Range to_delete;
00069         // Build range of quad to delete form iface0
00070         int ii = 0;
00071         for( Range::iterator qit = tets0.begin(); qit != tets0.end(); qit++, ii++ )
00072         {
00073             if( ii % 3 )
00074             {
00075                 to_delete.insert( *qit );
00076                 const EntityHandle* conn;
00077                 int number_nodes = 0;
00078                 iface0->get_connectivity( *qit, conn, number_nodes );
00079                 conn_seq.insert( conn_seq.end(), conn, &conn[number_nodes] );
00080             }
00081         }
00082         // Buidl tange of edges to delete from iface1
00083         // Create gaps in sequence, to be filled later on.
00084         for( Range::iterator eit = edges1.begin(); eit != edges1.end(); eit++, ii++ )
00085         {
00086             if( ii % 3 )
00087             {
00088                 to_delete.insert( *eit );
00089             }
00090         }
00091         for( Range::iterator eit = tris1.begin(); eit != tris1.end(); eit++, ii++ )
00092         {
00093             if( ii % 3 )
00094             {
00095                 to_delete.insert( *eit );
00096             }
00097         }
00098 
00099         err = iface0->delete_entities( to_delete );
00100         err = iface1->delete_entities( to_delete );
00101 
00102         for( unsigned qq = 0; qq != conn_seq.size() / 4; qq++ )
00103         {
00104             EntityHandle q0, q1;
00105             err = iface1->create_element( MBTET, &conn_seq[4 * qq], 4, q1 );CHECK_ERR( err );
00106             err = iface0->create_element( MBTET, &conn_seq[4 * qq], 4, q0 );CHECK_ERR( err );
00107             CHECK( q0 == q1 );
00108         }
00109 
00110         tets0.clear();
00111         err = iface0->get_entities_by_dimension( 0, 3, tets0 );CHECK_ERR( err );
00112         Range tets1;
00113         err = iface1->get_entities_by_dimension( 0, 3, tets1 );CHECK_ERR( err );
00114         CHECK_EQUAL( tets0, tets1 );
00115 
00116         // Finally check adjacency, this finally check if code is deterministic
00117         for( Range::iterator tit = tets1.begin(); tit != tets1.end(); tit++ )
00118         {
00119             std::vector< EntityHandle > adj0, adj1;
00120             err = iface0->get_adjacencies( &*tit, 1, 1, true, adj0 );CHECK_ERR( err );
00121             err = iface1->get_adjacencies( &*tit, 1, 1, true, adj1 );CHECK_ERR( err );
00122             CHECK_EQUAL( adj0, adj1 );
00123         }
00124         for( Range::iterator tit = tets1.begin(); tit != tets1.end(); tit++ )
00125         {
00126             std::vector< EntityHandle > adj0, adj1;
00127             err = iface0->get_adjacencies( &*tit, 1, 2, true, adj0 );CHECK_ERR( err );
00128             err = iface1->get_adjacencies( &*tit, 1, 2, true, adj1 );CHECK_ERR( err );
00129             CHECK_EQUAL( adj0, adj1 );
00130         }
00131     }
00132 
00133     delete iface0;
00134     delete iface1;
00135 
00136     return 0;
00137 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines