MOAB: Mesh Oriented datABase  (version 5.4.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 <cstdio>
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,
00079                           const bool overwrite,
00080                           const FileOptions& opts,
00081                           const EntityHandle* output_list,
00082                           const int num_sets,
00083                           const std::vector< std::string >& qa_list,
00084                           const Tag* tag_list  = NULL,
00085                           int num_tags         = 0,
00086                           int export_dimension = 3 );
00087 
00088     // Get and count vertex entities
00089     ErrorCode get_vertex_entities( cgsize_t& VrtSize, std::vector< moab::EntityHandle >& Nodes );
00090 
00091     // Get and count edge entities
00092     ErrorCode get_edge_entities( cgsize_t& EdgeSize, std::vector< moab::EntityHandle >& Edges );
00093 
00094     // Get and count face entities
00095     ErrorCode get_face_entities( cgsize_t& FaceSize, std::vector< moab::EntityHandle >& Faces );
00096 
00097     // Get and count cell entities
00098     ErrorCode get_cell_entities( cgsize_t& CellSize, std::vector< moab::EntityHandle >& Cells );
00099 
00100     // Write coordinates in the cgns file
00101     ErrorCode write_coord_cgns( std::vector< moab::EntityHandle >& nodes );
00102 
00103     // Set Tag values on entities
00104     ErrorCode set_tag_values( std::vector< moab::Tag >& TagHandles,
00105                               std::vector< moab::EntityHandle >& Edges,
00106                               std::vector< moab::EntityHandle >& Faces,
00107                               std::vector< moab::EntityHandle >& Cells,
00108                               std::vector< WriteCGNS::SetStruct >& Sets );
00109 
00110     // Get Entities in the set
00111     ErrorCode get_set_entities( int i,
00112                                 std::vector< moab::Tag >& TagHandles,
00113                                 std::vector< WriteCGNS::SetStruct >& Sets );
00114 
00115     // Get the CGNSType
00116     ErrorCode get_cgns_type( int i, std::vector< WriteCGNS::SetStruct >& Sets );
00117 
00118     // Get the connectivity table
00119     ErrorCode get_conn_table( std::vector< moab::EntityHandle >& Elements,
00120                               std::vector< int >& Begin,
00121                               std::vector< int >& End,
00122                               std::vector< moab::Tag >& TagHandles,
00123                               std::vector< WriteCGNS::SetStruct >& Sets,
00124                               std::vector< std::vector< cgsize_t > >& ConnTable );
00125 
00126     // Read the Moab type and return CGNS type
00127     int moab_cgns_conv( const EntityHandle handle );
00128 
00129   private:
00130     // interface instance
00131     Interface* mbImpl;
00132     WriteUtilIface* mWriteIface;
00133 
00134     // File var
00135     const char* fileName;
00136     int IndexFile;
00137 
00138     // Base var
00139     const char* BaseName;
00140     int IndexBase;
00141 
00142     // Zone var
00143     const char* ZoneName;
00144     int IndexZone;
00145 
00146     // Section var
00147     int IndexSection;
00148 
00149     // Coordinates var
00150     int IndexCoord[3];
00151 
00152     // Mesh dimension
00153     int celldim;
00154     int physdim;
00155     cgsize_t isize[3];
00156 
00157     // Entities of mesh
00158     std::vector< moab::EntityHandle > Nodes;
00159     std::vector< moab::EntityHandle > Edges;
00160     std::vector< moab::EntityHandle > Faces;
00161     std::vector< moab::EntityHandle > Cells;
00162 
00163     // Number of entities in the mesh
00164     cgsize_t VrtSize;
00165     cgsize_t EdgeSize;
00166     cgsize_t FaceSize;
00167     cgsize_t CellSize;
00168 };
00169 
00170 }  // namespace moab
00171 
00172 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines