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