1 /* *****************************************************************
2     MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4     Copyright 2007 Sandia National Laboratories.  Developed at the
5     University of Wisconsin--Madison under SNL contract number
6     624796.  The U.S. Government and the University of Wisconsin
7     retain certain rights to 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     This library is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17     Lesser General Public License for more details.
18 
19     You should have received a copy of the GNU Lesser General Public License
20     (lgpl.txt) along with this library; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 
23     (2007) kraftche@cae.wisc.edu
24 
25   ***************************************************************** */
26 
27 
28 /** \file ArrayMeshTest.cpp
29  *  \brief
30  *  \author Jason Kraftcheck
31  */
32 
33 #include "Mesquite.hpp"
34 #include "ArrayMesh.hpp"
35 #include "MsqVertex.hpp"
36 #include "MsqError.hpp"
37 #include "UnitUtil.hpp"
38 
39 using namespace MBMesquite;
40 
41 class ArrayMeshTest : public CppUnit::TestFixture
42 {
43 private:
44   CPPUNIT_TEST_SUITE( ArrayMeshTest );
45 
46   CPPUNIT_TEST( test_get_geometric_dimension );
47   CPPUNIT_TEST( test_get_all_elements );
48   CPPUNIT_TEST( test_get_all_vertices );
49   CPPUNIT_TEST( test_get_all_vertices_one_based );
50   CPPUNIT_TEST( test_vertex_iterator );
51   CPPUNIT_TEST( test_vertex_iterator_one_based );
52   CPPUNIT_TEST( test_element_iterator );
53   CPPUNIT_TEST( test_vertices_get_fixed_flag );
54   CPPUNIT_TEST( test_vertices_get_coordinates );
55   CPPUNIT_TEST( test_vertices_get_coordinates_two_d );
56   CPPUNIT_TEST( test_vertices_get_coordinates_one_based );
57   CPPUNIT_TEST( test_vertex_set_coordinates );
58   CPPUNIT_TEST( test_vertex_set_coordinates_two_d );
59   CPPUNIT_TEST( test_vertex_set_coordinates_one_based );
60   CPPUNIT_TEST( test_vertex_set_byte );
61   CPPUNIT_TEST( test_vertices_set_byte );
62   CPPUNIT_TEST( test_vertices_get_attached_elements );
63   CPPUNIT_TEST( test_vertices_get_attached_elements_one_based );
64   CPPUNIT_TEST( test_elements_get_attached_vertices );
65   CPPUNIT_TEST( test_elements_get_topologies );
66 
67   CPPUNIT_TEST( test_vertices_get_attached_elements_mixed );
68   CPPUNIT_TEST( test_vertices_get_attached_elements_mixed_one_based );
69   CPPUNIT_TEST( test_elements_get_attached_vertices_mixed );
70   CPPUNIT_TEST( test_elements_get_attached_vertices_mixed_one_based );
71   CPPUNIT_TEST( test_elements_get_topologies_mixed );
72 
73   CPPUNIT_TEST( test_vertex_readonly_tag_data );
74   CPPUNIT_TEST( test_vertex_readonly_tag_data_one_based );
75   CPPUNIT_TEST( test_element_readonly_tag_data );
76   CPPUNIT_TEST( test_vertex_writable_tag_data );
77   CPPUNIT_TEST( test_vertex_writable_tag_data_one_based );
78   CPPUNIT_TEST( test_element_writable_tag_data );
79   CPPUNIT_TEST( test_vertex_owned_tag_data );
80   CPPUNIT_TEST( test_vertex_owned_tag_data_one_based );
81   CPPUNIT_TEST( test_element_owned_tag_data );
82   CPPUNIT_TEST( test_delete_tag );
83 
84   CPPUNIT_TEST_SUITE_END();
85 
86   ArrayMesh *zeroBased3D, *oneBased3D, *zeroBased2D, *oneBased2D;
87   ArrayMesh *mixedZeroBased, *mixedOneBased;
88   double *zeroBased3Dcoords, *oneBased3Dcoords, *zeroBased2Dcoords, *oneBased2Dcoords;
89   double *mixedZeroBasedCoords, *mixedOneBasedCoords;
90 
91 public:
92 
93   void setUp();
94   void tearDown();
95 
96   void test_get_geometric_dimension ();
97   void test_get_all_elements ();
98   void test_get_all_vertices ();
99   void test_get_all_vertices_one_based ();
100   void test_vertex_iterator ();
101   void test_vertex_iterator_one_based ();
102   void test_element_iterator ();
103   void test_vertices_get_fixed_flag ();
104   void test_vertices_get_coordinates ();
105   void test_vertices_get_coordinates_two_d ();
106   void test_vertices_get_coordinates_one_based ();
107   void test_vertex_set_coordinates ();
108   void test_vertex_set_coordinates_two_d ();
109   void test_vertex_set_coordinates_one_based ();
110   void test_vertex_set_byte ();
111   void test_vertices_set_byte ();
112   void test_vertices_get_attached_elements ();
113   void test_vertices_get_attached_elements_one_based ();
114   void test_elements_get_attached_vertices ();
115   void test_elements_get_topologies ();
116 
117   void test_vertices_get_attached_elements_mixed ();
118   void test_vertices_get_attached_elements_mixed_one_based ();
119   void test_elements_get_attached_vertices_mixed ();
120   void test_elements_get_attached_vertices_mixed_one_based ();
121   void test_elements_get_topologies_mixed ();
122 
123   enum TagEntType { VERTEX, ONE_BASED_VERTEX, ELEMENT };
124   enum TagStorage { READONLY, WRITABLE, OWNED };
125   void test_tag_data( TagEntType type, TagStorage storage );
test_readonly_tag_data(TagEntType type)126   void test_readonly_tag_data( TagEntType type ) { test_tag_data( type, READONLY ); }
test_writable_tag_data(TagEntType type)127   void test_writable_tag_data( TagEntType type ) { test_tag_data( type, WRITABLE ); }
test_owned_tag_data(TagEntType type)128   void test_owned_tag_data( TagEntType type ) { test_tag_data( type, OWNED ); }
129 
test_vertex_readonly_tag_data()130   void test_vertex_readonly_tag_data( )           { test_readonly_tag_data( VERTEX ); }
test_vertex_readonly_tag_data_one_based()131   void test_vertex_readonly_tag_data_one_based( ) { test_readonly_tag_data( ONE_BASED_VERTEX ); }
test_element_readonly_tag_data()132   void test_element_readonly_tag_data( )          { test_readonly_tag_data( ELEMENT ); }
test_vertex_writable_tag_data()133   void test_vertex_writable_tag_data( )           { test_writable_tag_data( VERTEX ); }
test_vertex_writable_tag_data_one_based()134   void test_vertex_writable_tag_data_one_based( ) { test_writable_tag_data( ONE_BASED_VERTEX ); }
test_element_writable_tag_data()135   void test_element_writable_tag_data( )          { test_writable_tag_data( ELEMENT ); }
test_vertex_owned_tag_data()136   void test_vertex_owned_tag_data( )              { test_owned_tag_data( VERTEX ); }
test_vertex_owned_tag_data_one_based()137   void test_vertex_owned_tag_data_one_based( )    { test_owned_tag_data( ONE_BASED_VERTEX ); }
test_element_owned_tag_data()138   void test_element_owned_tag_data( )             { test_owned_tag_data( ELEMENT ); }
139   void test_delete_tag( );
140 };
141 
142 
143 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ArrayMeshTest, "ArrayMeshTest");
144 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ArrayMeshTest, "Unit");
145 
146 
147 /* Mesh:
148 
149    0---------1----------2
150    |         |          |
151    |    0    |    1     |
152    |         |          |
153    |         |          |
154    3---------4----------5
155    |         |          |
156    Y    2    |    3     |
157    ^         |          |
158    |         |          |
159    6-->X-----7----------8
160 
161  Z = -2
162 
163 */
164 const double coords_2d[] = { 0, 2,
165                              1, 2,
166                              2, 2,
167                              0, 1,
168                              1, 1,
169                              2, 1,
170                              0, 0,
171                              1, 0,
172                              2, 0 };
173 const double coords_3d[] = { 0, 2, -2,
174                              1, 2, -2,
175                              2, 2, -2,
176                              0, 1, -2,
177                              1, 1, -2,
178                              2, 1, -2,
179                              0, 0, -2,
180                              1, 0, -2,
181                              2, 0, -2};
182 const unsigned long conn_zero_based[] = { 3, 4, 1, 0,
183                                           4, 5, 2, 1,
184                                           6, 7, 4, 3,
185                                           7, 8, 5, 4 };
186 const unsigned long conn_one_based[] = {  4, 5, 2, 1,
187                                           5, 6, 3, 2,
188                                           7, 8, 5, 4,
189                                           8, 9, 6, 5 };
190 
191 const int fixed[] = { 1, 1, 1,
192                       1, 0, 1,
193                       1, 1, 1 };
194 
195 /* Mixed mesh
196  *
197  *   0-------1-------2-------3
198  *   |       | \  2  |       |
199  *   |   0   |   \   |   3   |
200  *   |       | 1   \ |       |
201  *   7-------6-------5-------4
202  */
203 const double mixed_coords[] = { 0.0, 1.0, 0.0,
204                                 1.0, 1.0, 0.0,
205                                 2.0, 1.0, 0.0,
206                                 3.0, 1.0, 0.0,
207                                 3.0, 0.0, 0.0,
208                                 2.0, 0.0, 0.0,
209                                 1.0, 0.0, 0.0,
210                                 0.0, 0.0, 0.0 };
211 const unsigned long mixed_conn_zero[] = { 7, 6, 1, 0,
212                                           6, 5, 1,
213                                           2, 1, 5,
214                                           5, 4, 3, 2 };
215 const unsigned long mixed_conn_one[]  = { 8, 7, 2, 1,
216                                           7, 6, 2,
217                                           3, 2, 6,
218                                           6, 5, 4, 3 };
219 const EntityTopology mixed_types[] = { QUADRILATERAL,
220                                        TRIANGLE,
221                                        TRIANGLE,
222                                        QUADRILATERAL };
223 const unsigned long conn_offsets_zero[] = { 0, 4, 7, 10, 14 };
224 
225 
setUp()226 void ArrayMeshTest::setUp()
227 {
228      zeroBased3Dcoords = new double[27];
229       oneBased3Dcoords = new double[27];
230      zeroBased2Dcoords = new double[18];
231       oneBased2Dcoords = new double[18];
232   mixedZeroBasedCoords = new double[24];
233    mixedOneBasedCoords = new double[24];
234   memcpy(    zeroBased3Dcoords, coords_3d,    27*sizeof(double) );
235   memcpy(     oneBased3Dcoords, coords_3d,    27*sizeof(double) );
236   memcpy(    zeroBased2Dcoords, coords_2d,    18*sizeof(double) );
237   memcpy(     oneBased2Dcoords, coords_2d,    18*sizeof(double) );
238   memcpy( mixedZeroBasedCoords, mixed_coords, 24*sizeof(double) );
239   memcpy(  mixedOneBasedCoords, mixed_coords, 24*sizeof(double) );
240      zeroBased3D = new ArrayMesh( 3, 9,    zeroBased3Dcoords, fixed, 4, QUADRILATERAL, conn_zero_based,                    false );
241       oneBased3D = new ArrayMesh( 3, 9,     oneBased3Dcoords, fixed, 4, QUADRILATERAL, conn_one_based,                     true  );
242      zeroBased2D = new ArrayMesh( 2, 9,    zeroBased2Dcoords, fixed, 4, QUADRILATERAL, conn_zero_based,                    false );
243       oneBased2D = new ArrayMesh( 2, 9,     oneBased2Dcoords, fixed, 4, QUADRILATERAL, conn_one_based,                     true  );
244   mixedZeroBased = new ArrayMesh( 3, 8, mixedZeroBasedCoords, fixed, 4, mixed_types,   mixed_conn_zero, conn_offsets_zero, false );
245    mixedOneBased = new ArrayMesh( 3, 8,  mixedOneBasedCoords, fixed, 4, mixed_types,   mixed_conn_one,  NULL,              true  );
246 }
247 
tearDown()248 void ArrayMeshTest::tearDown()
249 {
250   delete    zeroBased3D;
251   delete     oneBased3D;
252   delete    zeroBased2D;
253   delete     oneBased2D;
254   delete mixedZeroBased;
255   delete  mixedOneBased;
256   delete []    zeroBased3Dcoords;
257   delete []     oneBased3Dcoords;
258   delete []    zeroBased2Dcoords;
259   delete []     oneBased2Dcoords;
260   delete [] mixedZeroBasedCoords;
261   delete []  mixedOneBasedCoords;
262 }
263 
test_get_geometric_dimension()264 void ArrayMeshTest::test_get_geometric_dimension()
265 {
266   MsqPrintError err(std::cerr);
267   CPPUNIT_ASSERT_EQUAL( 2, zeroBased2D->get_geometric_dimension( err ) );
268   CPPUNIT_ASSERT_EQUAL( 2,  oneBased2D->get_geometric_dimension( err ) );
269   CPPUNIT_ASSERT_EQUAL( 3, zeroBased3D->get_geometric_dimension( err ) );
270   CPPUNIT_ASSERT_EQUAL( 3,  oneBased3D->get_geometric_dimension( err ) );
271 }
272 
test_get_all_elements()273 void ArrayMeshTest::test_get_all_elements()
274 {
275   MsqPrintError err(std::cerr);
276   std::vector<Mesh::ElementHandle> list;
277   zeroBased3D->get_all_elements( list, err );
278   CPPUNIT_ASSERT( !err );
279   CPPUNIT_ASSERT_EQUAL( (size_t)4, list.size() );
280   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)list[0] );
281   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)list[1] );
282   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)list[2] );
283   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)list[3] );
284 }
285 
test_get_all_vertices()286 void ArrayMeshTest::test_get_all_vertices()
287 {
288   MsqPrintError err(std::cerr);
289   std::vector<Mesh::VertexHandle> list;
290   zeroBased3D->get_all_vertices( list, err );
291   CPPUNIT_ASSERT( !err );
292   CPPUNIT_ASSERT_EQUAL( (size_t)9, list.size() );
293   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)list[0] );
294   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)list[1] );
295   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)list[2] );
296   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)list[3] );
297   CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)list[4] );
298   CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)list[5] );
299   CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)list[6] );
300   CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)list[7] );
301   CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)list[8] );
302 }
303 
test_get_all_vertices_one_based()304 void ArrayMeshTest::test_get_all_vertices_one_based()
305 {
306   MsqPrintError err(std::cerr);
307   std::vector<Mesh::VertexHandle> list;
308   oneBased3D->get_all_vertices( list, err );
309   CPPUNIT_ASSERT( !err );
310   CPPUNIT_ASSERT_EQUAL( (size_t)9, list.size() );
311   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)list[0] );
312   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)list[1] );
313   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)list[2] );
314   CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)list[3] );
315   CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)list[4] );
316   CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)list[5] );
317   CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)list[6] );
318   CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)list[7] );
319   CPPUNIT_ASSERT_EQUAL( (size_t)9, (size_t)list[8] );
320 }
321 
test_vertex_iterator()322 void ArrayMeshTest::test_vertex_iterator()
323 {
324   MsqPrintError err(std::cerr);
325   VertexIterator* iter = zeroBased3D->vertex_iterator( err );
326   CPPUNIT_ASSERT( !err );
327   std::auto_ptr<VertexIterator> deleter(iter);
328 
329   CPPUNIT_ASSERT(!iter->is_at_end());
330   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)iter->operator*() );
331   iter->operator++();
332   CPPUNIT_ASSERT(!iter->is_at_end());
333   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)iter->operator*() );
334   iter->operator++();
335   CPPUNIT_ASSERT(!iter->is_at_end());
336   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)iter->operator*() );
337   iter->operator++();
338   CPPUNIT_ASSERT(!iter->is_at_end());
339   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)iter->operator*() );
340   iter->operator++();
341   CPPUNIT_ASSERT(!iter->is_at_end());
342   CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)iter->operator*() );
343   iter->operator++();
344   CPPUNIT_ASSERT(!iter->is_at_end());
345   CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)iter->operator*() );
346    iter->operator++();
347   CPPUNIT_ASSERT(!iter->is_at_end());
348   CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)iter->operator*() );
349   iter->operator++();
350   CPPUNIT_ASSERT(!iter->is_at_end());
351   CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)iter->operator*() );
352   iter->operator++();
353   CPPUNIT_ASSERT(iter->is_at_end());
354   CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)iter->operator*() );
355 
356   iter->restart();
357   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)iter->operator*() );
358 }
359 
test_vertex_iterator_one_based()360 void ArrayMeshTest::test_vertex_iterator_one_based()
361 {
362   MsqPrintError err(std::cerr);
363   VertexIterator* iter = oneBased3D->vertex_iterator( err );
364   CPPUNIT_ASSERT( !err );
365   std::auto_ptr<VertexIterator> deleter(iter);
366 
367   CPPUNIT_ASSERT(!iter->is_at_end());
368   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)iter->operator*() );
369   iter->operator++();
370   CPPUNIT_ASSERT(!iter->is_at_end());
371   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)iter->operator*() );
372   iter->operator++();
373   CPPUNIT_ASSERT(!iter->is_at_end());
374   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)iter->operator*() );
375   iter->operator++();
376   CPPUNIT_ASSERT(!iter->is_at_end());
377   CPPUNIT_ASSERT_EQUAL( (size_t)4, (size_t)iter->operator*() );
378   iter->operator++();
379   CPPUNIT_ASSERT(!iter->is_at_end());
380   CPPUNIT_ASSERT_EQUAL( (size_t)5, (size_t)iter->operator*() );
381   iter->operator++();
382   CPPUNIT_ASSERT(!iter->is_at_end());
383   CPPUNIT_ASSERT_EQUAL( (size_t)6, (size_t)iter->operator*() );
384    iter->operator++();
385   CPPUNIT_ASSERT(!iter->is_at_end());
386   CPPUNIT_ASSERT_EQUAL( (size_t)7, (size_t)iter->operator*() );
387   iter->operator++();
388   CPPUNIT_ASSERT(!iter->is_at_end());
389   CPPUNIT_ASSERT_EQUAL( (size_t)8, (size_t)iter->operator*() );
390   iter->operator++();
391   CPPUNIT_ASSERT(iter->is_at_end());
392   CPPUNIT_ASSERT_EQUAL( (size_t)9, (size_t)iter->operator*() );
393 
394   iter->restart();
395   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)iter->operator*() );
396 }
397 
test_element_iterator()398 void ArrayMeshTest::test_element_iterator()
399 {
400   MsqPrintError err(std::cerr);
401   ElementIterator* iter = zeroBased3D->element_iterator( err );
402   CPPUNIT_ASSERT( !err );
403   std::auto_ptr<ElementIterator> deleter(iter);
404 
405   CPPUNIT_ASSERT(!iter->is_at_end());
406   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)iter->operator*() );
407   iter->operator++();
408   CPPUNIT_ASSERT(!iter->is_at_end());
409   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)iter->operator*() );
410   iter->operator++();
411   CPPUNIT_ASSERT(!iter->is_at_end());
412   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)iter->operator*() );
413   iter->operator++();
414   CPPUNIT_ASSERT(iter->is_at_end());
415   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)iter->operator*() );
416 
417   iter->restart();
418   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)iter->operator*() );
419 }
420 
test_vertices_get_fixed_flag()421 void ArrayMeshTest::test_vertices_get_fixed_flag()
422 {
423   MsqPrintError err(std::cerr);
424   const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 4 };
425   std::vector<bool> flags;
426   zeroBased3D->vertices_get_fixed_flag( (const Mesh::VertexHandle*)verts,
427                                         flags, 10, err );
428   CPPUNIT_ASSERT(!err);
429   CPPUNIT_ASSERT_EQUAL( (size_t)10, flags.size() );
430   CPPUNIT_ASSERT_EQUAL(  true, (bool)flags[0] );
431   CPPUNIT_ASSERT_EQUAL(  true, (bool)flags[1] );
432   CPPUNIT_ASSERT_EQUAL(  true, (bool)flags[2] );
433   CPPUNIT_ASSERT_EQUAL(  true, (bool)flags[3] );
434   CPPUNIT_ASSERT_EQUAL( false, (bool)flags[4] );
435   CPPUNIT_ASSERT_EQUAL(  true, (bool)flags[5] );
436   CPPUNIT_ASSERT_EQUAL(  true, (bool)flags[6] );
437   CPPUNIT_ASSERT_EQUAL(  true, (bool)flags[7] );
438   CPPUNIT_ASSERT_EQUAL(  true, (bool)flags[8] );
439   CPPUNIT_ASSERT_EQUAL( false, (bool)flags[9] );
440 }
441 
test_vertices_get_coordinates()442 void ArrayMeshTest::test_vertices_get_coordinates()
443 {
444   MsqPrintError err(std::cerr);
445   const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 4 };
446   MsqVertex coords[10];
447   zeroBased3D->vertices_get_coordinates( (const Mesh::VertexHandle*)verts,
448                                           coords, 10, err );
449   CPPUNIT_ASSERT(!err);
450   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+ 0), coords[0], DBL_EPSILON );
451   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+ 3), coords[1], DBL_EPSILON );
452   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+ 6), coords[2], DBL_EPSILON );
453   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+ 9), coords[3], DBL_EPSILON );
454   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+12), coords[4], DBL_EPSILON );
455   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+15), coords[5], DBL_EPSILON );
456   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+18), coords[6], DBL_EPSILON );
457   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+21), coords[7], DBL_EPSILON );
458   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+24), coords[8], DBL_EPSILON );
459   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+12), coords[4], DBL_EPSILON );
460 }
461 
test_vertices_get_coordinates_two_d()462 void ArrayMeshTest::test_vertices_get_coordinates_two_d()
463 {
464   MsqPrintError err(std::cerr);
465   const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 4 };
466   MsqVertex coords[10];
467   zeroBased2D->vertices_get_coordinates( (const Mesh::VertexHandle*)verts,
468                                           coords, 10, err );
469   CPPUNIT_ASSERT(!err);
470   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_2d[ 0],coords_2d[ 1],0), coords[0], DBL_EPSILON );
471   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_2d[ 2],coords_2d[ 3],0), coords[1], DBL_EPSILON );
472   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_2d[ 4],coords_2d[ 5],0), coords[2], DBL_EPSILON );
473   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_2d[ 6],coords_2d[ 7],0), coords[3], DBL_EPSILON );
474   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_2d[ 8],coords_2d[ 9],0), coords[4], DBL_EPSILON );
475   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_2d[10],coords_2d[11],0), coords[5], DBL_EPSILON );
476   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_2d[12],coords_2d[13],0), coords[6], DBL_EPSILON );
477   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_2d[14],coords_2d[15],0), coords[7], DBL_EPSILON );
478   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_2d[16],coords_2d[17],0), coords[8], DBL_EPSILON );
479   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_2d[ 8],coords_2d[ 9],0), coords[9], DBL_EPSILON );
480 }
481 
test_vertices_get_coordinates_one_based()482 void ArrayMeshTest::test_vertices_get_coordinates_one_based()
483 {
484   MsqPrintError err(std::cerr);
485   const size_t verts[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 5 };
486   MsqVertex coords[10];
487   oneBased3D->vertices_get_coordinates( (const Mesh::VertexHandle*)verts,
488                                           coords, 10, err );
489   CPPUNIT_ASSERT(!err);
490   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+ 0), coords[0], DBL_EPSILON );
491   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+ 3), coords[1], DBL_EPSILON );
492   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+ 6), coords[2], DBL_EPSILON );
493   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+ 9), coords[3], DBL_EPSILON );
494   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+12), coords[4], DBL_EPSILON );
495   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+15), coords[5], DBL_EPSILON );
496   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+18), coords[6], DBL_EPSILON );
497   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+21), coords[7], DBL_EPSILON );
498   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+24), coords[8], DBL_EPSILON );
499   CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D(coords_3d+12), coords[4], DBL_EPSILON );
500 }
501 
test_vertex_set_coordinates()502 void ArrayMeshTest::test_vertex_set_coordinates()
503 {
504   MsqPrintError err(std::cerr);
505   Mesh::VertexHandle vert = (Mesh::VertexHandle)4;
506   Vector3D new_pos( 5, 5, 5 );
507   MsqVertex pos;
508   zeroBased3D->vertex_set_coordinates( vert, new_pos, err );
509   CPPUNIT_ASSERT(!err);
510   zeroBased3D->vertices_get_coordinates( &vert, &pos, 1, err );
511   CPPUNIT_ASSERT(!err);
512   CPPUNIT_ASSERT_VECTORS_EQUAL( new_pos, pos, DBL_EPSILON );
513 }
514 
test_vertex_set_coordinates_two_d()515 void ArrayMeshTest::test_vertex_set_coordinates_two_d()
516 {
517   MsqPrintError err(std::cerr);
518   Mesh::VertexHandle vert = (Mesh::VertexHandle)4;
519   Vector3D new_pos( 5, 5, 5 );
520   MsqVertex pos;
521   zeroBased2D->vertex_set_coordinates( vert, new_pos, err );
522   CPPUNIT_ASSERT(!err);
523   zeroBased2D->vertices_get_coordinates( &vert, &pos, 1, err );
524   CPPUNIT_ASSERT(!err);
525   new_pos[2] = 0;
526   CPPUNIT_ASSERT_VECTORS_EQUAL( new_pos, pos, DBL_EPSILON );
527 }
528 
test_vertex_set_coordinates_one_based()529 void ArrayMeshTest::test_vertex_set_coordinates_one_based()
530 {
531   MsqPrintError err(std::cerr);
532   Mesh::VertexHandle vert = (Mesh::VertexHandle)5;
533   Vector3D new_pos( 5, 5, 5 );
534   MsqVertex pos;
535   oneBased3D->vertex_set_coordinates( vert, new_pos, err );
536   CPPUNIT_ASSERT(!err);
537   oneBased3D->vertices_get_coordinates( &vert, &pos, 1, err );
538   CPPUNIT_ASSERT(!err);
539   CPPUNIT_ASSERT_VECTORS_EQUAL( new_pos, pos, DBL_EPSILON );
540 }
541 
test_vertex_set_byte()542 void ArrayMeshTest::test_vertex_set_byte()
543 {
544   MsqPrintError err(std::cerr);
545   unsigned char byte = 'A';
546   Mesh::VertexHandle vert = (Mesh::VertexHandle)5;
547   zeroBased3D->vertex_set_byte( vert, byte, err );
548   CPPUNIT_ASSERT(!err);
549   byte = '0';
550   zeroBased3D->vertex_get_byte( vert, &byte, err );
551   CPPUNIT_ASSERT(!err);
552   CPPUNIT_ASSERT_EQUAL( (unsigned char)'A', byte );
553 }
554 
test_vertices_set_byte()555 void ArrayMeshTest::test_vertices_set_byte()
556 {
557   MsqPrintError err(std::cerr);
558   const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 4 };
559   const unsigned char bytes[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'E' };
560   unsigned char b[10];
561   memset( b, 0, 10 );
562   zeroBased3D->vertices_set_byte( (const Mesh::VertexHandle*)verts, bytes, 10, err );
563   CPPUNIT_ASSERT(!err);
564   zeroBased3D->vertices_get_byte( (const Mesh::VertexHandle*)verts, b, 10, err );
565   CPPUNIT_ASSERT(!err);
566   CPPUNIT_ASSERT_EQUAL( bytes[0], b[0] );
567   CPPUNIT_ASSERT_EQUAL( bytes[1], b[1] );
568   CPPUNIT_ASSERT_EQUAL( bytes[2], b[2] );
569   CPPUNIT_ASSERT_EQUAL( bytes[3], b[3] );
570   CPPUNIT_ASSERT_EQUAL( bytes[4], b[4] );
571   CPPUNIT_ASSERT_EQUAL( bytes[5], b[5] );
572   CPPUNIT_ASSERT_EQUAL( bytes[6], b[6] );
573   CPPUNIT_ASSERT_EQUAL( bytes[7], b[7] );
574   CPPUNIT_ASSERT_EQUAL( bytes[8], b[8] );
575 }
576 
577 
test_vertices_get_attached_elements()578 void ArrayMeshTest::test_vertices_get_attached_elements()
579 {
580   MsqPrintError err(std::cerr);
581   const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
582   std::vector<Mesh::ElementHandle> elems;
583   std::vector<size_t> offsets;
584   zeroBased3D->vertices_get_attached_elements( (const Mesh::VertexHandle*)verts,
585                                                9, elems, offsets, err );
586   CPPUNIT_ASSERT(!err);
587 
588   CPPUNIT_ASSERT_EQUAL( (size_t)16, elems.size() );
589   CPPUNIT_ASSERT( offsets.size() == 9 || offsets.size() == 10 );
590   if (offsets.size() == 10)
591     CPPUNIT_ASSERT_EQUAL( size_t(16), offsets[9] );
592 
593     // vert 0
594   CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
595   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[ 0] );
596     // vert 1
597   CPPUNIT_ASSERT_EQUAL( (size_t)1, offsets[1] );
598   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[ 1] );
599   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[ 2] );
600     // vert 2
601   CPPUNIT_ASSERT_EQUAL( (size_t)3, offsets[2] );
602   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[ 3] );
603     // vert 3
604   CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[3] );
605   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[ 4] );
606   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[ 5] );
607     // vert 4
608   CPPUNIT_ASSERT_EQUAL( (size_t)6, offsets[4] );
609   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[ 6] );
610   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[ 7] );
611   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[ 8] );
612   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[ 9] );
613     // vert 5
614   CPPUNIT_ASSERT_EQUAL( (size_t)10, offsets[5] );
615   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[10] );
616   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[11] );
617     // vert 6
618   CPPUNIT_ASSERT_EQUAL( (size_t)12, offsets[6] );
619   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[12] );
620     // vert 7
621   CPPUNIT_ASSERT_EQUAL( (size_t)13, offsets[7] );
622   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[13] );
623   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[14] );
624     // vert 8
625   CPPUNIT_ASSERT_EQUAL( (size_t)15, offsets[8] );
626   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[15] );
627 }
628 
test_vertices_get_attached_elements_one_based()629 void ArrayMeshTest::test_vertices_get_attached_elements_one_based()
630 {
631   MsqPrintError err(std::cerr);
632   const size_t verts[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
633   std::vector<Mesh::ElementHandle> elems;
634   std::vector<size_t> offsets;
635   oneBased3D->vertices_get_attached_elements( (const Mesh::VertexHandle*)verts,
636                                                9, elems, offsets, err );
637   CPPUNIT_ASSERT(!err);
638 
639   CPPUNIT_ASSERT_EQUAL( (size_t)16, elems.size() );
640   CPPUNIT_ASSERT( offsets.size() == 9 || offsets.size() == 10 );
641   if (offsets.size() == 10)
642     CPPUNIT_ASSERT_EQUAL( size_t(16), offsets[9] );
643 
644     // vert 0
645   CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
646   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[ 0] );
647     // vert 1
648   CPPUNIT_ASSERT_EQUAL( (size_t)1, offsets[1] );
649   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[ 1] );
650   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[ 2] );
651     // vert 2
652   CPPUNIT_ASSERT_EQUAL( (size_t)3, offsets[2] );
653   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[ 3] );
654     // vert 3
655   CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[3] );
656   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[ 4] );
657   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[ 5] );
658     // vert 4
659   CPPUNIT_ASSERT_EQUAL( (size_t)6, offsets[4] );
660   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[ 6] );
661   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[ 7] );
662   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[ 8] );
663   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[ 9] );
664     // vert 5
665   CPPUNIT_ASSERT_EQUAL( (size_t)10, offsets[5] );
666   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[10] );
667   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[11] );
668     // vert 6
669   CPPUNIT_ASSERT_EQUAL( (size_t)12, offsets[6] );
670   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[12] );
671     // vert 7
672   CPPUNIT_ASSERT_EQUAL( (size_t)13, offsets[7] );
673   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[13] );
674   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[14] );
675     // vert 8
676   CPPUNIT_ASSERT_EQUAL( (size_t)15, offsets[8] );
677   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[15] );
678 }
679 
test_elements_get_attached_vertices()680 void ArrayMeshTest::test_elements_get_attached_vertices()
681 {
682   MsqPrintError err(std::cerr);
683   const size_t elems[] = { 3, 2, 1, 0 };
684   std::vector<Mesh::VertexHandle> verts;
685   std::vector<size_t> offsets;
686   zeroBased3D->elements_get_attached_vertices( (const Mesh::ElementHandle*)elems,
687                                                4, verts, offsets, err );
688   CPPUNIT_ASSERT(!err);
689   CPPUNIT_ASSERT_EQUAL( (size_t)16,  verts.size() );
690   CPPUNIT_ASSERT( offsets.size() == 4 || offsets.size() == 5 );
691   if (offsets.size() == 5)
692     CPPUNIT_ASSERT_EQUAL( (size_t)16, offsets[4] );
693 
694     // elem 3
695   CPPUNIT_ASSERT_EQUAL( (size_t) 0, offsets[0] );
696   CPPUNIT_ASSERT_EQUAL( (size_t) 7, (size_t)verts[ 0] );
697   CPPUNIT_ASSERT_EQUAL( (size_t) 8, (size_t)verts[ 1] );
698   CPPUNIT_ASSERT_EQUAL( (size_t) 5, (size_t)verts[ 2] );
699   CPPUNIT_ASSERT_EQUAL( (size_t) 4, (size_t)verts[ 3] );
700 
701     // elem 2
702   CPPUNIT_ASSERT_EQUAL( (size_t) 4, offsets[1] );
703   CPPUNIT_ASSERT_EQUAL( (size_t) 6, (size_t)verts[ 4] );
704   CPPUNIT_ASSERT_EQUAL( (size_t) 7, (size_t)verts[ 5] );
705   CPPUNIT_ASSERT_EQUAL( (size_t) 4, (size_t)verts[ 6] );
706   CPPUNIT_ASSERT_EQUAL( (size_t) 3, (size_t)verts[ 7] );
707 
708     // elem 1
709   CPPUNIT_ASSERT_EQUAL( (size_t) 8, offsets[2] );
710   CPPUNIT_ASSERT_EQUAL( (size_t) 4, (size_t)verts[ 8] );
711   CPPUNIT_ASSERT_EQUAL( (size_t) 5, (size_t)verts[ 9] );
712   CPPUNIT_ASSERT_EQUAL( (size_t) 2, (size_t)verts[10] );
713   CPPUNIT_ASSERT_EQUAL( (size_t) 1, (size_t)verts[11] );
714 
715     // elem 0
716   CPPUNIT_ASSERT_EQUAL( (size_t)12, offsets[3] );
717   CPPUNIT_ASSERT_EQUAL( (size_t) 3, (size_t)verts[12] );
718   CPPUNIT_ASSERT_EQUAL( (size_t) 4, (size_t)verts[13] );
719   CPPUNIT_ASSERT_EQUAL( (size_t) 1, (size_t)verts[14] );
720   CPPUNIT_ASSERT_EQUAL( (size_t) 0, (size_t)verts[15] );
721 }
722 
723 
test_elements_get_topologies()724 void ArrayMeshTest::test_elements_get_topologies()
725 {
726   MsqPrintError err(std::cerr);
727   const size_t elems[] = { 3, 2, 1, 0, 1, 2, 3, 0 };
728   const size_t num_elem = sizeof(elems)/sizeof(elems[0]);
729   EntityTopology topo[num_elem];
730   memset( topo, 0, sizeof(topo) );
731   zeroBased3D->elements_get_topologies( (const Mesh::ElementHandle*)elems,
732                                          topo, num_elem, err );
733   CPPUNIT_ASSERT(!err);
734   for (size_t i = 0; i < num_elem; ++i)
735     CPPUNIT_ASSERT_EQUAL( (int)QUADRILATERAL, (int)topo[i] );
736 }
737 
738 
test_vertices_get_attached_elements_mixed()739 void ArrayMeshTest::test_vertices_get_attached_elements_mixed()
740 {
741   MsqPrintError err(std::cerr);
742   const size_t verts[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
743   std::vector<Mesh::ElementHandle> elems;
744   std::vector<size_t> offsets;
745   mixedZeroBased->vertices_get_attached_elements( (const Mesh::VertexHandle*)verts,
746                                                8, elems, offsets, err );
747   CPPUNIT_ASSERT(!err);
748 
749   CPPUNIT_ASSERT_EQUAL( (size_t)14, elems.size() );
750   CPPUNIT_ASSERT( offsets.size() == 8 || offsets.size() == 9 );
751   if (offsets.size() == 9)
752     CPPUNIT_ASSERT_EQUAL( elems.size(), offsets[8] );
753 
754     // vert 0
755   CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
756   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[ 0] );
757     // vert 1
758   CPPUNIT_ASSERT_EQUAL( (size_t)1, offsets[1] );
759   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[ 1] );
760   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[ 2] );
761   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[ 3] );
762     // vert 2
763   CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[2] );
764   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[ 4] );
765   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[ 5] );
766     // vert 3
767   CPPUNIT_ASSERT_EQUAL( (size_t)6, offsets[3] );
768   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[ 6] );
769     // vert 4
770   CPPUNIT_ASSERT_EQUAL( (size_t)7, offsets[4] );
771   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[ 7] );
772     // vert 5
773   CPPUNIT_ASSERT_EQUAL( (size_t)8, offsets[5] );
774   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[8] );
775   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[9] );
776   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[10] );
777     // vert 6
778   CPPUNIT_ASSERT_EQUAL( (size_t)11, offsets[6] );
779   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[11] );
780   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[12] );
781     // vert 7
782   CPPUNIT_ASSERT_EQUAL( (size_t)13, offsets[7] );
783   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[13] );
784 }
785 
test_vertices_get_attached_elements_mixed_one_based()786 void ArrayMeshTest::test_vertices_get_attached_elements_mixed_one_based()
787 {
788   MsqPrintError err(std::cerr);
789   const size_t verts[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
790   std::vector<Mesh::ElementHandle> elems;
791   std::vector<size_t> offsets;
792   mixedOneBased->vertices_get_attached_elements( (const Mesh::VertexHandle*)verts,
793                                                8, elems, offsets, err );
794   CPPUNIT_ASSERT(!err);
795 
796   CPPUNIT_ASSERT_EQUAL( (size_t)14, elems.size() );
797   CPPUNIT_ASSERT( offsets.size() == 8 || offsets.size() == 9 );
798   if (offsets.size() == 9)
799     CPPUNIT_ASSERT_EQUAL( elems.size(), offsets[8] );
800 
801     // vert 0
802   CPPUNIT_ASSERT_EQUAL( (size_t)0, offsets[0] );
803   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[ 0] );
804     // vert 1
805   CPPUNIT_ASSERT_EQUAL( (size_t)1, offsets[1] );
806   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[ 1] );
807   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[ 2] );
808   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[ 3] );
809     // vert 2
810   CPPUNIT_ASSERT_EQUAL( (size_t)4, offsets[2] );
811   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[ 4] );
812   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[ 5] );
813     // vert 3
814   CPPUNIT_ASSERT_EQUAL( (size_t)6, offsets[3] );
815   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[ 6] );
816     // vert 4
817   CPPUNIT_ASSERT_EQUAL( (size_t)7, offsets[4] );
818   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[ 7] );
819     // vert 5
820   CPPUNIT_ASSERT_EQUAL( (size_t)8, offsets[5] );
821   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[8] );
822   CPPUNIT_ASSERT_EQUAL( (size_t)2, (size_t)elems[9] );
823   CPPUNIT_ASSERT_EQUAL( (size_t)3, (size_t)elems[10] );
824     // vert 6
825   CPPUNIT_ASSERT_EQUAL( (size_t)11, offsets[6] );
826   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[11] );
827   CPPUNIT_ASSERT_EQUAL( (size_t)1, (size_t)elems[12] );
828     // vert 7
829   CPPUNIT_ASSERT_EQUAL( (size_t)13, offsets[7] );
830   CPPUNIT_ASSERT_EQUAL( (size_t)0, (size_t)elems[13] );
831 }
832 
test_elements_get_attached_vertices_mixed()833 void ArrayMeshTest::test_elements_get_attached_vertices_mixed()
834 {
835   MsqPrintError err(std::cerr);
836   const size_t elems[] = { 3, 2, 1, 0 };
837   std::vector<Mesh::VertexHandle> verts;
838   std::vector<size_t> offsets;
839   mixedZeroBased->elements_get_attached_vertices( (const Mesh::ElementHandle*)elems,
840                                                4, verts, offsets, err );
841   CPPUNIT_ASSERT(!err);
842   CPPUNIT_ASSERT_EQUAL( (size_t)14,  verts.size() );
843   CPPUNIT_ASSERT( offsets.size() == 4 || offsets.size() == 5 );
844   if (offsets.size() == 5)
845     CPPUNIT_ASSERT_EQUAL( verts.size(), offsets[4] );
846 
847     // elem 3
848   CPPUNIT_ASSERT_EQUAL( (size_t) 0, offsets[0] );
849   CPPUNIT_ASSERT_EQUAL( (size_t) 5, (size_t)verts[ 0] );
850   CPPUNIT_ASSERT_EQUAL( (size_t) 4, (size_t)verts[ 1] );
851   CPPUNIT_ASSERT_EQUAL( (size_t) 3, (size_t)verts[ 2] );
852   CPPUNIT_ASSERT_EQUAL( (size_t) 2, (size_t)verts[ 3] );
853 
854     // elem 2
855   CPPUNIT_ASSERT_EQUAL( (size_t) 4, offsets[1] );
856   CPPUNIT_ASSERT_EQUAL( (size_t) 2, (size_t)verts[ 4] );
857   CPPUNIT_ASSERT_EQUAL( (size_t) 1, (size_t)verts[ 5] );
858   CPPUNIT_ASSERT_EQUAL( (size_t) 5, (size_t)verts[ 6] );
859 
860     // elem 1
861   CPPUNIT_ASSERT_EQUAL( (size_t) 7, offsets[2] );
862   CPPUNIT_ASSERT_EQUAL( (size_t) 6, (size_t)verts[ 7] );
863   CPPUNIT_ASSERT_EQUAL( (size_t) 5, (size_t)verts[ 8] );
864   CPPUNIT_ASSERT_EQUAL( (size_t) 1, (size_t)verts[ 9] );
865 
866     // elem 0
867   CPPUNIT_ASSERT_EQUAL( (size_t)10, offsets[3] );
868   CPPUNIT_ASSERT_EQUAL( (size_t) 7, (size_t)verts[10] );
869   CPPUNIT_ASSERT_EQUAL( (size_t) 6, (size_t)verts[11] );
870   CPPUNIT_ASSERT_EQUAL( (size_t) 1, (size_t)verts[12] );
871   CPPUNIT_ASSERT_EQUAL( (size_t) 0, (size_t)verts[13] );
872 }
873 
test_elements_get_attached_vertices_mixed_one_based()874 void ArrayMeshTest::test_elements_get_attached_vertices_mixed_one_based()
875 {
876   MsqPrintError err(std::cerr);
877   const size_t elems[] = { 3, 2, 1, 0 };
878   std::vector<Mesh::VertexHandle> verts;
879   std::vector<size_t> offsets;
880   mixedOneBased->elements_get_attached_vertices( (const Mesh::ElementHandle*)elems,
881                                                4, verts, offsets, err );
882   CPPUNIT_ASSERT(!err);
883   CPPUNIT_ASSERT_EQUAL( (size_t)14,  verts.size() );
884   CPPUNIT_ASSERT( offsets.size() == 4 || offsets.size() == 5 );
885   if (offsets.size() == 5)
886     CPPUNIT_ASSERT_EQUAL( verts.size(), offsets[4] );
887 
888     // elem 3
889   CPPUNIT_ASSERT_EQUAL( (size_t) 0, offsets[0] );
890   CPPUNIT_ASSERT_EQUAL( (size_t) 6, (size_t)verts[ 0] );
891   CPPUNIT_ASSERT_EQUAL( (size_t) 5, (size_t)verts[ 1] );
892   CPPUNIT_ASSERT_EQUAL( (size_t) 4, (size_t)verts[ 2] );
893   CPPUNIT_ASSERT_EQUAL( (size_t) 3, (size_t)verts[ 3] );
894 
895     // elem 2
896   CPPUNIT_ASSERT_EQUAL( (size_t) 4, offsets[1] );
897   CPPUNIT_ASSERT_EQUAL( (size_t) 3, (size_t)verts[ 4] );
898   CPPUNIT_ASSERT_EQUAL( (size_t) 2, (size_t)verts[ 5] );
899   CPPUNIT_ASSERT_EQUAL( (size_t) 6, (size_t)verts[ 6] );
900 
901     // elem 1
902   CPPUNIT_ASSERT_EQUAL( (size_t) 7, offsets[2] );
903   CPPUNIT_ASSERT_EQUAL( (size_t) 7, (size_t)verts[ 7] );
904   CPPUNIT_ASSERT_EQUAL( (size_t) 6, (size_t)verts[ 8] );
905   CPPUNIT_ASSERT_EQUAL( (size_t) 2, (size_t)verts[ 9] );
906 
907     // elem 0
908   CPPUNIT_ASSERT_EQUAL( (size_t)10, offsets[3] );
909   CPPUNIT_ASSERT_EQUAL( (size_t) 8, (size_t)verts[10] );
910   CPPUNIT_ASSERT_EQUAL( (size_t) 7, (size_t)verts[11] );
911   CPPUNIT_ASSERT_EQUAL( (size_t) 2, (size_t)verts[12] );
912   CPPUNIT_ASSERT_EQUAL( (size_t) 1, (size_t)verts[13] );
913 }
914 
915 
test_elements_get_topologies_mixed()916 void ArrayMeshTest::test_elements_get_topologies_mixed()
917 {
918   MsqPrintError err(std::cerr);
919   const size_t elems[] = { 3, 2, 1, 0, 1, 2, 3 };
920   const size_t num_elem = sizeof(elems)/sizeof(elems[0]);
921   EntityTopology topo[num_elem];
922   memset( topo, 0, sizeof(topo) );
923   mixedZeroBased->elements_get_topologies( (const Mesh::ElementHandle*)elems,
924                                          topo, num_elem, err );
925   CPPUNIT_ASSERT(!err);
926   for (size_t i = 0; i < num_elem; ++i)
927     CPPUNIT_ASSERT_EQUAL( (int)mixed_types[elems[i]], (int)topo[i] );
928 }
929 
test_tag_data(TagEntType type,TagStorage storage)930 void ArrayMeshTest::test_tag_data( TagEntType type, TagStorage storage )
931 {
932     // Select what we're working with given 'type' parameter
933   ArrayMesh* const mesh = (type == ONE_BASED_VERTEX) ? oneBased3D : zeroBased3D;
934   std::vector<Mesh::EntityHandle> entities;
935   MsqError err;
936   if (type == ELEMENT)
937     mesh->get_all_elements( entities, err );
938   else
939     mesh->get_all_vertices( entities, err );
940   ASSERT_NO_ERROR(err);
941 
942     // Create a tag
943   char name1[] = "  _double_3"; name1[0] = 'A' + type; name1[1] = 'A' + storage;
944   TagHandle tag;
945   std::vector<double> values(3*entities.size());
946   double dval = -5;
947   for (std::vector<double>::iterator i = values.begin(); i != values.end(); ++i)
948     *i = dval--;
949   double* ele_ptr = (type == ELEMENT) ? arrptr(values) : 0;
950   double* vtx_ptr = (type != ELEMENT) ? arrptr(values) : 0;
951   if (storage == READONLY) {
952     tag = mesh->add_read_only_tag_data( name1, Mesh::DOUBLE, 3, vtx_ptr, ele_ptr, 0, err );
953     ASSERT_NO_ERROR(err);
954   }
955   else if (storage == WRITABLE) {
956     tag = mesh->add_writable_tag_data( name1, Mesh::DOUBLE, 3, vtx_ptr, ele_ptr, 0, err );
957     ASSERT_NO_ERROR(err);
958   }
959   else {
960     assert(OWNED == storage);
961     tag = mesh->tag_create( name1, Mesh::DOUBLE, 3, 0, err );
962     ASSERT_NO_ERROR(err);
963     if (type == ELEMENT)
964       mesh->tag_set_element_data( tag, entities.size(), arrptr(entities), arrptr(values), err );
965     else
966       mesh->tag_set_vertex_data( tag, entities.size(), arrptr(entities), arrptr(values), err );
967     ASSERT_NO_ERROR(err);
968   }
969 
970     // Check tag properties
971   TagHandle tag2 = mesh->tag_get( name1, err );
972   ASSERT_NO_ERROR(err);
973   CPPUNIT_ASSERT_EQUAL( tag, tag2 );
974   std::string n;
975   Mesh::TagType t;
976   unsigned s;
977   mesh->tag_properties( tag, n, t, s, err );
978   ASSERT_NO_ERROR(err);
979   CPPUNIT_ASSERT_EQUAL( std::string(name1), n );
980   CPPUNIT_ASSERT_EQUAL( Mesh::DOUBLE, t );
981   CPPUNIT_ASSERT_EQUAL( 3u, s );
982 
983     // Check values returned from tag_get_*_data
984   std::vector<double> values2(3*entities.size());
985   if (ELEMENT == type)
986     mesh->tag_get_element_data( tag, entities.size(), arrptr(entities), arrptr(values2), err );
987   else
988     mesh->tag_get_vertex_data( tag, entities.size(), arrptr(entities), arrptr(values2), err );
989   ASSERT_NO_ERROR(err);
990   ASSERT_STD_VECTORS_EQUAL( values, values2 );
991 
992     // check that we get an error for other type, because no default
993   if (ELEMENT != type)
994     mesh->tag_get_element_data( tag, entities.size(), arrptr(entities), arrptr(values2), err );
995   else
996     mesh->tag_get_vertex_data( tag, entities.size(), arrptr(entities), arrptr(values2), err );
997   CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
998   err.clear();
999 
1000     // check that we can or cannot modify the values as expected
1001   dval = entities.size() + 1;
1002   std::vector<double> values5(values.size());
1003   for (std::vector<double>::iterator i = values5.begin(); i != values5.end(); ++i)
1004     *i = dval++;
1005   if (ELEMENT == type)
1006     mesh->tag_set_element_data( tag, entities.size(), arrptr(entities), arrptr(values5), err );
1007   else
1008     mesh->tag_set_vertex_data( tag, entities.size(), arrptr(entities), arrptr(values5), err );
1009   if (READONLY == storage) {
1010     CPPUNIT_ASSERT( err );
1011     err.clear();
1012   }
1013   else {
1014     ASSERT_NO_ERROR(err);
1015   }
1016 
1017     // check that the values are as expected
1018   if (READONLY != storage) {
1019     if (ELEMENT == type)
1020       mesh->tag_get_element_data( tag, entities.size(), arrptr(entities), arrptr(values2), err );
1021     else
1022       mesh->tag_get_vertex_data( tag, entities.size(), arrptr(entities), arrptr(values2), err );
1023     ASSERT_NO_ERROR(err);
1024     ASSERT_STD_VECTORS_EQUAL( values5, values2 );
1025 
1026       // if WRITABLE storeage, original input array should have changed also
1027     if (WRITABLE == storage) {
1028       ASSERT_STD_VECTORS_EQUAL( values, values5 );
1029     }
1030   }
1031 
1032     // create a new tag with a default value
1033   char name2[] = "  _int_2"; name2[0] = 'A' + type; name2[1] = 'A' + storage;
1034   const int default_val[] = { 'J', 'K' };
1035   if (READONLY == storage)
1036     tag = mesh->add_read_only_tag_data( name2, Mesh::INT, 2, 0, 0, default_val, err );
1037   else if (WRITABLE == storage)
1038     tag = mesh->add_writable_tag_data( name2, Mesh::INT, 2, 0, 0, default_val, err );
1039   else // OWNED == storage
1040     tag = mesh->tag_create( name2, Mesh::INT, 2, default_val, err );
1041   ASSERT_NO_ERROR(err);
1042 
1043     // Check tag properties
1044   tag2 = mesh->tag_get( name2, err );
1045   ASSERT_NO_ERROR(err);
1046   CPPUNIT_ASSERT_EQUAL( tag, tag2 );
1047   mesh->tag_properties( tag, n, t, s, err );
1048   ASSERT_NO_ERROR(err);
1049   CPPUNIT_ASSERT_EQUAL( std::string(name2), n );
1050   CPPUNIT_ASSERT_EQUAL( Mesh::INT, t );
1051   CPPUNIT_ASSERT_EQUAL( 2u, s );
1052 
1053     // should get default value for each entity
1054   std::vector<int> values3(2*entities.size());
1055   if (ELEMENT == type)
1056     mesh->tag_get_element_data( tag, entities.size(), arrptr(entities), arrptr(values3), err );
1057   else
1058     mesh->tag_get_vertex_data( tag, entities.size(), arrptr(entities), arrptr(values3), err );
1059   ASSERT_NO_ERROR(err);
1060 
1061     // check that we got the default value for every entity
1062   for (size_t i = 0; i < entities.size(); ++i) {
1063     CPPUNIT_ASSERT_EQUAL( default_val[0], values3[2*i  ] );
1064     CPPUNIT_ASSERT_EQUAL( default_val[1], values3[2*i+1] );
1065   }
1066 
1067     // check that we cannot modify the values
1068   for (size_t i = 0; i < values3.size(); ++i)
1069     values[i] = i;
1070   if (ELEMENT == type)
1071     mesh->tag_set_element_data( tag, entities.size(), arrptr(entities), arrptr(values3), err );
1072   else
1073     mesh->tag_set_vertex_data( tag, entities.size(), arrptr(entities), arrptr(values3), err );
1074   if (OWNED != storage) {
1075     CPPUNIT_ASSERT( err );
1076     err.clear();
1077   }
1078   else {
1079     ASSERT_NO_ERROR(err);
1080   }
1081 
1082     // check that we did set the values as expected
1083   if (OWNED != storage) {
1084     std::vector<int> values4(values3.size());
1085     if (ELEMENT == type)
1086       mesh->tag_get_element_data( tag, entities.size(), arrptr(entities), arrptr(values4), err );
1087     else
1088       mesh->tag_get_vertex_data( tag, entities.size(), arrptr(entities), arrptr(values4), err );
1089     ASSERT_NO_ERROR(err);
1090     ASSERT_STD_VECTORS_EQUAL( values3, values4 );
1091   }
1092 }
1093 
test_delete_tag()1094 void ArrayMeshTest::test_delete_tag( )
1095 {
1096   MsqError err;
1097   ArrayMesh* mesh = zeroBased2D;
1098   TagHandle tag, tag1, tag2, tag3;
1099   tag1 = mesh->add_read_only_tag_data( "name1", Mesh::BOOL, 1, 0, 0, 0, err );
1100   ASSERT_NO_ERROR(err);
1101   tag2 = mesh->add_writable_tag_data( "name2", Mesh::BYTE, 5, 0, 0, 0, err );
1102   ASSERT_NO_ERROR(err);
1103   tag3 = mesh->tag_create( "name3", Mesh::HANDLE, 2, 0, err );
1104   ASSERT_NO_ERROR(err);
1105 
1106   tag = mesh->tag_get( "name2", err );
1107   ASSERT_NO_ERROR(err);
1108   CPPUNIT_ASSERT_EQUAL( tag2, tag );
1109 
1110   mesh->tag_delete( tag2, err );
1111   ASSERT_NO_ERROR(err);
1112   tag = mesh->tag_get( "name2", err );
1113   CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
1114   err.clear();
1115   tag = mesh->tag_get( "name1", err );
1116   ASSERT_NO_ERROR(err);
1117   CPPUNIT_ASSERT_EQUAL( tag1, tag );
1118   tag = mesh->tag_get( "name3", err );
1119   ASSERT_NO_ERROR(err);
1120   CPPUNIT_ASSERT_EQUAL( tag3, tag );
1121 
1122   mesh->tag_delete( tag1, err );
1123   ASSERT_NO_ERROR(err);
1124   tag = mesh->tag_get( "name2", err );
1125   CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
1126   err.clear();
1127   tag = mesh->tag_get( "name1", err );
1128   CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
1129   err.clear();
1130   tag = mesh->tag_get( "name3", err );
1131   ASSERT_NO_ERROR(err);
1132   CPPUNIT_ASSERT_EQUAL( tag3, tag );
1133 
1134   mesh->tag_delete( tag3, err );
1135   ASSERT_NO_ERROR(err);
1136   tag = mesh->tag_get( "name2", err );
1137   CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
1138   err.clear();
1139   tag = mesh->tag_get( "name1", err );
1140   CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
1141   err.clear();
1142   tag = mesh->tag_get( "name3", err );
1143   CPPUNIT_ASSERT_EQUAL( MsqError::TAG_NOT_FOUND, err.error_code() );
1144   err.clear();
1145 }
1146 
1147