From 0363953315ab02500dad7875ceb5b6d6e2f28507 Mon Sep 17 00:00:00 2001 From: Kursat Yurt Date: Fri, 31 Mar 2023 17:22:16 +0200 Subject: [PATCH] Add else after return --- .clang-tidy | 2 +- Common/src/CConfig.cpp | 10 ++++------ Common/src/fem/fem_geometry_structure.cpp | 9 ++++----- Common/src/geometry/CGeometry.cpp | 2 +- .../meshreader/CCGNSMeshReaderFVM.cpp | 4 ++-- Common/src/grid_movement/CBezierBlending.cpp | 15 +++++++------- SU2_CFD/src/drivers/CDriver.cpp | 3 +-- SU2_CFD/src/drivers/CMultizoneDriver.cpp | 4 ++-- SU2_CFD/src/fluid/CSU2TCLib.cpp | 19 ++++++++---------- SU2_CFD/src/interfaces/CInterface.cpp | 20 ++++++++----------- SU2_CFD/src/iteration/CFEAIteration.cpp | 5 ++--- SU2_CFD/src/iteration/CFluidIteration.cpp | 5 ++--- SU2_CFD/src/numerics/CNumerics.cpp | 4 ++-- SU2_CFD/src/output/CFlowOutput.cpp | 5 ++--- SU2_CFD/src/output/COutput.cpp | 5 ++--- SU2_CFD/src/variables/CNEMOEulerVariable.cpp | 4 ++-- .../src/drivers/CDiscAdjDeformationDriver.cpp | 19 +++++++++--------- 17 files changed, 59 insertions(+), 76 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 397fec948e8..f752385dc08 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,4 +1,4 @@ -Checks: '-*,modernize-avoid-bind,modernize-deprecated-headers,modernize-deprecated-ios-base-aliases,modernize-macro-to-enum,modernize-pass-by-value,modernize-raw-string-literal,modernize-redundant-void-arg,modernize-replace-auto-ptr,modernize-replace-disallow-copy-and-assign-macro,modernize-replace-random-shuffle,modernize-return-braced-init-list,modernize-shrink-to-fit,modernize-unary-static-assert,modernize-use-auto,modernize-use-bool-literals,modernize-use-default-member-init,modernize-use-emplace,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-noexcept,modernize-use-nullptr,modernize-use-override,modernize-use-transparent-functors,modernize-use-using,readability-const-return-type,readability-avoid-const-params-in-decls,readability-container-data-pointer,readability-container-size-empty,readability-delete-null-pointer,readability-duplicate-include,readability-non-const-parameter,readability-redundant-access-specifiers,readability-redundant-control-flow,readability-redundant-declaration,readability-redundant-function-ptr-dereference,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-redundant-string-init,readability-simplify-boolean-expr,readability-simplify-subscript-expr,performance-*' +Checks: '-*,modernize-avoid-bind,modernize-deprecated-headers,modernize-deprecated-ios-base-aliases,modernize-macro-to-enum,modernize-pass-by-value,modernize-raw-string-literal,modernize-redundant-void-arg,modernize-replace-auto-ptr,modernize-replace-disallow-copy-and-assign-macro,modernize-replace-random-shuffle,modernize-return-braced-init-list,modernize-shrink-to-fit,modernize-unary-static-assert,modernize-use-auto,modernize-use-bool-literals,modernize-use-default-member-init,modernize-use-emplace,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-noexcept,modernize-use-nullptr,modernize-use-override,modernize-use-transparent-functors,modernize-use-using,readability-const-return-type,readability-avoid-const-params-in-decls,readability-container-data-pointer,readability-container-size-empty,readability-delete-null-pointer,readability-duplicate-include,readability-non-const-parameter,readability-redundant-access-specifiers,readability-redundant-control-flow,readability-redundant-declaration,readability-redundant-function-ptr-dereference,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-redundant-string-init,readability-simplify-boolean-expr,readability-simplify-subscript-expr,readability-else-after-return,performance-*' CheckOptions: - {key: modernize-use-override.AllowOverrideAndFinal, value: 'true'} - {key: performance-unnecessary-copy-initialization.AllowedTypes, value: 'su2double'} diff --git a/Common/src/CConfig.cpp b/Common/src/CConfig.cpp index 5fd2e130f81..bf936e6e8fc 100644 --- a/Common/src/CConfig.cpp +++ b/Common/src/CConfig.cpp @@ -7659,9 +7659,8 @@ bool CConfig::TokenizeString(string & str, string & option_name, } it = option_value.begin(); // go back to beginning; not efficient continue; - } else { - it++; - } + } it++; + } #if 0 cout << "option value(s) = "; @@ -8842,9 +8841,8 @@ const su2double* CConfig::GetInlet_TurbVal(const string& val_marker) const { } if (Kind_Turb_Model == TURB_MODEL::SST) { return TurbIntensityAndViscRatioFreeStream; - } else { - return &NuFactor_FreeStream; - } + } return &NuFactor_FreeStream; + } su2double CConfig::GetOutlet_Pressure(const string& val_marker) const { diff --git a/Common/src/fem/fem_geometry_structure.cpp b/Common/src/fem/fem_geometry_structure.cpp index e226fc2ce9b..1cc219596f3 100644 --- a/Common/src/fem/fem_geometry_structure.cpp +++ b/Common/src/fem/fem_geometry_structure.cpp @@ -134,11 +134,10 @@ bool CSortFaces::operator()(const CFaceOfElement& f0, const CFaceOfElement& f1) to their element ID's in order to increase cache performance. */ if (elemIDMin0 != elemIDMin1) return elemIDMin0 < elemIDMin1; return elemIDMax0 < elemIDMax1; - } else { - /* One face is a local face and the other is not. Make sure that - the local faces are numbered first. */ - return face0IsLocal; - } + } /* One face is a local face and the other is not. Make sure that + the local faces are numbered first. */ + return face0IsLocal; + } else if (elemIDMax0 >= nVolElemTot && elemIDMax1 >= nVolElemTot) { /* Both faces are non-matching internal faces. Sort them according to their relevant element ID. The time level is not taken into account diff --git a/Common/src/geometry/CGeometry.cpp b/Common/src/geometry/CGeometry.cpp index 7f4626e4f98..cc5c84e54f3 100644 --- a/Common/src/geometry/CGeometry.cpp +++ b/Common/src/geometry/CGeometry.cpp @@ -1515,7 +1515,7 @@ bool CGeometry::SegmentIntersectsLine(const su2double point0[2], const su2double length = diff0_A * diff0_A + diff1_A * diff1_A; - return !((dist0 > length) || (dist1 > length)); + return (dist0 <= length) && (dist1 <= length); } bool CGeometry::SegmentIntersectsTriangle(su2double point0[3], const su2double point1[3], su2double vert0[3], diff --git a/Common/src/geometry/meshreader/CCGNSMeshReaderFVM.cpp b/Common/src/geometry/meshreader/CCGNSMeshReaderFVM.cpp index 81f5d1100ff..2d8db05e9c8 100644 --- a/Common/src/geometry/meshreader/CCGNSMeshReaderFVM.cpp +++ b/Common/src/geometry/meshreader/CCGNSMeshReaderFVM.cpp @@ -754,8 +754,8 @@ void CCGNSMeshReaderFVM::ReadCGNSVolumeSection(int val_section) { /*--- Free temporary memory from communications ---*/ - if (connSendReq != nullptr) delete[] connSendReq; - if (connRecvReq != nullptr) delete[] connRecvReq; + delete[] connSendReq; + delete[] connRecvReq; delete[] connSend; delete[] connRecv; diff --git a/Common/src/grid_movement/CBezierBlending.cpp b/Common/src/grid_movement/CBezierBlending.cpp index 0de026c0dba..0d8feebc645 100644 --- a/Common/src/grid_movement/CBezierBlending.cpp +++ b/Common/src/grid_movement/CBezierBlending.cpp @@ -88,15 +88,14 @@ su2double CBezierBlending::GetBernsteinDerivative(short val_n, short val_i, su2d if (val_i == 0) { value = val_n * (-GetBernsteinDerivative(val_n - 1, val_i, val_t, val_order_der - 1)); return value; + } + if (val_n == 0) { + value = val_t; + return value; } else { - if (val_n == 0) { - value = val_t; - return value; - } else { - value = val_n * (GetBernsteinDerivative(val_n - 1, val_i - 1, val_t, val_order_der - 1) - - GetBernsteinDerivative(val_n - 1, val_i, val_t, val_order_der - 1)); - return value; - } + value = val_n * (GetBernsteinDerivative(val_n - 1, val_i - 1, val_t, val_order_der - 1) - + GetBernsteinDerivative(val_n - 1, val_i, val_t, val_order_der - 1)); + return value; } return value; diff --git a/SU2_CFD/src/drivers/CDriver.cpp b/SU2_CFD/src/drivers/CDriver.cpp index 7b9621280f9..91378f64b1f 100644 --- a/SU2_CFD/src/drivers/CDriver.cpp +++ b/SU2_CFD/src/drivers/CDriver.cpp @@ -2821,8 +2821,7 @@ void CDriver::PrintDirectResidual(RECORDING kind_recording) { auto iVar_iZone2string = [&](unsigned short ivar, unsigned short izone) { if (multizone) return "[" + std::to_string(ivar) + "][" + std::to_string(izone) + "]"; - else - return "[" + std::to_string(ivar) + "]"; + return "[" + std::to_string(ivar) + "]"; }; /*--- Print residuals in the first iteration ---*/ diff --git a/SU2_CFD/src/drivers/CMultizoneDriver.cpp b/SU2_CFD/src/drivers/CMultizoneDriver.cpp index cd93263313f..4f2c83aa085 100644 --- a/SU2_CFD/src/drivers/CMultizoneDriver.cpp +++ b/SU2_CFD/src/drivers/CMultizoneDriver.cpp @@ -620,7 +620,7 @@ bool CMultizoneDriver::Monitor(unsigned long TimeIter){ return (MaxIterationsReached || InnerConvergence); } - else { // i.e. unsteady simulation + // i.e. unsteady simulation /*--- Check whether the outer time integration has reached the final time ---*/ const auto TimeConvergence = GetTimeConvergence(); @@ -641,7 +641,7 @@ bool CMultizoneDriver::Monitor(unsigned long TimeIter){ } return (FinalTimeReached || MaxIterationsReached); - } + } diff --git a/SU2_CFD/src/fluid/CSU2TCLib.cpp b/SU2_CFD/src/fluid/CSU2TCLib.cpp index 9e4d63b12ff..67cd77b343e 100644 --- a/SU2_CFD/src/fluid/CSU2TCLib.cpp +++ b/SU2_CFD/src/fluid/CSU2TCLib.cpp @@ -1581,7 +1581,7 @@ void CSU2TCLib::ComputeKeqConstants(unsigned short val_Reaction) { for (ii = 0; ii < 5; ii++) A[ii] = RxnConstantTable(0,ii); return; - } else if (iIndex >= 5) { + } if (iIndex >= 5) { for (ii = 0; ii < 5; ii++) A[ii] = RxnConstantTable(5,ii); return; @@ -1902,7 +1902,7 @@ su2double CSU2TCLib::ComputeCollisionCrossSection(unsigned iSpecies, unsigned jS if (Omega11(iSpecies, jSpecies, 0) == 1.0 && d1) { return 1E-20 * 5E15 * pi * pow((debyeLength / T), 2) * log(D1_a*T_star*(1 - C1_a * exp(-c1_a * T_star))+1); - } else if (Omega11(iSpecies, jSpecies, 0) == -1.0 && d1) { + } if (Omega11(iSpecies, jSpecies, 0) == -1.0 && d1) { return 1E-20 * 5E15 * pi * pow((debyeLength / T), 2) * log(D1_r*T_star*(1 - C1_r * exp(-c1_r * T_star))+1); } else if (Omega22(iSpecies, jSpecies, 0) == 1.0 && !d1) { return 1E-20 * 5E15 * pi * pow((debyeLength / T), 2) * log(D2_a*T_star*(1 - C2_a * exp(-c2_a * T_star))+1); @@ -1913,9 +1913,8 @@ su2double CSU2TCLib::ComputeCollisionCrossSection(unsigned iSpecies, unsigned jS } else { if (d1) { return 1E-20 * Omega11(iSpecies,jSpecies,3) * pow(T, Omega11(iSpecies,jSpecies,0)*log(T)*log(T) + Omega11(iSpecies,jSpecies,1)*log(T) + Omega11(iSpecies,jSpecies,2)); - } else { - return 1E-20 * Omega22(iSpecies,jSpecies,3) * pow(T, Omega22(iSpecies,jSpecies,0)*log(T)*log(T) + Omega22(iSpecies,jSpecies,1)*log(T) + Omega22(iSpecies,jSpecies,2)); - } + } return 1E-20 * Omega22(iSpecies,jSpecies,3) * pow(T, Omega22(iSpecies,jSpecies,0)*log(T)*log(T) + Omega22(iSpecies,jSpecies,1)*log(T) + Omega22(iSpecies,jSpecies,2)); + } } @@ -2169,9 +2168,8 @@ vector& CSU2TCLib::ComputeTemperatures(vector& val_rhos, s NRconvg = true; Tve = Tve2; break; - } else { - Tve = Tve2; - } + } Tve = Tve2; + } // If the Newton-Raphson method has converged, assign the value of Tve. @@ -2186,10 +2184,9 @@ vector& CSU2TCLib::ComputeTemperatures(vector& val_rhos, s if (fabs(rhoEve_t - rhoEve) < Btol) { Bconvg = true; break; - } else { - if (rhoEve_t > rhoEve) Tve2 = Tve; + } if (rhoEve_t > rhoEve) Tve2 = Tve; else Tve_o = Tve; - } + } } diff --git a/SU2_CFD/src/interfaces/CInterface.cpp b/SU2_CFD/src/interfaces/CInterface.cpp index 6053709a30c..dc068205324 100644 --- a/SU2_CFD/src/interfaces/CInterface.cpp +++ b/SU2_CFD/src/interfaces/CInterface.cpp @@ -227,11 +227,10 @@ void CInterface::PreprocessAverage(CGeometry *donor_geometry, CGeometry *target_ /*--- Exit the for loop: we have found the local index for Mixing-Plane interface ---*/ break; } - else { - /*--- If the tag hasn't matched any tag within the donor markers ---*/ + /*--- If the tag hasn't matched any tag within the donor markers ---*/ Marker_Donor = -1; Donor_Flag = -1; - } + } #ifdef HAVE_MPI @@ -273,10 +272,9 @@ void CInterface::PreprocessAverage(CGeometry *donor_geometry, CGeometry *target_ /*--- Exit the for loop: we have found the local index for iMarkerFSI on the FEA side ---*/ break; } - else { - /*--- If the tag hasn't matched any tag within the Flow markers ---*/ + /*--- If the tag hasn't matched any tag within the Flow markers ---*/ Marker_Target = -1; - } + } if (Marker_Target != -1 && Marker_Donor != -1){ @@ -418,10 +416,9 @@ void CInterface::AllgatherAverage(CSolver *donor_solution, CSolver *target_solut /*--- Exit the for loop: we have found the local index for Mixing-Plane interface ---*/ break; } - else { - /*--- If the tag hasn't matched any tag within the donor markers ---*/ + /*--- If the tag hasn't matched any tag within the donor markers ---*/ Marker_Donor = -1; - } + } /*--- Here we want to make available the quantities for all the processors and collect them in a buffer * for each span of the donor the span-wise height vector also so @@ -534,10 +531,9 @@ void CInterface::AllgatherAverage(CSolver *donor_solution, CSolver *target_solut /*--- Exit the for loop: we have found the local index for iMarkerFSI on the FEA side ---*/ break; } - else { - /*--- If the tag hasn't matched any tag within the Flow markers ---*/ + /*--- If the tag hasn't matched any tag within the Flow markers ---*/ Marker_Target = -1; - } + } diff --git a/SU2_CFD/src/iteration/CFEAIteration.cpp b/SU2_CFD/src/iteration/CFEAIteration.cpp index 45ded06c7ee..95e477d92c9 100644 --- a/SU2_CFD/src/iteration/CFEAIteration.cpp +++ b/SU2_CFD/src/iteration/CFEAIteration.cpp @@ -87,12 +87,11 @@ void CFEAIteration::Iterate(COutput* output, CIntegration**** integration, CGeom if (disc_adj_fem) { config[val_iZone]->SetInnerIter(CurIter); break; - } else { - StopCalc = Monitor(output, integration, geometry, solver, numerics, config, surface_movement, grid_movement, + } StopCalc = Monitor(output, integration, geometry, solver, numerics, config, surface_movement, grid_movement, FFDBox, val_iZone, INST_0); if (StopCalc && (IntIter > 0)) break; - } + } } else { diff --git a/SU2_CFD/src/iteration/CFluidIteration.cpp b/SU2_CFD/src/iteration/CFluidIteration.cpp index 7f7107f2ccb..f6feb7d9d58 100644 --- a/SU2_CFD/src/iteration/CFluidIteration.cpp +++ b/SU2_CFD/src/iteration/CFluidIteration.cpp @@ -588,9 +588,8 @@ void CFluidIteration::SetDualTime_Aeroelastic(CConfig* config) const { Monitoring_Tag = config->GetMarker_Monitoring_TagBound(iMarker_Monitoring); Marker_Tag = config->GetMarker_All_TagBound(iMarker); if (Marker_Tag == Monitoring_Tag) { owner = 1; break; - } else { - owner = 0; - } + } owner = 0; + } plunge = config->GetAeroelastic_plunge(iMarker_Monitoring); diff --git a/SU2_CFD/src/numerics/CNumerics.cpp b/SU2_CFD/src/numerics/CNumerics.cpp index 12a83bf7daa..1393c14a20a 100644 --- a/SU2_CFD/src/numerics/CNumerics.cpp +++ b/SU2_CFD/src/numerics/CNumerics.cpp @@ -31,7 +31,7 @@ #include "../../include/numerics/CNumerics.hpp" #include "../../include/fluid/CFluidModel.hpp" -CNumerics::CNumerics(void) { +CNumerics::CNumerics() { Proj_Flux_Tensor = nullptr; @@ -75,7 +75,7 @@ CNumerics::CNumerics(unsigned short val_nDim, unsigned short val_nVar, } -CNumerics::~CNumerics(void) { +CNumerics::~CNumerics() { // visc delete [] Proj_Flux_Tensor; diff --git a/SU2_CFD/src/output/CFlowOutput.cpp b/SU2_CFD/src/output/CFlowOutput.cpp index 1026b3d13e2..3fc02d126e7 100644 --- a/SU2_CFD/src/output/CFlowOutput.cpp +++ b/SU2_CFD/src/output/CFlowOutput.cpp @@ -873,9 +873,8 @@ void CFlowOutput::SetCustomOutputs(const CSolver* const* solver, const CGeometry const auto varIdx = i % CustomOutput::MAX_VARS_PER_SOLVER; if (solIdx == FLOW_SOL) { return flowNodes->GetPrimitive(iPoint, varIdx); - } else { - return solver[solIdx]->GetNodes()->GetSolution(iPoint, varIdx); - } + } return solver[solIdx]->GetNodes()->GetSolution(iPoint, varIdx); + } else { return *output.otherOutputs[i - CustomOutput::NOT_A_VARIABLE]; } diff --git a/SU2_CFD/src/output/COutput.cpp b/SU2_CFD/src/output/COutput.cpp index 9e95c9b4614..7c76bbf50bc 100644 --- a/SU2_CFD/src/output/COutput.cpp +++ b/SU2_CFD/src/output/COutput.cpp @@ -2134,9 +2134,8 @@ bool COutput::WriteVolumeOutput(CConfig *config, unsigned long Iter, bool force_ return ((Iter % config->GetVolumeOutputFrequency(iFile) == 0)) || force_writing; } - else { - return ((Iter > 0) && (Iter % config->GetVolumeOutputFrequency(iFile) == 0)) || force_writing; - } + return ((Iter > 0) && (Iter % config->GetVolumeOutputFrequency(iFile) == 0)) || force_writing; + } void COutput::SetCommonHistoryFields() { diff --git a/SU2_CFD/src/variables/CNEMOEulerVariable.cpp b/SU2_CFD/src/variables/CNEMOEulerVariable.cpp index 2c448786a29..e0a9836034a 100644 --- a/SU2_CFD/src/variables/CNEMOEulerVariable.cpp +++ b/SU2_CFD/src/variables/CNEMOEulerVariable.cpp @@ -228,12 +228,12 @@ bool CNEMOEulerVariable::Cons2PrimVar(su2double *U, su2double *V, // Determine if the temperature lies within the acceptable range if (V[T_INDEX] <= Tmin) { nonPhys = true; return nonPhys;} - else if (V[T_INDEX] >= Tmax) { nonPhys = true; return nonPhys;} + if (V[T_INDEX] >= Tmax) { nonPhys = true; return nonPhys;} else if (V[T_INDEX] != V[T_INDEX]){ nonPhys = true; return nonPhys;} if (!monoatomic){ if (V[TVE_INDEX] <= Tvemin) { nonPhys = true; return nonPhys;} - else if (V[TVE_INDEX] >= Tvemax) { nonPhys = true; return nonPhys;} + if (V[TVE_INDEX] >= Tvemax) { nonPhys = true; return nonPhys;} else if (V[TVE_INDEX] != V[TVE_INDEX]){ nonPhys = true; return nonPhys;} } else {V[TVE_INDEX] = Tve_Freestream;} diff --git a/SU2_DEF/src/drivers/CDiscAdjDeformationDriver.cpp b/SU2_DEF/src/drivers/CDiscAdjDeformationDriver.cpp index 3c4963a3d12..5645b8b7bdc 100644 --- a/SU2_DEF/src/drivers/CDiscAdjDeformationDriver.cpp +++ b/SU2_DEF/src/drivers/CDiscAdjDeformationDriver.cpp @@ -302,17 +302,16 @@ void CDiscAdjDeformationDriver::Run() { for (iZone = 0; iZone < nZone; iZone++) { if (!config_container[iZone]->GetDiscrete_Adjoint()) { continue; + } + if (rank == MASTER_NODE) + cout << "\n---------------------- Mesh sensitivity computation ---------------------" << endl; + if (config_container[iZone]->GetDiscrete_Adjoint() && config_container[iZone]->GetSmoothGradient() && + config_container[iZone]->GetSobMode() == ENUM_SOBOLEV_MODUS::MESH_LEVEL) { + DerivativeTreatment_MeshSensitivity(geometry_container[iZone][INST_0][MESH_0], config_container[iZone], + grid_movement[iZone][INST_0]); } else { - if (rank == MASTER_NODE) - cout << "\n---------------------- Mesh sensitivity computation ---------------------" << endl; - if (config_container[iZone]->GetDiscrete_Adjoint() && config_container[iZone]->GetSmoothGradient() && - config_container[iZone]->GetSobMode() == ENUM_SOBOLEV_MODUS::MESH_LEVEL) { - DerivativeTreatment_MeshSensitivity(geometry_container[iZone][INST_0][MESH_0], config_container[iZone], - grid_movement[iZone][INST_0]); - } else { - grid_movement[iZone][INST_0]->SetVolume_Deformation(geometry_container[iZone][INST_0][MESH_0], - config_container[iZone], false, true); - } + grid_movement[iZone][INST_0]->SetVolume_Deformation(geometry_container[iZone][INST_0][MESH_0], + config_container[iZone], false, true); } }