MOAB: Mesh Oriented datABase  (version 5.4.1)
ArrayMeshTest.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2007 Sandia National Laboratories.  Developed at the
00005     University of Wisconsin--Madison under SNL contract number
00006     624796.  The U.S. Government and the University of Wisconsin
00007     retain certain rights to 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     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     (lgpl.txt) along with this library; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023     (2007) [email protected]
00024 
00025   ***************************************************************** */
00026 
00027 /** \file ArrayMeshTest.cpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #include "Mesquite.hpp"
00033 #include "ArrayMesh.hpp"
00034 #include "MsqVertex.hpp"
00035 #include "MsqError.hpp"
00036 #include "UnitUtil.hpp"
00037 
00038 using namespace MBMesquite;
00039 
00040 class ArrayMeshTest : public CppUnit::TestFixture
00041 {
00042   private:
00043     CPPUNIT_TEST_SUITE( ArrayMeshTest );
00044 
00045     CPPUNIT_TEST( test_get_geometric_dimension );
00046     CPPUNIT_TEST( test_get_all_elements );
00047     CPPUNIT_TEST( test_get_all_vertices );
00048     CPPUNIT_TEST( test_get_all_vertices_one_based );
00049     CPPUNIT_TEST( test_vertex_iterator );
00050     CPPUNIT_TEST( test_vertex_iterator_one_based );
00051     CPPUNIT_TEST( test_element_iterator );
00052     CPPUNIT_TEST( test_vertices_get_fixed_flag );
00053     CPPUNIT_TEST( test_vertices_get_coordinates );
00054     CPPUNIT_TEST( test_vertices_get_coordinates_two_d );
00055     CPPUNIT_TEST( test_vertices_get_coordinates_one_based );
00056     CPPUNIT_TEST( test_vertex_set_coordinates );
00057     CPPUNIT_TEST( test_vertex_set_coordinates_two_d );
00058     CPPUNIT_TEST( test_vertex_set_coordinates_one_based );
00059     CPPUNIT_TEST( test_vertex_set_byte );
00060     CPPUNIT_TEST( test_vertices_set_byte );
00061     CPPUNIT_TEST( test_vertices_get_attached_elements );
00062     CPPUNIT_TEST( test_vertices_get_attached_elements_one_based );
00063     CPPUNIT_TEST( test_elements_get_attached_vertices );
00064     CPPUNIT_TEST( test_elements_get_topologies );
00065 
00066     CPPUNIT_TEST( test_vertices_get_attached_elements_mixed );
00067     CPPUNIT_TEST( test_vertices_get_attached_elements_mixed_one_based );
00068     CPPUNIT_TEST( test_elements_get_attached_vertices_mixed );
00069     CPPUNIT_TEST( test_elements_get_attached_vertices_mixed_one_based );
00070     CPPUNIT_TEST( test_elements_get_topologies_mixed );
00071 
00072     CPPUNIT_TEST( test_vertex_readonly_tag_data );
00073     CPPUNIT_TEST( test_vertex_readonly_tag_data_one_based );
00074     CPPUNIT_TEST( test_element_readonly_tag_data );
00075     CPPUNIT_TEST( test_vertex_writable_tag_data );
00076     CPPUNIT_TEST( test_vertex_writable_tag_data_one_based );
00077     CPPUNIT_TEST( test_element_writable_tag_data );
00078     CPPUNIT_TEST( test_vertex_owned_tag_data );
00079     CPPUNIT_TEST( test_vertex_owned_tag_data_one_based );
00080     CPPUNIT_TEST( test_element_owned_tag_data );
00081     CPPUNIT_TEST( test_delete_tag );
00082 
00083     CPPUNIT_TEST_SUITE_END();
00084 
00085     ArrayMesh *zeroBased3D, *oneBased3D, *zeroBased2D, *oneBased2D;
00086     ArrayMesh *mixedZeroBased, *mixedOneBased;
00087     double *zeroBased3Dcoords, *oneBased3Dcoords, *zeroBased2Dcoords, *oneBased2Dcoords;
00088     double *mixedZeroBasedCoords, *mixedOneBasedCoords;
00089 
00090   public:
00091     void setUp();
00092     void tearDown();
00093 
00094     void test_get_geometric_dimension();
00095     void test_get_all_elements();
00096     void test_get_all_vertices();
00097     void test_get_all_vertices_one_based();
00098     void test_vertex_iterator();
00099     void test_vertex_iterator_one_based();
00100     void test_element_iterator();
00101     void test_vertices_get_fixed_flag();
00102     void test_vertices_get_coordinates();
00103     void test_vertices_get_coordinates_two_d();
00104     void test_vertices_get_coordinates_one_based();
00105     void test_vertex_set_coordinates();
00106     void test_vertex_set_coordinates_two_d();
00107     void test_vertex_set_coordinates_one_based();
00108     void test_vertex_set_byte();
00109     void test_vertices_set_byte();
00110     void test_vertices_get_attached_elements();
00111     void test_vertices_get_attached_elements_one_based();
00112     void test_elements_get_attached_vertices();
00113     void test_elements_get_topologies();
00114 
00115     void test_vertices_get_attached_elements_mixed();
00116     void test_vertices_get_attached_elements_mixed_one_based();
00117     void test_elements_get_attached_vertices_mixed();
00118     void test_elements_get_attached_vertices_mixed_one_based();
00119     void test_elements_get_topologies_mixed();
00120 
00121     enum TagEntType
00122     {
00123         VERTEX,
00124         ONE_BASED_VERTEX,
00125         ELEMENT
00126     };
00127     enum TagStorage
00128     {
00129         READONLY,
00130         WRITABLE,
00131         OWNED
00132     };
00133     void test_tag_data( TagEntType type, TagStorage storage );
00134     void test_readonly_tag_data( TagEntType type )
00135     {
00136         test_tag_data( type, READONLY );
00137     }
00138     void test_writable_tag_data( TagEntType type )
00139     {
00140         test_tag_data( type, WRITABLE );
00141     }
00142     void test_owned_tag_data( TagEntType type )
00143     {
00144         test_tag_data( type, OWNED );
00145     }
00146 
00147     void test_vertex_readonly_tag_data()
00148     {
00149         test_readonly_tag_data( VERTEX );
00150     }
00151     void test_vertex_readonly_tag_data_one_based()
00152     {
00153         test_readonly_tag_data( ONE_BASED_VERTEX );
00154     }
00155     void test_element_readonly_tag_data()
00156     {
00157         test_readonly_tag_data( ELEMENT );
00158     }
00159     void test_vertex_writable_tag_data()
00160     {
00161         test_writable_tag_data( VERTEX );
00162     }
00163     void test_vertex_writable_tag_data_one_based()
00164     {
00165         test_writable_tag_data( ONE_BASED_VERTEX );
00166     }
00167     void test_element_writable_tag_data()
00168     {
00169         test_writable_tag_data( ELEMENT );
00170     }
00171     void test_vertex_owned_tag_data()
00172     {
00173         test_owned_tag_data( VERTEX );
00174     }
00175     void test_vertex_owned_tag_data_one_based()
00176     {
00177         test_owned_tag_data( ONE_BASED_VERTEX );
00178     }
00179     void test_element_owned_tag_data()
00180     {
00181         test_owned_tag_data( ELEMENT );
00182     }
00183     void test_delete_tag();
00184 };
00185 
00186 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ArrayMeshTest, "ArrayMeshTest" );
00187 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ArrayMeshTest, "Unit" );
00188 
00189 /* Mesh:
00190 
00191    0---------1----------2
00192    |         |          |
00193    |    0    |    1     |
00194    |         |          |
00195    |         |          |
00196    3---------4----------5
00197    |         |          |
00198    Y    2    |    3     |
00199    ^         |          |
00200    |         |          |
00201    6-->X-----7----------8
00202 
00203  Z = -2
00204 
00205 */
00206 const double coords_2d[] = { 0, 2, 1, 2, 2, 2, 0, 1, 1, 1, 2, 1, 0, 0, 1, 0, 2, 0 };
00207 const double coords_3d[] = { 0, 2, -2, 1, 2, -2, 2, 2, -2, 0, 1, -2, 1, 1, -2, 2, 1, -2, 0, 0, -2, 1, 0, -2, 2, 0, -2 };
00208 const unsigned long conn_zero_based[] = { 3, 4, 1, 0, 4, 5, 2, 1, 6, 7, 4, 3, 7, 8, 5, 4 };
00209 const unsigned long conn_one_based[]  = { 4, 5, 2, 1, 5, 6, 3, 2, 7, 8, 5, 4, 8, 9, 6, 5 };
00210 
00211 const int fixed[] = { 1, 1, 1, 1, 0, 1, 1, 1, 1 };
00212 
00213 /* Mixed mesh
00214  *
00215  *   0-------1-------2-------3
00216  *   |       | \  2  |       |
00217  *   |   0   |   \   |   3   |
00218  *   |       | 1   \ |       |
00219  *   7-------6-------5-------4
00220  */
00221 const double mixed_coords[]             = { 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 2.0, 1.0, 0.0, 3.0, 1.0, 0.0,
00222                                 3.0, 0.0, 0.0, 2.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
00223 const unsigned long mixed_conn_zero[]   = { 7, 6, 1, 0, 6, 5, 1, 2, 1, 5, 5, 4, 3, 2 };
00224 const unsigned long mixed_conn_one[]    = { 8, 7, 2, 1, 7, 6, 2, 3, 2, 6, 6, 5, 4, 3 };
00225 const EntityTopology mixed_types[]      = { QUADRILATERAL, TRIANGLE, TRIANGLE, QUADRILATERAL };
00226 const unsigned long conn_offsets_zero[] = { 0, 4, 7, 10, 14 };
00227 
00228 void ArrayMeshTest::setUp()
00229 {
00230     zeroBased3Dcoords    = new double[27];
00231     oneBased3Dcoords     = new double[27];
00232     zeroBased2Dcoords    = new double[18];
00233     oneBased2Dcoords     = new double[18];
00234     mixedZeroBasedCoords = new double[24];
00235     mixedOneBasedCoords  = new double[24];
00236     memcpy( zeroBased3Dcoords, coords_3d, 27 * sizeof( double ) );
00237     memcpy( oneBased3Dcoords, coords_3d, 27 * sizeof( double ) );
00238     memcpy( zeroBased2Dcoords, coords_2d, 18 * sizeof( double ) );
00239     memcpy( oneBased2Dcoords, coords_2d, 18 * sizeof( double ) );
00240     memcpy( mixedZeroBasedCoords, mixed_coords, 24 * sizeof( double ) );
00241     memcpy( mixedOneBasedCoords, mixed_coords, 24 * sizeof( double ) );
00242     zeroBased3D = new ArrayMesh( 3, 9, zeroBased3Dcoords, fixed, 4, QUADRILATERAL, conn_zero_based, false );
00243     oneBased3D  = new ArrayMesh( 3, 9, oneBased3Dcoords, fixed, 4, QUADRILATERAL, conn_one_based, true );
00244     zeroBased2D = new ArrayMesh( 2, 9, zeroBased2Dcoords, fixed, 4, QUADRILATERAL, conn_zero_based, false );
00245     oneBased2D  = new ArrayMesh( 2, 9, oneBased2Dcoords, fixed, 4, QUADRILATERAL, conn_one_based, true );
00246     mixedZeroBased =
00247         new ArrayMesh( 3, 8, mixedZeroBasedCoords, fixed, 4, mixed_types, mixed_conn_zero, conn_offsets_zero, false );
00248     mixedOneBased = new ArrayMesh( 3, 8, mixedOneBasedCoords, fixed, 4, mixed_types, mixed_conn_one, NULL, true );
00249 }
00250 
00251 void ArrayMeshTest::tearDown()
00252 {
00253     delete zeroBased3D;
00254     delete oneBased3D;
00255     delete zeroBased2D;
00256     delete oneBased2D;
00257     delete mixedZeroBased;
00258     delete mixedOneBased;
00259     delete[] zeroBased3Dcoords;
00260     delete[] oneBased3Dcoords;
00261     delete[] zeroBased2Dcoords;
00262     delete[] oneBased2Dcoords;
00263     delete[] mixedZeroBasedCoords;
00264     delete[] mixedOneBasedCoords;
00265 }
00266 
00267 void ArrayMeshTest::test_get_geometric_dimension()
00268 {
00269     MsqPrintError err( std::cerr );
00270     CPPUNIT_ASSERT_EQUAL( 2, zeroBased2D->get_geometric_dimension( err ) );
00271     CPPUNIT_ASSERT_EQUAL( 2, oneBased2D->get_geometric_dimension( err ) );
00272     CPPUNIT_ASSERT_EQUAL( 3, zeroBased3D->get_geometric_dimension( err ) );
00273     CPPUNIT_ASSERT_EQUAL( 3, oneBased3D->get_geometric_dimension( err ) );
00274 }
00275 
00276 void ArrayMeshTest::test_get_all_elements()
00277 {
00278     MsqPrintError err( std::cerr );
00279     std::vector< Mesh::ElementHandle > list;
00280     zeroBased3D->get_all_elements( list, err );
00281     CPPUNIT_ASSERT( !err );
00282     CPPUNIT_ASSERT_EQUAL( (size_t)4, list.size() );
00283     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)list[0] );
00284     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)list[1] );
00285     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)list[2] );
00286     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)list[3] );
00287 }
00288 
00289 void ArrayMeshTest::test_get_all_vertices()
00290 {
00291     MsqPrintError err( std::cerr );
00292     std::vector< Mesh::VertexHandle > list;
00293     zeroBased3D->get_all_vertices( list, err );
00294     CPPUNIT_ASSERT( !err );
00295     CPPUNIT_ASSERT_EQUAL( (size_t)9, list.size() );
00296     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)list[0] );
00297     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)list[1] );
00298     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)list[2] );
00299     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)list[3] );
00300     CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)list[4] );
00301     CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)list[5] );
00302     CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)list[6] );
00303     CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)list[7] );
00304     CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)list[8] );
00305 }
00306 
00307 void ArrayMeshTest::test_get_all_vertices_one_based()
00308 {
00309     MsqPrintError err( std::cerr );
00310     std::vector< Mesh::VertexHandle > list;
00311     oneBased3D->get_all_vertices( list, err );
00312     CPPUNIT_ASSERT( !err );
00313     CPPUNIT_ASSERT_EQUAL( (size_t)9, list.size() );
00314     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)list[0] );
00315     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)list[1] );
00316     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)list[2] );
00317     CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)list[3] );
00318     CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)list[4] );
00319     CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)list[5] );
00320     CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)list[6] );
00321     CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)list[7] );
00322     CPPUNIT_ASSERT_EQUAL( (size_t)9, (size_t)list[8] );
00323 }
00324 
00325 void ArrayMeshTest::test_vertex_iterator()
00326 {
00327     MsqPrintError err( std::cerr );
00328     VertexIterator* iter = zeroBased3D->vertex_iterator( err );
00329     CPPUNIT_ASSERT( !err );
00330     std::unique_ptr< VertexIterator > deleter( iter );
00331 
00332     CPPUNIT_ASSERT( !iter->is_at_end() );
00333     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)iter->operator*() );
00334     iter->operator++();
00335     CPPUNIT_ASSERT( !iter->is_at_end() );
00336     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)iter->operator*() );
00337     iter->operator++();
00338     CPPUNIT_ASSERT( !iter->is_at_end() );
00339     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)iter->operator*() );
00340     iter->operator++();
00341     CPPUNIT_ASSERT( !iter->is_at_end() );
00342     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)iter->operator*() );
00343     iter->operator++();
00344     CPPUNIT_ASSERT( !iter->is_at_end() );
00345     CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)iter->operator*() );
00346     iter->operator++();
00347     CPPUNIT_ASSERT( !iter->is_at_end() );
00348     CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)iter->operator*() );
00349     iter->operator++();
00350     CPPUNIT_ASSERT( !iter->is_at_end() );
00351     CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)iter->operator*() );
00352     iter->operator++();
00353     CPPUNIT_ASSERT( !iter->is_at_end() );
00354     CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)iter->operator*() );
00355     iter->operator++();
00356     CPPUNIT_ASSERT( iter->is_at_end() );
00357     CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)iter->operator*() );
00358 
00359     iter->restart();
00360     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)iter->operator*() );
00361 }
00362 
00363 void ArrayMeshTest::test_vertex_iterator_one_based()
00364 {
00365     MsqPrintError err( std::cerr );
00366     VertexIterator* iter = oneBased3D->vertex_iterator( err );
00367     CPPUNIT_ASSERT( !err );
00368     std::unique_ptr< VertexIterator > deleter( iter );
00369 
00370     CPPUNIT_ASSERT( !iter->is_at_end() );
00371     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)iter->operator*() );
00372     iter->operator++();
00373     CPPUNIT_ASSERT( !iter->is_at_end() );
00374     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)iter->operator*() );
00375     iter->operator++();
00376     CPPUNIT_ASSERT( !iter->is_at_end() );
00377     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)iter->operator*() );
00378     iter->operator++();
00379     CPPUNIT_ASSERT( !iter->is_at_end() );
00380     CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)iter->operator*() );
00381     iter->operator++();
00382     CPPUNIT_ASSERT( !iter->is_at_end() );
00383     CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)iter->operator*() );
00384     iter->operator++();
00385     CPPUNIT_ASSERT( !iter->is_at_end() );
00386     CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)iter->operator*() );
00387     iter->operator++();
00388     CPPUNIT_ASSERT( !iter->is_at_end() );
00389     CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)iter->operator*() );
00390     iter->operator++();
00391     CPPUNIT_ASSERT( !iter->is_at_end() );
00392     CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)iter->operator*() );
00393     iter->operator++();
00394     CPPUNIT_ASSERT( iter->is_at_end() );
00395     CPPUNIT_ASSERT_EQUAL( (size_t)9, (size_t)iter->operator*() );
00396 
00397     iter->restart();
00398     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)iter->operator*() );
00399 }
00400 
00401 void ArrayMeshTest::test_element_iterator()
00402 {
00403     MsqPrintError err( std::cerr );
00404     ElementIterator* iter = zeroBased3D->element_iterator( err );
00405     CPPUNIT_ASSERT( !err );
00406     std::unique_ptr< ElementIterator > deleter( iter );
00407 
00408     CPPUNIT_ASSERT( !iter->is_at_end() );
00409     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)iter->operator*() );
00410     iter->operator++();
00411     CPPUNIT_ASSERT( !iter->is_at_end() );
00412     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)iter->operator*() );
00413     iter->operator++();
00414     CPPUNIT_ASSERT( !iter->is_at_end() );
00415     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)iter->operator*() );
00416     iter->operator++();
00417     CPPUNIT_ASSERT( iter->is_at_end() );
00418     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)iter->operator*() );
00419 
00420     iter->restart();
00421     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)iter->operator*() );
00422 }
00423 
00424 void ArrayMeshTest::test_vertices_get_fixed_flag()
00425 {
00426     MsqPrintError err( std::cerr );
00427     const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 4 };
00428     std::vector< bool > flags;
00429     zeroBased3D->vertices_get_fixed_flag( (const Mesh::VertexHandle*)verts, flags, 10, err );
00430     CPPUNIT_ASSERT( !err );
00431     CPPUNIT_ASSERT_EQUAL( (size_t)10, flags.size() );
00432     CPPUNIT_ASSERT_EQUAL( true, (bool)flags[0] );
00433     CPPUNIT_ASSERT_EQUAL( true, (bool)flags[1] );
00434     CPPUNIT_ASSERT_EQUAL( true, (bool)flags[2] );
00435     CPPUNIT_ASSERT_EQUAL( true, (bool)flags[3] );
00436     CPPUNIT_ASSERT_EQUAL( false, (bool)flags[4] );
00437     CPPUNIT_ASSERT_EQUAL( true, (bool)flags[5] );
00438     CPPUNIT_ASSERT_EQUAL( true, (bool)flags[6] );
00439     CPPUNIT_ASSERT_EQUAL( true, (bool)flags[7] );
00440     CPPUNIT_ASSERT_EQUAL( true, (bool)flags[8] );
00441     CPPUNIT_ASSERT_EQUAL( false, (bool)flags[9] );
00442 }
00443 
00444 void ArrayMeshTest::test_vertices_get_coordinates()
00445 {
00446     MsqPrintError err( std::cerr );
00447     const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 4 };
00448     MsqVertex coords[10];
00449     zeroBased3D->vertices_get_coordinates( (const Mesh::VertexHandle*)verts, coords, 10, err );
00450     CPPUNIT_ASSERT( !err );
00451     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 0 ), coords[0], DBL_EPSILON );
00452     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 3 ), coords[1], DBL_EPSILON );
00453     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 6 ), coords[2], DBL_EPSILON );
00454     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 9 ), coords[3], DBL_EPSILON );
00455     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 12 ), coords[4], DBL_EPSILON );
00456     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 15 ), coords[5], DBL_EPSILON );
00457     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 18 ), coords[6], DBL_EPSILON );
00458     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 21 ), coords[7], DBL_EPSILON );
00459     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 24 ), coords[8], DBL_EPSILON );
00460     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 12 ), coords[4], DBL_EPSILON );
00461 }
00462 
00463 void ArrayMeshTest::test_vertices_get_coordinates_two_d()
00464 {
00465     MsqPrintError err( std::cerr );
00466     const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 4 };
00467     MsqVertex coords[10];
00468     zeroBased2D->vertices_get_coordinates( (const Mesh::VertexHandle*)verts, coords, 10, err );
00469     CPPUNIT_ASSERT( !err );
00470     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[0], coords_2d[1], 0 ), coords[0], DBL_EPSILON );
00471     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[2], coords_2d[3], 0 ), coords[1], DBL_EPSILON );
00472     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[4], coords_2d[5], 0 ), coords[2], DBL_EPSILON );
00473     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[6], coords_2d[7], 0 ), coords[3], DBL_EPSILON );
00474     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[8], coords_2d[9], 0 ), coords[4], DBL_EPSILON );
00475     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[10], coords_2d[11], 0 ), coords[5], DBL_EPSILON );
00476     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[12], coords_2d[13], 0 ), coords[6], DBL_EPSILON );
00477     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[14], coords_2d[15], 0 ), coords[7], DBL_EPSILON );
00478     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[16], coords_2d[17], 0 ), coords[8], DBL_EPSILON );
00479     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_2d[8], coords_2d[9], 0 ), coords[9], DBL_EPSILON );
00480 }
00481 
00482 void ArrayMeshTest::test_vertices_get_coordinates_one_based()
00483 {
00484     MsqPrintError err( std::cerr );
00485     const size_t verts[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 5 };
00486     MsqVertex coords[10];
00487     oneBased3D->vertices_get_coordinates( (const Mesh::VertexHandle*)verts, coords, 10, err );
00488     CPPUNIT_ASSERT( !err );
00489     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 0 ), coords[0], DBL_EPSILON );
00490     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 3 ), coords[1], DBL_EPSILON );
00491     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 6 ), coords[2], DBL_EPSILON );
00492     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 9 ), coords[3], DBL_EPSILON );
00493     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 12 ), coords[4], DBL_EPSILON );
00494     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 15 ), coords[5], DBL_EPSILON );
00495     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 18 ), coords[6], DBL_EPSILON );
00496     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 21 ), coords[7], DBL_EPSILON );
00497     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 24 ), coords[8], DBL_EPSILON );
00498     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( coords_3d + 12 ), coords[4], DBL_EPSILON );
00499 }
00500 
00501 void ArrayMeshTest::test_vertex_set_coordinates()
00502 {
00503     MsqPrintError err( std::cerr );
00504     Mesh::VertexHandle vert = (Mesh::VertexHandle)4;
00505     Vector3D new_pos( 5, 5, 5 );
00506     MsqVertex pos;
00507     zeroBased3D->vertex_set_coordinates( vert, new_pos, err );
00508     CPPUNIT_ASSERT( !err );
00509     zeroBased3D->vertices_get_coordinates( &vert, &pos, 1, err );
00510     CPPUNIT_ASSERT( !err );
00511     CPPUNIT_ASSERT_VECTORS_EQUAL( new_pos, pos, DBL_EPSILON );
00512 }
00513 
00514 void ArrayMeshTest::test_vertex_set_coordinates_two_d()
00515 {
00516     MsqPrintError err( std::cerr );
00517     Mesh::VertexHandle vert = (Mesh::VertexHandle)4;
00518     Vector3D new_pos( 5, 5, 5 );
00519     MsqVertex pos;
00520     zeroBased2D->vertex_set_coordinates( vert, new_pos, err );
00521     CPPUNIT_ASSERT( !err );
00522     zeroBased2D->vertices_get_coordinates( &vert, &pos, 1, err );
00523     CPPUNIT_ASSERT( !err );
00524     new_pos[2] = 0;
00525     CPPUNIT_ASSERT_VECTORS_EQUAL( new_pos, pos, DBL_EPSILON );
00526 }
00527 
00528 void ArrayMeshTest::test_vertex_set_coordinates_one_based()
00529 {
00530     MsqPrintError err( std::cerr );
00531     Mesh::VertexHandle vert = (Mesh::VertexHandle)5;
00532     Vector3D new_pos( 5, 5, 5 );
00533     MsqVertex pos;
00534     oneBased3D->vertex_set_coordinates( vert, new_pos, err );
00535     CPPUNIT_ASSERT( !err );
00536     oneBased3D->vertices_get_coordinates( &vert, &pos, 1, err );
00537     CPPUNIT_ASSERT( !err );
00538     CPPUNIT_ASSERT_VECTORS_EQUAL( new_pos, pos, DBL_EPSILON );
00539 }
00540 
00541 void ArrayMeshTest::test_vertex_set_byte()
00542 {
00543     MsqPrintError err( std::cerr );
00544     unsigned char byte      = 'A';
00545     Mesh::VertexHandle vert = (Mesh::VertexHandle)5;
00546     zeroBased3D->vertex_set_byte( vert, byte, err );
00547     CPPUNIT_ASSERT( !err );
00548     byte = '0';
00549     zeroBased3D->vertex_get_byte( vert, &byte, err );
00550     CPPUNIT_ASSERT( !err );
00551     CPPUNIT_ASSERT_EQUAL( (unsigned char)'A', byte );
00552 }
00553 
00554 void ArrayMeshTest::test_vertices_set_byte()
00555 {
00556     MsqPrintError err( std::cerr );
00557     const size_t verts[]        = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 4 };
00558     const unsigned char bytes[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'E' };
00559     unsigned char b[10];
00560     memset( b, 0, 10 );
00561     zeroBased3D->vertices_set_byte( (const Mesh::VertexHandle*)verts, bytes, 10, err );
00562     CPPUNIT_ASSERT( !err );
00563     zeroBased3D->vertices_get_byte( (const Mesh::VertexHandle*)verts, b, 10, err );
00564     CPPUNIT_ASSERT( !err );
00565     CPPUNIT_ASSERT_EQUAL( bytes[0], b[0] );
00566     CPPUNIT_ASSERT_EQUAL( bytes[1], b[1] );
00567     CPPUNIT_ASSERT_EQUAL( bytes[2], b[2] );
00568     CPPUNIT_ASSERT_EQUAL( bytes[3], b[3] );
00569     CPPUNIT_ASSERT_EQUAL( bytes[4], b[4] );
00570     CPPUNIT_ASSERT_EQUAL( bytes[5], b[5] );
00571     CPPUNIT_ASSERT_EQUAL( bytes[6], b[6] );
00572     CPPUNIT_ASSERT_EQUAL( bytes[7], b[7] );
00573     CPPUNIT_ASSERT_EQUAL( bytes[8], b[8] );
00574 }
00575 
00576 void ArrayMeshTest::test_vertices_get_attached_elements()
00577 {
00578     MsqPrintError err( std::cerr );
00579     const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
00580     std::vector< Mesh::ElementHandle > elems;
00581     std::vector< size_t > offsets;
00582     zeroBased3D->vertices_get_attached_elements( (const Mesh::VertexHandle*)verts, 9, elems, offsets, err );
00583     CPPUNIT_ASSERT( !err );
00584 
00585     CPPUNIT_ASSERT_EQUAL( (size_t)16, elems.size() );
00586     CPPUNIT_ASSERT( offsets.size() == 9 || offsets.size() == 10 );
00587     if( offsets.size() == 10 ) CPPUNIT_ASSERT_EQUAL( size_t( 16 ), offsets[9] );
00588 
00589     // vert 0
00590     CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
00591     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[0] );
00592     // vert 1
00593     CPPUNIT_ASSERT_EQUAL( (size_t)1, offsets[1] );
00594     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[1] );
00595     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[2] );
00596     // vert 2
00597     CPPUNIT_ASSERT_EQUAL( (size_t)3, offsets[2] );
00598     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[3] );
00599     // vert 3
00600     CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[3] );
00601     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[4] );
00602     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[5] );
00603     // vert 4
00604     CPPUNIT_ASSERT_EQUAL( (size_t)6, offsets[4] );
00605     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[6] );
00606     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[7] );
00607     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[8] );
00608     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[9] );
00609     // vert 5
00610     CPPUNIT_ASSERT_EQUAL( (size_t)10, offsets[5] );
00611     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[10] );
00612     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[11] );
00613     // vert 6
00614     CPPUNIT_ASSERT_EQUAL( (size_t)12, offsets[6] );
00615     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[12] );
00616     // vert 7
00617     CPPUNIT_ASSERT_EQUAL( (size_t)13, offsets[7] );
00618     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[13] );
00619     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[14] );
00620     // vert 8
00621     CPPUNIT_ASSERT_EQUAL( (size_t)15, offsets[8] );
00622     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[15] );
00623 }
00624 
00625 void ArrayMeshTest::test_vertices_get_attached_elements_one_based()
00626 {
00627     MsqPrintError err( std::cerr );
00628     const size_t verts[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
00629     std::vector< Mesh::ElementHandle > elems;
00630     std::vector< size_t > offsets;
00631     oneBased3D->vertices_get_attached_elements( (const Mesh::VertexHandle*)verts, 9, elems, offsets, err );
00632     CPPUNIT_ASSERT( !err );
00633 
00634     CPPUNIT_ASSERT_EQUAL( (size_t)16, elems.size() );
00635     CPPUNIT_ASSERT( offsets.size() == 9 || offsets.size() == 10 );
00636     if( offsets.size() == 10 ) CPPUNIT_ASSERT_EQUAL( size_t( 16 ), offsets[9] );
00637 
00638     // vert 0
00639     CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
00640     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[0] );
00641     // vert 1
00642     CPPUNIT_ASSERT_EQUAL( (size_t)1, offsets[1] );
00643     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[1] );
00644     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[2] );
00645     // vert 2
00646     CPPUNIT_ASSERT_EQUAL( (size_t)3, offsets[2] );
00647     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[3] );
00648     // vert 3
00649     CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[3] );
00650     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[4] );
00651     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[5] );
00652     // vert 4
00653     CPPUNIT_ASSERT_EQUAL( (size_t)6, offsets[4] );
00654     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[6] );
00655     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[7] );
00656     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[8] );
00657     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[9] );
00658     // vert 5
00659     CPPUNIT_ASSERT_EQUAL( (size_t)10, offsets[5] );
00660     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[10] );
00661     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[11] );
00662     // vert 6
00663     CPPUNIT_ASSERT_EQUAL( (size_t)12, offsets[6] );
00664     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[12] );
00665     // vert 7
00666     CPPUNIT_ASSERT_EQUAL( (size_t)13, offsets[7] );
00667     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[13] );
00668     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[14] );
00669     // vert 8
00670     CPPUNIT_ASSERT_EQUAL( (size_t)15, offsets[8] );
00671     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[15] );
00672 }
00673 
00674 void ArrayMeshTest::test_elements_get_attached_vertices()
00675 {
00676     MsqPrintError err( std::cerr );
00677     const size_t elems[] = { 3, 2, 1, 0 };
00678     std::vector< Mesh::VertexHandle > verts;
00679     std::vector< size_t > offsets;
00680     zeroBased3D->elements_get_attached_vertices( (const Mesh::ElementHandle*)elems, 4, verts, offsets, err );
00681     CPPUNIT_ASSERT( !err );
00682     CPPUNIT_ASSERT_EQUAL( (size_t)16, verts.size() );
00683     CPPUNIT_ASSERT( offsets.size() == 4 || offsets.size() == 5 );
00684     if( offsets.size() == 5 ) CPPUNIT_ASSERT_EQUAL( (size_t)16, offsets[4] );
00685 
00686     // elem 3
00687     CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
00688     CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)verts[0] );
00689     CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)verts[1] );
00690     CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)verts[2] );
00691     CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)verts[3] );
00692 
00693     // elem 2
00694     CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[1] );
00695     CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)verts[4] );
00696     CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)verts[5] );
00697     CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)verts[6] );
00698     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)verts[7] );
00699 
00700     // elem 1
00701     CPPUNIT_ASSERT_EQUAL( (size_t)8, offsets[2] );
00702     CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)verts[8] );
00703     CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)verts[9] );
00704     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)verts[10] );
00705     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)verts[11] );
00706 
00707     // elem 0
00708     CPPUNIT_ASSERT_EQUAL( (size_t)12, offsets[3] );
00709     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)verts[12] );
00710     CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)verts[13] );
00711     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)verts[14] );
00712     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)verts[15] );
00713 }
00714 
00715 void ArrayMeshTest::test_elements_get_topologies()
00716 {
00717     MsqPrintError err( std::cerr );
00718     const size_t elems[]  = { 3, 2, 1, 0, 1, 2, 3, 0 };
00719     const size_t num_elem = sizeof( elems ) / sizeof( elems[0] );
00720     EntityTopology topo[num_elem];
00721     memset( topo, 0, sizeof( topo ) );
00722     zeroBased3D->elements_get_topologies( (const Mesh::ElementHandle*)elems, topo, num_elem, err );
00723     CPPUNIT_ASSERT( !err );
00724     for( size_t i = 0; i < num_elem; ++i )
00725         CPPUNIT_ASSERT_EQUAL( (int)QUADRILATERAL, (int)topo[i] );
00726 }
00727 
00728 void ArrayMeshTest::test_vertices_get_attached_elements_mixed()
00729 {
00730     MsqPrintError err( std::cerr );
00731     const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
00732     std::vector< Mesh::ElementHandle > elems;
00733     std::vector< size_t > offsets;
00734     mixedZeroBased->vertices_get_attached_elements( (const Mesh::VertexHandle*)verts, 8, elems, offsets, err );
00735     CPPUNIT_ASSERT( !err );
00736 
00737     CPPUNIT_ASSERT_EQUAL( (size_t)14, elems.size() );
00738     CPPUNIT_ASSERT( offsets.size() == 8 || offsets.size() == 9 );
00739     if( offsets.size() == 9 ) CPPUNIT_ASSERT_EQUAL( elems.size(), offsets[8] );
00740 
00741     // vert 0
00742     CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
00743     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[0] );
00744     // vert 1
00745     CPPUNIT_ASSERT_EQUAL( (size_t)1, offsets[1] );
00746     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[1] );
00747     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[2] );
00748     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[3] );
00749     // vert 2
00750     CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[2] );
00751     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[4] );
00752     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[5] );
00753     // vert 3
00754     CPPUNIT_ASSERT_EQUAL( (size_t)6, offsets[3] );
00755     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[6] );
00756     // vert 4
00757     CPPUNIT_ASSERT_EQUAL( (size_t)7, offsets[4] );
00758     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[7] );
00759     // vert 5
00760     CPPUNIT_ASSERT_EQUAL( (size_t)8, offsets[5] );
00761     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[8] );
00762     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[9] );
00763     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[10] );
00764     // vert 6
00765     CPPUNIT_ASSERT_EQUAL( (size_t)11, offsets[6] );
00766     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[11] );
00767     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[12] );
00768     // vert 7
00769     CPPUNIT_ASSERT_EQUAL( (size_t)13, offsets[7] );
00770     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[13] );
00771 }
00772 
00773 void ArrayMeshTest::test_vertices_get_attached_elements_mixed_one_based()
00774 {
00775     MsqPrintError err( std::cerr );
00776     const size_t verts[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
00777     std::vector< Mesh::ElementHandle > elems;
00778     std::vector< size_t > offsets;
00779     mixedOneBased->vertices_get_attached_elements( (const Mesh::VertexHandle*)verts, 8, elems, offsets, err );
00780     CPPUNIT_ASSERT( !err );
00781 
00782     CPPUNIT_ASSERT_EQUAL( (size_t)14, elems.size() );
00783     CPPUNIT_ASSERT( offsets.size() == 8 || offsets.size() == 9 );
00784     if( offsets.size() == 9 ) CPPUNIT_ASSERT_EQUAL( elems.size(), offsets[8] );
00785 
00786     // vert 0
00787     CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
00788     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[0] );
00789     // vert 1
00790     CPPUNIT_ASSERT_EQUAL( (size_t)1, offsets[1] );
00791     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[1] );
00792     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[2] );
00793     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[3] );
00794     // vert 2
00795     CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[2] );
00796     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[4] );
00797     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[5] );
00798     // vert 3
00799     CPPUNIT_ASSERT_EQUAL( (size_t)6, offsets[3] );
00800     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[6] );
00801     // vert 4
00802     CPPUNIT_ASSERT_EQUAL( (size_t)7, offsets[4] );
00803     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[7] );
00804     // vert 5
00805     CPPUNIT_ASSERT_EQUAL( (size_t)8, offsets[5] );
00806     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[8] );
00807     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[9] );
00808     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[10] );
00809     // vert 6
00810     CPPUNIT_ASSERT_EQUAL( (size_t)11, offsets[6] );
00811     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[11] );
00812     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[12] );
00813     // vert 7
00814     CPPUNIT_ASSERT_EQUAL( (size_t)13, offsets[7] );
00815     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[13] );
00816 }
00817 
00818 void ArrayMeshTest::test_elements_get_attached_vertices_mixed()
00819 {
00820     MsqPrintError err( std::cerr );
00821     const size_t elems[] = { 3, 2, 1, 0 };
00822     std::vector< Mesh::VertexHandle > verts;
00823     std::vector< size_t > offsets;
00824     mixedZeroBased->elements_get_attached_vertices( (const Mesh::ElementHandle*)elems, 4, verts, offsets, err );
00825     CPPUNIT_ASSERT( !err );
00826     CPPUNIT_ASSERT_EQUAL( (size_t)14, verts.size() );
00827     CPPUNIT_ASSERT( offsets.size() == 4 || offsets.size() == 5 );
00828     if( offsets.size() == 5 ) CPPUNIT_ASSERT_EQUAL( verts.size(), offsets[4] );
00829 
00830     // elem 3
00831     CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
00832     CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)verts[0] );
00833     CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)verts[1] );
00834     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)verts[2] );
00835     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)verts[3] );
00836 
00837     // elem 2
00838     CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[1] );
00839     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)verts[4] );
00840     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)verts[5] );
00841     CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)verts[6] );
00842 
00843     // elem 1
00844     CPPUNIT_ASSERT_EQUAL( (size_t)7, offsets[2] );
00845     CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)verts[7] );
00846     CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)verts[8] );
00847     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)verts[9] );
00848 
00849     // elem 0
00850     CPPUNIT_ASSERT_EQUAL( (size_t)10, offsets[3] );
00851     CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)verts[10] );
00852     CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)verts[11] );
00853     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)verts[12] );
00854     CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)verts[13] );
00855 }
00856 
00857 void ArrayMeshTest::test_elements_get_attached_vertices_mixed_one_based()
00858 {
00859     MsqPrintError err( std::cerr );
00860     const size_t elems[] = { 3, 2, 1, 0 };
00861     std::vector< Mesh::VertexHandle > verts;
00862     std::vector< size_t > offsets;
00863     mixedOneBased->elements_get_attached_vertices( (const Mesh::ElementHandle*)elems, 4, verts, offsets, err );
00864     CPPUNIT_ASSERT( !err );
00865     CPPUNIT_ASSERT_EQUAL( (size_t)14, verts.size() );
00866     CPPUNIT_ASSERT( offsets.size() == 4 || offsets.size() == 5 );
00867     if( offsets.size() == 5 ) CPPUNIT_ASSERT_EQUAL( verts.size(), offsets[4] );
00868 
00869     // elem 3
00870     CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
00871     CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)verts[0] );
00872     CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)verts[1] );
00873     CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)verts[2] );
00874     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)verts[3] );
00875 
00876     // elem 2
00877     CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[1] );
00878     CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)verts[4] );
00879     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)verts[5] );
00880     CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)verts[6] );
00881 
00882     // elem 1
00883     CPPUNIT_ASSERT_EQUAL( (size_t)7, offsets[2] );
00884     CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)verts[7] );
00885     CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)verts[8] );
00886     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)verts[9] );
00887 
00888     // elem 0
00889     CPPUNIT_ASSERT_EQUAL( (size_t)10, offsets[3] );
00890     CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)verts[10] );
00891     CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)verts[11] );
00892     CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)verts[12] );
00893     CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)verts[13] );
00894 }
00895 
00896 void ArrayMeshTest::test_elements_get_topologies_mixed()
00897 {
00898     MsqPrintError err( std::cerr );
00899     const size_t elems[]  = { 3, 2, 1, 0, 1, 2, 3 };
00900     const size_t num_elem = sizeof( elems ) / sizeof( elems[0] );
00901     EntityTopology topo[num_elem];
00902     memset( topo, 0, sizeof( topo ) );
00903     mixedZeroBased->elements_get_topologies( (const Mesh::ElementHandle*)elems, topo, num_elem, err );
00904     CPPUNIT_ASSERT( !err );
00905     for( size_t i = 0; i < num_elem; ++i )
00906         CPPUNIT_ASSERT_EQUAL( (int)mixed_types[elems[i]], (int)topo[i] );
00907 }
00908 
00909 void ArrayMeshTest::test_tag_data( TagEntType type, TagStorage storage )
00910 {
00911     // Select what we're working with given 'type' parameter
00912     ArrayMesh* const mesh = ( type == ONE_BASED_VERTEX ) ? oneBased3D : zeroBased3D;
00913     std::vector< Mesh::EntityHandle > entities;
00914     MsqError err;
00915     if( type == ELEMENT )
00916         mesh->get_all_elements( entities, err );
00917     else
00918         mesh->get_all_vertices( entities, err );
00919     ASSERT_NO_ERROR( err );
00920 
00921     // Create a tag
00922     char name1[] = "  _double_3";
00923     name1[0]     = 'A' + type;
00924     name1[1]     = 'A' + storage;
00925     TagHandle tag;
00926     std::vector< double > values( 3 * entities.size() );
00927     double dval = -5;
00928     for( std::vector< double >::iterator i = values.begin(); i != values.end(); ++i )
00929         *i = dval--;
00930     double* ele_ptr = ( type == ELEMENT ) ? arrptr( values ) : 0;
00931     double* vtx_ptr = ( type != ELEMENT ) ? arrptr( values ) : 0;
00932     if( storage == READONLY )
00933     {
00934         tag = mesh->add_read_only_tag_data( name1, Mesh::DOUBLE, 3, vtx_ptr, ele_ptr, 0, err );
00935         ASSERT_NO_ERROR( err );
00936     }
00937     else if( storage == WRITABLE )
00938     {
00939         tag = mesh->add_writable_tag_data( name1, Mesh::DOUBLE, 3, vtx_ptr, ele_ptr, 0, err );
00940         ASSERT_NO_ERROR( err );
00941     }
00942     else
00943     {
00944         assert( OWNED == storage );
00945         tag = mesh->tag_create( name1, Mesh::DOUBLE, 3, 0, err );
00946         ASSERT_NO_ERROR( err );
00947         if( type == ELEMENT )
00948             mesh->tag_set_element_data( tag, entities.size(), arrptr( entities ), arrptr( values ), err );
00949         else
00950             mesh->tag_set_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values ), err );
00951         ASSERT_NO_ERROR( err );
00952     }
00953 
00954     // Check tag properties
00955     TagHandle tag2 = mesh->tag_get( name1, err );
00956     ASSERT_NO_ERROR( err );
00957     CPPUNIT_ASSERT_EQUAL( tag, tag2 );
00958     std::string n;
00959     Mesh::TagType t;
00960     unsigned s;
00961     mesh->tag_properties( tag, n, t, s, err );
00962     ASSERT_NO_ERROR( err );
00963     CPPUNIT_ASSERT_EQUAL( std::string( name1 ), n );
00964     CPPUNIT_ASSERT_EQUAL( Mesh::DOUBLE, t );
00965     CPPUNIT_ASSERT_EQUAL( 3u, s );
00966 
00967     // Check values returned from tag_get_*_data
00968     std::vector< double > values2( 3 * entities.size() );
00969     if( ELEMENT == type )
00970         mesh->tag_get_element_data( tag, entities.size(), arrptr( entities ), arrptr( values2 ), err );
00971     else
00972         mesh->tag_get_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values2 ), err );
00973     ASSERT_NO_ERROR( err );
00974     ASSERT_STD_VECTORS_EQUAL( values, values2 );
00975 
00976     // check that we get an error for other type, because no default
00977     if( ELEMENT != type )
00978         mesh->tag_get_element_data( tag, entities.size(), arrptr( entities ), arrptr( values2 ), err );
00979     else
00980         mesh->tag_get_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values2 ), err );
00981     CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
00982     err.clear();
00983 
00984     // check that we can or cannot modify the values as expected
00985     dval = entities.size() + 1;
00986     std::vector< double > values5( values.size() );
00987     for( std::vector< double >::iterator i = values5.begin(); i != values5.end(); ++i )
00988         *i = dval++;
00989     if( ELEMENT == type )
00990         mesh->tag_set_element_data( tag, entities.size(), arrptr( entities ), arrptr( values5 ), err );
00991     else
00992         mesh->tag_set_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values5 ), err );
00993     if( READONLY == storage )
00994     {
00995         CPPUNIT_ASSERT( err );
00996         err.clear();
00997     }
00998     else
00999     {
01000         ASSERT_NO_ERROR( err );
01001     }
01002 
01003     // check that the values are as expected
01004     if( READONLY != storage )
01005     {
01006         if( ELEMENT == type )
01007             mesh->tag_get_element_data( tag, entities.size(), arrptr( entities ), arrptr( values2 ), err );
01008         else
01009             mesh->tag_get_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values2 ), err );
01010         ASSERT_NO_ERROR( err );
01011         ASSERT_STD_VECTORS_EQUAL( values5, values2 );
01012 
01013         // if WRITABLE storeage, original input array should have changed also
01014         if( WRITABLE == storage )
01015         {
01016             ASSERT_STD_VECTORS_EQUAL( values, values5 );
01017         }
01018     }
01019 
01020     // create a new tag with a default value
01021     char name2[]            = "  _int_2";
01022     name2[0]                = 'A' + type;
01023     name2[1]                = 'A' + storage;
01024     const int default_val[] = { 'J', 'K' };
01025     if( READONLY == storage )
01026         tag = mesh->add_read_only_tag_data( name2, Mesh::INT, 2, 0, 0, default_val, err );
01027     else if( WRITABLE == storage )
01028         tag = mesh->add_writable_tag_data( name2, Mesh::INT, 2, 0, 0, default_val, err );
01029     else  // OWNED == storage
01030         tag = mesh->tag_create( name2, Mesh::INT, 2, default_val, err );
01031     ASSERT_NO_ERROR( err );
01032 
01033     // Check tag properties
01034     tag2 = mesh->tag_get( name2, err );
01035     ASSERT_NO_ERROR( err );
01036     CPPUNIT_ASSERT_EQUAL( tag, tag2 );
01037     mesh->tag_properties( tag, n, t, s, err );
01038     ASSERT_NO_ERROR( err );
01039     CPPUNIT_ASSERT_EQUAL( std::string( name2 ), n );
01040     CPPUNIT_ASSERT_EQUAL( Mesh::INT, t );
01041     CPPUNIT_ASSERT_EQUAL( 2u, s );
01042 
01043     // should get default value for each entity
01044     std::vector< int > values3( 2 * entities.size() );
01045     if( ELEMENT == type )
01046         mesh->tag_get_element_data( tag, entities.size(), arrptr( entities ), arrptr( values3 ), err );
01047     else
01048         mesh->tag_get_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values3 ), err );
01049     ASSERT_NO_ERROR( err );
01050 
01051     // check that we got the default value for every entity
01052     for( size_t i = 0; i < entities.size(); ++i )
01053     {
01054         CPPUNIT_ASSERT_EQUAL( default_val[0], values3[2 * i] );
01055         CPPUNIT_ASSERT_EQUAL( default_val[1], values3[2 * i + 1] );
01056     }
01057 
01058     // check that we cannot modify the values
01059     for( size_t i = 0; i < values3.size(); ++i )
01060         values[i] = i;
01061     if( ELEMENT == type )
01062         mesh->tag_set_element_data( tag, entities.size(), arrptr( entities ), arrptr( values3 ), err );
01063     else
01064         mesh->tag_set_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values3 ), err );
01065     if( OWNED != storage )
01066     {
01067         CPPUNIT_ASSERT( err );
01068         err.clear();
01069     }
01070     else
01071     {
01072         ASSERT_NO_ERROR( err );
01073     }
01074 
01075     // check that we did set the values as expected
01076     if( OWNED != storage )
01077     {
01078         std::vector< int > values4( values3.size() );
01079         if( ELEMENT == type )
01080             mesh->tag_get_element_data( tag, entities.size(), arrptr( entities ), arrptr( values4 ), err );
01081         else
01082             mesh->tag_get_vertex_data( tag, entities.size(), arrptr( entities ), arrptr( values4 ), err );
01083         ASSERT_NO_ERROR( err );
01084         ASSERT_STD_VECTORS_EQUAL( values3, values4 );
01085     }
01086 }
01087 
01088 void ArrayMeshTest::test_delete_tag()
01089 {
01090     MsqError err;
01091     ArrayMesh* mesh = zeroBased2D;
01092     TagHandle tag, tag1, tag2, tag3;
01093     tag1 = mesh->add_read_only_tag_data( "name1", Mesh::BOOL, 1, 0, 0, 0, err );
01094     ASSERT_NO_ERROR( err );
01095     tag2 = mesh->add_writable_tag_data( "name2", Mesh::BYTE, 5, 0, 0, 0, err );
01096     ASSERT_NO_ERROR( err );
01097     tag3 = mesh->tag_create( "name3", Mesh::HANDLE, 2, 0, err );
01098     ASSERT_NO_ERROR( err );
01099 
01100     tag = mesh->tag_get( "name2", err );
01101     ASSERT_NO_ERROR( err );
01102     CPPUNIT_ASSERT_EQUAL( tag2, tag );
01103 
01104     mesh->tag_delete( tag2, err );
01105     ASSERT_NO_ERROR( err );
01106     tag = mesh->tag_get( "name2", err );
01107     CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
01108     err.clear();
01109     tag = mesh->tag_get( "name1", err );
01110     ASSERT_NO_ERROR( err );
01111     CPPUNIT_ASSERT_EQUAL( tag1, tag );
01112     tag = mesh->tag_get( "name3", err );
01113     ASSERT_NO_ERROR( err );
01114     CPPUNIT_ASSERT_EQUAL( tag3, tag );
01115 
01116     mesh->tag_delete( tag1, err );
01117     ASSERT_NO_ERROR( err );
01118     tag = mesh->tag_get( "name2", err );
01119     CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
01120     err.clear();
01121     tag = mesh->tag_get( "name1", err );
01122     CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
01123     err.clear();
01124     tag = mesh->tag_get( "name3", err );
01125     ASSERT_NO_ERROR( err );
01126     CPPUNIT_ASSERT_EQUAL( tag3, tag );
01127 
01128     mesh->tag_delete( tag3, err );
01129     ASSERT_NO_ERROR( err );
01130     tag = mesh->tag_get( "name2", err );
01131     CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
01132     err.clear();
01133     tag = mesh->tag_get( "name1", err );
01134     CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
01135     err.clear();
01136     tag = mesh->tag_get( "name3", err );
01137     CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
01138     err.clear();
01139 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines