MOAB: Mesh Oriented datABase  (version 5.2.1)
test_rms.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 #include "TSTT_MB_QueryInterface.h"
00017 #include "moab/_RMBSet.hpp"
00018 
00019 using namespace moab;
00020 
00021 int compare_coords( double* xval, double* yval, double* zval, double* nodex, double* nodey, double* nodez,
00022                     const int num_nodes );
00023 int compare_connect( int* connect1, int* connect2, const int num_comps );
00024 
00025 #include <iostream>
00026 
00027 int main()
00028 {
00029     // very basic test of RMBSet
00030     // The test: instantiate a mesh with 2 tet elements sharing a face;
00031     // represent just the 5 nodes (1-5) and 2 elements (1234 & 3215)
00032     //
00033 
00034     // nodal coordinates: shared tri in x-y plane with edges on x and y
00035     // axes and a node at the origin, plus nodes at z = +- 1
00036     //
00037     //  x4
00038     //  . .
00039     //  .  x1               z
00040     //   . .\               /\  /\y
00041     //   . .  \ E1            . |
00042     //    ..    \              .|
00043     //    2x------x3            .---->x
00044     //      .     .
00045     //       .E2 .
00046     //        . .
00047     //         x5
00048     //         . .
00049     //         .  x6
00050     //          . .\
00051     //          . .  \ E3
00052     //           ..    \
00053     //           7x------x8
00054     //             .     .
00055     //              .   .  E4
00056     //               . .
00057     //                x9
00058     //
00059     //
00060     double nodex[] = { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 };
00061     double nodey[] = { 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 };
00062     double nodez[] = { 0.0, 0.0, 0.0, 1.0, -1.0, -2.0, -2.0, -2.0, -3.0 };
00063     int connect[]  = { 1, 2, 3, 4, 3, 2, 1, 5, 6, 7, 8, 5, 8, 7, 6, 9 };
00064 
00065     const int NUM_NODES = 9;
00066 
00067     // construct the RMS holding the nodes
00068     MB_RMBSet node_rms( NUM_NODES, nodex, nodey, nodez, 1, 0 );
00069 
00070     // construct two RMS's holding each pair of elements
00071     MB_RMBSet elem_rms1( 2, connect, 1, TSTT_REGION, TSTT_TETRAHEDRON );
00072     MB_RMBSet elem_rms2( 2, &connect[8], 3, TSTT_REGION, TSTT_TETRAHEDRON );
00073 
00074     // now do some querying on this mesh
00075 
00076     // INFO FUNCTIONS
00077     int entity_type1 = node_rms.entity_type();
00078     int entity_type2 = elem_rms1.entity_type();
00079     if( entity_type1 != TSTT_VERTEX || entity_type2 != TSTT_REGION )
00080         std::cout << "entity_type() function failed." << std::endl;
00081 
00082     int entity_topo = elem_rms1.entity_topology();
00083     if( entity_topo != TSTT_TETRAHEDRON ) std::cout << "entity_topology() function failed." << std::endl;
00084 
00085     int num_ents1 = node_rms.num_entities();
00086     int num_ents2 = elem_rms1.num_entities();
00087     if( num_ents1 != NUM_NODES || num_ents2 != 2 )
00088         std::cout << "num_entities() function failed for" << ( num_ents1 != NUM_NODES ? "(nodes)" : "" )
00089                   << ( num_ents2 != 2 ? "(elems)" : "" ) << std::endl;
00090 
00091     int vpe = elem_rms1.vertices_per_element();
00092     if( vpe != 4 ) std::cout << "vertices_per_element() failed." << std::endl;
00093 
00094     // NODES
00095     /*
00096         // get_coordinates
00097       double coords[15];
00098       coords[1] = node_rms.get_coordinates(1);
00099       coords[2] = node_rms.get_coordinates(2);
00100       coords[3] = node_rms.get_coordinates(3);
00101       coords[4] = node_rms.get_coordinates(4);
00102       coords[5] = node_rms.get_coordinates(5);
00103       int result = compare_coords(coords, nodex, nodey, nodez, 5);
00104       if (result == 0) std::cout << "get_coordinates works." << std::endl;
00105       else std::cout << "get_coordinates didn't work; result = " << result << "." << std::endl;
00106     */
00107     // node_x, node_y, node_z
00108     int num_nodes = NUM_NODES;
00109     double xval[NUM_NODES], yval[NUM_NODES], zval[NUM_NODES];
00110     double *xvalp = &xval[0], *yvalp = &yval[0], *zvalp = &zval[0];
00111     node_rms.node_x( 1, NUM_NODES, &xvalp, &num_nodes );
00112     node_rms.node_y( 1, NUM_NODES, &yvalp, &num_nodes );
00113     node_rms.node_z( 1, NUM_NODES, &zvalp, &num_nodes );
00114     int result = compare_coords( xval, yval, zval, nodex, nodey, nodez, NUM_NODES );
00115     if( result != 0 ) std::cout << "node_[xyz] didn't work; result = " << result << "." << std::endl;
00116 
00117     // set_node_x, set_node_y, set_node_z
00118     int i;
00119     for( i = 1; i <= NUM_NODES; i++ )
00120     {
00121         nodex[i - 1] = (double)i;
00122         nodey[i - 1] = (double)i;
00123         nodez[i - 1] = (double)i;
00124     }
00125     node_rms.set_node_x( 1, NUM_NODES, nodex, NUM_NODES );
00126     node_rms.set_node_y( 1, NUM_NODES, nodey, NUM_NODES );
00127     node_rms.set_node_z( 1, NUM_NODES, nodez, NUM_NODES );
00128     node_rms.node_x( 1, NUM_NODES, &xvalp, &num_nodes );
00129     node_rms.node_y( 1, NUM_NODES, &yvalp, &num_nodes );
00130     node_rms.node_z( 1, NUM_NODES, &zvalp, &num_nodes );
00131     result = compare_coords( xval, yval, zval, nodex, nodey, nodez, NUM_NODES );
00132     if( result != 0 ) std::cout << "node_[xyz] didn't work; result = " << result << "." << std::endl;
00133 
00134     // ELEMENTS
00135     // elem_connectivity
00136     int* connect2     = NULL;
00137     int size_connect2 = 0;
00138     bool status       = elem_rms1.elem_connectivity( 1, 2, &connect2, &size_connect2 );
00139     if( status != true ) std::cout << "elem_connectivity() RETURN VALUE failed." << std::endl;
00140     if( 8 != size_connect2 ) std::cout << "re-sizing of connect2 vector failed." << std::endl;
00141 
00142     result = compare_connect( connect2, connect, 8 );
00143     if( result != 0 ) std::cout << "elem_connectivity() VALUES failed." << std::endl;
00144 
00145     // set_elem_connectivity
00146     // reverse the connectivity
00147     for( i = 1; i <= 8; i++ )
00148         connect2[i - 1] = connect[8 - i];
00149     elem_rms1.set_elem_connectivity( 1, 2, connect2, size_connect2 );
00150     status = elem_rms1.elem_connectivity( 1, 2, &connect2, &size_connect2 );
00151     if( status != true ) std::cout << "set_elem_connectivity() RETURN VALUE failed." << std::endl;
00152 
00153     result = compare_connect( connect2, connect, 8 );
00154     if( result != 0 ) std::cout << "elem_connectivity() VALUES failed." << std::endl;
00155 
00156     // RMESHSET FIND FUNCTIONS
00157     // find the rmeshsets for a node, and an element in each set
00158     MB_RMBSet *new_rms1, *new_rms2, *new_rms3;
00159     new_rms1 = MB_RMBSet::find_rmeshset( TSTT_VERTEX, TSTT_LAST_TOPOLOGY, reinterpret_cast< const void* >( 2 ) );
00160     new_rms2 = MB_RMBSet::find_rmeshset( TSTT_REGION, TSTT_TETRAHEDRON, reinterpret_cast< const void* >( 2 ) );
00161     new_rms3 = MB_RMBSet::find_rmeshset( TSTT_REGION, TSTT_TETRAHEDRON, reinterpret_cast< const void* >( 4 ) );
00162     if( new_rms1 != &node_rms || new_rms2 != &elem_rms1 || new_rms3 != &elem_rms2 )
00163         std::cout << "find_rmeshset() function failed." << std::endl;
00164 
00165     // now test NULL returns
00166     new_rms1 = MB_RMBSet::find_rmeshset( TSTT_VERTEX, TSTT_LAST_TOPOLOGY, reinterpret_cast< const void* >( 10 ) );
00167     new_rms2 = MB_RMBSet::find_rmeshset( TSTT_REGION, TSTT_TETRAHEDRON, reinterpret_cast< const void* >( 0 ) );
00168     new_rms3 = MB_RMBSet::find_rmeshset( TSTT_REGION, TSTT_TETRAHEDRON, reinterpret_cast< const void* >( 5 ) );
00169     if( NULL != new_rms1 || NULL != new_rms2 || NULL != new_rms3 )
00170         std::cout << "find_rmeshset() for NULL RETURN failed." << std::endl;
00171 
00172     // test is_in_rmeshset
00173     bool result1, result2, result3;
00174     result1 = node_rms.is_in_rmeshset( reinterpret_cast< const void* >( 6 ) );
00175     result2 = elem_rms1.is_in_rmeshset( reinterpret_cast< const void* >( 2 ) );
00176     result3 = elem_rms2.is_in_rmeshset( reinterpret_cast< const void* >( 4 ) );
00177     if( false == result1 || false == result2 || false == result3 ) std::cout << "is_in_rmeshset() failed." << std::endl;
00178 
00179     // test is_in_rmeshset
00180     result1 = node_rms.is_in_rmeshset( reinterpret_cast< const void* >( 10 ) );
00181     result2 = elem_rms1.is_in_rmeshset( reinterpret_cast< const void* >( 4 ) );
00182     result3 = elem_rms2.is_in_rmeshset( reinterpret_cast< const void* >( 2 ) );
00183     if( true == result1 || true == result2 || true == result3 )
00184         std::cout << "is_in_rmeshset() for NULL RETURN failed." << std::endl;
00185 
00186     return 1;
00187 }
00188 
00189 int compare_coords( double* xval, double* yval, double* zval, double* nodex, double* nodey, double* nodez,
00190                     const int num_nodes )
00191 {
00192     int i, result = 0;
00193     for( i = 0; i < num_nodes; i++ )
00194     {
00195         if( xval[i] != nodex[i] || yval[i] != nodey[i] || zval[i] != nodez[i] ) result++;
00196         xval[i] = yval[i] = zval[i] = -2.0;
00197     }
00198     return result;
00199 }
00200 
00201 int compare_connect( int* connect1, int* connect2, const int num_comps )
00202 {
00203     int i, result = 0;
00204     for( i = 0; i < num_comps; i++ )
00205     {
00206         if( connect1[i] != connect2[i] ) result++;
00207         connect2[i] = -1;
00208     }
00209 
00210     return result;
00211 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines