|
| 1 | +/*! |
| 2 | + * \file CCGNSFileWriter.hpp |
| 3 | + * \brief Headers for CGNS file writer class. |
| 4 | + * \author G. Baldan |
| 5 | + * \version 7.2.0 "Blackbird" |
| 6 | + * |
| 7 | + * SU2 Project Website: https://su2code.github.io |
| 8 | + * |
| 9 | + * The SU2 Project is maintained by the SU2 Foundation |
| 10 | + * (http://su2foundation.org) |
| 11 | + * |
| 12 | + * Copyright 2012-2021, SU2 Contributors (cf. AUTHORS.md) |
| 13 | + * |
| 14 | + * SU2 is free software; you can redistribute it and/or |
| 15 | + * modify it under the terms of the GNU Lesser General Public |
| 16 | + * License as published by the Free Software Foundation; either |
| 17 | + * version 2.1 of the License, or (at your option) any later version. |
| 18 | + * |
| 19 | + * SU2 is distributed in the hope that it will be useful, |
| 20 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | + * Lesser General Public License for more details. |
| 23 | + * |
| 24 | + * You should have received a copy of the GNU Lesser General Public |
| 25 | + * License along with SU2. If not, see <http://www.gnu.org/licenses/>. |
| 26 | + */ |
| 27 | + |
| 28 | +#pragma once |
| 29 | + |
| 30 | +#ifdef HAVE_CGNS |
| 31 | +#include "cgnslib.h" |
| 32 | +#endif |
| 33 | + |
| 34 | +#include "CFileWriter.hpp" |
| 35 | + |
| 36 | +class CCGNSFileWriter final : public CFileWriter { |
| 37 | + private: |
| 38 | + const bool isSurface; /*!< \brief True if surface file. */ |
| 39 | + |
| 40 | +#ifdef HAVE_CGNS |
| 41 | + int cgnsFileID; /*!< \brief CGNS file identifier. */ |
| 42 | + int cgnsBase; /*!< \brief CGNS database index. */ |
| 43 | + int cgnsZone; /*!< \brief CGNS zone index. */ |
| 44 | + int cgnsFields; /*!< \brief CGNS flow solution index. */ |
| 45 | + |
| 46 | + int nZones; /*!< \brief Total number of zones in the CGNS file. */ |
| 47 | + int nSections; /*!< \brief Total number of sections in the CGNS file. */ |
| 48 | + |
| 49 | + unsigned short nDim; /*!< \brief Problem dimension. */ |
| 50 | + unsigned long nLocalPoints; /*!< \brief Local number of points. */ |
| 51 | + cgsize_t GlobalPoint; /*!< \brief Total number of points. */ |
| 52 | + cgsize_t GlobalElem; /*!< \brief Total number of elements. */ |
| 53 | + |
| 54 | + typedef float dataPrecision; /*!< \brief Define data precision of output (float or double). */ |
| 55 | + const DataType_t dataType = RealSingle; /*!< \brief Datatype of fields can be RealSingle or RealDouble. */ |
| 56 | + |
| 57 | + vector<cgsize_t> sendBufferConnectivity; /*!< \brief Send buffer for connectivity data. */ |
| 58 | + vector<cgsize_t> recvBufferConnectivity; /*!< \brief Receive buffer for connectivity data. */ |
| 59 | + vector<dataPrecision> recvBufferField; /*!< \brief Send buffer for field data. */ |
| 60 | + vector<dataPrecision> sendBufferField; /*!< \brief Receive buffer for field data. */ |
| 61 | + |
| 62 | + cgsize_t cumulative; /*!< \brief Cumulative number of elements written. */ |
| 63 | +#endif |
| 64 | + public: |
| 65 | + /*! |
| 66 | + * \brief File extension |
| 67 | + */ |
| 68 | + const static string fileExt; |
| 69 | + |
| 70 | + /*! |
| 71 | + * \brief Construct a file writer using field names and the data sorter. |
| 72 | + * \param[in] valFileName - The name of the file. |
| 73 | + * \param[in] valDataSorter - The parallel sorted data to write. |
| 74 | + * \param[in] isSurf - True if it is a surface file. |
| 75 | + */ |
| 76 | + CCGNSFileWriter(string valFileName, CParallelDataSorter* valDataSorter, bool isSurf = false); |
| 77 | + |
| 78 | + /*! |
| 79 | + * \brief Write sorted data to file in CGNS file format. |
| 80 | + */ |
| 81 | + void Write_Data() override; |
| 82 | + |
| 83 | + private: |
| 84 | +#ifdef HAVE_CGNS |
| 85 | + /*! |
| 86 | + * \brief Initialize CGNS mesh file. |
| 87 | + */ |
| 88 | + void InitializeMeshFile(); |
| 89 | + |
| 90 | + /*! |
| 91 | + * \brief Write i-th coordinate to file in CGNS file format. |
| 92 | + * \param[in] iField - the output field ID. |
| 93 | + * \param[in] FieldName - Field name in the CGNS. |
| 94 | + */ |
| 95 | + void WriteField(int iField, const string& FieldName); |
| 96 | + |
| 97 | + /*! |
| 98 | + * \brief Write connectivity to file for GEO_TYPE in CGNS file format. |
| 99 | + * \param[in] type - GEO_TYPE. |
| 100 | + * \param[in] SectionName - Section name in the CGNS file. |
| 101 | + */ |
| 102 | + void WriteConnectivity(GEO_TYPE type, const string& SectionName); |
| 103 | + |
| 104 | + /*! |
| 105 | + * \brief Initialize flow solution in the CGNS file. |
| 106 | + */ |
| 107 | + void InitializeFields(); |
| 108 | + |
| 109 | + /*! |
| 110 | + * \brief Call a generic CGNS function. |
| 111 | + * \param[in] ier - error value. |
| 112 | + */ |
| 113 | + static inline void CallCGNS(const int& ier) { |
| 114 | + if (ier) cg_error_exit(); |
| 115 | + } |
| 116 | + |
| 117 | + /*! |
| 118 | + * \brief Return the CGNS element type (ElementType_t). |
| 119 | + * \param[in] elementType - GEO_TYPE. |
| 120 | + */ |
| 121 | + static inline ElementType_t GetCGNSType(unsigned short elementType) { |
| 122 | + switch (elementType) { |
| 123 | + case LINE: |
| 124 | + return BAR_2; |
| 125 | + case TRIANGLE: |
| 126 | + return TRI_3; |
| 127 | + case QUADRILATERAL: |
| 128 | + return QUAD_4; |
| 129 | + case TETRAHEDRON: |
| 130 | + return TETRA_4; |
| 131 | + case HEXAHEDRON: |
| 132 | + return HEXA_8; |
| 133 | + case PYRAMID: |
| 134 | + return PYRA_5; |
| 135 | + case PRISM: |
| 136 | + return PENTA_6; |
| 137 | + default: |
| 138 | + assert(false && "Invalid element type."); |
| 139 | + return ElementTypeNull; |
| 140 | + } |
| 141 | + } |
| 142 | +#endif |
| 143 | +}; |
0 commit comments