Export CGNS files. More...
#include <WriteCGNS.hpp>
Classes | |
class | SetStruct |
Public Member Functions | |
WriteCGNS (Interface *impl) | |
Constructor. More... | |
virtual | ~WriteCGNS () |
Destructor. More... | |
ErrorCode | write_file (const char *file_name, const bool overwrite, const FileOptions &opts, const EntityHandle *output_list, const int num_sets, const std::vector< std::string > &qa_list, const Tag *tag_list=NULL, int num_tags=0, int export_dimension=3) |
writes out a file More... | |
ErrorCode | get_vertex_entities (cgsize_t &VrtSize, std::vector< moab::EntityHandle > &Nodes) |
ErrorCode | get_edge_entities (cgsize_t &EdgeSize, std::vector< moab::EntityHandle > &Edges) |
ErrorCode | get_face_entities (cgsize_t &FaceSize, std::vector< moab::EntityHandle > &Faces) |
ErrorCode | get_cell_entities (cgsize_t &CellSize, std::vector< moab::EntityHandle > &Cells) |
ErrorCode | write_coord_cgns (std::vector< moab::EntityHandle > &nodes) |
ErrorCode | set_tag_values (std::vector< moab::Tag > &TagHandles, std::vector< moab::EntityHandle > &Edges, std::vector< moab::EntityHandle > &Faces, std::vector< moab::EntityHandle > &Cells, std::vector< WriteCGNS::SetStruct > &Sets) |
ErrorCode | get_set_entities (int i, std::vector< moab::Tag > &TagHandles, std::vector< WriteCGNS::SetStruct > &Sets) |
ErrorCode | get_cgns_type (int i, std::vector< WriteCGNS::SetStruct > &Sets) |
ErrorCode | get_conn_table (std::vector< moab::EntityHandle > &Elements, std::vector< int > &Begin, std::vector< int > &End, std::vector< moab::Tag > &TagHandles, std::vector< WriteCGNS::SetStruct > &Sets, std::vector< std::vector< cgsize_t > > &ConnTable) |
int | moab_cgns_conv (const EntityHandle handle) |
![]() | |
virtual | ~WriterIface () |
Static Public Member Functions | |
static WriterIface * | factory (Interface *) |
factory method More... | |
Private Attributes | |
Interface * | mbImpl |
WriteUtilIface * | mWriteIface |
const char * | fileName |
int | IndexFile |
const char * | BaseName |
int | IndexBase |
const char * | ZoneName |
int | IndexZone |
int | IndexSection |
int | IndexCoord [3] |
int | celldim |
int | physdim |
cgsize_t | isize [3] |
std::vector< moab::EntityHandle > | Nodes |
std::vector< moab::EntityHandle > | Edges |
std::vector< moab::EntityHandle > | Faces |
std::vector< moab::EntityHandle > | Cells |
cgsize_t | VrtSize |
cgsize_t | EdgeSize |
cgsize_t | FaceSize |
cgsize_t | CellSize |
Export CGNS files.
Definition at line 46 of file WriteCGNS.hpp.
moab::WriteCGNS::WriteCGNS | ( | Interface * | impl | ) |
Constructor.
Definition at line 25 of file WriteCGNS.cpp.
26 : mbImpl( impl ), fileName( NULL ), IndexFile( 0 ), BaseName( NULL ), IndexBase( 0 ), ZoneName( NULL ),
27 IndexZone( 0 ), IndexSection( 0 ), celldim( 0 ), physdim( 0 ), VrtSize( 0 ), EdgeSize( 0 ), FaceSize( 0 ),
28 CellSize( 0 )
29 {
30 impl->query_interface( mWriteIface );
31 IndexCoord[0] = IndexCoord[1] = IndexCoord[2] = 0;
32 isize[0] = isize[1] = isize[2] = 0;
33 }
References IndexCoord, isize, mWriteIface, and moab::Interface::query_interface().
Referenced by factory().
|
virtual |
Destructor.
Definition at line 35 of file WriteCGNS.cpp.
36 { 37 mbImpl->release_interface( mWriteIface ); 38 }
References mbImpl, mWriteIface, and moab::Interface::release_interface().
|
static |
factory method
Definition at line 20 of file WriteCGNS.cpp.
21 {
22 return new WriteCGNS( iface );
23 }
References iface, and WriteCGNS().
Referenced by moab::ReaderWriterSet::ReaderWriterSet().
ErrorCode moab::WriteCGNS::get_cell_entities | ( | cgsize_t & | CellSize, |
std::vector< moab::EntityHandle > & | Cells | ||
) |
Definition at line 337 of file WriteCGNS.cpp.
338 {
339 ErrorCode rval;
340 // The first input is 0 because one queries the entire mesh.
341 // Get all entities of dimension = 3 in Cell
342 rval = mbImpl->get_entities_by_dimension( 0, 3, Cells_, false );
343 if( Cells_.size() )
344 {
345 celldim = 3;
346 physdim = 3;
347 // get the amout of volumes
348 CellSize_ = Cells_.size();
349 }
350 // done
351 return rval;
352 }
References celldim, ErrorCode, moab::Interface::get_entities_by_dimension(), mbImpl, and physdim.
Referenced by write_file().
ErrorCode moab::WriteCGNS::get_cgns_type | ( | int | i, |
std::vector< WriteCGNS::SetStruct > & | Sets | ||
) |
Definition at line 637 of file WriteCGNS.cpp.
638 {
639 std::vector< int > Test;
640 int Sum = 0;
641
642 // NbEntities is a vector which has the number of entities of each type
643 // 0-MBEDGE | 1-MBTRI | 2-MBQUAD | 3-MBTET | 4-MBPYRAMID | 5-MBPRISM | 6-MBHEX
644 // if NbEntities[i]>0 then Test[i]=1
645 // else then Test[i]=0
646 for( int j = 0; j < (int)Sets[i].NbEntities.size(); ++j )
647 {
648 if( Sets[i].NbEntities[j] > 0 )
649 {
650 Test.push_back( 1 );
651 Sum++;
652 }
653 else
654 {
655 Test.push_back( 0 );
656 }
657 }
658
659 // Test the Sum
660 // if Sum > 1 then the Set is MIXED
661 // if Sum = 0 then the Set is Homogeneous
662 // else then the Set is empty
663 if( Sum > 1 )
664 {
665 Sets[i].CGNSType = MIXED;
666 }
667 else if( Sum == 1 )
668 {
669 int j = 0;
670 std::cout << "Homogeneous Type\n";
671 while( j < (int)Sets[i].NbEntities.size() && Sets[i].NbEntities[j] != 1 )
672 {
673 ++j;
674 }
675 switch( j )
676 {
677 case 0:
678 Sets[i].CGNSType = BAR_2;
679 break;
680 case 1:
681 Sets[i].CGNSType = TRI_3;
682 break;
683 case 2:
684 Sets[i].CGNSType = QUAD_4;
685 break;
686 case 3:
687 Sets[i].CGNSType = TETRA_4;
688 break;
689 case 4:
690 Sets[i].CGNSType = PYRA_5;
691 break;
692 case 5:
693 Sets[i].CGNSType = PENTA_6;
694 break;
695 case 6:
696 Sets[i].CGNSType = HEXA_8;
697 break;
698 default:
699 std::cout << "It was not possible to identify the CGNSType\n";
700 return MB_FAILURE;
701 }
702 }
703 else
704 {
705 Sets[i].CGNSType = ElementTypeNull;
706 } // NOT SURE IF THAT'S THE RIGHT WAY.......
707
708 // Clear the test vector
709 Test.clear();
710
711 return MB_SUCCESS;
712 }
References MB_SUCCESS.
Referenced by set_tag_values().
ErrorCode moab::WriteCGNS::get_conn_table | ( | std::vector< moab::EntityHandle > & | Elements, |
std::vector< int > & | Begin, | ||
std::vector< int > & | End, | ||
std::vector< moab::Tag > & | TagHandles, | ||
std::vector< WriteCGNS::SetStruct > & | Sets, | ||
std::vector< std::vector< cgsize_t > > & | ConnTable | ||
) |
Definition at line 715 of file WriteCGNS.cpp.
721 {
722 ErrorCode rval;
723
724 // int Begin = 0; // GOT TO WORK ON THIS
725 // int End;
726
727 // Get the number of Tags in the mesh
728 int NbTags = TagHandles.size();
729
730 // Test all Elements, get their ids and connectivity
731 // to fill ConnTable
732 for( std::vector< moab::EntityHandle >::iterator i = Elements.begin(); i != Elements.end(); ++i )
733 {
734 int id;
735 // Test all Tags
736 for( int j = 0; j < NbTags; ++j )
737 {
738 // Test if the Tag has data
739 if( Sets[j].IdSet != -1 )
740 {
741 // Try to get data from entity
742 rval = mbImpl->tag_get_data( TagHandles[j], &*i, 1, &id );
743 if( MB_SUCCESS != rval )
744 {
745 return rval;
746 }
747 // If successful id==j
748 if( id == j )
749 {
750 // Get the entity type of the EntityHandle wich points to Cells
751 int num_vtx; // Number of MeshVertices in array connectivity.
752 const EntityHandle* conn; // Array in which connectivity of entity_handle is returned.
753 // Gets a pointer to constant connectivity data of entity_handle
754 rval = mbImpl->get_connectivity( *i, conn, num_vtx );
755 if( MB_SUCCESS != rval )
756 {
757 return rval;
758 }
759 // If the Set is MIXED type
760 // push CGNS ENUM type of the entity
761 // before the connectivity
762 if( Sets[j].CGNSType == MIXED )
763 {
764 ConnTable[j].push_back( moab_cgns_conv( *i ) ); // moab_cgns_conv return an int which
765 // represents the CGNS type
766 Begin[j]++;
767 }
768 End[j] = Begin[j] + num_vtx;
769 // Push conn in ConnTable in which "j" is the Set Index
770 for( int k = Begin[j]; k < End[j]; ++k )
771 {
772 ConnTable[j].push_back( (cgsize_t)conn[k - Begin[j]] );
773 }
774 Begin[j] = End[j];
775 }
776 }
777 }
778 }
779 return MB_SUCCESS;
780 }
References cgsize_t, ErrorCode, moab::Interface::get_connectivity(), MB_SUCCESS, mbImpl, moab_cgns_conv(), and moab::Interface::tag_get_data().
Referenced by write_file().
ErrorCode moab::WriteCGNS::get_edge_entities | ( | cgsize_t & | EdgeSize, |
std::vector< moab::EntityHandle > & | Edges | ||
) |
Definition at line 301 of file WriteCGNS.cpp.
302 {
303 ErrorCode rval;
304 // The first input is 0 because one queries the entire mesh.
305 // Get all entities of dimension = 1 in Edges
306 rval = mbImpl->get_entities_by_dimension( 0, 1, Edges_, false );
307 if( Edges_.size() > 0 )
308 {
309 celldim = 1;
310 physdim = 1;
311 // get the amout of edges
312 EdgeSize_ = Edges_.size();
313 }
314 // done
315 return rval;
316 }
References celldim, ErrorCode, moab::Interface::get_entities_by_dimension(), mbImpl, and physdim.
Referenced by write_file().
ErrorCode moab::WriteCGNS::get_face_entities | ( | cgsize_t & | FaceSize, |
std::vector< moab::EntityHandle > & | Faces | ||
) |
Definition at line 319 of file WriteCGNS.cpp.
320 {
321 ErrorCode rval;
322 // The first input is 0 because one queries the entire mesh.
323 // Get all entities of dimension = 2 in Faces
324 rval = mbImpl->get_entities_by_dimension( 0, 2, Faces_, false );
325 if( Faces_.size() )
326 {
327 celldim = 2;
328 physdim = 2;
329 // get the amout of faces
330 FaceSize_ = Faces_.size();
331 }
332 // done
333 return rval;
334 }
References celldim, ErrorCode, moab::Interface::get_entities_by_dimension(), mbImpl, and physdim.
Referenced by write_file().
ErrorCode moab::WriteCGNS::get_set_entities | ( | int | i, |
std::vector< moab::Tag > & | TagHandles, | ||
std::vector< WriteCGNS::SetStruct > & | Sets | ||
) |
Definition at line 532 of file WriteCGNS.cpp.
535 {
536 ErrorCode rval;
537
538 // Get the number of MBEDGE entities
539 // NbEntities[0] holds the number of MBEDGE in the "Sets"
540 int Number = 0;
541 rval = mbImpl->get_number_entities_by_type_and_tag( 0, MBEDGE, &TagHandles[i], 0, 1, Number );
542 if( rval != MB_SUCCESS )
543 {
544 std::cout << "Problem to get the number of entities by type and tag\n";
545 return rval;
546 }
547 Sets[i].NbEntities.push_back( Number ); // MBEDGE == Sets[i].NbEntities[0]
548 Sets[i].NbEdges += Number;
549 std::cout << "\tNumber of MBEDGE = " << Number << "\n";
550
551 // Get the number of MBTRI entities
552 // NbEntities[1] holds the number of MBTRI in the "Sets"
553 Number = 0;
554 rval = mbImpl->get_number_entities_by_type_and_tag( 0, MBTRI, &TagHandles[i], 0, 1, Number );
555 if( rval != MB_SUCCESS )
556 {
557 std::cout << "Problem to get the number of entities by type and tag\n";
558 return rval;
559 }
560 Sets[i].NbEntities.push_back( Number ); // MBTRI == Sets[i].NbEntities[1]
561 Sets[i].NbFaces += Number;
562 std::cout << "\tNumber of MBTRI = " << Number << "\n";
563
564 // Get the number of MBQUAD entities
565 // NbEntities[2] holds the number of MBQUAD in the "Sets"
566 Number = 0;
567 rval = mbImpl->get_number_entities_by_type_and_tag( 0, MBQUAD, &TagHandles[i], 0, 1, Number );
568 if( rval != MB_SUCCESS )
569 {
570 std::cout << "Problem to get the number of entities by type and tag\n";
571 return rval;
572 }
573 Sets[i].NbEntities.push_back( Number ); // MBQUAD == Sets[i].NbEntities[2]
574 Sets[i].NbFaces += Number;
575 std::cout << "\tNumber of MBQUAD = " << Number << "\n";
576
577 // Get the number of MBTET entities
578 // NbEntities[3] holds the number of MBTET in the "Sets"
579 Number = 0;
580 rval = mbImpl->get_number_entities_by_type_and_tag( 0, MBTET, &TagHandles[i], 0, 1, Number );
581 if( rval != MB_SUCCESS )
582 {
583 std::cout << "Problem to get the number of entities by type and tag\n";
584 return rval;
585 }
586 Sets[i].NbEntities.push_back( Number ); // MBTET == Sets[i].NbEntities[3]
587 Sets[i].NbCells += Number;
588 std::cout << "\tNumber of MBTET = " << Number << "\n";
589
590 // Get the number of MBPYRAMID entities
591 // NbEntities[4] holds the number of MBPYRAMID in the "Sets"
592 Number = 0;
593 rval = mbImpl->get_number_entities_by_type_and_tag( 0, MBPYRAMID, &TagHandles[i], 0, 1, Number );
594 if( rval != MB_SUCCESS )
595 {
596 std::cout << "Problem to get the number of entities by type and tag\n";
597 return rval;
598 }
599 Sets[i].NbEntities.push_back( Number ); // MBPYRAMID == Sets[i].NbEntities[4]
600 Sets[i].NbCells += Number;
601 std::cout << "\tNumber of MBPYRAMID = " << Number << "\n";
602
603 // Get the number of MBPRISM entities - MBPRISM == PENTA_6
604 // NbEntities[5] holds the number of MBPRISM in the "Sets"
605 Number = 0;
606 rval = mbImpl->get_number_entities_by_type_and_tag( 0, MBPRISM, &TagHandles[i], 0, 1, Number );
607 if( rval != MB_SUCCESS )
608 {
609 std::cout << "Problem to get the number of entities by type and tag\n";
610 return rval;
611 }
612 Sets[i].NbEntities.push_back( Number ); // MBPRISM == Sets[i].NbEntities[5]
613 Sets[i].NbCells += Number;
614 std::cout << "\tNumber of MBPRISM = " << Number << "\n";
615
616 // Get the number of MBHEX entities
617 // NbEntities[6] holds the number of MBHEX in the "Sets"
618 Number = 0;
619 rval = mbImpl->get_number_entities_by_type_and_tag( 0, MBHEX, &TagHandles[i], 0, 1, Number );
620 if( rval != MB_SUCCESS )
621 {
622 std::cout << "Problem to get the number of entities by type and tag\n";
623 return rval;
624 }
625 Sets[i].NbEntities.push_back( Number ); // MBHEX == Sets[i].NbEntities[6]
626 Sets[i].NbCells += Number;
627 std::cout << "\tNumber of MBHEX = " << Number << "\n";
628
629 std::cout << "\tTotal number of Edges = " << Sets[i].NbEdges << "\n";
630 std::cout << "\tTotal number of Faces = " << Sets[i].NbFaces << "\n";
631 std::cout << "\tTotal number of Cells = " << Sets[i].NbCells << "\n";
632
633 return MB_SUCCESS;
634 }
References ErrorCode, moab::Interface::get_number_entities_by_type_and_tag(), MB_SUCCESS, MBEDGE, MBHEX, mbImpl, MBPRISM, MBPYRAMID, MBQUAD, MBTET, and MBTRI.
Referenced by set_tag_values().
ErrorCode moab::WriteCGNS::get_vertex_entities | ( | cgsize_t & | VrtSize, |
std::vector< moab::EntityHandle > & | Nodes | ||
) |
Definition at line 278 of file WriteCGNS.cpp.
279 {
280 ErrorCode rval;
281 // Get vertex entities
282 // The first input is 0 because one queries the entire mesh.
283 // Retrieves all entities of dimension = 0 in "Nodes"
284 rval = mbImpl->get_entities_by_dimension( 0, 0, Nodes_, false );
285 if( Nodes.size() > 0 )
286 {
287 celldim = 0;
288 physdim = 0;
289 // get the amout of vertex
290 VrtSize_ = Nodes_.size();
291 }
292 else
293 {
294 std::cout << "The mesh has not node points.\n";
295 }
296 // done
297 return rval;
298 }
References celldim, ErrorCode, moab::Interface::get_entities_by_dimension(), mbImpl, Nodes, and physdim.
Referenced by write_file().
int moab::WriteCGNS::moab_cgns_conv | ( | const EntityHandle | handle | ) |
< Mesh Edge
< Triangular element (including shells)
< Quadrilateral element (including shells)
< Tetrahedral element
< Pyramid element
< Wedge element
< Hexahedral element
Definition at line 783 of file WriteCGNS.cpp.
784 {
785 EntityType MoabType = mbImpl->type_from_handle( handle );
786 switch( MoabType )
787 {
788 case MBEDGE: /**< Mesh Edge */
789 return BAR_2;
790 case MBTRI: /**< Triangular element (including shells) */
791 return TRI_3;
792 case MBQUAD: /**< Quadrilateral element (including shells) */
793 return QUAD_4;
794 case MBTET: /**< Tetrahedral element */
795 return TETRA_4;
796 case MBPYRAMID: /**< Pyramid element */
797 return PYRA_5;
798 case MBPRISM: /**< Wedge element */
799 return PENTA_6;
800 case MBHEX: /**< Hexahedral element */
801 return HEXA_8;
802 default:
803 std::cout << "It was not possible to identify the CGNSType\n";
804 return 0;
805 }
806 }
References MBEDGE, MBHEX, mbImpl, MBPRISM, MBPYRAMID, MBQUAD, MBTET, MBTRI, and moab::Interface::type_from_handle().
Referenced by get_conn_table().
ErrorCode moab::WriteCGNS::set_tag_values | ( | std::vector< moab::Tag > & | TagHandles, |
std::vector< moab::EntityHandle > & | Edges, | ||
std::vector< moab::EntityHandle > & | Faces, | ||
std::vector< moab::EntityHandle > & | Cells, | ||
std::vector< WriteCGNS::SetStruct > & | Sets | ||
) |
Definition at line 438 of file WriteCGNS.cpp.
443 {
444 ErrorCode rval;
445
446 // Get the number of Tags in the mesh
447 int NbTags = TagHandles.size();
448
449 // Loop over all Tags
450 for( int i = 0; i < NbTags; ++i )
451 {
452
453 // Allocate another position in the vector of SetStruct using a default constructor
454 Sets.push_back( SetStruct() );
455
456 // Get the Tag name
457 rval = mbImpl->tag_get_name( TagHandles[i], Sets[i].TagName );
458 if( rval != MB_SUCCESS )
459 {
460 std::cout << "Problem to get Tag Name\n";
461 return rval;
462 }
463 std::cout << "Tag name= " << Sets[i].TagName << "\n";
464
465 // Count all entities by type and put in Sets[i].NbEntities vector
466 rval = get_set_entities( i, TagHandles, Sets );
467 if( rval != MB_SUCCESS )
468 {
469 std::cout << "Problem to get Set entities\n";
470 return rval;
471 }
472
473 // Get the CGNSTYpe of the Set
474 rval = get_cgns_type( i, Sets );
475 if( rval != MB_SUCCESS )
476 {
477 std::cout << "Problem to get CGNSType\n";
478 return rval;
479 }
480 std::cout << "\tSets[" << i << "].CGNSType= " << Sets[i].CGNSType << "\n";
481
482 // int Number;
483
484 // Set a data index for Edges and TagHandles[i]
485 if( Sets[i].CGNSType == BAR_2 || Sets[i].CGNSType == TRI_3 || Sets[i].CGNSType == QUAD_4 ||
486 Sets[i].CGNSType == TETRA_4 || Sets[i].CGNSType == PYRA_5 || Sets[i].CGNSType == PENTA_6 ||
487 Sets[i].CGNSType == HEXA_8 || Sets[i].CGNSType == MIXED )
488 {
489
490 if( Sets[i].NbEdges > 0 && physdim < 3 )
491 {
492 // Set a data index for Edges and TagHandles[i]
493 const std::vector< int > tag_values( Edges_.size(), i );
494 rval = mbImpl->tag_set_data( TagHandles[i], &Edges_[0], Edges_.size(), &tag_values[0] );
495 if( rval != MB_SUCCESS )
496 {
497 std::cout << "Problem to set data for 1-D entities\n";
498 return rval;
499 }
500 }
501 if( Sets[i].NbFaces > 0 && physdim > 1 )
502 {
503 // Set a data index for Faces and TagHandles[i]
504 const std::vector< int > tag_values( Faces.size(), i );
505 rval = mbImpl->tag_set_data( TagHandles[i], &Faces_[0], Faces_.size(), &tag_values[0] );
506 if( rval != MB_SUCCESS )
507 {
508 std::cout << "Problem to set data for 2-D entities\n";
509 return rval;
510 }
511 }
512 if( Sets[i].NbCells > 0 && physdim > 2 )
513 {
514 // Set a data index for Cells and TagHandles[i]
515 const std::vector< int > tag_values( Cells.size(), i );
516 rval = mbImpl->tag_set_data( TagHandles[i], &Cells_[0], Cells_.size(), &tag_values[0] );
517 if( rval != MB_SUCCESS )
518 {
519 std::cout << "Problem to set data for 3-D entities\n";
520 return rval;
521 }
522 }
523 // IdSet gets the Set Index indicating that it is not empty
524 Sets[i].IdSet = i;
525 }
526 std::cout << "\tSets[" << i << "].IdSet = " << Sets[i].IdSet << "\n\n";
527 }
528 return MB_SUCCESS;
529 }
References Cells, ErrorCode, Faces, get_cgns_type(), get_set_entities(), MB_SUCCESS, mbImpl, physdim, moab::Interface::tag_get_name(), and moab::Interface::tag_set_data().
Referenced by write_file().
ErrorCode moab::WriteCGNS::write_coord_cgns | ( | std::vector< moab::EntityHandle > & | nodes | ) |
Definition at line 354 of file WriteCGNS.cpp.
355 {
356 ErrorCode rval;
357
358 const int num_entities = (int)Nodes_.size();
359
360 // Moab works with one vector for the threee coordinates
361 std::vector< double > Coords( 3 * num_entities );
362 std::vector< double >::iterator c = Coords.begin();
363
364 // CGNS uses one vector for each coordinate
365 std::vector< double > CoordX;
366 std::vector< double > CoordY;
367 std::vector< double > CoordZ;
368
369 // Summ the values of all coordinates to be sure if it is not zero
370 double SumX = 0;
371 double SumY = 0;
372 double SumZ = 0;
373
374 // Get the moab coordinates - Coords is the output
375 rval = mbImpl->get_coords( &Nodes_[0], num_entities, &Coords[0] );
376 if( MB_SUCCESS != rval )
377 {
378 std::cout << "Error getting coordinates from nodes.\n";
379 return rval;
380 }
381
382 // Reserve the size of nodes
383 CoordX.reserve( Nodes_.size() );
384 CoordY.reserve( Nodes_.size() );
385 CoordZ.reserve( Nodes_.size() );
386
387 for( std::vector< moab::EntityHandle >::iterator i = Nodes_.begin(); i != Nodes_.end(); ++i )
388 {
389 CoordX.push_back( *c ); // Put the X coordinate in CoordX vector
390 SumX += abs( *c ); // Sum all X coordinates
391 ++c; // Move to Y coordinate
392 CoordY.push_back( *c ); // Put the Y coordinate in CoordY vector
393 SumY += abs( *c ); // Sum all Y coordinates
394 ++c; // Move to Z coordinate
395 CoordZ.push_back( *c ); // Put the Z coordinate in CoordZ vector
396 SumZ += abs( *c ); // Sum all Z coordinates
397 ++c; // Move to X coordinate
398 }
399
400 // If X coordinate is not empty then write CoordX (user must use SIDS-standard names here)
401 if( SumX != 0 )
402 {
403 if( cg_coord_write( IndexFile, IndexBase, IndexZone, RealDouble, "CoordinateX", &CoordX[0], &IndexCoord[0] ) )
404 {
405 std::cout << " Error writing X coordinates.\n";
406 cg_error_exit();
407 }
408 }
409 // If Y coordinate is not empty then write CoordY (user must use SIDS-standard names here)
410 if( SumY != 0 )
411 {
412 if( cg_coord_write( IndexFile, IndexBase, IndexZone, RealDouble, "CoordinateY", &CoordY[0], &IndexCoord[1] ) )
413 {
414 std::cout << " Error writing Y coordinates.\n";
415 cg_error_exit();
416 }
417 }
418 // If Z coordinate is not empty then write CoordZ (user must use SIDS-standard names here)
419 if( SumZ != 0 )
420 {
421 if( cg_coord_write( IndexFile, IndexBase, IndexZone, RealDouble, "CoordinateZ", &CoordZ[0], &IndexCoord[2] ) )
422 {
423 std::cout << " Error writing Z coordinates.\n";
424 cg_error_exit();
425 }
426 }
427
428 // Clear vectors
429 Coords.clear();
430 CoordX.clear();
431 CoordY.clear();
432 CoordZ.clear();
433
434 // done
435 return MB_SUCCESS;
436 }
References ErrorCode, moab::Interface::get_coords(), IndexBase, IndexCoord, IndexFile, IndexZone, MB_SUCCESS, and mbImpl.
Referenced by write_file().
|
virtual |
writes out a file
Implements moab::WriterIface.
Definition at line 41 of file WriteCGNS.cpp.
50 {
51 ErrorCode rval;
52
53 if( !overwrite )
54 {
55 rval = mWriteIface->check_doesnt_exist( file_name );
56 if( MB_SUCCESS != rval ) return rval;
57 }
58 std::cout << "THE CGNS CONVERSION ONLY WORKS FOR ENTITIES CITED BELOW:";
59 std::cout << "\n -MBVERTEX\n -MBEDGE\n -MBTRI\n -MBQUAD";
60 std::cout << "\n -MBTET\n -MBPYRAMID\n -MBHEX\n";
61
62 // Get entities to write
63 // Get and count vertex entities
64 rval = get_vertex_entities( VrtSize, Nodes );
65 if( rval != MB_SUCCESS )
66 {
67 return rval;
68 }
69 // Get and count edge entities
70 rval = get_edge_entities( EdgeSize, Edges );
71 if( rval != MB_SUCCESS )
72 {
73 return rval;
74 }
75 // Get and count face entities
76 rval = get_face_entities( FaceSize, Faces );
77 if( rval != MB_SUCCESS )
78 {
79 return rval;
80 }
81 // Get and count cell entities
82 rval = get_cell_entities( CellSize, Cells );
83 if( rval != MB_SUCCESS )
84 {
85 return rval;
86 }
87 std::cout << "\nThe Number of Vertex is " << VrtSize << ".\n";
88 std::cout << "The Number of Edges is " << EdgeSize << ".\n";
89 std::cout << "The Number of Faces is " << FaceSize << ".\n";
90 std::cout << "The Number of Cells is " << CellSize << ".\n\n";
91
92 // save filename to member variable so we don't need to pass as an argument
93 // to called functions
94 fileName = file_name;
95 std::cout << fileName << " file is a " << physdim << "-D mesh.\n";
96
97 // Open file
98 IndexFile = 0;
99
100 // open the cgns file
101 // filename: (input) Name of the CGNS file, including path name if necessary. There is no
102 // limit on the
103 // length of this character variable.
104 // CG_MODE_WRITE: (input) Mode used for opening the file. The modes currently supported are
105 // CG_MODE_READ,
106 // CG_MODE_WRITE, and CG_MODE_MODIFY.
107 // filePtr: (output) CGNS file index number.
108 if( cg_open( fileName, CG_MODE_WRITE, &IndexFile ) )
109 {
110 std::cout << "Error opening file\n";
111 cg_error_exit();
112 }
113 // Give a base name
114 BaseName = "Cgns Base";
115 if( cg_base_write( IndexFile, BaseName, celldim, physdim, &IndexBase ) )
116 {
117 std::cout << "Error creating CGNS base";
118 }
119 // Give a zone name
120 ZoneName = "Cgns Zone";
121 // isize array contains the total vertex size, cell size, and boundary
122 // vertex size for the zone
123 // Note that for unstructured zones, the index dimension is always 1
124 isize[0] = VrtSize; // isize[0] contains the total vertex size
125 isize[1] = CellSize; // isize[1] contains the total cell size
126 isize[2] = 0; // isize[2] = 0 for unsorted elements
127 // Create zone */
128 // ZoneType_t: Unstructured
129 if( cg_zone_write( IndexFile, IndexBase, ZoneName, isize, Unstructured, &IndexZone ) )
130 {
131 std::cout << "Error creating CGNS zone\n";
132 cg_error_exit();
133 }
134 // Write the vertex coordinates
135 rval = write_coord_cgns( Nodes );
136 if( rval != MB_SUCCESS )
137 {
138 return rval;
139 }
140
141 // Create a vector to hold the Tags
142 std::vector< moab::Tag > TagHandles;
143 // Get Tags
144 rval = mbImpl->tag_get_tags( TagHandles );
145 if( rval != MB_SUCCESS )
146 {
147 return rval;
148 }
149 // Get the number of Tags in the mesh
150 int NbTags = TagHandles.size();
151 std::cout << "\nThe mesh has " << NbTags << " Tags.\n";
152
153 // Create a vector of size NbTags
154 // Sets have informations about the entity set
155 std::vector< SetStruct > Sets;
156 Sets.reserve( NbTags );
157 // Fill Sets with all information needed
158 rval = set_tag_values( TagHandles, Edges, Faces, Cells, Sets );
159 if( rval != MB_SUCCESS )
160 {
161 std::cout << "Problem to set tag values\n";
162 return rval;
163 }
164
165 // Create a matrix to hold connectivity
166 std::vector< std::vector< cgsize_t > > ConnTable;
167 ConnTable.resize( NbTags );
168
169 std::vector< int > Begin( NbTags, 0 );
170 std::vector< int > End( NbTags, 0 );
171
172 // Take the connectivity of higher dimension entities
173 cgsize_t BeginSetsIndex = 1;
174 cgsize_t EndSetsIndex;
175 switch( physdim )
176 {
177 case 1:
178 rval = get_conn_table( Edges, Begin, End, TagHandles, Sets, ConnTable );
179 if( rval != MB_SUCCESS )
180 {
181 std::cout << "Problem to fill the connectivity table for 1-D entities\n";
182 return rval;
183 }
184 for( int i = 0; i < NbTags; ++i )
185 {
186 if( Sets[i].IdSet != -1 )
187 {
188 const char* SectionName = Sets[i].TagName.c_str();
189 EndSetsIndex = BeginSetsIndex + Sets[i].NbEdges - 1;
190 // Write the section in CGNS file
191 if( cg_section_write( IndexFile, IndexBase, IndexBase, SectionName, Sets[i].CGNSType,
192 BeginSetsIndex, EndSetsIndex, 0, &ConnTable[i][0], &IndexSection ) )
193 {
194 std::cout << "Issue on writing connectivity - 3-D\n";
195 cg_error_exit();
196 }
197 BeginSetsIndex = EndSetsIndex + 1;
198 }
199 }
200 break;
201 case 2:
202 rval = get_conn_table( Edges, Begin, End, TagHandles, Sets, ConnTable );
203 if( rval != MB_SUCCESS )
204 {
205 std::cout << "Problem to fill the connectivity table for 1-D entities\n";
206 return rval;
207 }
208 rval = get_conn_table( Faces, Begin, End, TagHandles, Sets, ConnTable );
209 if( rval != MB_SUCCESS )
210 {
211 std::cout << "Problem to fill the connectivity table for 2-D entities\n";
212 return rval;
213 }
214 for( int i = 0; i < NbTags; ++i )
215 {
216 if( Sets[i].IdSet != -1 )
217 {
218 const char* SectionName = Sets[i].TagName.c_str();
219 EndSetsIndex = BeginSetsIndex + Sets[i].NbEdges + Sets[i].NbFaces - 1;
220 // Write the section in CGNS file
221 if( cg_section_write( IndexFile, IndexBase, IndexBase, SectionName, Sets[i].CGNSType,
222 BeginSetsIndex, EndSetsIndex, 0, &ConnTable[i][0], &IndexSection ) )
223 {
224 std::cout << "Issue on writing connectivity -- 2-D\n";
225 cg_error_exit();
226 }
227 BeginSetsIndex = EndSetsIndex + 1;
228 }
229 }
230 break;
231 case 3:
232 rval = get_conn_table( Faces, Begin, End, TagHandles, Sets, ConnTable );
233 if( rval != MB_SUCCESS )
234 {
235 std::cout << "Problem to fill the connectivity table for 2-D entities\n";
236 return rval;
237 }
238 rval = get_conn_table( Cells, Begin, End, TagHandles, Sets, ConnTable );
239 if( rval != MB_SUCCESS )
240 {
241 std::cout << "Problem to fill the connectivity table for 3-D entities\n";
242 return rval;
243 }
244 for( int i = 0; i < NbTags; ++i )
245 {
246 if( Sets[i].IdSet != -1 )
247 {
248 const char* SectionName = Sets[i].TagName.c_str();
249 EndSetsIndex = BeginSetsIndex + Sets[i].NbFaces + Sets[i].NbCells - 1;
250 std::cout << "BeginSetsIndex = " << BeginSetsIndex << "\tEndSetsIndex = " << EndSetsIndex << "\n";
251 // Write the section in CGNS file
252 if( cg_section_write( IndexFile, IndexBase, IndexBase, SectionName, Sets[i].CGNSType,
253 BeginSetsIndex, EndSetsIndex, 0, &ConnTable[i][0], &IndexSection ) )
254 {
255 std::cout << "Issue on writing connectivity -- 3-D\n";
256 cg_error_exit();
257 }
258 BeginSetsIndex = EndSetsIndex + 1;
259 }
260 }
261 break;
262 default:
263 std::cout << "Issue on Physical dimension\n";
264 return MB_FAILURE;
265 }
266
267 // Close the CGNS mesh file
268 if( cg_close( IndexFile ) )
269 {
270 std::cout << "Error closing file\n";
271 cg_error_exit();
272 }
273 // done
274 return MB_SUCCESS;
275 }
References BaseName, celldim, Cells, CellSize, cgsize_t, moab::WriteUtilIface::check_doesnt_exist(), Edges, EdgeSize, ErrorCode, Faces, FaceSize, fileName, get_cell_entities(), get_conn_table(), get_edge_entities(), get_face_entities(), get_vertex_entities(), IndexBase, IndexFile, IndexSection, IndexZone, isize, MB_SUCCESS, mbImpl, mWriteIface, Nodes, physdim, set_tag_values(), moab::Interface::tag_get_tags(), VrtSize, write_coord_cgns(), and ZoneName.
|
private |
Definition at line 139 of file WriteCGNS.hpp.
Referenced by write_file().
|
private |
Definition at line 153 of file WriteCGNS.hpp.
Referenced by get_cell_entities(), get_edge_entities(), get_face_entities(), get_vertex_entities(), and write_file().
|
private |
Definition at line 161 of file WriteCGNS.hpp.
Referenced by set_tag_values(), and write_file().
|
private |
Definition at line 167 of file WriteCGNS.hpp.
Referenced by write_file().
|
private |
Definition at line 159 of file WriteCGNS.hpp.
Referenced by write_file().
|
private |
Definition at line 165 of file WriteCGNS.hpp.
Referenced by write_file().
|
private |
Definition at line 160 of file WriteCGNS.hpp.
Referenced by set_tag_values(), and write_file().
|
private |
Definition at line 166 of file WriteCGNS.hpp.
Referenced by write_file().
|
private |
Definition at line 135 of file WriteCGNS.hpp.
Referenced by write_file().
|
private |
Definition at line 140 of file WriteCGNS.hpp.
Referenced by write_coord_cgns(), and write_file().
|
private |
Definition at line 150 of file WriteCGNS.hpp.
Referenced by write_coord_cgns(), and WriteCGNS().
|
private |
Definition at line 136 of file WriteCGNS.hpp.
Referenced by write_coord_cgns(), and write_file().
|
private |
Definition at line 147 of file WriteCGNS.hpp.
Referenced by write_file().
|
private |
Definition at line 144 of file WriteCGNS.hpp.
Referenced by write_coord_cgns(), and write_file().
|
private |
Definition at line 155 of file WriteCGNS.hpp.
Referenced by write_file(), and WriteCGNS().
|
private |
Definition at line 131 of file WriteCGNS.hpp.
Referenced by get_cell_entities(), get_conn_table(), get_edge_entities(), get_face_entities(), get_set_entities(), get_vertex_entities(), moab_cgns_conv(), set_tag_values(), write_coord_cgns(), write_file(), and ~WriteCGNS().
|
private |
Definition at line 132 of file WriteCGNS.hpp.
Referenced by write_file(), WriteCGNS(), and ~WriteCGNS().
|
private |
Definition at line 158 of file WriteCGNS.hpp.
Referenced by get_vertex_entities(), and write_file().
|
private |
Definition at line 154 of file WriteCGNS.hpp.
Referenced by get_cell_entities(), get_edge_entities(), get_face_entities(), get_vertex_entities(), set_tag_values(), and write_file().
|
private |
Definition at line 164 of file WriteCGNS.hpp.
Referenced by write_file().
|
private |
Definition at line 143 of file WriteCGNS.hpp.
Referenced by write_file().