COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-cgns.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 
8 #include <iostream>
9 
10 #define BOOST_TEST_DYN_LINK
11 #define BOOST_TEST_MODULE "Test module for CGNS"
12 #include <boost/test/unit_test.hpp>
13 #include <boost/foreach.hpp>
14 #include <boost/regex.hpp>
15 
16 #include "rapidxml/rapidxml.hpp"
17 
18 
19 #include "common/Log.hpp"
20 #include "common/OptionList.hpp"
21 #include "common/OSystem.hpp"
22 #include "common/LibLoader.hpp"
23 #include "common/Core.hpp"
24 #include "common/Environment.hpp"
25 
26 #include "mesh/Mesh.hpp"
27 #include "mesh/Region.hpp"
28 #include "mesh/Elements.hpp"
29 #include "common/Table.hpp"
30 #include "mesh/MeshReader.hpp"
31 #include "mesh/MeshWriter.hpp"
32 #include "mesh/MeshTransformer.hpp"
33 #include "mesh/Connectivity.hpp"
34 
35 #include "mesh/CGNS/Shared.hpp"
36 
37 
38 using namespace std;
39 using namespace boost;
40 using namespace cf3;
41 using namespace cf3::common;
42 using namespace cf3::mesh;
43 using namespace cf3::mesh::CGNS;
44 
46 
48 {
51  {
52  // uncomment if you want to use arguments to the test executable
53  //int* argc = &boost::unit_test::framework::master_test_suite().argc;
54  //char*** argv = &boost::unit_test::framework::master_test_suite().argv;
55  }
56 
59  {
60  }
61 
63 
65 
67  RealVector create_coord(const Real& x, const Real& y) {
68  RealVector coordVec(2);
69  coordVec[XX]=x;
70  coordVec[YY]=y;
71  return coordVec;
72  }
73 
75  std::vector<Uint> create_quad(const Uint& A, const Uint& B, const Uint& C, const Uint& D) {
76  Uint quad[] = {A,B,C,D};
77  std::vector<Uint> quadVec;
78  quadVec.assign(quad,quad+4);
79  return quadVec;
80  }
81 
83  std::vector<Uint> create_triag(const Uint& A, const Uint& B, const Uint& C) {
84  Uint triag[] = {A,B,C};
85  std::vector<Uint> triagVec;
86  triagVec.assign(triag,triag+3);
87  return triagVec;
88  }
89 
91 
92  std::string xml_config;
94  char* ctext;
95 
97  {
98  ctext = doc.allocate_string(xml_config.c_str());
99  doc.parse< rapidxml::parse_no_data_nodes >(ctext);
100  return doc.first_node();
101  }
102 };
103 
105 
106 BOOST_FIXTURE_TEST_SUITE( TestCGNS_TestSuite, TestCGNS_Fixture )
107 
108 
110 BOOST_AUTO_TEST_CASE( Constructors )
111 {
112  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.CGNS.Reader","meshreader");
113  BOOST_CHECK_EQUAL(meshreader->name(),"meshreader");
114  BOOST_CHECK_EQUAL(meshreader->get_format(),"CGNS");
115 }
116 
118 
119 #define NI 17
120 #define NJ 9
121 #define NK 5
122 
123 BOOST_AUTO_TEST_CASE( TestLibCGNS )
124 {
125 
126  int maxelemi = (NI-1)*(NJ-1)*(NK-1);
127  double x[NI*NJ*NK],y[NI*NJ*NK],z[NI*NJ*NK];
128  cgsize_t isize[3][1],ielem[maxelemi][8];
129  int ni,nj,nk,iset,i,j,k,index_file,icelldim,iphysdim;
130  int index_base,index_zone,index_coord,ielem_no,nelem_start;
131  int ifirstnode,nelem_end,nbdyelem,index_section;
132  char basename[33],zonename[33];
133 
134 /* create gridpoints for simple example: */
135  ni=NI;
136  nj=NJ;
137  nk=NK;
138  iset=0;
139  for (k=1; k <= nk; k++)
140  {
141  for (j=1; j <=nj; j++)
142  {
143  for (i=1; i <= ni; i++)
144  {
145  x[iset]=(float)i-1.;
146  y[iset]=(float)j-1.;
147  z[iset]=(float)k-1.;
148  iset=iset+1;
149  }
150  }
151  }
152 
153 /* WRITE X, Y, Z GRID POINTS TO CGNS FILE */
154 /* open CGNS file for write */
155  CALL_CGNS(cg_open("grid_c.cgns",CG_MODE_WRITE,&index_file));
156 /* create base (user can give any name) */
157  strcpy(basename,"Base");
158  icelldim=3;
159  iphysdim=3;
160  CALL_CGNS(cg_base_write(index_file,basename,icelldim,iphysdim,&index_base));
161 /* define zone name (user can give any name) */
162  strcpy(zonename,"Zone 1");
163 /* vertex size */
164  isize[0][0]=ni*nj*nk;
165 /* cell size */
166  isize[1][0]=(ni-1)*(nj-1)*(nk-1);
167 /* boundary vertex size (zero if elements not sorted) */
168  isize[2][0]=0;
169 /* create zone */
170  CALL_CGNS(cg_zone_write(index_file,index_base,zonename,isize[0],CGNS_ENUMV( Unstructured ),&index_zone));
171 /* write grid coordinates (user must use SIDS-standard names here) */
172  CALL_CGNS(cg_coord_write(index_file,index_base,index_zone,CGNS_ENUMV( RealDouble ),"CoordinateX",x,&index_coord));
173  CALL_CGNS(cg_coord_write(index_file,index_base,index_zone,CGNS_ENUMV( RealDouble ),"CoordinateY",y,&index_coord));
174  CALL_CGNS(cg_coord_write(index_file,index_base,index_zone,CGNS_ENUMV( RealDouble ),"CoordinateZ",z,&index_coord));
175 /* set element connectivity: */
176 /* ---------------------------------------------------------- */
177 /* do all the CGNS_ENUMV( HEXA_8 ) elements (this part is mandatory): */
178 /* maintain SIDS-standard ordering */
179  ielem_no=0;
180 /* index no of first element */
181  nelem_start=1;
182  for (k=1; k < nk; k++)
183  {
184  for (j=1; j < nj; j++)
185  {
186  for (i=1; i < ni; i++)
187  {
188 /*
189 in this example, due to the order in the node numbering, the
190 hexahedral elements can be reconstructed using the following
191 relationships:
192 */
193  ifirstnode=i+(j-1)*ni+(k-1)*ni*nj;
194  ielem[ielem_no][0]=ifirstnode;
195  ielem[ielem_no][1]=ifirstnode+1;
196  ielem[ielem_no][2]=ifirstnode+1+ni;
197  ielem[ielem_no][3]=ifirstnode+ni;
198  ielem[ielem_no][4]=ifirstnode+ni*nj;
199  ielem[ielem_no][5]=ifirstnode+ni*nj+1;
200  ielem[ielem_no][6]=ifirstnode+ni*nj+1+ni;
201  ielem[ielem_no][7]=ifirstnode+ni*nj+ni;
202  ielem_no=ielem_no+1;
203  }
204  }
205  }
206 /* index no of last element (=2560) */
207  nelem_end=ielem_no;
208  if (nelem_end > maxelemi)
209  {
210  printf("\nError, must increase maxelemi to at least %d\n",nelem_end);
211  exit(0);
212  }
213  std::cout << "volume: " << nelem_start << " , " << nelem_end << std::endl;
214 /* unsorted boundary elements */
215  nbdyelem=0;
216 /* write CGNS_ENUMV( HEXA_8 ) element connectivity (user can give any name) */
217  CALL_CGNS(cg_section_write(index_file,index_base,index_zone,"Elem",CGNS_ENUMV( HEXA_8 ),nelem_start, \
218  nelem_end,nbdyelem,ielem[0],&index_section));
219 /* ---------------------------------------------------------- */
220 int maxelemj = (NI)*(NJ)*(NK);
221 std::cout << "maxelemj = " << maxelemj << std::endl;
222 cgsize_t jelem[maxelemj][4];
223 /*
224 do boundary (QUAD) elements (this part is optional,
225 but you must do it if you eventually want to define BCs
226 at element faces rather than at nodes):
227 maintain SIDS-standard ordering
228 */
229 /* INFLOW: */
230  ielem_no=0;
231 /* index no of first element */
232  nelem_start=nelem_end+1;
233  int inflow_start = nelem_start;
234  i=1;
235  for (k=1; k < nk; k++)
236  {
237  for (j=1; j < nj; j++)
238  {
239  ifirstnode=i+(j-1)*ni+(k-1)*ni*nj;
240  jelem[ielem_no][0]=ifirstnode;
241  jelem[ielem_no][1]=ifirstnode+ni*nj;
242  jelem[ielem_no][2]=ifirstnode+ni*nj+ni;
243  jelem[ielem_no][3]=ifirstnode+ni;
244  ielem_no=ielem_no+1;
245  }
246  }
247 /* index no of last element */
248  nelem_end=nelem_start+ielem_no-1;
249  int inflow_last = nelem_end;
250  if (ielem_no > maxelemj)
251  {
252  printf("\nError, must increase maxelemj to at least %d\n",ielem_no);
253  exit(0);
254  }
255 /* write QUAD element connectivity for inflow face (user can give any name) */
256  CALL_CGNS(cg_section_write(index_file,index_base,index_zone,"InflowElem",CGNS_ENUMV( QUAD_4 ),nelem_start, \
257  nelem_end,nbdyelem,jelem[0],&index_section));
258 /* OUTFLOW: */
259  ielem_no=0;
260 /* index no of first element */
261  nelem_start=nelem_end+1;
262  int outflow_start = nelem_start;
263  i=ni-1;
264  for (k=1; k < nk; k++)
265  {
266  for (j=1; j < nj; j++)
267  {
268  ifirstnode=i+(j-1)*ni+(k-1)*ni*nj;
269  jelem[ielem_no][0]=ifirstnode+1;
270  jelem[ielem_no][1]=ifirstnode+1+ni;
271  jelem[ielem_no][2]=ifirstnode+ni*nj+1+ni;
272  jelem[ielem_no][3]=ifirstnode+ni*nj+1;
273  ielem_no=ielem_no+1;
274  }
275  }
276 /* index no of last element */
277  nelem_end=nelem_start+ielem_no-1;
278  int outflow_last = nelem_end;
279  if (ielem_no > maxelemj)
280  {
281  printf("\nError, must increase maxelemj to at least %d\n",ielem_no);
282  exit(0);
283  }
284 /* write QUAD element connectivity for outflow face (user can give any name) */
285  CALL_CGNS(cg_section_write(index_file,index_base,index_zone,"OutflowElem",CGNS_ENUMV( QUAD_4 ),nelem_start, \
286  nelem_end,nbdyelem,jelem[0],&index_section));
287 /* SIDEWALLS: */
288  ielem_no=0;
289 /* index no of first element */
290  nelem_start=nelem_end+1;
291  int side_wall_start = nelem_start;
292  j=1;
293  for (k=1; k < nk; k++)
294  {
295  for (i=1; i < ni; i++)
296  {
297  ifirstnode=i+(j-1)*ni+(k-1)*ni*nj;
298  jelem[ielem_no][0]=ifirstnode+1;
299  jelem[ielem_no][1]=ifirstnode+ni*nj+1;
300  jelem[ielem_no][2]=ifirstnode+ni*nj;
301  jelem[ielem_no][3]=ifirstnode;
302  ielem_no=ielem_no+1;
303  }
304  }
305  j=nj-1;
306  for (k=1; k < nk; k++)
307  {
308  for (i=1; i < ni; i++)
309  {
310  ifirstnode=i+(j-1)*ni+(k-1)*ni*nj;
311  jelem[ielem_no][0]=ifirstnode+1+ni;
312  jelem[ielem_no][1]=ifirstnode+ni;
313  jelem[ielem_no][2]=ifirstnode+ni*nj+ni;
314  jelem[ielem_no][3]=ifirstnode+ni*nj+1+ni;
315  ielem_no=ielem_no+1;
316  }
317  }
318  k=1;
319  for (j=1; j < nj; j++)
320  {
321  for (i=1; i < ni; i++)
322  {
323  ifirstnode=i+(j-1)*ni+(k-1)*ni*nj;
324  jelem[ielem_no][0]=ifirstnode+ni;
325  jelem[ielem_no][1]=ifirstnode+1+ni;
326  jelem[ielem_no][2]=ifirstnode+1;
327  jelem[ielem_no][3]=ifirstnode;
328  ielem_no=ielem_no+1;
329  }
330  }
331  k=nk-1;
332  for (j=1; j < nj; j++)
333  {
334  for (i=1; i < ni; i++)
335  {
336  ifirstnode=i+(j-1)*ni+(k-1)*ni*nj;
337  jelem[ielem_no][0]=ifirstnode+ni*nj+1;
338  jelem[ielem_no][1]=ifirstnode+ni*nj+1+ni;
339  jelem[ielem_no][2]=ifirstnode+ni*nj+ni;
340  jelem[ielem_no][3]=ifirstnode+ni*nj;
341  ielem_no=ielem_no+1;
342  }
343  }
344 /* index no of last element */
345  nelem_end=nelem_start+ielem_no-1;
346  int side_wall_last = nelem_end;
347  if (ielem_no > maxelemj)
348  {
349  printf("\nError, must increase maxelemj to at least %d\n",ielem_no);
350  exit(0);
351  }
352 /* write QUAD element connectivity for sidewall face (user can give any name) */
353  CALL_CGNS(cg_section_write(index_file,index_base,index_zone,"SidewallElem",CGNS_ENUMV( QUAD_4 ),nelem_start, \
354  nelem_end,nbdyelem,jelem[0],&index_section));
355 /* ---------------------------------------------------------- */
356 
357  // part 2: add boundary conditions
358  int icount, n, index_bc;
359  int maxcount(960);
360  cgsize_t ipnts[maxcount];
361  // BC inflow
362  std::cout << "inflow: " << inflow_start << " , " << inflow_last << std::endl;
363  nelem_start=inflow_start;
364  nelem_end=inflow_last;
365  icount=0;
366  for (n=nelem_start; n <= nelem_end; n++)
367  {
368  ipnts[icount]=n;
369  icount=icount+1;
370  }
371  if (icount > maxcount)
372  {
373  printf("\nError. Need to increase maxcount to at least %i\n",icount);
374  exit(0);
375  }
376  CGNS_ENUMT( PointSetType_t ) bc_type = CGNS_ENUMV( ElementList );
377 /* write boundary conditions for ilo face */
378  CALL_CGNS(cg_boco_write(index_file,index_base,index_zone,"inflow",CGNS_ENUMV( BCTunnelInflow ),bc_type, \
379  icount,ipnts,&index_bc));
380  std::cout << "\nSuccessfully wrote BC inflow (ElementList = "<<to_str<int>(CGNS_ENUMV( ElementList ))<<") to grid_c.cgns"<<std::endl;
381 
382  // BC outflow
383  /* we know that for the unstructured zone, the following face elements */
384  /* have been defined as outflow (real working code would check!): */
385  std::cout << "outflow: " << outflow_start << " , " << outflow_last << std::endl;
386  nelem_start=outflow_start;
387  nelem_end=outflow_last;
388  icount=0;
389  for (n=nelem_start; n <= nelem_end; n++)
390  {
391  ipnts[icount]=n;
392  icount=icount+1;
393  }
394  if (icount > maxcount)
395  {
396  printf("\nError. Need to increase maxcount to at least %i\n",icount);
397  exit(0);
398  }
399  /* write boundary conditions for ihi face */
400  CALL_CGNS(cg_boco_write(index_file,index_base,index_zone,"outflow",CGNS_ENUMV( BCExtrapolate ),bc_type,icount,ipnts,&index_bc));
401  std::cout << "\nSuccessfully wrote BC outflow (ElementList = "<<to_str<int>(CGNS_ENUMV( ElementList ))<<") to grid_c.cgns"<<std::endl;
402 
403 
404 /* we know that for the unstructured zone, the following face elements */
405 /* have been defined as walls (real working code would check!): */
406  std::cout << "side_walls: " << side_wall_start << " , " << side_wall_last << std::endl;
407  nelem_start=side_wall_start;
408  nelem_end=side_wall_last;
409  icount=0;
410  for (n=nelem_start; n <= nelem_end; n++)
411  {
412  ipnts[icount]=n;
413  icount=icount+1;
414  }
415  if (icount > maxcount)
416  {
417  printf("\nError. Need to increase maxcount to at least %i\n",icount);
418  exit(0);
419  }
420  /* write boundary conditions for wall faces */
421  CALL_CGNS(cg_boco_write(index_file,index_base,index_zone,"Walls",CGNS_ENUMV( BCWallInviscid ),bc_type,icount,ipnts,&index_bc));
422  std::cout << "\nSuccessfully wrote BC Walls (ElementList = "<<to_str<int>(CGNS_ENUMV( ElementList ))<<") to grid_c.cgns"<<std::endl;
423 
424 /* ---------------------------------------------------------- */
425 
426 
427 /* close CGNS file */
428  CALL_CGNS(cg_close(index_file));
429  std::cout << "\nSuccessfully wrote unstructured grid to file grid_c.cgns"<< std::endl;
430 
431  BOOST_CHECK(true);
432 }
433 
435 
436 BOOST_AUTO_TEST_CASE ( WriteStructured )
437 {
438  /*
439  dimension statements (note that tri-dimensional arrays
440  x,y,z must be dimensioned exactly as [N][17][21] (N>=9)
441  for this particular case or else they will be written to
442  the CGNS file incorrectly! Other options are to use 1-D
443  arrays, use dynamic memory, or pass index values to a
444  subroutine and dimension exactly there):
445  */
446  double x1[2][3][5],y1[2][3][5],z1[2][3][5];
447  double x2[2][3][5],y2[2][3][5],z2[2][3][5];
448  cgsize_t isize[3][3], ipnts[2][3];
449  int ni,nj,nk,i,j,k;
450  int index_file,icelldim,iphysdim,index_base;
451  int index_zone,index_coord,index_bc;
452  char basename[33],zonename[33];
453  int ilo,ihi,jlo,jhi,klo,khi;
454 
455  /* create gridpoints for simple example: */
456  ni=5;
457  nj=3;
458  nk=2;
459  for (k=0; k < nk; ++k)
460  {
461  for (j=0; j < nj; ++j)
462  {
463  for (i=0; i < ni; ++i)
464  {
465  x1[k][j][i]=i;
466  y1[k][j][i]=j;
467  z1[k][j][i]=k;
468  x2[k][j][i]=x1[k][j][i]+4.;
469  y2[k][j][i]=y1[k][j][i];
470  z2[k][j][i]=z1[k][j][i];
471  }
472  }
473  }
474  printf("\ncreated simple 3-D grid points (2 zones)");
475 
476  /* WRITE X, Y, Z GRID POINTS TO CGNS FILE */
477  /* open CGNS file for write */
478  cg_open("grid_str_2zones.cgns",CG_MODE_WRITE,&index_file);
479  /* create base (user can give any name) */
480  strcpy(basename,"Base");
481  icelldim=3;
482  iphysdim=3;
483  cg_base_write(index_file,basename,icelldim,iphysdim,&index_base);
484  /* vertex size */
485  isize[0][0]=5;
486  isize[0][1]=3;
487  isize[0][2]=2;
488  /* cell size */
489  isize[1][0]=isize[0][0]-1;
490  isize[1][1]=isize[0][1]-1;
491  isize[1][2]=isize[0][2]-1;
492  /* boundary vertex size (always zero for structured grids) */
493  isize[2][0]=0;
494  isize[2][1]=0;
495  isize[2][2]=0;
496  /* define zone 1 name (user can give any name) */
497  strcpy(zonename,"Zone 1");
498  /* create zone */
499  cg_zone_write(index_file,index_base,zonename,*isize,CGNS_ENUMV( Structured ),&index_zone);
500  /* write grid coordinates (user must use SIDS-standard names here) */
501  cg_coord_write(index_file,index_base,index_zone,CGNS_ENUMV( RealDouble ),"CoordinateX",x1,&index_coord);
502  cg_coord_write(index_file,index_base,index_zone,CGNS_ENUMV( RealDouble ),"CoordinateY",y1,&index_coord);
503  cg_coord_write(index_file,index_base,index_zone,CGNS_ENUMV( RealDouble ),"CoordinateZ",z1,&index_coord);
504 
505  ilo=1;
506  ihi=isize[0][0];
507  jlo=1;
508  jhi=isize[0][1];
509  klo=1;
510  khi=isize[0][2];
511  /* write boundary conditions for ilo face, defining range first */
512  /* (user can give any name) */
513  /* lower point of range */
514  ipnts[0][0]=ilo;
515  ipnts[0][1]=jlo;
516  ipnts[0][2]=klo;
517  /* upper point of range */
518  ipnts[1][0]=ilo;
519  ipnts[1][1]=jhi;
520  ipnts[1][2]=khi;
521  cg_boco_write(index_file,index_base,index_zone,"Ilo",CGNS_ENUMV( BCTunnelInflow ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
522  /* write boundary conditions for ihi face, defining range first */
523  /* (user can give any name) */
524  /* lower point of range */
525  ipnts[0][0]=ihi;
526  ipnts[0][1]=jlo;
527  ipnts[0][2]=klo;
528  /* upper point of range */
529  ipnts[1][0]=ihi;
530  ipnts[1][1]=jhi;
531  ipnts[1][2]=khi;
532  cg_boco_write(index_file,index_base,index_zone,"Ihi",CGNS_ENUMV( BCExtrapolate ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
533  /* write boundary conditions for jlo face, defining range first */
534  /* (user can give any name) */
535  /* lower point of range */
536  ipnts[0][0]=ilo;
537  ipnts[0][1]=jlo;
538  ipnts[0][2]=klo;
539  /* upper point of range */
540  ipnts[1][0]=ihi;
541  ipnts[1][1]=jlo;
542  ipnts[1][2]=khi;
543  cg_boco_write(index_file,index_base,index_zone,"Jlo",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
544  /* write boundary conditions for jhi face, defining range first */
545  /* (user can give any name) */
546  /* lower point of range */
547  ipnts[0][0]=ilo;
548  ipnts[0][1]=jhi;
549  ipnts[0][2]=klo;
550  /* upper point of range */
551  ipnts[1][0]=ihi;
552  ipnts[1][1]=jhi;
553  ipnts[1][2]=khi;
554  cg_boco_write(index_file,index_base,index_zone,"Jhi",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
555  /* write boundary conditions for klo face, defining range first */
556  /* (user can give any name) */
557  /* lower point of range */
558  ipnts[0][0]=ilo;
559  ipnts[0][1]=jlo;
560  ipnts[0][2]=klo;
561  /* upper point of range */
562  ipnts[1][0]=ihi;
563  ipnts[1][1]=jhi;
564  ipnts[1][2]=klo;
565  cg_boco_write(index_file,index_base,index_zone,"Klo",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
566  /* write boundary conditions for khi face, defining range first */
567  /* (user can give any name) */
568  /* lower point of range */
569  ipnts[0][0]=ilo;
570  ipnts[0][1]=jlo;
571  ipnts[0][2]=khi;
572  /* upper point of range */
573  ipnts[1][0]=ihi;
574  ipnts[1][1]=jhi;
575  ipnts[1][2]=khi;
576  cg_boco_write(index_file,index_base,index_zone,"Khi",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
577 
578 
579  /* define zone 2 name (user can give any name) */
580  strcpy(zonename,"Zone 2");
581  /* create zone */
582  cg_zone_write(index_file,index_base,zonename,*isize,CGNS_ENUMV( Structured ),&index_zone);
583  /* write grid coordinates (user must use SIDS-standard names here) */
584  cg_coord_write(index_file,index_base,index_zone,CGNS_ENUMV( RealDouble ),"CoordinateX",x2,&index_coord);
585  cg_coord_write(index_file,index_base,index_zone,CGNS_ENUMV( RealDouble ),"CoordinateY",y2,&index_coord);
586  cg_coord_write(index_file,index_base,index_zone,CGNS_ENUMV( RealDouble ),"CoordinateZ",z2,&index_coord);
587 
588 
589  ilo=1;
590  ihi=isize[0][0];
591  jlo=1;
592  jhi=isize[0][1];
593  klo=1;
594  khi=isize[0][2];
595  /* write boundary conditions for ilo face, defining range first */
596  /* (user can give any name) */
597  /* lower point of range */
598  ipnts[0][0]=ilo;
599  ipnts[0][1]=jlo;
600  ipnts[0][2]=klo;
601  /* upper point of range */
602  ipnts[1][0]=ilo;
603  ipnts[1][1]=jhi;
604  ipnts[1][2]=khi;
605  cg_boco_write(index_file,index_base,index_zone,"Ilo",CGNS_ENUMV( BCTunnelInflow ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
606  /* write boundary conditions for ihi face, defining range first */
607  /* (user can give any name) */
608  /* lower point of range */
609  ipnts[0][0]=ihi;
610  ipnts[0][1]=jlo;
611  ipnts[0][2]=klo;
612  /* upper point of range */
613  ipnts[1][0]=ihi;
614  ipnts[1][1]=jhi;
615  ipnts[1][2]=khi;
616  cg_boco_write(index_file,index_base,index_zone,"Ihi",CGNS_ENUMV( BCExtrapolate ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
617  /* write boundary conditions for jlo face, defining range first */
618  /* (user can give any name) */
619  /* lower point of range */
620  ipnts[0][0]=ilo;
621  ipnts[0][1]=jlo;
622  ipnts[0][2]=klo;
623  /* upper point of range */
624  ipnts[1][0]=ihi;
625  ipnts[1][1]=jlo;
626  ipnts[1][2]=khi;
627  cg_boco_write(index_file,index_base,index_zone,"Jlo",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
628  /* write boundary conditions for jhi face, defining range first */
629  /* (user can give any name) */
630  /* lower point of range */
631  ipnts[0][0]=ilo;
632  ipnts[0][1]=jhi;
633  ipnts[0][2]=klo;
634  /* upper point of range */
635  ipnts[1][0]=ihi;
636  ipnts[1][1]=jhi;
637  ipnts[1][2]=khi;
638  cg_boco_write(index_file,index_base,index_zone,"Jhi",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
639  /* write boundary conditions for klo face, defining range first */
640  /* (user can give any name) */
641  /* lower point of range */
642  ipnts[0][0]=ilo;
643  ipnts[0][1]=jlo;
644  ipnts[0][2]=klo;
645  /* upper point of range */
646  ipnts[1][0]=ihi;
647  ipnts[1][1]=jhi;
648  ipnts[1][2]=klo;
649  cg_boco_write(index_file,index_base,index_zone,"Klo",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
650  /* write boundary conditions for khi face, defining range first */
651  /* (user can give any name) */
652  /* lower point of range */
653  ipnts[0][0]=ilo;
654  ipnts[0][1]=jlo;
655  ipnts[0][2]=khi;
656  /* upper point of range */
657  ipnts[1][0]=ihi;
658  ipnts[1][1]=jhi;
659  ipnts[1][2]=khi;
660  cg_boco_write(index_file,index_base,index_zone,"Khi",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
661  /* close CGNS file */
662  cg_close(index_file);
663  printf("\nSuccessfully added BCs (PointRange) to file grid_str_2zones.cgns\n");
664 
665  /* close CGNS file */
666  cg_close(index_file);
667  printf("\nSuccessfully wrote grid to file grid_str_2zones.cgns\n");
668  BOOST_CHECK(true);
669 }
670 
672 
673 BOOST_AUTO_TEST_CASE( ReadUnstructured )
674 {
675  Core::instance().environment().options().set("log_level",(Uint)DEBUG);
676  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.CGNS.Reader","meshreader");
677 
678  // the mesh to store in
679  Mesh& mesh = *Core::instance().root().create_component<Mesh>("grid_c");
680  meshreader->options().set("zone_handling",true);
681  BOOST_CHECK_NO_THROW(meshreader->read_mesh_into("grid_c.cgns",mesh));
682 
683  // Write to gmsh
684  boost::shared_ptr< MeshWriter > gmsh_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
685  BOOST_CHECK_NO_THROW(gmsh_writer->write_from_to(mesh,"grid_c.msh"));
686 
687  // std::cout << mesh.tree() << std::endl;
688  // std::cout << *mesh.access_component_checked("topology/Walls/elements_cf3.mesh.LagrangeP1.Quad3D/spaces/geometry/connectivity")->handle<Connectivity>() << std::endl;
689 
690  // Write to neu
691  boost::shared_ptr< MeshWriter > neu_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.neu.Writer","meshwriter");
692  BOOST_CHECK_NO_THROW(neu_writer->write_from_to(mesh,"grid_c.neu"));
693 
694  // Read from neu
695  boost::shared_ptr< MeshReader > neu_reader = build_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
696  Mesh& mesh_from_neu = *Core::instance().root().create_component<Mesh>("mesh_from_neu");
697  BOOST_CHECK_NO_THROW(neu_reader->read_mesh_into("grid_c.neu",mesh_from_neu));
698 
699  // Write to gmsh
700  BOOST_CHECK_NO_THROW(gmsh_writer->write_from_to(mesh_from_neu,"cgns2neu2gmsh.msh"));
701 
702  //CFinfo << mesh_from_neu->tree() << CFendl;
703  BOOST_CHECK(true);
704 }
706 
707 BOOST_AUTO_TEST_CASE( ReadCGNS_Structured )
708 {
709 
710  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.CGNS.Reader","meshreader");
711 
712  // the mesh to store in
713  Mesh& mesh = *Core::instance().root().create_component<Mesh>("grid_str_2zones");
714  meshreader->read_mesh_into("grid_str_2zones.cgns",mesh);
715 
716  boost::shared_ptr< MeshTransformer > info = build_component_abstract_type<MeshTransformer>("cf3.mesh.actions.Info", "info");
717  info->transform(mesh);
718  // Write to gmsh
719  boost::shared_ptr< MeshWriter > gmsh_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
720  gmsh_writer->write_from_to(mesh,"grid_str_2zones.msh");
721 
722  // Write to neu
723  boost::shared_ptr< MeshWriter > neu_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.neu.Writer","meshwriter");
724  neu_writer->write_from_to(mesh,"grid_str_2zones.neu");
725 
726  // Read from neu
727  boost::shared_ptr< MeshReader > neu_reader = build_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
728  Mesh& mesh_from_neu = *Core::instance().root().create_component<Mesh>("grid_str_2zones_from_neu");
729  neu_reader->read_mesh_into("grid_str_2zones.neu",mesh_from_neu);
730 
731  // Write to gmsh
732  gmsh_writer->write_from_to(mesh_from_neu,"cgns2neu2gmsh_str_2zones.msh");
733 
734 
735 // CFinfo << mesh_from_neu.tree() << CFendl;
736  BOOST_CHECK(true);
737 }
738 
740 
741 BOOST_AUTO_TEST_CASE( WriteCNGS_unstructured )
742 {
743  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.CGNS.Reader","meshreader");
744 
745 
746 
747  // the mesh to store in
748  Mesh& mesh = *Core::instance().root().create_component<Mesh>("grid_c_unstr");
749  meshreader->read_mesh_into("grid_c.cgns",mesh);
750 
751  boost::shared_ptr< MeshWriter > meshwriter = build_component_abstract_type<MeshWriter>("cf3.mesh.CGNS.Writer","meshwriter");
752 
753  meshwriter->write_from_to(mesh,"grid_c2cgns.cgns");
754 
755  Mesh& mesh2 = *Core::instance().root().create_component<Mesh>("grid_c2cgns");
756  meshreader->read_mesh_into("grid_c2cgns.cgns",mesh2);
757 
758  boost::shared_ptr< MeshTransformer > info = build_component_abstract_type<MeshTransformer>("cf3.mesh.actions.Info", "info");
759  //info->transform(mesh2);
760 
761  // Write to gmsh
762  boost::shared_ptr< MeshWriter > gmsh_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
763  gmsh_writer->write_from_to(mesh2,"grid_c2cgns2gmsh.msh");
764  BOOST_CHECK(true);
765 
766 }
767 
769 
770 BOOST_AUTO_TEST_CASE( WriteCNGS_mixed )
771 {
772  boost::shared_ptr< MeshReader > neu_reader = build_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
773 
774  // the mesh to store in
775  Mesh& mesh = *Core::instance().root().create_component<Mesh>("quadtriag_mixed");
776  neu_reader->read_mesh_into("../../resources/quadtriag.neu",mesh);
777 
778  boost::shared_ptr< MeshWriter > meshwriter = build_component_abstract_type<MeshWriter>("cf3.mesh.CGNS.Writer","meshwriter");
779 
780  meshwriter->write_from_to(mesh,"quadtriag2cgns.cgns");
781 
782  boost::shared_ptr< MeshReader > cgns_reader = build_component_abstract_type<MeshReader>("cf3.mesh.CGNS.Reader","meshreader");
783 
784  Mesh& mesh2 = *Core::instance().root().create_component<Mesh>("quadtriag2cgns");
785  cgns_reader->read_mesh_into("quadtriag2cgns.cgns",mesh2);
786 
787  boost::shared_ptr< MeshTransformer > info = build_component_abstract_type<MeshTransformer>("cf3.mesh.actions.Info", "info");
788  info->transform(mesh2);
789 
790  // Write to gmsh
791  boost::shared_ptr< MeshWriter > gmsh_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
792  gmsh_writer->write_from_to(mesh2,"quadtriag2cgns2gmsh.msh");
793  BOOST_CHECK(true);
794 
795 }
796 
798 
799 BOOST_AUTO_TEST_SUITE_END()
800 
801 
#define CALL_CGNS(cgns_func)
Definition: Shared.hpp:28
RealVector create_coord(const Real &x, const Real &y)
possibly common functions used on the tests below
BOOST_AUTO_TEST_CASE(Constructors)
#define NK
#define NJ
external boost library namespace
STL namespace.
Common_API std::string to_str< int >(const int &v)
std::vector< Uint > create_triag(const Uint &A, const Uint &B, const Uint &C)
create a Uint vector with 3 node ID's
Handle< Component const > root() const
Definition: Component.cpp:266
Definition: Defs.hpp:17
Library for I/O of the CGNS format.
std::string xml_config
common values accessed by all tests goes here
Basic Classes for Mesh applications used by COOLFluiD.
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealVector
Dynamic sized column vector.
Definition: MatrixTypes.hpp:25
Top-level namespace for coolfluid.
Definition: Action.cpp:18
std::vector< Uint > create_quad(const Uint &A, const Uint &B, const Uint &C, const Uint &D)
create a Uint vector with 4 node ID's
rapidxml::xml_document< char > doc
#define NI
TestCGNS_Fixture()
common setup for each test case
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
Definition: Defs.hpp:17
OptionList & options()
Definition: Component.cpp:856
~TestCGNS_Fixture()
common tear-down for each test case
void set(const std::string &pname, const boost::any &val)
Definition: OptionList.cpp:132
Most basic kernel library.
Definition: Action.cpp:19
rapidxml::xml_node< char > * parsed_config()
Send comments to:
COOLFluiD Web Admin