COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-components.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Tests mesh component classes"
9 
10 #include <boost/test/unit_test.hpp>
11 #include <boost/foreach.hpp>
12 #include <boost/assign/list_of.hpp>
13 
14 #include "common/Log.hpp"
15 #include "common/Core.hpp"
16 #include "common/Group.hpp"
18 
19 #include "mesh/Mesh.hpp"
20 #include "mesh/Region.hpp"
21 #include "mesh/Elements.hpp"
22 #include "common/Table.hpp"
23 #include "common/List.hpp"
24 #include "common/Table.hpp"
25 #include "common/DynTable.hpp"
26 #include "mesh/ElementType.hpp"
27 #include "mesh/Dictionary.hpp"
28 #include "mesh/Field.hpp"
29 
30 using namespace boost;
31 using namespace boost::assign;
32 using namespace cf3;
33 using namespace cf3::mesh;
34 using namespace cf3::common;
35 
37 
39 {
42  root(Core::instance().root())
43  {
44  // uncomment if you want to use arguments to the test executable
45  //int* argc = &boost::unit_test::framework::master_test_suite().argc;
46  //char*** argv = &boost::unit_test::framework::master_test_suite().argv;
47  }
48 
51  {
52  }
53 
55 
56  std::vector<Real> create_coord(const Real& x, const Real& y) {
57  Real coord[] = {x,y};
58  std::vector<Real> coordVec;
59  coordVec.assign(coord,coord+2);
60  return coordVec;
61  }
64 };
65 
67 
68 BOOST_FIXTURE_TEST_SUITE( MeshComponent_TestSuite, MeshComponent_Fixture )
69 
70 
72 BOOST_AUTO_TEST_CASE( MeshComponentTest )
73 {
74  // CFinfo << "testing MeshComponents \n" << CFflush;
75 
76  // Create root and mesh component
77  boost::shared_ptr<Component> root = boost::static_pointer_cast<Component>(allocate_component<Group>("root"));
78 
79  Mesh& mesh = *root->create_component<Mesh>( "mesh" ) ;
80 
81  BOOST_CHECK_EQUAL ( mesh.name() , "mesh" );
82  BOOST_CHECK_EQUAL ( mesh.uri().base_path().string() , "cpath:/" );
83  BOOST_CHECK_EQUAL ( mesh.uri().string() , "cpath:/mesh" );
84 
85  // Create one region inside mesh
86  Region& region1 = mesh.topology().create_region("region1");
87  BOOST_CHECK_EQUAL ( region1.uri().string() , "cpath:/mesh/topology/region1" );
88 
89  // Create second region inside mesh, with 2 subregions inside
90  Region& region2 = mesh.topology().create_region("region2");
91 
92  CFinfo << mesh.tree() << CFendl;
93  region2.create_region("subregion1");
94  Region& subregion = region2.create_region("subregion2");
95  BOOST_CHECK_EQUAL ( subregion.uri().string() , "cpath:/mesh/topology/region2/subregion2" );
96 
97  // Create a connectivity table inside a subregion
98  subregion.create_component<Table<Uint> >("connTable");
99  BOOST_CHECK_EQUAL ( find_component_with_name(subregion, "connTable").uri().string() , "cpath:/mesh/topology/region2/subregion2/connTable" );
100 
101  // Create a elementsType component inside a subregion
102  subregion.create_component<Elements>("elementType");
103  BOOST_CHECK_EQUAL ( find_component_with_name(subregion, "elementType").uri().string() , "cpath:/mesh/topology/region2/subregion2/elementType" );
104 
105  // Create an array of coordinates inside mesh
106  mesh.create_component<Table<Real> >("coordinates");
107  BOOST_CHECK_EQUAL ( find_component_with_name(mesh, "coordinates").uri().string() , "cpath:/mesh/coordinates" );
108 
109  find_component_with_name<Region>(region2, "subregion1").create_region("subsubregion1");
110  find_component_with_name<Region>(region2, "subregion1").create_region("subsubregion2");
111 }
112 
114 
115 BOOST_AUTO_TEST_CASE( AddRemoveTest )
116 {
117  // create table
118  boost::shared_ptr< Table<Uint> > table (allocate_component< Table<Uint> >("table"));
119  // initialize with number of columns
120  Uint nbCols = 3;
121  table->set_row_size(nbCols);
122  // create a buffer to interact with the table
123  Table<Uint>::Buffer buffer = table->create_buffer();
124 
125  // make a row
126  std::vector<Uint> row(nbCols);
127 
128  // add 4 rows to buffer
129  for(Uint i=0; i<nbCols; i++) row[i] = 0;
130  buffer.add_row(row);
131  for(Uint i=0; i<nbCols; i++) row[i] = 1;
132  buffer.add_row(row);
133  for(Uint i=0; i<nbCols; i++) row[i] = 2;
134  buffer.add_row(row);
135  for(Uint i=0; i<nbCols; i++) row[i] = 3;
136  buffer.add_row(row);
137 
138  // remove row 0 and 2
139  buffer.rm_row(0);
140  buffer.rm_row(2);
141 
142  // table should still be empty as the buffer is not flushed
143  BOOST_CHECK_EQUAL(table->array().size(),(Uint) 0);
144 
145 
146  buffer.flush();
147 
148  // table should have 2 elements as the buffer is flushed
149  BOOST_CHECK_EQUAL(table->array().size(),(Uint) 2);
150  BOOST_CHECK_EQUAL(table->array()[0][0], (Uint) 1);
151  BOOST_CHECK_EQUAL(table->array()[1][0], (Uint) 3);
152 
153 
154  // Test now if 2 rows can be deleted and only 1 added
155 
156  for(Uint i=0; i<nbCols; i++) row[i] = 4;
157  buffer.add_row(row);
158  buffer.rm_row(0);
159  buffer.rm_row(1);
160  BOOST_CHECK_EQUAL(table->array().size(),(Uint) 2);
161 
162 
163  buffer.flush();
164  BOOST_CHECK_EQUAL(table->array().size(),(Uint) 1);
165  BOOST_CHECK_EQUAL(table->array()[0][0], (Uint) 4);
166 
167 }
168 
170 
171 BOOST_AUTO_TEST_CASE( NoChangeFlushTest )
172 {
173  // create table
174  boost::shared_ptr< Table<Uint> > table (allocate_component< Table<Uint> >("table"));
175  // initialize with number of columns
176  Uint nbCols = 2;
177  table->set_row_size(nbCols);
178  table->resize(6);
179  // create a buffer to interact with the table
180  Table<Uint>::Buffer buffer = table->create_buffer();
181  buffer.flush();
182 }
183 
185 {
186  // create table
187  boost::shared_ptr< Table<Uint> > table (allocate_component< Table<Uint> >("table"));
188  // initialize with number of columns
189  Uint nbCols = 3;
190  table->set_row_size(nbCols);
191  // create a buffer to interact with the table with buffersize 3 (if no argument, use default buffersize)
192  Table<Uint>::Buffer buffer = table->create_buffer(3);
193 
194  // make a row
195  std::vector<Uint> row(nbCols);
196 
197  // add 4 rows to buffer
198  for(Uint i=0; i<nbCols; i++) row[i] = 0;
199  buffer.add_row(row);
200  for(Uint i=0; i<nbCols; i++) row[i] = 1;
201  buffer.add_row(row);
202  for(Uint i=0; i<nbCols; i++) row[i] = 2;
203  buffer.add_row(row);
204  BOOST_CHECK_EQUAL(buffer.total_allocated(), (Uint) 3);
205  for(Uint i=0; i<nbCols; i++) row[i] = 3;
206  buffer.add_row(row);
207  // adding that last row allocated a new buffer of size 3
208  BOOST_CHECK_EQUAL(buffer.total_allocated(), (Uint) 6);
209  buffer.flush();
210  // the flush copied everything in the table, and removed the buffers
211  BOOST_CHECK_EQUAL(buffer.total_allocated(), (Uint) 4);
212  BOOST_CHECK_EQUAL(table->array().size(),(Uint) 4);
213 
214  // buffer is now empty.
215  // add a row to buffer, remove that same row, and add another row.
216  for(Uint i=0; i<nbCols; i++) row[i] = 4;
217  buffer.add_row(row);
218  buffer.rm_row(4);
219  for(Uint i=0; i<nbCols; i++) row[i] = 5;
220  buffer.add_row(row);
221  BOOST_CHECK_EQUAL(buffer.total_allocated(), (Uint) 7);
222 
223  buffer.flush();
224  // the table should have grown with 1 as the buffer with 1 item was flushed
225  BOOST_CHECK_EQUAL(buffer.total_allocated(), (Uint) 5);
226  BOOST_CHECK_EQUAL(table->array().size(),(Uint) 5);
227  BOOST_CHECK_EQUAL(table->array()[4][0],(Uint) 5);
228 
229  // remove row 0, 1, 2
230  buffer.rm_row(0);
231  buffer.rm_row(1);
232  buffer.rm_row(2);
233 
234  // table still has 5 rows, but first 3 rows are marked as disabled
235  BOOST_CHECK_EQUAL(table->array().size(),(Uint) 5);
236 
237  buffer.flush();
238  // now the table should only have 2 row, as the 3 disabled rows should be removed
239 
240  BOOST_CHECK_EQUAL(table->array().size(),(Uint) 2);
241  BOOST_CHECK_EQUAL(table->array()[0][0],(Uint) 3);
242  BOOST_CHECK_EQUAL(table->array()[1][0],(Uint) 5);
243 
244 
245 
246 }
247 
249 
250 BOOST_AUTO_TEST_CASE( Table_Uint_Test )
251 {
252  // CFinfo << "testing Table<Uint> \n" << CFflush;
253  Logger::instance().getStream(DEBUG).set_log_level(SILENT);
254  // Create mesh component
255  boost::shared_ptr<Component> root = boost::static_pointer_cast<Component>(allocate_component<Group>("root"));
256 
257  Mesh& mesh = *root->create_component<Mesh> ( "mesh" ) ;
258 
259  // Create one region inside mesh
260  Region& region = mesh.topology().create_region("region");
261 
262  // Create connectivity table inside the region
263  Table<Uint>& connTable = *region.create_component<Table<Uint> >("connTable");
264 
265  // check constructor
266  BOOST_CHECK_EQUAL(connTable.size(),(Uint) 0);
267  BOOST_CHECK_EQUAL(connTable.row_size(),(Uint) 0);
268  BOOST_CHECK_EQUAL(connTable.array().num_elements(),(Uint) 0);
269 
270  // check initalization
271  Uint nbCols = 5;
272  connTable.set_row_size(nbCols);
273  Table<Uint>::Buffer tableBuffer = connTable.create_buffer();
274 
275  BOOST_CHECK_EQUAL(connTable.size(),(Uint) 0);
276  BOOST_CHECK_EQUAL(connTable.row_size(),(Uint) 5);
277  BOOST_CHECK_EQUAL(connTable.array().num_elements(),(Uint) 0);
278 
279  // check for adding rows to table
280  std::vector<Uint> row(nbCols);
281  for (Uint i=0; i<nbCols; ++i)
282  row[i] = i;
283 
284  tableBuffer.add_row(row);
285  tableBuffer.flush();
286  BOOST_CHECK_EQUAL(connTable.size(),(Uint) 1);
287  BOOST_CHECK_EQUAL(connTable.row_size(),(Uint) 5);
288  BOOST_CHECK_EQUAL(connTable.array().num_elements(),(Uint) 5);
289 
290 
291  // check if buffer flushes without calling flush by the user
292  for (Uint i=0; i<1023; ++i)
293  tableBuffer.add_row(row);
294  BOOST_CHECK_EQUAL(connTable.size(),(Uint) 1);
295  BOOST_CHECK_EQUAL(connTable.row_size(),(Uint) 5);
296  BOOST_CHECK_EQUAL(connTable.array().num_elements(),(Uint) 5);
297 
298  tableBuffer.add_row(row);
299  tableBuffer.flush();
300  BOOST_CHECK_EQUAL(connTable.size(),(Uint) 1025);
301  BOOST_CHECK_EQUAL(connTable.row_size(),(Uint) 5);
302  BOOST_CHECK_EQUAL(connTable.array().num_elements(),(Uint) 5*1025);
303 
304  // check if accessor / mutator works
305  BOOST_CHECK_EQUAL(connTable[0][0], (Uint) 0);
306  BOOST_CHECK_EQUAL(connTable[1][1], (Uint) 1);
307  BOOST_CHECK_EQUAL(connTable[2][2], (Uint) 2);
308 
309  // check if a row can be accessed
310  Table<Uint>::Row rowRef = connTable[35];
311  for (Uint i=0; i<nbCols; ++i)
312  BOOST_CHECK_EQUAL(rowRef[i], i);
313 
314 }
315 
317 
318 BOOST_AUTO_TEST_CASE( Table_Real_Test )
319 {
320  // Create a Elements component
321  boost::shared_ptr< Table<Real> > coordinates (allocate_component< Table<Real> >("coords")) ;
322 
323  // initialize the array
324  Uint dim = 2;
325  coordinates->set_row_size(dim);
326  BOOST_CHECK_EQUAL(coordinates->row_size(),dim);
327  Table<Real>::Buffer coordinatesBuffer = coordinates->create_buffer();
328 
329  // Add coordinates to the array
330  coordinatesBuffer.add_row(create_coord( 0.0 , 0.0 ));
331  coordinatesBuffer.add_row(create_coord( 1.0 , 0.0 ));
332  coordinatesBuffer.add_row(create_coord( 1.0 , 1.0 ));
333  coordinatesBuffer.add_row(create_coord( 0.0 , 1.0 ));
334  coordinatesBuffer.flush();
335 
336  BOOST_CHECK_EQUAL(coordinates->array()[2][1], 1.0);
337 }
338 
340 
341 
342 
343 BOOST_AUTO_TEST_CASE( Table_Real_Templates )
344 {
345  Table<Real>& vectorArray = *root.create_component< Table<Real> >("vector");
346  vectorArray.set_row_size(3);
347  //CFinfo << "numdim = " << Table<Real><VECTOR>::Array::NumDims() << "\n" << CFflush;
348 
349  // Table<Real><SCALAR> scalarArray("scalar");
350  // scalarArray.initialize(3);
351 
352 }
353 
354 BOOST_AUTO_TEST_CASE( moving_mesh_components_around )
355 {
356  boost::shared_ptr<Component> root = boost::static_pointer_cast<Component>(allocate_component<Group>("root"));
357  Mesh& mesh = *root->create_component<Mesh>("mesh");
358  Region& regions = mesh.topology().create_region("regions");
359 
360  Region& subregion1 = regions.create_region("subregion1");
361  BOOST_CHECK_EQUAL(find_components<Region>(subregion1).empty(),true);
362 
363  subregion1.create_component<Table<Uint> >("table");
364  BOOST_CHECK_EQUAL(find_components<Region>(subregion1).empty(),true);
365 
366  // create subregion2 in the wrong place
367  Region& subregion2 = subregion1.create_region("subregion2");
368  BOOST_CHECK_EQUAL(find_components<Region>(subregion1).empty(),false);
369  BOOST_CHECK_EQUAL(count(find_components<Region>(regions)), (Uint) 1);
370 
371 
372  // move subregion 2 to the right place
373  boost::shared_ptr<Component> subregion2_ptr = subregion1.remove_component(subregion2.name());
374  regions.add_component(subregion2_ptr);
375  BOOST_CHECK_EQUAL(find_components<Region>(subregion1).empty(),true);
376  BOOST_CHECK_EQUAL(count(find_components<Region>(regions)), (Uint) 2);
377 
378 
379 }
380 
381 BOOST_AUTO_TEST_CASE( List_tests )
382 {
383  List<bool>& bool_list = *root.create_component< List<bool> >("bool_list");
384  BOOST_CHECK_EQUAL(bool_list.type_name(),"List<bool>");
385 
386  boost::shared_ptr< List<int> > integer_list (allocate_component< List<int> >("integer_list"));
387  BOOST_CHECK_EQUAL(integer_list->type_name(),"List<integer>");
388 
389  boost::shared_ptr< List<Uint> > unsigned_list (allocate_component< List<Uint> >("unsigned_list"));
390  BOOST_CHECK_EQUAL(unsigned_list->type_name(),"List<unsigned>");
391 
392  boost::shared_ptr< List<Real> > real_list (allocate_component< List<Real> >("real_list"));
393  BOOST_CHECK_EQUAL(real_list->type_name(),"List<real>");
394 
395  boost::shared_ptr< List<std::string> > string_list (allocate_component< List<std::string> >("string_list"));
396  BOOST_CHECK_EQUAL(string_list->type_name(),"List<string>");
397 
398  bool_list.resize(10);
399  BOOST_CHECK_EQUAL(bool_list.size(),(Uint) 10);
400  bool_list[0] = true;
401  bool_list[5] = true;
402 
403  for (Uint i=0; i<10; ++i)
404  {
405  switch (i)
406  {
407  case 0:
408  case 5:
409  BOOST_CHECK_EQUAL(bool_list[i],true);
410  break;
411  default:
412  BOOST_CHECK_EQUAL(bool_list[i],false);
413  break;
414  }
415  }
416 
417  bool_list.resize(20);
418  BOOST_CHECK_EQUAL(bool_list.size(),(Uint) 20);
419 
420  for (Uint i=0; i<20; ++i)
421  {
422  switch (i)
423  {
424  case 0:
425  case 5:
426  BOOST_CHECK_EQUAL(bool_list[i],true);
427  break;
428  default:
429  BOOST_CHECK_EQUAL(bool_list[i],false);
430  break;
431  }
432  }
433 }
434 
435 BOOST_AUTO_TEST_CASE( ListAddRemoveTest )
436 {
437  // create table
438  boost::shared_ptr< Table<Uint> > table (allocate_component< Table<Uint> >("table"));
439  // initialize with number of columns
440  Uint nbCols = 3;
441  table->set_row_size(nbCols);
442  // create a buffer to interact with the table
443  Table<Uint>::Buffer buffer = table->create_buffer();
444 
445  // make a row
446  std::vector<Uint> row(nbCols);
447 
448  // add 4 rows to buffer
449  for(Uint i=0; i<nbCols; i++) row[i] = 0;
450  buffer.add_row(row);
451  for(Uint i=0; i<nbCols; i++) row[i] = 1;
452  buffer.add_row(row);
453  for(Uint i=0; i<nbCols; i++) row[i] = 2;
454  buffer.add_row(row);
455  for(Uint i=0; i<nbCols; i++) row[i] = 3;
456  buffer.add_row(row);
457 
458  // remove row 0 and 2
459  buffer.rm_row(0);
460  buffer.rm_row(2);
461 
462  // table should still be empty as the buffer is not flushed
463  BOOST_CHECK_EQUAL(table->array().size(),(Uint) 0);
464 
465 
466  buffer.flush();
467 
468  // table should have 2 elements as the buffer is flushed
469  BOOST_CHECK_EQUAL(table->array().size(),(Uint) 2);
470  BOOST_CHECK_EQUAL(table->array()[0][0], (Uint) 1);
471  BOOST_CHECK_EQUAL(table->array()[1][0], (Uint) 3);
472 
473 
474  // Test now if 2 rows can be deleted and only 1 added
475 
476  for(Uint i=0; i<nbCols; i++) row[i] = 4;
477  buffer.add_row(row);
478  buffer.rm_row(0);
479  buffer.rm_row(1);
480  BOOST_CHECK_EQUAL(table->array().size(),(Uint) 2);
481 
482 
483  buffer.flush();
484  BOOST_CHECK_EQUAL(table->array().size(),(Uint) 1);
485  BOOST_CHECK_EQUAL(table->array()[0][0], (Uint) 4);
486 
487 }
488 
490 
491 BOOST_AUTO_TEST_CASE( ListFlushTest )
492 {
493  // create table
494  List<Uint>& list = *root.create_component< List<Uint> >("list");
495  // create a buffer to interact with the list with buffersize 3 (if no argument, use default buffersize)
496  List<Uint>::Buffer buffer = list.create_buffer(3);
497 
498  // make a row
499  Uint row;
500 
501  // add 4 rows to buffer
502  row = 0;
503  buffer.add_row(row);
504  row = 1;
505  buffer.add_row(row);
506  row = 2;
507  buffer.add_row(row);
508  BOOST_CHECK_EQUAL(buffer.total_allocated(), (Uint) 3);
509  row = 3;
510  buffer.add_row(row);
511 
512  // adding that last row allocated a new buffer of size 3
513  BOOST_CHECK_EQUAL(buffer.total_allocated(), (Uint) 6);
514  buffer.flush();
515  // the flush copied everything in the table, and removed the buffers
516  BOOST_CHECK_EQUAL(buffer.total_allocated(), (Uint) 4);
517  BOOST_CHECK_EQUAL(list.size(),(Uint) 4);
518 
519 
520  // buffer is now empty.
521  // add a row to buffer, remove that same row, and add another row.
522  row = 4;
523  buffer.add_row(row);
524  buffer.rm_row(4);
525  row = 5;
526  buffer.add_row(row);
527  BOOST_CHECK_EQUAL(buffer.total_allocated(), (Uint) 7);
528 
529  buffer.flush();
530  // the table should have grown with 1 as the buffer with 1 item was flushed
531  BOOST_CHECK_EQUAL(buffer.total_allocated(), (Uint) 5);
532  BOOST_CHECK_EQUAL(list.size(),(Uint) 5);
533  BOOST_CHECK_EQUAL(list[4],(Uint) 5);
534  CFinfo << list << CFendl;
535  // remove row 0, 1, 2
536  buffer.rm_row(0);
537  buffer.rm_row(1);
538  buffer.rm_row(2);
539 
540  // table still has 5 rows, but first 3 rows are marked as disabled
541  BOOST_CHECK_EQUAL(list.size(),(Uint) 5);
542 
543  buffer.flush();
544  // now the table should only have 2 row, as the 3 disabled rows should be removed
545 
546  BOOST_CHECK_EQUAL(list.size(),(Uint) 2);
547  BOOST_CHECK_EQUAL(list[0],(Uint) 3);
548  BOOST_CHECK_EQUAL(list[1],(Uint) 5);
549 
550  CFinfo << list << CFendl;
551 
552 
553 }
554 
555 BOOST_AUTO_TEST_CASE ( DynTable_test )
556 {
557  DynTable<Uint>& table = *root.create_component< DynTable<Uint> >("table");
558  DynTable<Uint>::Buffer buffer = table.create_buffer();
559 
560  std::vector<Uint> row;
561 
562  row.resize(3);
563  for(Uint i=0; i<row.size(); i++) row[i] = 0;
564  buffer.add_row(row);
565 
566  row.resize(4);
567  for(Uint i=0; i<row.size(); i++) row[i] = 1;
568  buffer.add_row(row);
569 
570  row.resize(6);
571  for(Uint i=0; i<row.size(); i++) row[i] = 2;
572  buffer.add_row(row);
573 
574  row.resize(2);
575  for(Uint i=0; i<row.size(); i++) row[i] = 3;
576  buffer.add_row(row);
577 
578  BOOST_CHECK_EQUAL(table.size(), (Uint) 0);
579 
580  buffer.flush();
581 
582  BOOST_CHECK_EQUAL(table.size(), (Uint) 4);
583 
584  BOOST_CHECK_EQUAL(table[0][0], (Uint) 0);
585  BOOST_CHECK_EQUAL(table[0].size(), (Uint) 3);
586  BOOST_CHECK_EQUAL(table.row_size(0), (Uint) 3);
587 
588  BOOST_CHECK_EQUAL(table[1][0], (Uint) 1);
589  BOOST_CHECK_EQUAL(table[1].size(), (Uint) 4);
590  BOOST_CHECK_EQUAL(table.row_size(1), (Uint) 4);
591 
592 
593  BOOST_CHECK_EQUAL(table[2][0], (Uint) 2);
594  BOOST_CHECK_EQUAL(table[2].size(), (Uint) 6);
595  BOOST_CHECK_EQUAL(table.row_size(2), (Uint) 6);
596 
597 
598  BOOST_CHECK_EQUAL(table[3][0], (Uint) 3);
599  BOOST_CHECK_EQUAL(table[3].size(), (Uint) 2);
600  BOOST_CHECK_EQUAL(table.row_size(3), (Uint) 2);
601 
602 
603  // buffer is now empty.
604  // add a row to buffer, remove that same row, and add another row.
605  row.resize(4);
606  for(Uint i=0; i<row.size(); i++) row[i] = 4;
607  buffer.add_row(row);
608  buffer.rm_row(4);
609 
610  row.resize(7);
611  for(Uint i=0; i<row.size(); i++) row[i] = 5;
612  buffer.add_row(row);
613 
614  BOOST_CHECK(true);
615  buffer.flush();
616 
617  // the table should have grown with 1 as the buffer with 1 item was flushed
618  BOOST_CHECK_EQUAL(table.size(),(Uint) 5);
619  BOOST_CHECK_EQUAL(table[4][0],(Uint) 5);
620  BOOST_CHECK_EQUAL(table.row_size(4), (Uint) 7);
621 
622  // remove row 0, 1, 2
623  buffer.rm_row(0);
624  buffer.rm_row(1);
625  buffer.rm_row(2);
626 
627 
628 
629  // table still has 5 rows, but first 3 rows are marked as disabled
630  BOOST_CHECK_EQUAL(table.size(),(Uint) 5);
631 
632  // Flush the buffer
633  buffer.flush();
634 
635  // now the table should only have 2 row, as the 3 disabled rows should be removed
636 
637  BOOST_CHECK_EQUAL(table.size(),(Uint) 2);
638 
639  BOOST_CHECK_EQUAL(table[0][0],(Uint) 3);
640  BOOST_CHECK_EQUAL(table.row_size(0), (Uint) 2);
641 
642  BOOST_CHECK_EQUAL(table[1][0],(Uint) 5);
643  BOOST_CHECK_EQUAL(table.row_size(1), (Uint) 7);
644 
645 }
646 
647 
648 BOOST_AUTO_TEST_CASE ( DynTable_test_hard )
649 {
650 
651 // 0: 0
652 // 1: 1
653 // 2: 0 1
654 // 3: 1 4 5
655 // 4: 0 3
656 // 5: ~
657 // 6: ~
658 // 7: 4294967295
659 // 8: ~
660  DynTable<Uint>& table = *root.create_component< DynTable<Uint> >("table");
661  DynTable<Uint>::Buffer buffer = table.create_buffer();
662 
663  std::vector<Uint> row;
664 
665  row = list_of(0);
666  buffer.add_row(row);
667 
668  row = list_of(1);
669  buffer.add_row(row);
670 
671  row = list_of(0)(1);
672  buffer.add_row(row);
673 
674  row = list_of(1)(4)(5);
675  buffer.add_row(row);
676 
677  row = list_of(0)(3);
678  buffer.add_row(row);
679 
680  row.resize(0);
681  buffer.add_row(row);
682 
683  row.resize(0);
684  buffer.add_row(row);
685 
686  row.resize(0);
687  buffer.add_row(row);
688 
689  row.resize(0);
690  buffer.add_row(row);
691 
692  BOOST_CHECK(true);
693 
694  buffer.flush();
695 
696  buffer.rm_row(7);
697 
698  buffer.flush();
699 
700 
701 }
702 
703 
704 BOOST_AUTO_TEST_CASE ( Mesh_test )
705 {
706  boost::shared_ptr<Component> root = boost::static_pointer_cast<Component>(allocate_component<Group>("root"));
707  Mesh& mesh = *root->create_component<Mesh>("mesh");
708  Region& region = mesh.topology().create_region("region");
709  Dictionary& nodes = mesh.geometry_fields();
710  mesh.initialize_nodes(2,DIM_3D);
711  BOOST_CHECK_EQUAL(mesh.geometry_fields().coordinates().row_size() , (Uint) DIM_3D);
712 }
713 
714 BOOST_AUTO_TEST_CASE( List_Uint_Test )
715 {
716  // CFinfo << "testing Table<Uint> \n" << CFflush;
717  Logger::instance().getStream(DEBUG).set_log_level(SILENT);
718  // Create mesh component
719  boost::shared_ptr<Component> root = boost::static_pointer_cast<Component>(allocate_component<Group>("root"));
720 
721  boost::shared_ptr<Mesh> mesh = allocate_component<Mesh> ( "mesh" ) ;
722 
723  root->add_component( mesh );
724 
725  // Create one region inside mesh
726  Region& region = mesh->topology().create_region("region");
727 
728  // Create connectivity table inside the region
729  List<Uint>& connTable = *region.create_component<List<Uint> >("connTable");
730 
731  // check constructor
732  BOOST_CHECK_EQUAL(connTable.size(),(Uint) 0);
733  BOOST_CHECK_EQUAL(connTable.array().num_elements(),(Uint) 0);
734 
735  // check initalization
736  List<Uint>::Buffer tableBuffer = connTable.create_buffer(10);
737 
738  BOOST_CHECK_EQUAL(connTable.size(),(Uint) 0);
739  BOOST_CHECK_EQUAL(connTable.array().num_elements(),(Uint) 0);
740 
741  // check for adding rows to table
742 
743  tableBuffer.add_row(0);
744  tableBuffer.flush();
745  BOOST_CHECK_EQUAL(connTable.size(),(Uint) 1);
746  BOOST_CHECK_EQUAL(connTable.array().num_elements(),(Uint) 1);
747 
748 
749  for (Uint i=0; i<10; ++i)
750  tableBuffer.add_row(1);
751  BOOST_CHECK_EQUAL(connTable.size(),(Uint) 1);
752  BOOST_CHECK_EQUAL(connTable.array().num_elements(),(Uint) 1);
753 
754  tableBuffer.add_row(1);
755  tableBuffer.flush();
756  BOOST_CHECK_EQUAL(connTable.size(),(Uint) 12);
757  BOOST_CHECK_EQUAL(connTable.array().num_elements(),(Uint) 12);
758 
759  // check if accessor / mutator works
760  BOOST_CHECK_EQUAL(connTable[0], (Uint) 0);
761  BOOST_CHECK_EQUAL(connTable[1], (Uint) 1);
762  BOOST_CHECK_EQUAL(connTable[2], (Uint) 1);
763 
764  // check if a row can be accessed
765  List<Uint>::value_type rowRef = connTable[6];
766 
767  tableBuffer.rm_row(0);
768  tableBuffer.add_row(2);
769  tableBuffer.add_row(3);
770  tableBuffer.add_row(4);
771  tableBuffer.add_row(5);
772  tableBuffer.add_row(6);
773  tableBuffer.rm_row(2);
774  tableBuffer.rm_row(13);
775  tableBuffer.flush();
776 
777  CFinfo << connTable << CFendl;
778 
779  tableBuffer.rm_row(2);
780  tableBuffer.rm_row(5);
781  tableBuffer.rm_row(7);
782  tableBuffer.rm_row(3);
783  tableBuffer.add_row(10);
784  tableBuffer.add_row(10);
785 
786  tableBuffer.flush();
787  CFinfo << connTable << CFendl;
788 }
789 
790 
791 BOOST_AUTO_TEST_CASE( List_Uint_rm_Test )
792 {
793  // CFinfo << "testing Table<Uint> \n" << CFflush;
794  Logger::instance().getStream(DEBUG).set_log_level(SILENT);
795  // Create mesh component
796  boost::shared_ptr<Component> root = boost::static_pointer_cast<Component>(allocate_component<Group>("root"));
797 
798  boost::shared_ptr<Mesh> mesh = allocate_component<Mesh> ( "mesh" ) ;
799 
800  root->add_component( mesh );
801 
802  // Create one region inside mesh
803  Region& region = mesh->topology().create_region("region");
804 
805  // Create connectivity table inside the region
806  List<Uint>& list = *region.create_component<List<Uint> >("connTable");
807 
808 
809  // check initalization
810  List<Uint>::Buffer buffer = list.create_buffer();
811 
812  // add rows to table
813 
814  buffer.add_row(0);
815  buffer.add_row(1);
816  buffer.add_row(2);
817  buffer.add_row(3);
818  buffer.add_row(6);
819  buffer.add_row(7);
820  buffer.add_row(8);
821 
822  buffer.flush();
823  BOOST_CHECK_EQUAL( list[0] , 0u);
824  BOOST_CHECK_EQUAL( list[1] , 1u);
825  BOOST_CHECK_EQUAL( list[2] , 2u);
826  BOOST_CHECK_EQUAL( list[3] , 3u);
827  BOOST_CHECK_EQUAL( list[4] , 6u);
828  BOOST_CHECK_EQUAL( list[5] , 7u);
829  BOOST_CHECK_EQUAL( list[6] , 8u);
830 
831  buffer.rm_row(0);
832  buffer.rm_row(3);
833  buffer.rm_row(4);
834 
835  buffer.flush();
836  BOOST_CHECK_EQUAL( list[0] , 7u);
837  BOOST_CHECK_EQUAL( list[1] , 1u);
838  BOOST_CHECK_EQUAL( list[2] , 2u);
839  BOOST_CHECK_EQUAL( list[3] , 8u);
840 }
841 
842 BOOST_AUTO_TEST_CASE( List_bool_Test )
843 {
844  // CFinfo << "testing Table<Uint> \n" << CFflush;
845  Logger::instance().getStream(DEBUG).set_log_level(SILENT);
846  // Create mesh component
847  boost::shared_ptr<Component> root = boost::static_pointer_cast<Component>(allocate_component<Group>("root"));
848 
849  boost::shared_ptr<Mesh> mesh = allocate_component<Mesh> ( "mesh" ) ;
850 
851  root->add_component( mesh );
852 
853  // Create one region inside mesh
854  Region& region = mesh->topology().create_region("region");
855 
856  // Create connectivity table inside the region
857  List<bool>& connTable = *region.create_component<List<bool> >("connTable");
858 
859  // check constructor
860  BOOST_CHECK_EQUAL(connTable.size(),(Uint) 0);
861  BOOST_CHECK_EQUAL(connTable.array().num_elements(),(Uint) 0);
862 
863  // check initalization
864  List<bool>::Buffer tableBuffer = connTable.create_buffer(10);
865 
866  BOOST_CHECK_EQUAL(connTable.size(),(Uint) 0);
867  BOOST_CHECK_EQUAL(connTable.array().num_elements(),(Uint) 0);
868 
869  // check for adding rows to table
870 
871  tableBuffer.add_row(false);
872  tableBuffer.flush();
873  BOOST_CHECK_EQUAL(connTable.size(),(Uint) 1);
874  BOOST_CHECK_EQUAL(connTable.array().num_elements(),(Uint) 1);
875 
876  for (Uint i=0; i<10; ++i)
877  tableBuffer.add_row(true);
878  BOOST_CHECK_EQUAL(connTable.size(),(Uint) 1);
879  BOOST_CHECK_EQUAL(connTable.array().num_elements(),(Uint) 1);
880  BOOST_CHECK_EQUAL(tableBuffer.get_row(10),true);
881 
882  tableBuffer.add_row(true);
883  tableBuffer.flush();
884  BOOST_CHECK_EQUAL(connTable.size(),(Uint) 12);
885  BOOST_CHECK_EQUAL(connTable.array().num_elements(),(Uint) 12);
886 
887  // check if accessor / mutator works
888  BOOST_CHECK_EQUAL(connTable[0], false);
889  BOOST_CHECK_EQUAL(connTable[1], true);
890  BOOST_CHECK_EQUAL(connTable[2], true);
891 
892  // check if a row can be accessed
893  List<bool>::value_type rowRef = connTable[6];
894 
895  tableBuffer.rm_row(0);
896  tableBuffer.flush();
897  BOOST_CHECK_EQUAL(connTable[0], true);
898 
899 }
900 
902 
903 
905 
906 BOOST_AUTO_TEST_SUITE_END()
907 
908 
ListT & array()
Definition: List.hpp:76
#define CFinfo
these are always defined
Definition: Log.hpp:104
URI base_path() const
Definition: URI.cpp:199
Uint size() const
Definition: DynTable.hpp:49
ArrayT & array()
Definition: Table.hpp:92
external boost library namespace
void resize(const Uint new_size)
Definition: List.hpp:69
void initialize_nodes(const Uint nb_nodes, const Uint dimension)
will among others set the coordinate dimension for the nodes
Definition: Mesh.cpp:127
BOOST_AUTO_TEST_CASE(MeshComponentTest)
Uint add_row(const vectorType &row)
static std::string type_name()
Definition: List.hpp:65
URI uri() const
Construct the full path.
Definition: Component.cpp:248
Region & create_region(const std::string &name)
Definition: Region.cpp:50
Buffer create_buffer(const size_t buffersize=16384)
Definition: Table.hpp:102
common::URI uri(ComponentWrapper &self)
MeshComponent_Fixture()
common setup for each test case
const std::string & name() const
Access the name of the component.
Definition: Component.hpp:146
const Field & coordinates() const
Definition: Dictionary.cpp:481
tuple root
Definition: coolfluid.py:24
#define CFendl
Definition: Log.hpp:109
boost::proto::terminal< SFOp< NodesOp > >::type const nodes
Component & root
common values accessed by all tests goes here
Uint size() const
Definition: Table.hpp:127
Uint row_size(const Uint i) const
Definition: DynTable.hpp:68
ComponentReference< Component >::type find_component_with_name(Component &parent, StringConverter name)
Basic Classes for Mesh applications used by COOLFluiD.
Top-level namespace for coolfluid.
Definition: Action.cpp:18
std::string tree(bool basic_mode=false, Uint depth=0, Uint recursion_level=0) const
Definition: Component.cpp:785
~MeshComponent_Fixture()
common tear-down for each test case
Uint row_size(Uint i=0) const
Definition: Table.hpp:133
boost::proto::terminal< SFOp< CoordinatesOp > >::type const coordinates
void set_row_size(const Uint nb_cols)
Definition: Table.hpp:78
Uint size() const
Definition: List.hpp:111
boost::shared_ptr< Component > remove_component(const std::string &name)
Remove a (sub)component of this component.
Definition: Component.cpp:357
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
Buffer create_buffer(const size_t buffersize=16384)
Definition: List.hpp:86
Buffer create_buffer(const size_t buffersize=16384)
Definition: DynTable.hpp:72
Region & topology() const
Definition: Mesh.hpp:51
std::vector< Real > create_coord(const Real &x, const Real &y)
possibly common functions used on the tests below
Dictionary & geometry_fields() const
Definition: Mesh.cpp:339
Base class for defining CF components.
Definition: Component.hpp:82
Handle< Component > create_component(const std::string &name, const std::string &builder)
Build a (sub)component of this component using the extended type_name of the component.
Definition: Component.cpp:568
Most basic kernel library.
Definition: Action.cpp:19
std::string string() const
Definition: URI.cpp:258
Uint count(const RangeT &range)
Count the elements in a range.
boost::shared_ptr< T > allocate_component(const std::string &name)
Stand-alone function to allocate components of a given type.
Definition: Component.hpp:55
Send comments to:
COOLFluiD Web Admin