MOAB: Mesh Oriented datABase  (version 5.2.1)
WriteCGNS.hpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
00016 #ifndef WRITE_CGNS_HPP
00017 #define WRITE_CGNS_HPP
00018 
00019 #include "moab/Forward.hpp"
00020 #include "moab/WriterIface.hpp"
00021 #include <stdio.h>
00022 
00023 // Junior
00024 #include "cgnslib.h"
00025 #include "moab/Range.hpp"
00026 
00027 // Junior
00028 #if CGNS_VERSION < 3100
00029 #define cgsize_t int
00030 #else
00031 #if CG_BUILD_SCOPE
00032 #error enumeration scoping needs to be off
00033 #endif
00034 #endif
00035 
00036 namespace moab
00037 {
00038 
00039 class WriteUtilIface;
00040 
00041 /**
00042  * \brief Export CGNS files.
00043  * \author Carlos Junqueira Junior
00044  */
00045 
00046 class WriteCGNS : public WriterIface
00047 {
00048 
00049   public:
00050     //! factory method
00051     static WriterIface* factory( Interface* );
00052 
00053     //! Constructor
00054     WriteCGNS( Interface* impl );
00055 
00056     //! Destructor
00057     virtual ~WriteCGNS();
00058 
00059     // A structure to store Set information.
00060     class SetStruct
00061     {
00062       public:
00063         std::string TagName;  // Tag name
00064         cgsize_t IdSet;       // Id of the Set
00065         cgsize_t NbEdges;     // Number of Edges in the Set
00066         cgsize_t NbFaces;     // Number of Faces in the Set
00067         cgsize_t NbCells;     // Number of Cells in the Set
00068         // vector with the number of entities in the Sets
00069         // 0-MBEDGE | 1-MBTRI | 2-MBQUAD | 3-MBTET | 4-MBPYRAMID | 5-MBPRISM  | 6-MBHEX
00070         std::vector< cgsize_t > NbEntities;
00071         ElementType_t CGNSType;
00072 
00073         SetStruct() : IdSet( -1 ), NbEdges( 0 ), NbFaces( 0 ), NbCells( 0 ){};
00074         ~SetStruct(){};
00075     };
00076 
00077     //! writes out a file
00078     ErrorCode write_file( const char* file_name, const bool overwrite, const FileOptions& opts,
00079                           const EntityHandle* output_list, const int num_sets,
00080                           const std::vector< std::string >& qa_list, const Tag* tag_list = NULL, int num_tags = 0,
00081                           int export_dimension = 3 );
00082 
00083     // Get and count vertex entities
00084     ErrorCode get_vertex_entities( cgsize_t& VrtSize, std::vector< moab::EntityHandle >& Nodes );
00085 
00086     // Get and count edge entities
00087     ErrorCode get_edge_entities( cgsize_t& EdgeSize, std::vector< moab::EntityHandle >& Edges );
00088 
00089     // Get and count face entities
00090     ErrorCode get_face_entities( cgsize_t& FaceSize, std::vector< moab::EntityHandle >& Faces );
00091 
00092     // Get and count cell entities
00093     ErrorCode get_cell_entities( cgsize_t& CellSize, std::vector< moab::EntityHandle >& Cells );
00094 
00095     // Write coordinates in the cgns file
00096     ErrorCode write_coord_cgns( std::vector< moab::EntityHandle >& nodes );
00097 
00098     // Set Tag values on entities
00099     ErrorCode set_tag_values( std::vector< moab::Tag >& TagHandles, std::vector< moab::EntityHandle >& Edges,
00100                               std::vector< moab::EntityHandle >& Faces, std::vector< moab::EntityHandle >& Cells,
00101                               std::vector< WriteCGNS::SetStruct >& Sets );
00102 
00103     // Get Entities in the set
00104     ErrorCode get_set_entities( int i, std::vector< moab::Tag >& TagHandles,
00105                                 std::vector< WriteCGNS::SetStruct >& Sets );
00106 
00107     // Get the CGNSType
00108     ErrorCode get_cgns_type( int i, std::vector< WriteCGNS::SetStruct >& Sets );
00109 
00110     // Get the connectivity table
00111     ErrorCode get_conn_table( std::vector< moab::EntityHandle >& Elements, std::vector< int >& Begin,
00112                               std::vector< int >& End, std::vector< moab::Tag >& TagHandles,
00113                               std::vector< WriteCGNS::SetStruct >& Sets,
00114                               std::vector< std::vector< cgsize_t > >& ConnTable );
00115 
00116     // Read the Moab type and return CGNS type
00117     int moab_cgns_conv( const EntityHandle handle );
00118 
00119   private:
00120     // interface instance
00121     Interface* mbImpl;
00122     WriteUtilIface* mWriteIface;
00123 
00124     // File var
00125     const char* fileName;
00126     int IndexFile;
00127 
00128     // Base var
00129     const char* BaseName;
00130     int IndexBase;
00131 
00132     // Zone var
00133     const char* ZoneName;
00134     int IndexZone;
00135 
00136     // Section var
00137     int IndexSection;
00138 
00139     // Coordinates var
00140     int IndexCoord[3];
00141 
00142     // Mesh dimension
00143     int celldim;
00144     int physdim;
00145     cgsize_t isize[3];
00146 
00147     // Entities of mesh
00148     std::vector< moab::EntityHandle > Nodes;
00149     std::vector< moab::EntityHandle > Edges;
00150     std::vector< moab::EntityHandle > Faces;
00151     std::vector< moab::EntityHandle > Cells;
00152 
00153     // Number of entities in the mesh
00154     cgsize_t VrtSize;
00155     cgsize_t EdgeSize;
00156     cgsize_t FaceSize;
00157     cgsize_t CellSize;
00158 };
00159 
00160 }  // namespace moab
00161 
00162 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines