Skip to content

Commit 9adacff

Browse files
committed
fewer bare pointers in flow solver base
1 parent daae8ff commit 9adacff

3 files changed

Lines changed: 49 additions & 169 deletions

File tree

SU2_CFD/include/solvers/CFVMFlowSolverBase.hpp

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -137,28 +137,28 @@ class CFVMFlowSolverBase : public CSolver {
137137
su2double Total_Heat = 0.0; /*!< \brief Total heat load for all the boundaries. */
138138
su2double Total_MaxHeat = 0.0; /*!< \brief Maximum heat flux on all boundaries. */
139139
su2double AllBound_CNearFieldOF_Inv = 0.0; /*!< \brief Near-Field press coeff (inviscid) for all the boundaries. */
140-
su2double* CNearFieldOF_Inv = nullptr; /*!< \brief Near field pressure (inviscid) for each boundary. */
141-
su2double* Surface_HF_Visc = nullptr; /*!< \brief Total (integrated) heat flux for each monitored surface. */
142-
su2double* Surface_MaxHF_Visc = nullptr; /*!< \brief Maximum heat flux for each monitored surface. */
143-
su2double* HF_Visc = nullptr; /*!< \brief Heat load (viscous contribution) for each boundary. */
144-
su2double* MaxHF_Visc = nullptr; /*!< \brief Maximum heat flux (viscous contribution) for each boundary. */
145-
su2double AllBound_HF_Visc = 0.0; /*!< \brief Heat load (viscous contribution) for all the boundaries. */
146-
su2double AllBound_MaxHF_Visc = 0.0; /*!< \brief Maximum heat flux (viscous contribution) for all boundaries. */
147-
148-
su2double** Inlet_Ptotal = nullptr; /*!< \brief Value of the Total P. */
149-
su2double** Inlet_Ttotal = nullptr; /*!< \brief Value of the Total T. */
150-
su2double*** Inlet_FlowDir = nullptr; /*!< \brief Value of the Flow Direction. */
151-
su2double** HeatFlux = nullptr; /*!< \brief Heat transfer coefficient for each boundary and vertex. */
152-
su2double** HeatFluxTarget = nullptr; /*!< \brief Heat transfer coefficient for each boundary and vertex. */
153-
su2double*** CharacPrimVar = nullptr; /*!< \brief Value of the characteristic variables at each boundary. */
154-
su2double*** CSkinFriction = nullptr; /*!< \brief Skin friction coefficient for each boundary and vertex. */
155-
su2double** WallShearStress = nullptr; /*!< \brief Wall Shear Stress for each boundary and vertex. */
156-
su2double*** HeatConjugateVar = nullptr; /*!< \brief CHT variables for each boundary and vertex. */
157-
su2double** CPressure = nullptr; /*!< \brief Pressure coefficient for each boundary and vertex. */
158-
su2double** CPressureTarget = nullptr; /*!< \brief Target Pressure coefficient for each boundary and vertex. */
159-
su2double** YPlus = nullptr; /*!< \brief Yplus for each boundary and vertex. */
160-
161-
bool space_centered; /*!< \brief True if space centered scheeme used. */
140+
vector<su2double> CNearFieldOF_Inv; /*!< \brief Near field pressure (inviscid) for each boundary. */
141+
vector<su2double> Surface_HF_Visc; /*!< \brief Total (integrated) heat flux for each monitored surface. */
142+
vector<su2double> Surface_MaxHF_Visc; /*!< \brief Maximum heat flux for each monitored surface. */
143+
vector<su2double> HF_Visc; /*!< \brief Heat load (viscous contribution) for each boundary. */
144+
vector<su2double> MaxHF_Visc; /*!< \brief Maximum heat flux (viscous contribution) for each boundary. */
145+
su2double AllBound_HF_Visc = 0.0; /*!< \brief Heat load (viscous contribution) for all the boundaries. */
146+
su2double AllBound_MaxHF_Visc = 0.0; /*!< \brief Maximum heat flux (viscous contribution) for all boundaries. */
147+
148+
vector<vector<su2double> > Inlet_Ptotal; /*!< \brief Value of the Total P. */
149+
vector<vector<su2double> > Inlet_Ttotal; /*!< \brief Value of the Total T. */
150+
vector<su2activematrix> Inlet_FlowDir; /*!< \brief Value of the Flow Direction. */
151+
vector<vector<su2double> > HeatFlux; /*!< \brief Heat transfer coefficient for each boundary and vertex. */
152+
vector<vector<su2double> > HeatFluxTarget; /*!< \brief Heat transfer coefficient for each boundary and vertex. */
153+
vector<su2activematrix> CharacPrimVar; /*!< \brief Value of the characteristic variables at each boundary. */
154+
vector<su2activematrix> CSkinFriction; /*!< \brief Skin friction coefficient for each boundary and vertex. */
155+
vector<vector<su2double> > WallShearStress; /*!< \brief Wall Shear Stress for each boundary and vertex. */
156+
vector<su2activematrix> HeatConjugateVar; /*!< \brief CHT variables for each boundary and vertex. */
157+
vector<vector<su2double> > CPressure; /*!< \brief Pressure coefficient for each boundary and vertex. */
158+
vector<vector<su2double> > CPressureTarget; /*!< \brief Target Pressure coefficient for each boundary and vertex. */
159+
vector<vector<su2double> > YPlus; /*!< \brief Yplus for each boundary and vertex. */
160+
161+
bool space_centered; /*!< \brief True if space centered scheme used. */
162162
bool euler_implicit; /*!< \brief True if euler implicit scheme used. */
163163
bool least_squares; /*!< \brief True if computing gradients by least squares. */
164164
su2double Gamma; /*!< \brief Fluid's Gamma constant (ratio of specific heats). */
@@ -167,7 +167,7 @@ class CFVMFlowSolverBase : public CSolver {
167167
/*--- Sliding meshes variables ---*/
168168

169169
su2double**** SlidingState = nullptr;
170-
int** SlidingStateNodes = nullptr;
170+
vector<vector<int> > SlidingStateNodes;
171171

172172
/*--- Shallow copy of grid coloring for OpenMP parallelization. ---*/
173173

@@ -2193,7 +2193,7 @@ class CFVMFlowSolverBase : public CSolver {
21932193
* \param[in] val_vertex - Vertex of the marker <i>val_marker</i> where the coefficient is evaluated.
21942194
* \return Value of the pressure coefficient.
21952195
*/
2196-
inline su2double* GetCharacPrimVar(unsigned short val_marker, unsigned long val_vertex) const final {
2196+
inline su2double* GetCharacPrimVar(unsigned short val_marker, unsigned long val_vertex) final {
21972197
return CharacPrimVar[val_marker][val_vertex];
21982198
}
21992199

@@ -2251,8 +2251,6 @@ class CFVMFlowSolverBase : public CSolver {
22512251
* checking to prevent segmentation faults ---*/
22522252
if (val_marker >= nMarker)
22532253
SU2_MPI::Error("Out-of-bounds marker index used on inlet.", CURRENT_FUNCTION);
2254-
else if (Inlet_Ttotal == nullptr || Inlet_Ttotal[val_marker] == nullptr)
2255-
SU2_MPI::Error("Tried to set custom inlet BC on an invalid marker.", CURRENT_FUNCTION);
22562254
else if (val_vertex >= nVertex[val_marker])
22572255
SU2_MPI::Error("Out-of-bounds vertex index used on inlet.", CURRENT_FUNCTION);
22582256
else
@@ -2270,8 +2268,6 @@ class CFVMFlowSolverBase : public CSolver {
22702268
* checking to prevent segmentation faults ---*/
22712269
if (val_marker >= nMarker)
22722270
SU2_MPI::Error("Out-of-bounds marker index used on inlet.", CURRENT_FUNCTION);
2273-
else if (Inlet_Ptotal == nullptr || Inlet_Ptotal[val_marker] == nullptr)
2274-
SU2_MPI::Error("Tried to set custom inlet BC on an invalid marker.", CURRENT_FUNCTION);
22752271
else if (val_vertex >= nVertex[val_marker])
22762272
SU2_MPI::Error("Out-of-bounds vertex index used on inlet.", CURRENT_FUNCTION);
22772273
else
@@ -2291,8 +2287,6 @@ class CFVMFlowSolverBase : public CSolver {
22912287
* checking to prevent segmentation faults ---*/
22922288
if (val_marker >= nMarker)
22932289
SU2_MPI::Error("Out-of-bounds marker index used on inlet.", CURRENT_FUNCTION);
2294-
else if (Inlet_FlowDir == nullptr || Inlet_FlowDir[val_marker] == nullptr)
2295-
SU2_MPI::Error("Tried to set custom inlet BC on an invalid marker.", CURRENT_FUNCTION);
22962290
else if (val_vertex >= nVertex[val_marker])
22972291
SU2_MPI::Error("Out-of-bounds vertex index used on inlet.", CURRENT_FUNCTION);
22982292
else

SU2_CFD/include/solvers/CFVMFlowSolverBase.inl

Lines changed: 24 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ void CFVMFlowSolverBase<V, R>::AeroCoeffsArray::setZero(int i) {
8484

8585
template <class V, ENUM_REGIME R>
8686
void CFVMFlowSolverBase<V, R>::Allocate(const CConfig& config) {
87-
unsigned short iDim, iVar, iMarker;
88-
unsigned long iPoint, iVertex;
87+
unsigned short iVar;
88+
unsigned long iPoint, iMarker;
8989

9090
/*--- Define some auxiliar vector related with the residual ---*/
9191

@@ -116,19 +116,16 @@ void CFVMFlowSolverBase<V, R>::Allocate(const CConfig& config) {
116116

117117
/*--- Allocates a 2D array with variable "outer" sizes and init to 0. ---*/
118118

119-
auto Alloc2D = [](unsigned long M, const unsigned long* N, su2double**& X) {
120-
X = new su2double*[M];
121-
for (unsigned long i = 0; i < M; ++i) X[i] = new su2double[N[i]]();
119+
auto Alloc2D = [](unsigned long M, const unsigned long* N, vector<vector<su2double> >& X) {
120+
X.resize(M);
121+
for (unsigned long i = 0; i < M; ++i) X[i].resize(N[i],0.0);
122122
};
123123

124124
/*--- Allocates a 3D array with variable "middle" sizes and init to 0. ---*/
125125

126-
auto Alloc3D = [](unsigned long M, const unsigned long* N, unsigned long P, su2double***& X) {
127-
X = new su2double**[M];
128-
for (unsigned long i = 0; i < M; ++i) {
129-
X[i] = new su2double*[N[i]];
130-
for (unsigned long j = 0; j < N[i]; ++j) X[i][j] = new su2double[P]();
131-
}
126+
auto Alloc3D = [](unsigned long M, const unsigned long* N, unsigned long P, vector<su2activematrix>& X) {
127+
X.resize(M);
128+
for (unsigned long i = 0; i < M; ++i) X[i].resize(N[i],P) = su2double(0.0);
132129
};
133130

134131
/*--- Store the value of the characteristic primitive variables at the boundaries ---*/
@@ -164,25 +161,25 @@ void CFVMFlowSolverBase<V, R>::Allocate(const CConfig& config) {
164161

165162
/*--- Heat flux coefficients. ---*/
166163

167-
HF_Visc = new su2double[nMarker];
168-
MaxHF_Visc = new su2double[nMarker];
164+
HF_Visc.resize(nMarker,0.0);
165+
MaxHF_Visc.resize(nMarker,0.0);
169166

170-
Surface_HF_Visc = new su2double[config.GetnMarker_Monitoring()];
171-
Surface_MaxHF_Visc = new su2double[config.GetnMarker_Monitoring()];
167+
Surface_HF_Visc.resize(config.GetnMarker_Monitoring());
168+
Surface_MaxHF_Visc.resize(config.GetnMarker_Monitoring());
172169

173170
/*--- Supersonic coefficients ---*/
174171

175-
CNearFieldOF_Inv = new su2double[nMarker];
172+
CNearFieldOF_Inv.resize(nMarker,0.0);
176173

177174
/*--- Initializate quantities for SlidingMesh Interface ---*/
178175

179176
SlidingState = new su2double***[nMarker]();
180-
SlidingStateNodes = new int*[nMarker]();
177+
SlidingStateNodes.resize(nMarker);
181178

182179
for (iMarker = 0; iMarker < nMarker; iMarker++) {
183180
if (config.GetMarker_All_KindBC(iMarker) == FLUID_INTERFACE) {
184181
SlidingState[iMarker] = new su2double**[nVertex[iMarker]]();
185-
SlidingStateNodes[iMarker] = new int[nVertex[iMarker]]();
182+
SlidingStateNodes[iMarker].resize(nVertex[iMarker],0);
186183

187184
for (iPoint = 0; iPoint < nVertex[iMarker]; iPoint++)
188185
SlidingState[iMarker][iPoint] = new su2double*[nPrimVar + 1]();
@@ -200,13 +197,9 @@ void CFVMFlowSolverBase<V, R>::Allocate(const CConfig& config) {
200197

201198
/*--- Skin friction in all the markers ---*/
202199

203-
CSkinFriction = new su2double**[nMarker];
204-
for (iMarker = 0; iMarker < nMarker; iMarker++) {
205-
CSkinFriction[iMarker] = new su2double*[nDim];
206-
for (iDim = 0; iDim < nDim; iDim++) {
207-
CSkinFriction[iMarker][iDim] = new su2double[nVertex[iMarker]]();
208-
}
209-
}
200+
CSkinFriction.resize(nMarker);
201+
for (iMarker = 0; iMarker < nMarker; iMarker++)
202+
CSkinFriction[iMarker].resize(nDim, nVertex[iMarker]) = su2double(0.0);
210203

211204
/*--- Wall Shear Stress in all the markers ---*/
212205

@@ -216,14 +209,8 @@ void CFVMFlowSolverBase<V, R>::Allocate(const CConfig& config) {
216209
used for coupling with a solid donor cell ---*/
217210
constexpr auto nHeatConjugateVar = 4u;
218211

219-
HeatConjugateVar = new su2double**[nMarker];
220-
for (iMarker = 0; iMarker < nMarker; iMarker++) {
221-
HeatConjugateVar[iMarker] = new su2double*[nVertex[iMarker]];
222-
for (iVertex = 0; iVertex < nVertex[iMarker]; iVertex++) {
223-
HeatConjugateVar[iMarker][iVertex] = new su2double[nHeatConjugateVar]();
224-
HeatConjugateVar[iMarker][iVertex][0] = config.GetTemperature_FreeStreamND();
225-
}
226-
}
212+
Alloc3D(nMarker, nVertex, nHeatConjugateVar, HeatConjugateVar);
213+
for (auto& x : HeatConjugateVar) x = config.GetTemperature_FreeStreamND();
227214

228215
if (MGLevel == MESH_0) {
229216
VertexTraction.resize(nMarker);
@@ -385,14 +372,8 @@ void CFVMFlowSolverBase<V, R>::HybridParallelInitialization(const CConfig& confi
385372

386373
template <class V, ENUM_REGIME R>
387374
CFVMFlowSolverBase<V, R>::~CFVMFlowSolverBase() {
388-
unsigned short iMarker, iVar, iDim;
389-
unsigned long iVertex;
390-
391-
delete[] CNearFieldOF_Inv;
392-
delete[] HF_Visc;
393-
delete[] MaxHF_Visc;
394-
delete[] Surface_HF_Visc;
395-
delete[] Surface_MaxHF_Visc;
375+
unsigned short iVar;
376+
unsigned long iMarker, iVertex;
396377

397378
if (SlidingState != nullptr) {
398379
for (iMarker = 0; iMarker < nMarker; iMarker++) {
@@ -408,101 +389,6 @@ CFVMFlowSolverBase<V, R>::~CFVMFlowSolverBase() {
408389
delete[] SlidingState;
409390
}
410391

411-
if (SlidingStateNodes != nullptr) {
412-
for (iMarker = 0; iMarker < nMarker; iMarker++) {
413-
if (SlidingStateNodes[iMarker] != nullptr) delete[] SlidingStateNodes[iMarker];
414-
}
415-
delete[] SlidingStateNodes;
416-
}
417-
418-
if (CPressure != nullptr) {
419-
for (iMarker = 0; iMarker < nMarker; iMarker++) delete[] CPressure[iMarker];
420-
delete[] CPressure;
421-
}
422-
423-
if (CPressureTarget != nullptr) {
424-
for (iMarker = 0; iMarker < nMarker; iMarker++) delete[] CPressureTarget[iMarker];
425-
delete[] CPressureTarget;
426-
}
427-
428-
if (CharacPrimVar != nullptr) {
429-
for (iMarker = 0; iMarker < nMarker; iMarker++) {
430-
for (iVertex = 0; iVertex < nVertex[iMarker]; iVertex++) delete[] CharacPrimVar[iMarker][iVertex];
431-
delete[] CharacPrimVar[iMarker];
432-
}
433-
delete[] CharacPrimVar;
434-
}
435-
436-
if (Inlet_Ttotal != nullptr) {
437-
for (iMarker = 0; iMarker < nMarker; iMarker++)
438-
if (Inlet_Ttotal[iMarker] != nullptr) delete[] Inlet_Ttotal[iMarker];
439-
delete[] Inlet_Ttotal;
440-
}
441-
442-
if (Inlet_Ptotal != nullptr) {
443-
for (iMarker = 0; iMarker < nMarker; iMarker++)
444-
if (Inlet_Ptotal[iMarker] != nullptr) delete[] Inlet_Ptotal[iMarker];
445-
delete[] Inlet_Ptotal;
446-
}
447-
448-
if (Inlet_FlowDir != nullptr) {
449-
for (iMarker = 0; iMarker < nMarker; iMarker++) {
450-
if (Inlet_FlowDir[iMarker] != nullptr) {
451-
for (iVertex = 0; iVertex < nVertex[iMarker]; iVertex++) delete[] Inlet_FlowDir[iMarker][iVertex];
452-
delete[] Inlet_FlowDir[iMarker];
453-
}
454-
}
455-
delete[] Inlet_FlowDir;
456-
}
457-
458-
if (HeatFlux != nullptr) {
459-
for (iMarker = 0; iMarker < nMarker; iMarker++) {
460-
delete[] HeatFlux[iMarker];
461-
}
462-
delete[] HeatFlux;
463-
}
464-
465-
if (HeatFluxTarget != nullptr) {
466-
for (iMarker = 0; iMarker < nMarker; iMarker++) {
467-
delete[] HeatFluxTarget[iMarker];
468-
}
469-
delete[] HeatFluxTarget;
470-
}
471-
472-
if (YPlus != nullptr) {
473-
for (iMarker = 0; iMarker < nMarker; iMarker++) {
474-
delete[] YPlus[iMarker];
475-
}
476-
delete[] YPlus;
477-
}
478-
479-
if (CSkinFriction != nullptr) {
480-
for (iMarker = 0; iMarker < nMarker; iMarker++) {
481-
for (iDim = 0; iDim < nDim; iDim++) {
482-
delete[] CSkinFriction[iMarker][iDim];
483-
}
484-
delete[] CSkinFriction[iMarker];
485-
}
486-
delete[] CSkinFriction;
487-
}
488-
489-
if (WallShearStress != nullptr) {
490-
for (iMarker = 0; iMarker < nMarker; iMarker++) {
491-
delete[] WallShearStress[iMarker];
492-
}
493-
delete[] WallShearStress;
494-
}
495-
496-
if (HeatConjugateVar != nullptr) {
497-
for (iMarker = 0; iMarker < nMarker; iMarker++) {
498-
for (iVertex = 0; iVertex < nVertex[iMarker]; iVertex++) {
499-
delete[] HeatConjugateVar[iMarker][iVertex];
500-
}
501-
delete[] HeatConjugateVar[iMarker];
502-
}
503-
delete[] HeatConjugateVar;
504-
}
505-
506392
delete nodes;
507393
delete edgeNumerics;
508394
}
@@ -2890,8 +2776,8 @@ void CFVMFlowSolverBase<V, FlowRegime>::Friction_Forces(const CGeometry* geometr
28902776
Allreduce_inplace(nMarkerMon, SurfaceViscCoeff.CMy);
28912777
Allreduce_inplace(nMarkerMon, SurfaceViscCoeff.CMz);
28922778

2893-
Allreduce_inplace(nMarkerMon, Surface_HF_Visc);
2894-
Allreduce_inplace(nMarkerMon, Surface_MaxHF_Visc);
2779+
Allreduce_inplace(nMarkerMon, Surface_HF_Visc.data());
2780+
Allreduce_inplace(nMarkerMon, Surface_MaxHF_Visc.data());
28952781

28962782
delete[] buffer;
28972783
}

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2976,7 +2976,7 @@ class CSolver {
29762976
* \return Value of the pressure coefficient.
29772977
*/
29782978
inline virtual su2double *GetCharacPrimVar(unsigned short val_marker,
2979-
unsigned long val_vertex) const { return nullptr; }
2979+
unsigned long val_vertex) { return nullptr; }
29802980

29812981
/*!
29822982
* \brief A virtual member

0 commit comments

Comments
 (0)