Skip to content

Commit

Permalink
Allow different OUTPUT_WRT_FREQ for each output file (#1552)
Browse files Browse the repository at this point in the history
* added file dependent writing frequency
* use OUTPUT_WRT_FREQ instead of new config option
* removed *volumeoutputfrequencies
* save freeformdefbox for another PR. print list of writing frequencies
* only print file frequency when there are output files
* Apply suggestions from code review
Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com>
  • Loading branch information
bigfooted authored Mar 29, 2022
1 parent 3f3cb55 commit c100612
Show file tree
Hide file tree
Showing 22 changed files with 171 additions and 123 deletions.
18 changes: 11 additions & 7 deletions Common/include/CConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,9 +1119,10 @@ class CConfig {

unsigned long HistoryWrtFreq[3], /*!< \brief Array containing history writing frequencies for timer iter, outer iter, inner iter */
ScreenWrtFreq[3]; /*!< \brief Array containing screen writing frequencies for timer iter, outer iter, inner iter */
unsigned long VolumeWrtFreq; /*!< \brief Writing frequency for solution files. */
OUTPUT_TYPE* VolumeOutputFiles; /*!< \brief File formats to output */
unsigned short nVolumeOutputFiles; /*!< \brief Number of File formats to output */
unsigned short nVolumeOutputFiles=0;/*!< \brief Number of File formats to output */
unsigned short nVolumeOutputFrequencies; /*!< \brief Number of frequencies for the volume outputs */
unsigned long *VolumeOutputFrequencies; /*!< \brief list containing the writing frequencies */

bool Multizone_Mesh; /*!< \brief Determines if the mesh contains multiple zones. */
bool SinglezoneDriver; /*!< \brief Determines if the single-zone driver is used. (TEMPORARY) */
Expand Down Expand Up @@ -1256,6 +1257,8 @@ class CConfig {

void addUShortListOption(const string name, unsigned short & size, unsigned short * & option_field);

void addULongListOption(const string name, unsigned short & size, unsigned long * & option_field);

void addStringListOption(const string name, unsigned short & num_marker, string* & option_field);

void addConvectOption(const string name, unsigned short & space_field, unsigned short & centered_field, unsigned short & upwind_field);
Expand Down Expand Up @@ -9438,11 +9441,6 @@ class CConfig {
*/
void SetScreen_Wrt_Freq(unsigned short iter, unsigned long nIter) { ScreenWrtFreq[iter] = nIter; }

/*!
* \brief GetScreen_Wrt_Freq_Inner
*/
unsigned long GetVolume_Wrt_Freq() const { return VolumeWrtFreq; }

/*!
* \brief GetVolumeOutputFiles
*/
Expand All @@ -9453,6 +9451,12 @@ class CConfig {
*/
unsigned short GetnVolumeOutputFiles() const { return nVolumeOutputFiles; }

/*!
* \brief GetVolumeOutputFrequency
* \param[in] iFile: index of file number for which the writing frequency needs to be returned.
*/
unsigned long GetVolumeOutputFrequency(unsigned short iFile) const { return VolumeOutputFrequencies[iFile]; }

/*!
* \brief Get the desired factorization frequency for PaStiX
* \return Number of calls to 'Build' that trigger re-factorization.
Expand Down
2 changes: 1 addition & 1 deletion Common/include/adt/CADTElemClass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CADTElemClass : public CADTBaseClass {
* \param[out] rankID Rank on which element containing the coordinate is stored.
* \param[out] parCoor Parametric coordinates of coor inside the element,
which contains the coordinate.
* \param[out] weightsInterpol Interpolation weigts of of coor inside the element,
* \param[out] weightsInterpol Interpolation weights of coor inside the element,
which contains the coordinate.
* \return True if an element is found, false if not.
*/
Expand Down
5 changes: 3 additions & 2 deletions Common/include/grid_movement/CFreeFormDefBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class CFreeFormDefBox : public CGridMovement {
unsigned short nCornerPoints, /*!< \brief Number of corner points of the FFDBox. */
nControlPoints, nControlPoints_Copy; /*!< \brief Number of control points of the FFDBox. */
su2double **Coord_Corner_Points, /*!< \brief Coordinates of the corner points. */
****Coord_Control_Points, /*!< \brief Coordinates of the control points. */
****Coord_Control_Points, /*!< \brief Coordinates of the control points. */
****ParCoord_Control_Points, /*!< \brief Coordinates of the control points. */
****Coord_Control_Points_Copy, /*!< \brief Coordinates of the control points (copy). */
****Coord_SupportCP; /*!< \brief Coordinates of the support control points. */
****Coord_SupportCP{nullptr}; /*!< \brief Coordinates of the support control points. */
unsigned short lOrder, lOrder_Copy, /*!< \brief Order of the FFDBox in the i direction. */
mOrder, mOrder_Copy, /*!< \brief Order of the FFDBox in the j direction. */
nOrder, nOrder_Copy; /*!< \brief Order of the FFDBox in the k direction. */
Expand Down Expand Up @@ -625,6 +625,7 @@ class CFreeFormDefBox : public CGridMovement {
* \param[in] config - Definition of the particular problem.
* \param[in] iFFDBox - Index of the FFDBox.
*/
// this routine is not used. We should consider deleting it.
void SetDeformationZone(CGeometry *geometry, CConfig *config, unsigned short iFFDBox) const;

/*!
Expand Down
8 changes: 8 additions & 0 deletions Common/include/option_structure.inl
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ public:
}
};

class COptionULongList final : public COptionScalarList<unsigned long> {
public:
template<class... Ts>
COptionULongList(Ts&&... args) :
COptionScalarList<unsigned long>("unsigned long", args...) {
}
};

class COptionStringList final : public COptionScalarList<string> {
public:
template<class... Ts>
Expand Down
72 changes: 61 additions & 11 deletions Common/src/CConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,13 @@ void CConfig::addUShortListOption(const string name, unsigned short & size, unsi
option_map.insert(pair<string, COptionBase *>(name, val));
}

void CConfig::addULongListOption(const string name, unsigned short & size, unsigned long * & option_field) {
assert(option_map.find(name) == option_map.end());
all_options.insert(pair<string, bool>(name, true));
COptionBase* val = new COptionULongList(name, size, option_field);
option_map.insert(pair<string, COptionBase *>(name, val));
}

void CConfig::addStringListOption(const string name, unsigned short & num_marker, string* & option_field) {
assert(option_map.find(name) == option_map.end());
all_options.insert(pair<string, bool>(name, true));
Expand Down Expand Up @@ -1018,6 +1025,7 @@ void CConfig::SetPointersNull(void) {
HistoryOutput = nullptr;
VolumeOutput = nullptr;
VolumeOutputFiles = nullptr;
VolumeOutputFrequencies = nullptr;
ConvField = nullptr;

/*--- Variable initialization ---*/
Expand Down Expand Up @@ -1173,7 +1181,6 @@ void CConfig::SetConfig_Options() {
addBoolOption("VT_RESIDUAL_LIMITING", vt_transfer_res_limit, false);
/* DESCRIPTION: List of catalytic walls */
addStringListOption("CATALYTIC_WALL", nWall_Catalytic, Wall_Catalytic);
/*!\brief MARKER_MONITORING\n DESCRIPTION: Marker(s) of the surface where evaluate the non-dimensional coefficients \ingroup Config*/


/*--- Options related to VAN der WAALS MODEL and PENG ROBINSON ---*/
Expand Down Expand Up @@ -1405,6 +1412,7 @@ void CConfig::SetConfig_Options() {
addStringListOption("MARKER_PLOTTING", nMarker_Plotting, Marker_Plotting);
/*!\brief MARKER_MONITORING\n DESCRIPTION: Marker(s) of the surface where evaluate the non-dimensional coefficients \ingroup Config*/
addStringListOption("MARKER_MONITORING", nMarker_Monitoring, Marker_Monitoring);

/*!\brief MARKER_CONTROL_VOLUME\n DESCRIPTION: Marker(s) of the surface in the surface flow solution file \ingroup Config*/
addStringListOption("MARKER_ANALYZE", nMarker_Analyze, Marker_Analyze);
/*!\brief MARKER_DESIGNING\n DESCRIPTION: Marker(s) of the surface where objective function (design problem) will be evaluated \ingroup Config*/
Expand Down Expand Up @@ -2444,7 +2452,8 @@ void CConfig::SetConfig_Options() {
/*!\par CONFIG_CATEGORY: Multizone definition \ingroup Config*/
/*--- Options related to multizone problems ---*/

/*!\brief MARKER_PLOTTING\n DESCRIPTION: Marker(s) of the surface in the surface flow solution file \ingroup Config*/
/* DESCRIPTION List of config files for each zone in a multizone setup with SOLVER=MULTIPHYSICS
* Order here has to match the order in the meshfile if just one is used. */
addStringListOption("CONFIG_LIST", nConfig_Files, Config_Filenames);

/* DESCRIPTION: Determines if the multizone problem is solved for time-domain. */
Expand Down Expand Up @@ -2814,8 +2823,9 @@ void CConfig::SetConfig_Options() {
addUnsignedLongOption("SCREEN_WRT_FREQ_OUTER", ScreenWrtFreq[1], 1);
/* DESCRIPTION: Screen writing frequency (TIME_ITER) */
addUnsignedLongOption("SCREEN_WRT_FREQ_TIME", ScreenWrtFreq[0], 1);
/* DESCRIPTION: Volume solution writing frequency */
addUnsignedLongOption("OUTPUT_WRT_FREQ", VolumeWrtFreq, 250);
/* DESCRIPTION: list of writing frequencies for each file type (length same as nVolumeOutputFiles) */
addULongListOption("OUTPUT_WRT_FREQ", nVolumeOutputFrequencies, VolumeOutputFrequencies);

/* DESCRIPTION: Volume solution files */
addEnumListOption("OUTPUT_FILES", nVolumeOutputFiles, VolumeOutputFiles, Output_Map);

Expand Down Expand Up @@ -3302,6 +3312,30 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
VolumeOutputFiles[2] = OUTPUT_TYPE::SURFACE_PARAVIEW_XML;
}

/*--- Set the default output frequencies ---*/
if (!OptionIsSet("OUTPUT_WRT_FREQ")){
nVolumeOutputFrequencies = nVolumeOutputFiles;
VolumeOutputFrequencies = new unsigned long [nVolumeOutputFrequencies];

/*--- Using default frequency of 250 for all files when steady, and 1 for unsteady. ---*/
for (auto iVolumeFreq = 0; iVolumeFreq < nVolumeOutputFrequencies; iVolumeFreq++){
VolumeOutputFrequencies[iVolumeFreq] = Time_Domain ? 1 : 250;
}
} else if (nVolumeOutputFrequencies < nVolumeOutputFiles) {
/*--- If there are fewer frequencies than files, repeat the last frequency.
* This is useful to define 1 frequency for the restart file and 1 frequency for all the visualization files. ---*/
auto* newFrequencies = new unsigned long[nVolumeOutputFiles];
for (unsigned short i = 0; i < nVolumeOutputFrequencies; ++i) {
newFrequencies[i] = VolumeOutputFrequencies[i];
}
for (auto i = nVolumeOutputFrequencies; i < nVolumeOutputFiles; ++i) {
newFrequencies[i] = newFrequencies[i-1];
}
delete [] VolumeOutputFrequencies;
VolumeOutputFrequencies = newFrequencies;
nVolumeOutputFrequencies = nVolumeOutputFiles;
}

/*--- Check if SU2 was build with TecIO support, as that is required for Tecplot Binary output. ---*/
#ifndef HAVE_TECIO
for (unsigned short iVolumeFile = 0; iVolumeFile < nVolumeOutputFiles; iVolumeFile++){
Expand Down Expand Up @@ -3577,9 +3611,6 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i

if (TimeMarching == TIME_MARCHING::TIME_STEPPING){ InnerIter = 1; }

/*--- Set the default write frequency to 1 if unsteady instead of 250 ---*/
if (!OptionIsSet("OUTPUT_WRT_FREQ")) { VolumeWrtFreq = 1; }

/*--- Set History write freq for inner and outer iteration to zero by default, so only time iterations write. ---*/
if (!OptionIsSet("HISTORY_WRT_FREQ_INNER")) { HistoryWrtFreq[2] = 0; }
if (!OptionIsSet("HISTORY_WRT_FREQ_OUTER")) { HistoryWrtFreq[1] = 0; }
Expand Down Expand Up @@ -6824,7 +6855,27 @@ void CConfig::SetOutput(SU2_COMPONENT val_software, unsigned short val_izone) {

if (val_software == SU2_COMPONENT::SU2_CFD) {

cout << "Writing solution files every " << VolumeWrtFreq <<" iterations."<< endl;
if (nVolumeOutputFiles != 0) {
cout << "File writing frequency: " << endl;
PrintingToolbox::CTablePrinter FileFreqTable(&std::cout);
FileFreqTable.AddColumn("File", 25);
FileFreqTable.AddColumn("Frequency", 10);
FileFreqTable.SetAlign(PrintingToolbox::CTablePrinter::RIGHT);
FileFreqTable.PrintHeader();

for (auto iFreq = 0; iFreq < nVolumeOutputFiles; iFreq++){
/*--- find the key belonging to the value in the map---*/
for (auto& it : Output_Map) {
if (it.second == VolumeOutputFiles[iFreq]) {
FileFreqTable << it.first << VolumeOutputFrequencies[iFreq];
break;
}
}
}

FileFreqTable.PrintFooter();
}

cout << "Writing the convergence history file every " << HistoryWrtFreq[2] <<" inner iterations."<< endl;
if (Multizone_Problem){
cout << "Writing the convergence history file every " << HistoryWrtFreq[1] <<" outer iterations."<< endl;
Expand Down Expand Up @@ -7419,10 +7470,10 @@ unsigned short CConfig::GetMarker_CfgFile_TagBound(string val_marker) const {

unsigned short iMarker_CfgFile;

for (iMarker_CfgFile = 0; iMarker_CfgFile < nMarker_CfgFile; iMarker_CfgFile++)
for (iMarker_CfgFile = 0; iMarker_CfgFile < nMarker_CfgFile; iMarker_CfgFile++) {
if (Marker_CfgFile_TagBound[iMarker_CfgFile] == val_marker)
return iMarker_CfgFile;

}
SU2_MPI::Error(string("The configuration file doesn't have any definition for marker ") + val_marker, CURRENT_FUNCTION);
return 0;
}
Expand Down Expand Up @@ -7821,7 +7872,6 @@ CConfig::~CConfig() {

delete [] nBlades;
delete [] FreeStreamTurboNormal;

}

string CConfig::GetFilename(string filename, string ext, int timeIter) const {
Expand Down
2 changes: 0 additions & 2 deletions Common/src/grid_movement/CSurfaceMovement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,9 +784,7 @@ void CSurfaceMovement::SetParametricCoord(CGeometry *geometry, CConfig *config,
TotalVertex++;

for (iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++) {

if (config->GetMarker_All_DV(iMarker) == YES) {

for (iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++) {

/*--- Get the cartesian coordinates ---*/
Expand Down
2 changes: 1 addition & 1 deletion QuickStart/inv_NACA0012.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ SOLUTION_FILENAME= solution_flow.dat
% Restart adjoint input file
SOLUTION_ADJ_FILENAME= solution_adj.dat
%
% Output file format (TECPLOT, PARAVIEW, TECPLOT_BINARY)
% Output file format (TECPLOT, CSV)
TABULAR_FORMAT= CSV
%
% Output file convergence history (w/o extension)
Expand Down
4 changes: 2 additions & 2 deletions SU2_CFD/include/numerics/CNumerics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1187,11 +1187,11 @@ class CNumerics {
void GetLMatrix(su2double val_soundspeed, su2double val_density, su2double **L_Matrix) const;

/*!
* \brief Computation of the flow Residual Jacoboan Matrix for Non Reflecting BC.
* \brief Computation of the flow Residual Jacobian Matrix for Non Reflecting BC.
* \param[in] val_soundspeed - value of the sound speed.
* \param[in] val_density - value of the density.
* \param[out] R_c - Residual Jacoboan Matrix
* \param[out] R_c_inv- inverse of the Residual Jacoboan Matrix .
* \param[out] R_c_inv- inverse of the Residual Jacobian Matrix .
*/
void ComputeResJacobianGiles(CFluidModel *FluidModel, su2double pressure, su2double density, const su2double *turboVel,
su2double alphaInBC, su2double gammaInBC, su2double **R_c, su2double **R_c_inv);
Expand Down
3 changes: 2 additions & 1 deletion SU2_CFD/include/output/CFlowOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ class CFlowOutput : public CFVMOutput{
* \param[in] config - Definition of the particular problem.
* \param[in] Iter - Current iteration index.
* \param[in] force_writing - boolean that forces writing of volume output
* \param[in] iFile - index to the file that we need to consider for volume output
*/
bool WriteVolume_Output(CConfig *config, unsigned long Iter, bool force_writing) override;
bool WriteVolume_Output(CConfig *config, unsigned long Iter, bool force_writing, unsigned short iFile) override;

/*!
* \brief Write the forces breakdown file
Expand Down
8 changes: 4 additions & 4 deletions SU2_CFD/include/output/COutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ class COutput {
curInnerIter; /*!< \brief Current value of the inner iteration index */

string historyFilename; /*!< \brief The history filename*/
char char_histfile[200]; /*! \brief Temporary variable to store the history filename */
ofstream histFile; /*! \brief Output file stream for the history */

ofstream histFile; /*!< \brief Output file stream for the history */

bool cauchyTimeConverged; /*! \brief: Flag indicating that solver is already converged. Needed for writing restart files. */

/** \brief Enum to identify the screen output format. */
Expand Down Expand Up @@ -778,8 +777,9 @@ class COutput {
* \param[in] config - Definition of the particular problem.
* \param[in] Iter - Current iteration index.
* \param[in] force_writing - boolean that forces writing of volume output
* \param[in] iFile - index to the file that we need to consider for volume output
*/
virtual bool WriteVolume_Output(CConfig *config, unsigned long Iter, bool force_writing);
virtual bool WriteVolume_Output(CConfig *config, unsigned long Iter, bool force_writing, unsigned short iFile);

/*!
* \brief Set the values of the volume output fields for a point.
Expand Down
26 changes: 1 addition & 25 deletions SU2_CFD/include/solvers/CFVMFlowSolverBase.inl
Original file line number Diff line number Diff line change
Expand Up @@ -689,32 +689,8 @@ void CFVMFlowSolverBase<V, R>::SetInletAtVertex(const su2double* val_inlet, unsi
unsigned short P_position = nDim + 1;
unsigned short FlowDir_position = nDim + 2;

/*--- Check that the norm of the flow unit vector is actually 1 ---*/
/*--- Note that it is not necessary anymore to use normalized normals for the inlet velocity ---*/

su2double norm = 0.0;
for (unsigned short iDim = 0; iDim < nDim; iDim++) {
norm += pow(val_inlet[FlowDir_position + iDim], 2);
}
norm = sqrt(norm);

/*--- The tolerance here needs to be loose. When adding a very
* small number (1e-10 or smaller) to a number close to 1.0, floating
* point roundoff errors can occur. ---*/

if (abs(norm - 1.0) > 1e-6) {
ostringstream error_msg;
error_msg << "ERROR: Found these values in columns ";
error_msg << FlowDir_position << " - ";
error_msg << FlowDir_position + nDim - 1 << endl;
error_msg << std::scientific;
error_msg << " [" << val_inlet[FlowDir_position];
error_msg << ", " << val_inlet[FlowDir_position + 1];
if (nDim == 3) error_msg << ", " << val_inlet[FlowDir_position + 2];
error_msg << "]" << endl;
error_msg << " These values should be components of a unit vector for direction," << endl;
error_msg << " but their magnitude is: " << norm << endl;
SU2_MPI::Error(error_msg.str(), CURRENT_FUNCTION);
}

/*--- Store the values in our inlet data structures. ---*/

Expand Down
3 changes: 2 additions & 1 deletion SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ void CDiscAdjMultizoneDriver::StartSolver() {
/*--- General setup. ---*/

for (iZone = 0; iZone < nZone; iZone++) {
wrt_sol_freq = min(wrt_sol_freq, config_container[iZone]->GetVolume_Wrt_Freq());

wrt_sol_freq = min(wrt_sol_freq, config_container[iZone]->GetVolumeOutputFrequency(0));

/*--- Set BGS_Solution_k to Solution, this is needed to restart
* correctly as the first OF gradient will overwrite the solution. ---*/
Expand Down
3 changes: 2 additions & 1 deletion SU2_CFD/src/drivers/CDriver.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* \file driver_structure.cpp
* \file CDriver.cpp
* \brief The main subroutines for driving single or multi-zone problems.
* \author T. Economon, H. Kline, R. Sanchez, F. Palacios
* \version 7.3.0 "Blackbird"
Expand Down Expand Up @@ -226,6 +226,7 @@ CDriver::CDriver(char* confFile, unsigned short val_nZone, SU2_Comm MPICommunica

DynamicMesh_Preprocessing(config_container[iZone], geometry_container[iZone][iInst], solver_container[iZone][iInst],
iteration_container[iZone][iInst], grid_movement[iZone][iInst], surface_movement[iZone]);

/*--- Static mesh processing. ---*/

StaticMesh_Preprocessing(config_container[iZone], geometry_container[iZone][iInst]);
Expand Down
Loading

0 comments on commit c100612

Please sign in to comment.