1 /**
2  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3  * storing and accessing finite element mesh data.
4  *
5  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
6  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7  * retains certain rights in this software.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  */
15 
16 
17 #ifndef WRITE_CGNS_HPP
18 #define WRITE_CGNS_HPP
19 
20 #include "moab/Forward.hpp"
21 #include "moab/WriterIface.hpp"
22 #include <stdio.h>
23 
24 //Junior
25 #include "cgnslib.h"
26 #include "moab/Range.hpp"
27 
28 //Junior
29 #if CGNS_VERSION < 3100
30 # define cgsize_t int
31 #else
32 # if CG_BUILD_SCOPE
33 #  error enumeration scoping needs to be off
34 # endif
35 #endif
36 
37 
38 
39 namespace moab {
40 
41 class WriteUtilIface;
42 
43 /**
44  * \brief Export CGNS files.
45  * \author Carlos Junqueira Junior
46  */
47 
48 class WriteCGNS : public WriterIface
49 {
50 
51 public:
52 
53     //! factory method
54   static WriterIface* factory( Interface* );
55 
56    //! Constructor
57   WriteCGNS(Interface *impl);
58 
59    //! Destructor
60   virtual ~WriteCGNS();
61 
62   // A structure to store Set information.
63   class SetStruct {
64   public:
65     std::string TagName;      // Tag name
66     cgsize_t IdSet ;      // Id of the Set
67     cgsize_t NbEdges;       // Number of Edges in the Set
68     cgsize_t NbFaces;       // Number of Faces in the Set
69     cgsize_t NbCells;       // Number of Cells in the Set
70     // vector with the number of entities in the Sets
71     // 0-MBEDGE | 1-MBTRI | 2-MBQUAD | 3-MBTET | 4-MBPYRAMID | 5-MBPRISM  | 6-MBHEX
72     std::vector<cgsize_t> NbEntities;
73     ElementType_t CGNSType;
74 
SetStruct()75     SetStruct(): IdSet(-1), NbEdges(0), NbFaces(0), NbCells(0) {};
~SetStruct()76     ~SetStruct() {};
77   };
78 
79     //! writes out a file
80   ErrorCode write_file(const char *file_name,
81                          const bool overwrite,
82                          const FileOptions& opts,
83                          const EntityHandle *output_list,
84                          const int num_sets,
85                          const std::vector<std::string>& qa_list,
86                          const Tag* tag_list = NULL,
87                          int num_tags = 0,
88                          int export_dimension = 3);
89 
90   // Get and count vertex entities
91   ErrorCode get_vertex_entities ( cgsize_t &VrtSize,
92 				   std::vector< moab::EntityHandle > &Nodes );
93 
94   // Get and count edge entities
95   ErrorCode get_edge_entities ( cgsize_t &EdgeSize,
96 				  std::vector< moab::EntityHandle > &Edges );
97 
98   // Get and count face entities
99   ErrorCode get_face_entities ( cgsize_t &FaceSize,
100 				  std::vector< moab::EntityHandle > &Faces );
101 
102   // Get and count cell entities
103   ErrorCode get_cell_entities ( cgsize_t &CellSize,
104 				  std::vector< moab::EntityHandle > &Cells );
105 
106   // Write coordinates in the cgns file
107   ErrorCode write_coord_cgns ( std::vector< moab::EntityHandle > &nodes );
108 
109   // Set Tag values on entities
110   ErrorCode set_tag_values ( std::vector<moab::Tag> &TagHandles,
111 			     std::vector< moab::EntityHandle > &Edges,
112 			     std::vector< moab::EntityHandle > &Faces,
113 			     std::vector< moab::EntityHandle > &Cells,
114 			     std::vector<WriteCGNS::SetStruct> &Sets );
115 
116   // Get Entities in the set
117   ErrorCode get_set_entities ( int i, std::vector<moab::Tag> &TagHandles,
118 			       std::vector<WriteCGNS::SetStruct> &Sets );
119 
120   // Get the CGNSType
121   ErrorCode get_cgns_type ( int i, std::vector<WriteCGNS::SetStruct> &Sets );
122 
123   // Get the connectivity table
124   ErrorCode get_conn_table ( std::vector< moab::EntityHandle > &Elements,
125 			     std::vector < int > &Begin,
126 			     std::vector < int > &End,
127 			     std::vector< moab::Tag > &TagHandles,
128 			     std::vector< WriteCGNS::SetStruct > &Sets,
129 			     std::vector < std::vector<cgsize_t> > &ConnTable );
130 
131   // Read the Moab type and return CGNS type
132   int moab_cgns_conv ( const EntityHandle handle );
133 
134 private:
135 
136     // interface instance
137   Interface *mbImpl;
138   WriteUtilIface* mWriteIface;
139 
140   // File var
141   const char *fileName;
142   int IndexFile;
143 
144   // Base var
145   const char *BaseName;
146   int IndexBase;
147 
148   // Zone var
149   const char *ZoneName;
150   int IndexZone;
151 
152   // Section var
153   int IndexSection;
154 
155   // Coordinates var
156   int IndexCoord[3];
157 
158   // Mesh dimension
159   int celldim;
160   int physdim;
161   cgsize_t isize[3];
162 
163   // Entities of mesh
164   std::vector< moab::EntityHandle > Nodes;
165   std::vector< moab::EntityHandle > Edges;
166   std::vector< moab::EntityHandle > Faces;
167   std::vector< moab::EntityHandle > Cells;
168 
169   // Number of entities in the mesh
170   cgsize_t VrtSize ;
171   cgsize_t EdgeSize;
172   cgsize_t FaceSize;
173   cgsize_t CellSize;
174 
175 };
176 
177 } // namespace moab
178 
179 #endif
180