1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/**
 * MOAB, a Mesh-Oriented datABase, is a software component for creating,
 * storing and accessing finite element mesh data.
 *
 * Copyright 2004 Sandia Corporation.  Under the terms of Contract
 * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
 * retains certain rights in this software.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 */

#ifndef WRITE_CGNS_HPP
#define WRITE_CGNS_HPP

#include "moab/Forward.hpp"
#include "moab/WriterIface.hpp"
#include <cstdio>

// Junior
#include "cgnslib.h"
#include "moab/Range.hpp"

// Junior
#if CGNS_VERSION < 3100
#define cgsize_t int
#else
#if CG_BUILD_SCOPE
#error enumeration scoping needs to be off
#endif
#endif

namespace moab
{

class WriteUtilIface;

/**
 * \brief Export CGNS files.
 * \author Carlos Junqueira Junior
 */

class WriteCGNS : public WriterIface
{

  public:
    //! factory method
    static WriterIface* factory( Interface* );

    //! Constructor
    WriteCGNS( Interface* impl );

    //! Destructor
    virtual ~WriteCGNS();

    // A structure to store Set information.
    class SetStruct
    {
      public:
        std::string TagName;  // Tag name
        cgsize_t IdSet;       // Id of the Set
        cgsize_t NbEdges;     // Number of Edges in the Set
        cgsize_t NbFaces;     // Number of Faces in the Set
        cgsize_t NbCells;     // Number of Cells in the Set
        // vector with the number of entities in the Sets
        // 0-MBEDGE | 1-MBTRI | 2-MBQUAD | 3-MBTET | 4-MBPYRAMID | 5-MBPRISM  | 6-MBHEX
        std::vector< cgsize_t > NbEntities;
        ElementType_t CGNSType;

        SetStruct() : IdSet( -1 ), NbEdges( 0 ), NbFaces( 0 ), NbCells( 0 ){};
        ~SetStruct(){};
    };

    //! writes out a file
    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 );

    // Get and count vertex entities
    ErrorCode get_vertex_entities( cgsize_t& VrtSize, std::vector< moab::EntityHandle >& Nodes );

    // Get and count edge entities
    ErrorCode get_edge_entities( cgsize_t& EdgeSize, std::vector< moab::EntityHandle >& Edges );

    // Get and count face entities
    ErrorCode get_face_entities( cgsize_t& FaceSize, std::vector< moab::EntityHandle >& Faces );

    // Get and count cell entities
    ErrorCode get_cell_entities( cgsize_t& CellSize, std::vector< moab::EntityHandle >& Cells );

    // Write coordinates in the cgns file
    ErrorCode write_coord_cgns( std::vector< moab::EntityHandle >& nodes );

    // Set Tag values on entities
    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 );

    // Get Entities in the set
    ErrorCode get_set_entities( int i,
                                std::vector< moab::Tag >& TagHandles,
                                std::vector< WriteCGNS::SetStruct >& Sets );

    // Get the CGNSType
    ErrorCode get_cgns_type( int i, std::vector< WriteCGNS::SetStruct >& Sets );

    // Get the connectivity table
    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 );

    // Read the Moab type and return CGNS type
    int moab_cgns_conv( const EntityHandle handle );

  private:
    // interface instance
    Interface* mbImpl;
    WriteUtilIface* mWriteIface;

    // File var
    const char* fileName;
    int IndexFile;

    // Base var
    const char* BaseName;
    int IndexBase;

    // Zone var
    const char* ZoneName;
    int IndexZone;

    // Section var
    int IndexSection;

    // Coordinates var
    int IndexCoord[3];

    // Mesh dimension
    int celldim;
    int physdim;
    cgsize_t isize[3];

    // Entities of mesh
    std::vector< moab::EntityHandle > Nodes;
    std::vector< moab::EntityHandle > Edges;
    std::vector< moab::EntityHandle > Faces;
    std::vector< moab::EntityHandle > Cells;

    // Number of entities in the mesh
    cgsize_t VrtSize;
    cgsize_t EdgeSize;
    cgsize_t FaceSize;
    cgsize_t CellSize;
};

}  // namespace moab

#endif