Skip to content

Commit f4cda52

Browse files
authored
Merge pull request #2372 from su2code/feature_small_restart
Write compact restart files
2 parents 99e6e54 + 13b08f5 commit f4cda52

File tree

20 files changed

+224
-153
lines changed

20 files changed

+224
-153
lines changed

Common/include/CConfig.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ class CConfig {
700700
unsigned long StartConv_Iter; /*!< \brief Start convergence criteria at iteration. */
701701
su2double Cauchy_Eps; /*!< \brief Epsilon used for the convergence. */
702702
bool Restart, /*!< \brief Restart solution (for direct, adjoint, and linearized problems).*/
703+
Wrt_Restart_Compact, /*!< \brief Write compact restart files with minimum nr. of variables. */
703704
Read_Binary_Restart, /*!< \brief Read binary SU2 native restart files.*/
704705
Wrt_Restart_Overwrite, /*!< \brief Overwrite restart files or append iteration number.*/
705706
Wrt_Surface_Overwrite, /*!< \brief Overwrite surface output files or append iteration number.*/
@@ -5503,6 +5504,12 @@ class CConfig {
55035504
*/
55045505
bool GetRead_Binary_Restart(void) const { return Read_Binary_Restart; }
55055506

5507+
/*!
5508+
* \brief Flag for whether restart files contain only necessary variables.
5509+
* \return Flag <code>TRUE</code> then the code will write compact restart files.
5510+
*/
5511+
bool GetWrt_Restart_Compact(void) const { return Wrt_Restart_Compact; }
5512+
55065513
/*!
55075514
* \brief Flag for whether restart solution files are overwritten.
55085515
* \return Flag for overwriting. If Flag=false, iteration nr is appended to filename

Common/src/CConfig.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,8 @@ void CConfig::SetConfig_Options() {
11721172

11731173
/*!\brief RESTART_SOL \n DESCRIPTION: Restart solution from native solution file \n Options: NO, YES \ingroup Config */
11741174
addBoolOption("RESTART_SOL", Restart, false);
1175+
/*!\brief WRT_RESTART_COMPACT \n DESCRIPTION: Minimize the size of restart files \n Options: NO, YES \ingroup Config */
1176+
addBoolOption("WRT_RESTART_COMPACT", Wrt_Restart_Compact, true);
11751177
/*!\brief BINARY_RESTART \n DESCRIPTION: Read binary SU2 native restart files. \n Options: YES, NO \ingroup Config */
11761178
addBoolOption("READ_BINARY_RESTART", Read_Binary_Restart, true);
11771179
/*!\brief WRT_RESTART_OVERWRITE \n DESCRIPTION: overwrite restart files or append iteration number. \n Options: YES, NO \ingroup Config */

SU2_CFD/include/output/COutput.hpp

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,16 @@ class COutput {
241241

242242
/*----------------------------- Volume output ----------------------------*/
243243

244-
CParallelDataSorter* volumeDataSorter; //!< Volume data sorter
245-
CParallelDataSorter* surfaceDataSorter; //!< Surface data sorter
244+
CParallelDataSorter* volumeDataSorter; //!< Volume data sorter.
245+
CParallelDataSorter* volumeDataSorterCompact; //!< Volume data sorter for compact files.
246+
CParallelDataSorter* surfaceDataSorter; //!< Surface data sorter.
246247

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

250-
string volumeFilename, //!< Volume output filename
251-
surfaceFilename, //!< Surface output filename
252-
restartFilename; //!< Restart output filename
251+
string volumeFilename, //!< Volume output filename.
252+
surfaceFilename, //!< Surface output filename.
253+
restartFilename; //!< Restart output filename.
253254

254255
/** \brief Structure to store information for a volume output field.
255256
*
@@ -259,40 +260,48 @@ class COutput {
259260
/*! \brief The name of the field, i.e. the name that is printed in the file header.*/
260261
string fieldName;
261262
/*! \brief This value identifies the position of the values of this field at each node in the ::Local_Data array. */
262-
short offset;
263+
short offset = -1;
264+
/*! \brief This offset is used for the compact formulation. */
265+
short offsetCompact = -1;
263266
/*! \brief The group this field belongs to. */
264267
string outputGroup;
265-
/*! \brief String containing the description of the field */
268+
/*! \brief String containing the description of the field. */
266269
string description;
267270
/*! \brief Default constructor. */
268-
VolumeOutputField () {}
271+
VolumeOutputField() = default;
269272
/*! \brief Constructor to initialize all members. */
270-
VolumeOutputField(string fieldName_, int offset_, string volumeOutputGroup_, string description_):
271-
fieldName(std::move(fieldName_)), offset(std::move(offset_)),
272-
outputGroup(std::move(volumeOutputGroup_)), description(std::move(description_)){}
273+
VolumeOutputField(string fieldName_, string volumeOutputGroup_, string description_):
274+
fieldName(std::move(fieldName_)),
275+
outputGroup(std::move(volumeOutputGroup_)),
276+
description(std::move(description_)) {}
273277
};
274278

275279
/*! \brief Associative map to access data stored in the volume output fields by a string identifier. */
276-
std::map<string, VolumeOutputField > volumeOutput_Map;
280+
std::map<string, VolumeOutputField > volumeOutput_Map;
277281
/*! \brief Vector that contains the keys of the ::volumeOutput_Map in the order of their insertion. */
278-
std::vector<string> volumeOutput_List;
279-
280-
/*! \brief Vector to cache the positions of the field in the data array */
281-
std::vector<short> fieldIndexCache;
282-
/*! \brief Current value of the cache index */
283-
unsigned short cachePosition;
284-
/*! \brief Boolean to store whether the field index cache should be build. */
285-
bool buildFieldIndexCache;
286-
/*! \brief Vector to cache the positions of the field in the data array */
287-
std::vector<short> fieldGetIndexCache;
288-
/*! \brief Current value of the cache index */
289-
unsigned short curGetFieldIndex;
282+
std::vector<string> volumeOutput_List;
283+
284+
/*! \brief Whether the field index caches should be build. */
285+
bool buildFieldIndexCache;
286+
287+
/*! \brief Vectors to cache the positions of the fields in the data array. */
288+
std::vector<short> fieldIndexCache, fieldIndexCacheCompact;
289+
/*! \brief Current value of the cache indices. */
290+
unsigned short cachePosition;
291+
292+
/*! \brief Vector to cache the positions of the field in the data array. */
293+
std::vector<short> fieldGetIndexCache;
294+
/*! \brief Current value of the cache index. */
295+
unsigned short curGetFieldIndex;
290296

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

302+
/*! \brief Minimum required volume fields for restart file. */
303+
const std::vector<string> restartVolumeFields = {"COORDINATES", "SOLUTION", "SENSITIVITY", "GRID_VELOCITY"};
304+
296305
/*----------------------------- Convergence monitoring ----------------------------*/
297306

298307
su2double cauchyValue, /*!< \brief Summed value of the convergence indicator. */
@@ -736,8 +745,9 @@ class COutput {
736745
* \param[in] groupname - The name of the group this field belongs to.
737746
* \param[in] description - Description of the volume field.
738747
*/
739-
inline void AddVolumeOutput(string name, string field_name, string groupname, string description){
740-
volumeOutput_Map[name] = VolumeOutputField(field_name, -1, groupname, description);
748+
inline void AddVolumeOutput(const string& name, const string& field_name,
749+
const string& group_name, const string& description) {
750+
volumeOutput_Map[name] = VolumeOutputField(field_name, group_name, description);
741751
volumeOutput_List.push_back(name);
742752
}
743753

@@ -959,14 +969,14 @@ class COutput {
959969

960970
/*!
961971
* \brief Sets the turboperformance screen output
962-
* \param[in] TurboPerf - Turboperformance class
972+
* \param[in] TurboPerf - Turboperformance class
963973
* \param[in] config - Definition of the particular problem
964974
* \param[in] TimeIter - Index of the current time-step
965975
* \param[in] OuterIter - Index of current outer iteration
966976
* \param[in] InnerIter - Index of current inner iteration
967977
*/
968978
inline virtual void SetTurboPerformance_Output(std::shared_ptr<CTurboOutput> TurboPerf, CConfig *config, unsigned long TimeIter, unsigned long OuterIter, unsigned long InnerIter) {}
969-
979+
970980
/*!
971981
* \brief Sets the multizone turboperformacne screen output
972982
* \param[in] TurboStagePerf - Stage turboperformance class
@@ -982,7 +992,7 @@ class COutput {
982992
* \param[in] config - Definition of the particular problem
983993
*/
984994
inline virtual void LoadTurboHistoryData(std::shared_ptr<CTurbomachineryStagePerformance> TurboStagePerf, std::shared_ptr<CTurboOutput> TurboPerf, CConfig *config) {}
985-
995+
986996
/*!
987997
* \brief Write the kinematic and thermodynamic variables at each spanwise division
988998
* \param[in] solver - The container hold all solution data

SU2_CFD/include/output/filewriter/CParallelDataSorter.hpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ class CParallelDataSorter{
108108
int nSends, //!< Number of sends
109109
nRecvs; //!< Number of receives
110110

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

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

@@ -340,6 +341,22 @@ class CParallelDataSorter{
340341
return fieldNames;
341342
}
342343

344+
/*!
345+
* \brief Get the vector containing the names of the required output fields
346+
* \return Vector of strings containing the required field names
347+
*/
348+
const vector<string>& GetRequiredFieldNames() const{
349+
return requiredFieldNames;
350+
}
351+
352+
/*!
353+
* \brief Set the vector of required output fields.
354+
* \return None.
355+
*/
356+
void SetRequiredFieldNames(const vector<string>& req_field_names) {
357+
requiredFieldNames = req_field_names;
358+
}
359+
343360
/*!
344361
* \brief Get the spatial dimension
345362
* \return The spatial dimension

SU2_CFD/src/output/CAdjFlowCompOutput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ CAdjFlowCompOutput::CAdjFlowCompOutput(CConfig *config, unsigned short nDim) : C
6161

6262
if (find(requestedVolumeFields.begin(), requestedVolumeFields.end(), string("SENSITIVITY")) == requestedVolumeFields.end()) {
6363
requestedVolumeFields.emplace_back("SENSITIVITY");
64-
nRequestedVolumeFields ++;
64+
nRequestedVolumeFields++;
6565
}
6666

6767
stringstream ss;

SU2_CFD/src/output/CAdjFlowIncOutput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ CAdjFlowIncOutput::CAdjFlowIncOutput(CConfig *config, unsigned short nDim) : CAd
6767

6868
if (find(requestedVolumeFields.begin(), requestedVolumeFields.end(), string("SENSITIVITY")) == requestedVolumeFields.end()) {
6969
requestedVolumeFields.emplace_back("SENSITIVITY");
70-
nRequestedVolumeFields ++;
70+
nRequestedVolumeFields++;
7171
}
7272

7373
stringstream ss;

SU2_CFD/src/output/CAdjHeatOutput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ CAdjHeatOutput::CAdjHeatOutput(CConfig *config, unsigned short nDim) : COutput(c
5858

5959
if (find(requestedVolumeFields.begin(), requestedVolumeFields.end(), string("SENSITIVITY")) == requestedVolumeFields.end()) {
6060
requestedVolumeFields.emplace_back("SENSITIVITY");
61-
nRequestedVolumeFields ++;
61+
nRequestedVolumeFields++;
6262
}
6363

6464
stringstream ss;

SU2_CFD/src/output/CElasticityOutput.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,21 +235,20 @@ void CElasticityOutput::SetVolumeOutputFields(CConfig *config){
235235
// Grid coordinates
236236
AddVolumeOutput("COORD-X", "x", "COORDINATES", "x-component of the coordinate vector");
237237
AddVolumeOutput("COORD-Y", "y", "COORDINATES", "y-component of the coordinate vector");
238-
if (nDim == 3)
239-
AddVolumeOutput("COORD-Z", "z", "COORDINATES", "z-component of the coordinate vector");
238+
if (nDim == 3) AddVolumeOutput("COORD-Z", "z", "COORDINATES", "z-component of the coordinate vector");
240239

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

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

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

255254
AddVolumeOutput("STRESS-XX", "Sxx", "STRESS", "x-component of the normal stress vector");

SU2_CFD/src/output/CFlowCompOutput.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ CFlowCompOutput::CFlowCompOutput(const CConfig *config, unsigned short nDim) : C
6161
auto notFound = requestedVolumeFields.end();
6262
if (find(requestedVolumeFields.begin(), notFound, string("GRID_VELOCITY")) == notFound) {
6363
requestedVolumeFields.emplace_back("GRID_VELOCITY");
64-
nRequestedVolumeFields ++;
64+
nRequestedVolumeFields++;
6565
}
6666
}
6767

@@ -219,7 +219,7 @@ void CFlowCompOutput::SetVolumeOutputFields(CConfig *config){
219219
AddVolumeOutput("DENSITY", "Density", "SOLUTION", "Density");
220220
AddVolumeOutput("MOMENTUM-X", "Momentum_x", "SOLUTION", "x-component of the momentum vector");
221221
AddVolumeOutput("MOMENTUM-Y", "Momentum_y", "SOLUTION", "y-component of the momentum vector");
222-
222+
223223
if (nDim == 3)
224224
AddVolumeOutput("MOMENTUM-Z", "Momentum_z", "SOLUTION", "z-component of the momentum vector");
225225
AddVolumeOutput("ENERGY", "Energy", "SOLUTION", "Energy");
@@ -241,7 +241,7 @@ void CFlowCompOutput::SetVolumeOutputFields(CConfig *config){
241241
AddVolumeOutput("PRESSURE_COEFF", "Pressure_Coefficient", "PRIMITIVE", "Pressure coefficient");
242242
AddVolumeOutput("VELOCITY-X", "Velocity_x", "PRIMITIVE", "x-component of the velocity vector");
243243
AddVolumeOutput("VELOCITY-Y", "Velocity_y", "PRIMITIVE", "y-component of the velocity vector");
244-
244+
245245
if (nDim == 3)
246246
AddVolumeOutput("VELOCITY-Z", "Velocity_z", "PRIMITIVE", "z-component of the velocity vector");
247247

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

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

530530
TurboInOut<<" BLADE ROW INDEX "<<iZone <<"";
531531
TurboInOut.PrintFooter();
@@ -772,7 +772,7 @@ void CFlowCompOutput::WriteTurboSpanwisePerformance(std::shared_ptr<CTurboOutput
772772
file.width(30); file << BladePerf->GetInletState().GetVelocity()[iDim]*config[ZONE_0]->GetVelocity_Ref();
773773
}
774774
file.width(30); file << BladePerf->GetInletState().GetVelocityValue()*config[ZONE_0]->GetVelocity_Ref();
775-
// This captures NaNs
775+
// This captures NaNs
776776
if(isnan(BladePerf->GetInletState().GetAbsFlowAngle())){
777777
file.width(30); file << "0.0000";
778778
}
@@ -792,11 +792,11 @@ void CFlowCompOutput::WriteTurboSpanwisePerformance(std::shared_ptr<CTurboOutput
792792

793793
/*--- Writing Span wise outflow thermodynamic quantities. ---*/
794794
spanwise_performance_filename = "TURBOMACHINERY/outflow_spanwise_kinematic_values";
795-
if (nZone > 1) {
796-
spanwise_performance_filename.append("_" + std::to_string(val_iZone) + ".dat");
797-
} else {
798-
spanwise_performance_filename.append(".dat");
799-
}
795+
if (nZone > 1) {
796+
spanwise_performance_filename.append("_" + std::to_string(val_iZone) + ".dat");
797+
} else {
798+
spanwise_performance_filename.append(".dat");
799+
}
800800
file.open (spanwise_performance_filename.data(), ios::out | ios::trunc);
801801
file.setf(ios::scientific);
802802
file.precision(12);

SU2_CFD/src/output/CFlowIncOutput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ CFlowIncOutput::CFlowIncOutput(CConfig *config, unsigned short nDim) : CFlowOutp
7070
auto notFound = requestedVolumeFields.end();
7171
if (find(requestedVolumeFields.begin(), notFound, string("GRID_VELOCITY")) == notFound) {
7272
requestedVolumeFields.emplace_back("GRID_VELOCITY");
73-
nRequestedVolumeFields ++;
73+
nRequestedVolumeFields++;
7474
}
7575
}
7676

0 commit comments

Comments
 (0)