Skip to content

Commit 16f3836

Browse files
authored
Merge pull request #1044 from su2code/cleanup_flow_solver_duplication
Intermediate base class for flow solvers to avoid duplication.
2 parents 574c286 + c271293 commit 16f3836

34 files changed

Lines changed: 5259 additions & 10206 deletions

Common/include/CConfig.hpp

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ class CConfig {
396396
unsigned long OuterIter; /*!< \brief Current Outer iterations for multizone problems. */
397397
unsigned long InnerIter; /*!< \brief Current inner iterations for multizone problems. */
398398
unsigned long TimeIter; /*!< \brief Current time iterations for multizone problems. */
399-
unsigned long Unst_nIntIter; /*!< \brief Number of internal iterations (Dual time Method). */
400399
long Unst_RestartIter; /*!< \brief Iteration number to restart an unsteady simulation (Dual time Method). */
401400
long Unst_AdjointIter; /*!< \brief Iteration number to begin the reverse time integration in the direct solver for the unsteady adjoint. */
402401
long Iter_Avg_Objective; /*!< \brief Iteration the number of time steps to be averaged, counting from the back */
@@ -729,7 +728,6 @@ class CConfig {
729728
RefElemLength, /*!< \brief Reference element length for computing the slope limiting epsilon. */
730729
RefSharpEdges, /*!< \brief Reference coefficient for detecting sharp edges. */
731730
RefLength, /*!< \brief Reference length for moment computation. */
732-
*RefOriginMoment, /*!< \brief Origin for moment computation. */
733731
*RefOriginMoment_X, /*!< \brief X Origin for moment computation. */
734732
*RefOriginMoment_Y, /*!< \brief Y Origin for moment computation. */
735733
*RefOriginMoment_Z, /*!< \brief Z Origin for moment computation. */
@@ -1370,7 +1368,8 @@ class CConfig {
13701368
* \param[in] val_marker - the marker we are monitoring.
13711369
* \return Reference origin (in cartesians coordinates) for moment computation.
13721370
*/
1373-
su2double *GetRefOriginMoment(unsigned short val_marker) {
1371+
std::array<su2double,3> GetRefOriginMoment(unsigned short val_marker) const {
1372+
std::array<su2double,3> RefOriginMoment{{0.0}};
13741373
if(val_marker < nMarker_Monitoring) {
13751374
RefOriginMoment[0] = RefOriginMoment_X[val_marker];
13761375
RefOriginMoment[1] = RefOriginMoment_Y[val_marker];
@@ -2937,12 +2936,6 @@ class CConfig {
29372936
*/
29382937
void SetnMarker_All(unsigned short val_nmarker) { nMarker_All = val_nmarker; }
29392938

2940-
/*!
2941-
* \brief Get the number of internal iterations.
2942-
* \return Number of internal iterations.
2943-
*/
2944-
unsigned long GetUnst_nIntIter(void) const { return Unst_nIntIter; }
2945-
29462939
/*!
29472940
* \brief Get the starting direct iteration number for the unsteady adjoint (reverse time integration).
29482941
* \return Starting direct iteration number for the unsteady adjoint.
@@ -5388,20 +5381,14 @@ class CConfig {
53885381
*/
53895382
string GetVolume_FileName(void) const { return Volume_FileName; }
53905383

5391-
/*!
5392-
* \brief Get the name of the restart file for the heat variables.
5393-
* \return Name of the restart file for the flow variables.
5394-
*/
5395-
string GetRestart_HeatFileName(void);
5396-
53975384
/*!
53985385
* \brief Add any numbers necessary to the filename (iteration number, zone ID ...)
53995386
* \param[in] config - Definition of the particular problem.
54005387
* \param[in] filename - the base filename.
54015388
* \param[in] ext - the extension to be added.
54025389
* \return The new filename
54035390
*/
5404-
string GetFilename(string filename, string ext, unsigned long Iter);
5391+
string GetFilename(string filename, string ext, unsigned long Iter) const;
54055392

54065393
/*!
54075394
* \brief Append the zone index to the restart or the solution files.
@@ -5419,13 +5406,13 @@ class CConfig {
54195406
* \brief Append the instance index to the restart or the solution files.
54205407
* \return Name of the restart file for the flow variables.
54215408
*/
5422-
string GetMultiInstance_FileName(string val_filename, int val_iInst, string ext);
5409+
string GetMultiInstance_FileName(string val_filename, int val_iInst, string ext) const;
54235410

54245411
/*!
54255412
* \brief Append the instance index to the restart or the solution files.
54265413
* \return Name of the restart file for the flow variables.
54275414
*/
5428-
string GetMultiInstance_HistoryFileName(string val_filename, int val_iInst);
5415+
string GetMultiInstance_HistoryFileName(string val_filename, int val_iInst) const;
54295416

54305417
/*!
54315418
* \brief Get the name of the restart file for the flow variables.
@@ -5494,7 +5481,7 @@ class CConfig {
54945481
* \param[in] val_filename - String value of the base filename.
54955482
* \return Name of the file with the appropriate objective function extension.
54965483
*/
5497-
string GetObjFunc_Extension(string val_filename);
5484+
string GetObjFunc_Extension(string val_filename) const;
54985485

54995486
/*!
55005487
* \brief Get the criteria for structural residual (relative/absolute).
@@ -6566,7 +6553,7 @@ class CConfig {
65666553
* \param[in] val_index - Index corresponding to the inlet boundary.
65676554
* \return The flow direction vector.
65686555
*/
6569-
su2double* GetInlet_FlowDir(string val_index);
6556+
const su2double* GetInlet_FlowDir(string val_index) const;
65706557

65716558
/*!
65726559
* \brief Get the back pressure (static) at an outlet boundary.
@@ -8367,14 +8354,14 @@ class CConfig {
83678354
* \brief Start the timer for profiling subroutines.
83688355
* \param[in] val_start_time - the value of the start time.
83698356
*/
8370-
void GEMM_Tick(double *val_start_time);
8357+
void GEMM_Tick(double *val_start_time) const;
83718358

83728359
/*!
83738360
* \brief Stop the timer for the GEMM profiling and store results.
83748361
* \param[in] val_start_time - The value of the start time.
83758362
* \param[in] M, N, K - Matrix size of the GEMM call.
83768363
*/
8377-
void GEMM_Tock(double val_start_time, int M, int N, int K);
8364+
void GEMM_Tock(double val_start_time, int M, int N, int K) const;
83788365

83798366
/*!
83808367
* \brief Write a CSV file containing the results of the profiling.

Common/include/blas_structure.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929

3030
#pragma once
3131

32-
#include "CConfig.hpp"
33-
3432
/* LIBXSMM include files, if supported. */
3533
#ifdef HAVE_LIBXSMM
3634
#include "libxsmm.h"
3735
#endif
3836

37+
class CConfig;
38+
3939
/*!
4040
* \class CBlasStructure
4141
* \brief Class, which serves as an interface to the BLAS functionalities needed.
@@ -66,7 +66,7 @@ class CBlasStructure {
6666
*/
6767
void gemm(const int M, const int N, const int K,
6868
const su2double *A, const su2double *B, su2double *C,
69-
CConfig *config);
69+
const CConfig *config);
7070

7171
/*!
7272
* \brief Function, which carries out a dense matrix vector product

Common/include/omp_structure.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#pragma once
4040

4141
#include <type_traits>
42+
#include <cstdlib>
4243

4344
#if defined(_MSC_VER)
4445
#define PRAGMIZE(X) __pragma(X)

Common/include/toolboxes/geometry_toolbox.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#pragma once
2828

29+
#include <cmath>
30+
2931
namespace GeometryToolbox {
3032

3133
/*! \return ||a-b||^2 */

Common/src/CConfig.cpp

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,6 @@ void CConfig::SetPointersNull(void) {
911911
Velocity_FreeStream = nullptr;
912912
Inc_Velocity_Init = nullptr;
913913

914-
RefOriginMoment = nullptr;
915914
CFL_AdaptParam = nullptr;
916915
CFL = nullptr;
917916
HTP_Axis = nullptr;
@@ -3856,10 +3855,6 @@ void CConfig::SetPostprocessing(unsigned short val_software, unsigned short val_
38563855
}*/
38573856

38583857

3859-
/*--- Initialize the RefOriginMoment Pointer ---*/
3860-
3861-
RefOriginMoment = new su2double[3]();
3862-
38633858
/*--- In case the moment origin coordinates have not been declared in the
38643859
config file, set them equal to zero for safety. Also check to make sure
38653860
that for each marker, a value has been declared for the moment origin.
@@ -6216,28 +6211,28 @@ void CConfig::SetOutput(unsigned short val_software, unsigned short val_izone) {
62166211
case TIME_STEPPING:
62176212
cout << "Unsteady simulation using a time stepping strategy."<< endl;
62186213
if (Unst_CFL != 0.0) {
6219-
cout << "Time step computed by the code. Unsteady CFL number: " << Unst_CFL <<"."<< endl;
6220-
if (Delta_UnstTime != 0.0) {
6221-
cout << "Synchronization time provided by the user (s): "<< Delta_UnstTime << "." << endl;
6222-
}
6223-
}
6214+
cout << "Time step computed by the code. Unsteady CFL number: " << Unst_CFL <<"."<< endl;
6215+
if (Delta_UnstTime != 0.0) {
6216+
cout << "Synchronization time provided by the user (s): "<< Delta_UnstTime << "." << endl;
6217+
}
6218+
}
62246219
else cout << "Unsteady time step provided by the user (s): "<< Delta_UnstTime << "." << endl;
62256220
break;
62266221
case DT_STEPPING_1ST: case DT_STEPPING_2ND:
62276222
if (TimeMarching == DT_STEPPING_1ST) cout << "Unsteady simulation, dual time stepping strategy (first order in time)."<< endl;
62286223
if (TimeMarching == DT_STEPPING_2ND) cout << "Unsteady simulation, dual time stepping strategy (second order in time)."<< endl;
62296224
if (Unst_CFL != 0.0) cout << "Time step computed by the code. Unsteady CFL number: " << Unst_CFL <<"."<< endl;
62306225
else cout << "Unsteady time step provided by the user (s): "<< Delta_UnstTime << "." << endl;
6231-
cout << "Total number of internal Dual Time iterations: "<< Unst_nIntIter <<"." << endl;
6226+
cout << "Total number of internal Dual Time iterations: "<< InnerIter <<"." << endl;
62326227
break;
62336228
}
62346229
}
62356230
else {
62366231
if (Time_Domain) {
6237-
cout << "Dynamic structural analysis."<< endl;
6238-
cout << "Time step provided by the user for the dynamic analysis(s): "<< Delta_DynTime << "." << endl;
6239-
} else {
6240-
cout << "Static structural analysis." << endl;
6232+
cout << "Dynamic structural analysis."<< endl;
6233+
cout << "Time step provided by the user for the dynamic analysis(s): "<< Delta_DynTime << "." << endl;
6234+
} else {
6235+
cout << "Static structural analysis." << endl;
62416236
}
62426237
}
62436238

@@ -7296,7 +7291,6 @@ CConfig::~CConfig(void) {
72967291

72977292
/*--- reference origin for moments ---*/
72987293

7299-
delete [] RefOriginMoment;
73007294
delete [] RefOriginMoment_X;
73017295
delete [] RefOriginMoment_Y;
73027296
delete [] RefOriginMoment_Z;
@@ -7667,7 +7661,7 @@ CConfig::~CConfig(void) {
76677661

76687662
}
76697663

7670-
string CConfig::GetFilename(string filename, string ext, unsigned long Iter){
7664+
string CConfig::GetFilename(string filename, string ext, unsigned long Iter) const {
76717665

76727666
/*--- Remove any extension --- */
76737667

@@ -7755,33 +7749,33 @@ string CConfig::GetMultizone_HistoryFileName(string val_filename, int val_iZone,
77557749
return multizone_filename;
77567750
}
77577751

7758-
string CConfig::GetMultiInstance_FileName(string val_filename, int val_iInst, string ext) {
7752+
string CConfig::GetMultiInstance_FileName(string val_filename, int val_iInst, string ext) const {
77597753

7760-
string multizone_filename = val_filename;
7761-
char buffer[50];
7754+
string multizone_filename = val_filename;
7755+
char buffer[50];
77627756

7763-
unsigned short lastindex = multizone_filename.find_last_of(".");
7764-
multizone_filename = multizone_filename.substr(0, lastindex);
7765-
SPRINTF (buffer, "_%d", SU2_TYPE::Int(val_iInst));
7766-
multizone_filename.append(string(buffer));
7767-
multizone_filename += ext;
7768-
return multizone_filename;
7757+
unsigned short lastindex = multizone_filename.find_last_of(".");
7758+
multizone_filename = multizone_filename.substr(0, lastindex);
7759+
SPRINTF (buffer, "_%d", SU2_TYPE::Int(val_iInst));
7760+
multizone_filename.append(string(buffer));
7761+
multizone_filename += ext;
7762+
return multizone_filename;
77697763
}
77707764

7771-
string CConfig::GetMultiInstance_HistoryFileName(string val_filename, int val_iInst) {
7765+
string CConfig::GetMultiInstance_HistoryFileName(string val_filename, int val_iInst) const {
77727766

7773-
string multizone_filename = val_filename;
7774-
char buffer[50];
7767+
string multizone_filename = val_filename;
7768+
char buffer[50];
77757769

7776-
unsigned short lastindex = multizone_filename.find_last_of(".");
7777-
multizone_filename = multizone_filename.substr(0, lastindex);
7778-
SPRINTF (buffer, "_%d", SU2_TYPE::Int(val_iInst));
7779-
multizone_filename.append(string(buffer));
7770+
unsigned short lastindex = multizone_filename.find_last_of(".");
7771+
multizone_filename = multizone_filename.substr(0, lastindex);
7772+
SPRINTF (buffer, "_%d", SU2_TYPE::Int(val_iInst));
7773+
multizone_filename.append(string(buffer));
77807774

7781-
return multizone_filename;
7775+
return multizone_filename;
77827776
}
77837777

7784-
string CConfig::GetObjFunc_Extension(string val_filename) {
7778+
string CConfig::GetObjFunc_Extension(string val_filename) const {
77857779

77867780
string AdjExt, Filename = val_filename;
77877781

@@ -8359,7 +8353,7 @@ void CConfig::SetInlet_Ptotal(su2double val_pressure, string val_marker) {
83598353
Inlet_Ptotal[iMarker_Inlet] = val_pressure;
83608354
}
83618355

8362-
su2double* CConfig::GetInlet_FlowDir(string val_marker) {
8356+
const su2double* CConfig::GetInlet_FlowDir(string val_marker) const {
83638357
unsigned short iMarker_Inlet;
83648358
for (iMarker_Inlet = 0; iMarker_Inlet < nMarker_Inlet; iMarker_Inlet++)
83658359
if (Marker_Inlet[iMarker_Inlet] == val_marker) break;
@@ -9263,7 +9257,7 @@ void CConfig::SetProfilingCSV(void) {
92639257

92649258
}
92659259

9266-
void CConfig::GEMM_Tick(double *val_start_time) {
9260+
void CConfig::GEMM_Tick(double *val_start_time) const {
92679261

92689262
#ifdef PROFILE
92699263

@@ -9277,7 +9271,7 @@ void CConfig::GEMM_Tick(double *val_start_time) {
92779271

92789272
}
92799273

9280-
void CConfig::GEMM_Tock(double val_start_time, int M, int N, int K) {
9274+
void CConfig::GEMM_Tock(double val_start_time, int M, int N, int K) const {
92819275

92829276
#ifdef PROFILE
92839277

Common/src/blas_structure.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* SU2 Project Website: https://su2code.github.io
99
*
10-
* The SU2 Project is maintained by the SU2 Foundation
10+
* The SU2 Project is maintained by the SU2 Foundation
1111
* (http://su2foundation.org)
1212
*
1313
* Copyright 2012-2020, SU2 Contributors (cf. AUTHORS.md)
@@ -26,6 +26,7 @@
2626
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
2727
*/
2828

29+
#include "../include/CConfig.hpp"
2930
#include "../include/blas_structure.hpp"
3031
#include <cstring>
3132

@@ -46,7 +47,7 @@ extern "C" void dgemv_(char*, const int*, const int*, const passivedouble*,
4647
/* Constructor. Initialize the const member variables, if needed. */
4748
CBlasStructure::CBlasStructure(void)
4849
#if !(defined(HAVE_LIBXSMM) || defined(HAVE_BLAS) || defined(HAVE_MKL)) || (defined(CODI_REVERSE_TYPE) || defined(CODI_FORWARD_TYPE))
49-
: mc (256), kc (128), nc (128)
50+
: mc (256), kc (128), nc (128)
5051
#endif
5152
{}
5253

@@ -56,7 +57,7 @@ CBlasStructure::~CBlasStructure(void) {}
5657
/* Dense matrix multiplication, gemm functionality. */
5758
void CBlasStructure::gemm(const int M, const int N, const int K,
5859
const su2double *A, const su2double *B, su2double *C,
59-
CConfig *config) {
60+
const CConfig *config) {
6061

6162
/* Initialize the variable for the timing, if profiling is active. */
6263
#ifdef PROFILE
@@ -124,7 +125,7 @@ void CBlasStructure::gemv(const int M, const int N, const su2double *A,
124125

125126
/* Native implementation of the matix vector product.
126127
Initialize the elements of y to zero. */
127-
memset(y, 0, M*sizeof(su2double));
128+
memset(y, 0, M*sizeof(su2double));
128129

129130
/* Carry out the matrix vector product. */
130131
for(int k=0; k<M; ++k) {

SU2_CFD/include/solvers/CAdjEulerSolver.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class CAdjEulerSolver : public CSolver {
117117
* \param[in] geometry - Geometrical definition of the problem.
118118
* \param[in] config - Definition of the particular problem.
119119
*/
120-
void Set_MPI_Nearfield(CGeometry *geometry, CConfig *config) final;
120+
void Set_MPI_Nearfield(CGeometry *geometry, CConfig *config);
121121

122122
/*!
123123
* \brief Parallelization of Undivided Laplacian.
@@ -236,7 +236,7 @@ class CAdjEulerSolver : public CSolver {
236236
* \param[in] val_vertex - Vertex of the marker <i>val_marker</i> where the coefficient is evaluated.
237237
* \return Value of the pressure coefficient.
238238
*/
239-
inline su2double *GetDonorAdjVar(unsigned short val_marker, unsigned long val_vertex) const final {
239+
inline su2double *GetDonorAdjVar(unsigned short val_marker, unsigned long val_vertex) const {
240240
return DonorAdjVar[val_marker][val_vertex];
241241
}
242242

@@ -249,7 +249,7 @@ class CAdjEulerSolver : public CSolver {
249249
inline void SetDonorAdjVar(unsigned short val_marker,
250250
unsigned long val_vertex,
251251
unsigned short val_var,
252-
su2double val_value) final {
252+
su2double val_value) {
253253
DonorAdjVar[val_marker][val_vertex][val_var] = val_value;
254254
}
255255

@@ -261,7 +261,7 @@ class CAdjEulerSolver : public CSolver {
261261
*/
262262
inline su2double GetDonorAdjVar(unsigned short val_marker,
263263
unsigned long val_vertex,
264-
unsigned short val_var) const final {
264+
unsigned short val_var) const {
265265
return DonorAdjVar[val_marker][val_vertex][val_var];
266266
}
267267

SU2_CFD/include/solvers/CBaselineSolver.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ class CBaselineSolver final : public CSolver {
100100
*/
101101
void SetOutputVariables(CGeometry *geometry, CConfig *config);
102102

103-
};
103+
};

0 commit comments

Comments
 (0)