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>
16 #include "rapidxml/rapidxml.hpp"
39 using namespace boost;
76 Uint quad[] = {A,B,C,D};
77 std::vector<Uint> quadVec;
78 quadVec.assign(quad,quad+4);
84 Uint triag[] = {A,B,C};
85 std::vector<Uint> triagVec;
86 triagVec.assign(triag,triag+3);
98 ctext = doc.allocate_string(xml_config.c_str());
99 doc.parse< rapidxml::parse_no_data_nodes >(ctext);
100 return doc.first_node();
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");
126 int maxelemi = (
NI-1)*(
NJ-1)*(
NK-1);
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];
139 for (k=1; k <= nk; k++)
141 for (j=1; j <=nj; j++)
143 for (i=1; i <= ni; i++)
155 CALL_CGNS(cg_open(
"grid_c.cgns",CG_MODE_WRITE,&index_file));
157 strcpy(basename,
"Base");
160 CALL_CGNS(cg_base_write(index_file,basename,icelldim,iphysdim,&index_base));
162 strcpy(zonename,
"Zone 1");
164 isize[0][0]=ni*nj*nk;
166 isize[1][0]=(ni-1)*(nj-1)*(nk-1);
170 CALL_CGNS(cg_zone_write(index_file,index_base,zonename,isize[0],CGNS_ENUMV( Unstructured ),&index_zone));
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));
182 for (k=1; k < nk; k++)
184 for (j=1; j < nj; j++)
186 for (i=1; i < ni; i++)
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;
208 if (nelem_end > maxelemi)
210 printf(
"\nError, must increase maxelemi to at least %d\n",nelem_end);
213 std::cout <<
"volume: " << nelem_start <<
" , " << nelem_end << std::endl;
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));
220 int maxelemj = (
NI)*(
NJ)*(
NK);
221 std::cout <<
"maxelemj = " << maxelemj << std::endl;
222 cgsize_t jelem[maxelemj][4];
232 nelem_start=nelem_end+1;
233 int inflow_start = nelem_start;
235 for (k=1; k < nk; k++)
237 for (j=1; j < nj; j++)
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;
248 nelem_end=nelem_start+ielem_no-1;
249 int inflow_last = nelem_end;
250 if (ielem_no > maxelemj)
252 printf(
"\nError, must increase maxelemj to at least %d\n",ielem_no);
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));
261 nelem_start=nelem_end+1;
262 int outflow_start = nelem_start;
264 for (k=1; k < nk; k++)
266 for (j=1; j < nj; j++)
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;
277 nelem_end=nelem_start+ielem_no-1;
278 int outflow_last = nelem_end;
279 if (ielem_no > maxelemj)
281 printf(
"\nError, must increase maxelemj to at least %d\n",ielem_no);
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));
290 nelem_start=nelem_end+1;
291 int side_wall_start = nelem_start;
293 for (k=1; k < nk; k++)
295 for (i=1; i < ni; i++)
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;
306 for (k=1; k < nk; k++)
308 for (i=1; i < ni; i++)
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;
319 for (j=1; j < nj; j++)
321 for (i=1; i < ni; i++)
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;
332 for (j=1; j < nj; j++)
334 for (i=1; i < ni; i++)
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;
345 nelem_end=nelem_start+ielem_no-1;
346 int side_wall_last = nelem_end;
347 if (ielem_no > maxelemj)
349 printf(
"\nError, must increase maxelemj to at least %d\n",ielem_no);
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));
358 int icount,
n, index_bc;
360 cgsize_t ipnts[maxcount];
362 std::cout <<
"inflow: " << inflow_start <<
" , " << inflow_last << std::endl;
363 nelem_start=inflow_start;
364 nelem_end=inflow_last;
366 for (n=nelem_start; n <= nelem_end; n++)
371 if (icount > maxcount)
373 printf(
"\nError. Need to increase maxcount to at least %i\n",icount);
376 CGNS_ENUMT( PointSetType_t ) bc_type = CGNS_ENUMV( ElementList );
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;
385 std::cout <<
"outflow: " << outflow_start <<
" , " << outflow_last << std::endl;
386 nelem_start=outflow_start;
387 nelem_end=outflow_last;
389 for (n=nelem_start; n <= nelem_end; n++)
394 if (icount > maxcount)
396 printf(
"\nError. Need to increase maxcount to at least %i\n",icount);
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;
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;
410 for (n=nelem_start; n <= nelem_end; n++)
415 if (icount > maxcount)
417 printf(
"\nError. Need to increase maxcount to at least %i\n",icount);
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;
429 std::cout <<
"\nSuccessfully wrote unstructured grid to file grid_c.cgns"<< std::endl;
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];
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;
459 for (k=0; k < nk; ++
k)
461 for (j=0; j < nj; ++j)
463 for (i=0; i < ni; ++i)
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];
474 printf(
"\ncreated simple 3-D grid points (2 zones)");
478 cg_open(
"grid_str_2zones.cgns",CG_MODE_WRITE,&index_file);
480 strcpy(basename,
"Base");
483 cg_base_write(index_file,basename,icelldim,iphysdim,&index_base);
489 isize[1][0]=isize[0][0]-1;
490 isize[1][1]=isize[0][1]-1;
491 isize[1][2]=isize[0][2]-1;
497 strcpy(zonename,
"Zone 1");
499 cg_zone_write(index_file,index_base,zonename,*isize,CGNS_ENUMV( Structured ),&index_zone);
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);
521 cg_boco_write(index_file,index_base,index_zone,
"Ilo",CGNS_ENUMV( BCTunnelInflow ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
532 cg_boco_write(index_file,index_base,index_zone,
"Ihi",CGNS_ENUMV( BCExtrapolate ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
543 cg_boco_write(index_file,index_base,index_zone,
"Jlo",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
554 cg_boco_write(index_file,index_base,index_zone,
"Jhi",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
565 cg_boco_write(index_file,index_base,index_zone,
"Klo",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
576 cg_boco_write(index_file,index_base,index_zone,
"Khi",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
580 strcpy(zonename,
"Zone 2");
582 cg_zone_write(index_file,index_base,zonename,*isize,CGNS_ENUMV( Structured ),&index_zone);
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);
605 cg_boco_write(index_file,index_base,index_zone,
"Ilo",CGNS_ENUMV( BCTunnelInflow ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
616 cg_boco_write(index_file,index_base,index_zone,
"Ihi",CGNS_ENUMV( BCExtrapolate ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
627 cg_boco_write(index_file,index_base,index_zone,
"Jlo",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
638 cg_boco_write(index_file,index_base,index_zone,
"Jhi",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
649 cg_boco_write(index_file,index_base,index_zone,
"Klo",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
660 cg_boco_write(index_file,index_base,index_zone,
"Khi",CGNS_ENUMV( BCWallInviscid ),CGNS_ENUMV( PointRange ),2,ipnts[0],&index_bc);
662 cg_close(index_file);
663 printf(
"\nSuccessfully added BCs (PointRange) to file grid_str_2zones.cgns\n");
666 cg_close(index_file);
667 printf(
"\nSuccessfully wrote grid to file grid_str_2zones.cgns\n");
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");
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));
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"));
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"));
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));
700 BOOST_CHECK_NO_THROW(gmsh_writer->write_from_to(mesh_from_neu,
"cgns2neu2gmsh.msh"));
710 boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>(
"cf3.mesh.CGNS.Reader",
"meshreader");
713 Mesh&
mesh = *Core::instance().root().create_component<
Mesh>(
"grid_str_2zones");
714 meshreader->read_mesh_into(
"grid_str_2zones.cgns",mesh);
716 boost::shared_ptr< MeshTransformer > info = build_component_abstract_type<MeshTransformer>(
"cf3.mesh.actions.Info",
"info");
717 info->transform(mesh);
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");
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");
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);
732 gmsh_writer->write_from_to(mesh_from_neu,
"cgns2neu2gmsh_str_2zones.msh");
743 boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>(
"cf3.mesh.CGNS.Reader",
"meshreader");
748 Mesh&
mesh = *Core::instance().root().create_component<
Mesh>(
"grid_c_unstr");
749 meshreader->read_mesh_into(
"grid_c.cgns",mesh);
751 boost::shared_ptr< MeshWriter > meshwriter = build_component_abstract_type<MeshWriter>(
"cf3.mesh.CGNS.Writer",
"meshwriter");
753 meshwriter->write_from_to(mesh,
"grid_c2cgns.cgns");
755 Mesh& mesh2 = *Core::instance().
root().create_component<
Mesh>(
"grid_c2cgns");
756 meshreader->read_mesh_into(
"grid_c2cgns.cgns",mesh2);
758 boost::shared_ptr< MeshTransformer > info = build_component_abstract_type<MeshTransformer>(
"cf3.mesh.actions.Info",
"info");
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");
772 boost::shared_ptr< MeshReader > neu_reader = build_component_abstract_type<MeshReader>(
"cf3.mesh.neu.Reader",
"meshreader");
775 Mesh&
mesh = *Core::instance().root().create_component<
Mesh>(
"quadtriag_mixed");
776 neu_reader->read_mesh_into(
"../../resources/quadtriag.neu",mesh);
778 boost::shared_ptr< MeshWriter > meshwriter = build_component_abstract_type<MeshWriter>(
"cf3.mesh.CGNS.Writer",
"meshwriter");
780 meshwriter->write_from_to(mesh,
"quadtriag2cgns.cgns");
782 boost::shared_ptr< MeshReader > cgns_reader = build_component_abstract_type<MeshReader>(
"cf3.mesh.CGNS.Reader",
"meshreader");
784 Mesh& mesh2 = *Core::instance().
root().create_component<
Mesh>(
"quadtriag2cgns");
785 cgns_reader->read_mesh_into(
"quadtriag2cgns.cgns",mesh2);
787 boost::shared_ptr< MeshTransformer > info = build_component_abstract_type<MeshTransformer>(
"cf3.mesh.actions.Info",
"info");
788 info->transform(mesh2);
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");
799 BOOST_AUTO_TEST_SUITE_END()
#define CALL_CGNS(cgns_func)
RealVector create_coord(const Real &x, const Real &y)
possibly common functions used on the tests below
BOOST_AUTO_TEST_CASE(Constructors)
external boost library 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
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.
Top-level namespace for coolfluid.
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
TestCGNS_Fixture()
common setup for each test case
unsigned int Uint
typedef for unsigned int
~TestCGNS_Fixture()
common tear-down for each test case
void set(const std::string &pname, const boost::any &val)
Most basic kernel library.
rapidxml::xml_node< char > * parsed_config()