Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write compact restart files #2372

Open
wants to merge 35 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
838cd96
initial idea
bigfooted Oct 31, 2024
7d30a57
Merge branch 'develop' into feature_small_restart
bigfooted Oct 31, 2024
4fdc8b4
do not write SOLUTION by default
bigfooted Oct 31, 2024
028d148
Merge branch 'feature_small_restart' of https://github.com/su2code/su…
bigfooted Oct 31, 2024
de9ce79
small cleanup
bigfooted Oct 31, 2024
2992d7c
change default to false
bigfooted Nov 1, 2024
79bce1f
Merge branch 'develop' into feature_small_restart
bigfooted Nov 5, 2024
af2fd4f
fixed
bigfooted Nov 6, 2024
1f43902
cleanup
bigfooted Nov 6, 2024
f968780
variable renaming
bigfooted Nov 6, 2024
d2e69ea
Merge branch 'develop' into feature_small_restart
bigfooted Nov 19, 2024
ecfca08
Fix code scanning alert no. 625: Comparison of narrow type with wide …
bigfooted Nov 20, 2024
202cc3c
include surface csv
bigfooted Nov 21, 2024
8fbc825
change to size_t
bigfooted Nov 21, 2024
9307d7d
remove variable
bigfooted Nov 21, 2024
3db0627
change to size_t
bigfooted Nov 21, 2024
4c2ba55
Update SU2_CFD/src/output/COutput.cpp
bigfooted Nov 25, 2024
fb8e895
Update SU2_CFD/src/output/COutput.cpp
bigfooted Nov 25, 2024
6dc6724
Update SU2_CFD/src/output/COutput.cpp
bigfooted Nov 25, 2024
bb0a568
Update Common/src/CConfig.cpp
bigfooted Nov 25, 2024
a5d27b3
Update config_template.cfg
bigfooted Nov 25, 2024
b18b92d
Update SU2_CFD/include/output/filewriter/CParallelDataSorter.hpp
bigfooted Nov 25, 2024
b6f23c3
Update SU2_CFD/include/output/COutput.hpp
bigfooted Nov 25, 2024
c5a6c5e
introduce COMPACT keyword
bigfooted Nov 26, 2024
8cd04b0
update dry-run text
bigfooted Nov 26, 2024
4d6f92e
Update SU2_CFD/include/output/COutput.hpp
bigfooted Nov 27, 2024
1ba790c
Update SU2_CFD/src/output/COutput.cpp
bigfooted Nov 27, 2024
d9ec993
Update SU2_CFD/src/output/COutput.cpp
bigfooted Nov 27, 2024
e48c22a
Update SU2_CFD/src/output/COutput.cpp
bigfooted Nov 27, 2024
6e6c70e
Update SU2_CFD/src/output/COutput.cpp
bigfooted Nov 27, 2024
9134d8b
Update SU2_CFD/src/output/COutput.cpp
bigfooted Nov 27, 2024
1a0aef8
add better config_template description
bigfooted Nov 27, 2024
da4c87e
update variable name
bigfooted Nov 27, 2024
d54eb64
update variable name
bigfooted Nov 27, 2024
915fa30
update variable name
bigfooted Nov 27, 2024
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
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 @@ -5490,6 +5491,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 @@ -1169,6 +1169,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
12 changes: 8 additions & 4 deletions SU2_CFD/include/output/COutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ class COutput {
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> requiredVolumeFieldNames; //!< Vector containing the minimum required volume field names.

string volumeFilename, //!< Volume output filename
surfaceFilename, //!< Surface output filename
Expand Down Expand Up @@ -293,6 +294,9 @@ class COutput {
/*! \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", "GRID_VELOCITY"};

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

su2double cauchyValue, /*!< \brief Summed value of the convergence indicator. */
Expand Down Expand Up @@ -959,14 +963,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 +986,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
87 changes: 64 additions & 23 deletions SU2_CFD/src/output/COutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,13 @@ void COutput::WriteToFile(CConfig *config, CGeometry *geometry, OUTPUT_TYPE form
if (!config->GetWrt_Surface_Overwrite())
filename_iter = config->GetFilename_Iter(fileName, curInnerIter, curOuterIter);

/*--- If we have compact restarts, we use only the required fields. ---*/
if (config->GetWrt_Restart_Compact())
surfaceDataSorter->SetRequiredFieldNames(surfaceDataSorter->GetFieldNames());
else
surfaceDataSorter->SetRequiredFieldNames(requiredVolumeFieldNames);


surfaceDataSorter->SortConnectivity(config, geometry);
surfaceDataSorter->SortOutputData();

Expand All @@ -430,6 +437,13 @@ void COutput::WriteToFile(CConfig *config, CGeometry *geometry, OUTPUT_TYPE form
if (!config->GetWrt_Restart_Overwrite())
filename_iter = config->GetFilename_Iter(fileName, curInnerIter, curOuterIter);


/*--- If we have compact restarts, we use only the required fields. ---*/
if (config->GetWrt_Restart_Compact())
volumeDataSorter->SetRequiredFieldNames(requiredVolumeFieldNames);
else
volumeDataSorter->SetRequiredFieldNames(volumeDataSorter->GetFieldNames());

LogOutputFiles("SU2 ASCII restart");
fileWriter = new CSU2FileWriter(volumeDataSorter);

Expand All @@ -445,6 +459,12 @@ void COutput::WriteToFile(CConfig *config, CGeometry *geometry, OUTPUT_TYPE form
if (!config->GetWrt_Restart_Overwrite())
filename_iter = config->GetFilename_Iter(fileName, curInnerIter, curOuterIter);

/*--- If we have compact restarts, we use only the required fields. ---*/
if (config->GetWrt_Restart_Compact())
volumeDataSorter->SetRequiredFieldNames(requiredVolumeFieldNames);
else
volumeDataSorter->SetRequiredFieldNames(volumeDataSorter->GetFieldNames());

LogOutputFiles("SU2 binary restart");
fileWriter = new CSU2BinaryFileWriter(volumeDataSorter);

Expand Down Expand Up @@ -1504,66 +1524,88 @@ void COutput::PreprocessVolumeOutput(CConfig *config){

SetVolumeOutputFields(config);

/*---Coordinates and solution groups must be always in the output.
/*--- Coordinates must be always in the output.
* If they are not requested, add them here. ---*/

auto itCoord = std::find(requestedVolumeFields.begin(),
requestedVolumeFields.end(), "COORDINATES");
if (itCoord == requestedVolumeFields.end()){
if (itCoord == requestedVolumeFields.end()) {
requestedVolumeFields.emplace_back("COORDINATES");
nRequestedVolumeFields++;
}

/*--- Add the solution if it was not requested for backwards compatibility, unless the COMPACT keyword was used to request exclusively the specified fields. ---*/
auto itSol = std::find(requestedVolumeFields.begin(),
requestedVolumeFields.end(), "SOLUTION");
if (itSol == requestedVolumeFields.end()){
requestedVolumeFields.emplace_back("SOLUTION");
nRequestedVolumeFields++;
requestedVolumeFields.end(), "SOLUTION");
if (itSol == requestedVolumeFields.end()) {
auto itCompact = std::find(requestedVolumeFields.begin(),
requestedVolumeFields.end(), "COMPACT");
if (itCompact == requestedVolumeFields.end()) {
requestedVolumeFields.emplace_back("SOLUTION");
nRequestedVolumeFields++;
}
}

nVolumeFields = 0;

string RequestedField;
string RequiredField;
std::vector<bool> FoundField(nRequestedVolumeFields, false);
vector<string> FieldsToRemove;


/*--- Loop through all fields defined in the corresponding SetVolumeOutputFields().
* If it is also defined in the config (either as part of a group or a single field), the field
* object gets an offset so that we know where to find the data in the Local_Data() array.
* Note that the default offset is -1. An index !=-1 defines this field as part of the output. ---*/
* If it is also defined in the config (either as part of a group or a single field), the field
* object gets an offset so that we know where to find the data in the Local_Data() array.
* Note that the default offset is -1. An index !=-1 defines this field as part of the output. ---*/

for (size_t iField_Output = 0; iField_Output < volumeOutput_List.size(); iField_Output++) {

const string &fieldReference = volumeOutput_List[iField_Output];

for (unsigned short iField_Output = 0; iField_Output < volumeOutput_List.size(); iField_Output++){
if (volumeOutput_Map.count(fieldReference) > 0) {

VolumeOutputField &Field = volumeOutput_Map.at(fieldReference);
/*--- Loop through all fields specified in the config ---*/
for (size_t iReqField = 0; iReqField < restartVolumeFields.size(); iReqField++) {

RequiredField = restartVolumeFields[iReqField];
if (((RequiredField == Field.outputGroup) || (RequiredField == fieldReference)) && (Field.offset == -1)) {
requiredVolumeFieldNames.push_back(Field.fieldName);
}
}
}
}

unsigned short nVolumeFields = 0;

for (size_t iField_Output = 0; iField_Output < volumeOutput_List.size(); iField_Output++) {

const string &fieldReference = volumeOutput_List[iField_Output];
if (volumeOutput_Map.count(fieldReference) > 0){
VolumeOutputField &Field = volumeOutput_Map.at(fieldReference);

/*--- Loop through all fields specified in the config ---*/

for (unsigned short iReqField = 0; iReqField < nRequestedVolumeFields; iReqField++){
for (size_t iReqField = 0; iReqField < nRequestedVolumeFields; iReqField++) {

RequestedField = requestedVolumeFields[iReqField];
const string &RequestedField = requestedVolumeFields[iReqField];

if (((RequestedField == Field.outputGroup) || (RequestedField == fieldReference)) && (Field.offset == -1)) {

if (((RequestedField == Field.outputGroup) || (RequestedField == fieldReference)) && (Field.offset == -1)){
Field.offset = nVolumeFields;
volumeFieldNames.push_back(Field.fieldName);
nVolumeFields++;

FoundField[iReqField] = true;
}
}
}
}

for (unsigned short iReqField = 0; iReqField < nRequestedVolumeFields; iReqField++){
for (size_t iReqField = 0; iReqField < nRequestedVolumeFields; iReqField++){
if (!FoundField[iReqField]){
FieldsToRemove.push_back(requestedVolumeFields[iReqField]);
}
}

/*--- Remove fields which are not defined --- */

for (unsigned short iReqField = 0; iReqField < FieldsToRemove.size(); iReqField++){
for (size_t iReqField = 0; iReqField < FieldsToRemove.size(); iReqField++){
if (rank == MASTER_NODE) {
if (iReqField == 0){
cout << " Info: Ignoring the following volume output fields/groups:" << endl;
Expand All @@ -1585,7 +1627,6 @@ void COutput::PreprocessVolumeOutput(CConfig *config){
if (rank == MASTER_NODE){
cout <<"Volume output fields: ";
for (unsigned short iReqField = 0; iReqField < nRequestedVolumeFields; iReqField++){
RequestedField = requestedVolumeFields[iReqField];
cout << requestedVolumeFields[iReqField];
if (iReqField != nRequestedVolumeFields - 1) cout << ", ";
}
Expand Down Expand Up @@ -2414,7 +2455,7 @@ void COutput::PrintVolumeFields(){
}

cout << "Available volume output fields for the current configuration in " << multiZoneHeaderString << ":" << endl;
cout << "Note: COORDINATES and SOLUTION groups are always in the volume output." << endl;
cout << "Note: COORDINATES and SOLUTION groups are always in the volume output unless you add the keyword COMPACT." << endl;
VolumeFieldTable.AddColumn("Name", NameSize);
VolumeFieldTable.AddColumn("Group Name", GroupSize);
VolumeFieldTable.AddColumn("Description", DescrSize);
Expand Down
2 changes: 1 addition & 1 deletion SU2_CFD/src/output/filewriter/CSU2BinaryFileWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void CSU2BinaryFileWriter::WriteData(string val_filename){

unsigned short iVar;

const vector<string>& fieldNames = dataSorter->GetFieldNames();
const vector<string>& fieldNames = dataSorter->GetRequiredFieldNames();
unsigned short nVar = fieldNames.size();
unsigned long nParallel_Poin = dataSorter->GetnPoints();
unsigned long nPoint_Global = dataSorter->GetnPointsGlobal();
Expand Down
3 changes: 2 additions & 1 deletion SU2_CFD/src/output/filewriter/CSU2FileWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ CSU2FileWriter::CSU2FileWriter(CParallelDataSorter *valDataSorter) :
void CSU2FileWriter::WriteData(string val_filename){

ofstream restart_file;
const vector<string> fieldNames = dataSorter->GetFieldNames();
const vector<string> fieldNames = dataSorter->GetRequiredFieldNames();

/*--- We append the pre-defined suffix (extension) to the filename (prefix) ---*/
val_filename.append(fileExt);

Expand Down
8 changes: 7 additions & 1 deletion config_template.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ KIND_VERIFICATION_SOLUTION= NO_VERIFICATION_SOLUTION
% Defaults to DISCRETE_ADJOINT for the SU2_*_AD codes, and to DIRECT otherwise.
MATH_PROBLEM= DIRECT
%
% Axisymmetric simulation, only compressible flows (NO, YES)
% Axisymmetric simulation for 2D problems. (NO, YES)
AXISYMMETRIC= NO
%
% Gravity force
Expand All @@ -60,6 +60,12 @@ GRAVITY_FORCE= NO
% Restart solution (NO, YES)
RESTART_SOL= NO
%
% Only save minimum required variables to restart files (NO, YES).
% If this option is set to NO, then the SOLUTION fields will be written to all output
% files by default. If you would also like to have minimum output files
% (e.g. paraview, tecplot), then add the keyword COMPACT to VOLUME_OUTPUT.
WRT_RESTART_COMPACT= YES
%
% Discard the data storaged in the solution and geometry files
% e.g. AOA, dCL/dAoA, dCD/dCL, iter, etc.
% Note that AoA in the solution and geometry files is critical
Expand Down