Documentation a537f1bdf2
Loading...
Searching...
No Matches
CSU2BinaryMeshReaderBase.hpp
Go to the documentation of this file.
1/*!
2 * \file CSU2BinaryMeshReaderBase.hpp
3 * \brief Header file for the class CSU2BinaryMeshReaderBase.
4 * The implementations are in the <i>CSU2BinaryMeshReaderBase.cpp</i> file.
5 * \author T. Economon, E. van der Weide
6 * \version 8.5.0 "Harrier"
7 *
8 * SU2 Project Website: https://su2code.github.io
9 *
10 * The SU2 Project is maintained by the SU2 Foundation
11 * (http://su2foundation.org)
12 *
13 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
14 *
15 * SU2 is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * SU2 is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
27 */
28
29#pragma once
30
32#include "../../../include/toolboxes/SwapBytes.hpp"
33
34/*!
35 * \class CSU2BinaryMeshReaderBase
36 * \brief Base class for the reading of a native SU2 binary grid.
37 * \author T. Economon, E. van der Weide
38 */
40 protected:
41 constexpr static int SU2_STRING_SIZE =
42 SU2_BINARY_STRING_SIZE; /*!< \brief Size of the strings in the SU2 binary mesh file. */
43
44 FILE* mesh_file; /*!< \brief File object for the SU2 binary mesh file. */
45 bool swap_bytes; /*!< \brief Whether or not byte swapping must be used. */
46 int size_conn_type; /*!< \brief Size, in bytes of the connectivity type. */
47
48 /*!
49 * \brief Reads the connectivity type used in the binary file and check if
50 * byte swapping must be applied.
51 */
53
54 /*!
55 * \brief Reads all SU2 binary mesh metadata and checks for errors.
56 * \param[in] config - Problem configuration for the current zone.
57 */
59
60 /*!
61 * \brief Reads the grid points from an SU2 zone into linear partitions across all ranks.
62 */
63 virtual void ReadPointCoordinates();
64
65 /*!
66 * \brief Reads the interior volume elements from one section of an SU2 zone into linear partitions across all ranks.
67 */
68 virtual void ReadVolumeElementConnectivity();
69
70 /*!
71 * \brief Reads the surface (boundary) elements from the SU2 zone.
72 */
73 virtual void ReadSurfaceElementConnectivity();
74
75 /*!
76 * \brief Helper function to find the current zone in an SU2 binary mesh object.
77 */
79
80 /*!
81 * \brief Portable, 64-bit safe replacement for fseek. Needed because binary
82 * SU2 grid files can exceed 2 GiB even on platforms where "long" is
83 * only 32 bits wide (e.g. Windows).
84 */
85 static int FileSeek64(FILE* file, int64_t offset, int whence);
86
87 /*!
88 * \brief Portable, 64-bit safe replacement for ftell.
89 */
90 static int64_t FileTell64(FILE* file);
91
92 /*!
93 * \brief Function to read one entity of the connectivity type from the binary file.
94 * \return uint64_t version of the the data.
95 */
96 uint64_t ReadBinaryNEntities();
97
98 /*!
99 * \brief Template function to read data from the binary file.
100 */
101 template <typename T>
102 void ReadBinaryData(T* data, const size_t nItems) {
103 /*--- Read the actual data. ---*/
104 auto ret = fread(data, sizeof(T), nItems, mesh_file);
105 if (ret != nItems) SU2_MPI::Error(string("Error while reading the file ") + meshFilename, CURRENT_FUNCTION);
106
107 /*--- Apply byte swapping, if needed. ---*/
108 if (swap_bytes) SwapBytes((char*)data, sizeof(T), nItems);
109 }
110
111 private:
112 /*!
113 * \brief Read the meta data for a zone, advancing the file position past it.
114 * \param[in] storeMetadata - Whether to store the read values in the
115 * dimension, numberOfGlobalElements, numberOfGlobalPoints and
116 * numberOfMarkers members. Must be false when only skipping
117 * past a lower-numbered zone (from
118 * FastForwardToMyZone), so that doing so does not clobber the
119 * metadata already read for the current (target) zone.
120 */
121 void ReadMetadataZone(bool storeMetadata);
122
123 public:
124 /*!
125 * \brief Constructor of the CSU2BinaryMeshReaderBase class.
126 */
127 CSU2BinaryMeshReaderBase(CConfig* val_config, unsigned short val_iZone, unsigned short val_nZone);
128
129 /*!
130 * \brief Destructor of the CSU2BinaryMeshReaderBase class.
131 */
133};
Header file for the class CSU2MeshReaderBase. The implementations are in the CSU2MeshReaderBase....
void SwapBytes(char *buffer, size_t nBytes, unsigned long nVar)
Change storage of buffer to/from big endian from/to little endian.
Definition SwapBytes.cpp:32
static void Error(const std::string &ErrorMsg, const std::string &FunctionName)
Definition mpi_structure.cpp:131
Main class for defining the problem; basically this class reads the configuration file,...
Definition CConfig.hpp:64
const CConfig * config
Local pointer to the config parameter object.
Definition CMeshReaderBase.hpp:49
Base class for the reading of a native SU2 binary grid.
Definition CSU2BinaryMeshReaderBase.hpp:39
bool swap_bytes
Whether or not byte swapping must be used.
Definition CSU2BinaryMeshReaderBase.hpp:45
virtual void ReadSurfaceElementConnectivity()
Reads the surface (boundary) elements from the SU2 zone.
Definition CSU2BinaryMeshReaderBase.cpp:345
virtual void ReadPointCoordinates()
Reads the grid points from an SU2 zone into linear partitions across all ranks.
Definition CSU2BinaryMeshReaderBase.cpp:108
void ReadConnectivityType()
Reads the connectivity type used in the binary file and check if byte swapping must be applied.
Definition CSU2BinaryMeshReaderBase.cpp:56
void ReadMetadata(CConfig *config)
Reads all SU2 binary mesh metadata and checks for errors.
Definition CSU2BinaryMeshReaderBase.cpp:73
void FastForwardToMyZone()
Helper function to find the current zone in an SU2 binary mesh object.
Definition CSU2BinaryMeshReaderBase.cpp:426
uint64_t ReadBinaryNEntities()
Function to read one entity of the connectivity type from the binary file.
Definition CSU2BinaryMeshReaderBase.cpp:442
~CSU2BinaryMeshReaderBase(void) override
Destructor of the CSU2BinaryMeshReaderBase class.
static constexpr int SU2_STRING_SIZE
Size of the strings in the SU2 binary mesh file.
Definition CSU2BinaryMeshReaderBase.hpp:41
FILE * mesh_file
File object for the SU2 binary mesh file.
Definition CSU2BinaryMeshReaderBase.hpp:44
int size_conn_type
Size, in bytes of the connectivity type.
Definition CSU2BinaryMeshReaderBase.hpp:46
static int FileSeek64(FILE *file, int64_t offset, int whence)
Portable, 64-bit safe replacement for fseek. Needed because binary SU2 grid files can exceed 2 GiB ev...
Definition CSU2BinaryMeshReaderBase.cpp:40
void ReadBinaryData(T *data, const size_t nItems)
Template function to read data from the binary file.
Definition CSU2BinaryMeshReaderBase.hpp:102
static int64_t FileTell64(FILE *file)
Portable, 64-bit safe replacement for ftell.
Definition CSU2BinaryMeshReaderBase.cpp:48
virtual void ReadVolumeElementConnectivity()
Reads the interior volume elements from one section of an SU2 zone into linear partitions across all ...
Definition CSU2BinaryMeshReaderBase.cpp:146
Base class for the reading of a native SU2 grid.
Definition CSU2MeshReaderBase.hpp:40
const string meshFilename
Name of the SU2 ASCII mesh file being read.
Definition CSU2MeshReaderBase.hpp:45
#define CURRENT_FUNCTION
Definition mpi_structure.hpp:59
const int SU2_BINARY_STRING_SIZE
Length of strings (e.g. marker names) used in the native SU2 binary mesh format. Shared by CSU2Binary...
Definition option_structure.hpp:263