Skip to content

Commit

Permalink
Merge pull request #2372 from su2code/feature_small_restart
Browse files Browse the repository at this point in the history
Write compact restart files
  • Loading branch information
pcarruscag authored Jan 2, 2025
2 parents 99e6e54 + 13b08f5 commit f4cda52
Show file tree
Hide file tree
Showing 20 changed files with 224 additions and 153 deletions.
7 changes: 7 additions & 0 deletions Common/include/CConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ class CConfig {
unsigned long StartConv_Iter; /*!< \brief Start convergence criteria at iteration. */
su2double Cauchy_Eps; /*!< \brief Epsilon used for the convergence. */
bool Restart, /*!< \brief Restart solution (for direct, adjoint, and linearized problems).*/
Wrt_Restart_Compact, /*!< \brief Write compact restart files with minimum nr. of variables. */
Read_Binary_Restart, /*!< \brief Read binary SU2 native restart files.*/
Wrt_Restart_Overwrite, /*!< \brief Overwrite restart files or append iteration number.*/
Wrt_Surface_Overwrite, /*!< \brief Overwrite surface output files or append iteration number.*/
Expand Down Expand Up @@ -5503,6 +5504,12 @@ class CConfig {
*/
bool GetRead_Binary_Restart(void) const { return Read_Binary_Restart; }

/*!
* \brief Flag for whether restart files contain only necessary variables.
* \return Flag <code>TRUE</code> then the code will write compact restart files.
*/
bool GetWrt_Restart_Compact(void) const { return Wrt_Restart_Compact; }

/*!
* \brief Flag for whether restart solution files are overwritten.
* \return Flag for overwriting. If Flag=false, iteration nr is appended to filename
Expand Down
2 changes: 2 additions & 0 deletions Common/src/CConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,8 @@ void CConfig::SetConfig_Options() {

/*!\brief RESTART_SOL \n DESCRIPTION: Restart solution from native solution file \n Options: NO, YES \ingroup Config */
addBoolOption("RESTART_SOL", Restart, false);
/*!\brief WRT_RESTART_COMPACT \n DESCRIPTION: Minimize the size of restart files \n Options: NO, YES \ingroup Config */
addBoolOption("WRT_RESTART_COMPACT", Wrt_Restart_Compact, true);
/*!\brief BINARY_RESTART \n DESCRIPTION: Read binary SU2 native restart files. \n Options: YES, NO \ingroup Config */
addBoolOption("READ_BINARY_RESTART", Read_Binary_Restart, true);
/*!\brief WRT_RESTART_OVERWRITE \n DESCRIPTION: overwrite restart files or append iteration number. \n Options: YES, NO \ingroup Config */
Expand Down
72 changes: 41 additions & 31 deletions SU2_CFD/include/output/COutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,16 @@ class COutput {

/*----------------------------- Volume output ----------------------------*/

CParallelDataSorter* volumeDataSorter; //!< Volume data sorter
CParallelDataSorter* surfaceDataSorter; //!< Surface data sorter
CParallelDataSorter* volumeDataSorter; //!< Volume data sorter.
CParallelDataSorter* volumeDataSorterCompact; //!< Volume data sorter for compact files.
CParallelDataSorter* surfaceDataSorter; //!< Surface data sorter.

vector<string> volumeFieldNames; //!< Vector containing the volume field names
unsigned short nVolumeFields; //!< Number of fields in the volume output
vector<string> volumeFieldNames; //!< Vector containing the volume field names.
vector<string> requiredVolumeFieldNames; //!< Vector containing the minimum required volume field names.

string volumeFilename, //!< Volume output filename
surfaceFilename, //!< Surface output filename
restartFilename; //!< Restart output filename
string volumeFilename, //!< Volume output filename.
surfaceFilename, //!< Surface output filename.
restartFilename; //!< Restart output filename.

/** \brief Structure to store information for a volume output field.
*
Expand All @@ -259,40 +260,48 @@ class COutput {
/*! \brief The name of the field, i.e. the name that is printed in the file header.*/
string fieldName;
/*! \brief This value identifies the position of the values of this field at each node in the ::Local_Data array. */
short offset;
short offset = -1;
/*! \brief This offset is used for the compact formulation. */
short offsetCompact = -1;
/*! \brief The group this field belongs to. */
string outputGroup;
/*! \brief String containing the description of the field */
/*! \brief String containing the description of the field. */
string description;
/*! \brief Default constructor. */
VolumeOutputField () {}
VolumeOutputField() = default;
/*! \brief Constructor to initialize all members. */
VolumeOutputField(string fieldName_, int offset_, string volumeOutputGroup_, string description_):
fieldName(std::move(fieldName_)), offset(std::move(offset_)),
outputGroup(std::move(volumeOutputGroup_)), description(std::move(description_)){}
VolumeOutputField(string fieldName_, string volumeOutputGroup_, string description_):
fieldName(std::move(fieldName_)),
outputGroup(std::move(volumeOutputGroup_)),
description(std::move(description_)) {}
};

/*! \brief Associative map to access data stored in the volume output fields by a string identifier. */
std::map<string, VolumeOutputField > volumeOutput_Map;
std::map<string, VolumeOutputField > volumeOutput_Map;
/*! \brief Vector that contains the keys of the ::volumeOutput_Map in the order of their insertion. */
std::vector<string> volumeOutput_List;

/*! \brief Vector to cache the positions of the field in the data array */
std::vector<short> fieldIndexCache;
/*! \brief Current value of the cache index */
unsigned short cachePosition;
/*! \brief Boolean to store whether the field index cache should be build. */
bool buildFieldIndexCache;
/*! \brief Vector to cache the positions of the field in the data array */
std::vector<short> fieldGetIndexCache;
/*! \brief Current value of the cache index */
unsigned short curGetFieldIndex;
std::vector<string> volumeOutput_List;

/*! \brief Whether the field index caches should be build. */
bool buildFieldIndexCache;

/*! \brief Vectors to cache the positions of the fields in the data array. */
std::vector<short> fieldIndexCache, fieldIndexCacheCompact;
/*! \brief Current value of the cache indices. */
unsigned short cachePosition;

/*! \brief Vector to cache the positions of the field in the data array. */
std::vector<short> fieldGetIndexCache;
/*! \brief Current value of the cache index. */
unsigned short curGetFieldIndex;

/*! \brief Requested volume field names in the config file. */
std::vector<string> requestedVolumeFields;
/*! \brief Number of requested volume field names in the config file. */
unsigned short nRequestedVolumeFields;

/*! \brief Minimum required volume fields for restart file. */
const std::vector<string> restartVolumeFields = {"COORDINATES", "SOLUTION", "SENSITIVITY", "GRID_VELOCITY"};

/*----------------------------- Convergence monitoring ----------------------------*/

su2double cauchyValue, /*!< \brief Summed value of the convergence indicator. */
Expand Down Expand Up @@ -736,8 +745,9 @@ class COutput {
* \param[in] groupname - The name of the group this field belongs to.
* \param[in] description - Description of the volume field.
*/
inline void AddVolumeOutput(string name, string field_name, string groupname, string description){
volumeOutput_Map[name] = VolumeOutputField(field_name, -1, groupname, description);
inline void AddVolumeOutput(const string& name, const string& field_name,
const string& group_name, const string& description) {
volumeOutput_Map[name] = VolumeOutputField(field_name, group_name, description);
volumeOutput_List.push_back(name);
}

Expand Down Expand Up @@ -959,14 +969,14 @@ class COutput {

/*!
* \brief Sets the turboperformance screen output
* \param[in] TurboPerf - Turboperformance class
* \param[in] TurboPerf - Turboperformance class
* \param[in] config - Definition of the particular problem
* \param[in] TimeIter - Index of the current time-step
* \param[in] OuterIter - Index of current outer iteration
* \param[in] InnerIter - Index of current inner iteration
*/
inline virtual void SetTurboPerformance_Output(std::shared_ptr<CTurboOutput> TurboPerf, CConfig *config, unsigned long TimeIter, unsigned long OuterIter, unsigned long InnerIter) {}

/*!
* \brief Sets the multizone turboperformacne screen output
* \param[in] TurboStagePerf - Stage turboperformance class
Expand All @@ -982,7 +992,7 @@ class COutput {
* \param[in] config - Definition of the particular problem
*/
inline virtual void LoadTurboHistoryData(std::shared_ptr<CTurbomachineryStagePerformance> TurboStagePerf, std::shared_ptr<CTurboOutput> TurboPerf, CConfig *config) {}

/*!
* \brief Write the kinematic and thermodynamic variables at each spanwise division
* \param[in] solver - The container hold all solution data
Expand Down
19 changes: 18 additions & 1 deletion SU2_CFD/include/output/filewriter/CParallelDataSorter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ class CParallelDataSorter{
int nSends, //!< Number of sends
nRecvs; //!< Number of receives

vector<string> fieldNames; //!< Vector with names of the output fields
vector<string> fieldNames; //!< Vector with names of all the output fields
vector<string> requiredFieldNames; //!< Vector with names of the required output fields that we write to file

unsigned short nDim; //!< Spatial dimension of the data

Expand Down Expand Up @@ -340,6 +341,22 @@ class CParallelDataSorter{
return fieldNames;
}

/*!
* \brief Get the vector containing the names of the required output fields
* \return Vector of strings containing the required field names
*/
const vector<string>& GetRequiredFieldNames() const{
return requiredFieldNames;
}

/*!
* \brief Set the vector of required output fields.
* \return None.
*/
void SetRequiredFieldNames(const vector<string>& req_field_names) {
requiredFieldNames = req_field_names;
}

/*!
* \brief Get the spatial dimension
* \return The spatial dimension
Expand Down
2 changes: 1 addition & 1 deletion SU2_CFD/src/output/CAdjFlowCompOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ CAdjFlowCompOutput::CAdjFlowCompOutput(CConfig *config, unsigned short nDim) : C

if (find(requestedVolumeFields.begin(), requestedVolumeFields.end(), string("SENSITIVITY")) == requestedVolumeFields.end()) {
requestedVolumeFields.emplace_back("SENSITIVITY");
nRequestedVolumeFields ++;
nRequestedVolumeFields++;
}

stringstream ss;
Expand Down
2 changes: 1 addition & 1 deletion SU2_CFD/src/output/CAdjFlowIncOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ CAdjFlowIncOutput::CAdjFlowIncOutput(CConfig *config, unsigned short nDim) : CAd

if (find(requestedVolumeFields.begin(), requestedVolumeFields.end(), string("SENSITIVITY")) == requestedVolumeFields.end()) {
requestedVolumeFields.emplace_back("SENSITIVITY");
nRequestedVolumeFields ++;
nRequestedVolumeFields++;
}

stringstream ss;
Expand Down
2 changes: 1 addition & 1 deletion SU2_CFD/src/output/CAdjHeatOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ CAdjHeatOutput::CAdjHeatOutput(CConfig *config, unsigned short nDim) : COutput(c

if (find(requestedVolumeFields.begin(), requestedVolumeFields.end(), string("SENSITIVITY")) == requestedVolumeFields.end()) {
requestedVolumeFields.emplace_back("SENSITIVITY");
nRequestedVolumeFields ++;
nRequestedVolumeFields++;
}

stringstream ss;
Expand Down
17 changes: 8 additions & 9 deletions SU2_CFD/src/output/CElasticityOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,21 +235,20 @@ void CElasticityOutput::SetVolumeOutputFields(CConfig *config){
// Grid coordinates
AddVolumeOutput("COORD-X", "x", "COORDINATES", "x-component of the coordinate vector");
AddVolumeOutput("COORD-Y", "y", "COORDINATES", "y-component of the coordinate vector");
if (nDim == 3)
AddVolumeOutput("COORD-Z", "z", "COORDINATES", "z-component of the coordinate vector");
if (nDim == 3) AddVolumeOutput("COORD-Z", "z", "COORDINATES", "z-component of the coordinate vector");

AddVolumeOutput("DISPLACEMENT-X", "Displacement_x", "SOLUTION", "x-component of the displacement vector");
AddVolumeOutput("DISPLACEMENT-Y", "Displacement_y", "SOLUTION", "y-component of the displacement vector");
if (nDim == 3) AddVolumeOutput("DISPLACEMENT-Z", "Displacement_z", "SOLUTION", "z-component of the displacement vector");

if(dynamic){
AddVolumeOutput("VELOCITY-X", "Velocity_x", "VELOCITY", "x-component of the velocity vector");
AddVolumeOutput("VELOCITY-Y", "Velocity_y", "VELOCITY", "y-component of the velocity vector");
if (nDim == 3) AddVolumeOutput("VELOCITY-Z", "Velocity_z", "VELOCITY", "z-component of the velocity vector");
if (dynamic) {
AddVolumeOutput("VELOCITY-X", "Velocity_x", "SOLUTION", "x-component of the velocity vector");
AddVolumeOutput("VELOCITY-Y", "Velocity_y", "SOLUTION", "y-component of the velocity vector");
if (nDim == 3) AddVolumeOutput("VELOCITY-Z", "Velocity_z", "SOLUTION", "z-component of the velocity vector");

AddVolumeOutput("ACCELERATION-X", "Acceleration_x", "ACCELERATION", "x-component of the acceleration vector");
AddVolumeOutput("ACCELERATION-Y", "Acceleration_y", "ACCELERATION", "y-component of the acceleration vector");
if (nDim == 3) AddVolumeOutput("ACCELERATION-Z", "Acceleration_z", "ACCELERATION", "z-component of the acceleration vector");
AddVolumeOutput("ACCELERATION-X", "Acceleration_x", "SOLUTION", "x-component of the acceleration vector");
AddVolumeOutput("ACCELERATION-Y", "Acceleration_y", "SOLUTION", "y-component of the acceleration vector");
if (nDim == 3) AddVolumeOutput("ACCELERATION-Z", "Acceleration_z", "SOLUTION", "z-component of the acceleration vector");
}

AddVolumeOutput("STRESS-XX", "Sxx", "STRESS", "x-component of the normal stress vector");
Expand Down
20 changes: 10 additions & 10 deletions SU2_CFD/src/output/CFlowCompOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ CFlowCompOutput::CFlowCompOutput(const CConfig *config, unsigned short nDim) : C
auto notFound = requestedVolumeFields.end();
if (find(requestedVolumeFields.begin(), notFound, string("GRID_VELOCITY")) == notFound) {
requestedVolumeFields.emplace_back("GRID_VELOCITY");
nRequestedVolumeFields ++;
nRequestedVolumeFields++;
}
}

Expand Down Expand Up @@ -219,7 +219,7 @@ void CFlowCompOutput::SetVolumeOutputFields(CConfig *config){
AddVolumeOutput("DENSITY", "Density", "SOLUTION", "Density");
AddVolumeOutput("MOMENTUM-X", "Momentum_x", "SOLUTION", "x-component of the momentum vector");
AddVolumeOutput("MOMENTUM-Y", "Momentum_y", "SOLUTION", "y-component of the momentum vector");

if (nDim == 3)
AddVolumeOutput("MOMENTUM-Z", "Momentum_z", "SOLUTION", "z-component of the momentum vector");
AddVolumeOutput("ENERGY", "Energy", "SOLUTION", "Energy");
Expand All @@ -241,7 +241,7 @@ void CFlowCompOutput::SetVolumeOutputFields(CConfig *config){
AddVolumeOutput("PRESSURE_COEFF", "Pressure_Coefficient", "PRIMITIVE", "Pressure coefficient");
AddVolumeOutput("VELOCITY-X", "Velocity_x", "PRIMITIVE", "x-component of the velocity vector");
AddVolumeOutput("VELOCITY-Y", "Velocity_y", "PRIMITIVE", "y-component of the velocity vector");

if (nDim == 3)
AddVolumeOutput("VELOCITY-Z", "Velocity_z", "PRIMITIVE", "z-component of the velocity vector");

Expand Down Expand Up @@ -525,7 +525,7 @@ void CFlowCompOutput::SetTurboPerformance_Output(std::shared_ptr<CTurboOutput> T

for (unsigned short iZone = 0; iZone <= config->GetnZone()-1; iZone++) {
auto nSpan = config->GetnSpan_iZones(iZone);
const auto& BladePerf = BladePerformance.at(iZone).at(nSpan);
const auto& BladePerf = BladePerformance.at(iZone).at(nSpan);

TurboInOut<<" BLADE ROW INDEX "<<iZone <<"";
TurboInOut.PrintFooter();
Expand Down Expand Up @@ -772,7 +772,7 @@ void CFlowCompOutput::WriteTurboSpanwisePerformance(std::shared_ptr<CTurboOutput
file.width(30); file << BladePerf->GetInletState().GetVelocity()[iDim]*config[ZONE_0]->GetVelocity_Ref();
}
file.width(30); file << BladePerf->GetInletState().GetVelocityValue()*config[ZONE_0]->GetVelocity_Ref();
// This captures NaNs
// This captures NaNs
if(isnan(BladePerf->GetInletState().GetAbsFlowAngle())){
file.width(30); file << "0.0000";
}
Expand All @@ -792,11 +792,11 @@ void CFlowCompOutput::WriteTurboSpanwisePerformance(std::shared_ptr<CTurboOutput

/*--- Writing Span wise outflow thermodynamic quantities. ---*/
spanwise_performance_filename = "TURBOMACHINERY/outflow_spanwise_kinematic_values";
if (nZone > 1) {
spanwise_performance_filename.append("_" + std::to_string(val_iZone) + ".dat");
} else {
spanwise_performance_filename.append(".dat");
}
if (nZone > 1) {
spanwise_performance_filename.append("_" + std::to_string(val_iZone) + ".dat");
} else {
spanwise_performance_filename.append(".dat");
}
file.open (spanwise_performance_filename.data(), ios::out | ios::trunc);
file.setf(ios::scientific);
file.precision(12);
Expand Down
2 changes: 1 addition & 1 deletion SU2_CFD/src/output/CFlowIncOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ CFlowIncOutput::CFlowIncOutput(CConfig *config, unsigned short nDim) : CFlowOutp
auto notFound = requestedVolumeFields.end();
if (find(requestedVolumeFields.begin(), notFound, string("GRID_VELOCITY")) == notFound) {
requestedVolumeFields.emplace_back("GRID_VELOCITY");
nRequestedVolumeFields ++;
nRequestedVolumeFields++;
}
}

Expand Down
2 changes: 1 addition & 1 deletion SU2_CFD/src/output/CNEMOCompOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ CNEMOCompOutput::CNEMOCompOutput(const CConfig *config, unsigned short nDim) : C
auto notFound = requestedVolumeFields.end();
if (find(requestedVolumeFields.begin(), notFound, string("GRID_VELOCITY")) == notFound) {
requestedVolumeFields.emplace_back("GRID_VELOCITY");
nRequestedVolumeFields ++;
nRequestedVolumeFields++;
}
}

Expand Down
Loading

0 comments on commit f4cda52

Please sign in to comment.