Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 3 additions & 34 deletions Common/include/geometry/meshreader/CSU2ASCIIMeshReaderBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,50 +30,19 @@

#include <array>

#include "CMeshReaderBase.hpp"
#include "CSU2MeshReaderBase.hpp"

/*!
* \class CSU2ASCIIMeshReaderBase
* \brief Base class for the reading of a native SU2 ASCII grid.
* \author T. Economon
*/
class CSU2ASCIIMeshReaderBase : public CMeshReaderBase {
class CSU2ASCIIMeshReaderBase : public CSU2MeshReaderBase {
protected:
enum class FileSection { POINTS, ELEMENTS, MARKERS }; /*!< \brief Different sections of the file. */
std::array<FileSection, 3> SectionOrder{}; /*!< \brief Order of the sections in the file. */

const unsigned short myZone; /*!< \brief Current SU2 zone index. */
const unsigned short nZones; /*!< \brief Total number of zones in the SU2 file. */

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

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

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

su2double Xloc = 0.0; /*!< \brief X-coordinate of the CG of the actuator disk surface. */
su2double Yloc = 0.0; /*!< \brief X-coordinate of the CG of the actuator disk surface. */
su2double Zloc = 0.0; /*!< \brief X-coordinate of the CG of the actuator disk surface. */

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

vector<unsigned long> ActDiskPoint_Back; /*!< \brief Vector containing the global index for the new grid points added
to the back of the actuator disk. */
vector<unsigned long> VolumePoint_Inv; /*!< \brief Vector containing the inverse mapping from the global index to the
added point index for the actuator disk. */

vector<su2double> CoordXActDisk; /*!< \brief X-coordinates of the new grid points added by splitting the actuator disk
(size = ActDiskNewPoints). */
vector<su2double> CoordYActDisk; /*!< \brief Y-coordinates of the new grid points added by splitting the actuator disk
(size = ActDiskNewPoints). */
vector<su2double> CoordZActDisk; /*!< \brief Z-coordinates of the new grid points added by splitting the actuator disk
(size = ActDiskNewPoints). */

vector<su2double> CoordXVolumePoint; /*!< \brief X-coordinates of the volume elements touching the actuator disk. */
vector<su2double> CoordYVolumePoint; /*!< \brief Y-coordinates of the volume elements touching the actuator disk. */
vector<su2double> CoordZVolumePoint; /*!< \brief Z-coordinates of the volume elements touching the actuator disk. */
ifstream mesh_file; /*!< \brief File object for the SU2 ASCII mesh file. */

/*!
* \brief Reads all SU2 ASCII mesh metadata and checks for errors.
Expand Down
114 changes: 114 additions & 0 deletions Common/include/geometry/meshreader/CSU2BinaryMeshReaderBase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*!
* \file CSU2BinaryMeshReaderBase.hpp
* \brief Header file for the class CSU2BinaryMeshReaderBase.
* The implementations are in the <i>CSU2BinaryMeshReaderBase.cpp</i> file.
* \author T. Economon, E. van der Weide
* \version 8.2.0 "Harrier"
*
* SU2 Project Website: https://su2code.github.io
*
* The SU2 Project is maintained by the SU2 Foundation
* (http://su2foundation.org)
*
* Copyright 2012-2025, SU2 Contributors (cf. AUTHORS.md)
*
* SU2 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.
*
* SU2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "CSU2MeshReaderBase.hpp"
#include "../../../include/toolboxes/SwapBytes.hpp"

/*!
* \class CSU2BinaryMeshReaderBase
* \brief Base class for the reading of a native SU2 binary grid.
* \author T. Economon, E. van der Weide
*/
class CSU2BinaryMeshReaderBase : public CSU2MeshReaderBase {
protected:
constexpr static int SU2_STRING_SIZE = 33; /*!< \brief Size of the strings in the SU2 binary mesh file. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason behind the small-ish limit? Can it be relaxed? I remember some of the CRM meshes having quite long names padded with spaces.


FILE* mesh_file; /*!< \brief File object for the SU2 binary mesh file. */
bool swap_bytes; /*!< \brief Whether or not byte swapping must be used. */
int size_conn_type; /*!< \brief Size, in bytes of the connectivity type. */

/*!
* \brief Reads the connectivity type used in the binary file and check if
* byte swapping must be applied.
*/
void ReadConnectivityType();

/*!
* \brief Reads all SU2 binary mesh metadata and checks for errors.
* \param[in,out] config - Problem configuration where some metadata is updated (e.g. AoA).
*/
void ReadMetadata(CConfig* config);

/*!
* \brief Reads the grid points from an SU2 zone into linear partitions across all ranks.
*/
virtual void ReadPointCoordinates();

/*!
* \brief Reads the interior volume elements from one section of an SU2 zone into linear partitions across all ranks.
*/
virtual void ReadVolumeElementConnectivity();

/*!
* \brief Reads the surface (boundary) elements from the SU2 zone.
*/
virtual void ReadSurfaceElementConnectivity();

/*!
* \brief Helper function to find the current zone in an SU2 binary mesh object.
*/
void FastForwardToMyZone();

/*!
* \brief Function to read one entity of the connectivity type from the binary file.
* \return uint64_t version of the the data.
*/
uint64_t ReadBinaryNEntities();

/*!
* \brief Template function to read data from the binary file.
*/
template <typename T>
void ReadBinaryData(T* data, const size_t nItems) {
/*--- Read the actual data. ---*/
auto ret = fread(data, sizeof(T), nItems, mesh_file);
if (ret != nItems) SU2_MPI::Error(string("Error while reading the file ") + meshFilename, CURRENT_FUNCTION);

/*--- Apply byte swapping, if needed. ---*/
if (swap_bytes) SwapBytes((char*)data, sizeof(T), nItems);
}

private:
/*!
* \brief Read the meta data for a zone.
*/
void ReadMetadataZone();

public:
/*!
* \brief Constructor of the CSU2BinaryMeshReaderBase class.
*/
CSU2BinaryMeshReaderBase(CConfig* val_config, unsigned short val_iZone, unsigned short val_nZone);

/*!
* \brief Destructor of the CSU2BinaryMeshReaderBase class.
*/
~CSU2BinaryMeshReaderBase(void) override;
};
66 changes: 66 additions & 0 deletions Common/include/geometry/meshreader/CSU2BinaryMeshReaderFEM.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*!
* \file CSU2BinaryMeshReaderFEM.hpp
* \brief Header file for the class CSU2BinaryMeshReaderFEM.
* The implementations are in the <i>CSU2BinaryMeshReaderFEM.cpp</i> file.
* \author T. Economon, E. van der Weide
* \version 8.2.0 "Harrier"
*
* SU2 Project Website: https://su2code.github.io
*
* The SU2 Project is maintained by the SU2 Foundation
* (http://su2foundation.org)
*
* Copyright 2012-2025, SU2 Contributors (cf. AUTHORS.md)
*
* SU2 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.
*
* SU2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "CSU2BinaryMeshReaderBase.hpp"

/*!
* \class CSU2BinaryMeshReaderFEM
* \brief Reads a native SU2 binary grid into linear partitions for the finite element solver (FEM).
* \author T. Economon, E. van der Weide
*/
class CSU2BinaryMeshReaderFEM : public CSU2BinaryMeshReaderBase {
private:
/*!
* \brief Reads the grid points from an SU2 zone into linear partitions across all ranks.
*/
void ReadPointCoordinates();

/*!
* \brief Reads the interior volume elements from one section of an SU2 zone into linear partitions across all ranks.
*/
void ReadVolumeElementConnectivity();

/*!
* \brief Reads the surface (boundary) elements from one section of an SU2 zone into linear partitions across all
* ranks.
*/
void ReadSurfaceElementConnectivity();

public:
/*!
* \brief Constructor of the CSU2BinaryMeshReaderFEM class.
*/
CSU2BinaryMeshReaderFEM(CConfig* val_config, unsigned short val_iZone, unsigned short val_nZone);

/*!
* \brief Destructor of the CSU2BinaryMeshReaderFEM class.
*/
~CSU2BinaryMeshReaderFEM(void) override;
Comment on lines +62 to +65
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omit destructors if you don't need them to do something custom.

};
55 changes: 55 additions & 0 deletions Common/include/geometry/meshreader/CSU2BinaryMeshReaderFVM.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*!
* \file CSU2BinaryMeshReaderFVM.hpp
* \brief Header file for the class CSU2BinaryMeshReaderFVM.
* The implementations are in the <i>CSU2BinaryMeshReaderFVM.cpp</i> file.
* \author T. Econonmon, E. van der Weide
* \version 8.2.0 "Harrier"
*
* SU2 Project Website: https://su2code.github.io
*
* The SU2 Project is maintained by the SU2 Foundation
* (http://su2foundation.org)
*
* Copyright 2012-2025, SU2 Contributors (cf. AUTHORS.md)
*
* SU2 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.
*
* SU2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "CSU2BinaryMeshReaderBase.hpp"

/*!
* \class CSU2BinaryMeshReaderFVM
* \brief Reads a native SU2 binary grid into linear partitions for the finite volume solver (FVM).
* \author T. Econonmon, E. van der Weide
*/
class CSU2BinaryMeshReaderFVM : public CSU2BinaryMeshReaderBase {
private:
/*!
* \brief Splits a single surface actuator disk boundary into two separate markers (repeated points).
*/
void SplitActuatorDiskSurface();

public:
/*!
* \brief Constructor of the CSU2BinaryMeshReaderFVM class.
*/
CSU2BinaryMeshReaderFVM(CConfig* val_config, unsigned short val_iZone, unsigned short val_nZone);

/*!
* \brief Destructor of the CSU2BinaryMeshReaderFVM class.
*/
~CSU2BinaryMeshReaderFVM(void) override;
};
84 changes: 84 additions & 0 deletions Common/include/geometry/meshreader/CSU2MeshReaderBase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*!
* \file CSU2MeshReaderBase.hpp
* \brief Header file for the class CSU2MeshReaderBase.
* The implementations are in the <i>CSU2MeshReaderBase.cpp</i> file.
* \author T. Economon
* \version 8.2.0 "Harrier"
*
* SU2 Project Website: https://su2code.github.io
*
* The SU2 Project is maintained by the SU2 Foundation
* (http://su2foundation.org)
*
* Copyright 2012-2025, SU2 Contributors (cf. AUTHORS.md)
*
* SU2 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.
*
* SU2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <array>

#include "CMeshReaderBase.hpp"

/*!
* \class CSU2MeshReaderBase
* \brief Base class for the reading of a native SU2 grid.
* \author T. Economon
*/
class CSU2MeshReaderBase : public CMeshReaderBase {
protected:
const unsigned short myZone; /*!< \brief Current SU2 zone index. */
const unsigned short nZones; /*!< \brief Total number of zones in the SU2 file. */

const string meshFilename; /*!< \brief Name of the SU2 ASCII mesh file being read. */

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

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

su2double Xloc = 0.0; /*!< \brief X-coordinate of the CG of the actuator disk surface. */
su2double Yloc = 0.0; /*!< \brief X-coordinate of the CG of the actuator disk surface. */
su2double Zloc = 0.0; /*!< \brief X-coordinate of the CG of the actuator disk surface. */

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

vector<unsigned long> ActDiskPoint_Back; /*!< \brief Vector containing the global index for the new grid points added
to the back of the actuator disk. */
vector<unsigned long> VolumePoint_Inv; /*!< \brief Vector containing the inverse mapping from the global index to the
added point index for the actuator disk. */

vector<su2double> CoordXActDisk; /*!< \brief X-coordinates of the new grid points added by splitting the actuator disk
(size = ActDiskNewPoints). */
vector<su2double> CoordYActDisk; /*!< \brief Y-coordinates of the new grid points added by splitting the actuator disk
(size = ActDiskNewPoints). */
vector<su2double> CoordZActDisk; /*!< \brief Z-coordinates of the new grid points added by splitting the actuator disk
(size = ActDiskNewPoints). */

vector<su2double> CoordXVolumePoint; /*!< \brief X-coordinates of the volume elements touching the actuator disk. */
vector<su2double> CoordYVolumePoint; /*!< \brief Y-coordinates of the volume elements touching the actuator disk. */
vector<su2double> CoordZVolumePoint; /*!< \brief Z-coordinates of the volume elements touching the actuator disk. */

public:
/*!
* \brief Constructor of the CSU2MeshReaderBase class.
*/
CSU2MeshReaderBase(CConfig* val_config, unsigned short val_iZone, unsigned short val_nZone);

/*!
* \brief Destructor of the CSU2MeshReaderBase class.
*/
~CSU2MeshReaderBase(void) override;
};
8 changes: 5 additions & 3 deletions Common/include/option_structure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2116,12 +2116,14 @@ static const MapType<std::string, ENUM_OBJECTIVE> Objective_Map = {
*/
enum ENUM_INPUT {
SU2 = 1, /*!< \brief SU2 input format. */
CGNS_GRID = 2, /*!< \brief CGNS input format for the computational grid. */
RECTANGLE = 3, /*!< \brief 2D rectangular mesh with N x M points of size Lx x Ly. */
BOX = 4 /*!< \brief 3D box mesh with N x M x L points of size Lx x Ly x Lz. */
SU2_BIN = 2, /*!< \brief SU2 binary input format. */
CGNS_GRID = 3, /*!< \brief CGNS input format for the computational grid. */
RECTANGLE = 4, /*!< \brief 2D rectangular mesh with N x M points of size Lx x Ly. */
BOX = 5 /*!< \brief 3D box mesh with N x M x L points of size Lx x Ly x Lz. */
};
static const MapType<std::string, ENUM_INPUT> Input_Map = {
MakePair("SU2", SU2)
MakePair("SU2B", SU2_BIN)
MakePair("CGNS", CGNS_GRID)
MakePair("RECTANGLE", RECTANGLE)
MakePair("BOX", BOX)
Expand Down
Loading
Loading