Skip to content

Commit 34c46b6

Browse files
authored
Merge pull request #1361 from su2code/cleanup_meshreader
Cleanup ASCII mesh reader
2 parents 63b2dea + 949d9ec commit 34c46b6

9 files changed

Lines changed: 365 additions & 732 deletions

File tree

Common/include/geometry/meshreader/CMeshReaderFVM.hpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
/*!
3838
* \class CMeshReaderFVM
3939
* \brief Base class for the mesh zone readers of the finite volume solver (FVM).
40-
* \author: T. Economon
40+
* \author T. Economon
4141
*/
4242
class CMeshReaderFVM {
4343

@@ -46,7 +46,7 @@ class CMeshReaderFVM {
4646
const int rank; /*!< \brief MPI Rank. */
4747
const int size; /*!< \brief MPI Size. */
4848

49-
CConfig* const config = nullptr; /*!< \brief Local pointer to the config parameter object. */
49+
const CConfig* config = nullptr; /*!< \brief Local pointer to the config parameter object. */
5050

5151
unsigned short dimension = 0; /*!< \brief Dimension of the problem (2 or 3). */
5252

@@ -70,15 +70,10 @@ class CMeshReaderFVM {
7070
* \param[in] val_iZone - Current zone index.
7171
* \param[in] val_nZone - Total number of zones.
7272
*/
73-
CMeshReaderFVM(CConfig *val_config,
73+
CMeshReaderFVM(const CConfig *val_config,
7474
unsigned short val_iZone,
7575
unsigned short val_nZone);
7676

77-
/*!
78-
* \brief Destructor of the CMeshReaderFVM class.
79-
*/
80-
~CMeshReaderFVM(void) = default;
81-
8277
/*!
8378
* \brief Get the physical dimension of the problem (2 or 3).
8479
* \returns Physical dimension of the problem.
@@ -109,7 +104,7 @@ class CMeshReaderFVM {
109104
* \param[in] val_iMarker - current marker index.
110105
* \returns Number of surface elements for a marker.
111106
*/
112-
inline unsigned long GetNumberOfSurfaceElementsForMarker(int val_iMarker) {
107+
inline unsigned long GetNumberOfSurfaceElementsForMarker(int val_iMarker) const {
113108
return (unsigned long)surfaceElementConnectivity[val_iMarker].size()/SU2_CONN_SIZE;
114109
}
115110

Common/include/geometry/meshreader/CRectangularMeshReaderFVM.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,8 @@ class CRectangularMeshReaderFVM: public CMeshReaderFVM {
7171
/*!
7272
* \brief Constructor of the CRectangularMeshReaderFVM class.
7373
*/
74-
CRectangularMeshReaderFVM(CConfig *val_config,
74+
CRectangularMeshReaderFVM(const CConfig *val_config,
7575
unsigned short val_iZone,
7676
unsigned short val_nZone);
7777

78-
/*!
79-
* \brief Destructor of the CRectangularMeshReaderFVM class.
80-
*/
81-
~CRectangularMeshReaderFVM(void);
82-
8378
};

Common/include/geometry/meshreader/CSU2ASCIIMeshReaderFVM.hpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,34 @@
2828

2929
#pragma once
3030

31+
#include <array>
32+
3133
#include "CMeshReaderFVM.hpp"
3234

3335
/*!
3436
* \class CSU2ASCIIMeshReaderFVM
3537
* \brief Reads a native SU2 ASCII grid into linear partitions for the finite volume solver (FVM).
36-
* \author: T. Economon
38+
* \author T. Economon
3739
*/
3840
class CSU2ASCIIMeshReaderFVM: public CMeshReaderFVM {
3941

4042
private:
43+
enum class FileSection { POINTS, ELEMENTS, MARKERS }; /*!< \brief Different sections of the file. */
44+
std::array<FileSection, 3> SectionOrder{}; /*!< \brief Order of the sections in the file. */
4145

42-
unsigned short myZone; /*!< \brief Current SU2 zone index. */
43-
unsigned short nZones; /*!< \brief Total number of zones in the SU2 file. */
46+
const unsigned short myZone; /*!< \brief Current SU2 zone index. */
47+
const unsigned short nZones; /*!< \brief Total number of zones in the SU2 file. */
4448

45-
string meshFilename; /*!< \brief Name of the SU2 ASCII mesh file being read. */
49+
const string meshFilename; /*!< \brief Name of the SU2 ASCII mesh file being read. */
4650
ifstream mesh_file; /*!< \brief File object for the SU2 ASCII mesh file. */
4751

4852
bool actuator_disk; /*!< \brief Boolean for whether we have an actuator disk to split. */
4953

50-
unsigned long ActDiskNewPoints; /*!< \brief Total number of new grid points to add due to actuator disk splitting. */
54+
unsigned long ActDiskNewPoints = 0; /*!< \brief Total number of new grid points to add due to actuator disk splitting. */
5155

52-
su2double Xloc; /*!< \brief X-coordinate of the CG of the actuator disk surface. */
53-
su2double Yloc; /*!< \brief X-coordinate of the CG of the actuator disk surface. */
54-
su2double Zloc; /*!< \brief X-coordinate of the CG of the actuator disk surface. */
56+
su2double Xloc = 0.0; /*!< \brief X-coordinate of the CG of the actuator disk surface. */
57+
su2double Yloc = 0.0; /*!< \brief X-coordinate of the CG of the actuator disk surface. */
58+
su2double Zloc = 0.0; /*!< \brief X-coordinate of the CG of the actuator disk surface. */
5559

5660
vector<bool> ActDisk_Bool; /*!< \brief Flag to identify the grid points on the actuator disk. */
5761

@@ -68,8 +72,11 @@ class CSU2ASCIIMeshReaderFVM: public CMeshReaderFVM {
6872

6973
/*!
7074
* \brief Reads all SU2 ASCII mesh metadata and checks for errors.
75+
* \param[in] single_pass - Try to read the contents together with the metadata if the order allows (points before elements).
76+
* \param[in,out] config - Problem configuration where some metadata is updated (e.g. AoA).
77+
* \returns True if single_pass was successful.
7178
*/
72-
void ReadMetadata();
79+
bool ReadMetadata(const bool single_pass, CConfig *config);
7380

7481
/*!
7582
* \brief Splits a single surface actuator disk boundary into two separate markers (repeated points).
@@ -79,17 +86,17 @@ class CSU2ASCIIMeshReaderFVM: public CMeshReaderFVM {
7986
/*!
8087
* \brief Reads the grid points from an SU2 zone into linear partitions across all ranks.
8188
*/
82-
void ReadPointCoordinates();
89+
void ReadPointCoordinates(const bool single_pass = false);
8390

8491
/*!
8592
* \brief Reads the interior volume elements from one section of an SU2 zone into linear partitions across all ranks.
8693
*/
87-
void ReadVolumeElementConnectivity();
94+
void ReadVolumeElementConnectivity(const bool single_pass = false);
8895

8996
/*!
9097
* \brief Reads the surface (boundary) elements from the SU2 zone.
9198
*/
92-
void ReadSurfaceElementConnectivity();
99+
void ReadSurfaceElementConnectivity(const bool single_pass = false);
93100

94101
/*!
95102
* \brief Helper function to find the current zone in an SU2 ASCII mesh object.
@@ -101,13 +108,8 @@ class CSU2ASCIIMeshReaderFVM: public CMeshReaderFVM {
101108
/*!
102109
* \brief Constructor of the CSU2ASCIIMeshReaderFVM class.
103110
*/
104-
CSU2ASCIIMeshReaderFVM(CConfig *val_config,
111+
CSU2ASCIIMeshReaderFVM(CConfig *val_config,
105112
unsigned short val_iZone,
106113
unsigned short val_nZone);
107114

108-
/*!
109-
* \brief Destructor of the CSU2ASCIIMeshReaderFVM class.
110-
*/
111-
~CSU2ASCIIMeshReaderFVM(void);
112-
113115
};

Common/include/option_structure.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,24 @@ inline unsigned short nFacesOfElementType(unsigned short elementType) {
170170
}
171171
}
172172

173+
/*!
174+
* \brief Get the number of points of the element.
175+
* \param[in] elementType - element type
176+
* \return number of points
177+
*/
178+
inline unsigned short nPointsOfElementType(unsigned short elementType) {
179+
switch (elementType) {
180+
case LINE: return N_POINTS_LINE;
181+
case TRIANGLE: return N_POINTS_TRIANGLE;
182+
case QUADRILATERAL: return N_POINTS_QUADRILATERAL;
183+
case TETRAHEDRON: return N_POINTS_TETRAHEDRON;
184+
case HEXAHEDRON: return N_POINTS_HEXAHEDRON;
185+
case PYRAMID: return N_POINTS_PYRAMID;
186+
case PRISM: return N_POINTS_PRISM;
187+
default: assert(false && "Invalid element type."); return 0;
188+
}
189+
}
190+
173191
const int CGNS_STRING_SIZE = 33; /*!< \brief Length of strings used in the CGNS format. */
174192
const int SU2_CONN_SIZE = 10; /*!< \brief Size of the connectivity array that is allocated for each element
175193
that we read from a mesh file in the format [[globalID vtkType n0 n1 n2 n3 n4 n5 n6 n7 n8]. */

Common/include/toolboxes/CLinearPartitioner.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,14 @@ class CLinearPartitioner {
116116
return cumulativeSizeBeforeRank[rank];
117117
}
118118

119+
/*!
120+
* \brief Checks if an index belongs to a rank.
121+
* \param[in] index - Current index.
122+
* \param[in] rank - MPI rank identifier.
123+
* \returns True if index is owned by rank.
124+
*/
125+
bool IndexBelongsToRank(unsigned long index, int rank) const {
126+
return index >= cumulativeSizeBeforeRank[rank] && index < cumulativeSizeBeforeRank[rank+1];
127+
}
128+
119129
};

Common/src/geometry/meshreader/CMeshReaderFVM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#include "../../../include/geometry/meshreader/CMeshReaderFVM.hpp"
3030

31-
CMeshReaderFVM::CMeshReaderFVM(CConfig *val_config,
31+
CMeshReaderFVM::CMeshReaderFVM(const CConfig *val_config,
3232
unsigned short val_iZone,
3333
unsigned short val_nZone) :
3434
rank(SU2_MPI::GetRank()),

Common/src/geometry/meshreader/CRectangularMeshReaderFVM.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "../../../include/toolboxes/CLinearPartitioner.hpp"
3030
#include "../../../include/geometry/meshreader/CRectangularMeshReaderFVM.hpp"
3131

32-
CRectangularMeshReaderFVM::CRectangularMeshReaderFVM(CConfig *val_config,
32+
CRectangularMeshReaderFVM::CRectangularMeshReaderFVM(const CConfig *val_config,
3333
unsigned short val_iZone,
3434
unsigned short val_nZone)
3535
: CMeshReaderFVM(val_config, val_iZone, val_nZone) {
@@ -64,8 +64,6 @@ CRectangularMeshReaderFVM::CRectangularMeshReaderFVM(CConfig *val_config,
6464

6565
}
6666

67-
CRectangularMeshReaderFVM::~CRectangularMeshReaderFVM(void) { }
68-
6967
void CRectangularMeshReaderFVM::ComputeRectangularPointCoordinates() {
7068

7169
/* Set the global count of points based on the grid dimensions. */

0 commit comments

Comments
 (0)