From 59d8ac2718b71be3600b67d6ee3c1fbd1ccdadd0 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Fri, 25 Sep 2026 11:37:07 +0200 Subject: [PATCH 01/42] small fix for the 1x2 agglomerations for implicit line agglomeration --- Common/src/geometry/CMultiGridGeometry.cpp | 91 ++++++++++++++++++++-- 1 file changed, 83 insertions(+), 8 deletions(-) diff --git a/Common/src/geometry/CMultiGridGeometry.cpp b/Common/src/geometry/CMultiGridGeometry.cpp index d3bca729bf5b..86b8c272871f 100644 --- a/Common/src/geometry/CMultiGridGeometry.cpp +++ b/Common/src/geometry/CMultiGridGeometry.cpp @@ -1619,7 +1619,7 @@ CMultiGridGeometry::CFrontSeeds CMultiGridGeometry::SeedFrontNodes(const CGeomet /*--- Paving order: a no-slip wall first, a slip wall next, everything else last. ---*/ auto tierOfBC = [](unsigned short bc) -> char { if ((bc == HEAT_FLUX) || (bc == ISOTHERMAL) || (bc == CHT_WALL_INTERFACE) || (bc == SMOLUCHOWSKI_MAXWELL)) return 0; - return (bc == EULER_WALL) ? 1 : 2; + return ((bc == EULER_WALL) || (bc == SYMMETRY_PLANE)) ? 1 : 2; }; for (auto iMarker = 0u; iMarker < fine_grid->GetnMarker(); iMarker++) { @@ -2322,6 +2322,63 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co byLayer[iColumn][layerOf[iPoint]].push_back(iPoint); } + /*--- A boundary run with an odd number of seeds, and every node where two boundaries meet, + * leaves one column a single node wide. Two such columns side by side are emitted together, + * so the domain gets square cells instead of a file of narrow ones. ---*/ + vector partnerOf(nColumn, -1); + { + auto isNarrow = [&](unsigned long iColumn) { + return isSeeded[iColumn] && (byLayer[iColumn].size() > 1) && (byLayer[iColumn][0].size() == 1); + }; + + /*--- Both columns must stand shoulder to shoulder over every layer they share, otherwise the + * cells the merge makes are not compact. ---*/ + auto aligned = [&](unsigned long iColumn, unsigned long jColumn) { + const auto nCommon = std::min(byLayer[iColumn].size(), byLayer[jColumn].size()); + for (auto iLayer = 1ul; iLayer < nCommon; ++iLayer) { + const auto iPoint = byLayer[iColumn][iLayer].front(); + const auto jPoint = byLayer[jColumn][iLayer].front(); + bool touch = false; + for (auto kPoint : fine_grid->nodes->GetPoints(iPoint)) touch = touch || (kPoint == jPoint); + if (!touch) return false; + } + return nCommon > 1; + }; + + /*--- Taken in global index order, so the pairing does not depend on the partitioning. ---*/ + vector narrow; + for (auto iColumn = 0ul; iColumn < nColumn; ++iColumn) + if (isNarrow(iColumn)) narrow.push_back(iColumn); + std::sort(narrow.begin(), narrow.end(), [&](unsigned long a, unsigned long b) { + return fine_grid->nodes->GetGlobalIndex(byLayer[a][0].front()) < + fine_grid->nodes->GetGlobalIndex(byLayer[b][0].front()); + }); + + for (auto iColumn : narrow) { + if (partnerOf[iColumn] >= 0) continue; + auto best = NO_COLUMN; + auto bestKey = std::numeric_limits::max(); + + for (auto jPoint : fine_grid->nodes->GetPoints(byLayer[iColumn][1].front())) { + const auto jColumn = columnOf[jPoint]; + if ((jColumn == NO_COLUMN) || (jColumn == iColumn)) continue; + if ((partnerOf[jColumn] >= 0) || !isNarrow(jColumn)) continue; + if (tierOf[jColumn] != tierOf[iColumn]) continue; + if (!aligned(iColumn, jColumn)) continue; + + const auto key = fine_grid->nodes->GetGlobalIndex(byLayer[jColumn][0].front()); + if (key < bestKey) { + bestKey = key; + best = jColumn; + } + } + + if (best == NO_COLUMN) continue; + partnerOf[iColumn] = static_cast(best); + partnerOf[best] = static_cast(iColumn); + } + } + auto emitGroup = [&](const vector& group) { nodes->SetChildren_CV(Index_CoarseCV, group); for (auto iPoint : group) { @@ -2334,6 +2391,7 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co auto minDepth = std::numeric_limits::max(), maxDepth = 0ul; vector group; + vector> paired; /*--- Hand a set of nodes out as coarse CVs, each connected and within the size limit. ---*/ vector inSet(nPointFine, 0); @@ -2379,7 +2437,8 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co auto iLayer = 0ul; if (isSeeded[iColumn]) { - /*--- The boundary row is a coarse CV of its own, which fixes the footprint above it. ---*/ + /*--- The boundary row is a coarse CV of its own, which fixes the footprint above it. A + * paired column keeps its own row, which may hold a boundary condition of its own. ---*/ const auto baseCV = emitGroup(layers[0]); ct[P_CVS]++; ct[P_COVERED] += layers[0].size(); @@ -2387,19 +2446,35 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co iLayer = 1; } + /*--- Of a pair, the column of lower index emits what stands above both boundary rows. ---*/ + if ((partnerOf[iColumn] >= 0) && (partnerOf[iColumn] < static_cast(iColumn))) continue; + + const auto* emitted = &layers; + if (partnerOf[iColumn] > static_cast(iColumn)) { + const auto& other = byLayer[partnerOf[iColumn]]; + paired = layers; + for (auto k = 1ul; k < other.size(); ++k) { + if (k < paired.size()) + paired[k].insert(paired[k].end(), other[k].begin(), other[k].end()); + else + paired.push_back(other[k]); + } + emitted = &paired; + } + /*--- Above it, consecutive layers are blocked so the coarse cell coarsens by the same ratio * along the column as the patch does across it. ---*/ - while (iLayer < layers.size()) { + while (iLayer < emitted->size()) { group.clear(); - const auto block = BlockFor(maxAgglomSize, layers[iLayer].size()); - for (auto k = 0ul; (k < block) && (iLayer < layers.size()); ++k) { - if (!group.empty() && (group.size() + layers[iLayer].size() > static_cast(maxAgglomSize))) break; - group.insert(group.end(), layers[iLayer].begin(), layers[iLayer].end()); + const auto block = BlockFor(maxAgglomSize, (*emitted)[iLayer].size()); + for (auto k = 0ul; (k < block) && (iLayer < emitted->size()); ++k) { + if (!group.empty() && (group.size() + (*emitted)[iLayer].size() > static_cast(maxAgglomSize))) break; + group.insert(group.end(), (*emitted)[iLayer].begin(), (*emitted)[iLayer].end()); iLayer++; } /*--- A single layer wider than the limit still has to go somewhere. ---*/ if (group.empty()) { - group = layers[iLayer]; + group = (*emitted)[iLayer]; iLayer++; } emitConnected(group); From 17badc027892ecfe9dd52249583874da4255b8b7 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Fri, 25 Sep 2026 14:55:00 +0200 Subject: [PATCH 02/42] linear prolongation --- Common/include/option_structure.hpp | 2 + Common/src/CConfig.cpp | 4 + .../integration/CMultiGridIntegration.hpp | 20 +- SU2_CFD/src/drivers/CDriver.cpp | 16 +- .../src/integration/CMultiGridIntegration.cpp | 244 +++++++++++++++++- config_template.cfg | 6 + 6 files changed, 280 insertions(+), 12 deletions(-) diff --git a/Common/include/option_structure.hpp b/Common/include/option_structure.hpp index bcd2e9c06328..de84b14d5037 100644 --- a/Common/include/option_structure.hpp +++ b/Common/include/option_structure.hpp @@ -1234,6 +1234,8 @@ struct CMGOptions { bool MG_Smooth_Output{false}; /*!< \brief Output compact per-cycle smoothing summary. */ su2double MG_Smooth_StagnationTol{0.0}; /*!< \brief Stagnation early exit: stop if current_rms >= prev_rms * tol. 0 = disabled. */ bool MG_Implicit_Lines{false}; /*!< \brief Enable implicit-lines agglomeration from walls. */ + bool MG_Linear_Prolongation{false}; /*!< \brief Prolong the correction with a limited least-squares + gradient instead of piecewise-constant injection. */ unsigned long MG_Startup_Iter{100}; /*!< \brief Iterations per mesh during FMG startup, and the length of each level's CFL ramp. 0 = no iteration budget. */ su2double MG_Startup_Convergence{-2.0}; /*!< \brief FMG: orders of magnitude (log10) that CONV_FIELD must drop on the active level before promoting to the next finer one. Negative is a diff --git a/Common/src/CConfig.cpp b/Common/src/CConfig.cpp index fd4207b0c5fe..bb26e78c2445 100644 --- a/Common/src/CConfig.cpp +++ b/Common/src/CConfig.cpp @@ -2104,6 +2104,10 @@ void CConfig::SetConfig_Options() { /*!\brief MG_IMPLICIT_LINES\n DESCRIPTION: Pave the coarse grid with advancing fronts raised from boundaries * that carry a stretched layer normal to themselves. DEFAULT: NO \ingroup Config*/ addBoolOption("MG_IMPLICIT_LINES", MGOptions.MG_Implicit_Lines, false); + /*!\brief MG_LINEAR_PROLONGATION\n DESCRIPTION: Prolong the multigrid correction with a limited least-squares + * gradient over the coarse control volume instead of injecting the parent value into every child. Coarse CVs on + * walls and symmetry planes keep the constant operator. DEFAULT: NO \ingroup Config*/ + addBoolOption("MG_LINEAR_PROLONGATION", MGOptions.MG_Linear_Prolongation, false); /*!\brief MG_STARTUP_ITER\n DESCRIPTION: Max number of iterations spent on each mesh during the Full * Multigrid (FMG) startup phase. DEFAULT: 100 \ingroup Config*/ addUnsignedLongOption("MG_STARTUP_ITER", MGOptions.MG_Startup_Iter, 100); diff --git a/SU2_CFD/include/integration/CMultiGridIntegration.hpp b/SU2_CFD/include/integration/CMultiGridIntegration.hpp index d73b4962128f..8433f2cb25d3 100644 --- a/SU2_CFD/include/integration/CMultiGridIntegration.hpp +++ b/SU2_CFD/include/integration/CMultiGridIntegration.hpp @@ -26,6 +26,7 @@ */ #include "CIntegration.hpp" +#include "../../../Common/include/containers/container_decorators.hpp" /*! * \class CMultiGridIntegration @@ -190,7 +191,20 @@ class CMultiGridIntegration final : public CIntegration { * \param[in] config - Definition of the particular problem. */ void GetProlongated_Correction(unsigned short RunTime_EqSystem, CSolver *sol_fine, CSolver *sol_coarse, - CGeometry *geo_fine, CGeometry *geo_coarse, CConfig *config); + CGeometry *geo_fine, CGeometry *geo_coarse, CConfig *config, + unsigned short iMesh); + + /*! + * \brief Least-squares gradient of the coarse-grid correction, limited so no child value + * leaves the range of the coarse stencil. + * \param[in] sol_coarse - Solver holding the correction in Solution_Old. + * \param[in] geo_coarse - Geometrical definition of the coarse grid. + * \param[in] geo_fine - Geometrical definition of the fine grid. + * \param[in] config - Definition of the particular problem. + * \param[in] iMesh - Index of the coarse mesh. + */ + void ComputeProlongationGradient(CSolver *sol_coarse, CGeometry *geo_coarse, CGeometry *geo_fine, + const CConfig *config, unsigned short iMesh); /*! * \brief Do an implicit smoothing of the prolongated correction. @@ -367,6 +381,10 @@ class CMultiGridIntegration final : public CIntegration { enum class MGStartupPromote { NONE, BUDGET, CONVERGENCE, STAGNATION }; MGStartupPromote mg_startup_promote_reason = MGStartupPromote::NONE; + /*! \brief Limited least-squares gradient of the correction, indexed by coarse level. + * Allocated on first use, only when MG_LINEAR_PROLONGATION is on. */ + vector prolongGradient; + vector mg_startup_conv_start; /*!< \brief Field values when the active level became active. */ vector mg_startup_conv_prev; /*!< \brief Field values on the previous iteration. */ unsigned long mg_startup_stall_count = 0; /*!< \brief Consecutive iterations without useful reduction. */ diff --git a/SU2_CFD/src/drivers/CDriver.cpp b/SU2_CFD/src/drivers/CDriver.cpp index 29fb325fa233..dbe6458b9aa2 100644 --- a/SU2_CFD/src/drivers/CDriver.cpp +++ b/SU2_CFD/src/drivers/CDriver.cpp @@ -881,10 +881,6 @@ void CDriver::InitializeGeometryFVM(CConfig *config, CGeometry **&geometry) { geometry[iMGlevel]->SetCoord(geometry[iMGlevel-1]); - /*--- Find closest, most normal, neighbor to a surface point ---*/ - - geometry[iMGlevel]->FindNormal_Neighbor(config); - /*--- Store our multigrid index. ---*/ geometry[iMGlevel]->SetMGLevel(iMGlevel); @@ -934,6 +930,18 @@ void CDriver::InitializeGeometryFVM(CConfig *config, CGeometry **&geometry) { for (iMGlevel = 0; iMGlevel <= config->GetnMGLevels(); iMGlevel++) { + /*--- SetCoord centred a halo agglomerate on the partial child list this rank holds. Take + the owner's coordinate, otherwise coarse stencils depend on the partitioning. ---*/ + + if (iMGlevel > MESH_0) { + geometry[iMGlevel]->InitiateComms(geometry[iMGlevel], config, MPI_QUANTITIES::COORDINATES); + geometry[iMGlevel]->CompleteComms(geometry[iMGlevel], config, MPI_QUANTITIES::COORDINATES); + + /*--- Find closest, most normal, neighbor to a surface point ---*/ + + geometry[iMGlevel]->FindNormal_Neighbor(config); + } + /*--- Compute the max length. ---*/ if (!fea) { diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index 607a0915d3c8..8c26640139d4 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -28,6 +28,7 @@ #include "../../include/integration/CMultiGridIntegration.hpp" #include "../../../Common/include/parallelization/omp_structure.hpp" #include "../../../Common/include/toolboxes/printing_toolbox.hpp" +#include "../../../Common/include/toolboxes/geometry_toolbox.hpp" #include @@ -50,6 +51,50 @@ static su2double applyGlobalTrend(su2double factor, passivedouble crossCycleRati return max(su2double{CLAMP_MIN}, min(su2double{CLAMP_MAX}, factor)); } +/*!\cond PRIVATE + * Inverts the symmetric least-squares matrix. False means the stencil is too degenerate + * to define a gradient. + \endcond */ +static bool invertLeastSquaresMatrix(unsigned short nDim, const su2double A[3][3], su2double inv[3][3]) { + + /*--- Compare against the trace so the test does not depend on the mesh units. ---*/ + + su2double trace = 0.0; + for (auto iDim = 0u; iDim < nDim; iDim++) trace += A[iDim][iDim]; + if (trace <= 0.0) return false; + + const su2double scale = trace / su2double(nDim); + constexpr passivedouble REL_TOL = 1e-12; + + if (nDim == 2) { + const su2double det = A[0][0]*A[1][1] - A[0][1]*A[0][1]; + if (det <= REL_TOL * scale * scale) return false; + + inv[0][0] = A[1][1]/det; + inv[0][1] = -A[0][1]/det; + inv[1][0] = inv[0][1]; + inv[1][1] = A[0][0]/det; + return true; + } + + const su2double a = A[0][0], b = A[0][1], c = A[0][2]; + const su2double d = A[1][1], e = A[1][2], f = A[2][2]; + + const su2double det = a*(d*f - e*e) - b*(b*f - e*c) + c*(b*e - d*c); + if (det <= REL_TOL * scale * scale * scale) return false; + + inv[0][0] = (d*f - e*e)/det; + inv[0][1] = (c*e - b*f)/det; + inv[0][2] = (b*e - c*d)/det; + inv[1][1] = (a*f - c*c)/det; + inv[1][2] = (b*c - a*e)/det; + inv[2][2] = (a*d - b*b)/det; + inv[1][0] = inv[0][1]; + inv[2][0] = inv[0][2]; + inv[2][1] = inv[1][2]; + return true; +} + inline passivedouble ComputeLinSysResRMS(const CSolver* solver) { passivedouble result = 0; for (unsigned short iVar = 0; iVar < solver->GetnVar(); ++iVar) { @@ -72,7 +117,9 @@ void CMultiGridIntegration::adaptDampingFactors(CConfig* config, passivedouble c applyGlobalTrend(config->GetDamp_Correc_Prolong(), crossCycleRatio)); } -CMultiGridIntegration::CMultiGridIntegration() : CIntegration() { } +CMultiGridIntegration::CMultiGridIntegration() : CIntegration() { + prolongGradient.resize(MAX_MG_LEVELS + 1); +} void CMultiGridIntegration::MonitorFullMG_Startup(const vector >& convFields, const CConfig *config) { @@ -670,7 +717,8 @@ void CMultiGridIntegration::MultiGrid_Cycle(CGeometry ****geometry, /*--- Compute prolongated solution, and smooth the correction $u^(new)_k = u_k + Smooth(I^k_(k+1)(u_(k+1)-I^(k+1)_k u_k))$ ---*/ - GetProlongated_Correction(RunTime_EqSystem, solver_fine, solver_coarse, geometry_fine, geometry_coarse, config); + GetProlongated_Correction(RunTime_EqSystem, solver_fine, solver_coarse, geometry_fine, geometry_coarse, config, + iMesh+1); const auto& mgOpts = config->GetMGOptions(); SmoothProlongated_Correction(RunTime_EqSystem, solver_fine, geometry_fine, mgOpts.MG_CorrecSmooth[iMesh], mgOpts.MG_Smooth_Coeff, config, iMesh); @@ -873,7 +921,8 @@ void CMultiGridIntegration::PostSmoothing(unsigned short RunTime_EqSystem, void CMultiGridIntegration::GetProlongated_Correction(unsigned short RunTime_EqSystem, CSolver *sol_fine, CSolver *sol_coarse, - CGeometry *geo_fine, CGeometry *geo_coarse, CConfig *config) { + CGeometry *geo_fine, CGeometry *geo_coarse, CConfig *config, + unsigned short iMesh) { SU2_ZONE_SCOPED const unsigned short nVar = sol_coarse->GetnVar(); @@ -941,13 +990,194 @@ void CMultiGridIntegration::GetProlongated_Correction(unsigned short RunTime_EqS /*--- Interpolate the coarse-grid correction onto the fine * grid and store in LinSysRes. ---*/ - /*--- Halos too: the correction smoother reads them before its first exchange. ---*/ - SU2_OMP_FOR_STAT(roundUpDiv(geo_coarse->GetnPoint(), omp_get_num_threads())) - for (auto Point_Coarse = 0ul; Point_Coarse < geo_coarse->GetnPoint(); Point_Coarse++) { + if (!config->GetMGOptions().MG_Linear_Prolongation) { + + /*--- Halos too: the correction smoother reads them before its first exchange. ---*/ + SU2_OMP_FOR_STAT(roundUpDiv(geo_coarse->GetnPoint(), omp_get_num_threads())) + for (auto Point_Coarse = 0ul; Point_Coarse < geo_coarse->GetnPoint(); Point_Coarse++) { + const auto* Correction = sol_coarse->GetNodes()->GetSolution_Old(Point_Coarse); + for (auto iChildren = 0u; iChildren < geo_coarse->nodes->GetnChildren_CV(Point_Coarse); iChildren++) { + const auto Point_Fine = geo_coarse->nodes->GetChildren_CV(Point_Coarse, iChildren); + sol_fine->LinSysRes.SetBlock(Point_Fine, Correction); + } + } + END_SU2_OMP_FOR + + return; + } + + /*--- The coarse coordinate is the volume-weighted centroid of the children, so the + * reconstruction below averages back to the coarse correction exactly. ---*/ + + ComputeProlongationGradient(sol_coarse, geo_coarse, geo_fine, config, iMesh); + + const unsigned short nDim = geo_coarse->GetnDim(); + const auto& gradient = prolongGradient[iMesh]; + + /*--- A halo agglomerate holds a partial child list, so only owners write, and the + * exchange below fills the fine halos the correction smoother reads. ---*/ + + SU2_OMP_FOR_STAT(roundUpDiv(geo_coarse->GetnPointDomain(), omp_get_num_threads())) + for (auto Point_Coarse = 0ul; Point_Coarse < geo_coarse->GetnPointDomain(); Point_Coarse++) { + const auto* Correction = sol_coarse->GetNodes()->GetSolution_Old(Point_Coarse); + const auto* Coord_Coarse = geo_coarse->nodes->GetCoord(Point_Coarse); + for (auto iChildren = 0u; iChildren < geo_coarse->nodes->GetnChildren_CV(Point_Coarse); iChildren++) { const auto Point_Fine = geo_coarse->nodes->GetChildren_CV(Point_Coarse, iChildren); - sol_fine->LinSysRes.SetBlock(Point_Fine, Correction); + + su2double Distance[MAXNDIM] = {0.0}; + GeometryToolbox::Distance(nDim, geo_fine->nodes->GetCoord(Point_Fine), Coord_Coarse, Distance); + + su2double Solution[MAXNVAR] = {0.0}; + for (auto iVar = 0u; iVar < nVar; iVar++) { + Solution[iVar] = Correction[iVar]; + for (auto iDim = 0u; iDim < nDim; iDim++) + Solution[iVar] += gradient(Point_Coarse, iVar, iDim) * Distance[iDim]; + } + sol_fine->LinSysRes.SetBlock(Point_Fine, Solution); + } + } + END_SU2_OMP_FOR + + SU2_OMP_BARRIER + CSysMatrixComms::Initiate(sol_fine->LinSysRes, geo_fine, config); + CSysMatrixComms::Complete(sol_fine->LinSysRes, geo_fine, config); + +} + +void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGeometry *geo_coarse, + CGeometry *geo_fine, const CConfig *config, + unsigned short iMesh) { + SU2_ZONE_SCOPED + + const unsigned short nVar = sol_coarse->GetnVar(); + const unsigned short nDim = geo_coarse->GetnDim(); + const auto nPointDomain = geo_coarse->GetnPointDomain(); + auto* nodes = sol_coarse->GetNodes(); + + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS + { + auto& grad = prolongGradient[iMesh]; + if ((grad.length() != nPointDomain) || (grad.rows() != nVar) || (grad.cols() != nDim)) + grad.resize(nPointDomain, nVar, nDim, 0.0); + } + END_SU2_OMP_SAFE_GLOBAL_ACCESS + + auto& gradient = prolongGradient[iMesh]; + + /*--- Unweighted fit: inverse-distance weights would let the short wall-normal edges of a + * stretched agglomerate dominate it. ---*/ + + SU2_OMP_FOR_STAT(roundUpDiv(nPointDomain, omp_get_num_threads())) + for (auto iPoint = 0ul; iPoint < nPointDomain; iPoint++) { + + for (auto iVar = 0u; iVar < nVar; iVar++) + for (auto iDim = 0u; iDim < nDim; iDim++) gradient(iPoint, iVar, iDim) = 0.0; + + const auto* Coord_i = geo_coarse->nodes->GetCoord(iPoint); + const auto* Correction_i = nodes->GetSolution_Old(iPoint); + + su2double Amat[MAXNDIM][MAXNDIM] = {{0.0}}; + su2double rhs[MAXNVAR][MAXNDIM] = {{0.0}}; + + for (auto jPoint : geo_coarse->nodes->GetPoints(iPoint)) { + + su2double Distance[MAXNDIM] = {0.0}; + GeometryToolbox::Distance(nDim, geo_coarse->nodes->GetCoord(jPoint), Coord_i, Distance); + + for (auto iDim = 0u; iDim < nDim; iDim++) + for (auto jDim = 0u; jDim < nDim; jDim++) Amat[iDim][jDim] += Distance[iDim]*Distance[jDim]; + + const auto* Correction_j = nodes->GetSolution_Old(jPoint); + + for (auto iVar = 0u; iVar < nVar; iVar++) { + const su2double delta = Correction_j[iVar] - Correction_i[iVar]; + for (auto iDim = 0u; iDim < nDim; iDim++) rhs[iVar][iDim] += Distance[iDim]*delta; + } + } + + su2double Ainv[MAXNDIM][MAXNDIM] = {{0.0}}; + if (!invertLeastSquaresMatrix(nDim, Amat, Ainv)) continue; + + for (auto iVar = 0u; iVar < nVar; iVar++) + for (auto iDim = 0u; iDim < nDim; iDim++) { + su2double value = 0.0; + for (auto jDim = 0u; jDim < nDim; jDim++) value += Ainv[iDim][jDim]*rhs[iVar][jDim]; + gradient(iPoint, iVar, iDim) = value; + } + } + END_SU2_OMP_FOR + + /*--- Control volumes on a wall or symmetry plane keep the constant operator, their + * correction being constrained by the boundary condition. ---*/ + + for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); iMarker++) { + + const auto kindBC = config->GetMarker_All_KindBC(iMarker); + if (!config->GetViscous_Wall(iMarker) && (kindBC != EULER_WALL) && (kindBC != SYMMETRY_PLANE)) continue; + + SU2_OMP_FOR_STAT(32) + for (auto iVertex = 0ul; iVertex < geo_coarse->nVertex[iMarker]; iVertex++) { + const auto iPoint = geo_coarse->vertex[iMarker][iVertex]->GetNode(); + if (iPoint >= nPointDomain) continue; + for (auto iVar = 0u; iVar < nVar; iVar++) + for (auto iDim = 0u; iDim < nDim; iDim++) gradient(iPoint, iVar, iDim) = 0.0; + } + END_SU2_OMP_FOR + } + + /*--- Barth-Jespersen limiter over the children. One factor per variable scales the whole + * gradient, which is what keeps the children averaging back to the coarse value. ---*/ + + SU2_OMP_FOR_STAT(roundUpDiv(nPointDomain, omp_get_num_threads())) + for (auto iPoint = 0ul; iPoint < nPointDomain; iPoint++) { + + const auto* Coord_i = geo_coarse->nodes->GetCoord(iPoint); + const auto* Correction_i = nodes->GetSolution_Old(iPoint); + + su2double Correction_Min[MAXNVAR], Correction_Max[MAXNVAR]; + for (auto iVar = 0u; iVar < nVar; iVar++) { + Correction_Min[iVar] = Correction_i[iVar]; + Correction_Max[iVar] = Correction_i[iVar]; + } + + for (auto jPoint : geo_coarse->nodes->GetPoints(iPoint)) { + const auto* Correction_j = nodes->GetSolution_Old(jPoint); + for (auto iVar = 0u; iVar < nVar; iVar++) { + Correction_Min[iVar] = min(Correction_Min[iVar], Correction_j[iVar]); + Correction_Max[iVar] = max(Correction_Max[iVar], Correction_j[iVar]); + } + } + + su2double limiter[MAXNVAR]; + for (auto iVar = 0u; iVar < nVar; iVar++) limiter[iVar] = 1.0; + + for (auto iChildren = 0u; iChildren < geo_coarse->nodes->GetnChildren_CV(iPoint); iChildren++) { + + const auto Point_Fine = geo_coarse->nodes->GetChildren_CV(iPoint, iChildren); + + su2double Distance[MAXNDIM] = {0.0}; + GeometryToolbox::Distance(nDim, geo_fine->nodes->GetCoord(Point_Fine), Coord_i, Distance); + + for (auto iVar = 0u; iVar < nVar; iVar++) { + + su2double delta = 0.0; + for (auto iDim = 0u; iDim < nDim; iDim++) delta += gradient(iPoint, iVar, iDim)*Distance[iDim]; + + /*--- Scaled with the correction so the cut-off tracks its magnitude. ---*/ + const su2double tol = EPS*max(fabs(Correction_Max[iVar]), fabs(Correction_Min[iVar])) + EPS*EPS; + + if (delta > tol) + limiter[iVar] = min(limiter[iVar], (Correction_Max[iVar] - Correction_i[iVar])/delta); + else if (delta < -tol) + limiter[iVar] = min(limiter[iVar], (Correction_Min[iVar] - Correction_i[iVar])/delta); + } + } + + for (auto iVar = 0u; iVar < nVar; iVar++) { + const su2double factor = max(su2double(0.0), min(su2double(1.0), limiter[iVar])); + for (auto iDim = 0u; iDim < nDim; iDim++) gradient(iPoint, iVar, iDim) *= factor; } } END_SU2_OMP_FOR diff --git a/config_template.cfg b/config_template.cfg index 88533d33c689..a9d211119c79 100644 --- a/config_template.cfg +++ b/config_template.cfg @@ -1766,6 +1766,12 @@ MG_DAMP_RESTRICTION= 0.5 % Damping factor for the correction prolongation MG_DAMP_PROLONGATION= 0.5 % +% Prolong the correction with a limited least-squares gradient over the coarse control +% volume instead of injecting the parent value into every child. The reconstruction is +% exact for a linear correction and the children still average back to the coarse value. +% Control volumes on walls and symmetry planes keep the constant operator (NO, YES) +MG_LINEAR_PROLONGATION= NO +% % Enable early exit from multigrid smoothing when the residual RMS drops % below MG_SMOOTH_RES_THRESHOLD * initial_rms (NO, YES) MG_SMOOTH_EARLY_EXIT= YES From 453befc066a741cd885c9b046817533973df82dc Mon Sep 17 00:00:00 2001 From: bigfooted Date: Fri, 25 Sep 2026 20:29:38 +0200 Subject: [PATCH 03/42] fix FMG turbulence --- .../containers/container_decorators.hpp | 3 +- Common/include/option_structure.hpp | 2 + Common/src/CConfig.cpp | 12 +++- Common/src/geometry/CGeometry.cpp | 70 +++++++++++++++++++ .../integration/CMultiGridIntegration.hpp | 3 +- .../include/variables/CAdjEulerVariable.hpp | 5 ++ SU2_CFD/include/variables/CEulerVariable.hpp | 5 ++ .../include/variables/CIncEulerVariable.hpp | 5 ++ .../include/variables/CNEMOEulerVariable.hpp | 6 ++ SU2_CFD/include/variables/CVariable.hpp | 6 ++ .../src/integration/CMultiGridIntegration.cpp | 54 +++++++++----- .../integration/CSingleGridIntegration.cpp | 7 ++ config_template.cfg | 5 +- 13 files changed, 161 insertions(+), 22 deletions(-) diff --git a/Common/include/containers/container_decorators.hpp b/Common/include/containers/container_decorators.hpp index 331e87b9a0f4..82b89814960a 100644 --- a/Common/include/containers/container_decorators.hpp +++ b/Common/include/containers/container_decorators.hpp @@ -126,7 +126,8 @@ class C3DContainerDecorator { private: Storage m_storage; - Index m_innerSz; + /*--- One, not zero, so rows() on a container that was never resized does not divide by it. ---*/ + Index m_innerSz = 1; public: C3DContainerDecorator() = default; diff --git a/Common/include/option_structure.hpp b/Common/include/option_structure.hpp index de84b14d5037..506d4cf83678 100644 --- a/Common/include/option_structure.hpp +++ b/Common/include/option_structure.hpp @@ -80,6 +80,7 @@ const unsigned int MAX_NUMBER_FFD = 15; /*!< \brief Maximum number of FFDB enum: unsigned int{MAX_SOLS = 14}; /*!< \brief Maximum number of solutions at the same time (dimension of solution container array). */ const unsigned int MAX_TERMS = 7; /*!< \brief Maximum number of terms in the numerical equations (dimension of solver container array). */ const unsigned int MAX_ZONES = 3; /*!< \brief Maximum number of zones. */ +const unsigned short MAX_MGLEVELS = 10; /*!< \brief Maximum number of coarse multigrid levels, which bounds the per-level arrays of the multigrid integration. */ const unsigned int MAX_FE_KINDS = 7; /*!< \brief Maximum number of Finite Elements. */ const unsigned int NO_RK_ITER = 0; /*!< \brief No Runge-Kutta iteration. */ @@ -2877,6 +2878,7 @@ enum class MPI_QUANTITIES { COORDINATES , /*!< \brief Vertex coordinates communication. */ COORDINATES_OLD , /*!< \brief Old vertex coordinates communication. */ MAX_LENGTH , /*!< \brief Maximum length communication. */ + WALL_DISTANCE , /*!< \brief Wall distance and roughness of the nearest wall communication. */ GRID_VELOCITY , /*!< \brief Grid velocity communication. */ SOLUTION_EDDY , /*!< \brief Turbulent solution plus eddy viscosity communication. */ STOCH_SOURCE_LANG , /*!< \brief Stochastic source term for Langevin equations communication. */ diff --git a/Common/src/CConfig.cpp b/Common/src/CConfig.cpp index bb26e78c2445..39d9e23b8f18 100644 --- a/Common/src/CConfig.cpp +++ b/Common/src/CConfig.cpp @@ -2116,8 +2116,9 @@ void CConfig::SetConfig_Options() { * DEFAULT: -2 \ingroup Config*/ addDoubleOption("MG_STARTUP_CONVERGENCE", MGOptions.MG_Startup_Convergence, -2.0); /*!\brief MG_STARTUP_STAGNATION\n DESCRIPTION: Full-MG promotion on stagnation. If the active level's residual ratio - * between successive iterations exceeds this value for MG_STARTUP_STAGNATION_ITER consecutive iterations, promote to - * the next finer level without waiting out MG_STARTUP_ITER. 0 disables it. DEFAULT: 0.99 \ingroup Config*/ + * between successive iterations stays between this value and its inverse for MG_STARTUP_STAGNATION_ITER consecutive + * iterations, promote to the next finer level without waiting out MG_STARTUP_ITER. 0 disables it. + * DEFAULT: 0.99 \ingroup Config*/ addDoubleOption("MG_STARTUP_STAGNATION", MGOptions.MG_Startup_Stagnation, 0.99); /*!\brief MG_STARTUP_STAGNATION_ITER\n DESCRIPTION: Consecutive stalled iterations required before Full-MG promotes * on stagnation. 0 disables it, as MG_STARTUP_STAGNATION= 0 does. DEFAULT: 5 \ingroup Config*/ @@ -4983,6 +4984,13 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i Kappa_2nd_AdjFlow = jst_adj_coeff[0]; Kappa_4th_AdjFlow = jst_adj_coeff[1]; + /*--- The multigrid integration carries per-level arrays of this size. ---*/ + + if (nMGLevels > MAX_MGLEVELS) { + SU2_MPI::Error("MGLEVEL is larger than the supported maximum of " + std::to_string(MAX_MGLEVELS) + ".", + CURRENT_FUNCTION); + } + /*--- Fill MG smooth vectors to size nMGLevels+1. Use parsed values (truncating or extending by repeat) or defaults if not set. ---*/ diff --git a/Common/src/geometry/CGeometry.cpp b/Common/src/geometry/CGeometry.cpp index 360da1aaaa1e..736a12057162 100644 --- a/Common/src/geometry/CGeometry.cpp +++ b/Common/src/geometry/CGeometry.cpp @@ -627,6 +627,10 @@ void CGeometry::GetCommCountAndType(const CConfig* config, MPI_QUANTITIES commTy COUNT_PER_POINT = 1; MPI_TYPE = COMM_TYPE::DOUBLE; break; + case MPI_QUANTITIES::WALL_DISTANCE: + COUNT_PER_POINT = 2; + MPI_TYPE = COMM_TYPE::DOUBLE; + break; case MPI_QUANTITIES::NEIGHBORS: COUNT_PER_POINT = 1; MPI_TYPE = COMM_TYPE::UNSIGNED_SHORT; @@ -718,6 +722,10 @@ void CGeometry::InitiateComms(CGeometry* geometry, const CConfig* config, MPI_QU case MPI_QUANTITIES::MAX_LENGTH: bufDSend[buf_offset] = nodes->GetMaxLength(iPoint); break; + case MPI_QUANTITIES::WALL_DISTANCE: + bufDSend[buf_offset] = nodes->GetWall_Distance(iPoint); + bufDSend[buf_offset + 1] = nodes->GetRoughnessHeight(iPoint); + break; case MPI_QUANTITIES::NEIGHBORS: bufSSend[buf_offset] = geometry->nodes->GetnNeighbor(iPoint); break; @@ -811,6 +819,10 @@ void CGeometry::CompleteComms(CGeometry* geometry, const CConfig* config, MPI_QU case MPI_QUANTITIES::MAX_LENGTH: nodes->SetMaxLength(iPoint, bufDRecv[buf_offset]); break; + case MPI_QUANTITIES::WALL_DISTANCE: + nodes->SetWall_Distance(iPoint, bufDRecv[buf_offset]); + nodes->SetRoughnessHeight(iPoint, bufDRecv[buf_offset + 1]); + break; case MPI_QUANTITIES::NEIGHBORS: nodes->SetnNeighbor(iPoint, bufSRecv[buf_offset]); break; @@ -2741,6 +2753,16 @@ void CGeometry::UpdateGeometry(CGeometry** geometry_container, CConfig* config) geometry_container[iMesh]->SetControlVolume(geometry_container[iMesh - 1], UPDATE); geometry_container[iMesh]->SetBoundControlVolume(geometry_container[iMesh - 1], config, UPDATE); geometry_container[iMesh]->SetCoord(geometry_container[iMesh - 1]); + + /*--- SetCoord centred a halo agglomerate on the partial child list this rank holds. Take + the owner's coordinate, otherwise coarse stencils depend on the partitioning. Deformation + runs this inside a parallel region, so only one thread may reach the exchange. ---*/ + + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { + geometry_container[iMesh]->InitiateComms(geometry_container[iMesh], config, MPI_QUANTITIES::COORDINATES); + geometry_container[iMesh]->CompleteComms(geometry_container[iMesh], config, MPI_QUANTITIES::COORDINATES); + } + END_SU2_OMP_SAFE_GLOBAL_ACCESS } /*--- Compute the global surface areas for all markers. ---*/ @@ -4538,6 +4560,47 @@ su2double NearestNeighborDistance(CGeometry* geometry, const CConfig* config, co const su2double Vol = geometry->nodes->GetVolume(iPoint) + geometry->nodes->GetPeriodicVolume(iPoint); return 2 * Vol / GeometryToolbox::Norm(3, Normal); } + +/*--- Volume-averages the wall distance and roughness of the children onto a coarse grid, then sets the + * nearest-neighbor distance of its viscous wall vertices. ---*/ +void RestrictWallDistance(const CGeometry* geo_fine, CGeometry* geo_coarse, const CConfig* config) { + SU2_OMP_FOR_STAT(roundUpDiv(geo_coarse->GetnPointDomain(), omp_get_num_threads())) + for (auto iPoint = 0ul; iPoint < geo_coarse->GetnPointDomain(); iPoint++) { + su2double dist = 0.0, roughness = 0.0, vol = 0.0; + for (auto iChild = 0u; iChild < geo_coarse->nodes->GetnChildren_CV(iPoint); iChild++) { + const auto jPoint = geo_coarse->nodes->GetChildren_CV(iPoint, iChild); + const su2double volChild = geo_fine->nodes->GetVolume(jPoint); + dist += geo_fine->nodes->GetWall_Distance(jPoint) * volChild; + roughness += geo_fine->nodes->GetRoughnessHeight(jPoint) * volChild; + vol += volChild; + } + geo_coarse->nodes->SetWall_Distance(iPoint, (vol > 0.0) ? dist / vol : 0.0); + geo_coarse->nodes->SetRoughnessHeight(iPoint, (vol > 0.0) ? roughness / vol : 0.0); + } + END_SU2_OMP_FOR + + /*--- A halo agglomerate only holds the children on this rank, so take the owner's values. ---*/ + + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { + geo_coarse->InitiateComms(geo_coarse, config, MPI_QUANTITIES::WALL_DISTANCE); + geo_coarse->CompleteComms(geo_coarse, config, MPI_QUANTITIES::WALL_DISTANCE); + } + END_SU2_OMP_SAFE_GLOBAL_ACCESS + + for (unsigned short iMarker = 0; iMarker < config->GetnMarker_All(); ++iMarker) { + const auto viscous = config->GetViscous_Wall(iMarker); + + SU2_OMP_FOR_STAT(OMP_MIN_SIZE) + for (auto iVertex = 0u; iVertex < geo_coarse->nVertex[iMarker]; iVertex++) { + const auto iPoint = geo_coarse->vertex[iMarker][iVertex]->GetNode(); + const su2double dist = (viscous && geo_coarse->nodes->GetDomain(iPoint)) + ? NearestNeighborDistance(geo_coarse, config, iPoint) + : geo_coarse->nodes->GetWall_Distance(iPoint); + geo_coarse->vertex[iMarker][iVertex]->SetNearestNeighborDistance(dist); + } + END_SU2_OMP_FOR + } +} } // namespace void CGeometry::ComputeWallDistance(const CConfig* const* config_container, CGeometry**** geometry_container, @@ -4638,6 +4701,13 @@ void CGeometry::ComputeWallDistance(const CConfig* const* config_container, CGeo } END_SU2_OMP_FOR } + + /*--- The Full-MG startup solves the turbulence model on coarse grids. ---*/ + + for (unsigned short iMesh = 1; iMesh <= config->GetnMGLevels(); iMesh++) { + RestrictWallDistance(geometry_container[iZone][iInst][iMesh - 1], geometry_container[iZone][iInst][iMesh], + config); + } } } } diff --git a/SU2_CFD/include/integration/CMultiGridIntegration.hpp b/SU2_CFD/include/integration/CMultiGridIntegration.hpp index 8433f2cb25d3..155f98523d38 100644 --- a/SU2_CFD/include/integration/CMultiGridIntegration.hpp +++ b/SU2_CFD/include/integration/CMultiGridIntegration.hpp @@ -333,7 +333,8 @@ class CMultiGridIntegration final : public CIntegration { passivedouble lastRMS[2], char& exitReason, passivedouble& worstStepRatio, unsigned short& worstStep); - static constexpr int MAX_MG_LEVELS = 10; + /*--- CConfig rejects a larger MGLEVEL, so the per-level arrays below always fit. ---*/ + static constexpr int MAX_MG_LEVELS = MAX_MGLEVELS; /*--- Bounds the fixed-size stack buffers in the restriction and prolongation kernels, * independently of the CSysMatrix limit of the same name. ---*/ diff --git a/SU2_CFD/include/variables/CAdjEulerVariable.hpp b/SU2_CFD/include/variables/CAdjEulerVariable.hpp index 1faf911816aa..cb039f291358 100644 --- a/SU2_CFD/include/variables/CAdjEulerVariable.hpp +++ b/SU2_CFD/include/variables/CAdjEulerVariable.hpp @@ -102,6 +102,11 @@ class CAdjEulerVariable : public CVariable { Solution_Old(iPoint,iDim+1) = val_velocity[iDim]*Solution(iPoint,0); } + /*! + * \brief Index of the adjoint momentum in the solution vector. + */ + inline short GetVelocityIndex() const final { return 1; } + /*! * \brief Set the momentum part of the truncation error to zero. * \param[in] iPoint - Point index. diff --git a/SU2_CFD/include/variables/CEulerVariable.hpp b/SU2_CFD/include/variables/CEulerVariable.hpp index abd63a3afd27..ebd817fa1339 100644 --- a/SU2_CFD/include/variables/CEulerVariable.hpp +++ b/SU2_CFD/include/variables/CEulerVariable.hpp @@ -298,6 +298,11 @@ class CEulerVariable : public CFlowVariable { Solution_Old(iPoint,iDim+1) = val_velocity[iDim]*Solution(iPoint,0); } + /*! + * \brief Index of the momentum in the conservative solution vector. + */ + inline short GetVelocityIndex() const final { return 1; } + /*! * \brief Set the momentum part of the truncation error to zero. * \param[in] iPoint - Point index. diff --git a/SU2_CFD/include/variables/CIncEulerVariable.hpp b/SU2_CFD/include/variables/CIncEulerVariable.hpp index aaa6c437b665..7fc1860a826a 100644 --- a/SU2_CFD/include/variables/CIncEulerVariable.hpp +++ b/SU2_CFD/include/variables/CIncEulerVariable.hpp @@ -213,6 +213,11 @@ class CIncEulerVariable : public CFlowVariable { Solution_Old(iPoint,iDim+1) = val_velocity[iDim]; } + /*! + * \brief Index of the velocity in the solution vector. + */ + inline short GetVelocityIndex() const final { return 1; } + /*! * \brief Set the momentum part of the truncation error to zero. * \param[in] iPoint - Point index. diff --git a/SU2_CFD/include/variables/CNEMOEulerVariable.hpp b/SU2_CFD/include/variables/CNEMOEulerVariable.hpp index e0d4199144c4..37229a595945 100644 --- a/SU2_CFD/include/variables/CNEMOEulerVariable.hpp +++ b/SU2_CFD/include/variables/CNEMOEulerVariable.hpp @@ -298,6 +298,12 @@ class CNEMOEulerVariable : public CFlowVariable { } } + /*! + * \brief Index of the momentum in the conservative solution vector, which the primitive + * index Velocity() does not give. + */ + inline short GetVelocityIndex() const final { return static_cast(nSpecies); } + /*! * \brief A virtual member. * \return Value of the vibrational-electronic temperature. diff --git a/SU2_CFD/include/variables/CVariable.hpp b/SU2_CFD/include/variables/CVariable.hpp index 739a1af75fa5..13224df85125 100644 --- a/SU2_CFD/include/variables/CVariable.hpp +++ b/SU2_CFD/include/variables/CVariable.hpp @@ -1607,6 +1607,12 @@ class CVariable { */ inline virtual void SetVelocity_Old(unsigned long iPoint, const su2double *val_velocity) {} + /*! + * \brief Index of the first velocity or momentum component in the solution vector. + * \return The index, or -1 when the solution carries no velocity. + */ + inline virtual short GetVelocityIndex() const { return -1; } + /*! * \brief A virtual member. * \param[in] laminarViscosity diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index 8c26640139d4..b6908a389b92 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -64,7 +64,10 @@ static bool invertLeastSquaresMatrix(unsigned short nDim, const su2double A[3][3 if (trace <= 0.0) return false; const su2double scale = trace / su2double(nDim); - constexpr passivedouble REL_TOL = 1e-12; + + /*--- det/scale^nDim is the conditioning of the fit. At 1e-8 the inverse still carries about + * nine digits; below it the gradient is noise and the control volume stays constant. ---*/ + constexpr passivedouble REL_TOL = 1e-8; if (nDim == 2) { const su2double det = A[0][0]*A[1][1] - A[0][1]*A[0][1]; @@ -148,14 +151,15 @@ void CMultiGridIntegration::MonitorFullMG_Startup(const vector 0.0 && !mg_startup_conv_prev.empty()) { + const passivedouble band = fabs(log10(stall_tol)); bool stalled = true; for (auto iField = 0ul; iField < nFields; iField++) - stalled = stalled && (convFields[iField].second - mg_startup_conv_prev[iField] >= log10(stall_tol)); + stalled = stalled && (fabs(convFields[iField].second - mg_startup_conv_prev[iField]) <= band); if (stalled) mg_startup_stall_count++; @@ -498,6 +502,15 @@ void CMultiGridIntegration::MultiGrid_Iteration(CGeometry ****geometry, geometry[iZone][iInst][FinestMesh], config[iZone], true); } + /*--- The scalar solvers run on the active startup level and need its vorticity and strain rate. ---*/ + + if (fmg_warmup) { + solver_container[iZone][iInst][FinestMesh][Solver_Position]->Preprocessing(geometry[iZone][iInst][FinestMesh], + solver_container[iZone][iInst][FinestMesh], + config[iZone], FinestMesh, NO_RK_ITER, + RunTime_EqSystem, true); + } + /*--- Computes primitive variables and gradients in the finest mesh (useful for the next solver (turbulence) and output ---*/ solver_container[iZone][iInst][MESH_0][Solver_Position]->Preprocessing(geometry[iZone][iInst][MESH_0], @@ -1056,6 +1069,10 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe const auto nPointDomain = geo_coarse->GetnPointDomain(); auto* nodes = sol_coarse->GetNodes(); + /*--- Every thread of this rank takes this branch together, and the loops below would all be + * empty anyway. It also keeps the sizing test off a container that was never resized. ---*/ + if (nPointDomain == 0) return; + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { auto& grad = prolongGradient[iMesh]; @@ -1109,22 +1126,27 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe } END_SU2_OMP_FOR - /*--- Control volumes on a wall or symmetry plane keep the constant operator, their - * correction being constrained by the boundary condition. ---*/ + /*--- The children of a wall agglomerate are all wall nodes, so their velocity correction is + * the constrained one the caller already imposed and only its gradient has to go. The + * remaining variables carry no wall condition and reconstruct along the surface. ---*/ - for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); iMarker++) { + const short iVel = nodes->GetVelocityIndex(); + + if (iVel >= 0) { + for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); iMarker++) { - const auto kindBC = config->GetMarker_All_KindBC(iMarker); - if (!config->GetViscous_Wall(iMarker) && (kindBC != EULER_WALL) && (kindBC != SYMMETRY_PLANE)) continue; + const auto kindBC = config->GetMarker_All_KindBC(iMarker); + if (!config->GetViscous_Wall(iMarker) && (kindBC != EULER_WALL) && (kindBC != SYMMETRY_PLANE)) continue; - SU2_OMP_FOR_STAT(32) - for (auto iVertex = 0ul; iVertex < geo_coarse->nVertex[iMarker]; iVertex++) { - const auto iPoint = geo_coarse->vertex[iMarker][iVertex]->GetNode(); - if (iPoint >= nPointDomain) continue; - for (auto iVar = 0u; iVar < nVar; iVar++) - for (auto iDim = 0u; iDim < nDim; iDim++) gradient(iPoint, iVar, iDim) = 0.0; + SU2_OMP_FOR_STAT(32) + for (auto iVertex = 0ul; iVertex < geo_coarse->nVertex[iMarker]; iVertex++) { + const auto iPoint = geo_coarse->vertex[iMarker][iVertex]->GetNode(); + if (iPoint >= nPointDomain) continue; + for (auto iVar = iVel; iVar < min(iVel + nDim, nVar); iVar++) + for (auto iDim = 0u; iDim < nDim; iDim++) gradient(iPoint, iVar, iDim) = 0.0; + } + END_SU2_OMP_FOR } - END_SU2_OMP_FOR } /*--- Barth-Jespersen limiter over the children. One factor per variable scales the whole diff --git a/SU2_CFD/src/integration/CSingleGridIntegration.cpp b/SU2_CFD/src/integration/CSingleGridIntegration.cpp index 29c71b2ed360..3fb340cda924 100644 --- a/SU2_CFD/src/integration/CSingleGridIntegration.cpp +++ b/SU2_CFD/src/integration/CSingleGridIntegration.cpp @@ -87,6 +87,13 @@ void CSingleGridIntegration::SingleGrid_Iteration(CGeometry ****geometry, CSolve Time_Integration(geometry_fine, solvers_fine, config[iZone], NO_RK_ITER, RunTime_EqSystem); + /*--- Coarse-level residuals are per-rank sums of squares unless reduced, which the smoothing + * early exit already does. ---*/ + + if ((FinestMesh != MESH_0) && !config[iZone]->GetMGOptions().MG_Smooth_EarlyExit) { + solvers_fine[Solver_Position]->SetResidual_RMS(geometry_fine, config[iZone], true); + } + /*--- Postprocessing ---*/ solvers_fine[Solver_Position]->Postprocessing(geometry_fine, solvers_fine, config[iZone], FinestMesh); diff --git a/config_template.cfg b/config_template.cfg index a9d211119c79..d26c2a90453b 100644 --- a/config_template.cfg +++ b/config_template.cfg @@ -1822,8 +1822,9 @@ MG_STARTUP_ITER= 100 MG_STARTUP_CONVERGENCE= -2 % % Full-MG promotion on stagnation: if the active level's residual ratio between -% successive iterations exceeds this for MG_STARTUP_STAGNATION_ITER consecutive -% iterations, promote to the next finer level early. 0 disables (default 0.99). +% successive iterations stays between this value and its inverse for +% MG_STARTUP_STAGNATION_ITER consecutive iterations, promote to the next finer level +% early. A growing residual does not count as stagnation. 0 disables (default 0.99). MG_STARTUP_STAGNATION= 0.99 % % Consecutive stalled iterations required before Full-MG promotes on stagnation. From 05511b3146620c4b3162663eecd38788b97dd56a Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sat, 26 Sep 2026 14:14:12 +0200 Subject: [PATCH 04/42] codi error --- Common/src/geometry/CGeometry.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Common/src/geometry/CGeometry.cpp b/Common/src/geometry/CGeometry.cpp index 736a12057162..a9adc2cd8198 100644 --- a/Common/src/geometry/CGeometry.cpp +++ b/Common/src/geometry/CGeometry.cpp @@ -4574,8 +4574,8 @@ void RestrictWallDistance(const CGeometry* geo_fine, CGeometry* geo_coarse, cons roughness += geo_fine->nodes->GetRoughnessHeight(jPoint) * volChild; vol += volChild; } - geo_coarse->nodes->SetWall_Distance(iPoint, (vol > 0.0) ? dist / vol : 0.0); - geo_coarse->nodes->SetRoughnessHeight(iPoint, (vol > 0.0) ? roughness / vol : 0.0); + geo_coarse->nodes->SetWall_Distance(iPoint, (vol > 0.0) ? su2double(dist / vol) : su2double(0.0)); + geo_coarse->nodes->SetRoughnessHeight(iPoint, (vol > 0.0) ? su2double(roughness / vol) : su2double(0.0)); } END_SU2_OMP_FOR From d9e044d81b3d2e1001d96603476a94d763326a03 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sat, 26 Sep 2026 16:47:32 +0200 Subject: [PATCH 05/42] codi error --- Common/src/geometry/CGeometry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/src/geometry/CGeometry.cpp b/Common/src/geometry/CGeometry.cpp index a9adc2cd8198..9a6eaef0661f 100644 --- a/Common/src/geometry/CGeometry.cpp +++ b/Common/src/geometry/CGeometry.cpp @@ -4590,7 +4590,7 @@ void RestrictWallDistance(const CGeometry* geo_fine, CGeometry* geo_coarse, cons for (unsigned short iMarker = 0; iMarker < config->GetnMarker_All(); ++iMarker) { const auto viscous = config->GetViscous_Wall(iMarker); - SU2_OMP_FOR_STAT(OMP_MIN_SIZE) + SU2_OMP_FOR_STAT(roundUpDiv(geo_coarse->nVertex[iMarker], omp_get_num_threads())) for (auto iVertex = 0u; iVertex < geo_coarse->nVertex[iMarker]; iVertex++) { const auto iPoint = geo_coarse->vertex[iMarker][iVertex]->GetNode(); const su2double dist = (viscous && geo_coarse->nodes->GetDomain(iPoint)) From 9f1885be2411cffa7956998e425e7659bf4e5886 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sun, 27 Sep 2026 11:31:19 +0200 Subject: [PATCH 06/42] tests with adaptive cfl, and fix to viscous flux for multigrid --- Common/include/CConfig.hpp | 12 ++ Common/include/geometry/CPhysicalGeometry.hpp | 9 ++ Common/src/CConfig.cpp | 9 ++ Common/src/geometry/CPhysicalGeometry.cpp | 140 +++++++++++++++++- .../flow/diffusion/viscous_fluxes.hpp | 17 ++- SU2_CFD/include/solvers/CSolver.hpp | 13 ++ SU2_CFD/src/drivers/CDriver.cpp | 6 +- SU2_CFD/src/solvers/CSolver.cpp | 86 +++++++++++ config_template.cfg | 14 ++ 9 files changed, 294 insertions(+), 12 deletions(-) diff --git a/Common/include/CConfig.hpp b/Common/include/CConfig.hpp index bf5bbd0684cb..2475d7c3a9e0 100644 --- a/Common/include/CConfig.hpp +++ b/Common/include/CConfig.hpp @@ -841,6 +841,7 @@ class CConfig { unsigned short nCFL_AdaptParam; /*!< \brief Number of CFL parameters provided in config. */ unsigned long outlierMitigationParam[4]; /*!< \brief Parameters of outlier mitigation strategy. */ bool CFL_Adapt; /*!< \brief Use adaptive CFL number. */ + bool CFL_AdaptResidual; /*!< \brief Adapt the CFL on the nonlinear residual trend instead of the linear solve. */ bool HB_Precondition; /*!< \brief Flag to turn on harmonic balance source term preconditioning */ su2double RefArea, /*!< \brief Reference area for coefficient computation. */ RefElemLength, /*!< \brief Reference element length for computing the slope limiting epsilon. */ @@ -1115,6 +1116,7 @@ class CConfig { su2double ParMETIS_tolerance; /*!< \brief Load balancing tolerance for ParMETIS. */ long ParMETIS_pointWgt; /*!< \brief Load balancing weight given to points. */ long ParMETIS_edgeWgt; /*!< \brief Load balancing weight given to edges. */ + bool ParMETIS_anisotropyWgt; /*!< \brief Weight graph edges by cell anisotropy and partition with coordinates. */ unsigned short DirectDiff; /*!< \brief Direct Differentation mode. */ bool DiscreteAdjoint, /*!< \brief AD-based discrete adjoint mode. */ DiscreteAdjointDebug; /*!< \brief Discrete adjoint debug mode using tags. */ @@ -1750,6 +1752,11 @@ class CConfig { */ bool GetCFL_Adapt(void) const { return CFL_Adapt; } + /*! + * \brief Whether the adaptive CFL follows the nonlinear residual trend instead of the linear solve. + */ + bool GetCFL_AdaptResidual(void) const { return CFL_AdaptResidual; } + /*! * \brief Get the outlier mitigation parameters. */ @@ -10238,6 +10245,11 @@ class CConfig { */ long GetParMETIS_EdgeWeight() const { return ParMETIS_edgeWgt; } + /*! + * \brief Whether ParMETIS weights graph edges by cell anisotropy and partitions with coordinates. + */ + bool GetParMETIS_AnisotropyWeight() const { return ParMETIS_anisotropyWgt; } + /*! * \brief Find the marker index (if any) that is part of a given interface pair. * \param[in] iInterface - Number of the interface pair being tested, starting at 0. diff --git a/Common/include/geometry/CPhysicalGeometry.hpp b/Common/include/geometry/CPhysicalGeometry.hpp index 52d8ea6da08e..3f2a55684829 100644 --- a/Common/include/geometry/CPhysicalGeometry.hpp +++ b/Common/include/geometry/CPhysicalGeometry.hpp @@ -337,6 +337,15 @@ class CPhysicalGeometry final : public CGeometry { */ void PrepareAdjacency(const CConfig* config); +#if defined(HAVE_MPI) && defined(HAVE_PARMETIS) + /*! + * \brief ParMETIS edge weights that make cutting across the short edges of anisotropic cells expensive. + * \param[in] maxWeight - Cap on the weight of any edge. + * \return One weight per entry of the adjacency array. + */ + vector ComputeAnisotropyEdgeWeights(long maxWeight) const; +#endif + /*! * \brief Find repeated nodes between two elements to identify the common face. * \param[in] first_elem - Identification of the first element. diff --git a/Common/src/CConfig.cpp b/Common/src/CConfig.cpp index 39d9e23b8f18..6857123503b6 100644 --- a/Common/src/CConfig.cpp +++ b/Common/src/CConfig.cpp @@ -1905,6 +1905,8 @@ void CConfig::SetConfig_Options() { addULongArrayOption("OUTLIER_MITIGATION_PARAM", 4, true, outlierMitigationParam); /* DESCRIPTION: Activate The adaptive CFL number. */ addBoolOption("CFL_ADAPT", CFL_Adapt, false); + /* DESCRIPTION: Adapt the CFL on the finest-grid nonlinear residuals instead of the linear solve, with a cut on divergence. */ + addBoolOption("CFL_ADAPT_RESIDUAL", CFL_AdaptResidual, false); /* !\brief CFL_ADAPT_PARAM * DESCRIPTION: Parameters of the adaptive CFL number (factor down, factor up, CFL limit (min and max)[, acceptable linear residual][, starting iteration]). * Parameters in square brackets are optional, parameter "starting iteration" only valid with parameter "acceptable linear residual". @@ -3093,6 +3095,9 @@ void CConfig::SetConfig_Options() { /* DESCRIPTION: ParMETIS load balancing weight for edges (equiv. to neighbors) */ addLongOption("PARMETIS_EDGE_WEIGHT", ParMETIS_edgeWgt, 1); + /* DESCRIPTION: Weight ParMETIS graph edges by cell anisotropy and partition with coordinates */ + addBoolOption("PARMETIS_ANISOTROPY_WEIGHT", ParMETIS_anisotropyWgt, false); + /*--- options that are used in the Hybrid RANS/LES Simulations ---*/ /*!\par CONFIG_CATEGORY:Hybrid_RANSLES Options\ingroup Config*/ @@ -5838,6 +5843,10 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i /* Protect against using CFL adaption for non-flow or certain unsteady flow problems. */ + if (CFL_AdaptResidual && OptionIsSet("OUTLIER_MITIGATION_PARAM")) { + SU2_MPI::Error("CFL_ADAPT_RESIDUAL cannot be combined with OUTLIER_MITIGATION_PARAM.", CURRENT_FUNCTION); + } + if (CFL_Adapt && !GetFluidProblem()) { SU2_MPI::Error(string("CFL adaption only available for finite-volume fluid solvers.\n") + string("Please select CFL_ADAPT = NO."), diff --git a/Common/src/geometry/CPhysicalGeometry.cpp b/Common/src/geometry/CPhysicalGeometry.cpp index 6928c2d922b5..65b013b5421a 100644 --- a/Common/src/geometry/CPhysicalGeometry.cpp +++ b/Common/src/geometry/CPhysicalGeometry.cpp @@ -7361,6 +7361,113 @@ void CPhysicalGeometry::SetBoundTecPlot(char mesh_filename[MAX_STRING_SIZE], boo Tecplot_File.close(); } +#if defined(HAVE_MPI) && defined(HAVE_PARMETIS) +vector CPhysicalGeometry::ComputeAnisotropyEdgeWeights(long maxWeight) const { + CLinearPartitioner pointPartitioner(Global_nPointDomain, 0); + const unsigned long firstIndex = pointPartitioner.GetFirstIndexOnRank(rank); + const auto isLocal = [&](unsigned long iGlobal) { + return (iGlobal >= firstIndex) && (iGlobal - firstIndex < nPoint); + }; + + /*--- Request the coordinates of element nodes that other ranks hold. ---*/ + + vector> request(size); + for (auto iElem = 0ul; iElem < nElem; iElem++) { + for (auto iNode = 0u; iNode < elem[iElem]->GetnNodes(); iNode++) { + const auto iGlobal = elem[iElem]->GetNode(iNode); + if (!isLocal(iGlobal)) request[pointPartitioner.GetRankContainingIndex(iGlobal)].push_back(iGlobal); + } + } + + vector nSend(size), nRecv(size), sendDisp(size + 1, 0), recvDisp(size + 1, 0); + for (int iRank = 0; iRank < size; iRank++) { + auto& list = request[iRank]; + sort(list.begin(), list.end()); + list.erase(unique(list.begin(), list.end()), list.end()); + nSend[iRank] = static_cast(list.size()); + } + SU2_MPI::Alltoall(nSend.data(), 1, MPI_INT, nRecv.data(), 1, MPI_INT, SU2_MPI::GetComm()); + + for (int iRank = 0; iRank < size; iRank++) { + sendDisp[iRank + 1] = sendDisp[iRank] + nSend[iRank]; + recvDisp[iRank + 1] = recvDisp[iRank] + nRecv[iRank]; + } + + vector sendIndex, recvIndex(recvDisp[size]); + sendIndex.reserve(sendDisp[size]); + for (const auto& list : request) sendIndex.insert(sendIndex.end(), list.begin(), list.end()); + + SU2_MPI::Alltoallv(sendIndex.data(), nSend.data(), sendDisp.data(), MPI_UNSIGNED_LONG, recvIndex.data(), + nRecv.data(), recvDisp.data(), MPI_UNSIGNED_LONG, SU2_MPI::GetComm()); + + + vector replyCoord(recvIndex.size() * nDim), remoteCoord(sendIndex.size() * nDim); + for (auto i = 0ul; i < recvIndex.size(); i++) + for (auto iDim = 0u; iDim < nDim; iDim++) + replyCoord[i * nDim + iDim] = SU2_TYPE::GetValue(nodes->GetCoord(recvIndex[i] - firstIndex, iDim)); + + for (int iRank = 0; iRank < size; iRank++) { + nSend[iRank] *= nDim; + nRecv[iRank] *= nDim; + sendDisp[iRank] *= nDim; + recvDisp[iRank] *= nDim; + } + SU2_MPI::Alltoallv(replyCoord.data(), nRecv.data(), recvDisp.data(), MPI_DOUBLE, remoteCoord.data(), nSend.data(), + sendDisp.data(), MPI_DOUBLE, SU2_MPI::GetComm()); + + unordered_map remoteSlot; + for (auto i = 0ul; i < sendIndex.size(); i++) remoteSlot[sendIndex[i]] = i; + + auto getCoord = [&](unsigned long iGlobal, unsigned short iDim) -> passivedouble { + if (isLocal(iGlobal)) return SU2_TYPE::GetValue(nodes->GetCoord(iGlobal - firstIndex, iDim)); + return remoteCoord[remoteSlot.at(iGlobal) * nDim + iDim]; + }; + + /*--- Weight is the longest node distance of the element over the edge length, maximized over elements. ---*/ + + vector weight(adjacency.size(), 1); + + for (auto iElem = 0ul; iElem < nElem; iElem++) { + const auto nNodes = elem[iElem]->GetnNodes(); + passivedouble coord[N_POINTS_HEXAHEDRON][MAXNDIM] = {}; + for (auto iNode = 0u; iNode < nNodes; iNode++) + for (auto iDim = 0u; iDim < nDim; iDim++) coord[iNode][iDim] = getCoord(elem[iElem]->GetNode(iNode), iDim); + + auto distance2 = [&](unsigned short a, unsigned short b) { + passivedouble d2 = 0.0; + for (auto iDim = 0u; iDim < nDim; iDim++) d2 += pow(coord[a][iDim] - coord[b][iDim], 2); + return d2; + }; + + passivedouble maxDist2 = 0.0; + for (auto a = 0u; a < nNodes; a++) + for (auto b = a + 1; b < nNodes; b++) maxDist2 = max(maxDist2, distance2(a, b)); + + for (auto a = 0u; a < nNodes; a++) { + const auto iGlobal = elem[iElem]->GetNode(a); + if (!isLocal(iGlobal)) continue; + const auto iLocal = iGlobal - firstIndex; + const auto begin = adjacency.begin() + xadj[iLocal]; + const auto end = adjacency.begin() + xadj[iLocal + 1]; + + for (auto b = 0u; b < nNodes; b++) { + const auto d2 = distance2(a, b); + if ((b == a) || (d2 <= 0.0)) continue; + + const auto jGlobal = static_cast(elem[iElem]->GetNode(b)); + const auto it = lower_bound(begin, end, jGlobal); + if ((it == end) || (*it != jGlobal)) continue; + + const auto ratio = static_cast(sqrt(maxDist2 / d2)); + auto& w = weight[it - adjacency.begin()]; + w = max(w, min(maxWeight, max(1, ratio))); + } + } + } + return weight; +} +#endif + void CPhysicalGeometry::SetColorGrid_Parallel(const CConfig* config) { /*--- We need to have parallel support with MPI and have the ParMETIS library compiled and linked for parallel graph partitioning. ---*/ @@ -7412,6 +7519,22 @@ void CPhysicalGeometry::SetColorGrid_Parallel(const CConfig* config) { vwgt[iPoint] = wp + we * (xadj[iPoint + 1] - xadj[iPoint]); } + /*--- Keep partition boundaries off the short edges of anisotropic cells, with the coordinates + * seeding the partition. The cap keeps the total edge weight within the range of idx_t. ---*/ + + const bool anisotropic = config->GetParMETIS_AnisotropyWeight(); + vector adjwgt; + vector xyz; + if (anisotropic) { + constexpr long maxWeight = (sizeof(idx_t) >= 8) ? 1000000 : 1000; + adjwgt = ComputeAnisotropyEdgeWeights(maxWeight); + wgtflag = 3; + xyz.resize(nPoint * nDim); + for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) + for (unsigned short iDim = 0; iDim < nDim; iDim++) + xyz[iPoint * nDim + iDim] = SU2_TYPE::GetValue(nodes->GetCoord(iPoint, iDim)); + } + /*--- Create some structures that ParMETIS needs to output the partitioning. ---*/ idx_t edgecut; @@ -7420,12 +7543,21 @@ void CPhysicalGeometry::SetColorGrid_Parallel(const CConfig* config) { /*--- Calling ParMETIS ---*/ if (rank == MASTER_NODE) cout << "Calling ParMETIS..."; - auto err = - ParMETIS_V3_PartKway(vtxdist.data(), xadj.data(), adjacency.data(), vwgt.data(), nullptr, &wgtflag, &numflag, - &ncon, &nparts, tpwgts.data(), &ubvec, options, &edgecut, part.data(), &comm); + int err; + if (anisotropic) { + idx_t ndims = nDim; + err = ParMETIS_V3_PartGeomKway(vtxdist.data(), xadj.data(), adjacency.data(), vwgt.data(), adjwgt.data(), + &wgtflag, &numflag, &ndims, xyz.data(), &ncon, &nparts, tpwgts.data(), &ubvec, + options, &edgecut, part.data(), &comm); + } else { + err = ParMETIS_V3_PartKway(vtxdist.data(), xadj.data(), adjacency.data(), vwgt.data(), nullptr, &wgtflag, + &numflag, &ncon, &nparts, tpwgts.data(), &ubvec, options, &edgecut, part.data(), + &comm); + } if (err != METIS_OK) SU2_MPI::Error("Partitioning failed.", CURRENT_FUNCTION); if (rank == MASTER_NODE) { - cout << " graph partitioning complete (" << edgecut << " edge cuts)." << endl; + cout << " graph partitioning complete (" << edgecut << (anisotropic ? " weighted" : "") << " edge cuts)." + << endl; } /*--- Store the results of the partitioning (note that this is local diff --git a/SU2_CFD/include/numerics_simd/flow/diffusion/viscous_fluxes.hpp b/SU2_CFD/include/numerics_simd/flow/diffusion/viscous_fluxes.hpp index 1a8745b10bc2..ae544de1b0c3 100644 --- a/SU2_CFD/include/numerics_simd/flow/diffusion/viscous_fluxes.hpp +++ b/SU2_CFD/include/numerics_simd/flow/diffusion/viscous_fluxes.hpp @@ -76,7 +76,7 @@ class CCompressibleViscousFluxBase : public CNumericsSIMD { const su2double gamma; const su2double gasConst; const su2double prandtlTurb; - const bool correct; + const bool effDistJac; /*!< EXPERIMENT: SU2_VISC_JAC_EFFDIST. */ const bool useSA_QCR; const bool wallFun; const bool uq; @@ -91,12 +91,12 @@ class CCompressibleViscousFluxBase : public CNumericsSIMD { * \brief Constructor, initialize constants and booleans. */ template - CCompressibleViscousFluxBase(const CConfig& config, int iMesh, + CCompressibleViscousFluxBase(const CConfig& config, int, const CVariable* turbVars_, Ts&...) : gamma(config.GetGamma()), gasConst(config.GetGas_ConstantND()), prandtlTurb(config.GetPrandtl_Turb()), - correct(iMesh == MESH_0), + effDistJac(getenv("SU2_VISC_JAC_EFFDIST") != nullptr), useSA_QCR(config.GetSAParsedOptions().qcr2000), wallFun(config.GetWall_Functions()), uq(config.GetSSTParsedOptions().uq), @@ -142,10 +142,10 @@ class CCompressibleViscousFluxBase : public CNumericsSIMD { Double mask = dist2_ij < EPS*EPS; dist2_ij += mask / (EPS*EPS); - /*--- Compute the corrected mean gradient. ---*/ + /*--- Compute the corrected mean gradient on all levels. ---*/ auto avgGrad = averageGradient(iPoint, jPoint, gradient); - if(correct) correctGradient(V, vector_ij, dist2_ij, avgGrad); + correctGradient(V, vector_ij, dist2_ij, avgGrad); /*--- Stress and heat flux tensors. ---*/ @@ -180,6 +180,13 @@ class CCompressibleViscousFluxBase : public CNumericsSIMD { /*--- Flux Jacobians. ---*/ Double dist_ij = sqrt(dist2_ij); + + /*--- EXPERIMENT: SU2_VISC_JAC_EFFDIST linearizes the corrected gradient, whose normal part depends + * on the neighbour difference over |d|^2/(d.n) rather than over |d|. ---*/ + if (effDistJac) { + const Double projDist = abs(dot(vector_ij, unitNormal)); + dist_ij = dist2_ij / fmax(projDist, 0.1 * dist_ij); + } auto dtau = stressTensorJacobian(avgV, unitNormal, dist_ij); /*--- Energy flux Jacobian. ---*/ diff --git a/SU2_CFD/include/solvers/CSolver.hpp b/SU2_CFD/include/solvers/CSolver.hpp index 7a7b6c726021..acc465282064 100644 --- a/SU2_CFD/include/solvers/CSolver.hpp +++ b/SU2_CFD/include/solvers/CSolver.hpp @@ -81,6 +81,19 @@ class CSolver { vector NonLinRes_Series; /*!< \brief Vector holding the nonlinear residual indicator series. */ su2double Old_Func, /*!< \brief Old value of the nonlinear residual indicator. */ New_Func; /*!< \brief Current value of the nonlinear residual indicator. */ + /*--- State of CFL_ADAPT_RESIDUAL, a negative ceiling or cap means none is active. ---*/ + vector ResTrend_History; /*!< \brief Recent mean log residuals. */ + vector> ResJump_History; /*!< \brief Recent log residuals of the flow variables. */ + bool ResTrend_Increase = false; /*!< \brief The residual trend allows a larger CFL. */ + bool ResTrend_Reduce = false; /*!< \brief The residual trend requires a smaller CFL. */ + passivedouble ResTrend_Best = 1e30; /*!< \brief Lowest mean log residual so far. */ + unsigned long ResTrend_LastBest = 0; /*!< \brief Iteration of that minimum. */ + bool CFL_Cut = false; /*!< \brief Halve the CFL in this update. */ + passivedouble CFL_Ceiling = -1.0; /*!< \brief Temporary ceiling after a cut. */ + passivedouble CFL_Cap = -1.0; /*!< \brief Lasting limit learned from repeated events. */ + vector CFL_EventValues; /*!< \brief CFL at each cut. */ + unsigned long CFL_LastEvent = 0; /*!< \brief Iteration of the last cut. */ + unsigned long CFL_LastStagnation = 0; /*!< \brief Iteration of the last stagnation cap. */ unsigned short nVar, /*!< \brief Number of variables of the problem. */ nPrimVar, /*!< \brief Number of primitive variables of the problem. */ nPrimVarGrad, /*!< \brief Number of primitive variables of the problem in the gradient computation. */ diff --git a/SU2_CFD/src/drivers/CDriver.cpp b/SU2_CFD/src/drivers/CDriver.cpp index dbe6458b9aa2..15356402b2d7 100644 --- a/SU2_CFD/src/drivers/CDriver.cpp +++ b/SU2_CFD/src/drivers/CDriver.cpp @@ -1813,7 +1813,7 @@ void CDriver::InitializeNumerics(CConfig *config, CGeometry **geometry, CSolver /*--- Compressible flow Ideal gas ---*/ numerics[MESH_0][FLOW_SOL][visc_term] = new CAvgGrad_Flow(nDim, nVar_Flow, true, config); for (iMGlevel = 1; iMGlevel <= config->GetnMGLevels(); iMGlevel++) - numerics[iMGlevel][FLOW_SOL][visc_term] = new CAvgGrad_Flow(nDim, nVar_Flow, false, config); + numerics[iMGlevel][FLOW_SOL][visc_term] = new CAvgGrad_Flow(nDim, nVar_Flow, true, config); /*--- Definition of the boundary condition method ---*/ for (iMGlevel = 0; iMGlevel <= config->GetnMGLevels(); iMGlevel++) @@ -1824,7 +1824,7 @@ void CDriver::InitializeNumerics(CConfig *config, CGeometry **geometry, CSolver /*--- Compressible flow Real gas ---*/ numerics[MESH_0][FLOW_SOL][visc_term] = new CGeneralAvgGrad_Flow(nDim, nVar_Flow, true, config); for (iMGlevel = 1; iMGlevel <= config->GetnMGLevels(); iMGlevel++) - numerics[iMGlevel][FLOW_SOL][visc_term] = new CGeneralAvgGrad_Flow(nDim, nVar_Flow, false, config); + numerics[iMGlevel][FLOW_SOL][visc_term] = new CGeneralAvgGrad_Flow(nDim, nVar_Flow, true, config); /*--- Definition of the boundary condition method ---*/ for (iMGlevel = 0; iMGlevel <= config->GetnMGLevels(); iMGlevel++) @@ -1836,7 +1836,7 @@ void CDriver::InitializeNumerics(CConfig *config, CGeometry **geometry, CSolver /*--- Incompressible flow, use preconditioning method ---*/ numerics[MESH_0][FLOW_SOL][visc_term] = new CAvgGradInc_Flow(nDim, nVar_Flow, true, config); for (iMGlevel = 1; iMGlevel <= config->GetnMGLevels(); iMGlevel++) - numerics[iMGlevel][FLOW_SOL][visc_term] = new CAvgGradInc_Flow(nDim, nVar_Flow, false, config); + numerics[iMGlevel][FLOW_SOL][visc_term] = new CAvgGradInc_Flow(nDim, nVar_Flow, true, config); /*--- Definition of the boundary condition method ---*/ for (iMGlevel = 0; iMGlevel <= config->GetnMGLevels(); iMGlevel++) diff --git a/SU2_CFD/src/solvers/CSolver.cpp b/SU2_CFD/src/solvers/CSolver.cpp index 270293101081..cfa04cd8b63a 100644 --- a/SU2_CFD/src/solvers/CSolver.cpp +++ b/SU2_CFD/src/solvers/CSolver.cpp @@ -1910,6 +1910,90 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, } } } + + /*--- CFL_ADAPT_RESIDUAL: the finest-grid nonlinear residuals drive the CFL, so the decision does + * not depend on how many ranks split the preconditioner. The finest grid decides for all levels. ---*/ + + if (config->GetCFL_AdaptResidual()) { + constexpr size_t trendWindow = 5, jumpWindow = 3; + constexpr passivedouble growBelow = 0.01, shrinkAbove = 0.03, jumpAbove = 0.75; + constexpr passivedouble linearBrake = 0.5, linearFailure = 0.8; + constexpr unsigned long stagnationIters = 150, quietIters = 20; + + if (iMesh == MESH_0) { + const passivedouble avgCFL = SU2_TYPE::GetValue(Avg_CFL_Local); + + /*--- Short-window trend of the mean log residual. ---*/ + ResTrend_History.push_back(SU2_TYPE::GetValue(New_Func)); + if (ResTrend_History.size() > trendWindow + 1) ResTrend_History.erase(ResTrend_History.begin()); + const bool full = (ResTrend_History.size() > trendWindow); + const passivedouble trend = full ? (ResTrend_History.back() - ResTrend_History.front()) / trendWindow : 0.0; + ResTrend_Increase = full && (trend < growBelow); + ResTrend_Reduce = full && (trend > shrinkAbove); + + /*--- A divergence raises all flow residuals together, a transient usually only one, so the jump + * is the median rise over the flow variables. ---*/ + vector logRes(solverFlow->GetnVar()); + for (auto iVar = 0u; iVar < solverFlow->GetnVar(); iVar++) + logRes[iVar] = log10(SU2_TYPE::GetValue(solverFlow->GetRes_RMS(iVar))); + ResJump_History.push_back(logRes); + if (ResJump_History.size() > jumpWindow + 1) ResJump_History.erase(ResJump_History.begin()); + bool jump = false; + if (ResJump_History.size() > jumpWindow) { + vector rise(logRes.size()); + for (auto iVar = 0u; iVar < logRes.size(); iVar++) rise[iVar] = logRes[iVar] - ResJump_History.front()[iVar]; + sort(rise.begin(), rise.end()); + const auto n = rise.size(); + jump = (0.5 * (rise[(n - 1) / 2] + rise[n / 2]) > jumpAbove); + } + + /*--- Halve the CFL on a jump or a failed linear solve and keep it below a ceiling. A second event + * near the CFL of an earlier one sets a lasting cap below both. ---*/ + CFL_Cut = (jump || (linRes > linearFailure)) && (iter >= CFL_LastEvent + jumpWindow); + if (CFL_Cut) { + for (const auto eventCFL : CFL_EventValues) + if ((avgCFL < 1.5 * eventCFL) && (eventCFL < 1.5 * avgCFL)) { + const passivedouble cap = 0.8 * min(eventCFL, avgCFL); + CFL_Cap = (CFL_Cap > 0.0) ? min(CFL_Cap, cap) : cap; + } + CFL_EventValues.push_back(avgCFL); + CFL_Ceiling = 0.7 * avgCFL; + CFL_LastEvent = iter; + if (rank == MASTER_NODE) + cout << "CFL_ADAPT_RESIDUAL: " << (jump ? "residual jump" : "linear solver failure") << " at iteration " + << iter << ", CFL halved from " << avgCFL << "." << endl; + } + + /*--- Without a new residual minimum for a long time, cap the CFL below its current level. ---*/ + const passivedouble func = SU2_TYPE::GetValue(New_Func); + if (func < ResTrend_Best - 0.01) { + ResTrend_Best = func; + ResTrend_LastBest = iter; + } + if ((iter > ResTrend_LastBest + stagnationIters) && (iter > CFL_LastStagnation + stagnationIters) && + (iter > CFL_LastEvent + 50)) { + CFL_Cap = 0.8 * ((CFL_Cap > 0.0) ? min(CFL_Cap, avgCFL) : avgCFL); + CFL_Ceiling = CFL_Cap; + CFL_LastStagnation = iter; + ResTrend_LastBest = iter; + if (rank == MASTER_NODE) + cout << "CFL_ADAPT_RESIDUAL: no progress by iteration " << iter << ", CFL capped at " << CFL_Cap << "." << endl; + } + + /*--- Lift the ceiling again while the residuals fall, up to the cap. ---*/ + if ((CFL_Ceiling > 0.0) && (iter > max(CFL_LastEvent, CFL_LastStagnation) + quietIters) && ResTrend_Increase) { + CFL_Ceiling *= 1.05; + if (CFL_Cap > 0.0) CFL_Ceiling = min(CFL_Ceiling, CFL_Cap); + else if (CFL_Ceiling > SU2_TYPE::GetValue(CFLMax)) CFL_Ceiling = -1.0; + } + } + + /*--- These replace the linear-residual and oscillation rules above. A poor linear solve holds the + * CFL back gently, a failed one halves it above. ---*/ + canIncrease = ResTrend_Increase && (linRes < linearBrake) && (iter >= startingIter); + reduceCFL = (ResTrend_Reduce || (linRes > linearBrake)) && (iter >= startingIter); + resetCFL = false; + } } /* End safe global access, now all threads update the CFL number. */ END_SU2_OMP_SAFE_GLOBAL_ACCESS @@ -1979,7 +2063,9 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, /* Apply the adjustment to the CFL and store local values. */ + if (CFL_Cut) CFLFactor = 0.5; CFL *= CFLFactor; + if ((CFL_Ceiling > 0.0) && (CFL > CFL_Ceiling)) CFL = max(su2double(CFL_Ceiling), CFLMin); solverFlow->GetNodes()->SetLocalCFL(iPoint, CFL); if ((iMesh == MESH_0) && solverTurb) { solverTurb->GetNodes()->SetLocalCFL(iPoint, CFL * CFLTurbReduction); diff --git a/config_template.cfg b/config_template.cfg index d26c2a90453b..739d79817374 100644 --- a/config_template.cfg +++ b/config_template.cfg @@ -1540,6 +1540,14 @@ CFL_NUMBER= 15.0 % Adaptive CFL number (NO, YES) CFL_ADAPT= NO % +% Adapt the CFL on the finest-grid nonlinear residuals instead of on the linear solver, which +% makes it independent of the number of MPI ranks. The CFL grows while the residuals fall and +% shrinks when they rise. A sudden residual jump or a failed linear solve halves it and keeps it +% below a ceiling; repeated events, or no progress for 150 iterations, cap it lasting below the +% level where that happened. Uses factor up/down and the CFL limits of CFL_ADAPT_PARAM. +% Cannot be combined with OUTLIER_MITIGATION_PARAM (NO, YES) (default NO) +CFL_ADAPT_RESIDUAL= NO +% % Parameters of the adaptive CFL number (factor-down, factor-up, CFL min value, % CFL max value, acceptable linear solver convergence, starting iteration) % After the starting iteration has passed, local CFL increases by factor-up until max if the solution rate of @@ -2525,6 +2533,12 @@ PARMETIS_TOLERANCE= 0.02 PARMETIS_EDGE_WEIGHT= 1 PARMETIS_POINT_WEIGHT= 0 % +% Make cutting a short edge of an anisotropic cell expensive, so that partition +% boundaries cross boundary layers in the wall-normal direction instead of running +% through them. Each graph edge is weighted by the longest node distance of its cells +% over its own length, and the coordinates seed the partition (NO, YES) (default NO). +PARMETIS_ANISOTROPY_WEIGHT= NO +% % ----------------------- SOBOLEV GRADIENT SMOOTHING OPTIONS ----------------------% % % Activate the gradient smoothing solver for the discrete adjoint driver (NO, YES) From 76271d1834f5832f75c470ccdc9537da3463c509 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sun, 27 Sep 2026 16:57:55 +0200 Subject: [PATCH 07/42] improve some agglomeration for rae2822 --- Common/include/linear_algebra/CSysSolve.hpp | 1 + Common/src/geometry/CMultiGridGeometry.cpp | 61 +++++++++++++++---- Common/src/linear_algebra/CSysSolve.cpp | 14 +++++ .../flow/diffusion/viscous_fluxes.hpp | 12 +--- 4 files changed, 66 insertions(+), 22 deletions(-) diff --git a/Common/include/linear_algebra/CSysSolve.hpp b/Common/include/linear_algebra/CSysSolve.hpp index 1f9bc851b92e..4d5aea756dd5 100644 --- a/Common/include/linear_algebra/CSysSolve.hpp +++ b/Common/include/linear_algebra/CSysSolve.hpp @@ -111,6 +111,7 @@ class CSysSolve { mutable VectorType r_0; /*!< \brief The "arbitrary" vector in BCGSTAB. */ mutable VectorType v; /*!< \brief BCGSTAB "v" vector (v = A * M^-1 * p). */ + mutable VectorType x_best; /*!< \brief BCGSTAB iterate with the smallest residual. */ mutable bool ritz_failed = false; mutable unsigned long k = 0, k_new = 0; diff --git a/Common/src/geometry/CMultiGridGeometry.cpp b/Common/src/geometry/CMultiGridGeometry.cpp index 86b8c272871f..88652e262d39 100644 --- a/Common/src/geometry/CMultiGridGeometry.cpp +++ b/Common/src/geometry/CMultiGridGeometry.cpp @@ -502,6 +502,9 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un unsigned short shared = 0; for (auto jPoint : fine_grid->nodes->GetPoints(CVPoint)) shared += inCV[jPoint]; + /*--- In 2D a CV of three or more nodes only takes nodes touching two members, so it cannot + * grow into a chain. ---*/ + if ((nDim == 2) && (nChildren >= 3) && (shared < 2)) continue; /*--- Distance to the centroid in cells: the offset is scaled by the seed edge pointing * most nearly along it. ---*/ @@ -638,18 +641,43 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un nodes->SetnChildren_CV(fromCV, 0); }; - /*--- Neighbour with the fewest children that may take this CV, NO_CV if there is none. Neighbours - * an earlier merge in the same pass emptied are not revived. ---*/ - auto smallestPartner = [&](unsigned long iCV, unsigned short maxPartnerSize, bool keepOffPartition) { + /*--- Dual-face area and number of fine edges between the children of two coarse CVs. ---*/ + auto sharedFaces = [&](unsigned long iCV, unsigned long jCV) { + su2double area = 0.0; + unsigned short nEdges = 0; + for (auto iChildren = 0u; iChildren < nodes->GetnChildren_CV(iCV); iChildren++) { + const auto iFinePoint = nodes->GetChildren_CV(iCV, iChildren); + for (auto iNeigh = 0u; iNeigh < fine_grid->nodes->GetnPoint(iFinePoint); iNeigh++) { + if (fine_grid->nodes->GetParent_CV(fine_grid->nodes->GetPoint(iFinePoint, iNeigh)) != jCV) continue; + area += GeometryToolbox::Norm(nDim, fine_grid->edges->GetNormal(fine_grid->nodes->GetEdge(iFinePoint, iNeigh))); + nEdges++; + } + } + return std::make_pair(area, nEdges); + }; + + /*--- Neighbour sharing the most dual-face area that may take this CV, the one with fewer children on + * a tie, NO_CV if there is none. A compact merge must join the two through at least as many fine + * edges as the smaller one has children. Neighbours an earlier merge in the same pass emptied are + * not revived. ---*/ + auto bestPartner = [&](unsigned long iCV, unsigned short maxPartnerSize, bool keepOffPartition, + bool compact) { auto best = NO_CV; auto best_nChildren = std::numeric_limits::max(); + su2double best_area = -1.0; for (auto jCV : nodes->GetPoints(iCV)) { const auto nChildren = nodes->GetnChildren_CV(jCV); - if ((nChildren == 0) || (nChildren > maxPartnerSize) || (nChildren >= best_nChildren)) continue; + if ((nChildren == 0) || (nChildren > maxPartnerSize)) continue; if (keepOffPartition && touchesPartition[jCV]) continue; if (!mayMerge(iCV, jCV)) continue; - best_nChildren = nChildren; - best = jCV; + const auto shared = sharedFaces(iCV, jCV); + if (compact && (shared.second < min(nChildren, nodes->GetnChildren_CV(iCV)))) continue; + if ((shared.first > best_area * (1.0 + 1e-6)) || + ((shared.first >= best_area * (1.0 - 1e-6)) && (nChildren < best_nChildren))) { + best_nChildren = nChildren; + best_area = shared.first; + best = jCV; + } } return best; }; @@ -686,8 +714,8 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un mergeInto(iCoarsePoint, iTarget); } - /*--- A CV left holding a single child joins the neighbour with the fewest, even where that takes - the neighbour one past maxAgglomSize. ---*/ + /*--- A CV left holding a single child joins the neighbour it shares the most face with, even where + that takes the neighbour one past maxAgglomSize. ---*/ for (auto iCoarsePoint = 0ul; iCoarsePoint < nPointDomain; iCoarsePoint++) { if (nodes->GetnChildren_CV(iCoarsePoint) != 1) continue; @@ -695,12 +723,12 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un /*--- Already handled above, or truly islanded. ---*/ if (nodes->GetnPoint(iCoarsePoint) <= 1) continue; - const auto iTarget = smallestPartner(iCoarsePoint, std::numeric_limits::max(), false); + const auto iTarget = bestPartner(iCoarsePoint, std::numeric_limits::max(), false, false); if (iTarget != NO_CV) mergeInto(iCoarsePoint, iTarget); } - /*--- Merge a paved CV of at most SMALL_STACK_CV children into an equally small neighbour, which - the two passes above do not reach. Two of them can never exceed maxAgglomSize together. ---*/ + /*--- Merge a paved CV of at most SMALL_STACK_CV children into an equally small neighbour it joins + compactly, which the two passes above do not reach. Two of them can never exceed maxAgglomSize together. ---*/ constexpr unsigned short SMALL_STACK_CV = 2; /*!< \brief The block size a narrow stack emits between flushes; see BlockFor. */ @@ -712,7 +740,7 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un /*--- Interior stack fragments only, a boundary row keeps its footprint. ---*/ if (cvOnBoundary[iCoarsePoint]) continue; - const auto iTarget = smallestPartner(iCoarsePoint, SMALL_STACK_CV, true); + const auto iTarget = bestPartner(iCoarsePoint, SMALL_STACK_CV, true, true); if (iTarget != NO_CV) mergeInto(iCoarsePoint, iTarget); } @@ -2148,7 +2176,14 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co std::sort(distinct.begin(), distinct.end()); distinct.erase(std::unique(distinct.begin(), distinct.end()), distinct.end()); if (distinct.size() != width) return false; - return true; + /*--- The layer must stay connected, or its blocks split into strands. ---*/ + vector reached(1, distinct[0]); + for (size_t k = 0; k < reached.size(); ++k) + for (auto jPoint : fine_grid->nodes->GetPoints(reached[k])) + if (std::binary_search(distinct.begin(), distinct.end(), jPoint) && + (std::find(reached.begin(), reached.end(), jPoint) == reached.end())) + reached.push_back(jPoint); + return reached.size() == width; }; if (complete(candidates)) { diff --git a/Common/src/linear_algebra/CSysSolve.cpp b/Common/src/linear_algebra/CSysSolve.cpp index 8ec1b19b23b3..b480dcacdd95 100644 --- a/Common/src/linear_algebra/CSysSolve.cpp +++ b/Common/src/linear_algebra/CSysSolve.cpp @@ -1087,6 +1087,7 @@ unsigned long CSysSolve::BCGSTAB_LinSolver(const CSysVector::BCGSTAB_LinSolver(const CSysVector::BCGSTAB_LinSolver(const CSysVector::BCGSTAB_LinSolver(const CSysVectorGetComm_Level() == COMM_FULL) && (norm_r > norm_best)) { + x = x_best; + norm_r = norm_best; + } + /*--- Recalculate final residual (this should be optional) ---*/ if ((monitoring) && (config->GetComm_Level() == COMM_FULL)) { diff --git a/SU2_CFD/include/numerics_simd/flow/diffusion/viscous_fluxes.hpp b/SU2_CFD/include/numerics_simd/flow/diffusion/viscous_fluxes.hpp index ae544de1b0c3..3edc0232abd9 100644 --- a/SU2_CFD/include/numerics_simd/flow/diffusion/viscous_fluxes.hpp +++ b/SU2_CFD/include/numerics_simd/flow/diffusion/viscous_fluxes.hpp @@ -76,7 +76,6 @@ class CCompressibleViscousFluxBase : public CNumericsSIMD { const su2double gamma; const su2double gasConst; const su2double prandtlTurb; - const bool effDistJac; /*!< EXPERIMENT: SU2_VISC_JAC_EFFDIST. */ const bool useSA_QCR; const bool wallFun; const bool uq; @@ -96,7 +95,6 @@ class CCompressibleViscousFluxBase : public CNumericsSIMD { gamma(config.GetGamma()), gasConst(config.GetGas_ConstantND()), prandtlTurb(config.GetPrandtl_Turb()), - effDistJac(getenv("SU2_VISC_JAC_EFFDIST") != nullptr), useSA_QCR(config.GetSAParsedOptions().qcr2000), wallFun(config.GetWall_Functions()), uq(config.GetSSTParsedOptions().uq), @@ -179,14 +177,10 @@ class CCompressibleViscousFluxBase : public CNumericsSIMD { /*--- Flux Jacobians. ---*/ - Double dist_ij = sqrt(dist2_ij); + /*--- Effective distance |d|^2/|d.n| matches the normal derivative of the corrected gradient. ---*/ - /*--- EXPERIMENT: SU2_VISC_JAC_EFFDIST linearizes the corrected gradient, whose normal part depends - * on the neighbour difference over |d|^2/(d.n) rather than over |d|. ---*/ - if (effDistJac) { - const Double projDist = abs(dot(vector_ij, unitNormal)); - dist_ij = dist2_ij / fmax(projDist, 0.1 * dist_ij); - } + const Double projDist = abs(dot(vector_ij, unitNormal)); + const Double dist_ij = dist2_ij / fmax(projDist, 0.1 * sqrt(dist2_ij)); auto dtau = stressTensorJacobian(avgV, unitNormal, dist_ij); /*--- Energy flux Jacobian. ---*/ From 2247399dc85f038f96f359e726b89a7026e8afb1 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Fri, 2 Oct 2026 12:09:50 +0200 Subject: [PATCH 08/42] wall ends are first order --- Common/include/CConfig.hpp | 10 +- Common/include/geometry/CPhysicalGeometry.hpp | 25 +++ Common/src/CConfig.cpp | 5 +- Common/src/geometry/CPhysicalGeometry.cpp | 203 ++++++++++++++++-- .../numerics_simd/flow/convection/common.hpp | 11 +- SU2_CFD/include/variables/CEulerVariable.hpp | 5 + SU2_CFD/src/solvers/CEulerSolver.cpp | 97 ++++++++- SU2_CFD/src/variables/CEulerVariable.cpp | 1 + config_template.cfg | 9 +- 9 files changed, 341 insertions(+), 25 deletions(-) diff --git a/Common/include/CConfig.hpp b/Common/include/CConfig.hpp index 2475d7c3a9e0..69de97b6eea3 100644 --- a/Common/include/CConfig.hpp +++ b/Common/include/CConfig.hpp @@ -600,7 +600,8 @@ class CConfig { MUSCL_Heat, /*!< \brief MUSCL scheme for the (fvm) heat equation.*/ MUSCL_AdjFlow, /*!< \brief MUSCL scheme for the adj flow equations.*/ MUSCL_AdjTurb, /*!< \brief MUSCL scheme for the adj turbulence equations.*/ - MUSCL_Species; /*!< \brief MUSCL scheme for the species equations.*/ + MUSCL_Species, /*!< \brief MUSCL scheme for the species equations.*/ + MUSCL_FirstOrderWallEnds; /*!< \brief First-order reconstruction at no-slip wall ends and sharp wall edges.*/ su2double MUSCL_Kappa, /*!< \brief Blending coefficient for U-MUSCL scheme (for the runtime eq. system). */ MUSCL_Kappa_Flow, /*!< \brief Blending coefficient for U-MUSCL scheme for the flow equations.*/ MUSCL_Kappa_Turb, /*!< \brief Blending coefficient for U-MUSCL scheme for the turbulence equations.*/ @@ -1116,7 +1117,7 @@ class CConfig { su2double ParMETIS_tolerance; /*!< \brief Load balancing tolerance for ParMETIS. */ long ParMETIS_pointWgt; /*!< \brief Load balancing weight given to points. */ long ParMETIS_edgeWgt; /*!< \brief Load balancing weight given to edges. */ - bool ParMETIS_anisotropyWgt; /*!< \brief Weight graph edges by cell anisotropy and partition with coordinates. */ + bool ParMETIS_anisotropyWgt; /*!< \brief Weight graph edges by cell anisotropy and keep anisotropic lines on one rank. */ unsigned short DirectDiff; /*!< \brief Direct Differentation mode. */ bool DiscreteAdjoint, /*!< \brief AD-based discrete adjoint mode. */ DiscreteAdjointDebug; /*!< \brief Discrete adjoint debug mode using tags. */ @@ -4779,6 +4780,11 @@ class CConfig { */ bool GetMUSCL_Flow(void) const { return MUSCL_Flow; } + /*! + * \brief Get if edges at no-slip wall ends and sharp wall edges are reconstructed to first order. + */ + bool GetMUSCL_FirstOrderWallEnds(void) const { return MUSCL_FirstOrderWallEnds; } + /*! * \brief Get if the upwind scheme used MUSCL or not. * \return MUSCL scheme. diff --git a/Common/include/geometry/CPhysicalGeometry.hpp b/Common/include/geometry/CPhysicalGeometry.hpp index 3f2a55684829..70677889e08d 100644 --- a/Common/include/geometry/CPhysicalGeometry.hpp +++ b/Common/include/geometry/CPhysicalGeometry.hpp @@ -344,6 +344,31 @@ class CPhysicalGeometry final : public CGeometry { * \return One weight per entry of the adjacency array. */ vector ComputeAnisotropyEdgeWeights(long maxWeight) const; + + /*! + * \brief Reads, for any global points of the linear partition, a value each rank holds for its own points. + * \param[in] wanted - Global indices to read. + * \param[in] localValue - Value of every local point. + * \return The value of each wanted point. + */ + vector FetchFromOwners(const vector& wanted, + const vector& localValue) const; + + /*! + * \brief Links every point to the neighbour across its strongest anisotropic edge, chains of links are lines. + * \param[in] adjwgt - Anisotropy weight of every entry of the adjacency array. + * \return Global index of the linked neighbour, or of the point itself when no edge is strong enough. + */ + vector LinkAnisotropicLines(const vector& adjwgt) const; + + /*! + * \brief Moves each line to the partition that holds most of its points. + * \param[in] link - Line links from LinkAnisotropicLines. + * \param[in,out] part - Partition of every local point. + * \param[out] longestLine - Number of points of the longest line. + * \return Number of points that changed partition, summed over all ranks. + */ + unsigned long KeepLinesTogether(vector link, vector& part, unsigned long& longestLine) const; #endif /*! diff --git a/Common/src/CConfig.cpp b/Common/src/CConfig.cpp index 6857123503b6..3fd872d1acd8 100644 --- a/Common/src/CConfig.cpp +++ b/Common/src/CConfig.cpp @@ -2158,6 +2158,9 @@ void CConfig::SetConfig_Options() { /*!\brief MUSCL_FLOW \n DESCRIPTION: Check if the MUSCL scheme should be used \ingroup Config*/ addBoolOption("MUSCL_FLOW", MUSCL_Flow, true); + /*!\brief MUSCL_FIRST_ORDER_WALL_ENDS \n DESCRIPTION: Reconstruct the flow to first order on the edges of points + * where a no-slip wall ends on a boundary continuing its surface, or has a sharp edge such as a trailing edge \ingroup Config*/ + addBoolOption("MUSCL_FIRST_ORDER_WALL_ENDS", MUSCL_FirstOrderWallEnds, false); /*!\brief MUSCL_KAPPA_FLOW \n DESCRIPTION: Blending coefficient for the U-MUSCL scheme \ingroup Config*/ addDoubleOption("MUSCL_KAPPA_FLOW", MUSCL_Kappa_Flow, 0.0); /*!\brief RAMP_MUSCL \n DESCRIPTION: Enable ramping of the MUSCL scheme from 1st to 2nd order using specified method*/ @@ -3095,7 +3098,7 @@ void CConfig::SetConfig_Options() { /* DESCRIPTION: ParMETIS load balancing weight for edges (equiv. to neighbors) */ addLongOption("PARMETIS_EDGE_WEIGHT", ParMETIS_edgeWgt, 1); - /* DESCRIPTION: Weight ParMETIS graph edges by cell anisotropy and partition with coordinates */ + /* DESCRIPTION: Weight ParMETIS graph edges by cell anisotropy and keep anisotropic lines on one rank */ addBoolOption("PARMETIS_ANISOTROPY_WEIGHT", ParMETIS_anisotropyWgt, false); /*--- options that are used in the Hybrid RANS/LES Simulations ---*/ diff --git a/Common/src/geometry/CPhysicalGeometry.cpp b/Common/src/geometry/CPhysicalGeometry.cpp index 65b013b5421a..ce9b771c50f5 100644 --- a/Common/src/geometry/CPhysicalGeometry.cpp +++ b/Common/src/geometry/CPhysicalGeometry.cpp @@ -7362,6 +7362,156 @@ void CPhysicalGeometry::SetBoundTecPlot(char mesh_filename[MAX_STRING_SIZE], boo } #if defined(HAVE_MPI) && defined(HAVE_PARMETIS) +vector CPhysicalGeometry::FetchFromOwners(const vector& wanted, + const vector& localValue) const { + CLinearPartitioner pointPartitioner(Global_nPointDomain, 0); + const unsigned long firstIndex = pointPartitioner.GetFirstIndexOnRank(rank); + + vector nSend(size, 0), nRecv(size), sendDisp(size + 1, 0), recvDisp(size + 1, 0); + for (const auto iGlobal : wanted) nSend[pointPartitioner.GetRankContainingIndex(iGlobal)]++; + SU2_MPI::Alltoall(nSend.data(), 1, MPI_INT, nRecv.data(), 1, MPI_INT, SU2_MPI::GetComm()); + for (int iRank = 0; iRank < size; iRank++) { + sendDisp[iRank + 1] = sendDisp[iRank] + nSend[iRank]; + recvDisp[iRank + 1] = recvDisp[iRank] + nRecv[iRank]; + } + + vector sendIndex(sendDisp[size]), slotOf(wanted.size()), recvIndex(recvDisp[size]); + vector next(sendDisp.begin(), sendDisp.end() - 1); + for (auto k = 0ul; k < wanted.size(); k++) { + const auto slot = next[pointPartitioner.GetRankContainingIndex(wanted[k])]++; + sendIndex[slot] = wanted[k]; + slotOf[k] = slot; + } + SU2_MPI::Alltoallv(sendIndex.data(), nSend.data(), sendDisp.data(), MPI_UNSIGNED_LONG, recvIndex.data(), + nRecv.data(), recvDisp.data(), MPI_UNSIGNED_LONG, SU2_MPI::GetComm()); + + vector reply(recvIndex.size()), answer(sendIndex.size()), result(wanted.size()); + for (auto k = 0ul; k < recvIndex.size(); k++) reply[k] = localValue[recvIndex[k] - firstIndex]; + SU2_MPI::Alltoallv(reply.data(), nRecv.data(), recvDisp.data(), MPI_UNSIGNED_LONG, answer.data(), nSend.data(), + sendDisp.data(), MPI_UNSIGNED_LONG, SU2_MPI::GetComm()); + + for (auto k = 0ul; k < wanted.size(); k++) result[k] = answer[slotOf[k]]; + return result; +} + +vector CPhysicalGeometry::LinkAnisotropicLines(const vector& adjwgt) const { + /*--- An edge at least this many times shorter than its element joins its points into a line. ---*/ + constexpr idx_t LINE_WEIGHT = 4; + + const unsigned long firstIndex = CLinearPartitioner(Global_nPointDomain, 0).GetFirstIndexOnRank(rank); + + /*--- Edges are ordered by weight, then by their end points, so every point picks the same edge its + * neighbour would and the links form a forest whose only cycles are mutual pairs. ---*/ + vector link(nPoint); + for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) { + const unsigned long iGlobal = firstIndex + iPoint; + link[iPoint] = iGlobal; + idx_t bestWeight = LINE_WEIGHT - 1; + unsigned long bestLo = 0, bestHi = 0; + for (auto k = xadj[iPoint]; k < xadj[iPoint + 1]; k++) { + const auto jGlobal = static_cast(adjacency[k]); + const auto lo = min(iGlobal, jGlobal), hi = max(iGlobal, jGlobal); + const bool better = (adjwgt[k] > bestWeight) || + ((adjwgt[k] == bestWeight) && ((lo < bestLo) || ((lo == bestLo) && (hi < bestHi)))); + if (better) { + bestWeight = adjwgt[k]; + bestLo = lo; + bestHi = hi; + link[iPoint] = jGlobal; + } + } + } + return link; +} + +unsigned long CPhysicalGeometry::KeepLinesTogether(vector link, vector& part, + unsigned long& longestLine) const { + CLinearPartitioner pointPartitioner(Global_nPointDomain, 0); + const unsigned long firstIndex = pointPartitioner.GetFirstIndexOnRank(rank); + + /*--- The lower point of a mutual pair becomes the root of its line. ---*/ + { + const auto linkOfLink = FetchFromOwners(link, link); + for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) { + const unsigned long iGlobal = firstIndex + iPoint; + if ((linkOfLink[iPoint] == iGlobal) && (iGlobal < link[iPoint])) link[iPoint] = iGlobal; + } + } + + /*--- Pointer jumping links every point to the root of its line. ---*/ + for (;;) { + const auto linkOfLink = FetchFromOwners(link, link); + unsigned long changed = 0, changedGlobal = 0; + for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) { + if (linkOfLink[iPoint] != link[iPoint]) { + link[iPoint] = linkOfLink[iPoint]; + changed++; + } + } + SU2_MPI::Allreduce(&changed, &changedGlobal, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm()); + if (changedGlobal == 0) break; + } + + /*--- The owner of each root counts in which partitions its line lies. ---*/ + vector nSend(size, 0), nRecv(size), sendDisp(size + 1, 0), recvDisp(size + 1, 0); + for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) nSend[pointPartitioner.GetRankContainingIndex(link[iPoint])] += 2; + SU2_MPI::Alltoall(nSend.data(), 1, MPI_INT, nRecv.data(), 1, MPI_INT, SU2_MPI::GetComm()); + for (int iRank = 0; iRank < size; iRank++) { + sendDisp[iRank + 1] = sendDisp[iRank] + nSend[iRank]; + recvDisp[iRank + 1] = recvDisp[iRank] + nRecv[iRank]; + } + vector sendBuf(sendDisp[size]), recvBuf(recvDisp[size]); + vector next(sendDisp.begin(), sendDisp.end() - 1); + for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) { + auto& slot = next[pointPartitioner.GetRankContainingIndex(link[iPoint])]; + sendBuf[slot++] = link[iPoint]; + sendBuf[slot++] = static_cast(part[iPoint]); + } + SU2_MPI::Alltoallv(sendBuf.data(), nSend.data(), sendDisp.data(), MPI_UNSIGNED_LONG, recvBuf.data(), nRecv.data(), + recvDisp.data(), MPI_UNSIGNED_LONG, SU2_MPI::GetComm()); + + map> votes; + for (auto k = 0ul; k < recvBuf.size(); k += 2) votes[recvBuf[k]][recvBuf[k + 1]]++; + + unsigned long longest = 0; + for (const auto& line : votes) { + unsigned long length = 0; + for (const auto& vote : line.second) length += vote.second; + longest = max(longest, length); + } + SU2_MPI::Allreduce(&longest, &longestLine, 1, MPI_UNSIGNED_LONG, MPI_MAX, SU2_MPI::GetComm()); + + vector decision(nPoint); + for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) decision[iPoint] = static_cast(part[iPoint]); + for (const auto& line : votes) { + unsigned long best = 0, bestCount = 0; + for (const auto& vote : line.second) { + if (vote.second > bestCount) { + best = vote.first; + bestCount = vote.second; + } + } + decision[line.first - firstIndex] = best; + } + + /*--- Every point takes the partition of its line, unless that would leave a rank without points. ---*/ + const auto chosen = FetchFromOwners(link, decision); + vector count(size, 0), countGlobal(size); + for (const auto iPart : chosen) count[iPart]++; + SU2_MPI::Allreduce(count.data(), countGlobal.data(), size, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm()); + if (*min_element(countGlobal.begin(), countGlobal.end()) == 0) return 0; + + unsigned long moved = 0, movedGlobal = 0; + for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) { + if (static_cast(part[iPoint]) != chosen[iPoint]) { + part[iPoint] = static_cast(chosen[iPoint]); + moved++; + } + } + SU2_MPI::Allreduce(&moved, &movedGlobal, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm()); + return movedGlobal; +} + vector CPhysicalGeometry::ComputeAnisotropyEdgeWeights(long maxWeight) const { CLinearPartitioner pointPartitioner(Global_nPointDomain, 0); const unsigned long firstIndex = pointPartitioner.GetFirstIndexOnRank(rank); @@ -7519,20 +7669,27 @@ void CPhysicalGeometry::SetColorGrid_Parallel(const CConfig* config) { vwgt[iPoint] = wp + we * (xadj[iPoint + 1] - xadj[iPoint]); } - /*--- Keep partition boundaries off the short edges of anisotropic cells, with the coordinates - * seeding the partition. The cap keeps the total edge weight within the range of idx_t. ---*/ + /*--- Keep partition boundaries off the short edges of anisotropic cells. The edges that chain + * points into wall-normal lines get the largest weight, so the graph coarsening merges each + * line before it balances. The cap keeps the total edge weight within the range of idx_t. ---*/ const bool anisotropic = config->GetParMETIS_AnisotropyWeight(); vector adjwgt; - vector xyz; + vector lineLink; if (anisotropic) { constexpr long maxWeight = (sizeof(idx_t) >= 8) ? 1000000 : 1000; adjwgt = ComputeAnisotropyEdgeWeights(maxWeight); + lineLink = LinkAnisotropicLines(adjwgt); + + const vector neighbor(adjacency.begin(), adjacency.end()); + const auto neighborLink = FetchFromOwners(neighbor, lineLink); + const unsigned long firstIndex = pointPartitioner.GetFirstIndexOnRank(rank); + for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) { + for (auto k = xadj[iPoint]; k < xadj[iPoint + 1]; k++) { + if ((lineLink[iPoint] == neighbor[k]) || (neighborLink[k] == firstIndex + iPoint)) adjwgt[k] = maxWeight; + } + } wgtflag = 3; - xyz.resize(nPoint * nDim); - for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) - for (unsigned short iDim = 0; iDim < nDim; iDim++) - xyz[iPoint * nDim + iDim] = SU2_TYPE::GetValue(nodes->GetCoord(iPoint, iDim)); } /*--- Create some structures that ParMETIS needs to output the partitioning. ---*/ @@ -7543,23 +7700,33 @@ void CPhysicalGeometry::SetColorGrid_Parallel(const CConfig* config) { /*--- Calling ParMETIS ---*/ if (rank == MASTER_NODE) cout << "Calling ParMETIS..."; - int err; - if (anisotropic) { - idx_t ndims = nDim; - err = ParMETIS_V3_PartGeomKway(vtxdist.data(), xadj.data(), adjacency.data(), vwgt.data(), adjwgt.data(), - &wgtflag, &numflag, &ndims, xyz.data(), &ncon, &nparts, tpwgts.data(), &ubvec, - options, &edgecut, part.data(), &comm); - } else { - err = ParMETIS_V3_PartKway(vtxdist.data(), xadj.data(), adjacency.data(), vwgt.data(), nullptr, &wgtflag, - &numflag, &ncon, &nparts, tpwgts.data(), &ubvec, options, &edgecut, part.data(), - &comm); - } + const int err = ParMETIS_V3_PartKway(vtxdist.data(), xadj.data(), adjacency.data(), vwgt.data(), + anisotropic ? adjwgt.data() : nullptr, &wgtflag, &numflag, &ncon, &nparts, + tpwgts.data(), &ubvec, options, &edgecut, part.data(), &comm); if (err != METIS_OK) SU2_MPI::Error("Partitioning failed.", CURRENT_FUNCTION); if (rank == MASTER_NODE) { cout << " graph partitioning complete (" << edgecut << (anisotropic ? " weighted" : "") << " edge cuts)." << endl; } + /*--- A line split between ranks loses its strongest couplings in the preconditioner, and its + * fragments give tangled coarse control volumes. ---*/ + + if (anisotropic) { + unsigned long longestLine = 0; + const auto moved = KeepLinesTogether(lineLink, part, longestLine); + /*--- The imbalance is measured in the vertex weights ParMETIS balances. ---*/ + vector load(size, 0), loadGlobal(size); + for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) load[part[iPoint]] += vwgt[iPoint]; + SU2_MPI::Allreduce(load.data(), loadGlobal.data(), size, MPI_UNSIGNED_LONG, MPI_SUM, comm); + const auto maxLoad = *max_element(loadGlobal.begin(), loadGlobal.end()); + const auto sumLoad = accumulate(loadGlobal.begin(), loadGlobal.end(), 0ul); + if (rank == MASTER_NODE) { + cout << "Longest anisotropic line " << longestLine << " points, moved " << moved + << " points to keep lines on one rank, load imbalance " << double(maxLoad) * size / sumLoad << "." << endl; + } + } + /*--- Store the results of the partitioning (note that this is local since each processor is calling ParMETIS in parallel and storing the results for its initial piece of the grid. ---*/ diff --git a/SU2_CFD/include/numerics_simd/flow/convection/common.hpp b/SU2_CFD/include/numerics_simd/flow/convection/common.hpp index 800167d4b0f5..c683d9445b11 100644 --- a/SU2_CFD/include/numerics_simd/flow/convection/common.hpp +++ b/SU2_CFD/include/numerics_simd/flow/convection/common.hpp @@ -119,9 +119,16 @@ FORCEINLINE CPair reconstructPrimitives(const Int& iEdge, fmax(solution.OutlierMitigation(iPoint[k]), solution.OutlierMitigation(jPoint[k])) / VariableType::MAX_OUTLIER_MITIGATION); } + /*--- Edges of flagged points drop to first order without the extra dissipation of a + * non-physical edge. ---*/ + Double firstOrder = nonPhysical; + for (size_t k = 0; k < Double::Size; ++k) { + firstOrder[k] = fmax(firstOrder[k], fmax(solution.FirstOrderReconstruction(iPoint[k]), + solution.FirstOrderReconstruction(jPoint[k]))); + } for (size_t iVar = 0; iVar < ReconVarType::nVar; ++iVar) { - V.i.all(iVar) = nonPhysical * V1st.i.all(iVar) + (1-nonPhysical) * V.i.all(iVar); - V.j.all(iVar) = nonPhysical * V1st.j.all(iVar) + (1-nonPhysical) * V.j.all(iVar); + V.i.all(iVar) = firstOrder * V1st.i.all(iVar) + (1-firstOrder) * V.i.all(iVar); + V.j.all(iVar) = firstOrder * V1st.j.all(iVar) + (1-firstOrder) * V.j.all(iVar); } } else { nonPhysical = 0; diff --git a/SU2_CFD/include/variables/CEulerVariable.hpp b/SU2_CFD/include/variables/CEulerVariable.hpp index ebd817fa1339..2bc1fa7d9ca7 100644 --- a/SU2_CFD/include/variables/CEulerVariable.hpp +++ b/SU2_CFD/include/variables/CEulerVariable.hpp @@ -374,4 +374,9 @@ class CEulerVariable : public CFlowVariable { */ su2vector OutlierMitigation; + /*! + * \brief Points whose edges are reconstructed to first order (1), others use MUSCL (0). + */ + su2vector FirstOrderReconstruction; + }; diff --git a/SU2_CFD/src/solvers/CEulerSolver.cpp b/SU2_CFD/src/solvers/CEulerSolver.cpp index 32c265e55656..1d28f5d8dc71 100644 --- a/SU2_CFD/src/solvers/CEulerSolver.cpp +++ b/SU2_CFD/src/solvers/CEulerSolver.cpp @@ -302,6 +302,101 @@ CEulerSolver::CEulerSolver(CGeometry *geometry, CConfig *config, nodes->NonPhysicalEdgeCounter.resize(geometry->GetnEdge()) = 0; } + /*--- The gradient is singular where a no-slip wall meets another kind of boundary. Unlimited + * reconstruction across it gives a defect the first-order multigrid levels cannot correct. ---*/ + + if ((iMesh == MESH_0) && config->GetMUSCL_Flow() && config->GetMUSCL_FirstOrderWallEnds()) { + /*--- Only where the other boundary continues the wall surface does the condition jump along a + * smooth surface. Where they meet at an angle, as at a wing root on a symmetry plane, the + * flow is smooth. Halfway between parallel and perpendicular separates the two. ---*/ + const su2double minAlignment = sqrt(0.5); + + auto unitNormal = [&](unsigned short iMarker, long iVertex, su2double* normal) { + geometry->vertex[iMarker][iVertex]->GetNormal(normal); + const su2double area = GeometryToolbox::Norm(nDim, normal); + for (unsigned short iDim = 0; iDim < nDim; iDim++) normal[iDim] /= max(area, EPS); + }; + + /*--- A sharp edge of the wall itself, such as a trailing edge, is singular as well. Its vertex + * normal is much shorter than the area of the faces around it, cos(half the angle between + * their normals); the same halfway threshold applies. ---*/ + vector wallArea(nPoint, 0.0); + for (unsigned short iWall = 0; iWall < config->GetnMarker_All(); iWall++) { + if (!config->GetViscous_Wall(iWall)) continue; + for (unsigned long iElem = 0; iElem < geometry->GetnElem_Bound(iWall); iElem++) { + const auto* elem = geometry->bound[iWall][iElem]; + const auto nNodes = elem->GetnNodes(); + su2double area = 0.0; + if (nDim == 2) { + su2double edge[MAXNDIM] = {0.0}; + GeometryToolbox::Distance(nDim, geometry->nodes->GetCoord(elem->GetNode(1)), + geometry->nodes->GetCoord(elem->GetNode(0)), edge); + area = GeometryToolbox::Norm(nDim, edge); + } else { + for (unsigned short iNode = 1; iNode + 1 < nNodes; iNode++) { + su2double a[3] = {0.0}, b[3] = {0.0}, c[3] = {0.0}; + GeometryToolbox::Distance(3, geometry->nodes->GetCoord(elem->GetNode(iNode)), + geometry->nodes->GetCoord(elem->GetNode(0)), a); + GeometryToolbox::Distance(3, geometry->nodes->GetCoord(elem->GetNode(iNode + 1)), + geometry->nodes->GetCoord(elem->GetNode(0)), b); + GeometryToolbox::CrossProduct(a, b, c); + area += 0.5 * GeometryToolbox::Norm(3, c); + } + } + for (unsigned short iNode = 0; iNode < nNodes; iNode++) wallArea[elem->GetNode(iNode)] += area / nNodes; + } + } + const su2double minFlatness = cos(PI_NUMBER / 8); + + for (iPoint = 0; iPoint < nPoint; iPoint++) { + bool wallEnds = false; + for (unsigned short iWall = 0; iWall < config->GetnMarker_All(); iWall++) { + const auto wallVertex = geometry->nodes->GetVertex(iPoint, iWall); + if (!config->GetViscous_Wall(iWall) || (wallVertex < 0)) continue; + + const su2double vertexArea = GeometryToolbox::Norm(nDim, geometry->vertex[iWall][wallVertex]->GetNormal()); + if (vertexArea < minFlatness * wallArea[iPoint]) wallEnds = true; + + su2double wallNormal[MAXNDIM] = {0.0}; + unitNormal(iWall, wallVertex, wallNormal); + + for (unsigned short iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++) { + const auto kindBC = config->GetMarker_All_KindBC(iMarker); + if (config->GetViscous_Wall(iMarker) || (kindBC == SEND_RECEIVE) || (kindBC == PERIODIC_BOUNDARY) || + (kindBC == INTERNAL_BOUNDARY) || (kindBC == NEARFIELD_BOUNDARY) || (kindBC == FLUID_INTERFACE)) continue; + const auto iVertex = geometry->nodes->GetVertex(iPoint, iMarker); + if (iVertex < 0) continue; + su2double normal[MAXNDIM] = {0.0}; + unitNormal(iMarker, iVertex, normal); + if (fabs(GeometryToolbox::DotProduct(nDim, wallNormal, normal)) > minAlignment) wallEnds = true; + } + } + nodes->FirstOrderReconstruction(iPoint) = wallEnds; + } + + unsigned long nFlagged = 0, nFlaggedGlobal = 0; + for (iPoint = 0; iPoint < nPointDomain; iPoint++) nFlagged += nodes->FirstOrderReconstruction(iPoint); + SU2_MPI::Allreduce(&nFlagged, &nFlaggedGlobal, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm()); + if (rank == MASTER_NODE) + cout << "First-order reconstruction at " << nFlaggedGlobal << " points where a no-slip wall ends or has a sharp edge." << endl; + + /*--- A halo may lack one of the markers its owner has, so it takes the owner's flag. ---*/ + for (unsigned short iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++) { + if ((config->GetMarker_All_KindBC(iMarker) != SEND_RECEIVE) || (config->GetMarker_All_SendRecv(iMarker) <= 0)) + continue; + const auto markerS = iMarker, markerR = static_cast(iMarker + 1); + const int sendTo = config->GetMarker_All_SendRecv(markerS) - 1; + const int receiveFrom = abs(config->GetMarker_All_SendRecv(markerR)) - 1; + vector bufSend(geometry->nVertex[markerS]), bufRecv(geometry->nVertex[markerR]); + for (auto iVertex = 0ul; iVertex < geometry->nVertex[markerS]; iVertex++) + bufSend[iVertex] = nodes->FirstOrderReconstruction(geometry->vertex[markerS][iVertex]->GetNode()); + SU2_MPI::Sendrecv(bufSend.data(), bufSend.size(), MPI_UNSIGNED_SHORT, sendTo, 0, bufRecv.data(), bufRecv.size(), + MPI_UNSIGNED_SHORT, receiveFrom, 0, SU2_MPI::GetComm(), MPI_STATUS_IGNORE); + for (auto iVertex = 0ul; iVertex < geometry->nVertex[markerR]; iVertex++) + nodes->FirstOrderReconstruction(geometry->vertex[markerR][iVertex]->GetNode()) = bufRecv[iVertex]; + } + } + /*--- Check that the initial solution is physical, report any non-physical nodes ---*/ counter_local = 0; @@ -1909,7 +2004,7 @@ void CEulerSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_contain /*--- Set them with or without high order reconstruction using MUSCL strategy. ---*/ - if (!muscl) { + if (!muscl || nodes->FirstOrderReconstruction(iPoint) || nodes->FirstOrderReconstruction(jPoint)) { numerics->SetPrimitive(V_i, V_j); numerics->SetSecondary(S_i, S_j); diff --git a/SU2_CFD/src/variables/CEulerVariable.cpp b/SU2_CFD/src/variables/CEulerVariable.cpp index f45c60060b81..2c556501f78f 100644 --- a/SU2_CFD/src/variables/CEulerVariable.cpp +++ b/SU2_CFD/src/variables/CEulerVariable.cpp @@ -107,6 +107,7 @@ CEulerVariable::CEulerVariable(su2double density, const su2double *velocity, su2 } OutlierMitigation.resize(nPoint) = 0; + FirstOrderReconstruction.resize(nPoint) = 0; } bool CEulerVariable::SetPrimVar(unsigned long iPoint, CFluidModel *FluidModel) { diff --git a/config_template.cfg b/config_template.cfg index 739d79817374..8d49841bee87 100644 --- a/config_template.cfg +++ b/config_template.cfg @@ -1598,6 +1598,12 @@ CUSTOM_OBJFUNC= 'DRAG + 10 * pow(fmax(0.4-LIFT, 0), 2)' % Required for 2nd order upwind schemes (NO, YES) MUSCL_FLOW= YES % +% Reconstruct to first order on the edges of points where a no-slip wall ends on a boundary that +% continues its surface (a leading edge after a symmetry plane) or has a sharp edge (a sharp +% trailing edge). The gradient is singular there, and MUSCL across it can stall or destabilize +% the solver, multigrid in particular (NO, YES) +MUSCL_FIRST_ORDER_WALL_ENDS= NO +% % Option to ramp the MUSCL reconstruction scheme gradually from first to second order RAMP_MUSCL= NO % @@ -2536,7 +2542,8 @@ PARMETIS_POINT_WEIGHT= 0 % Make cutting a short edge of an anisotropic cell expensive, so that partition % boundaries cross boundary layers in the wall-normal direction instead of running % through them. Each graph edge is weighted by the longest node distance of its cells -% over its own length, and the coordinates seed the partition (NO, YES) (default NO). +% over its own length, and lines of strongly coupled points (wall-normal lines in a +% boundary layer) are kept whole on one rank (NO, YES) (default NO). PARMETIS_ANISOTROPY_WEIGHT= NO % % ----------------------- SOBOLEV GRADIENT SMOOTHING OPTIONS ----------------------% From 845ec6edc0ca3d2324941441ee80929ea3d0ea2b Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sun, 4 Oct 2026 09:16:41 +0200 Subject: [PATCH 09/42] small fix to adaptive CFL and mpi treatment --- Common/include/geometry/CPhysicalGeometry.hpp | 12 +- Common/src/geometry/CPhysicalGeometry.cpp | 106 +++++++++--------- SU2_CFD/include/solvers/CSolver.hpp | 2 + SU2_CFD/src/solvers/CSolver.cpp | 36 +++++- 4 files changed, 92 insertions(+), 64 deletions(-) diff --git a/Common/include/geometry/CPhysicalGeometry.hpp b/Common/include/geometry/CPhysicalGeometry.hpp index 70677889e08d..e69b1a04a9b0 100644 --- a/Common/include/geometry/CPhysicalGeometry.hpp +++ b/Common/include/geometry/CPhysicalGeometry.hpp @@ -355,20 +355,22 @@ class CPhysicalGeometry final : public CGeometry { const vector& localValue) const; /*! - * \brief Links every point to the neighbour across its strongest anisotropic edge, chains of links are lines. + * \brief Joins points into lines along the strong anisotropic edges and names each line by its lowest global index. * \param[in] adjwgt - Anisotropy weight of every entry of the adjacency array. - * \return Global index of the linked neighbour, or of the point itself when no edge is strong enough. + * \param[out] lineEdge - Whether each entry of the adjacency array is a line edge. + * \return Global index of the root of the line of every local point, the point itself when it is on no line. */ - vector LinkAnisotropicLines(const vector& adjwgt) const; + vector LinkAnisotropicLines(const vector& adjwgt, vector& lineEdge) const; /*! * \brief Moves each line to the partition that holds most of its points. - * \param[in] link - Line links from LinkAnisotropicLines. + * \param[in] root - Line roots from LinkAnisotropicLines. * \param[in,out] part - Partition of every local point. * \param[out] longestLine - Number of points of the longest line. * \return Number of points that changed partition, summed over all ranks. */ - unsigned long KeepLinesTogether(vector link, vector& part, unsigned long& longestLine) const; + unsigned long KeepLinesTogether(const vector& root, vector& part, + unsigned long& longestLine) const; #endif /*! diff --git a/Common/src/geometry/CPhysicalGeometry.cpp b/Common/src/geometry/CPhysicalGeometry.cpp index ce9b771c50f5..e58ed07c76ed 100644 --- a/Common/src/geometry/CPhysicalGeometry.cpp +++ b/Common/src/geometry/CPhysicalGeometry.cpp @@ -7394,67 +7394,69 @@ vector CPhysicalGeometry::FetchFromOwners(const vector CPhysicalGeometry::LinkAnisotropicLines(const vector& adjwgt) const { - /*--- An edge at least this many times shorter than its element joins its points into a line. ---*/ +vector CPhysicalGeometry::LinkAnisotropicLines(const vector& adjwgt, + vector& lineEdge) const { + /*--- An edge at least this many times shorter than its element can join its points into a line. ---*/ constexpr idx_t LINE_WEIGHT = 4; const unsigned long firstIndex = CLinearPartitioner(Global_nPointDomain, 0).GetFirstIndexOnRank(rank); + const vector neighbor(adjacency.begin(), adjacency.end()); - /*--- Edges are ordered by weight, then by their end points, so every point picks the same edge its - * neighbour would and the links form a forest whose only cycles are mutual pairs. ---*/ - vector link(nPoint); + vector strongest(nPoint, 0); + for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) + for (auto k = xadj[iPoint]; k < xadj[iPoint + 1]; k++) + strongest[iPoint] = max(strongest[iPoint], static_cast(adjwgt[k])); + const auto neighborStrongest = FetchFromOwners(neighbor, strongest); + + /*--- An edge joins a line if it is the strongest at one end, or nearly so at both. Equal or + * slowly varying spacing then keeps a line whole instead of splitting it where weights tie. ---*/ + lineEdge.assign(adjacency.size(), 0); for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) { - const unsigned long iGlobal = firstIndex + iPoint; - link[iPoint] = iGlobal; - idx_t bestWeight = LINE_WEIGHT - 1; - unsigned long bestLo = 0, bestHi = 0; for (auto k = xadj[iPoint]; k < xadj[iPoint + 1]; k++) { - const auto jGlobal = static_cast(adjacency[k]); - const auto lo = min(iGlobal, jGlobal), hi = max(iGlobal, jGlobal); - const bool better = (adjwgt[k] > bestWeight) || - ((adjwgt[k] == bestWeight) && ((lo < bestLo) || ((lo == bestLo) && (hi < bestHi)))); - if (better) { - bestWeight = adjwgt[k]; - bestLo = lo; - bestHi = hi; - link[iPoint] = jGlobal; - } + const auto w = static_cast(adjwgt[k]); + if (w < static_cast(LINE_WEIGHT)) continue; + const bool strongestAtEnd = (w == strongest[iPoint]) || (w == neighborStrongest[k]); + const bool strongAtBoth = (2 * w >= strongest[iPoint]) && (2 * w >= neighborStrongest[k]); + lineEdge[k] = strongestAtEnd || strongAtBoth; } } - return link; -} - -unsigned long CPhysicalGeometry::KeepLinesTogether(vector link, vector& part, - unsigned long& longestLine) const { - CLinearPartitioner pointPartitioner(Global_nPointDomain, 0); - const unsigned long firstIndex = pointPartitioner.GetFirstIndexOnRank(rank); - /*--- The lower point of a mutual pair becomes the root of its line. ---*/ - { - const auto linkOfLink = FetchFromOwners(link, link); - for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) { - const unsigned long iGlobal = firstIndex + iPoint; - if ((linkOfLink[iPoint] == iGlobal) && (iGlobal < link[iPoint])) link[iPoint] = iGlobal; - } - } - - /*--- Pointer jumping links every point to the root of its line. ---*/ + /*--- Each line is named by its lowest global index, found by propagating labels along the line + * edges and pointer jumping. ---*/ + vector root(nPoint); + for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) root[iPoint] = firstIndex + iPoint; for (;;) { - const auto linkOfLink = FetchFromOwners(link, link); unsigned long changed = 0, changedGlobal = 0; + const auto neighborRoot = FetchFromOwners(neighbor, root); for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) { - if (linkOfLink[iPoint] != link[iPoint]) { - link[iPoint] = linkOfLink[iPoint]; + for (auto k = xadj[iPoint]; k < xadj[iPoint + 1]; k++) { + if (lineEdge[k] && (neighborRoot[k] < root[iPoint])) { + root[iPoint] = neighborRoot[k]; + changed++; + } + } + } + const auto rootOfRoot = FetchFromOwners(root, root); + for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) { + if (rootOfRoot[iPoint] < root[iPoint]) { + root[iPoint] = rootOfRoot[iPoint]; changed++; } } SU2_MPI::Allreduce(&changed, &changedGlobal, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm()); if (changedGlobal == 0) break; } + return root; +} + +unsigned long CPhysicalGeometry::KeepLinesTogether(const vector& root, vector& part, + unsigned long& longestLine) const { + CLinearPartitioner pointPartitioner(Global_nPointDomain, 0); + const unsigned long firstIndex = pointPartitioner.GetFirstIndexOnRank(rank); /*--- The owner of each root counts in which partitions its line lies. ---*/ vector nSend(size, 0), nRecv(size), sendDisp(size + 1, 0), recvDisp(size + 1, 0); - for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) nSend[pointPartitioner.GetRankContainingIndex(link[iPoint])] += 2; + for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) nSend[pointPartitioner.GetRankContainingIndex(root[iPoint])] += 2; SU2_MPI::Alltoall(nSend.data(), 1, MPI_INT, nRecv.data(), 1, MPI_INT, SU2_MPI::GetComm()); for (int iRank = 0; iRank < size; iRank++) { sendDisp[iRank + 1] = sendDisp[iRank] + nSend[iRank]; @@ -7463,8 +7465,8 @@ unsigned long CPhysicalGeometry::KeepLinesTogether(vector link, v vector sendBuf(sendDisp[size]), recvBuf(recvDisp[size]); vector next(sendDisp.begin(), sendDisp.end() - 1); for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) { - auto& slot = next[pointPartitioner.GetRankContainingIndex(link[iPoint])]; - sendBuf[slot++] = link[iPoint]; + auto& slot = next[pointPartitioner.GetRankContainingIndex(root[iPoint])]; + sendBuf[slot++] = root[iPoint]; sendBuf[slot++] = static_cast(part[iPoint]); } SU2_MPI::Alltoallv(sendBuf.data(), nSend.data(), sendDisp.data(), MPI_UNSIGNED_LONG, recvBuf.data(), nRecv.data(), @@ -7495,7 +7497,7 @@ unsigned long CPhysicalGeometry::KeepLinesTogether(vector link, v } /*--- Every point takes the partition of its line, unless that would leave a rank without points. ---*/ - const auto chosen = FetchFromOwners(link, decision); + const auto chosen = FetchFromOwners(root, decision); vector count(size, 0), countGlobal(size); for (const auto iPart : chosen) count[iPart]++; SU2_MPI::Allreduce(count.data(), countGlobal.data(), size, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm()); @@ -7675,20 +7677,14 @@ void CPhysicalGeometry::SetColorGrid_Parallel(const CConfig* config) { const bool anisotropic = config->GetParMETIS_AnisotropyWeight(); vector adjwgt; - vector lineLink; + vector lineRoot; if (anisotropic) { constexpr long maxWeight = (sizeof(idx_t) >= 8) ? 1000000 : 1000; adjwgt = ComputeAnisotropyEdgeWeights(maxWeight); - lineLink = LinkAnisotropicLines(adjwgt); - - const vector neighbor(adjacency.begin(), adjacency.end()); - const auto neighborLink = FetchFromOwners(neighbor, lineLink); - const unsigned long firstIndex = pointPartitioner.GetFirstIndexOnRank(rank); - for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) { - for (auto k = xadj[iPoint]; k < xadj[iPoint + 1]; k++) { - if ((lineLink[iPoint] == neighbor[k]) || (neighborLink[k] == firstIndex + iPoint)) adjwgt[k] = maxWeight; - } - } + vector lineEdge; + lineRoot = LinkAnisotropicLines(adjwgt, lineEdge); + for (auto k = 0ul; k < adjwgt.size(); k++) + if (lineEdge[k]) adjwgt[k] = maxWeight; wgtflag = 3; } @@ -7714,7 +7710,7 @@ void CPhysicalGeometry::SetColorGrid_Parallel(const CConfig* config) { if (anisotropic) { unsigned long longestLine = 0; - const auto moved = KeepLinesTogether(lineLink, part, longestLine); + const auto moved = KeepLinesTogether(lineRoot, part, longestLine); /*--- The imbalance is measured in the vertex weights ParMETIS balances. ---*/ vector load(size, 0), loadGlobal(size); for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) load[part[iPoint]] += vwgt[iPoint]; diff --git a/SU2_CFD/include/solvers/CSolver.hpp b/SU2_CFD/include/solvers/CSolver.hpp index acc465282064..7a3200a11290 100644 --- a/SU2_CFD/include/solvers/CSolver.hpp +++ b/SU2_CFD/include/solvers/CSolver.hpp @@ -84,6 +84,7 @@ class CSolver { /*--- State of CFL_ADAPT_RESIDUAL, a negative ceiling or cap means none is active. ---*/ vector ResTrend_History; /*!< \brief Recent mean log residuals. */ vector> ResJump_History; /*!< \brief Recent log residuals of the flow variables. */ + vector ResFlow_History; /*!< \brief Recent mean log residuals of the flow variables. */ bool ResTrend_Increase = false; /*!< \brief The residual trend allows a larger CFL. */ bool ResTrend_Reduce = false; /*!< \brief The residual trend requires a smaller CFL. */ passivedouble ResTrend_Best = 1e30; /*!< \brief Lowest mean log residual so far. */ @@ -94,6 +95,7 @@ class CSolver { vector CFL_EventValues; /*!< \brief CFL at each cut. */ unsigned long CFL_LastEvent = 0; /*!< \brief Iteration of the last cut. */ unsigned long CFL_LastStagnation = 0; /*!< \brief Iteration of the last stagnation cap. */ + unsigned long CFL_LastFrozen = 0; /*!< \brief Iteration of the last frozen-residual cap. */ unsigned short nVar, /*!< \brief Number of variables of the problem. */ nPrimVar, /*!< \brief Number of primitive variables of the problem. */ nPrimVarGrad, /*!< \brief Number of primitive variables of the problem in the gradient computation. */ diff --git a/SU2_CFD/src/solvers/CSolver.cpp b/SU2_CFD/src/solvers/CSolver.cpp index cfa04cd8b63a..4f7cfaf0ff2c 100644 --- a/SU2_CFD/src/solvers/CSolver.cpp +++ b/SU2_CFD/src/solvers/CSolver.cpp @@ -1915,8 +1915,9 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, * not depend on how many ranks split the preconditioner. The finest grid decides for all levels. ---*/ if (config->GetCFL_AdaptResidual()) { - constexpr size_t trendWindow = 5, jumpWindow = 3; - constexpr passivedouble growBelow = 0.01, shrinkAbove = 0.03, jumpAbove = 0.75; + constexpr size_t trendWindow = 5, jumpWindow = 3, spikeWindow = 5, frozenWindow = 30; + constexpr passivedouble growBelow = 0.01, shrinkAbove = 0.03, jumpAbove = 0.75, spikeAbove = 1.0; + constexpr passivedouble frozenSpread = 0.01, frozenCut = 0.6; constexpr passivedouble linearBrake = 0.5, linearFailure = 0.8; constexpr unsigned long stagnationIters = 150, quietIters = 20; @@ -1937,15 +1938,42 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, for (auto iVar = 0u; iVar < solverFlow->GetnVar(); iVar++) logRes[iVar] = log10(SU2_TYPE::GetValue(solverFlow->GetRes_RMS(iVar))); ResJump_History.push_back(logRes); - if (ResJump_History.size() > jumpWindow + 1) ResJump_History.erase(ResJump_History.begin()); + if (ResJump_History.size() > spikeWindow + 1) ResJump_History.erase(ResJump_History.begin()); bool jump = false; if (ResJump_History.size() > jumpWindow) { + const auto& past = ResJump_History[ResJump_History.size() - 1 - jumpWindow]; vector rise(logRes.size()); - for (auto iVar = 0u; iVar < logRes.size(); iVar++) rise[iVar] = logRes[iVar] - ResJump_History.front()[iVar]; + for (auto iVar = 0u; iVar < logRes.size(); iVar++) rise[iVar] = logRes[iVar] - past[iVar]; sort(rise.begin(), rise.end()); const auto n = rise.size(); jump = (0.5 * (rise[(n - 1) / 2] + rise[n / 2]) > jumpAbove); } + /*--- A spike in a single equation, such as the energy at a stagnation corner, is the first sign of + * a CFL that is too high even when the other residuals do not move. ---*/ + if (ResJump_History.size() > spikeWindow) { + for (auto iVar = 0u; iVar < logRes.size(); iVar++) + jump = jump || (logRes[iVar] - ResJump_History.front()[iVar] > spikeAbove); + } + + /*--- Flow residuals that stop moving at a high CFL are stuck, not converging: the turbulence + * residual may still fall, so it is left out of this test. ---*/ + passivedouble flowMean = 0.0; + for (const auto value : logRes) flowMean += value / logRes.size(); + ResFlow_History.push_back(flowMean); + if (ResFlow_History.size() > frozenWindow + 1) ResFlow_History.erase(ResFlow_History.begin()); + const bool frozen = (ResFlow_History.size() > frozenWindow) && (iter >= startingIter + frozenWindow) && + (*max_element(ResFlow_History.begin(), ResFlow_History.end()) - + *min_element(ResFlow_History.begin(), ResFlow_History.end()) < + frozenSpread) && + (iter > CFL_LastEvent + frozenWindow) && (iter > CFL_LastFrozen + frozenWindow); + if (frozen) { + CFL_Cap = frozenCut * ((CFL_Cap > 0.0) ? min(CFL_Cap, avgCFL) : avgCFL); + CFL_Ceiling = CFL_Cap; + CFL_LastFrozen = iter; + if (rank == MASTER_NODE) + cout << "CFL_ADAPT_RESIDUAL: flow residuals frozen at iteration " << iter << ", CFL capped at " << CFL_Cap + << "." << endl; + } /*--- Halve the CFL on a jump or a failed linear solve and keep it below a ceiling. A second event * near the CFL of an earlier one sets a lasting cap below both. ---*/ From e2e83b67dbb19781ef3e1209cfd1626775758b25 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sun, 4 Oct 2026 09:30:19 +0200 Subject: [PATCH 10/42] precommit --- Common/include/linear_algebra/CSysSolve.hpp | 4 +-- Common/src/geometry/CMultiGridGeometry.cpp | 3 +- Common/src/geometry/CPhysicalGeometry.cpp | 34 ++++++++++----------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Common/include/linear_algebra/CSysSolve.hpp b/Common/include/linear_algebra/CSysSolve.hpp index 4d5aea756dd5..98ab059804ce 100644 --- a/Common/include/linear_algebra/CSysSolve.hpp +++ b/Common/include/linear_algebra/CSysSolve.hpp @@ -109,8 +109,8 @@ class CSysSolve { mutable VectorType p; /*!< \brief Direction in CG and BCGSTAB. */ mutable VectorType z; /*!< \brief Preconditioned residual/direction in CG/BCGSTAB. */ - mutable VectorType r_0; /*!< \brief The "arbitrary" vector in BCGSTAB. */ - mutable VectorType v; /*!< \brief BCGSTAB "v" vector (v = A * M^-1 * p). */ + mutable VectorType r_0; /*!< \brief The "arbitrary" vector in BCGSTAB. */ + mutable VectorType v; /*!< \brief BCGSTAB "v" vector (v = A * M^-1 * p). */ mutable VectorType x_best; /*!< \brief BCGSTAB iterate with the smallest residual. */ mutable bool ritz_failed = false; diff --git a/Common/src/geometry/CMultiGridGeometry.cpp b/Common/src/geometry/CMultiGridGeometry.cpp index 88652e262d39..317c730fc88a 100644 --- a/Common/src/geometry/CMultiGridGeometry.cpp +++ b/Common/src/geometry/CMultiGridGeometry.cpp @@ -660,8 +660,7 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un * a tie, NO_CV if there is none. A compact merge must join the two through at least as many fine * edges as the smaller one has children. Neighbours an earlier merge in the same pass emptied are * not revived. ---*/ - auto bestPartner = [&](unsigned long iCV, unsigned short maxPartnerSize, bool keepOffPartition, - bool compact) { + auto bestPartner = [&](unsigned long iCV, unsigned short maxPartnerSize, bool keepOffPartition, bool compact) { auto best = NO_CV; auto best_nChildren = std::numeric_limits::max(); su2double best_area = -1.0; diff --git a/Common/src/geometry/CPhysicalGeometry.cpp b/Common/src/geometry/CPhysicalGeometry.cpp index e58ed07c76ed..456d96b2757d 100644 --- a/Common/src/geometry/CPhysicalGeometry.cpp +++ b/Common/src/geometry/CPhysicalGeometry.cpp @@ -2426,9 +2426,9 @@ void CPhysicalGeometry::LoadSurfaceElements(CConfig* config, CGeometry* geometry unsigned long Local_Nodes[N_POINTS_HEXAHEDRON]; - vector > Line_List; - vector > BoundTria_List; - vector > BoundQuad_List; + vector> Line_List; + vector> BoundTria_List; + vector> BoundQuad_List; vector Marker_Local; @@ -2967,14 +2967,14 @@ void CPhysicalGeometry::SetSendReceive(const CConfig* config) { unsigned short iNode, jNode; vector::iterator it; - vector > + vector> SendTransfLocal; /*!< \brief Vector to store the type of transformation for this send point. */ - vector > + vector> ReceivedTransfLocal; /*!< \brief Vector to store the type of transformation for this received point. */ - vector > SendDomainLocal; /*!< \brief SendDomain[from domain][to domain] and return the point - index of the node that must me sended. */ - vector > ReceivedDomainLocal; /*!< \brief SendDomain[from domain][to domain] and return the - point index of the node that must me sended. */ + vector> SendDomainLocal; /*!< \brief SendDomain[from domain][to domain] and return the point + index of the node that must me sended. */ + vector> ReceivedDomainLocal; /*!< \brief SendDomain[from domain][to domain] and return the + point index of the node that must me sended. */ unordered_map::const_iterator MI; @@ -4426,7 +4426,7 @@ void CPhysicalGeometry::SetPositive_ZArea(CConfig* config) { } void CPhysicalGeometry::SetPoint_Connectivity() { - vector > points(nPoint); + vector> points(nPoint); SU2_OMP_PARALLEL { unsigned short Node_Neighbor, iNode, iNeighbor; @@ -4434,7 +4434,7 @@ void CPhysicalGeometry::SetPoint_Connectivity() { /*--- Loop over all the elements ---*/ BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { - vector > elems(nPoint); + vector> elems(nPoint); for (iElem = 0; iElem < nElem; iElem++) { /*--- Loop over all the nodes of an element ---*/ @@ -7382,8 +7382,8 @@ vector CPhysicalGeometry::FetchFromOwners(const vector reply(recvIndex.size()), answer(sendIndex.size()), result(wanted.size()); for (auto k = 0ul; k < recvIndex.size(); k++) reply[k] = localValue[recvIndex[k] - firstIndex]; @@ -7549,9 +7549,8 @@ vector CPhysicalGeometry::ComputeAnisotropyEdgeWeights(long maxWeight) co sendIndex.reserve(sendDisp[size]); for (const auto& list : request) sendIndex.insert(sendIndex.end(), list.begin(), list.end()); - SU2_MPI::Alltoallv(sendIndex.data(), nSend.data(), sendDisp.data(), MPI_UNSIGNED_LONG, recvIndex.data(), - nRecv.data(), recvDisp.data(), MPI_UNSIGNED_LONG, SU2_MPI::GetComm()); - + SU2_MPI::Alltoallv(sendIndex.data(), nSend.data(), sendDisp.data(), MPI_UNSIGNED_LONG, recvIndex.data(), nRecv.data(), + recvDisp.data(), MPI_UNSIGNED_LONG, SU2_MPI::GetComm()); vector replyCoord(recvIndex.size() * nDim), remoteCoord(sendIndex.size() * nDim); for (auto i = 0ul; i < recvIndex.size(); i++) @@ -7701,8 +7700,7 @@ void CPhysicalGeometry::SetColorGrid_Parallel(const CConfig* config) { tpwgts.data(), &ubvec, options, &edgecut, part.data(), &comm); if (err != METIS_OK) SU2_MPI::Error("Partitioning failed.", CURRENT_FUNCTION); if (rank == MASTER_NODE) { - cout << " graph partitioning complete (" << edgecut << (anisotropic ? " weighted" : "") << " edge cuts)." - << endl; + cout << " graph partitioning complete (" << edgecut << (anisotropic ? " weighted" : "") << " edge cuts)." << endl; } /*--- A line split between ranks loses its strongest couplings in the preconditioner, and its From 2f533490e17c405c714127c18cf0bd3820469e17 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Mon, 12 Oct 2026 09:22:22 +0200 Subject: [PATCH 11/42] huge update --- Common/include/CConfig.hpp | 2 - Common/src/CConfig.cpp | 8 +- Common/src/geometry/CMultiGridGeometry.cpp | 2 +- .../integration/CMultiGridIntegration.hpp | 9 +- SU2_CFD/include/solvers/CSolver.hpp | 17 +- SU2_CFD/include/variables/CEulerVariable.hpp | 5 + .../src/integration/CMultiGridIntegration.cpp | 79 ++++++- SU2_CFD/src/solvers/CEulerSolver.cpp | 9 + SU2_CFD/src/solvers/CSolver.cpp | 200 ++++++++++++++---- SU2_CFD/src/variables/CEulerVariable.cpp | 1 + config_template.cfg | 24 ++- 11 files changed, 282 insertions(+), 74 deletions(-) diff --git a/Common/include/CConfig.hpp b/Common/include/CConfig.hpp index 69de97b6eea3..b8906156f83e 100644 --- a/Common/include/CConfig.hpp +++ b/Common/include/CConfig.hpp @@ -842,7 +842,6 @@ class CConfig { unsigned short nCFL_AdaptParam; /*!< \brief Number of CFL parameters provided in config. */ unsigned long outlierMitigationParam[4]; /*!< \brief Parameters of outlier mitigation strategy. */ bool CFL_Adapt; /*!< \brief Use adaptive CFL number. */ - bool CFL_AdaptResidual; /*!< \brief Adapt the CFL on the nonlinear residual trend instead of the linear solve. */ bool HB_Precondition; /*!< \brief Flag to turn on harmonic balance source term preconditioning */ su2double RefArea, /*!< \brief Reference area for coefficient computation. */ RefElemLength, /*!< \brief Reference element length for computing the slope limiting epsilon. */ @@ -1756,7 +1755,6 @@ class CConfig { /*! * \brief Whether the adaptive CFL follows the nonlinear residual trend instead of the linear solve. */ - bool GetCFL_AdaptResidual(void) const { return CFL_AdaptResidual; } /*! * \brief Get the outlier mitigation parameters. diff --git a/Common/src/CConfig.cpp b/Common/src/CConfig.cpp index 3fd872d1acd8..00f336540214 100644 --- a/Common/src/CConfig.cpp +++ b/Common/src/CConfig.cpp @@ -1906,7 +1906,6 @@ void CConfig::SetConfig_Options() { /* DESCRIPTION: Activate The adaptive CFL number. */ addBoolOption("CFL_ADAPT", CFL_Adapt, false); /* DESCRIPTION: Adapt the CFL on the finest-grid nonlinear residuals instead of the linear solve, with a cut on divergence. */ - addBoolOption("CFL_ADAPT_RESIDUAL", CFL_AdaptResidual, false); /* !\brief CFL_ADAPT_PARAM * DESCRIPTION: Parameters of the adaptive CFL number (factor down, factor up, CFL limit (min and max)[, acceptable linear residual][, starting iteration]). * Parameters in square brackets are optional, parameter "starting iteration" only valid with parameter "acceptable linear residual". @@ -2159,7 +2158,8 @@ void CConfig::SetConfig_Options() { /*!\brief MUSCL_FLOW \n DESCRIPTION: Check if the MUSCL scheme should be used \ingroup Config*/ addBoolOption("MUSCL_FLOW", MUSCL_Flow, true); /*!\brief MUSCL_FIRST_ORDER_WALL_ENDS \n DESCRIPTION: Reconstruct the flow to first order on the edges of points - * where a no-slip wall ends on a boundary continuing its surface, or has a sharp edge such as a trailing edge \ingroup Config*/ + * where a no-slip wall ends on a boundary continuing its surface, or has a sharp edge such as a trailing edge, and + * skip the multigrid correction of the flow there \ingroup Config*/ addBoolOption("MUSCL_FIRST_ORDER_WALL_ENDS", MUSCL_FirstOrderWallEnds, false); /*!\brief MUSCL_KAPPA_FLOW \n DESCRIPTION: Blending coefficient for the U-MUSCL scheme \ingroup Config*/ addDoubleOption("MUSCL_KAPPA_FLOW", MUSCL_Kappa_Flow, 0.0); @@ -5846,10 +5846,6 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i /* Protect against using CFL adaption for non-flow or certain unsteady flow problems. */ - if (CFL_AdaptResidual && OptionIsSet("OUTLIER_MITIGATION_PARAM")) { - SU2_MPI::Error("CFL_ADAPT_RESIDUAL cannot be combined with OUTLIER_MITIGATION_PARAM.", CURRENT_FUNCTION); - } - if (CFL_Adapt && !GetFluidProblem()) { SU2_MPI::Error(string("CFL adaption only available for finite-volume fluid solvers.\n") + string("Please select CFL_ADAPT = NO."), diff --git a/Common/src/geometry/CMultiGridGeometry.cpp b/Common/src/geometry/CMultiGridGeometry.cpp index 317c730fc88a..7a6add0f18d7 100644 --- a/Common/src/geometry/CMultiGridGeometry.cpp +++ b/Common/src/geometry/CMultiGridGeometry.cpp @@ -2159,7 +2159,7 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co if (admissible(best)) { candidates.push_back(best); - stepDir.push_back(bestStep); + stepDir.push_back(marching); } else if (!fine_grid->nodes->GetDomain(best) && (haloSlot[best] >= 0) && (haloClaim[best] == NO_COLUMN)) { haloWanted.push_back(best); diff --git a/SU2_CFD/include/integration/CMultiGridIntegration.hpp b/SU2_CFD/include/integration/CMultiGridIntegration.hpp index 155f98523d38..02486516d584 100644 --- a/SU2_CFD/include/integration/CMultiGridIntegration.hpp +++ b/SU2_CFD/include/integration/CMultiGridIntegration.hpp @@ -104,10 +104,12 @@ class CMultiGridIntegration final : public CIntegration { /*! * \brief Set the value of the corrected fine grid solution. * \param[out] sol_fine - Pointer to the solution on the fine grid. + * \param[in] sol_flow - Flow solver on the fine grid, which flags the points that get no correction. * \param[in] geo_fine - Geometrical definition of the fine grid. * \param[in] config - Definition of the particular problem. */ - void SetProlongated_Correction(CSolver *sol_fine, CGeometry *geo_fine, CConfig *config, unsigned short iMesh); + void SetProlongated_Correction(CSolver *sol_fine, CSolver *sol_flow, CGeometry *geo_fine, CConfig *config, + unsigned short iMesh); /*! * \brief Compute the gradient in coarse grid using the fine grid information. @@ -386,6 +388,11 @@ class CMultiGridIntegration final : public CIntegration { * Allocated on first use, only when MG_LINEAR_PROLONGATION is on. */ vector prolongGradient; + /*! \brief Coarse cells per level whose gradient fit is too ill-conditioned and keep the constant + * operator, and whether that level has been reported. */ + unsigned long prolongIllConditioned[MAX_MG_LEVELS + 1] = {}; + bool prolongReported[MAX_MG_LEVELS + 1] = {}; + vector mg_startup_conv_start; /*!< \brief Field values when the active level became active. */ vector mg_startup_conv_prev; /*!< \brief Field values on the previous iteration. */ unsigned long mg_startup_stall_count = 0; /*!< \brief Consecutive iterations without useful reduction. */ diff --git a/SU2_CFD/include/solvers/CSolver.hpp b/SU2_CFD/include/solvers/CSolver.hpp index 7a3200a11290..9a964e246108 100644 --- a/SU2_CFD/include/solvers/CSolver.hpp +++ b/SU2_CFD/include/solvers/CSolver.hpp @@ -81,21 +81,28 @@ class CSolver { vector NonLinRes_Series; /*!< \brief Vector holding the nonlinear residual indicator series. */ su2double Old_Func, /*!< \brief Old value of the nonlinear residual indicator. */ New_Func; /*!< \brief Current value of the nonlinear residual indicator. */ - /*--- State of CFL_ADAPT_RESIDUAL, a negative ceiling or cap means none is active. ---*/ + /*--- State of the residual-driven CFL adaption, a negative ceiling or cap means none is active. ---*/ vector ResTrend_History; /*!< \brief Recent mean log residuals. */ vector> ResJump_History; /*!< \brief Recent log residuals of the flow variables. */ - vector ResFlow_History; /*!< \brief Recent mean log residuals of the flow variables. */ + vector> ResFlow_History; /*!< \brief Recent log residuals of the flow variables. */ + vector ResMean_History; /*!< \brief Recent mean log residuals of the flow variables. */ + passivedouble ResRise = 0.0; /*!< \brief Rise of the flow residual above its recent best. */ + unsigned long CFL_LastFlip = 0; /*!< \brief Iteration of the last flip-flop. */ + unsigned long CFL_LastRegress = 0; /*!< \brief Iteration of the last residual regression. */ bool ResTrend_Increase = false; /*!< \brief The residual trend allows a larger CFL. */ bool ResTrend_Reduce = false; /*!< \brief The residual trend requires a smaller CFL. */ - passivedouble ResTrend_Best = 1e30; /*!< \brief Lowest mean log residual so far. */ - unsigned long ResTrend_LastBest = 0; /*!< \brief Iteration of that minimum. */ bool CFL_Cut = false; /*!< \brief Halve the CFL in this update. */ passivedouble CFL_Ceiling = -1.0; /*!< \brief Temporary ceiling after a cut. */ passivedouble CFL_Cap = -1.0; /*!< \brief Lasting limit learned from repeated events. */ vector CFL_EventValues; /*!< \brief CFL at each cut. */ unsigned long CFL_LastEvent = 0; /*!< \brief Iteration of the last cut. */ - unsigned long CFL_LastStagnation = 0; /*!< \brief Iteration of the last stagnation cap. */ + unsigned long CFL_LastCapProbe = 0; /*!< \brief Iteration of the last cap increase. */ unsigned long CFL_LastFrozen = 0; /*!< \brief Iteration of the last frozen-residual cap. */ + vector> ResStall_History; /*!< \brief Log flow residuals over two stall windows. */ + vector CFLStall_History; /*!< \brief Mean CFL over two stall windows. */ + unsigned long Stall_Streak = 0; /*!< \brief Consecutive iterations without envelope progress. */ + unsigned long CFL_LastStall = 0; /*!< \brief Iteration of the last stall cap. */ + passivedouble CFL_StallValue = -1.0; /*!< \brief Lowest CFL at which the residuals stalled. */ unsigned short nVar, /*!< \brief Number of variables of the problem. */ nPrimVar, /*!< \brief Number of primitive variables of the problem. */ nPrimVarGrad, /*!< \brief Number of primitive variables of the problem in the gradient computation. */ diff --git a/SU2_CFD/include/variables/CEulerVariable.hpp b/SU2_CFD/include/variables/CEulerVariable.hpp index 2bc1fa7d9ca7..2466d6e61698 100644 --- a/SU2_CFD/include/variables/CEulerVariable.hpp +++ b/SU2_CFD/include/variables/CEulerVariable.hpp @@ -379,4 +379,9 @@ class CEulerVariable : public CFlowVariable { */ su2vector FirstOrderReconstruction; + /*! + * \brief Points, and their neighbours, where the multigrid correction is not prolongated (1), others (0). + */ + su2vector SkipMGCorrection; + }; diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index b6908a389b92..4311b8103bb7 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -30,6 +30,7 @@ #include "../../../Common/include/toolboxes/printing_toolbox.hpp" #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" #include +#include "../../include/variables/CEulerVariable.hpp" namespace { @@ -736,7 +737,7 @@ void CMultiGridIntegration::MultiGrid_Cycle(CGeometry ****geometry, const auto& mgOpts = config->GetMGOptions(); SmoothProlongated_Correction(RunTime_EqSystem, solver_fine, geometry_fine, mgOpts.MG_CorrecSmooth[iMesh], mgOpts.MG_Smooth_Coeff, config, iMesh); - SetProlongated_Correction(solver_fine, geometry_fine, config, iMesh); + SetProlongated_Correction(solver_fine, solver_container_fine[FLOW_SOL], geometry_fine, config, iMesh); /*--- Solution post-smoothing in the prolongated grid. ---*/ @@ -1059,6 +1060,42 @@ void CMultiGridIntegration::GetProlongated_Correction(unsigned short RunTime_EqS } +/*--- Largest condition number of the prolongation gradient fit that is still trusted. ---*/ +static constexpr passivedouble PROLONG_MAX_CONDITION = 1e5; + +namespace { +/*--- Condition number of a symmetric 2x2 or 3x3 matrix, infinite if it is not positive definite. ---*/ +passivedouble FitConditionNumber(unsigned short nDim, const su2double A[3][3]) { + constexpr passivedouble big = 1e300; + passivedouble lmin, lmax; + if (nDim == 2) { + const passivedouble a = SU2_TYPE::GetValue(A[0][0]), b = SU2_TYPE::GetValue(A[0][1]), d = SU2_TYPE::GetValue(A[1][1]); + const passivedouble mean = 0.5 * (a + d), radius = sqrt(0.25 * (a - d) * (a - d) + b * b); + lmin = mean - radius; + lmax = mean + radius; + } else { + passivedouble M[3][3]; + for (auto i = 0u; i < 3; ++i) + for (auto j = 0u; j < 3; ++j) M[i][j] = SU2_TYPE::GetValue(A[i][j]); + const passivedouble q = (M[0][0] + M[1][1] + M[2][2]) / 3.0; + const passivedouble p1 = M[0][1] * M[0][1] + M[0][2] * M[0][2] + M[1][2] * M[1][2]; + const passivedouble p2 = pow(M[0][0] - q, 2) + pow(M[1][1] - q, 2) + pow(M[2][2] - q, 2) + 2.0 * p1; + const passivedouble p = sqrt(p2 / 6.0); + if (p <= 0.0) return (q > 0.0) ? 1.0 : big; + passivedouble B[3][3]; + for (auto i = 0u; i < 3; ++i) + for (auto j = 0u; j < 3; ++j) B[i][j] = (M[i][j] - ((i == j) ? q : 0.0)) / p; + const passivedouble detB = B[0][0] * (B[1][1] * B[2][2] - B[1][2] * B[2][1]) - + B[0][1] * (B[1][0] * B[2][2] - B[1][2] * B[2][0]) + + B[0][2] * (B[1][0] * B[2][1] - B[1][1] * B[2][0]); + const passivedouble phi = acos(max(-1.0, min(1.0, 0.5 * detB))) / 3.0; + lmax = q + 2.0 * p * cos(phi); + lmin = q + 2.0 * p * cos(phi + 2.0 * M_PI / 3.0); + } + return (lmin > 0.0) ? lmax / lmin : big; +} +} // namespace + void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGeometry *geo_coarse, CGeometry *geo_fine, const CConfig *config, unsigned short iMesh) { @@ -1071,7 +1108,31 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe /*--- Every thread of this rank takes this branch together, and the loops below would all be * empty anyway. It also keeps the sizing test off a container that was never resized. ---*/ - if (nPointDomain == 0) return; + /*--- The coarse grid does not change, so each level is reported once. ---*/ + auto reportIllConditioned = [&]() { + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS + { + if (!prolongReported[iMesh]) { + prolongReported[iMesh] = true; + unsigned long local[2] = {prolongIllConditioned[iMesh], nPointDomain}, global[2] = {0, 0}; + SU2_MPI::Allreduce(local, global, 2, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm()); + if ((global[0] > 0) && (SU2_MPI::GetRank() == MASTER_NODE)) + cout << "MG level " << iMesh << ": linear prolongation keeps the constant operator in " << global[0] + << " of " << global[1] << " coarse cells (gradient fit condition number above " + << PROLONG_MAX_CONDITION << ")." << endl; + } + } + END_SU2_OMP_SAFE_GLOBAL_ACCESS + }; + + if (nPointDomain == 0) { + reportIllConditioned(); + return; + } + + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS + { prolongIllConditioned[iMesh] = 0; } + END_SU2_OMP_SAFE_GLOBAL_ACCESS BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { @@ -1114,6 +1175,14 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe } } + /*--- On a strongly stretched agglomerate the fit cannot tell the slopes apart, so the cell keeps the + * constant operator. ---*/ + if (FitConditionNumber(nDim, Amat) > PROLONG_MAX_CONDITION) { + SU2_OMP_ATOMIC + prolongIllConditioned[iMesh]++; + continue; + } + su2double Ainv[MAXNDIM][MAXNDIM] = {{0.0}}; if (!invertLeastSquaresMatrix(nDim, Amat, Ainv)) continue; @@ -1204,6 +1273,7 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe } END_SU2_OMP_FOR + reportIllConditioned(); } void CMultiGridIntegration::SmoothProlongated_Correction(unsigned short RunTime_EqSystem, CSolver *solver, CGeometry *geometry, @@ -1293,7 +1363,7 @@ void CMultiGridIntegration::SmoothProlongated_Correction(unsigned short RunTime_ } } -void CMultiGridIntegration::SetProlongated_Correction(CSolver *sol_fine, CGeometry *geo_fine, +void CMultiGridIntegration::SetProlongated_Correction(CSolver *sol_fine, CSolver *sol_flow, CGeometry *geo_fine, CConfig *config, unsigned short iMesh) { SU2_ZONE_SCOPED @@ -1301,9 +1371,12 @@ void CMultiGridIntegration::SetProlongated_Correction(CSolver *sol_fine, CGeomet /*--- Use the adaptive damping factor uniformly across all prolongation levels. ---*/ const su2double factor = config->GetDamp_Correc_Prolong(); + const auto* flowNodes = sol_flow ? dynamic_cast(sol_flow->GetNodes()) : nullptr; + const bool skipHere = flowNodes && (sol_fine == sol_flow); SU2_OMP_FOR_STAT(roundUpDiv(geo_fine->GetnPointDomain(), omp_get_num_threads())) for (auto Point_Fine = 0ul; Point_Fine < geo_fine->GetnPointDomain(); Point_Fine++) { + if (skipHere && flowNodes->SkipMGCorrection(Point_Fine)) continue; auto* Residual_Fine = sol_fine->LinSysRes.GetBlock(Point_Fine); auto* Solution_Fine = sol_fine->GetNodes()->GetSolution(Point_Fine); for (auto iVar = 0u; iVar < nVar; iVar++) { diff --git a/SU2_CFD/src/solvers/CEulerSolver.cpp b/SU2_CFD/src/solvers/CEulerSolver.cpp index 1d28f5d8dc71..207653b18637 100644 --- a/SU2_CFD/src/solvers/CEulerSolver.cpp +++ b/SU2_CFD/src/solvers/CEulerSolver.cpp @@ -395,6 +395,15 @@ CEulerSolver::CEulerSolver(CGeometry *geometry, CConfig *config, for (auto iVertex = 0ul; iVertex < geometry->nVertex[markerR]; iVertex++) nodes->FirstOrderReconstruction(geometry->vertex[markerR][iVertex]->GetNode()) = bufRecv[iVertex]; } + + /*--- The coarse grid cannot represent the singular flow there, its correction is not prolongated to + * those points and their neighbours. ---*/ + for (iPoint = 0; iPoint < nPointDomain; iPoint++) { + bool skip = nodes->FirstOrderReconstruction(iPoint); + for (auto iNeigh = 0u; !skip && (iNeigh < geometry->nodes->GetnPoint(iPoint)); iNeigh++) + skip = nodes->FirstOrderReconstruction(geometry->nodes->GetPoint(iPoint, iNeigh)); + nodes->SkipMGCorrection(iPoint) = skip; + } } /*--- Check that the initial solution is physical, report any non-physical nodes ---*/ diff --git a/SU2_CFD/src/solvers/CSolver.cpp b/SU2_CFD/src/solvers/CSolver.cpp index 156a4163127a..1fa62f455610 100644 --- a/SU2_CFD/src/solvers/CSolver.cpp +++ b/SU2_CFD/src/solvers/CSolver.cpp @@ -1911,15 +1911,23 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, } } - /*--- CFL_ADAPT_RESIDUAL: the finest-grid nonlinear residuals drive the CFL, so the decision does - * not depend on how many ranks split the preconditioner. The finest grid decides for all levels. ---*/ + /*--- The finest-grid nonlinear residuals drive the CFL, so the decision does not depend on how many + * ranks split the preconditioner. The finest grid decides for all levels. ---*/ - if (config->GetCFL_AdaptResidual()) { + if (!config->OptionIsSet("OUTLIER_MITIGATION_PARAM")) { constexpr size_t trendWindow = 5, jumpWindow = 3, spikeWindow = 5, frozenWindow = 30; constexpr passivedouble growBelow = 0.01, shrinkAbove = 0.03, jumpAbove = 0.75, spikeAbove = 1.0; - constexpr passivedouble frozenSpread = 0.01, frozenCut = 0.6; + constexpr passivedouble frozenSpread = 0.05, frozenProgress = 0.02, frozenCut = 0.6; constexpr passivedouble linearBrake = 0.5, linearFailure = 0.8; - constexpr unsigned long stagnationIters = 150, quietIters = 20; + constexpr unsigned long quietIters = 20, eventGap = 20, bestWindow = 100, regressGap = 5, regressEpisode = 30; + constexpr unsigned long capProbeQuiet = 50; + constexpr passivedouble capProbeFactor = 1.3, eventCapFactor = 0.8, eventMatch = 1.5, cutFactor = 0.7; + constexpr size_t flipWindow = 10, stuckWindow = 15; + constexpr passivedouble regressAbove = 1.0, regressCap = 0.3, growBelowBest = 0.5; + constexpr passivedouble stuckSpread = 0.15, flipAmplitude = 0.03, flipProgress = 0.15; + constexpr size_t stallWindow = 100; + constexpr unsigned long stallPersist = 20; + constexpr passivedouble stallProgress = 0.1, stallGrowth = 1.1, stallCut = 0.5, stallRoom = 0.8; if (iMesh == MESH_0) { const passivedouble avgCFL = SU2_TYPE::GetValue(Avg_CFL_Local); @@ -1955,61 +1963,160 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, jump = jump || (logRes[iVar] - ResJump_History.front()[iVar] > spikeAbove); } - /*--- Flow residuals that stop moving at a high CFL are stuck, not converging: the turbulence - * residual may still fall, so it is left out of this test. ---*/ - passivedouble flowMean = 0.0; - for (const auto value : logRes) flowMean += value / logRes.size(); - ResFlow_History.push_back(flowMean); + /*--- Flow residuals that all stop falling are stuck, not converging. The turbulence residual may + * still fall, so it is left out. The CFL cannot go below its lower limit, so nothing is done there. ---*/ + const passivedouble cflMin = SU2_TYPE::GetValue(CFLMin); + ResFlow_History.push_back(logRes); if (ResFlow_History.size() > frozenWindow + 1) ResFlow_History.erase(ResFlow_History.begin()); - const bool frozen = (ResFlow_History.size() > frozenWindow) && (iter >= startingIter + frozenWindow) && - (*max_element(ResFlow_History.begin(), ResFlow_History.end()) - - *min_element(ResFlow_History.begin(), ResFlow_History.end()) < - frozenSpread) && - (iter > CFL_LastEvent + frozenWindow) && (iter > CFL_LastFrozen + frozenWindow); + bool frozen = (ResFlow_History.size() > frozenWindow) && (iter >= startingIter + frozenWindow) && + (iter > CFL_LastEvent + frozenWindow) && (iter > CFL_LastFrozen + frozenWindow) && + (avgCFL > 1.05 * cflMin); + for (auto iVar = 0u; frozen && (iVar < logRes.size()); iVar++) { + passivedouble lowest = ResFlow_History.front()[iVar], highest = lowest; + for (const auto& past : ResFlow_History) { + lowest = min(lowest, past[iVar]); + highest = max(highest, past[iVar]); + } + frozen = (ResFlow_History.front()[iVar] - ResFlow_History.back()[iVar] < frozenProgress) && + (highest - lowest < frozenSpread); + } if (frozen) { - CFL_Cap = frozenCut * ((CFL_Cap > 0.0) ? min(CFL_Cap, avgCFL) : avgCFL); + CFL_Cap = max(frozenCut * ((CFL_Cap > 0.0) ? min(CFL_Cap, avgCFL) : avgCFL), cflMin); CFL_Ceiling = CFL_Cap; CFL_LastFrozen = iter; if (rank == MASTER_NODE) - cout << "CFL_ADAPT_RESIDUAL: flow residuals frozen at iteration " << iter << ", CFL capped at " << CFL_Cap + cout << "CFL_ADAPT: flow residuals frozen at iteration " << iter << ", CFL capped at " << CFL_Cap << "." << endl; } + /*--- A divergence that grows slowly never looks like a jump from one iteration to the next, so the + * flow residual is also compared with its best value of the last bestWindow iterations. A residual + * far above it that no longer moves is stuck at a CFL that is too high. ---*/ + passivedouble flowMean = 0.0; + for (const auto value : logRes) flowMean += value / logRes.size(); + if (iter >= startingIter) { + ResMean_History.push_back(flowMean); + if (ResMean_History.size() > bestWindow + 1) ResMean_History.erase(ResMean_History.begin()); + } + passivedouble best = flowMean; + for (const auto value : ResMean_History) best = min(best, value); + ResRise = (iter >= startingIter) ? flowMean - best : 0.0; + bool regress = (ResRise > regressAbove) && (iter >= CFL_LastEvent + regressGap); + if (!regress && (ResMean_History.size() >= stuckWindow) && (ResRise > regressAbove) && + (iter >= CFL_LastEvent + stuckWindow)) { + passivedouble lowest = ResMean_History.back(), highest = lowest; + for (auto k = ResMean_History.size() - stuckWindow; k < ResMean_History.size(); ++k) { + lowest = min(lowest, ResMean_History[k]); + highest = max(highest, ResMean_History[k]); + } + regress = (highest - lowest < stuckSpread); + } + + /*--- Most flow residuals that alternate up and down at every iteration without net progress are a + * flip-flop, which a CFL that is too high produces. ---*/ + bool flip = (ResFlow_History.size() > flipWindow) && (iter >= startingIter + flipWindow) && + (iter >= CFL_LastEvent + flipWindow) && (iter >= CFL_LastFlip + flipWindow); + if (flip) { + const auto nHist = ResFlow_History.size(); + unsigned short nAlternating = 0; + passivedouble progress = 0.0; + for (auto iVar = 0u; iVar < logRes.size(); iVar++) { + unsigned short nChanges = 0; + passivedouble amplitude = 0.0; + for (auto k = nHist - flipWindow; k < nHist; ++k) { + const auto d1 = ResFlow_History[k][iVar] - ResFlow_History[k - 1][iVar]; + amplitude += fabs(d1) / flipWindow; + if (k > nHist - flipWindow) { + const auto d0 = ResFlow_History[k - 1][iVar] - ResFlow_History[k - 2][iVar]; + if (d0 * d1 < 0.0) nChanges++; + } + } + if ((nChanges + 1 >= flipWindow - 1) && (amplitude > flipAmplitude)) nAlternating++; + progress += (ResFlow_History[nHist - 1 - flipWindow][iVar] - ResFlow_History.back()[iVar]) / logRes.size(); + } + flip = (nAlternating * 4 >= logRes.size() * 3) && (progress < flipProgress); + } + if (flip) CFL_LastFlip = iter; + + /*--- Residuals that stop falling while the CFL no longer grows are stalled by a CFL that is too + * high, whatever the shape of their oscillation. The upper envelope of each residual over a + * window is compared with that of the window before. ---*/ + ResStall_History.push_back(logRes); + CFLStall_History.push_back(avgCFL); + if (ResStall_History.size() > 2 * stallWindow) { + ResStall_History.erase(ResStall_History.begin()); + CFLStall_History.erase(CFLStall_History.begin()); + } + bool stall = false; + if ((ResStall_History.size() == 2 * stallWindow) && (iter >= startingIter + 2 * stallWindow) && + (iter >= max(CFL_LastEvent, CFL_LastStall) + stallWindow) && (avgCFL > 1.05 * cflMin)) { + passivedouble progress = 0.0; + for (auto iVar = 0u; iVar < logRes.size(); iVar++) { + passivedouble envOld = ResStall_History.front()[iVar], envNew = ResStall_History.back()[iVar]; + for (size_t k = 0; k < stallWindow; k++) { + envOld = max(envOld, ResStall_History[k][iVar]); + envNew = max(envNew, ResStall_History[k + stallWindow][iVar]); + } + progress += (envOld - envNew) / logRes.size(); + } + const bool cflFlat = (avgCFL < stallGrowth * CFLStall_History[stallWindow - 1]); + Stall_Streak = ((progress < stallProgress) && cflFlat) ? Stall_Streak + 1 : 0; + stall = (Stall_Streak >= stallPersist); + } else { + Stall_Streak = 0; + } + if (stall) { + CFL_Cap = max(stallCut * ((CFL_Cap > 0.0) ? min(CFL_Cap, avgCFL) : avgCFL), cflMin); + CFL_Ceiling = CFL_Cap; + CFL_StallValue = (CFL_StallValue > 0.0) ? min(CFL_StallValue, avgCFL) : avgCFL; + CFL_LastStall = iter; + Stall_Streak = 0; + if (rank == MASTER_NODE) + cout << "CFL_ADAPT: residuals stalled at iteration " << iter << ", CFL capped at " << CFL_Cap << "." + << endl; + } + /*--- Halve the CFL on a jump or a failed linear solve and keep it below a ceiling. A second event * near the CFL of an earlier one sets a lasting cap below both. ---*/ - CFL_Cut = (jump || (linRes > linearFailure)) && (iter >= CFL_LastEvent + jumpWindow); + CFL_Cut = (jump || regress || flip || (linRes > linearFailure)) && (iter >= CFL_LastEvent + jumpWindow) && + (avgCFL > 1.05 * cflMin); if (CFL_Cut) { - for (const auto eventCFL : CFL_EventValues) - if ((avgCFL < 1.5 * eventCFL) && (eventCFL < 1.5 * avgCFL)) { - const passivedouble cap = 0.8 * min(eventCFL, avgCFL); - CFL_Cap = (CFL_Cap > 0.0) ? min(CFL_Cap, cap) : cap; - } - CFL_EventValues.push_back(avgCFL); - CFL_Ceiling = 0.7 * avgCFL; + /*--- Cuts that follow each other closely belong to one event, only its first CFL is recorded. ---*/ + if (iter >= CFL_LastEvent + eventGap) { + for (const auto eventCFL : CFL_EventValues) + if ((avgCFL < eventMatch * eventCFL) && (eventCFL < eventMatch * avgCFL)) { + const passivedouble cap = max(eventCapFactor * min(eventCFL, avgCFL), cflMin); + CFL_Cap = (CFL_Cap > 0.0) ? min(CFL_Cap, cap) : cap; + } + CFL_EventValues.push_back(avgCFL); + } + if (regress && (iter >= CFL_LastRegress + regressEpisode)) { + const passivedouble cap = max(regressCap * avgCFL, cflMin); + CFL_Cap = (CFL_Cap > 0.0) ? min(CFL_Cap, cap) : cap; + } + if (regress) CFL_LastRegress = iter; + CFL_Ceiling = (CFL_Cap > 0.0) ? min(cutFactor * avgCFL, CFL_Cap) : cutFactor * avgCFL; CFL_LastEvent = iter; if (rank == MASTER_NODE) - cout << "CFL_ADAPT_RESIDUAL: " << (jump ? "residual jump" : "linear solver failure") << " at iteration " - << iter << ", CFL halved from " << avgCFL << "." << endl; + cout << "CFL_ADAPT: " + << (jump ? "residual jump" : regress ? "residual regression" : flip ? "residual flip-flop" : "linear solver failure") + << " at iteration " << iter << ", CFL halved from " << avgCFL << "." << endl; } - /*--- Without a new residual minimum for a long time, cap the CFL below its current level. ---*/ - const passivedouble func = SU2_TYPE::GetValue(New_Func); - if (func < ResTrend_Best - 0.01) { - ResTrend_Best = func; - ResTrend_LastBest = iter; - } - if ((iter > ResTrend_LastBest + stagnationIters) && (iter > CFL_LastStagnation + stagnationIters) && - (iter > CFL_LastEvent + 50)) { - CFL_Cap = 0.8 * ((CFL_Cap > 0.0) ? min(CFL_Cap, avgCFL) : avgCFL); - CFL_Ceiling = CFL_Cap; - CFL_LastStagnation = iter; - ResTrend_LastBest = iter; - if (rank == MASTER_NODE) - cout << "CFL_ADAPT_RESIDUAL: no progress by iteration " << iter << ", CFL capped at " << CFL_Cap << "." << endl; + /*--- A cap that has held the CFL through a quiet, converging stretch is raised, so that it does not + * outlive the transient that caused it. A new event at the higher CFL brings it back down. It + * stays below a CFL at which the residuals stalled. ---*/ + const passivedouble probeLimit = (CFL_StallValue > 0.0) ? stallRoom * CFL_StallValue : 1e30; + if ((CFL_Cap > 0.0) && (avgCFL > 0.95 * CFL_Cap) && (iter > max(CFL_LastEvent, CFL_LastStall) + capProbeQuiet) && + (iter > CFL_LastCapProbe + capProbeQuiet) && ResTrend_Increase && (ResRise < growBelowBest) && + (CFL_Cap < probeLimit)) { + CFL_Cap = min(CFL_Cap * capProbeFactor, probeLimit); + CFL_LastCapProbe = iter; + CFL_EventValues.clear(); } /*--- Lift the ceiling again while the residuals fall, up to the cap. ---*/ - if ((CFL_Ceiling > 0.0) && (iter > max(CFL_LastEvent, CFL_LastStagnation) + quietIters) && ResTrend_Increase) { + if ((CFL_Ceiling > 0.0) && (iter > CFL_LastEvent + quietIters) && ResTrend_Increase && (ResRise < growBelowBest)) { CFL_Ceiling *= 1.05; if (CFL_Cap > 0.0) CFL_Ceiling = min(CFL_Ceiling, CFL_Cap); else if (CFL_Ceiling > SU2_TYPE::GetValue(CFLMax)) CFL_Ceiling = -1.0; @@ -2018,7 +2125,7 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, /*--- These replace the linear-residual and oscillation rules above. A poor linear solve holds the * CFL back gently, a failed one halves it above. ---*/ - canIncrease = ResTrend_Increase && (linRes < linearBrake) && (iter >= startingIter); + canIncrease = ResTrend_Increase && (linRes < linearBrake) && (iter >= startingIter) && (ResRise < growBelowBest); reduceCFL = (ResTrend_Reduce || (linRes > linearBrake)) && (iter >= startingIter); resetCFL = false; } @@ -2073,10 +2180,10 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, /* Check if we are hitting the min or max and adjust. */ - if (CFL*CFLFactor <= CFLMin) { - CFL = CFLMin; + if (CFL * CFLFactor <= CFLMin) { + CFL = CFLMin; CFLFactor = MGFactor[iMesh]; - } else if (CFL*CFLFactor >= CFLMax) { + } else if (CFL * CFLFactor >= CFLMax) { CFL = CFLMax; CFLFactor = MGFactor[iMesh]; } @@ -2093,6 +2200,7 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, if (CFL_Cut) CFLFactor = 0.5; CFL *= CFLFactor; + if (CFL_Cut) CFL = max(CFL, CFLMin * MGFactor[iMesh]); if ((CFL_Ceiling > 0.0) && (CFL > CFL_Ceiling)) CFL = max(su2double(CFL_Ceiling), CFLMin); solverFlow->GetNodes()->SetLocalCFL(iPoint, CFL); if ((iMesh == MESH_0) && solverTurb) { diff --git a/SU2_CFD/src/variables/CEulerVariable.cpp b/SU2_CFD/src/variables/CEulerVariable.cpp index 2c556501f78f..19ecaba04314 100644 --- a/SU2_CFD/src/variables/CEulerVariable.cpp +++ b/SU2_CFD/src/variables/CEulerVariable.cpp @@ -108,6 +108,7 @@ CEulerVariable::CEulerVariable(su2double density, const su2double *velocity, su2 OutlierMitigation.resize(nPoint) = 0; FirstOrderReconstruction.resize(nPoint) = 0; + SkipMGCorrection.resize(nPoint) = 0; } bool CEulerVariable::SetPrimVar(unsigned long iPoint, CFluidModel *FluidModel) { diff --git a/config_template.cfg b/config_template.cfg index 8d49841bee87..e4839143ecfc 100644 --- a/config_template.cfg +++ b/config_template.cfg @@ -1538,16 +1538,18 @@ NUM_METHOD_GRAD_RECON = LEAST_SQUARES CFL_NUMBER= 15.0 % % Adaptive CFL number (NO, YES) +% The CFL is adapted on the finest-grid nonlinear residuals, which makes it independent of the number +% of MPI ranks. It grows while the residuals do not rise and shrinks when they rise. The CFL is halved +% and kept below a ceiling that lifts while the residuals fall on: a sudden residual jump (also of a +% single flow equation), a flow residual more than one order of magnitude above its best value of the +% last 100 iterations (also when it stays there), most flow residuals alternating up and down at every +% iteration without progress (flip-flop), or a failed linear solve. The CFL does not grow while the +% residual is far above its best value. Repeated events, a regression, a flip-flop, or all flow +% residuals stalling for 30 iterations cap the CFL lasting below the level where that happened. Uses +% factor up/down and the CFL limits of CFL_ADAPT_PARAM, and never goes below the lower limit. With +% OUTLIER_MITIGATION_PARAM the CFL is adapted on the linear solver convergence instead. CFL_ADAPT= NO % -% Adapt the CFL on the finest-grid nonlinear residuals instead of on the linear solver, which -% makes it independent of the number of MPI ranks. The CFL grows while the residuals fall and -% shrinks when they rise. A sudden residual jump or a failed linear solve halves it and keeps it -% below a ceiling; repeated events, or no progress for 150 iterations, cap it lasting below the -% level where that happened. Uses factor up/down and the CFL limits of CFL_ADAPT_PARAM. -% Cannot be combined with OUTLIER_MITIGATION_PARAM (NO, YES) (default NO) -CFL_ADAPT_RESIDUAL= NO -% % Parameters of the adaptive CFL number (factor-down, factor-up, CFL min value, % CFL max value, acceptable linear solver convergence, starting iteration) % After the starting iteration has passed, local CFL increases by factor-up until max if the solution rate of @@ -1601,7 +1603,8 @@ MUSCL_FLOW= YES % Reconstruct to first order on the edges of points where a no-slip wall ends on a boundary that % continues its surface (a leading edge after a symmetry plane) or has a sharp edge (a sharp % trailing edge). The gradient is singular there, and MUSCL across it can stall or destabilize -% the solver, multigrid in particular (NO, YES) +% the solver, multigrid in particular. With multigrid, the coarse-grid correction of the flow +% solution is also not prolongated to these points and their neighbours (NO, YES) MUSCL_FIRST_ORDER_WALL_ENDS= NO % % Option to ramp the MUSCL reconstruction scheme gradually from first to second order @@ -1783,7 +1786,8 @@ MG_DAMP_PROLONGATION= 0.5 % Prolong the correction with a limited least-squares gradient over the coarse control % volume instead of injecting the parent value into every child. The reconstruction is % exact for a linear correction and the children still average back to the coarse value. -% Control volumes on walls and symmetry planes keep the constant operator (NO, YES) +% Control volumes on walls and symmetry planes, and those where the gradient fit has a condition number +% above 1e5 (strongly stretched agglomerates, reported on screen), keep the constant operator (NO, YES) MG_LINEAR_PROLONGATION= NO % % Enable early exit from multigrid smoothing when the residual RMS drops From c6d8d786563a31289239652c9bd376f634f981db Mon Sep 17 00:00:00 2001 From: bigfooted Date: Mon, 12 Oct 2026 20:14:50 +0200 Subject: [PATCH 12/42] Make agglomeration multigrid robust on 3D stretched grids with wall ends Agglomeration: - In 3D a symmetry plane met at an angle by another boundary no longer makes a node mixed, so wall/symmetry edges coarsen instead of staying fine-size singletons on every level (3D bump: 288 -> 26 singletons per level). - Columns standing on mixed nodes (wall ends) are paved first, so no column from either side straddles a leading or trailing edge. - A column only advances along a stiff edge of the mesh, so columns from side planes no longer march along thin layers and break up wall-normal columns. Prolongation: - The linear prolongation gradient is rejected only for a degenerate stencil (condition of the unit directions), and solved by Cholesky, instead of rejecting every stretched cell (constant fallback 31% -> 1.5% of cells). - Each level's correction fades in over 4 coarse CVs from where a wall ends. Adaptive CFL: escalating cuts on repeated stalls, and cap increases stay below the cap set at the last stall. 3D bump 17x177x81 (MG_CFL_SCALING 0.05): MG1 313 its, MG2 374, single grid 561, MG1 before 1128. 2D flat plate and 3-element airfoil unchanged. Co-Authored-By: Claude Opus 5.5 --- .../include/geometry/CMultiGridGeometry.hpp | 3 +- Common/src/geometry/CMultiGridGeometry.cpp | 64 +++++- .../integration/CMultiGridIntegration.hpp | 11 ++ SU2_CFD/include/solvers/CSolver.hpp | 4 +- .../src/integration/CMultiGridIntegration.cpp | 182 +++++++++++------- SU2_CFD/src/solvers/CSolver.cpp | 16 +- config_template.cfg | 4 +- 7 files changed, 208 insertions(+), 76 deletions(-) diff --git a/Common/include/geometry/CMultiGridGeometry.hpp b/Common/include/geometry/CMultiGridGeometry.hpp index 3658dc0ea2f5..6e38ef2fea7a 100644 --- a/Common/include/geometry/CMultiGridGeometry.hpp +++ b/Common/include/geometry/CMultiGridGeometry.hpp @@ -110,7 +110,8 @@ class CMultiGridGeometry final : public CGeometry { vector> normal; /*!< \brief Unit normal there, pointing into the domain. */ vector strength; /*!< \brief Local anisotropy, the ordering key. */ vector tier; /*!< \brief Paving order: 0 viscous wall, 1 Euler - wall, 2 anything else. */ + wall, 2 anything else; one more once the + mixed nodes are put first. */ unsigned long nRefusedCurvature = 0; /*!< \brief Euler wall nodes the curvature limit kept out. */ }; diff --git a/Common/src/geometry/CMultiGridGeometry.cpp b/Common/src/geometry/CMultiGridGeometry.cpp index 7a6add0f18d7..b9775579cd65 100644 --- a/Common/src/geometry/CMultiGridGeometry.cpp +++ b/Common/src/geometry/CMultiGridGeometry.cpp @@ -69,6 +69,37 @@ vector MarkerSetClasses(unsigned long nEntity, vectorGetnDim(); + if ((nDim != 3) || (config->GetMarker_All_KindBC(iMarker) != SYMMETRY_PLANE)) return false; + + auto unitNormal = [&](unsigned short jMarker, su2double* n) { + const long iVertex = grid->nodes->GetVertex(iPoint, jMarker); + if (iVertex < 0) return false; + grid->vertex[jMarker][iVertex]->GetNormal(n); + const su2double nrm = GeometryToolbox::Norm(nDim, n); + if (nrm <= 0.0) return false; + for (unsigned short d = 0; d < nDim; ++d) n[d] /= nrm; + return true; + }; + + su2double nSym[3] = {0.0}, nOther[3] = {0.0}; + if (!unitNormal(iMarker, nSym)) return false; + + bool hasOther = false; + for (auto jMarker = 0u; jMarker < grid->GetnMarker(); jMarker++) { + const auto bc = config->GetMarker_All_KindBC(jMarker); + if ((bc == SEND_RECEIVE) || (bc == SYMMETRY_PLANE) || (grid->nodes->GetVertex(iPoint, jMarker) < 0)) continue; + if ((bc == PERIODIC_BOUNDARY) || !unitNormal(jMarker, nOther)) return false; + if (fabs(GeometryToolbox::DotProduct(nDim, nSym, nOther)) >= sqrt(0.5)) return false; + hasOther = true; + } + return hasOther; +} + } // namespace CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, unsigned short iMesh) : CGeometry() { @@ -1023,6 +1054,7 @@ vector CMultiGridGeometry::FindMixedBoundaryNodes(const CGeometry* fine_gr const auto bc = static_cast(config->GetMarker_All_KindBC(iMarker)); for (auto iVertex = 0ul; iVertex < fine_grid->GetnVertex(iMarker); iVertex++) { const auto iPoint = fine_grid->vertex[iMarker][iVertex]->GetNode(); + if (AbsorbedSymmetry(fine_grid, config, iPoint, iMarker)) continue; if (firstBC[iPoint] < 0) firstBC[iPoint] = bc; else if (firstBC[iPoint] != bc) @@ -1678,6 +1710,7 @@ CMultiGridGeometry::CFrontSeeds CMultiGridGeometry::SeedFrontNodes(const CGeomet std::array n0{}; for (unsigned short d = 0; d < nDim; ++d) n0[d] = Normal[d]; + seeds.node.push_back(iPoint); seeds.normal.push_back(n0); seeds.strength.push_back(strength); @@ -1926,7 +1959,11 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co const short int maxAgglomSize = MaxAgglomSize(nDim); /*--- SeedFrontNodes returns the seeds ordered by anisotropy. ---*/ - const auto seeds = SeedFrontNodes(fine_grid, config); + auto seeds = SeedFrontNodes(fine_grid, config); + + /*--- A node where two conditions meet stays a CV of its own, and the column above it is paved + * before any other, so no column from either side reaches over to the other. ---*/ + for (auto si = 0ul; si < seeds.node.size(); ++si) seeds.tier[si] = mixedBC[seeds.node[si]] ? 0 : seeds.tier[si] + 1; vector walkOf; const auto patches = BuildFrontPatches(seeds, fine_grid, config, mixedBC, walkOf); @@ -2046,7 +2083,7 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co /*--- One tier is paved out everywhere before the next starts, so an inherited column belongs to * the tier that is running. ---*/ - constexpr char N_TIER = 3; + constexpr char N_TIER = 4; vector active; for (char tier = 0; tier < N_TIER; ++tier) { /*--- The columns of this tier still advancing, in seed order. A column that stops drops out at @@ -2185,7 +2222,28 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co return reached.size() == width; }; - if (complete(candidates)) { + /*--- A column follows the stiff direction of the mesh. A step whose edges couple far more + * weakly than the stiffest edge at their node runs along a thin layer, not across it, + * and is left to a column crossing that layer. ---*/ + auto stiffStep = [&](const vector& set) { + constexpr passivedouble STIFF_FRACTION = 0.1; + su2double ratio = 0.0; + for (auto iPoint : layer[iColumn]) { + su2double wStep = 0.0, wMax = 0.0; + for (auto iNeigh = 0u; iNeigh < fine_grid->nodes->GetnPoint(iPoint); ++iNeigh) { + const auto jPoint = fine_grid->nodes->GetPoint(iPoint, iNeigh); + const auto iEdge = fine_grid->nodes->GetEdge(iPoint, iNeigh); + const su2double w = GeometryToolbox::Norm(nDim, fine_grid->edges->GetNormal(iEdge)) * + (1.0 / fine_grid->nodes->GetVolume(iPoint) + 1.0 / fine_grid->nodes->GetVolume(jPoint)); + wMax = std::max(wMax, w); + if (std::find(set.begin(), set.end(), jPoint) != set.end()) wStep = std::max(wStep, w); + } + ratio += (wMax > 0.0) ? wStep / wMax : 1.0; + } + return ratio >= STIFF_FRACTION * su2double(layer[iColumn].size()); + }; + + if (complete(candidates) && stiffStep(candidates)) { for (auto jPoint : candidates) { columnOf[jPoint] = iColumn; layerOf[jPoint] = iRound; diff --git a/SU2_CFD/include/integration/CMultiGridIntegration.hpp b/SU2_CFD/include/integration/CMultiGridIntegration.hpp index 02486516d584..1bc2213845eb 100644 --- a/SU2_CFD/include/integration/CMultiGridIntegration.hpp +++ b/SU2_CFD/include/integration/CMultiGridIntegration.hpp @@ -28,6 +28,8 @@ #include "CIntegration.hpp" #include "../../../Common/include/containers/container_decorators.hpp" +class CEulerVariable; + /*! * \class CMultiGridIntegration * \ingroup Drivers @@ -387,6 +389,15 @@ class CMultiGridIntegration final : public CIntegration { /*! \brief Limited least-squares gradient of the correction, indexed by coarse level. * Allocated on first use, only when MG_LINEAR_PROLONGATION is on. */ vector prolongGradient; + vector> correctionWeight; /*!< \brief Per level, weight of the correction near wall ends. */ + + /*! + * \brief Weight each level's prolongated correction from zero where a wall ends to one a few coarse CVs away. + * \param[in] geometry - Geometry of all levels of this zone and instance. + * \param[in] flowNodes - Flow variables of the finest grid, which flag the wall ends. + * \param[in] nLevels - Number of multigrid levels. + */ + void ComputeCorrectionWeights(CGeometry** geometry, const CEulerVariable* flowNodes, unsigned short nLevels); /*! \brief Coarse cells per level whose gradient fit is too ill-conditioned and keep the constant * operator, and whether that level has been reported. */ diff --git a/SU2_CFD/include/solvers/CSolver.hpp b/SU2_CFD/include/solvers/CSolver.hpp index 9a964e246108..26e7bd614a3c 100644 --- a/SU2_CFD/include/solvers/CSolver.hpp +++ b/SU2_CFD/include/solvers/CSolver.hpp @@ -102,7 +102,9 @@ class CSolver { vector CFLStall_History; /*!< \brief Mean CFL over two stall windows. */ unsigned long Stall_Streak = 0; /*!< \brief Consecutive iterations without envelope progress. */ unsigned long CFL_LastStall = 0; /*!< \brief Iteration of the last stall cap. */ - passivedouble CFL_StallValue = -1.0; /*!< \brief Lowest CFL at which the residuals stalled. */ + passivedouble CFL_StallCap = -1.0; /*!< \brief Cap set at the last stall, which cap increases respect. */ + unsigned short Stall_Count = 0; /*!< \brief Stalls since the residual last fell well below one. */ + passivedouble Res_AtStall = 0.0; /*!< \brief Mean log flow residual at the last stall. */ unsigned short nVar, /*!< \brief Number of variables of the problem. */ nPrimVar, /*!< \brief Number of primitive variables of the problem. */ nPrimVarGrad, /*!< \brief Number of primitive variables of the problem in the gradient computation. */ diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index 4311b8103bb7..ed09cdc5108b 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -30,6 +30,7 @@ #include "../../../Common/include/toolboxes/printing_toolbox.hpp" #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" #include +#include #include "../../include/variables/CEulerVariable.hpp" @@ -52,53 +53,6 @@ static su2double applyGlobalTrend(su2double factor, passivedouble crossCycleRati return max(su2double{CLAMP_MIN}, min(su2double{CLAMP_MAX}, factor)); } -/*!\cond PRIVATE - * Inverts the symmetric least-squares matrix. False means the stencil is too degenerate - * to define a gradient. - \endcond */ -static bool invertLeastSquaresMatrix(unsigned short nDim, const su2double A[3][3], su2double inv[3][3]) { - - /*--- Compare against the trace so the test does not depend on the mesh units. ---*/ - - su2double trace = 0.0; - for (auto iDim = 0u; iDim < nDim; iDim++) trace += A[iDim][iDim]; - if (trace <= 0.0) return false; - - const su2double scale = trace / su2double(nDim); - - /*--- det/scale^nDim is the conditioning of the fit. At 1e-8 the inverse still carries about - * nine digits; below it the gradient is noise and the control volume stays constant. ---*/ - constexpr passivedouble REL_TOL = 1e-8; - - if (nDim == 2) { - const su2double det = A[0][0]*A[1][1] - A[0][1]*A[0][1]; - if (det <= REL_TOL * scale * scale) return false; - - inv[0][0] = A[1][1]/det; - inv[0][1] = -A[0][1]/det; - inv[1][0] = inv[0][1]; - inv[1][1] = A[0][0]/det; - return true; - } - - const su2double a = A[0][0], b = A[0][1], c = A[0][2]; - const su2double d = A[1][1], e = A[1][2], f = A[2][2]; - - const su2double det = a*(d*f - e*e) - b*(b*f - e*c) + c*(b*e - d*c); - if (det <= REL_TOL * scale * scale * scale) return false; - - inv[0][0] = (d*f - e*e)/det; - inv[0][1] = (c*e - b*f)/det; - inv[0][2] = (b*e - c*d)/det; - inv[1][1] = (a*f - c*c)/det; - inv[1][2] = (b*c - a*e)/det; - inv[2][2] = (a*d - b*b)/det; - inv[1][0] = inv[0][1]; - inv[2][0] = inv[0][2]; - inv[2][1] = inv[1][2]; - return true; -} - inline passivedouble ComputeLinSysResRMS(const CSolver* solver) { passivedouble result = 0; for (unsigned short iVar = 0; iVar < solver->GetnVar(); ++iVar) { @@ -660,6 +614,14 @@ void CMultiGridIntegration::MultiGrid_Cycle(CGeometry ****geometry, unsigned short iRKLimit = config->GetnRKStep(); + /*--- Wall end weights for every level, once the hierarchy exists. ---*/ + if ((iMesh == MESH_0) && correctionWeight.empty()) { + const auto* flowNodes = dynamic_cast(solver_container_fine[FLOW_SOL]->GetNodes()); + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS + ComputeCorrectionWeights(geometry[iZone][iInst], flowNodes, config->GetnMGLevels()); + END_SU2_OMP_SAFE_GLOBAL_ACCESS + } + /*--- Do a presmoothing on the grid iMesh to be restricted to the grid iMesh+1 ---*/ PreSmoothing(RunTime_EqSystem, geometry, solver_container, config_container, solver_fine, numerics_fine, @@ -1060,8 +1022,8 @@ void CMultiGridIntegration::GetProlongated_Correction(unsigned short RunTime_EqS } -/*--- Largest condition number of the prolongation gradient fit that is still trusted. ---*/ -static constexpr passivedouble PROLONG_MAX_CONDITION = 1e5; +/*--- Largest condition number of the stencil directions for which the prolongation gradient is fitted. ---*/ +static constexpr passivedouble PROLONG_MAX_CONDITION = 1e3; namespace { /*--- Condition number of a symmetric 2x2 or 3x3 matrix, infinite if it is not positive definite. ---*/ @@ -1094,6 +1056,39 @@ passivedouble FitConditionNumber(unsigned short nDim, const su2double A[3][3]) { } return (lmin > 0.0) ? lmax / lmin : big; } + +/*--- Inverse of a symmetric positive definite matrix by Cholesky factorization, which stays accurate + * for the strong anisotropy of a boundary layer stencil. False if a pivot vanishes. ---*/ +bool CholeskyInverse(unsigned short n, const su2double A[3][3], su2double inv[3][3]) { + su2double L[3][3] = {{0.0}}; + for (auto i = 0u; i < n; ++i) { + for (auto j = 0u; j <= i; ++j) { + su2double sum = A[i][j]; + for (auto k = 0u; k < j; ++k) sum -= L[i][k] * L[j][k]; + if (i == j) { + if (sum <= 1e-14 * A[i][i]) return false; + L[i][i] = sqrt(sum); + } else { + L[i][j] = sum / L[j][j]; + } + } + } + for (auto c = 0u; c < n; ++c) { + su2double y[3] = {0.0}, x[3] = {0.0}; + for (auto i = 0u; i < n; ++i) { + su2double sum = (i == c) ? 1.0 : 0.0; + for (auto k = 0u; k < i; ++k) sum -= L[i][k] * y[k]; + y[i] = sum / L[i][i]; + } + for (int i = n - 1; i >= 0; --i) { + su2double sum = y[i]; + for (auto k = i + 1u; k < n; ++k) sum -= L[k][i] * x[k]; + x[i] = sum / L[i][i]; + } + for (auto i = 0u; i < n; ++i) inv[i][c] = x[i]; + } + return true; +} } // namespace void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGeometry *geo_coarse, @@ -1118,7 +1113,7 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe SU2_MPI::Allreduce(local, global, 2, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm()); if ((global[0] > 0) && (SU2_MPI::GetRank() == MASTER_NODE)) cout << "MG level " << iMesh << ": linear prolongation keeps the constant operator in " << global[0] - << " of " << global[1] << " coarse cells (gradient fit condition number above " + << " of " << global[1] << " coarse cells (stencil direction condition number above " << PROLONG_MAX_CONDITION << ")." << endl; } } @@ -1156,16 +1151,21 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe const auto* Coord_i = geo_coarse->nodes->GetCoord(iPoint); const auto* Correction_i = nodes->GetSolution_Old(iPoint); - su2double Amat[MAXNDIM][MAXNDIM] = {{0.0}}; + su2double Amat[MAXNDIM][MAXNDIM] = {{0.0}}, Bmat[MAXNDIM][MAXNDIM] = {{0.0}}; su2double rhs[MAXNVAR][MAXNDIM] = {{0.0}}; for (auto jPoint : geo_coarse->nodes->GetPoints(iPoint)) { su2double Distance[MAXNDIM] = {0.0}; GeometryToolbox::Distance(nDim, geo_coarse->nodes->GetCoord(jPoint), Coord_i, Distance); + const su2double dist2 = GeometryToolbox::SquaredNorm(nDim, Distance); + if (dist2 <= 0.0) continue; for (auto iDim = 0u; iDim < nDim; iDim++) - for (auto jDim = 0u; jDim < nDim; jDim++) Amat[iDim][jDim] += Distance[iDim]*Distance[jDim]; + for (auto jDim = 0u; jDim < nDim; jDim++) { + Amat[iDim][jDim] += Distance[iDim]*Distance[jDim]; + Bmat[iDim][jDim] += Distance[iDim]*Distance[jDim]/dist2; + } const auto* Correction_j = nodes->GetSolution_Old(jPoint); @@ -1175,17 +1175,15 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe } } - /*--- On a strongly stretched agglomerate the fit cannot tell the slopes apart, so the cell keeps the - * constant operator. ---*/ - if (FitConditionNumber(nDim, Amat) > PROLONG_MAX_CONDITION) { + /*--- Stretching alone leaves the fit well posed. Only neighbours that do not span every direction + * leave a slope undefined, and then the cell keeps the constant operator. ---*/ + su2double Ainv[MAXNDIM][MAXNDIM] = {{0.0}}; + if ((FitConditionNumber(nDim, Bmat) > PROLONG_MAX_CONDITION) || !CholeskyInverse(nDim, Amat, Ainv)) { SU2_OMP_ATOMIC prolongIllConditioned[iMesh]++; continue; } - su2double Ainv[MAXNDIM][MAXNDIM] = {{0.0}}; - if (!invertLeastSquaresMatrix(nDim, Amat, Ainv)) continue; - for (auto iVar = 0u; iVar < nVar; iVar++) for (auto iDim = 0u; iDim < nDim; iDim++) { su2double value = 0.0; @@ -1363,6 +1361,60 @@ void CMultiGridIntegration::SmoothProlongated_Correction(unsigned short RunTime_ } } +void CMultiGridIntegration::ComputeCorrectionWeights(CGeometry** geometry, const CEulerVariable* flowNodes, + unsigned short nLevels) { + /*--- Coarse CVs over which the correction fades in from a wall end. ---*/ + constexpr unsigned long nBlend = 4; + + correctionWeight.assign(nLevels, {}); + if (!flowNodes) return; + + /*--- Points of each level holding a wall end, passed down from the finest grid. ---*/ + vector wallEnd(geometry[MESH_0]->GetnPoint(), 0); + for (auto iPoint = 0ul; iPoint < geometry[MESH_0]->GetnPointDomain(); iPoint++) + wallEnd[iPoint] = flowNodes->SkipMGCorrection(iPoint); + + constexpr auto FAR = std::numeric_limits::max(); + vector hops, front, next; + + for (unsigned short iMesh = 0; iMesh < nLevels; iMesh++) { + const auto* fine = geometry[iMesh]; + const auto* coarse = geometry[iMesh + 1]; + + vector coarseWallEnd(coarse->GetnPoint(), 0); + hops.assign(coarse->GetnPoint(), FAR); + front.clear(); + for (auto iCoarse = 0ul; iCoarse < coarse->GetnPointDomain(); iCoarse++) + for (auto iChild = 0u; iChild < coarse->nodes->GetnChildren_CV(iCoarse); iChild++) + if (wallEnd[coarse->nodes->GetChildren_CV(iCoarse, iChild)]) { + coarseWallEnd[iCoarse] = 1; + hops[iCoarse] = 0; + front.push_back(iCoarse); + break; + } + + for (unsigned long d = 1; (d < nBlend) && !front.empty(); d++) { + next.clear(); + for (auto iCoarse : front) + for (auto jCoarse : coarse->nodes->GetPoints(iCoarse)) + if (hops[jCoarse] == FAR) { + hops[jCoarse] = d; + next.push_back(jCoarse); + } + front.swap(next); + } + + auto& weight = correctionWeight[iMesh]; + weight.assign(fine->GetnPoint(), 1.0); + for (auto iCoarse = 0ul; iCoarse < coarse->GetnPointDomain(); iCoarse++) { + if (hops[iCoarse] == FAR) continue; + for (auto iChild = 0u; iChild < coarse->nodes->GetnChildren_CV(iCoarse); iChild++) + weight[coarse->nodes->GetChildren_CV(iCoarse, iChild)] = passivedouble(hops[iCoarse]) / passivedouble(nBlend); + } + wallEnd.swap(coarseWallEnd); + } +} + void CMultiGridIntegration::SetProlongated_Correction(CSolver *sol_fine, CSolver *sol_flow, CGeometry *geo_fine, CConfig *config, unsigned short iMesh) { SU2_ZONE_SCOPED @@ -1379,15 +1431,15 @@ void CMultiGridIntegration::SetProlongated_Correction(CSolver *sol_fine, CSolver if (skipHere && flowNodes->SkipMGCorrection(Point_Fine)) continue; auto* Residual_Fine = sol_fine->LinSysRes.GetBlock(Point_Fine); auto* Solution_Fine = sol_fine->GetNodes()->GetSolution(Point_Fine); - for (auto iVar = 0u; iVar < nVar; iVar++) { - /*--- Prevent a fine grid divergence due to a coarse grid divergence ---*/ - if (Residual_Fine[iVar] != Residual_Fine[iVar]) - Residual_Fine[iVar] = 0.0; - su2double correction = factor * Residual_Fine[iVar]; + /*--- Prevent a fine grid divergence due to a coarse grid divergence ---*/ + for (auto iVar = 0u; iVar < nVar; iVar++) + if (Residual_Fine[iVar] != Residual_Fine[iVar]) Residual_Fine[iVar] = 0.0; - Solution_Fine[iVar] += correction; - } + su2double relax = factor; + if ((iMesh < correctionWeight.size()) && !correctionWeight[iMesh].empty()) relax *= correctionWeight[iMesh][Point_Fine]; + + for (auto iVar = 0u; iVar < nVar; iVar++) Solution_Fine[iVar] += relax * Residual_Fine[iVar]; } END_SU2_OMP_FOR diff --git a/SU2_CFD/src/solvers/CSolver.cpp b/SU2_CFD/src/solvers/CSolver.cpp index 1fa62f455610..1e88b07fcfbd 100644 --- a/SU2_CFD/src/solvers/CSolver.cpp +++ b/SU2_CFD/src/solvers/CSolver.cpp @@ -1927,7 +1927,8 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, constexpr passivedouble stuckSpread = 0.15, flipAmplitude = 0.03, flipProgress = 0.15; constexpr size_t stallWindow = 100; constexpr unsigned long stallPersist = 20; - constexpr passivedouble stallProgress = 0.1, stallGrowth = 1.1, stallCut = 0.5, stallRoom = 0.8; + constexpr unsigned short stallMaxCount = 3; + constexpr passivedouble stallProgress = 0.1, stallGrowth = 1.1, stallCut = 0.5, stallReset = 1.0; if (iMesh == MESH_0) { const passivedouble avgCFL = SU2_TYPE::GetValue(Avg_CFL_Local); @@ -2065,10 +2066,15 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, } else { Stall_Streak = 0; } + /*--- Each further stall before the residual falls well below the last one cuts twice as hard. ---*/ + if ((Stall_Count > 0) && (flowMean < Res_AtStall - stallReset)) Stall_Count = 0; if (stall) { - CFL_Cap = max(stallCut * ((CFL_Cap > 0.0) ? min(CFL_Cap, avgCFL) : avgCFL), cflMin); + Stall_Count = min(Stall_Count + 1, stallMaxCount); + Res_AtStall = flowMean; + const passivedouble cut = pow(stallCut, Stall_Count); + CFL_Cap = max(cut * ((CFL_Cap > 0.0) ? min(CFL_Cap, avgCFL) : avgCFL), cflMin); CFL_Ceiling = CFL_Cap; - CFL_StallValue = (CFL_StallValue > 0.0) ? min(CFL_StallValue, avgCFL) : avgCFL; + CFL_StallCap = CFL_Cap; CFL_LastStall = iter; Stall_Streak = 0; if (rank == MASTER_NODE) @@ -2105,8 +2111,8 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, /*--- A cap that has held the CFL through a quiet, converging stretch is raised, so that it does not * outlive the transient that caused it. A new event at the higher CFL brings it back down. It - * stays below a CFL at which the residuals stalled. ---*/ - const passivedouble probeLimit = (CFL_StallValue > 0.0) ? stallRoom * CFL_StallValue : 1e30; + * stays below the cap set at the last stall. ---*/ + const passivedouble probeLimit = (CFL_StallCap > 0.0) ? CFL_StallCap : 1e30; if ((CFL_Cap > 0.0) && (avgCFL > 0.95 * CFL_Cap) && (iter > max(CFL_LastEvent, CFL_LastStall) + capProbeQuiet) && (iter > CFL_LastCapProbe + capProbeQuiet) && ResTrend_Increase && (ResRise < growBelowBest) && (CFL_Cap < probeLimit)) { diff --git a/config_template.cfg b/config_template.cfg index e4839143ecfc..84f47e86f516 100644 --- a/config_template.cfg +++ b/config_template.cfg @@ -1545,7 +1545,9 @@ CFL_NUMBER= 15.0 % last 100 iterations (also when it stays there), most flow residuals alternating up and down at every % iteration without progress (flip-flop), or a failed linear solve. The CFL does not grow while the % residual is far above its best value. Repeated events, a regression, a flip-flop, or all flow -% residuals stalling for 30 iterations cap the CFL lasting below the level where that happened. Uses +% residuals stalling for 30 iterations cap the CFL lasting below the level where that happened. Flow +% residuals whose upper envelope stops falling over 100 iterations while the CFL no longer grows cap +% the CFL at half its value, a quarter on a second such stall, an eighth on a third. Uses % factor up/down and the CFL limits of CFL_ADAPT_PARAM, and never goes below the lower limit. With % OUTLIER_MITIGATION_PARAM the CFL is adapted on the linear solver convergence instead. CFL_ADAPT= NO From cbd048687fdeade5050cd7cc5943cae0dfa19acd Mon Sep 17 00:00:00 2001 From: bigfooted Date: Mon, 12 Oct 2026 22:46:12 +0200 Subject: [PATCH 13/42] Take the coarse multigrid viscous flux from the edge difference only On an agglomerated coarse level the averaged gradient term of the viscous flux crosses faces that are poorly aligned with the edges between CV centroids. The implicit Jacobian does not hold that term, so the coarse iteration diverged once the coarse CFL exceeded a few hundred, which is why MG_CFL_SCALING had to be around 0.05. With the primitive gradients zero on coarse levels the coarse residual matches its Jacobian and the coarse smoother converges at any CFL. 3D bump 9x89x41, MG_CFL_SCALING 0.25: MG1 204, MG2 200, MG3 202 iterations (single grid 210, previously 700 / 318 / 321 or worse). Scaling 1.0 also works. 2D flat plate and 3-element airfoil unchanged. Co-Authored-By: Claude Opus 5.5 --- SU2_CFD/src/solvers/CNSSolver.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/SU2_CFD/src/solvers/CNSSolver.cpp b/SU2_CFD/src/solvers/CNSSolver.cpp index 643cb9a4f6c9..f76c03be4ccd 100644 --- a/SU2_CFD/src/solvers/CNSSolver.cpp +++ b/SU2_CFD/src/solvers/CNSSolver.cpp @@ -100,9 +100,17 @@ void CNSSolver::Preprocessing(CGeometry *geometry, CSolver **solver_container, C } } - /*--- Compute gradient of the primitive variables ---*/ - - if (config->GetKind_Gradient_Method() == GREEN_GAUSS) { + /*--- Compute gradient of the primitive variables. Coarse levels take the viscous flux from the edge + * difference only, as their Jacobian does. ---*/ + + if (iMesh != MESH_0) { + SU2_OMP_FOR_STAT(omp_chunk_size) + for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) + for (unsigned short iVar = 0; iVar < nPrimVarGrad; iVar++) + for (unsigned short iDim = 0; iDim < nDim; iDim++) nodes->GetGradient_Primitive()(iPoint, iVar, iDim) = 0.0; + END_SU2_OMP_FOR + } + else if (config->GetKind_Gradient_Method() == GREEN_GAUSS) { SetPrimitive_Gradient_GG(geometry, config); } else if (config->GetKind_Gradient_Method() == WEIGHTED_LEAST_SQUARES) { From c9d3a76fdd64d99c536a70aaba9aa15c9018c1ee Mon Sep 17 00:00:00 2001 From: bigfooted Date: Tue, 13 Oct 2026 03:34:20 +0200 Subject: [PATCH 14/42] Bound the adaptive CFL below the level where the residuals flip-flop A flip-flop above a certain CFL repeats at every CFL that the cap probe and the ceiling regrowth reach again, so on a stalled run each attempt cost 40 to 70 iterations and the residual never fell. The lowest CFL at which a flip-flop occurred now caps the CFL at half of it and limits the cap probe to that, until the flow residuals have fallen three orders of magnitude. 3D bump 17x177x81, MG1, CFL cap 1e5: converges in 480 iterations where it stalled at -10 for more than 960. Single grid, 2D flat plate, 2_2DCJ and the 2D bump are unchanged (561, 226, 330, 581 iterations); 4_2DANW does not reach the rule and behaves as before. Co-Authored-By: Claude Sonnet 5.5 --- SU2_CFD/include/solvers/CSolver.hpp | 4 +++- SU2_CFD/src/solvers/CSolver.cpp | 14 ++++++++++++-- config_template.cfg | 3 ++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/SU2_CFD/include/solvers/CSolver.hpp b/SU2_CFD/include/solvers/CSolver.hpp index 26e7bd614a3c..378b6bbfa679 100644 --- a/SU2_CFD/include/solvers/CSolver.hpp +++ b/SU2_CFD/include/solvers/CSolver.hpp @@ -102,7 +102,9 @@ class CSolver { vector CFLStall_History; /*!< \brief Mean CFL over two stall windows. */ unsigned long Stall_Streak = 0; /*!< \brief Consecutive iterations without envelope progress. */ unsigned long CFL_LastStall = 0; /*!< \brief Iteration of the last stall cap. */ - passivedouble CFL_StallCap = -1.0; /*!< \brief Cap set at the last stall, which cap increases respect. */ + passivedouble CFL_StallCap = -1.0; /*!< \brief Cap set at the last stall, which cap increases stay below. */ + passivedouble CFL_OscLevel = -1.0; /*!< \brief Lowest CFL at which the residuals flip-flopped. */ + passivedouble Res_AtOsc = 0.0; /*!< \brief Mean log flow residual at that flip-flop. */ unsigned short Stall_Count = 0; /*!< \brief Stalls since the residual last fell well below one. */ passivedouble Res_AtStall = 0.0; /*!< \brief Mean log flow residual at the last stall. */ unsigned short nVar, /*!< \brief Number of variables of the problem. */ diff --git a/SU2_CFD/src/solvers/CSolver.cpp b/SU2_CFD/src/solvers/CSolver.cpp index 1e88b07fcfbd..bfef1785bf3e 100644 --- a/SU2_CFD/src/solvers/CSolver.cpp +++ b/SU2_CFD/src/solvers/CSolver.cpp @@ -1929,6 +1929,7 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, constexpr unsigned long stallPersist = 20; constexpr unsigned short stallMaxCount = 3; constexpr passivedouble stallProgress = 0.1, stallGrowth = 1.1, stallCut = 0.5, stallReset = 1.0; + constexpr passivedouble oscCap = 0.5, oscReset = 3.0; if (iMesh == MESH_0) { const passivedouble avgCFL = SU2_TYPE::GetValue(Avg_CFL_Local); @@ -2101,6 +2102,13 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, CFL_Cap = (CFL_Cap > 0.0) ? min(CFL_Cap, cap) : cap; } if (regress) CFL_LastRegress = iter; + /*--- Flip-flops bound the CFL below the lowest level that produced one. ---*/ + if (flip) { + CFL_OscLevel = (CFL_OscLevel > 0.0) ? min(CFL_OscLevel, avgCFL) : avgCFL; + Res_AtOsc = flowMean; + const passivedouble cap = max(oscCap * CFL_OscLevel, cflMin); + CFL_Cap = (CFL_Cap > 0.0) ? min(CFL_Cap, cap) : cap; + } CFL_Ceiling = (CFL_Cap > 0.0) ? min(cutFactor * avgCFL, CFL_Cap) : cutFactor * avgCFL; CFL_LastEvent = iter; if (rank == MASTER_NODE) @@ -2111,8 +2119,10 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, /*--- A cap that has held the CFL through a quiet, converging stretch is raised, so that it does not * outlive the transient that caused it. A new event at the higher CFL brings it back down. It - * stays below the cap set at the last stall. ---*/ - const passivedouble probeLimit = (CFL_StallCap > 0.0) ? CFL_StallCap : 1e30; + * stays below the cap set at the last stall and below the flip-flop limit. ---*/ + if ((CFL_OscLevel > 0.0) && (flowMean < Res_AtOsc - oscReset)) CFL_OscLevel = -1.0; + passivedouble probeLimit = (CFL_StallCap > 0.0) ? CFL_StallCap : 1e30; + if (CFL_OscLevel > 0.0) probeLimit = min(probeLimit, max(oscCap * CFL_OscLevel, cflMin)); if ((CFL_Cap > 0.0) && (avgCFL > 0.95 * CFL_Cap) && (iter > max(CFL_LastEvent, CFL_LastStall) + capProbeQuiet) && (iter > CFL_LastCapProbe + capProbeQuiet) && ResTrend_Increase && (ResRise < growBelowBest) && (CFL_Cap < probeLimit)) { diff --git a/config_template.cfg b/config_template.cfg index 84f47e86f516..12f1fc9efeda 100644 --- a/config_template.cfg +++ b/config_template.cfg @@ -1547,7 +1547,8 @@ CFL_NUMBER= 15.0 % residual is far above its best value. Repeated events, a regression, a flip-flop, or all flow % residuals stalling for 30 iterations cap the CFL lasting below the level where that happened. Flow % residuals whose upper envelope stops falling over 100 iterations while the CFL no longer grows cap -% the CFL at half its value, a quarter on a second such stall, an eighth on a third. Uses +% the CFL at half its value, a quarter on a second such stall, an eighth on a third. A flip-flop caps +% the CFL at half the lowest CFL where one occurred, until the residuals fall three orders of magnitude. Uses % factor up/down and the CFL limits of CFL_ADAPT_PARAM, and never goes below the lower limit. With % OUTLIER_MITIGATION_PARAM the CFL is adapted on the linear solver convergence instead. CFL_ADAPT= NO From 13a05390d20b8f8ab011b740d6809fbedb1116d0 Mon Sep 17 00:00:00 2001 From: Nijso Date: Wed, 14 Oct 2026 21:10:43 +0200 Subject: [PATCH 15/42] Potential fix for pull request finding 'CodeQL / Poorly documented large function' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- Common/src/geometry/CPhysicalGeometry.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Common/src/geometry/CPhysicalGeometry.cpp b/Common/src/geometry/CPhysicalGeometry.cpp index 456d96b2757d..ef7de89ec30f 100644 --- a/Common/src/geometry/CPhysicalGeometry.cpp +++ b/Common/src/geometry/CPhysicalGeometry.cpp @@ -7514,15 +7514,27 @@ unsigned long CPhysicalGeometry::KeepLinesTogether(const vector& return movedGlobal; } +/*! + * \brief Compute graph edge weights that encode mesh anisotropy for partitioning. + * + * The routine builds edge weights from geometric information of neighboring points. + * Since element connectivity can reference points owned by other MPI ranks, it first + * exchanges the remote coordinates that are required locally. The resulting weights are + * scaled/clamped to the user-provided \p maxWeight and returned in graph-edge order. + * + * \param[in] maxWeight Upper bound used when converting anisotropy metrics to integer + * partitioning weights. + * \return Edge weights suitable for graph partitioning (one value per graph edge entry). + */ vector CPhysicalGeometry::ComputeAnisotropyEdgeWeights(long maxWeight) const { + /*--- Build local/global point-index helpers used throughout communication. ---*/ CLinearPartitioner pointPartitioner(Global_nPointDomain, 0); const unsigned long firstIndex = pointPartitioner.GetFirstIndexOnRank(rank); const auto isLocal = [&](unsigned long iGlobal) { return (iGlobal >= firstIndex) && (iGlobal - firstIndex < nPoint); }; - /*--- Request the coordinates of element nodes that other ranks hold. ---*/ - + /*--- Identify remote element nodes whose coordinates must be requested. ---*/ vector> request(size); for (auto iElem = 0ul; iElem < nElem; iElem++) { for (auto iNode = 0u; iNode < elem[iElem]->GetnNodes(); iNode++) { @@ -7531,6 +7543,7 @@ vector CPhysicalGeometry::ComputeAnisotropyEdgeWeights(long maxWeight) co } } + /*--- Exchange request sizes (after deduplication) to prepare all-to-all transfers. ---*/ vector nSend(size), nRecv(size), sendDisp(size + 1, 0), recvDisp(size + 1, 0); for (int iRank = 0; iRank < size; iRank++) { auto& list = request[iRank]; From 947e88e02cfeb4a4db6a2ae4d637cba2b072f6e6 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Thu, 15 Oct 2026 12:04:05 +0200 Subject: [PATCH 16/42] update --- Common/include/linear_algebra/CSysMatrix.hpp | 33 ++++ Common/src/CConfig.cpp | 5 + Common/src/geometry/CMultiGridGeometry.cpp | 187 ++++++++++++++++--- Common/src/linear_algebra/CSysMatrix.cpp | 125 ++++++++++++- 4 files changed, 316 insertions(+), 34 deletions(-) diff --git a/Common/include/linear_algebra/CSysMatrix.hpp b/Common/include/linear_algebra/CSysMatrix.hpp index 70dd943690ec..2b0b00dbc4a2 100644 --- a/Common/include/linear_algebra/CSysMatrix.hpp +++ b/Common/include/linear_algebra/CSysMatrix.hpp @@ -34,6 +34,7 @@ #include "CPastixWrapper.hpp" #include "../toolboxes/graph_toolbox.hpp" +#include #include #include #include @@ -360,6 +361,19 @@ class CSysMatrix { * into ilu_level_ptr / d_precond_level_idx below for the GPU triangular solves. */ CCompressedSparsePatternUL levels_ilu; + /*!< \brief Per-thread progress counter, padded to a cache line. */ + struct alignas(64) LevelProgress { + std::atomic steps{0}; + LevelProgress() = default; + LevelProgress(const LevelProgress& other) : steps(other.steps.load()) {} + }; + + /*!< \brief Steps each thread must see completed by every other thread, per (step, thread, other thread), + * for the forward and backward level scheduled sweeps. Empty when barriers separate the levels. */ + std::vector level_waits_fwd, level_waits_bwd; + mutable std::vector level_progress; + unsigned long level_num_threads = 0; + /*!< \brief Coloring of the (domain-only) ILU dependency graph, used only by the GPU iterative * factorization (see IluFactorColorKernel and ilu_color_ptr / d_ilu_color_idx below). The * host/OMP path and the GPU triangular solves use levels_ilu instead. */ @@ -663,6 +677,25 @@ class CSysMatrix { void ComputeJacobiPreconditionerGPU(const CSysVector& vec, CSysVector& prod, CGeometry* geometry, const CConfig* config) const; + /*! + * \brief Compute the wait tables of the point-to-point synchronized level scheduled sweeps. + */ + void BuildLevelWaits(); + + /*! + * \brief Apply a function to the rows of all levels in increasing or decreasing order, waiting only for + * the threads owning the rows depended on. Must be called by all threads of the team. + */ + template + void LevelSweep(bool forward, const F& row_func) const; + + /*! + * \brief Whether the calling thread team matches the one the wait tables were built for. + */ + inline bool UseLevelWaits() const { + return !level_waits_fwd.empty() && static_cast(omp_get_num_threads()) == level_num_threads; + } + /*! * \brief Build the ILU preconditioner on the device, from the device copy of the matrix. * \note Requires the device matrix to be up to date, see HtDTransfer. diff --git a/Common/src/CConfig.cpp b/Common/src/CConfig.cpp index 00f336540214..50a5780f6b64 100644 --- a/Common/src/CConfig.cpp +++ b/Common/src/CConfig.cpp @@ -4790,6 +4790,11 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i } } + if (RampMUSCL && !(MUSCL_Flow || MUSCL_Turb || MUSCL_Species || MUSCL_Heat)) { + if (rank == MASTER_NODE) cout << "WARNING: RAMP_MUSCL is ignored because no MUSCL reconstruction is active." << endl; + RampMUSCL = false; + } + if(RampMUSCL && !DiscreteAdjoint){ if (RampMUSCLParam.RampMUSCLPower <= 0.0) SU2_MPI::Error("RAMP_MUSCL_POWER cannot be less than or equal to zero!", CURRENT_FUNCTION); rampMUSCLValue = 0.0; diff --git a/Common/src/geometry/CMultiGridGeometry.cpp b/Common/src/geometry/CMultiGridGeometry.cpp index b9775579cd65..5131655f9bfb 100644 --- a/Common/src/geometry/CMultiGridGeometry.cpp +++ b/Common/src/geometry/CMultiGridGeometry.cpp @@ -100,6 +100,8 @@ bool AbsorbedSymmetry(const CGeometry* grid, const CConfig* config, unsigned lon return hasOther; } +bool HasElements(const CGeometry* grid); + } // namespace CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, unsigned short iMesh) : CGeometry() { @@ -465,6 +467,41 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un addMember(iPoint); + /*--- A seed standing in a free quadrilateral or hexahedron takes that element whole, the one + * pressing hardest against what is already agglomerated, so leftover structured mesh is + * tiled by whole cells. ---*/ + if (HasElements(fine_grid)) { + auto bestElem = NO_CV; + unsigned long bestContact = 0, bestKey = NO_CV; + for (auto iElem = 0u; iElem < fine_grid->nodes->GetnElem(iPoint); ++iElem) { + const auto jElem = fine_grid->nodes->GetElem(iPoint, iElem); + const auto* elem = fine_grid->elem[jElem]; + if ((elem->GetVTK_Type() != QUADRILATERAL) && (elem->GetVTK_Type() != HEXAHEDRON)) continue; + + bool free = true; + unsigned long contact = 0, key = NO_CV; + for (auto iNode = 0u; (iNode < elem->GetnNodes()) && free; ++iNode) { + const auto kPoint = elem->GetNode(iNode); + key = std::min(key, fine_grid->nodes->GetGlobalIndex(kPoint)); + if (kPoint == iPoint) continue; + free = !fine_grid->nodes->GetAgglomerate(kPoint) && fine_grid->nodes->GetDomain(kPoint) && + GeometricalCheck(kPoint, fine_grid, config); + for (auto mPoint : fine_grid->nodes->GetPoints(kPoint)) contact += fine_grid->nodes->GetAgglomerate(mPoint); + } + if (!free) continue; + if ((bestElem == NO_CV) || (contact > bestContact) || ((contact == bestContact) && (key < bestKey))) { + bestElem = jElem; + bestContact = contact; + bestKey = key; + } + } + if (bestElem != NO_CV) { + const auto* elem = fine_grid->elem[bestElem]; + for (auto iNode = 0u; iNode < elem->GetnNodes(); ++iNode) + if (elem->GetNode(iNode) != iPoint) addMember(elem->GetNode(iNode)); + } + } + edgeDir.clear(); edgeLen.clear(); su2double seedShortest = std::numeric_limits::max(); @@ -1957,6 +1994,8 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co const auto nPointFine = fine_grid->GetnPoint(); constexpr auto NO_COLUMN = std::numeric_limits::max(); const short int maxAgglomSize = MaxAgglomSize(nDim); + /*--- Largest CV a parity leftover may form by joining its neighbour. ---*/ + const size_t maxOversize = 3 * maxAgglomSize / 2; /*--- SeedFrontNodes returns the seeds ordered by anisotropy. ---*/ auto seeds = SeedFrontNodes(fine_grid, config); @@ -2224,9 +2263,10 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co /*--- A column follows the stiff direction of the mesh. A step whose edges couple far more * weakly than the stiffest edge at their node runs along a thin layer, not across it, - * and is left to a column crossing that layer. ---*/ + * and is left to a column crossing that layer. A column rising from a no-slip wall + * stops only at a much thinner layer, so moderate stretching does not cut it short. ---*/ auto stiffStep = [&](const vector& set) { - constexpr passivedouble STIFF_FRACTION = 0.1; + const passivedouble STIFF_FRACTION = (tierOf[iColumn] <= 1) ? 0.01 : 0.1; su2double ratio = 0.0; for (auto iPoint : layer[iColumn]) { su2double wStep = 0.0, wMax = 0.0; @@ -2243,7 +2283,38 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co return ratio >= STIFF_FRACTION * su2double(layer[iColumn].size()); }; - if (complete(candidates) && stiffStep(candidates)) { + /*--- Whether every node of the step reaches a physical boundary within a few steps on the + * way it travels. A band two coarse cells thin is taken, the domain pass tiles it poorly. ---*/ + auto nearBoundary = [&](const vector& set, const vector>& dirs) { + constexpr unsigned short THIN_BAND = 4; + for (size_t k = 0; k < set.size(); ++k) { + auto iPoint = set[k]; + bool reached = false; + for (unsigned short iStep = 0; (iStep < THIN_BAND) && !reached; ++iStep) { + auto next = NO_COLUMN; + su2double bestAlign = 0.0; + for (auto jPoint : fine_grid->nodes->GetPoints(iPoint)) { + su2double step[MAXNDIM] = {0.0}; + GeometryToolbox::Distance(nDim, fine_grid->nodes->GetCoord(jPoint), fine_grid->nodes->GetCoord(iPoint), + step); + const su2double len = GeometryToolbox::Norm(nDim, step); + if (len <= 0.0) continue; + const su2double align = GeometryToolbox::DotProduct(nDim, step, dirs[k].data()) / len; + if (align > bestAlign) { + bestAlign = align; + next = jPoint; + } + } + if (next == NO_COLUMN) return false; + reached = onPhysBoundary[next]; + iPoint = next; + } + if (!reached) return false; + } + return true; + }; + + if (complete(candidates) && (stiffStep(candidates) || nearBoundary(candidates, stepDir))) { for (auto jPoint : candidates) { columnOf[jPoint] = iColumn; layerOf[jPoint] = iRound; @@ -2404,6 +2475,28 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co } } + /*--- Last-layer nodes whose next step, the way they travel, lands on free mesh. ---*/ + vector openAhead(nPointFine, 0); + for (auto iColumn = 0ul; iColumn < layer.size(); ++iColumn) { + for (size_t k = 0; k < layer[iColumn].size(); ++k) { + const auto iPoint = layer[iColumn][k]; + auto next = NO_COLUMN; + su2double bestAlign = 0.0; + for (auto jPoint : fine_grid->nodes->GetPoints(iPoint)) { + su2double step[MAXNDIM] = {0.0}; + GeometryToolbox::Distance(nDim, fine_grid->nodes->GetCoord(jPoint), fine_grid->nodes->GetCoord(iPoint), step); + const su2double len = GeometryToolbox::Norm(nDim, step); + if (len <= 0.0) continue; + const su2double align = GeometryToolbox::DotProduct(nDim, step, dirOf[iColumn][k].data()) / len; + if (align > bestAlign) { + bestAlign = align; + next = jPoint; + } + } + openAhead[iPoint] = (next != NO_COLUMN) && admissible(next); + } + } + /*--- Gather each column by layer. ---*/ const auto nColumn = layer.size(); vector>> byLayer(nColumn); @@ -2429,9 +2522,10 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co const auto nCommon = std::min(byLayer[iColumn].size(), byLayer[jColumn].size()); for (auto iLayer = 1ul; iLayer < nCommon; ++iLayer) { const auto iPoint = byLayer[iColumn][iLayer].front(); - const auto jPoint = byLayer[jColumn][iLayer].front(); + const auto& jLayer = byLayer[jColumn][iLayer]; bool touch = false; - for (auto kPoint : fine_grid->nodes->GetPoints(iPoint)) touch = touch || (kPoint == jPoint); + for (auto kPoint : fine_grid->nodes->GetPoints(iPoint)) + touch = touch || (std::find(jLayer.begin(), jLayer.end(), kPoint) != jLayer.end()); if (!touch) return false; } return nCommon > 1; @@ -2446,28 +2540,39 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co fine_grid->nodes->GetGlobalIndex(byLayer[b][0].front()); }); - for (auto iColumn : narrow) { - if (partnerOf[iColumn] >= 0) continue; - auto best = NO_COLUMN; - auto bestKey = std::numeric_limits::max(); - - for (auto jPoint : fine_grid->nodes->GetPoints(byLayer[iColumn][1].front())) { - const auto jColumn = columnOf[jPoint]; - if ((jColumn == NO_COLUMN) || (jColumn == iColumn)) continue; - if ((partnerOf[jColumn] >= 0) || !isNarrow(jColumn)) continue; - if (tierOf[jColumn] != tierOf[iColumn]) continue; - if (!aligned(iColumn, jColumn)) continue; - - const auto key = fine_grid->nodes->GetGlobalIndex(byLayer[jColumn][0].front()); - if (key < bestKey) { - bestKey = key; - best = jColumn; + /*--- A column a narrow one may lean on when no narrow neighbour is left: seeded, grown, and + * narrow enough that the merged block stays within the oversize limit. ---*/ + auto isWide = [&](unsigned long iColumn) { + return isSeeded[iColumn] && (byLayer[iColumn].size() > 1) && (byLayer[iColumn][0].size() > 1) && + (2 * (byLayer[iColumn][0].size() + 1) <= maxOversize); + }; + + /*--- Narrow neighbours pair first, the narrow columns left over then join a wide one. ---*/ + for (const bool toWide : {false, true}) { + for (auto iColumn : narrow) { + if (partnerOf[iColumn] >= 0) continue; + auto best = NO_COLUMN; + auto bestKey = std::numeric_limits::max(); + + for (auto jPoint : fine_grid->nodes->GetPoints(byLayer[iColumn][1].front())) { + const auto jColumn = columnOf[jPoint]; + if ((jColumn == NO_COLUMN) || (jColumn == iColumn) || (partnerOf[jColumn] >= 0)) continue; + if (toWide ? !isWide(jColumn) : !isNarrow(jColumn)) continue; + /*--- The column above a corner, tier 0, may pair with either side. ---*/ + if ((tierOf[jColumn] != tierOf[iColumn]) && (tierOf[jColumn] != 0) && (tierOf[iColumn] != 0)) continue; + if (!aligned(iColumn, jColumn)) continue; + + const auto key = fine_grid->nodes->GetGlobalIndex(byLayer[jColumn][0].front()); + if (key < bestKey) { + bestKey = key; + best = jColumn; + } } - } - if (best == NO_COLUMN) continue; - partnerOf[iColumn] = static_cast(best); - partnerOf[best] = static_cast(iColumn); + if (best == NO_COLUMN) continue; + partnerOf[iColumn] = static_cast(best); + partnerOf[best] = static_cast(iColumn); + } } } @@ -2488,7 +2593,7 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co /*--- Hand a set of nodes out as coarse CVs, each connected and within the size limit. ---*/ vector inSet(nPointFine, 0); vector chunk, stack; - auto emitConnected = [&](const vector& set) { + auto emitConnected = [&](const vector& set, size_t maxSize) { for (auto iPoint : set) inSet[iPoint] = 1; for (auto iSeed : set) { @@ -2497,13 +2602,13 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co stack.assign(1, iSeed); inSet[iSeed] = 0; - while (!stack.empty() && (chunk.size() < static_cast(maxAgglomSize))) { + while (!stack.empty() && (chunk.size() < maxSize)) { const auto iPoint = stack.back(); stack.pop_back(); chunk.push_back(iPoint); for (auto jPoint : fine_grid->nodes->GetPoints(iPoint)) { if (!inSet[jPoint]) continue; - if (chunk.size() + stack.size() >= static_cast(maxAgglomSize)) break; + if (chunk.size() + stack.size() >= maxSize) break; inSet[jPoint] = 0; stack.push_back(jPoint); } @@ -2542,6 +2647,9 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co if ((partnerOf[iColumn] >= 0) && (partnerOf[iColumn] < static_cast(iColumn))) continue; const auto* emitted = &layers; + /*--- The block depth follows the widest of the columns, as it would for each on its own. ---*/ + auto blockWidth = layers.back().size(); + auto maxSize = static_cast(maxAgglomSize); if (partnerOf[iColumn] > static_cast(iColumn)) { const auto& other = byLayer[partnerOf[iColumn]]; paired = layers; @@ -2552,15 +2660,19 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co paired.push_back(other[k]); } emitted = &paired; + blockWidth = std::max(blockWidth, other.back().size()); + /*--- A narrow column leaning on a wide one is a parity strip, its cells may be oversized. ---*/ + if (blockWidth > 1) maxSize = maxOversize; } + const auto block = BlockFor(maxAgglomSize, blockWidth); /*--- Above it, consecutive layers are blocked so the coarse cell coarsens by the same ratio * along the column as the patch does across it. ---*/ while (iLayer < emitted->size()) { group.clear(); - const auto block = BlockFor(maxAgglomSize, (*emitted)[iLayer].size()); + auto groupSize = maxSize; for (auto k = 0ul; (k < block) && (iLayer < emitted->size()); ++k) { - if (!group.empty() && (group.size() + (*emitted)[iLayer].size() > static_cast(maxAgglomSize))) break; + if (!group.empty() && (group.size() + (*emitted)[iLayer].size() > maxSize)) break; group.insert(group.end(), (*emitted)[iLayer].begin(), (*emitted)[iLayer].end()); iLayer++; } @@ -2569,7 +2681,20 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co group = (*emitted)[iLayer]; iLayer++; } - emitConnected(group); + /*--- An odd last layer facing free mesh is left to the domain pass, which can pair it with + * that mesh. Otherwise it joins the block below instead of standing one layer thick. ---*/ + if ((block > 1) && (iLayer + 1 == emitted->size())) { + bool open = true; + for (auto iPoint : emitted->back()) open = open && openAhead[iPoint]; + if (open) { + iLayer++; + } else if (group.size() + emitted->back().size() <= static_cast(maxOversize)) { + group.insert(group.end(), emitted->back().begin(), emitted->back().end()); + groupSize = group.size(); + iLayer++; + } + } + emitConnected(group, groupSize); } } if (minDepth == std::numeric_limits::max()) minDepth = 0; diff --git a/Common/src/linear_algebra/CSysMatrix.cpp b/Common/src/linear_algebra/CSysMatrix.cpp index 503e2ad4893c..ab75feb32ba6 100644 --- a/Common/src/linear_algebra/CSysMatrix.cpp +++ b/Common/src/linear_algebra/CSysMatrix.cpp @@ -31,6 +31,9 @@ #include "../../include/linear_algebra/CMatrixInverse.hpp" #include "../../include/toolboxes/allocation_toolbox.hpp" +#include + +#include #include #include #include @@ -350,9 +353,19 @@ void CSysMatrix::Initialize(unsigned long npoint, unsigned long npoi /*--- The GPU triangular solves are level-scheduled (exact, one pass per level), so they need * levels_ilu unconditionally; the host/OMP path only needs it when both multi-threaded and * requested via config. ---*/ - if (useCuda || (omp_get_max_threads() > 1 && config->GetIluOptions().LevelScheduling)) { + if (useCuda) { levels_ilu = computeLevels(pat_ilu.l); + } else if (omp_get_max_threads() > 1 && config->GetIluOptions().LevelScheduling) { + /*--- The levels only cover the domain points, like the thread partitions. ---*/ + const auto& pat_l = pat_ilu.l; + su2vector outerPtr(nPointDomain + 1); + for (auto i = 0ul; i <= nPointDomain; ++i) outerPtr(i) = pat_l.outerPtr()[i]; + su2vector innerIdx(outerPtr(nPointDomain)); + for (auto k = 0ul; k < innerIdx.size(); ++k) innerIdx(k) = pat_l.innerIdx()[k]; + levels_ilu = computeLevels(CCompressedSparsePatternUL(std::move(outerPtr), std::move(innerIdx))); } + level_waits_fwd.clear(); + level_waits_bwd.clear(); /*--- Coloring for the GPU iterative factorization, see IluFactorColorKernel. Colors are * true independent sets of the (domain-only, symmetric) dependency graph, computed the same @@ -521,6 +534,8 @@ void CSysMatrix::Initialize(unsigned long npoint, unsigned long npoi } } + if (ilu_needed && !levels_ilu.empty() && !useCuda && num_threads > 1) BuildLevelWaits(); + /*--- Generate MKL Kernels ---*/ #ifdef USE_MKL @@ -1060,6 +1075,102 @@ void CSysMatrix::ComputeJacobiPreconditioner(const CSysVector +void CSysMatrix::BuildLevelWaits() { + const auto nThreads = static_cast(omp_get_max_threads()); + const auto nLevels = levels_ilu.getOuterSize(); + + /*--- Level and owning thread of each row, the rows of a level are split in equal contiguous slices. ---*/ + + std::vector level(nPointDomain, 0), owner(nPointDomain, 0); + for (unsigned long iLevel = 0; iLevel < nLevels; ++iLevel) { + const unsigned long n = levels_ilu.getNumNonZeros(iLevel); + for (unsigned long iThread = 0; iThread < nThreads; ++iThread) { + for (auto k = n * iThread / nThreads; k < n * (iThread + 1) / nThreads; ++k) { + const auto iPoint = levels_ilu.getInnerIdx(iLevel, k); + level[iPoint] = iLevel; + owner[iPoint] = iThread; + } + } + } + + std::vector fwd(nLevels * nThreads * nThreads, 0), bwd(fwd); + bool valid = true; + + for (unsigned long iLevel = 0; iLevel < nLevels; ++iLevel) { + const unsigned long n = levels_ilu.getNumNonZeros(iLevel); + const auto iStep = nLevels - 1 - iLevel; // Position in the backward sweep. + + for (unsigned long iThread = 0; iThread < nThreads; ++iThread) { + auto* wait_f = &fwd[(iLevel * nThreads + iThread) * nThreads]; + auto* wait_b = &bwd[(iStep * nThreads + iThread) * nThreads]; + + for (auto k = n * iThread / nThreads; k < n * (iThread + 1) / nThreads; ++k) { + const auto iPoint = levels_ilu.getInnerIdx(iLevel, k); + + for (auto kl = ilu.row_ptr_l[iPoint]; kl < ilu.row_ptr_l[iPoint + 1]; ++kl) { + const auto jPoint = ilu.col_ind_l[kl]; + if (level[jPoint] >= iLevel) valid = false; + wait_f[owner[jPoint]] = std::max(wait_f[owner[jPoint]], level[jPoint] + 1); + } + for (auto ku = ilu.row_ptr_u[iPoint]; ku < ilu.row_ptr_u[iPoint + 1]; ++ku) { + const auto jPoint = ilu.col_ind_u[ku]; + if (jPoint >= nPointDomain) break; + if (level[jPoint] <= iLevel) valid = false; + const auto jStep = nLevels - 1 - level[jPoint]; + wait_b[owner[jPoint]] = std::max(wait_b[owner[jPoint]], jStep + 1); + } + } + wait_f[iThread] = 0; + wait_b[iThread] = 0; + } + } + + /*--- The backward sweep needs a symmetric pattern, otherwise keep the barriers. ---*/ + if (!valid) return; + + level_waits_fwd = std::move(fwd); + level_waits_bwd = std::move(bwd); + level_num_threads = nThreads; + level_progress = std::vector(nThreads); +} + +template +template +void CSysMatrix::LevelSweep(bool forward, const F& row_func) const { + const auto nThreads = level_num_threads; + const auto iThread = static_cast(omp_get_thread_num()); + const auto nLevels = levels_ilu.getOuterSize(); + const auto& waits = forward ? level_waits_fwd : level_waits_bwd; + + /*--- All counters are equal at the start of a sweep. ---*/ + SU2_OMP_BARRIER + + auto& progress = level_progress[iThread].steps; + const uint64_t base = progress.load(std::memory_order_relaxed); + + for (unsigned long iStep = 0; iStep < nLevels; ++iStep) { + const auto* wait = &waits[(iStep * nThreads + iThread) * nThreads]; + + for (unsigned long jThread = 0; jThread < nThreads; ++jThread) { + if (wait[jThread] == 0) continue; + const uint64_t target = base + wait[jThread]; + for (unsigned spin = 0; level_progress[jThread].steps.load(std::memory_order_acquire) < target; ++spin) { + if (spin > 4096) sched_yield(); + } + } + + const auto iLevel = forward ? iStep : nLevels - 1 - iStep; + const unsigned long n = levels_ilu.getNumNonZeros(iLevel); + for (auto k = n * iThread / nThreads; k < n * (iThread + 1) / nThreads; ++k) { + row_func(levels_ilu.getInnerIdx(iLevel, k)); + } + progress.store(base + iStep + 1, std::memory_order_release); + } + + SU2_OMP_BARRIER +} + template void CSysMatrix::BuildILUPreconditioner() { SU2_ZONE_SCOPED @@ -1159,7 +1270,12 @@ void CSysMatrix::BuildILUPreconditioner() { InvertDiagonalBlockILUMatrix(iPoint); }; - if (levels_ilu.empty()) { + if (UseLevelWaits()) { + LevelSweep(true, [&](const auto iPoint) { + InitIluRow(iPoint); + BuildIluRow(iPoint, 0ul, nPointDomain); + }); + } else if (levels_ilu.empty()) { /*--- Each OMP thread will work on the submatrix defined from * row/col "begin" to row/col "end-1" (i.e. the range [begin,end[). * Which is exactly what the MPI-only implementation does. ---*/ @@ -1256,7 +1372,10 @@ void CSysMatrix::ComputeILUPreconditioner(const CSysVector Date: Fri, 16 Oct 2026 20:25:40 +0200 Subject: [PATCH 17/42] update linear prolongation --- Common/src/geometry/CMultiGridGeometry.cpp | 167 +++++++++++++++--- SU2_CFD/include/solvers/CSolver.hpp | 1 + .../src/integration/CMultiGridIntegration.cpp | 22 ++- SU2_CFD/src/solvers/CSolver.cpp | 11 +- 4 files changed, 167 insertions(+), 34 deletions(-) diff --git a/Common/src/geometry/CMultiGridGeometry.cpp b/Common/src/geometry/CMultiGridGeometry.cpp index 5131655f9bfb..235fe6a4a7b6 100644 --- a/Common/src/geometry/CMultiGridGeometry.cpp +++ b/Common/src/geometry/CMultiGridGeometry.cpp @@ -420,6 +420,7 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un vector inCV(fine_grid->GetnPoint(), 0); vector isCandidate(fine_grid->GetnPoint(), 0); vector members, candidates; + vector> wholeCells; members.reserve(maxAgglomSize); /*--- A local frame at the seed: up to nDim of its incident edges, as mutually orthogonal as @@ -469,38 +470,53 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un /*--- A seed standing in a free quadrilateral or hexahedron takes that element whole, the one * pressing hardest against what is already agglomerated, so leftover structured mesh is - * tiled by whole cells. ---*/ + * tiled by whole cells. A grid without elements, a coarse one, offers the 4-cycles of its + * connectivity as quadrilaterals. ---*/ + wholeCells.clear(); if (HasElements(fine_grid)) { - auto bestElem = NO_CV; - unsigned long bestContact = 0, bestKey = NO_CV; for (auto iElem = 0u; iElem < fine_grid->nodes->GetnElem(iPoint); ++iElem) { - const auto jElem = fine_grid->nodes->GetElem(iPoint, iElem); - const auto* elem = fine_grid->elem[jElem]; + const auto* elem = fine_grid->elem[fine_grid->nodes->GetElem(iPoint, iElem)]; if ((elem->GetVTK_Type() != QUADRILATERAL) && (elem->GetVTK_Type() != HEXAHEDRON)) continue; - - bool free = true; - unsigned long contact = 0, key = NO_CV; - for (auto iNode = 0u; (iNode < elem->GetnNodes()) && free; ++iNode) { - const auto kPoint = elem->GetNode(iNode); - key = std::min(key, fine_grid->nodes->GetGlobalIndex(kPoint)); - if (kPoint == iPoint) continue; - free = !fine_grid->nodes->GetAgglomerate(kPoint) && fine_grid->nodes->GetDomain(kPoint) && - GeometricalCheck(kPoint, fine_grid, config); - for (auto mPoint : fine_grid->nodes->GetPoints(kPoint)) contact += fine_grid->nodes->GetAgglomerate(mPoint); - } - if (!free) continue; - if ((bestElem == NO_CV) || (contact > bestContact) || ((contact == bestContact) && (key < bestKey))) { - bestElem = jElem; - bestContact = contact; - bestKey = key; + wholeCells.emplace_back(); + for (auto iNode = 0u; iNode < elem->GetnNodes(); ++iNode) + if (elem->GetNode(iNode) != static_cast(iPoint)) + wholeCells.back().push_back(elem->GetNode(iNode)); + } + } else if (nDim == 2) { + const auto neighbours = fine_grid->nodes->GetPoints(iPoint); + auto touching = [&](unsigned long a, unsigned long b) { + const auto around = fine_grid->nodes->GetPoints(a); + return std::find(around.begin(), around.end(), b) != around.end(); + }; + for (auto a : neighbours) + for (auto b : neighbours) { + if ((a >= b) || touching(a, b)) continue; + for (auto m : fine_grid->nodes->GetPoints(a)) + if ((m != iPoint) && touching(m, b) && !touching(m, iPoint)) wholeCells.push_back({a, m, b}); } + } + + auto bestCell = NO_CV; + unsigned long bestContact = 0, bestKey = NO_CV; + for (auto iCell = 0ul; iCell < wholeCells.size(); ++iCell) { + bool free = true; + unsigned long contact = 0, key = fine_grid->nodes->GetGlobalIndex(iPoint); + for (auto kPoint : wholeCells[iCell]) { + key = std::min(key, fine_grid->nodes->GetGlobalIndex(kPoint)); + free = free && !fine_grid->nodes->GetAgglomerate(kPoint) && fine_grid->nodes->GetDomain(kPoint) && + GeometricalCheck(kPoint, fine_grid, config); + if (!free) break; + for (auto mPoint : fine_grid->nodes->GetPoints(kPoint)) contact += fine_grid->nodes->GetAgglomerate(mPoint); } - if (bestElem != NO_CV) { - const auto* elem = fine_grid->elem[bestElem]; - for (auto iNode = 0u; iNode < elem->GetnNodes(); ++iNode) - if (elem->GetNode(iNode) != iPoint) addMember(elem->GetNode(iNode)); + if (!free) continue; + if ((bestCell == NO_CV) || (contact > bestContact) || ((contact == bestContact) && (key < bestKey))) { + bestCell = iCell; + bestContact = contact; + bestKey = key; } } + if (bestCell != NO_CV) + for (auto kPoint : wholeCells[bestCell]) addMember(kPoint); edgeDir.clear(); edgeLen.clear(); @@ -562,7 +578,7 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un } unsigned long best = NO_CV; - unsigned short best_shared = 0; + unsigned short best_shared = 0, best_flush = 0; su2double best_dist = std::numeric_limits::max(); for (auto CVPoint : candidates) { @@ -574,6 +590,24 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un * grow into a chain. ---*/ if ((nDim == 2) && (nChildren >= 3) && (shared < 2)) continue; + /*--- A pair does not grow into a line of three, the third node then seeds a pair of its own, + * so the cells of a row keep the phase of the cells beside them. ---*/ + if ((nDim == 2) && (nChildren == 2) && (shared == 1)) { + const auto around = fine_grid->nodes->GetPoints(CVPoint); + const bool firstTouches = std::find(around.begin(), around.end(), members[0]) != around.end(); + const auto tip = firstTouches ? members[0] : members[1], tail = firstTouches ? members[1] : members[0]; + su2double along[MAXNDIM] = {0.0}, across[MAXNDIM] = {0.0}; + for (unsigned short d = 0; d < nDim; ++d) { + along[d] = fine_grid->nodes->GetCoord(CVPoint, d) - fine_grid->nodes->GetCoord(tip, d); + across[d] = fine_grid->nodes->GetCoord(tip, d) - fine_grid->nodes->GetCoord(tail, d); + } + const su2double lenAlong = GeometryToolbox::Norm(nDim, along); + const su2double lenAcross = GeometryToolbox::Norm(nDim, across); + if ((lenAlong > 0.0) && (lenAcross > 0.0) && + (GeometryToolbox::DotProduct(nDim, along, across) > 0.5 * lenAlong * lenAcross)) + continue; + } + /*--- Distance to the centroid in cells: the offset is scaled by the seed edge pointing * most nearly along it. ---*/ su2double off[MAXNDIM] = {0.0}; @@ -593,9 +627,24 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un dist = r * r; } - if ((shared > best_shared) || ((shared == best_shared) && (dist < best_dist))) { + /*--- Between equals, the node lying flush against the same neighbouring CVs as the members + * keeps the cells of a structured mesh in line with those already made. ---*/ + unsigned short flush = 0; + for (auto jPoint : fine_grid->nodes->GetPoints(CVPoint)) { + if (!fine_grid->nodes->GetAgglomerate(jPoint) || inCV[jPoint]) continue; + bool lies = false; + for (auto kPoint : members) + for (auto lPoint : fine_grid->nodes->GetPoints(kPoint)) + lies = lies || ((lPoint != jPoint) && fine_grid->nodes->GetAgglomerate(lPoint) && !inCV[lPoint] && + (fine_grid->nodes->GetParent_CV(lPoint) == fine_grid->nodes->GetParent_CV(jPoint))); + flush += lies; + } + + if ((shared > best_shared) || ((shared == best_shared) && (flush > best_flush)) || + ((shared == best_shared) && (flush == best_flush) && (dist < best_dist))) { best = CVPoint; best_shared = shared; + best_flush = flush; best_dist = dist; } } @@ -811,6 +860,70 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un if (iTarget != NO_CV) mergeInto(iCoarsePoint, iTarget); } + /*--- In 2D, a CV of three nodes bent round a corner takes the fourth node of its quadrilateral from + * a neighbouring three-node CV that can spare it, which turns staggered seams into rectangles. ---*/ + if (nDim == 2) { + auto adjacent = [&](unsigned long iFinePoint, unsigned long jFinePoint) { + const auto neighbours = fine_grid->nodes->GetPoints(iFinePoint); + return std::find(neighbours.begin(), neighbours.end(), jFinePoint) != neighbours.end(); + }; + + for (auto iPass = 0u; iPass < 4; iPass++) { + bool changed = false; + + for (auto iCoarsePoint = 0ul; iCoarsePoint < nPointDomain; iCoarsePoint++) { + if (nodes->GetnChildren_CV(iCoarsePoint) != 3) continue; + if (mustStayAlone[iCoarsePoint] || isStackBase(iCoarsePoint) || touchesPartition[iCoarsePoint]) continue; + if ((iCoarsePoint >= firstLineCV) && (iCoarsePoint < endLineCV)) continue; + + /*--- The middle node of the bend touches the other two, which do not touch each other. ---*/ + unsigned long child[3]; + for (auto k = 0u; k < 3; k++) child[k] = nodes->GetChildren_CV(iCoarsePoint, k); + long corner = -1; + for (auto k = 0u; k < 3; k++) { + const auto a = child[(k + 1) % 3], b = child[(k + 2) % 3]; + if (adjacent(child[k], a) && adjacent(child[k], b) && !adjacent(a, b)) corner = k; + } + if (corner < 0) continue; + const auto a = child[(corner + 1) % 3], b = child[(corner + 2) % 3]; + + /*--- The node closing the quadrilateral touches both ends of the bend, not its middle. ---*/ + auto donor = NO_CV; + unsigned long fourth = NO_CV; + for (auto m : fine_grid->nodes->GetPoints(a)) { + const auto jCoarsePoint = fine_grid->nodes->GetParent_CV(m); + if ((jCoarsePoint == NO_CV) || (jCoarsePoint >= nPointDomain) || (jCoarsePoint == iCoarsePoint)) continue; + if (!adjacent(m, b) || adjacent(m, child[corner])) continue; + if (nodes->GetnChildren_CV(jCoarsePoint) != 3) continue; + if (mustStayAlone[jCoarsePoint] || isStackBase(jCoarsePoint) || touchesPartition[jCoarsePoint]) continue; + if ((jCoarsePoint >= firstLineCV) && (jCoarsePoint < endLineCV)) continue; + if (cvMarkerClass[jCoarsePoint] != cvMarkerClass[iCoarsePoint]) continue; + + /*--- What the donor keeps must stay connected. ---*/ + vector kept; + for (auto k = 0u; k < 3; k++) + if (nodes->GetChildren_CV(jCoarsePoint, k) != m) kept.push_back(nodes->GetChildren_CV(jCoarsePoint, k)); + if (!adjacent(kept[0], kept[1])) continue; + + donor = jCoarsePoint; + fourth = m; + break; + } + if (donor == NO_CV) continue; + + const auto nDonor = nodes->GetnChildren_CV(donor); + for (auto k = 0u; k < nDonor; k++) + if (nodes->GetChildren_CV(donor, k) == fourth) + nodes->SetChildren_CV(donor, k, nodes->GetChildren_CV(donor, nDonor - 1)); + nodes->SetnChildren_CV(donor, nDonor - 1); + giveChild(fourth, iCoarsePoint); + changed = true; + } + + if (!changed) break; + } + } + /*--- Compact the coarse numbering, squeezing out the indices the repair passes emptied. The children lists, indirect-agglomeration flags and owned parent indices are remapped. ---*/ diff --git a/SU2_CFD/include/solvers/CSolver.hpp b/SU2_CFD/include/solvers/CSolver.hpp index 66be4bfbb24d..f45f242e4d89 100644 --- a/SU2_CFD/include/solvers/CSolver.hpp +++ b/SU2_CFD/include/solvers/CSolver.hpp @@ -105,6 +105,7 @@ class CSolver { unsigned long CFL_LastStall = 0; /*!< \brief Iteration of the last stall cap. */ passivedouble CFL_StallCap = -1.0; /*!< \brief Cap set at the last stall, which cap increases stay below. */ passivedouble CFL_OscLevel = -1.0; /*!< \brief Lowest CFL at which the residuals flip-flopped. */ + unsigned long CFL_LastOscRelease = 0; /*!< \brief Iteration of the last flip-flop limit increase. */ passivedouble Res_AtOsc = 0.0; /*!< \brief Mean log flow residual at that flip-flop. */ unsigned short Stall_Count = 0; /*!< \brief Stalls since the residual last fell well below one. */ passivedouble Res_AtStall = 0.0; /*!< \brief Mean log flow residual at the last stall. */ diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index ed09cdc5108b..48ded9e5c43d 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -1025,6 +1025,11 @@ void CMultiGridIntegration::GetProlongated_Correction(unsigned short RunTime_EqS /*--- Largest condition number of the stencil directions for which the prolongation gradient is fitted. ---*/ static constexpr passivedouble PROLONG_MAX_CONDITION = 1e3; +/*--- Stencil aspect ratio up to which the fitted gradient is used in full, and from which the cell + * keeps the constant operator. In between the gradient fades out with the logarithm of the ratio. ---*/ +static constexpr passivedouble PROLONG_FULL_ASPECT = 10.0; +static constexpr passivedouble PROLONG_MAX_ASPECT = 100.0; + namespace { /*--- Condition number of a symmetric 2x2 or 3x3 matrix, infinite if it is not positive definite. ---*/ passivedouble FitConditionNumber(unsigned short nDim, const su2double A[3][3]) { @@ -1114,7 +1119,7 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe if ((global[0] > 0) && (SU2_MPI::GetRank() == MASTER_NODE)) cout << "MG level " << iMesh << ": linear prolongation keeps the constant operator in " << global[0] << " of " << global[1] << " coarse cells (stencil direction condition number above " - << PROLONG_MAX_CONDITION << ")." << endl; + << PROLONG_MAX_CONDITION << " or aspect ratio above " << PROLONG_MAX_ASPECT << ")." << endl; } } END_SU2_OMP_SAFE_GLOBAL_ACCESS @@ -1175,10 +1180,17 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe } } - /*--- Stretching alone leaves the fit well posed. Only neighbours that do not span every direction - * leave a slope undefined, and then the cell keeps the constant operator. ---*/ + /*--- Neighbours that do not span every direction leave a slope undefined. A stencil much longer in + * one direction than another, from cell stretching, weakens the gradient or removes it. In both + * cases the cell falls back to the constant operator. ---*/ su2double Ainv[MAXNDIM][MAXNDIM] = {{0.0}}; - if ((FitConditionNumber(nDim, Bmat) > PROLONG_MAX_CONDITION) || !CholeskyInverse(nDim, Amat, Ainv)) { + const passivedouble aspect = sqrt(FitConditionNumber(nDim, Amat)); + const passivedouble weight = + (aspect <= PROLONG_FULL_ASPECT) + ? 1.0 + : max(0.0, log(PROLONG_MAX_ASPECT / aspect) / log(PROLONG_MAX_ASPECT / PROLONG_FULL_ASPECT)); + if ((FitConditionNumber(nDim, Bmat) > PROLONG_MAX_CONDITION) || (weight <= 0.0) || + !CholeskyInverse(nDim, Amat, Ainv)) { SU2_OMP_ATOMIC prolongIllConditioned[iMesh]++; continue; @@ -1188,7 +1200,7 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe for (auto iDim = 0u; iDim < nDim; iDim++) { su2double value = 0.0; for (auto jDim = 0u; jDim < nDim; jDim++) value += Ainv[iDim][jDim]*rhs[iVar][jDim]; - gradient(iPoint, iVar, iDim) = value; + gradient(iPoint, iVar, iDim) = weight * value; } } END_SU2_OMP_FOR diff --git a/SU2_CFD/src/solvers/CSolver.cpp b/SU2_CFD/src/solvers/CSolver.cpp index 2b74232ae534..8424259327e0 100644 --- a/SU2_CFD/src/solvers/CSolver.cpp +++ b/SU2_CFD/src/solvers/CSolver.cpp @@ -2054,7 +2054,8 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, constexpr unsigned long stallPersist = 20; constexpr unsigned short stallMaxCount = 3; constexpr passivedouble stallProgress = 0.1, stallGrowth = 1.1, stallCut = 0.5, stallReset = 1.0; - constexpr passivedouble oscCap = 0.5, oscReset = 3.0; + constexpr passivedouble oscCap = 0.5, oscReset = 3.0, oscRelease = 1.2; + constexpr unsigned long oscQuiet = 100; if (iMesh == MESH_0) { const passivedouble avgCFL = SU2_TYPE::GetValue(Avg_CFL_Local); @@ -2244,8 +2245,14 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, /*--- A cap that has held the CFL through a quiet, converging stretch is raised, so that it does not * outlive the transient that caused it. A new event at the higher CFL brings it back down. It - * stays below the cap set at the last stall and below the flip-flop limit. ---*/ + * stays below the cap set at the last stall and below the flip-flop limit, which itself rises + * in small steps over quiet, converging stretches. ---*/ if ((CFL_OscLevel > 0.0) && (flowMean < Res_AtOsc - oscReset)) CFL_OscLevel = -1.0; + if ((CFL_OscLevel > 0.0) && (iter > max(CFL_LastEvent, CFL_LastOscRelease) + oscQuiet) && ResTrend_Increase && + (ResRise < growBelowBest)) { + CFL_OscLevel *= oscRelease; + CFL_LastOscRelease = iter; + } passivedouble probeLimit = (CFL_StallCap > 0.0) ? CFL_StallCap : 1e30; if (CFL_OscLevel > 0.0) probeLimit = min(probeLimit, max(oscCap * CFL_OscLevel, cflMin)); if ((CFL_Cap > 0.0) && (avgCFL > 0.95 * CFL_Cap) && (iter > max(CFL_LastEvent, CFL_LastStall) + capProbeQuiet) && From a66ff5172d33d68d60958f128626679cefefa938 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sat, 17 Oct 2026 11:31:56 +0200 Subject: [PATCH 18/42] less linear iterations for coarser grids --- Common/include/CConfig.hpp | 2 + Common/include/linear_algebra/CSysSolve.hpp | 3 +- Common/include/option_structure.hpp | 1 + Common/src/CConfig.cpp | 10 +++++ Common/src/linear_algebra/CSysSolve.cpp | 4 +- .../integration/CMultiGridIntegration.hpp | 8 ++++ .../include/solvers/CFVMFlowSolverBase.inl | 3 +- SU2_CFD/include/solvers/CScalarSolver.inl | 3 +- .../src/integration/CMultiGridIntegration.cpp | 40 ++++++++++++++++++- 9 files changed, 67 insertions(+), 7 deletions(-) diff --git a/Common/include/CConfig.hpp b/Common/include/CConfig.hpp index b158eedffc10..43e819312d5a 100644 --- a/Common/include/CConfig.hpp +++ b/Common/include/CConfig.hpp @@ -1178,6 +1178,8 @@ class CConfig { unsigned short *MG_PreSmooth_p{nullptr}, *MG_PostSmooth_p{nullptr}, *MG_CorrecSmooth_p{nullptr}; unsigned short nMG_CflScaling_p{0}; su2double *MG_CflScaling_p{nullptr}; + unsigned short nMG_LinSolIter_p{0}; + unsigned short *MG_LinSolIter_p{nullptr}; ENUM_STREAMWISE_PERIODIC Kind_Streamwise_Periodic; /*!< \brief Kind of Streamwise periodic flow (pressure drop or massflow) */ bool Streamwise_Periodic_Temperature; /*!< \brief Use real periodicity for Energy equation or otherwise outlet source term. */ diff --git a/Common/include/linear_algebra/CSysSolve.hpp b/Common/include/linear_algebra/CSysSolve.hpp index 98ab059804ce..ca0f9db8e74d 100644 --- a/Common/include/linear_algebra/CSysSolve.hpp +++ b/Common/include/linear_algebra/CSysSolve.hpp @@ -455,9 +455,10 @@ class CSysSolve { * \param[in,out] LinSysSol - Linear system solution * \param[in] geometry - Geometrical definition of the problem. * \param[in] config - Definition of the particular problem. + * \param[in] maxIter - Iteration cap replacing LINEAR_SOLVER_ITER in standard mode, 0 keeps the config value. */ unsigned long Solve(MatrixType& Jacobian, const CSysVector& LinSysRes, CSysVector& LinSysSol, - CGeometry* geometry, const CConfig* config); + CGeometry* geometry, const CConfig* config, unsigned long maxIter = 0); /*! * \brief Solve the adjoint linear system using a Krylov subspace method diff --git a/Common/include/option_structure.hpp b/Common/include/option_structure.hpp index f79a0025d00c..de43007848fe 100644 --- a/Common/include/option_structure.hpp +++ b/Common/include/option_structure.hpp @@ -1231,6 +1231,7 @@ struct CMGOptions { std::vector MG_PostSmooth; /*!< \brief Multigrid post-smoothing iterations per level. */ std::vector MG_CorrecSmooth; /*!< \brief Multigrid Jacobi correction-smoothing per level. */ std::vector MG_CflScaling; /*!< \brief Per-level CFL scaling factors relative to the previous (finer) level. Entry [i] scales level i+1 from level i. Size = nMGLevels. */ + std::vector MG_LinSolIter; /*!< \brief Linear solver iteration cap per MG level (entry 0 = finest). */ bool MG_Smooth_EarlyExit{false}; /*!< \brief Enable early exit for MG smoothing iterations. */ bool MG_Smooth_Output{false}; /*!< \brief Output compact per-cycle smoothing summary. */ su2double MG_Smooth_StagnationTol{0.0}; /*!< \brief Stagnation early exit: stop if current_rms >= prev_rms * tol. 0 = disabled. */ diff --git a/Common/src/CConfig.cpp b/Common/src/CConfig.cpp index 4efcc49e342b..e89c72b6ed3b 100644 --- a/Common/src/CConfig.cpp +++ b/Common/src/CConfig.cpp @@ -2132,6 +2132,9 @@ void CConfig::SetConfig_Options() { /*!\brief MG_CFL_SCALING\n DESCRIPTION: Per-level CFL scaling factors for coarse MG levels. Entry i is the ratio CFL(i+1)/CFL(i). * If fewer values than nMGLevels are given, the last value is repeated. DEFAULT: 0.25 (i.e., 1/4 per level) \ingroup Config*/ addDoubleListOption("MG_CFL_SCALING", nMG_CflScaling_p, MG_CflScaling_p); + /*!\brief MG_LINEAR_SOLVER_ITER\n DESCRIPTION: Maximum linear solver iterations on coarse MG levels. Entry i applies to level i+1; + * the last value is repeated, and the cap never exceeds LINEAR_SOLVER_ITER. DEFAULT: LINEAR_SOLVER_ITER \ingroup Config*/ + addUShortListOption("MG_LINEAR_SOLVER_ITER", nMG_LinSolIter_p, MG_LinSolIter_p); /*!\par CONFIG_CATEGORY: Spatial Discretization \ingroup Config*/ /*--- Options related to the spatial discretization ---*/ @@ -5036,6 +5039,13 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i for (unsigned short i = 0; i < nMGLevels; ++i) MGOptions.MG_CflScaling[i] = 0.25; } + + /*--- Linear solver iteration cap per level; level 0 always uses LINEAR_SOLVER_ITER. ---*/ + MGOptions.MG_LinSolIter.assign(nMGLevels + 1, Linear_Solver_Iter); + for (unsigned short i = 1; i <= nMGLevels && nMG_LinSolIter_p != 0; ++i) { + const auto cap = MG_LinSolIter_p[min(i - 1, nMG_LinSolIter_p - 1)]; + MGOptions.MG_LinSolIter[i] = min(cap, Linear_Solver_Iter); + } } /*--- Override MG Smooth parameters ---*/ diff --git a/Common/src/linear_algebra/CSysSolve.cpp b/Common/src/linear_algebra/CSysSolve.cpp index c1a356dfbcce..57ab0e123294 100644 --- a/Common/src/linear_algebra/CSysSolve.cpp +++ b/Common/src/linear_algebra/CSysSolve.cpp @@ -1405,7 +1405,7 @@ bool CSysSolve::SetupInnerSolver(unsigned short kind_solver, const C template unsigned long CSysSolve::Solve(CSysMatrix& Jacobian, const CSysVector& LinSysRes, CSysVector& LinSysSol, CGeometry* geometry, - const CConfig* config) { + const CConfig* config, unsigned long maxIter) { SU2_ZONE_SCOPED /*--- A word about the templated types. It is assumed that the residual and solution vectors are always of su2doubles, @@ -1458,7 +1458,7 @@ unsigned long CSysSolve::Solve(CSysMatrix& Jacobian, con default: { KindSolver = config->GetKind_Linear_Solver(); KindPrecond = config->GetKind_Linear_Solver_Prec(); - MaxIter = config->GetLinear_Solver_Iter(); + MaxIter = (maxIter != 0) ? maxIter : config->GetLinear_Solver_Iter(); SolverTol = SU2_TYPE::GetValue(config->GetLinear_Solver_Error()); ScreenOutput = false; break; diff --git a/SU2_CFD/include/integration/CMultiGridIntegration.hpp b/SU2_CFD/include/integration/CMultiGridIntegration.hpp index 1bc2213845eb..2e5fb0c40029 100644 --- a/SU2_CFD/include/integration/CMultiGridIntegration.hpp +++ b/SU2_CFD/include/integration/CMultiGridIntegration.hpp @@ -372,6 +372,14 @@ class CMultiGridIntegration final : public CIntegration { unsigned short lastPreSmoothWorstStep[MAX_MG_LEVELS+1] = {}; unsigned short lastPostSmoothWorstStep[MAX_MG_LEVELS+1] = {}; + /*--- Linear solver iterations and final relative residual of each smoothing step, per level. ---*/ + struct LinSolInfo { + unsigned long iters; + passivedouble res; + }; + std::vector lastPreLinSol[MAX_MG_LEVELS+1]; + std::vector lastPostLinSol[MAX_MG_LEVELS+1]; + /*! \brief FinestMesh observed on the previous call; 0 also serves as the sentinel forcing a * reset on the first call, since a FULL cycle starts at FinestMesh == nMGLevels > 0. */ unsigned short mg_ramp_last_FinestMesh = 0; diff --git a/SU2_CFD/include/solvers/CFVMFlowSolverBase.inl b/SU2_CFD/include/solvers/CFVMFlowSolverBase.inl index 3a46fc8c4db6..35f020b4ad40 100644 --- a/SU2_CFD/include/solvers/CFVMFlowSolverBase.inl +++ b/SU2_CFD/include/solvers/CFVMFlowSolverBase.inl @@ -629,7 +629,8 @@ void CFVMFlowSolverBase::ImplicitEuler_Iteration(CGeometry *geometry, CSol } END_SU2_OMP_FOR - auto iter = System.Solve(Jacobian, LinSysRes, LinSysSol, geometry, config); + auto iter = System.Solve(Jacobian, LinSysRes, LinSysSol, geometry, config, + config->GetMGOptions().MG_LinSolIter[geometry->GetMGLevel()]); BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { SetIterLinSolver(iter); diff --git a/SU2_CFD/include/solvers/CScalarSolver.inl b/SU2_CFD/include/solvers/CScalarSolver.inl index af03659fe7f5..96c5f37e5cf6 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.inl +++ b/SU2_CFD/include/solvers/CScalarSolver.inl @@ -586,7 +586,8 @@ void CScalarSolver::ImplicitEuler_Iteration(CGeometry* geometry, C } END_SU2_OMP_FOR - auto iter = System.Solve(Jacobian, LinSysRes, LinSysSol, geometry, config); + auto iter = System.Solve(Jacobian, LinSysRes, LinSysSol, geometry, config, + config->GetMGOptions().MG_LinSolIter[geometry->GetMGLevel()]); BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { SetIterLinSolver(iter); diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index 48ded9e5c43d..6e1baf3207b7 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -552,6 +552,26 @@ void CMultiGridIntegration::MultiGrid_Iteration(CGeometry ****geometry, table << "-"; /*--- Corr.-smooth: defined on levels 0..nMGLevels-1; coarsest has none. ---*/ + /*--- Linear solver iterations and final relative residual of each smoothing step. ---*/ + auto linRows = [&](const char* name, const std::vector* info, unsigned short nLev) { + std::vector its(nMGLevels + 1, "-"), res(nMGLevels + 1, "-"); + for (unsigned short i = 0; i < nLev; ++i) { + std::ostringstream si, sr; + sr << std::scientific << std::setprecision(1); + for (std::size_t k = 0; k < info[i].size(); ++k) { + si << (k ? "," : "") << info[i][k].iters; + sr << (k ? "," : "") << info[i][k].res; + } + if (!info[i].empty()) { its[i] = si.str(); res[i] = sr.str(); } + } + table << std::string(name) + " its"; + for (const auto& str : its) table << str; + table << std::string(name) + " res"; + for (const auto& str : res) table << str; + }; + linRows("Pre-lin", lastPreLinSol, nMGLevels + 1); + linRows("Post-lin", lastPostLinSol, nMGLevels); + table << "Corr-smooth"; for (unsigned short i = 0; i < nMGLevels; ++i) table << cellStr(lastCorrecSmoothIters[i], mgOptsZone.MG_CorrecSmooth[i], @@ -767,7 +787,7 @@ void CMultiGridIntegration::PreSmoothing(unsigned short RunTime_EqSystem, ? SU2_TYPE::GetValue(mgOpts.MG_Smooth_StagnationTol) : passivedouble(1.0); /*--- Reset the shared early-exit flag (master only). ---*/ - SU2_OMP_SAFE_GLOBAL_ACCESS(mg_early_exit_flag = false;) + SU2_OMP_SAFE_GLOBAL_ACCESS(mg_early_exit_flag = false; lastPreLinSol[iMesh].clear();) for (unsigned short iPreSmooth = 0; iPreSmooth < nPreSmooth; iPreSmooth++) { /*--- Time and space integration ---*/ @@ -792,6 +812,14 @@ void CMultiGridIntegration::PreSmoothing(unsigned short RunTime_EqSystem, /*--- Time integration, update solution using the old solution plus the solution increment ---*/ Time_Integration(geometry_fine, solver_container_fine, config, iRKStep, RunTime_EqSystem); + if (mgOpts.MG_Smooth_Output) { + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { + lastPreLinSol[iMesh].push_back({solver_fine->GetIterLinSolver(), + SU2_TYPE::GetValue(solver_fine->GetResLinSolver())}); + } + END_SU2_OMP_SAFE_GLOBAL_ACCESS + } + /*--- At iRKStep==0 LinSysRes = R(u_k). ---*/ if (iRKStep == 0 && need_initial_rms) { BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { @@ -843,7 +871,7 @@ void CMultiGridIntegration::PostSmoothing(unsigned short RunTime_EqSystem, ? SU2_TYPE::GetValue(mgOpts.MG_Smooth_StagnationTol) : passivedouble(1.0); /*--- Reset the shared early-exit flag (master only). ---*/ - SU2_OMP_SAFE_GLOBAL_ACCESS(mg_early_exit_flag = false;) + SU2_OMP_SAFE_GLOBAL_ACCESS(mg_early_exit_flag = false; lastPostLinSol[iMesh].clear();) /*--- Do a postsmoothing on the grid iMesh after prolongation from the grid iMesh+1 ---*/ for (unsigned short iPostSmooth = 0; iPostSmooth < nPostSmooth; iPostSmooth++) { @@ -865,6 +893,14 @@ void CMultiGridIntegration::PostSmoothing(unsigned short RunTime_EqSystem, /*--- Time integration, update solution using the old solution plus the solution increment ---*/ Time_Integration(geometry_fine, solver_container_fine, config, iRKStep, RunTime_EqSystem); + if (mgOpts.MG_Smooth_Output) { + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { + lastPostLinSol[iMesh].push_back({solver_fine->GetIterLinSolver(), + SU2_TYPE::GetValue(solver_fine->GetResLinSolver())}); + } + END_SU2_OMP_SAFE_GLOBAL_ACCESS + } + /*--- At iRKStep==0 LinSysRes = R(u_k) ---*/ if (iRKStep == 0 && need_per_step_rms) { BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { From 3ddbe3534426bda81fa8365cc7c5ecff464148d7 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sat, 17 Oct 2026 22:18:06 +0200 Subject: [PATCH 19/42] modify adaptive CFL stalling behavior --- SU2_CFD/include/solvers/CSolver.hpp | 14 +++-- SU2_CFD/src/solvers/CSolver.cpp | 92 ++++++++++++++++++++--------- 2 files changed, 73 insertions(+), 33 deletions(-) diff --git a/SU2_CFD/include/solvers/CSolver.hpp b/SU2_CFD/include/solvers/CSolver.hpp index f45f242e4d89..f227dee18ca7 100644 --- a/SU2_CFD/include/solvers/CSolver.hpp +++ b/SU2_CFD/include/solvers/CSolver.hpp @@ -98,17 +98,23 @@ class CSolver { vector CFL_EventValues; /*!< \brief CFL at each cut. */ unsigned long CFL_LastEvent = 0; /*!< \brief Iteration of the last cut. */ unsigned long CFL_LastCapProbe = 0; /*!< \brief Iteration of the last cap increase. */ - unsigned long CFL_LastFrozen = 0; /*!< \brief Iteration of the last frozen-residual cap. */ vector> ResStall_History; /*!< \brief Log flow residuals over two stall windows. */ vector CFLStall_History; /*!< \brief Mean CFL over two stall windows. */ unsigned long Stall_Streak = 0; /*!< \brief Consecutive iterations without envelope progress. */ - unsigned long CFL_LastStall = 0; /*!< \brief Iteration of the last stall cap. */ + unsigned long CFL_LastStall = 0; /*!< \brief Iteration of the last plateau. */ passivedouble CFL_StallCap = -1.0; /*!< \brief Cap set at the last stall, which cap increases stay below. */ passivedouble CFL_OscLevel = -1.0; /*!< \brief Lowest CFL at which the residuals flip-flopped. */ unsigned long CFL_LastOscRelease = 0; /*!< \brief Iteration of the last flip-flop limit increase. */ passivedouble Res_AtOsc = 0.0; /*!< \brief Mean log flow residual at that flip-flop. */ - unsigned short Stall_Count = 0; /*!< \brief Stalls since the residual last fell well below one. */ - passivedouble Res_AtStall = 0.0; /*!< \brief Mean log flow residual at the last stall. */ + bool Trial_Active = false; /*!< \brief CFL cuts at a residual plateau are being evaluated. */ + unsigned long Trial_Start = 0; /*!< \brief Iteration of the first cut of the trial. */ + unsigned long Trial_Hold = 0; /*!< \brief No trial starts before this iteration. */ + unsigned long Trial_Settle = 0; /*!< \brief Iteration after which the lowest CFL of the trial is judged. */ + passivedouble Trial_Res = 0.0; /*!< \brief Mean log flow residual when the trial started. */ + passivedouble Trial_CFL = 0.0; /*!< \brief Mean CFL when the trial started. */ + passivedouble Trial_Ceiling = -1.0; /*!< \brief CFL ceiling before the trial. */ + passivedouble Trial_Cap = -1.0; /*!< \brief CFL cap before the trial. */ + passivedouble Trial_StallCap = -1.0; /*!< \brief Plateau cap before the trial. */ unsigned short nVar, /*!< \brief Number of variables of the problem. */ nPrimVar, /*!< \brief Number of primitive variables of the problem. */ nPrimVarGrad, /*!< \brief Number of primitive variables of the problem in the gradient computation. */ diff --git a/SU2_CFD/src/solvers/CSolver.cpp b/SU2_CFD/src/solvers/CSolver.cpp index 8424259327e0..a47a4f899cb3 100644 --- a/SU2_CFD/src/solvers/CSolver.cpp +++ b/SU2_CFD/src/solvers/CSolver.cpp @@ -2042,7 +2042,7 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, if (!config->OptionIsSet("OUTLIER_MITIGATION_PARAM")) { constexpr size_t trendWindow = 5, jumpWindow = 3, spikeWindow = 5, frozenWindow = 30; constexpr passivedouble growBelow = 0.01, shrinkAbove = 0.03, jumpAbove = 0.75, spikeAbove = 1.0; - constexpr passivedouble frozenSpread = 0.05, frozenProgress = 0.02, frozenCut = 0.6; + constexpr passivedouble frozenSpread = 0.05, frozenProgress = 0.02; constexpr passivedouble linearBrake = 0.5, linearFailure = 0.8; constexpr unsigned long quietIters = 20, eventGap = 20, bestWindow = 100, regressGap = 5, regressEpisode = 30; constexpr unsigned long capProbeQuiet = 50; @@ -2052,8 +2052,10 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, constexpr passivedouble stuckSpread = 0.15, flipAmplitude = 0.03, flipProgress = 0.15; constexpr size_t stallWindow = 100; constexpr unsigned long stallPersist = 20; - constexpr unsigned short stallMaxCount = 3; - constexpr passivedouble stallProgress = 0.1, stallGrowth = 1.1, stallCut = 0.5, stallReset = 1.0; + constexpr passivedouble stallProgress = 0.1, stallGrowth = 1.1; + constexpr size_t slopeWindow = 60; + constexpr unsigned long trialHold = 300, trialQuiet = 100, trialSettle = 150; + constexpr passivedouble trialCut = 0.75, trialBudget = 30.0, fallingSlope = 0.3, trialResponse = 0.5; constexpr passivedouble oscCap = 0.5, oscReset = 3.0, oscRelease = 1.2; constexpr unsigned long oscQuiet = 100; @@ -2091,13 +2093,13 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, jump = jump || (logRes[iVar] - ResJump_History.front()[iVar] > spikeAbove); } - /*--- Flow residuals that all stop falling are stuck, not converging. The turbulence residual may - * still fall, so it is left out. The CFL cannot go below its lower limit, so nothing is done there. ---*/ + /*--- Flow residuals that all stop falling are frozen. The turbulence residual may still fall, so it + * is left out. The CFL cannot go below its lower limit, so nothing is done there. ---*/ const passivedouble cflMin = SU2_TYPE::GetValue(CFLMin); ResFlow_History.push_back(logRes); if (ResFlow_History.size() > frozenWindow + 1) ResFlow_History.erase(ResFlow_History.begin()); bool frozen = (ResFlow_History.size() > frozenWindow) && (iter >= startingIter + frozenWindow) && - (iter > CFL_LastEvent + frozenWindow) && (iter > CFL_LastFrozen + frozenWindow) && + (iter > CFL_LastEvent + frozenWindow) && (iter > CFL_LastStall + frozenWindow) && (avgCFL > 1.05 * cflMin); for (auto iVar = 0u; frozen && (iVar < logRes.size()); iVar++) { passivedouble lowest = ResFlow_History.front()[iVar], highest = lowest; @@ -2108,14 +2110,6 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, frozen = (ResFlow_History.front()[iVar] - ResFlow_History.back()[iVar] < frozenProgress) && (highest - lowest < frozenSpread); } - if (frozen) { - CFL_Cap = max(frozenCut * ((CFL_Cap > 0.0) ? min(CFL_Cap, avgCFL) : avgCFL), cflMin); - CFL_Ceiling = CFL_Cap; - CFL_LastFrozen = iter; - if (rank == MASTER_NODE) - cout << "CFL_ADAPT: flow residuals frozen at iteration " << iter << ", CFL capped at " << CFL_Cap - << "." << endl; - } /*--- A divergence that grows slowly never looks like a jump from one iteration to the next, so the * flow residual is also compared with its best value of the last bestWindow iterations. A residual @@ -2193,20 +2187,60 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, } else { Stall_Streak = 0; } - /*--- Each further stall before the residual falls well below the last one cuts twice as hard. ---*/ - if ((Stall_Count > 0) && (flowMean < Res_AtStall - stallReset)) Stall_Count = 0; - if (stall) { - Stall_Count = min(Stall_Count + 1, stallMaxCount); - Res_AtStall = flowMean; - const passivedouble cut = pow(stallCut, Stall_Count); - CFL_Cap = max(cut * ((CFL_Cap > 0.0) ? min(CFL_Cap, avgCFL) : avgCFL), cflMin); - CFL_Ceiling = CFL_Cap; - CFL_StallCap = CFL_Cap; + /*--- Cut a plateau repeatedly unless the residual is falling, and undo the cuts if it does not respond. ---*/ + const auto nMean = ResMean_History.size(); + auto meanSlope = [&](size_t window) { /* Least-squares slope in decades per 100 iterations. */ + passivedouble sumX = 0.0, sumY = 0.0, sumXY = 0.0, sumXX = 0.0; + for (size_t k = 0; k <= window; k++) { + const passivedouble y = ResMean_History[nMean - 1 - window + k]; + sumX += k; sumY += y; sumXY += k * y; sumXX += passivedouble(k) * k; + } + const passivedouble n = window + 1; + return 100.0 * (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX); + }; + if (Trial_Active && (CFL_LastEvent > Trial_Start)) Trial_Active = false; + if (Trial_Active && (iter >= CFL_LastStall + trialQuiet)) { + Trial_Active = false; + if (rank == MASTER_NODE) cout << "CFL_ADAPT: plateau ended, CFL cuts kept." << endl; + } + if ((frozen || stall) && (iter >= Trial_Hold) && (nMean > slopeWindow)) { + const passivedouble slope = meanSlope(slopeWindow); CFL_LastStall = iter; Stall_Streak = 0; - if (rank == MASTER_NODE) - cout << "CFL_ADAPT: residuals stalled at iteration " << iter << ", CFL capped at " << CFL_Cap << "." - << endl; + if (Trial_Active && (avgCFL < Trial_CFL / trialBudget) && (Trial_Settle == 0)) { + Trial_Settle = iter + trialSettle; + } else if (Trial_Active && (Trial_Settle > 0) && (iter < Trial_Settle)) { + /* The residual is given time to respond at the lowest CFL. */ + } else if (Trial_Active && (Trial_Settle > 0) && (Trial_Res - flowMean > trialResponse)) { + Trial_Active = false; + if (rank == MASTER_NODE) cout << "CFL_ADAPT: residuals responded to the CFL cuts, they are kept." << endl; + } else if (Trial_Active && (Trial_Settle > 0)) { + CFL_Cap = Trial_Cap; + CFL_Ceiling = Trial_Ceiling; + CFL_StallCap = Trial_StallCap; + Trial_Active = false; + Trial_Hold = iter + trialHold; + if (rank == MASTER_NODE) + cout << "CFL_ADAPT: residuals did not respond to the CFL cuts since iteration " << Trial_Start + << ", CFL cuts undone." << endl; + } else if (Trial_Active || (slope > -fallingSlope)) { + if (!Trial_Active) { + Trial_Active = true; + Trial_Start = iter; + Trial_CFL = avgCFL; + Trial_Res = flowMean; + Trial_Settle = 0; + Trial_Ceiling = CFL_Ceiling; + Trial_Cap = CFL_Cap; + Trial_StallCap = CFL_StallCap; + } + CFL_Cap = max(trialCut * ((CFL_Cap > 0.0) ? min(CFL_Cap, avgCFL) : avgCFL), cflMin); + CFL_Ceiling = CFL_Cap; + CFL_StallCap = CFL_Cap; + if (rank == MASTER_NODE) + cout << "CFL_ADAPT: residuals " << (frozen ? "frozen" : "stalled") << " at iteration " << iter + << ", CFL capped at " << CFL_Cap << "." << endl; + } } /*--- Halve the CFL on a jump or a failed linear solve and keep it below a ceiling. A second event @@ -2256,7 +2290,7 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, passivedouble probeLimit = (CFL_StallCap > 0.0) ? CFL_StallCap : 1e30; if (CFL_OscLevel > 0.0) probeLimit = min(probeLimit, max(oscCap * CFL_OscLevel, cflMin)); if ((CFL_Cap > 0.0) && (avgCFL > 0.95 * CFL_Cap) && (iter > max(CFL_LastEvent, CFL_LastStall) + capProbeQuiet) && - (iter > CFL_LastCapProbe + capProbeQuiet) && ResTrend_Increase && (ResRise < growBelowBest) && + (iter > CFL_LastCapProbe + capProbeQuiet) && !Trial_Active && ResTrend_Increase && (ResRise < growBelowBest) && (CFL_Cap < probeLimit)) { CFL_Cap = min(CFL_Cap * capProbeFactor, probeLimit); CFL_LastCapProbe = iter; @@ -2264,7 +2298,7 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, } /*--- Lift the ceiling again while the residuals fall, up to the cap. ---*/ - if ((CFL_Ceiling > 0.0) && (iter > CFL_LastEvent + quietIters) && ResTrend_Increase && (ResRise < growBelowBest)) { + if ((CFL_Ceiling > 0.0) && (iter > CFL_LastEvent + quietIters) && !Trial_Active && ResTrend_Increase && (ResRise < growBelowBest)) { CFL_Ceiling *= 1.05; if (CFL_Cap > 0.0) CFL_Ceiling = min(CFL_Ceiling, CFL_Cap); else if (CFL_Ceiling > SU2_TYPE::GetValue(CFLMax)) CFL_Ceiling = -1.0; @@ -2273,7 +2307,7 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, /*--- These replace the linear-residual and oscillation rules above. A poor linear solve holds the * CFL back gently, a failed one halves it above. ---*/ - canIncrease = ResTrend_Increase && (linRes < linearBrake) && (iter >= startingIter) && (ResRise < growBelowBest); + canIncrease = ResTrend_Increase && !Trial_Active && (linRes < linearBrake) && (iter >= startingIter) && (ResRise < growBelowBest); reduceCFL = (ResTrend_Reduce || (linRes > linearBrake)) && (iter >= startingIter); resetCFL = false; } From 33ba72532b145f6dbed2ee1b9f987852e89323f2 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sun, 18 Oct 2026 00:23:52 +0200 Subject: [PATCH 20/42] linear prolongation of the solution at full multigrid promotion MG_LINEAR_PROLONGATION now also selects the limited linear reconstruction when the full multigrid warmup hands its solution to the next finer level, for the flow and the scalar solvers. Co-Authored-By: Claude Opus 5.5 --- .../integration/CMultiGridIntegration.hpp | 24 +++++- .../src/integration/CMultiGridIntegration.cpp | 85 +++++++++++++------ 2 files changed, 80 insertions(+), 29 deletions(-) diff --git a/SU2_CFD/include/integration/CMultiGridIntegration.hpp b/SU2_CFD/include/integration/CMultiGridIntegration.hpp index 2e5fb0c40029..fdf426bf4608 100644 --- a/SU2_CFD/include/integration/CMultiGridIntegration.hpp +++ b/SU2_CFD/include/integration/CMultiGridIntegration.hpp @@ -146,9 +146,22 @@ class CMultiGridIntegration final : public CIntegration { * \param[in] geo_fine - Geometrical definition of the fine grid. * \param[in] geo_coarse - Geometrical definition of the coarse grid. * \param[in] config - Definition of the particular problem. + * \param[in] iMesh - Index of the coarse mesh. */ void SetProlongated_Solution(unsigned short RunTime_EqSystem, CSolver *sol_fine, CSolver *sol_coarse, - CGeometry *geo_fine, CGeometry *geo_coarse, CConfig *config); + CGeometry *geo_fine, CGeometry *geo_coarse, CConfig *config, unsigned short iMesh); + + /*! + * \brief Set the solution of every fine child from its coarse parent, constant or linearly reconstructed. + * \param[in,out] sol_fine - Solver on the fine grid. + * \param[in] sol_coarse - Solver on the coarse grid. + * \param[in] geo_fine - Geometrical definition of the fine grid. + * \param[in] geo_coarse - Geometrical definition of the coarse grid. + * \param[in] config - Definition of the particular problem. + * \param[in] iMesh - Index of the coarse mesh. + */ + void InterpolateSolutionToChildren(CSolver *sol_fine, CSolver *sol_coarse, CGeometry *geo_fine, + CGeometry *geo_coarse, CConfig *config, unsigned short iMesh); /*! @@ -201,14 +214,15 @@ class CMultiGridIntegration final : public CIntegration { /*! * \brief Least-squares gradient of the coarse-grid correction, limited so no child value * leaves the range of the coarse stencil. - * \param[in] sol_coarse - Solver holding the correction in Solution_Old. + * \param[in] sol_coarse - Solver holding the correction in Solution_Old, or the solution itself. * \param[in] geo_coarse - Geometrical definition of the coarse grid. * \param[in] geo_fine - Geometrical definition of the fine grid. * \param[in] config - Definition of the particular problem. * \param[in] iMesh - Index of the coarse mesh. + * \param[in] useSolution - Differentiate Solution instead of Solution_Old. */ void ComputeProlongationGradient(CSolver *sol_coarse, CGeometry *geo_coarse, CGeometry *geo_fine, - const CConfig *config, unsigned short iMesh); + const CConfig *config, unsigned short iMesh, bool useSolution); /*! * \brief Do an implicit smoothing of the prolongated correction. @@ -314,9 +328,11 @@ class CMultiGridIntegration final : public CIntegration { * \param[in] geo_coarse - Geometry of the level handing over. * \param[in] config - Definition of the particular problem. * \param[in] eddy_viscosity - Carry the eddy viscosity across as well. + * \param[in] iMesh - Index of the coarse mesh. */ void SetProlongated_ScalarSolution(CSolver *sol_fine, CSolver *sol_coarse, CGeometry *geo_fine, - CGeometry *geo_coarse, CConfig *config, bool eddy_viscosity); + CGeometry *geo_coarse, CConfig *config, bool eddy_viscosity, + unsigned short iMesh); /*! * \brief Helper function for early-exit logic during pre/post-smoothing. diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index 6e1baf3207b7..0ba8a46040f5 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -349,7 +349,7 @@ void CMultiGridIntegration::MultiGrid_Iteration(CGeometry ****geometry, solver_container[iZone][iInst][FinestMesh][Solver_Position], geometry[iZone][iInst][FinestMesh-1], geometry[iZone][iInst][FinestMesh], - config[iZone]); + config[iZone], FinestMesh); /*--- The scalar equations only restrict downward, so hand the new level their solution too, * otherwise they restart from their initial condition at every promotion. ---*/ @@ -363,7 +363,7 @@ void CMultiGridIntegration::MultiGrid_Iteration(CGeometry ****geometry, SetProlongated_ScalarSolution(scalar_fine, scalar_coarse, geometry[iZone][iInst][FinestMesh-1], geometry[iZone][iInst][FinestMesh], - config[iZone], Scalar_Position == TURB_SOL); + config[iZone], Scalar_Position == TURB_SOL, FinestMesh); } /*--- Report the promotion before the startup state is reset below. ---*/ @@ -1021,7 +1021,7 @@ void CMultiGridIntegration::GetProlongated_Correction(unsigned short RunTime_EqS /*--- The coarse coordinate is the volume-weighted centroid of the children, so the * reconstruction below averages back to the coarse correction exactly. ---*/ - ComputeProlongationGradient(sol_coarse, geo_coarse, geo_fine, config, iMesh); + ComputeProlongationGradient(sol_coarse, geo_coarse, geo_fine, config, iMesh, false); const unsigned short nDim = geo_coarse->GetnDim(); const auto& gradient = prolongGradient[iMesh]; @@ -1134,13 +1134,16 @@ bool CholeskyInverse(unsigned short n, const su2double A[3][3], su2double inv[3] void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGeometry *geo_coarse, CGeometry *geo_fine, const CConfig *config, - unsigned short iMesh) { + unsigned short iMesh, bool useSolution) { SU2_ZONE_SCOPED const unsigned short nVar = sol_coarse->GetnVar(); const unsigned short nDim = geo_coarse->GetnDim(); const auto nPointDomain = geo_coarse->GetnPointDomain(); auto* nodes = sol_coarse->GetNodes(); + auto Field = [&](unsigned long iPoint) { + return useSolution ? nodes->GetSolution(iPoint) : nodes->GetSolution_Old(iPoint); + }; /*--- Every thread of this rank takes this branch together, and the loops below would all be * empty anyway. It also keeps the sizing test off a container that was never resized. ---*/ @@ -1190,7 +1193,7 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe for (auto iDim = 0u; iDim < nDim; iDim++) gradient(iPoint, iVar, iDim) = 0.0; const auto* Coord_i = geo_coarse->nodes->GetCoord(iPoint); - const auto* Correction_i = nodes->GetSolution_Old(iPoint); + const auto* Correction_i = Field(iPoint); su2double Amat[MAXNDIM][MAXNDIM] = {{0.0}}, Bmat[MAXNDIM][MAXNDIM] = {{0.0}}; su2double rhs[MAXNVAR][MAXNDIM] = {{0.0}}; @@ -1208,7 +1211,7 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe Bmat[iDim][jDim] += Distance[iDim]*Distance[jDim]/dist2; } - const auto* Correction_j = nodes->GetSolution_Old(jPoint); + const auto* Correction_j = Field(jPoint); for (auto iVar = 0u; iVar < nVar; iVar++) { const su2double delta = Correction_j[iVar] - Correction_i[iVar]; @@ -1271,7 +1274,7 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe for (auto iPoint = 0ul; iPoint < nPointDomain; iPoint++) { const auto* Coord_i = geo_coarse->nodes->GetCoord(iPoint); - const auto* Correction_i = nodes->GetSolution_Old(iPoint); + const auto* Correction_i = Field(iPoint); su2double Correction_Min[MAXNVAR], Correction_Max[MAXNVAR]; for (auto iVar = 0u; iVar < nVar; iVar++) { @@ -1280,7 +1283,7 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe } for (auto jPoint : geo_coarse->nodes->GetPoints(iPoint)) { - const auto* Correction_j = nodes->GetSolution_Old(jPoint); + const auto* Correction_j = Field(jPoint); for (auto iVar = 0u; iVar < nVar; iVar++) { Correction_Min[iVar] = min(Correction_Min[iVar], Correction_j[iVar]); Correction_Max[iVar] = max(Correction_Max[iVar], Correction_j[iVar]); @@ -1498,24 +1501,55 @@ void CMultiGridIntegration::SetProlongated_Correction(CSolver *sol_fine, CSolver } -void CMultiGridIntegration::SetProlongated_Solution(unsigned short RunTime_EqSystem, CSolver *sol_fine, CSolver *sol_coarse, - CGeometry *geo_fine, CGeometry *geo_coarse, CConfig *config) { +void CMultiGridIntegration::InterpolateSolutionToChildren(CSolver *sol_fine, CSolver *sol_coarse, CGeometry *geo_fine, + CGeometry *geo_coarse, CConfig *config, + unsigned short iMesh) { SU2_ZONE_SCOPED - const unsigned short Solver_Position = config->GetContainerPosition(RunTime_EqSystem); - const bool grid_movement = config->GetGrid_Movement(); + const unsigned short nVar = sol_coarse->GetnVar(); + const unsigned short nDim = geo_coarse->GetnDim(); + const bool linear = config->GetMGOptions().MG_Linear_Prolongation; - /*--- Constant injection: every fine child of a coarse CV takes its parent's value. ---*/ + if (linear) ComputeProlongationGradient(sol_coarse, geo_coarse, geo_fine, config, iMesh, true); SU2_OMP_FOR_STAT(roundUpDiv(geo_coarse->GetnPointDomain(), omp_get_num_threads())) for (auto Point_Coarse = 0ul; Point_Coarse < geo_coarse->GetnPointDomain(); Point_Coarse++) { const auto* Solution_Coarse = sol_coarse->GetNodes()->GetSolution(Point_Coarse); + const auto* Coord_Coarse = geo_coarse->nodes->GetCoord(Point_Coarse); + for (auto iChildren = 0u; iChildren < geo_coarse->nodes->GetnChildren_CV(Point_Coarse); iChildren++) { const auto Point_Fine = geo_coarse->nodes->GetChildren_CV(Point_Coarse, iChildren); - sol_fine->GetNodes()->SetSolution(Point_Fine, Solution_Coarse); + + if (!linear) { + sol_fine->GetNodes()->SetSolution(Point_Fine, Solution_Coarse); + continue; + } + + su2double Distance[MAXNDIM] = {0.0}; + GeometryToolbox::Distance(nDim, geo_fine->nodes->GetCoord(Point_Fine), Coord_Coarse, Distance); + + for (auto iVar = 0u; iVar < nVar; iVar++) { + su2double value = Solution_Coarse[iVar]; + for (auto iDim = 0u; iDim < nDim; iDim++) + value += prolongGradient[iMesh](Point_Coarse, iVar, iDim) * Distance[iDim]; + sol_fine->GetNodes()->SetSolution(Point_Fine, iVar, value); + } } } END_SU2_OMP_FOR +} + +void CMultiGridIntegration::SetProlongated_Solution(unsigned short RunTime_EqSystem, CSolver *sol_fine, CSolver *sol_coarse, + CGeometry *geo_fine, CGeometry *geo_coarse, CConfig *config, + unsigned short iMesh) { + SU2_ZONE_SCOPED + + const unsigned short Solver_Position = config->GetContainerPosition(RunTime_EqSystem); + const bool grid_movement = config->GetGrid_Movement(); + + /*--- Constant injection, or the limited linear reconstruction when MG_Linear_Prolongation is set. ---*/ + + InterpolateSolutionToChildren(sol_fine, sol_coarse, geo_fine, geo_coarse, config, iMesh); /*--- The injected values do not satisfy the fine-grid wall conditions on their own. ---*/ @@ -1565,24 +1599,25 @@ void CMultiGridIntegration::SetProlongated_Solution(unsigned short RunTime_EqSys void CMultiGridIntegration::SetProlongated_ScalarSolution(CSolver *sol_fine, CSolver *sol_coarse, CGeometry *geo_fine, CGeometry *geo_coarse, - CConfig *config, bool eddy_viscosity) { + CConfig *config, bool eddy_viscosity, + unsigned short iMesh) { SU2_ZONE_SCOPED - /*--- Constant injection: every fine child of a coarse CV takes its parent's value. ---*/ + /*--- Constant injection, or the limited linear reconstruction when MG_Linear_Prolongation is set. ---*/ - SU2_OMP_FOR_STAT(roundUpDiv(geo_coarse->GetnPointDomain(), omp_get_num_threads())) - for (auto Point_Coarse = 0ul; Point_Coarse < geo_coarse->GetnPointDomain(); Point_Coarse++) { + InterpolateSolutionToChildren(sol_fine, sol_coarse, geo_fine, geo_coarse, config, iMesh); - const auto* Solution_Coarse = sol_coarse->GetNodes()->GetSolution(Point_Coarse); - const su2double muT_Coarse = eddy_viscosity ? sol_coarse->GetNodes()->GetmuT(Point_Coarse) : su2double(0.0); + /*--- The eddy viscosity is injected as a constant. ---*/ - for (auto iChildren = 0u; iChildren < geo_coarse->nodes->GetnChildren_CV(Point_Coarse); iChildren++) { - const auto Point_Fine = geo_coarse->nodes->GetChildren_CV(Point_Coarse, iChildren); - sol_fine->GetNodes()->SetSolution(Point_Fine, Solution_Coarse); - if (eddy_viscosity) sol_fine->GetNodes()->SetmuT(Point_Fine, muT_Coarse); + if (eddy_viscosity) { + SU2_OMP_FOR_STAT(roundUpDiv(geo_coarse->GetnPointDomain(), omp_get_num_threads())) + for (auto Point_Coarse = 0ul; Point_Coarse < geo_coarse->GetnPointDomain(); Point_Coarse++) { + const su2double muT_Coarse = sol_coarse->GetNodes()->GetmuT(Point_Coarse); + for (auto iChildren = 0u; iChildren < geo_coarse->nodes->GetnChildren_CV(Point_Coarse); iChildren++) + sol_fine->GetNodes()->SetmuT(geo_coarse->nodes->GetChildren_CV(Point_Coarse, iChildren), muT_Coarse); } + END_SU2_OMP_FOR } - END_SU2_OMP_FOR /*--- The eddy viscosity is zero on a no-slip wall, the injected value is not. ---*/ From b302b3b6d7c9ba94125a78be9d0b81783b2787ee Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sun, 18 Oct 2026 00:23:52 +0200 Subject: [PATCH 21/42] keep the wall condition of the turbulence variables at full multigrid promotion Wall nodes take their coarse wall parent's value instead of the linear extrapolation, so the promoted solution starts from the wall condition. Co-Authored-By: Claude Opus 5.5 --- SU2_CFD/src/integration/CMultiGridIntegration.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index 0ba8a46040f5..c94702229527 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -1619,7 +1619,8 @@ void CMultiGridIntegration::SetProlongated_ScalarSolution(CSolver *sol_fine, CSo END_SU2_OMP_FOR } - /*--- The eddy viscosity is zero on a no-slip wall, the injected value is not. ---*/ + /*--- On a no-slip wall the eddy viscosity is zero, and the turbulence variables take the value + * of their wall parent, which holds the wall condition instead of an extrapolation. ---*/ if (eddy_viscosity) { for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); iMarker++) { @@ -1628,6 +1629,8 @@ void CMultiGridIntegration::SetProlongated_ScalarSolution(CSolver *sol_fine, CSo SU2_OMP_FOR_STAT(32) for (auto iVertex = 0ul; iVertex < geo_fine->nVertex[iMarker]; iVertex++) { const auto Point_Fine = geo_fine->vertex[iMarker][iVertex]->GetNode(); + const auto Point_Coarse = geo_fine->nodes->GetParent_CV(Point_Fine); + sol_fine->GetNodes()->SetSolution(Point_Fine, sol_coarse->GetNodes()->GetSolution(Point_Coarse)); sol_fine->GetNodes()->SetmuT(Point_Fine, 0.0); } END_SU2_OMP_FOR From 03df5192501318648e74df55d2b3cbcc2e35e12e Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sun, 18 Oct 2026 08:49:43 +0200 Subject: [PATCH 22/42] report the correction norm before smoothing, no correction smoothing in the template The Corr-smooth column of MG_SMOOTH_OUTPUT printed the initial norm, which was never set. The config template now shows MG_CORRECTION_SMOOTH at its default of 0. Co-Authored-By: Claude Opus 5.5 --- SU2_CFD/src/integration/CMultiGridIntegration.cpp | 5 +++++ config_template.cfg | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index c94702229527..8ab0228867d7 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -1335,6 +1335,11 @@ void CMultiGridIntegration::SmoothProlongated_Correction(unsigned short RunTime_ const unsigned short nVar = solver->GetnVar(); + if (config->GetMGOptions().MG_Smooth_Output) { + const su2double res = sqrt(solver->LinSysRes.squaredNorm() / (nVar * geometry->GetGlobal_nPointDomain())); + SU2_OMP_SAFE_GLOBAL_ACCESS(lastCorrecSmoothRMS[iMesh][0] = SU2_TYPE::GetValue(res);) + } + SU2_OMP_FOR_STAT(roundUpDiv(geometry->GetnPoint(), omp_get_num_threads())) for (auto iPoint = 0ul; iPoint < geometry->GetnPoint(); iPoint++) { const auto* Residual_Old = solver->LinSysRes.GetBlock(iPoint); diff --git a/config_template.cfg b/config_template.cfg index 5dbfe53631be..50fb403a4ba6 100644 --- a/config_template.cfg +++ b/config_template.cfg @@ -1777,8 +1777,8 @@ MG_PRE_SMOOTH= ( 2, 2, 2, 2 ) % Max. iterations for multi-grid post-smoothing level MG_POST_SMOOTH= ( 2, 2, 2, 2 ) % -% Jacobi implicit smoothing of the correction -MG_CORRECTION_SMOOTH= ( 1, 1, 1, 1 ) +% Jacobi implicit smoothing of the correction (default 0) +MG_CORRECTION_SMOOTH= ( 0, 0, 0, 0 ) % % Damping factor for the residual restriction MG_DAMP_RESTRICTION= 0.5 From 9f17b9b589021d5c4c05cff25fd26334d4a0e09c Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sun, 18 Oct 2026 09:55:26 +0200 Subject: [PATCH 23/42] inverse-distance-squared weights in the prolongation gradient fit The fit now weights each neighbour's directional difference equally, which makes it independent of the neighbour distances. Restricting analytic fields and prolongating them back, the error drops on every level of an irregular mixed-element mesh (wall-layer field on level 3: 0.24 of the constant-operator error, against 0.36 unweighted). Iteration counts are equal or slightly lower: 2_2DCJ 197 (198), 1_2DZP 137x097 214 (217), 273x193 at CFL cap 500 2040 (2040). The aspect-ratio gate stays. Without it, the more accurate transfer slows the solver in boundary and shear layers (2_2DCJ 266, 273x193 capped 2143). Co-Authored-By: Claude Opus 5.5 --- .../src/integration/CMultiGridIntegration.cpp | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index 8ab0228867d7..7d988cfe2a9d 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -1183,8 +1183,8 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe auto& gradient = prolongGradient[iMesh]; - /*--- Unweighted fit: inverse-distance weights would let the short wall-normal edges of a - * stretched agglomerate dominate it. ---*/ + /*--- Inverse-distance-squared weights give every neighbour's directional difference the same + * weight, so the fit does not depend on how far apart the neighbours are. ---*/ SU2_OMP_FOR_STAT(roundUpDiv(nPointDomain, omp_get_num_threads())) for (auto iPoint = 0ul; iPoint < nPointDomain; iPoint++) { @@ -1195,7 +1195,8 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe const auto* Coord_i = geo_coarse->nodes->GetCoord(iPoint); const auto* Correction_i = Field(iPoint); - su2double Amat[MAXNDIM][MAXNDIM] = {{0.0}}, Bmat[MAXNDIM][MAXNDIM] = {{0.0}}; + /*--- The extent matrix measures the stencil's stretching, the fit matrix is the weighted normal matrix. ---*/ + su2double extentMat[MAXNDIM][MAXNDIM] = {{0.0}}, fitMat[MAXNDIM][MAXNDIM] = {{0.0}}; su2double rhs[MAXNVAR][MAXNDIM] = {{0.0}}; for (auto jPoint : geo_coarse->nodes->GetPoints(iPoint)) { @@ -1207,29 +1208,29 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe for (auto iDim = 0u; iDim < nDim; iDim++) for (auto jDim = 0u; jDim < nDim; jDim++) { - Amat[iDim][jDim] += Distance[iDim]*Distance[jDim]; - Bmat[iDim][jDim] += Distance[iDim]*Distance[jDim]/dist2; + extentMat[iDim][jDim] += Distance[iDim]*Distance[jDim]; + fitMat[iDim][jDim] += Distance[iDim]*Distance[jDim]/dist2; } const auto* Correction_j = Field(jPoint); for (auto iVar = 0u; iVar < nVar; iVar++) { const su2double delta = Correction_j[iVar] - Correction_i[iVar]; - for (auto iDim = 0u; iDim < nDim; iDim++) rhs[iVar][iDim] += Distance[iDim]*delta; + for (auto iDim = 0u; iDim < nDim; iDim++) rhs[iVar][iDim] += Distance[iDim]*delta/dist2; } } /*--- Neighbours that do not span every direction leave a slope undefined. A stencil much longer in * one direction than another, from cell stretching, weakens the gradient or removes it. In both * cases the cell falls back to the constant operator. ---*/ - su2double Ainv[MAXNDIM][MAXNDIM] = {{0.0}}; - const passivedouble aspect = sqrt(FitConditionNumber(nDim, Amat)); + su2double fitInv[MAXNDIM][MAXNDIM] = {{0.0}}; + const passivedouble aspect = sqrt(FitConditionNumber(nDim, extentMat)); const passivedouble weight = (aspect <= PROLONG_FULL_ASPECT) ? 1.0 : max(0.0, log(PROLONG_MAX_ASPECT / aspect) / log(PROLONG_MAX_ASPECT / PROLONG_FULL_ASPECT)); - if ((FitConditionNumber(nDim, Bmat) > PROLONG_MAX_CONDITION) || (weight <= 0.0) || - !CholeskyInverse(nDim, Amat, Ainv)) { + if ((FitConditionNumber(nDim, fitMat) > PROLONG_MAX_CONDITION) || (weight <= 0.0) || + !CholeskyInverse(nDim, fitMat, fitInv)) { SU2_OMP_ATOMIC prolongIllConditioned[iMesh]++; continue; @@ -1238,7 +1239,7 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe for (auto iVar = 0u; iVar < nVar; iVar++) for (auto iDim = 0u; iDim < nDim; iDim++) { su2double value = 0.0; - for (auto jDim = 0u; jDim < nDim; jDim++) value += Ainv[iDim][jDim]*rhs[iVar][jDim]; + for (auto jDim = 0u; jDim < nDim; jDim++) value += fitInv[iDim][jDim]*rhs[iVar][jDim]; gradient(iPoint, iVar, iDim) = weight * value; } } From b4aeeb13e4df692ac35e8141bc134566a4f0eb35 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Fri, 23 Oct 2026 14:32:21 +0200 Subject: [PATCH 24/42] pre-commit --- Common/src/geometry/CMultiGridGeometry.cpp | 12 +++++++----- Common/src/linear_algebra/CSysMatrix.cpp | 4 ++-- Common/src/linear_algebra/CSysSolve.cpp | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Common/src/geometry/CMultiGridGeometry.cpp b/Common/src/geometry/CMultiGridGeometry.cpp index e1ee13ecbca3..0dae95edac74 100644 --- a/Common/src/geometry/CMultiGridGeometry.cpp +++ b/Common/src/geometry/CMultiGridGeometry.cpp @@ -2383,8 +2383,9 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co for (auto iNeigh = 0u; iNeigh < fine_grid->nodes->GetnPoint(iPoint); ++iNeigh) { const auto jPoint = fine_grid->nodes->GetPoint(iPoint, iNeigh); const auto iEdge = fine_grid->nodes->GetEdge(iPoint, iNeigh); - const su2double w = GeometryToolbox::Norm(nDim, fine_grid->edges->GetNormal(iEdge)) * - (1.0 / fine_grid->nodes->GetVolume(iPoint) + 1.0 / fine_grid->nodes->GetVolume(jPoint)); + const su2double w = + GeometryToolbox::Norm(nDim, fine_grid->edges->GetNormal(iEdge)) * + (1.0 / fine_grid->nodes->GetVolume(iPoint) + 1.0 / fine_grid->nodes->GetVolume(jPoint)); wMax = std::max(wMax, w); if (std::find(set.begin(), set.end(), jPoint) != set.end()) wStep = std::max(wStep, w); } @@ -2395,7 +2396,8 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co /*--- Whether every node of the step reaches a physical boundary within a few steps on the * way it travels. A band two coarse cells thin is taken, the domain pass tiles it poorly. ---*/ - auto nearBoundary = [&](const vector& set, const vector>& dirs) { + auto nearBoundary = [&](const vector& set, + const vector>& dirs) { constexpr unsigned short THIN_BAND = 4; for (size_t k = 0; k < set.size(); ++k) { auto iPoint = set[k]; @@ -2405,8 +2407,8 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co su2double bestAlign = 0.0; for (auto jPoint : fine_grid->nodes->GetPoints(iPoint)) { su2double step[MAXNDIM] = {0.0}; - GeometryToolbox::Distance(nDim, fine_grid->nodes->GetCoord(jPoint), fine_grid->nodes->GetCoord(iPoint), - step); + GeometryToolbox::Distance(nDim, fine_grid->nodes->GetCoord(jPoint), + fine_grid->nodes->GetCoord(iPoint), step); const su2double len = GeometryToolbox::Norm(nDim, step); if (len <= 0.0) continue; const su2double align = GeometryToolbox::DotProduct(nDim, step, dirs[k].data()) / len; diff --git a/Common/src/linear_algebra/CSysMatrix.cpp b/Common/src/linear_algebra/CSysMatrix.cpp index 19717ff37814..c0b3a46a01e0 100644 --- a/Common/src/linear_algebra/CSysMatrix.cpp +++ b/Common/src/linear_algebra/CSysMatrix.cpp @@ -536,7 +536,7 @@ void CSysMatrix::Initialize(unsigned long npoint, unsigned long npoi if (ilu_needed && !levels_ilu.empty() && !useCuda && num_threads > 1) BuildLevelWaits(); - /*--- Generate MKL Kernels ---*/ + /*--- Generate MKL Kernels ---*/ #ifdef USE_MKL using mkl = mkl_jit_wrapper; @@ -1121,7 +1121,7 @@ void CSysMatrix::BuildLevelWaits() { wait_b[owner[jPoint]] = std::max(wait_b[owner[jPoint]], jStep + 1); } } - wait_f[iThread] = 0; + wait_f[iThread] = 0; wait_b[iThread] = 0; } } diff --git a/Common/src/linear_algebra/CSysSolve.cpp b/Common/src/linear_algebra/CSysSolve.cpp index 57ab0e123294..1719e475b321 100644 --- a/Common/src/linear_algebra/CSysSolve.cpp +++ b/Common/src/linear_algebra/CSysSolve.cpp @@ -1404,8 +1404,8 @@ bool CSysSolve::SetupInnerSolver(unsigned short kind_solver, const C template unsigned long CSysSolve::Solve(CSysMatrix& Jacobian, const CSysVector& LinSysRes, - CSysVector& LinSysSol, CGeometry* geometry, - const CConfig* config, unsigned long maxIter) { + CSysVector& LinSysSol, CGeometry* geometry, const CConfig* config, + unsigned long maxIter) { SU2_ZONE_SCOPED /*--- A word about the templated types. It is assumed that the residual and solution vectors are always of su2doubles, From a96ed9550149229a9d3a7efddeffbfccddbfa99d Mon Sep 17 00:00:00 2001 From: bigfooted Date: Fri, 30 Oct 2026 12:08:30 +0100 Subject: [PATCH 25/42] fix parmetis --- Common/src/geometry/CMultiGridGeometry.cpp | 113 +++++++++++++++++- SU2_CFD/src/drivers/CDriver.cpp | 75 ++++++++++++ .../src/integration/CMultiGridIntegration.cpp | 36 ++++++ 3 files changed, 219 insertions(+), 5 deletions(-) diff --git a/Common/src/geometry/CMultiGridGeometry.cpp b/Common/src/geometry/CMultiGridGeometry.cpp index 0dae95edac74..0b06c4e5e829 100644 --- a/Common/src/geometry/CMultiGridGeometry.cpp +++ b/Common/src/geometry/CMultiGridGeometry.cpp @@ -758,6 +758,15 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un nodes->SetnChildren_CV(fromCV, 0); }; + /*--- Take one fine point out of the children of a coarse CV. ---*/ + auto removeChild = [&](unsigned long fromCV, unsigned long iFinePoint) { + vector kept; + for (auto iChildren = 0u; iChildren < nodes->GetnChildren_CV(fromCV); iChildren++) + if (nodes->GetChildren_CV(fromCV, iChildren) != iFinePoint) kept.push_back(nodes->GetChildren_CV(fromCV, iChildren)); + nodes->SetChildren_CV(fromCV, kept); + nodes->SetnChildren_CV(fromCV, kept.size()); + }; + /*--- Dual-face area and number of fine edges between the children of two coarse CVs. ---*/ auto sharedFaces = [&](unsigned long iCV, unsigned long jCV) { su2double area = 0.0; @@ -911,11 +920,7 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un } if (donor == NO_CV) continue; - const auto nDonor = nodes->GetnChildren_CV(donor); - for (auto k = 0u; k < nDonor; k++) - if (nodes->GetChildren_CV(donor, k) == fourth) - nodes->SetChildren_CV(donor, k, nodes->GetChildren_CV(donor, nDonor - 1)); - nodes->SetnChildren_CV(donor, nDonor - 1); + removeChild(donor, fourth); giveChild(fourth, iCoarsePoint); changed = true; } @@ -924,6 +929,104 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un } } + /*--- A group of halo points whose neighbors on this rank all lie in one coarse CV is enclosed by it. + * The rank owning the group then gets a coarse CV with one neighbor and cancelling face normals, + * so one member around the group moves to another CV. ---*/ + + { + const auto nFineDomain = fine_grid->GetnPointDomain(); + const auto nRepaired = nPointDomain; + vector visited(fine_grid->GetnPoint(), 0); + vector group, around; + + auto isChildOf = [&](unsigned long iFinePoint, unsigned long iCV, unsigned long except) { + return (iFinePoint != except) && (iFinePoint < nFineDomain) && (fine_grid->nodes->GetParent_CV(iFinePoint) == iCV); + }; + + /*--- Whether the children of a CV other than one excluded point form one connected set. ---*/ + auto connectedWithout = [&](unsigned long iCV, unsigned long except) { + vector stack, reached; + for (auto iChildren = 0u; iChildren < nodes->GetnChildren_CV(iCV); iChildren++) { + if (nodes->GetChildren_CV(iCV, iChildren) == except) continue; + stack.push_back(nodes->GetChildren_CV(iCV, iChildren)); + break; + } + if (stack.empty()) return false; + reached = stack; + while (!stack.empty()) { + const auto iFinePoint = stack.back(); + stack.pop_back(); + for (auto jFinePoint : fine_grid->nodes->GetPoints(iFinePoint)) { + if (!isChildOf(jFinePoint, iCV, except)) continue; + if (find(reached.begin(), reached.end(), jFinePoint) != reached.end()) continue; + reached.push_back(jFinePoint); + stack.push_back(jFinePoint); + } + } + return reached.size() + 1 == nodes->GetnChildren_CV(iCV); + }; + + for (auto iSeed = nFineDomain; iSeed < fine_grid->GetnPoint(); iSeed++) { + if (visited[iSeed]) continue; + + /*--- Collect the connected group of halo points and the domain points around it. ---*/ + group.assign(1, iSeed); + around.clear(); + visited[iSeed] = 1; + for (auto k = 0ul; k < group.size(); k++) { + for (auto jFinePoint : fine_grid->nodes->GetPoints(group[k])) { + if (jFinePoint >= nFineDomain) { + if (!visited[jFinePoint]) { + visited[jFinePoint] = 1; + group.push_back(jFinePoint); + } + } else if (find(around.begin(), around.end(), jFinePoint) == around.end()) { + around.push_back(jFinePoint); + } + } + } + if (around.empty()) continue; + + const auto enclosing = fine_grid->nodes->GetParent_CV(around[0]); + bool enclosed = (enclosing < nRepaired); + for (auto iFinePoint : around) enclosed = enclosed && (fine_grid->nodes->GetParent_CV(iFinePoint) == enclosing); + if (!enclosed || (nodes->GetnChildren_CV(enclosing) < 2)) continue; + + /*--- Move the member around the group with the largest face to a neighboring CV, keeping the + * enclosing CV connected when possible. A new CV takes it when no neighbor may. ---*/ + unsigned long moved = NO_CV, toCV = NO_CV; + su2double bestArea = -1.0; + for (const bool needConnected : {true, false}) { + for (auto iFinePoint : around) { + if (needConnected && !connectedWithout(enclosing, iFinePoint)) continue; + for (auto iNeigh = 0u; iNeigh < fine_grid->nodes->GetnPoint(iFinePoint); iNeigh++) { + const auto jCV = fine_grid->nodes->GetParent_CV(fine_grid->nodes->GetPoint(iFinePoint, iNeigh)); + if ((jCV >= nRepaired) || (jCV == enclosing) || !mayMerge(enclosing, jCV)) continue; + const auto area = + GeometryToolbox::Norm(nDim, fine_grid->edges->GetNormal(fine_grid->nodes->GetEdge(iFinePoint, iNeigh))); + if (area > bestArea) { + bestArea = area; + moved = iFinePoint; + toCV = jCV; + } + } + } + if (moved != NO_CV) break; + } + if (moved == NO_CV) { + moved = around[0]; + toCV = Index_CoarseCV++; + nodes->SetnChildren_CV(toCV, 0); + nodes->SetAgglomerate_Indirect(toCV, fine_grid->nodes->GetAgglomerate_Indirect(moved)); + nPointDomain = Index_CoarseCV; + nPoint = Index_CoarseCV; + } + + removeChild(enclosing, moved); + giveChild(moved, toCV); + } + } + /*--- Compact the coarse numbering, squeezing out the indices the repair passes emptied. The children lists, indirect-agglomeration flags and owned parent indices are remapped. ---*/ diff --git a/SU2_CFD/src/drivers/CDriver.cpp b/SU2_CFD/src/drivers/CDriver.cpp index 395ae8f4b18f..a56bac5093af 100644 --- a/SU2_CFD/src/drivers/CDriver.cpp +++ b/SU2_CFD/src/drivers/CDriver.cpp @@ -821,6 +821,79 @@ void CDriver::InitializeGeometryFVM(CConfig *config, CGeometry **&geometry) { return range; }; + /*--- The face normals of a closed control volume sum to zero. Reports the CV with the largest + * sum relative to the sum of the face areas, and how many CVs exceed a small tolerance. ---*/ + auto closureReport = [&](const CGeometry* grid, const CGeometry* fine, unsigned short iLevel) { + const auto nDomain = grid->GetnPointDomain(); + const auto nDim = grid->GetnDim(); + vector> boundary(nDomain, {0.0, 0.0, 0.0}); + for (auto iMarker = 0u; iMarker < grid->GetnMarker(); iMarker++) { + if (config->GetMarker_All_KindBC(iMarker) == SEND_RECEIVE) continue; + for (auto iVertex = 0ul; iVertex < grid->GetnVertex(iMarker); iVertex++) { + const auto iPoint = grid->vertex[iMarker][iVertex]->GetNode(); + if (iPoint >= nDomain) continue; + for (auto iDim = 0u; iDim < nDim; iDim++) + boundary[iPoint][iDim] -= SU2_TYPE::GetValue(grid->vertex[iMarker][iVertex]->GetNormal(iDim)); + } + } + + passivedouble worst = 0.0; + unsigned long worstPoint = 0, nBad = 0, nBadGlobal = 0; + for (auto iPoint = 0ul; iPoint < nDomain; iPoint++) { + std::array sum = boundary[iPoint]; + passivedouble area = 0.0; + for (auto iDim = 0u; iDim < nDim; iDim++) area += fabs(sum[iDim]); + for (auto iNeigh = 0u; iNeigh < grid->nodes->GetnPoint(iPoint); iNeigh++) { + const auto iEdge = grid->nodes->GetEdge(iPoint, iNeigh); + const passivedouble sign = (grid->edges->GetNode(iEdge, 0) == iPoint) ? 1.0 : -1.0; + passivedouble norm2 = 0.0; + for (auto iDim = 0u; iDim < nDim; iDim++) { + const passivedouble n = SU2_TYPE::GetValue(grid->edges->GetNormal(iEdge)[iDim]); + sum[iDim] += sign * n; + norm2 += n * n; + } + area += sqrt(norm2); + } + passivedouble defect = 0.0; + for (auto iDim = 0u; iDim < nDim; iDim++) defect += sum[iDim] * sum[iDim]; + defect = sqrt(defect) / max(area, std::numeric_limits::min()); + if (defect > 1e-6) nBad++; + if (defect > worst) { + worst = defect; + worstPoint = iPoint; + } + } + passivedouble worstGlobal = 0.0; + CPassiveMPI::Allreduce(&worst, &worstGlobal, 1, MPI_DOUBLE, MPI_MAX, SU2_MPI::GetComm()); + SU2_MPI::Allreduce(&nBad, &nBadGlobal, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm()); + if (rank == MASTER_NODE) { + cout << " MG level " << iLevel << " CV closure: " << nBadGlobal << " CVs with a face normal sum above 1e-6 of the " + << "face area, worst " << worstGlobal << "\n"; + } + if ((worst == worstGlobal) && (worst > 1e-6)) { + cout << " MG level " << iLevel << " worst closure on rank " << rank << ", global point " + << grid->nodes->GetGlobalIndex(worstPoint) << ", volume " << grid->nodes->GetVolume(worstPoint) << ", " + << grid->nodes->GetnPoint(worstPoint) << " neighbors, x ="; + for (auto iDim = 0u; iDim < nDim; iDim++) cout << " " << grid->nodes->GetCoord(worstPoint, iDim); + cout << "\n"; + for (auto iChild = 0u; iChild < grid->nodes->GetnChildren_CV(worstPoint); iChild++) { + const auto iFine = grid->nodes->GetChildren_CV(worstPoint, iChild); + cout << " child " << fine->nodes->GetGlobalIndex(iFine) << " volume " << fine->nodes->GetVolume(iFine) + << ", neighbors (global index, h = halo, parent):"; + for (auto jFine : fine->nodes->GetPoints(iFine)) { + const auto parent = fine->nodes->GetParent_CV(jFine); + cout << " " << fine->nodes->GetGlobalIndex(jFine) << (fine->nodes->GetDomain(jFine) ? "" : "h") << ":"; + if (parent == std::numeric_limits::max()) cout << "none"; + else cout << parent; + } + cout << "\n"; + } + cout << " coarse neighbors:"; + for (auto jPoint : grid->nodes->GetPoints(worstPoint)) cout << " " << jPoint << (grid->nodes->GetDomain(jPoint) ? "" : "h"); + cout << " (this CV " << worstPoint << ")\n"; + } + }; + /*--- Agglomeration should not spread the CV volumes far wider than the fine grid already does. * An absolute limit cannot tell a coarsened mesh from a badly stretched input one. ---*/ constexpr passivedouble VOL_RATIO_GROWTH_WARN = 10.0; @@ -879,6 +952,8 @@ void CDriver::InitializeGeometryFVM(CConfig *config, CGeometry **&geometry) { geometry[iMGlevel]->SetBoundControlVolume(geometry[iMGlevel-1], config, ALLOCATE); + closureReport(geometry[iMGlevel], geometry[iMGlevel-1], iMGlevel); + geometry[iMGlevel]->SetCoord(geometry[iMGlevel-1]); /*--- Store our multigrid index. ---*/ diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index 7d988cfe2a9d..fd4453bedee7 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -1339,6 +1339,42 @@ void CMultiGridIntegration::SmoothProlongated_Correction(unsigned short RunTime_ if (config->GetMGOptions().MG_Smooth_Output) { const su2double res = sqrt(solver->LinSysRes.squaredNorm() / (nVar * geometry->GetGlobal_nPointDomain())); SU2_OMP_SAFE_GLOBAL_ACCESS(lastCorrecSmoothRMS[iMesh][0] = SU2_TYPE::GetValue(res);) + + /*--- Report a single point that carries a large share of the correction norm. ---*/ + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { + constexpr passivedouble peakShare = 0.2; + passivedouble local[2] = {0.0, 0.0}, global[2]; + unsigned long peakPoint = 0; + for (auto iPoint = 0ul; iPoint < geometry->GetnPointDomain(); iPoint++) { + passivedouble sq = 0.0; + for (auto iVar = 0u; iVar < nVar; iVar++) sq += pow(SU2_TYPE::GetValue(solver->LinSysRes(iPoint, iVar)), 2); + local[1] += sq; + if (sq > local[0]) { + local[0] = sq; + peakPoint = iPoint; + } + } + SU2_MPI::Allreduce(&local[0], &global[0], 1, MPI_DOUBLE, MPI_MAX, SU2_MPI::GetComm()); + SU2_MPI::Allreduce(&local[1], &global[1], 1, MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm()); + if ((local[0] == global[0]) && (global[0] > peakShare * global[1])) { + std::cout << "Corr-peak level " << iMesh << ": rank " << SU2_MPI::GetRank() << ", global point " + << geometry->nodes->GetGlobalIndex(peakPoint) << ", " << 100 * global[0] / global[1] + << "% of the correction norm, volume " << geometry->nodes->GetVolume(peakPoint) << ", " + << geometry->nodes->GetnPoint(peakPoint) << " neighbors, parent CV " + << geometry->nodes->GetParent_CV(peakPoint) << ", x ="; + for (auto iDim = 0u; iDim < geometry->GetnDim(); iDim++) + std::cout << " " << geometry->nodes->GetCoord(peakPoint, iDim); + std::cout << ", correction ="; + for (auto iVar = 0u; iVar < nVar; iVar++) std::cout << " " << solver->LinSysRes(peakPoint, iVar); + std::cout << "\n neighbor volumes (h = halo):"; + for (auto iNeigh = 0u; iNeigh < geometry->nodes->GetnPoint(peakPoint); iNeigh++) { + const auto jPoint = geometry->nodes->GetPoint(peakPoint, iNeigh); + std::cout << " " << geometry->nodes->GetVolume(jPoint) << (geometry->nodes->GetDomain(jPoint) ? "" : "h"); + } + std::cout << std::endl; + } + } + END_SU2_OMP_SAFE_GLOBAL_ACCESS } SU2_OMP_FOR_STAT(roundUpDiv(geometry->GetnPoint(), omp_get_num_threads())) From 15764925ff536444bddd094b4aa6d9bdf787fe5b Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sat, 7 Nov 2026 15:20:12 +0100 Subject: [PATCH 26/42] single CFL probe at residual plateaus instead of the cut ratchet The frozen and stall rules cut the CFL by 0.75x per event and kept the cuts. The branch that undid them only armed after a 30x reduction, so a run that started below 30x CFLmin reached the floor first, and the cap probe could not raise a plateau cap above itself. The CFL then stayed at CFLmin: all 4_2DANW 1025 cluster runs, 2_2DCJ 0levelsdown MG3/MG4 and 5_2DMEA mesh 5 MG0. A plateau now triggers one cut to 0.35x the plateau CFL. After a 40 iteration transient, the fall of the mean log residual over 100 iterations (S1) is compared with the fall before the cut (S0): - S1 >= 1.3 max(S0, 0) + 0.03: the cut is kept, and the cap may grow back to 0.7x the plateau CFL; - S1 < S0 - 0.03: the cut is undone, the plateau caps are released and no more probes follow; - otherwise the cut is undone, probes hold for 300 iterations, and the next one needs a fall below min(0.5 S0, S0 - 0.03). No probe starts while the residual falls by 0.3 decades per 100 iterations or more, or while the first flow residual reaches CONV_RESIDUAL_MINVAL within the iteration limit at the current rate. A jump, regression, flip-flop or linear solver failure ends a probe. 4_2DANW 65 on 2 ranks: MG0 reaches -12 at iteration 1384 (before: -10 at 2178, no -12 in 2500), MG1 -12 at 1395 (before: no -10 in 2500). With a kept cut as a permanent cap, the CFL stayed at 205 and MG0 converged slower than with the ratchet, hence the regrowth. Co-Authored-By: Claude Opus 5.5 --- SU2_CFD/include/solvers/CSolver.hpp | 23 +++--- SU2_CFD/src/solvers/CSolver.cpp | 111 +++++++++++++++++----------- 2 files changed, 80 insertions(+), 54 deletions(-) diff --git a/SU2_CFD/include/solvers/CSolver.hpp b/SU2_CFD/include/solvers/CSolver.hpp index a7a62db8a964..ffb58932a61f 100644 --- a/SU2_CFD/include/solvers/CSolver.hpp +++ b/SU2_CFD/include/solvers/CSolver.hpp @@ -101,20 +101,21 @@ class CSolver { vector> ResStall_History; /*!< \brief Log flow residuals over two stall windows. */ vector CFLStall_History; /*!< \brief Mean CFL over two stall windows. */ unsigned long Stall_Streak = 0; /*!< \brief Consecutive iterations without envelope progress. */ - unsigned long CFL_LastStall = 0; /*!< \brief Iteration of the last plateau. */ - passivedouble CFL_StallCap = -1.0; /*!< \brief Cap set at the last stall, which cap increases stay below. */ + unsigned long CFL_LastStall = 0; /*!< \brief Iteration of the last plateau probe decision. */ + passivedouble CFL_StallCap = -1.0; /*!< \brief Cap kept after a plateau probe, which cap increases stay below. */ passivedouble CFL_OscLevel = -1.0; /*!< \brief Lowest CFL at which the residuals flip-flopped. */ unsigned long CFL_LastOscRelease = 0; /*!< \brief Iteration of the last flip-flop limit increase. */ passivedouble Res_AtOsc = 0.0; /*!< \brief Mean log flow residual at that flip-flop. */ - bool Trial_Active = false; /*!< \brief CFL cuts at a residual plateau are being evaluated. */ - unsigned long Trial_Start = 0; /*!< \brief Iteration of the first cut of the trial. */ - unsigned long Trial_Hold = 0; /*!< \brief No trial starts before this iteration. */ - unsigned long Trial_Settle = 0; /*!< \brief Iteration after which the lowest CFL of the trial is judged. */ - passivedouble Trial_Res = 0.0; /*!< \brief Mean log flow residual when the trial started. */ - passivedouble Trial_CFL = 0.0; /*!< \brief Mean CFL when the trial started. */ - passivedouble Trial_Ceiling = -1.0; /*!< \brief CFL ceiling before the trial. */ - passivedouble Trial_Cap = -1.0; /*!< \brief CFL cap before the trial. */ - passivedouble Trial_StallCap = -1.0; /*!< \brief Plateau cap before the trial. */ + bool Trial_Active = false; /*!< \brief A CFL cut at a residual plateau is being evaluated. */ + bool Trial_Off = false; /*!< \brief A probe showed slower convergence at the lower CFL, no more probes. */ + unsigned long Trial_Start = 0; /*!< \brief Iteration of the probe cut. */ + unsigned long Trial_Hold = 0; /*!< \brief No probe starts before this iteration. */ + passivedouble Trial_Rate = 0.0; /*!< \brief Residual fall before the probe, in decades per 100 iterations. */ + passivedouble Trial_CFL = 0.0; /*!< \brief CFL at the plateau, which sets how far a kept cut may grow back. */ + passivedouble Trial_MaxRate = 1e30; /*!< \brief A probe starts only below this residual fall. */ + passivedouble Trial_Ceiling = -1.0; /*!< \brief CFL ceiling before the probe. */ + passivedouble Trial_Cap = -1.0; /*!< \brief CFL cap before the probe. */ + passivedouble Trial_StallCap = -1.0; /*!< \brief Plateau cap before the probe. */ unsigned short nVar, /*!< \brief Number of variables of the problem. */ nPrimVar, /*!< \brief Number of primitive variables of the problem. */ nPrimVarGrad, /*!< \brief Number of primitive variables of the problem in the gradient computation. */ diff --git a/SU2_CFD/src/solvers/CSolver.cpp b/SU2_CFD/src/solvers/CSolver.cpp index a47a4f899cb3..f748911fd837 100644 --- a/SU2_CFD/src/solvers/CSolver.cpp +++ b/SU2_CFD/src/solvers/CSolver.cpp @@ -2053,9 +2053,11 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, constexpr size_t stallWindow = 100; constexpr unsigned long stallPersist = 20; constexpr passivedouble stallProgress = 0.1, stallGrowth = 1.1; - constexpr size_t slopeWindow = 60; - constexpr unsigned long trialHold = 300, trialQuiet = 100, trialSettle = 150; - constexpr passivedouble trialCut = 0.75, trialBudget = 30.0, fallingSlope = 0.3, trialResponse = 0.5; + constexpr size_t rateWindow = 100; + static_assert(rateWindow <= bestWindow, "The rate window must fit in the stored residual history."); + constexpr unsigned long trialHold = 300, trialTransient = 40; + constexpr passivedouble trialCut = 0.35, trialRegrow = 0.7, trialGain = 1.3, trialNoise = 0.03, trialRetry = 0.5; + constexpr passivedouble fallingSlope = 0.3; constexpr passivedouble oscCap = 0.5, oscReset = 3.0, oscRelease = 1.2; constexpr unsigned long oscQuiet = 100; @@ -2160,9 +2162,9 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, } if (flip) CFL_LastFlip = iter; - /*--- Residuals that stop falling while the CFL no longer grows are stalled by a CFL that is too - * high, whatever the shape of their oscillation. The upper envelope of each residual over a - * window is compared with that of the window before. ---*/ + /*--- Residuals that stop falling while the CFL no longer grows are stalled, whatever the shape of + * their oscillation. The upper envelope of each residual over a window is compared with that of + * the window before. ---*/ ResStall_History.push_back(logRes); CFLStall_History.push_back(avgCFL); if (ResStall_History.size() > 2 * stallWindow) { @@ -2187,59 +2189,82 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, } else { Stall_Streak = 0; } - /*--- Cut a plateau repeatedly unless the residual is falling, and undo the cuts if it does not respond. ---*/ + /*--- One CFL cut probes a plateau, and the residual fall after its transient decides what stays. ---*/ const auto nMean = ResMean_History.size(); - auto meanSlope = [&](size_t window) { /* Least-squares slope in decades per 100 iterations. */ + auto meanRate = [&]() { /* Least-squares fall of the mean residual, in decades per 100 iterations. */ passivedouble sumX = 0.0, sumY = 0.0, sumXY = 0.0, sumXX = 0.0; - for (size_t k = 0; k <= window; k++) { - const passivedouble y = ResMean_History[nMean - 1 - window + k]; + for (size_t k = 0; k <= rateWindow; k++) { + const passivedouble y = ResMean_History[nMean - 1 - rateWindow + k]; sumX += k; sumY += y; sumXY += k * y; sumXX += passivedouble(k) * k; } - const passivedouble n = window + 1; - return 100.0 * (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX); + const passivedouble n = rateWindow + 1; + return -100.0 * (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX); }; - if (Trial_Active && (CFL_LastEvent > Trial_Start)) Trial_Active = false; - if (Trial_Active && (iter >= CFL_LastStall + trialQuiet)) { + auto rateText = [](passivedouble rate) { + std::ostringstream text; + text << std::fixed << std::setprecision(3) << rate; + return text.str(); + }; + bool probeEnded = false; + if (Trial_Active && (CFL_LastEvent > Trial_Start)) { Trial_Active = false; - if (rank == MASTER_NODE) cout << "CFL_ADAPT: plateau ended, CFL cuts kept." << endl; + probeEnded = true; + CFL_StallCap = Trial_StallCap; + if (rank == MASTER_NODE) cout << "CFL_ADAPT: probe ended by the CFL cut at iteration " << CFL_LastEvent << "." << endl; } - if ((frozen || stall) && (iter >= Trial_Hold) && (nMean > slopeWindow)) { - const passivedouble slope = meanSlope(slopeWindow); + if (Trial_Active && (iter >= Trial_Start + trialTransient + rateWindow)) { + const passivedouble rate = meanRate(); + Trial_Active = false; + probeEnded = true; CFL_LastStall = iter; Stall_Streak = 0; - if (Trial_Active && (avgCFL < Trial_CFL / trialBudget) && (Trial_Settle == 0)) { - Trial_Settle = iter + trialSettle; - } else if (Trial_Active && (Trial_Settle > 0) && (iter < Trial_Settle)) { - /* The residual is given time to respond at the lowest CFL. */ - } else if (Trial_Active && (Trial_Settle > 0) && (Trial_Res - flowMean > trialResponse)) { - Trial_Active = false; - if (rank == MASTER_NODE) cout << "CFL_ADAPT: residuals responded to the CFL cuts, they are kept." << endl; - } else if (Trial_Active && (Trial_Settle > 0)) { + std::ostringstream verdict; + if (rate >= trialGain * max(Trial_Rate, passivedouble(0.0)) + trialNoise) { + CFL_StallCap = max(trialRegrow * Trial_CFL, CFL_Cap); + verdict << "CFL cut kept, its cap may grow to " << CFL_StallCap << "."; + } else { CFL_Cap = Trial_Cap; CFL_Ceiling = Trial_Ceiling; CFL_StallCap = Trial_StallCap; - Trial_Active = false; - Trial_Hold = iter + trialHold; - if (rank == MASTER_NODE) - cout << "CFL_ADAPT: residuals did not respond to the CFL cuts since iteration " << Trial_Start - << ", CFL cuts undone." << endl; - } else if (Trial_Active || (slope > -fallingSlope)) { - if (!Trial_Active) { - Trial_Active = true; - Trial_Start = iter; - Trial_CFL = avgCFL; - Trial_Res = flowMean; - Trial_Settle = 0; - Trial_Ceiling = CFL_Ceiling; - Trial_Cap = CFL_Cap; - Trial_StallCap = CFL_StallCap; + if (rate < Trial_Rate - trialNoise) { + Trial_Off = true; + CFL_StallCap = -1.0; + verdict << "CFL cut undone, no more probes."; + } else { + Trial_Hold = iter + trialHold; + Trial_MaxRate = min(trialRetry * Trial_Rate, Trial_Rate - trialNoise); + verdict << "CFL cut undone."; } - CFL_Cap = max(trialCut * ((CFL_Cap > 0.0) ? min(CFL_Cap, avgCFL) : avgCFL), cflMin); + } + if (rank == MASTER_NODE) + cout << "CFL_ADAPT: probe at iteration " << iter << ", residuals fall " << rateText(rate) << " against " + << rateText(Trial_Rate) << " decades per 100 iterations, " << verdict.str() << endl; + } + if ((frozen || stall) && !Trial_Active && !Trial_Off && !probeEnded && (iter >= Trial_Hold) && + (nMean > rateWindow)) { + const passivedouble rate = meanRate(); + /*--- No probe while the first flow residual reaches its target within the iteration limit. ---*/ + const passivedouble decades = logRes[0] - SU2_TYPE::GetValue(config->GetMinLogResidual()); + const unsigned long nIter = config->GetMultizone_Problem() ? config->GetnOuter_Iter() : config->GetnInner_Iter(); + const passivedouble remaining = (nIter > iter) ? passivedouble(nIter - iter) : 0.0; + const bool onTime = (decades <= 0.0) || ((rate > 0.0) && (100.0 * decades <= rate * remaining)); + if ((rate < min(fallingSlope, Trial_MaxRate)) && !onTime) { + Trial_Active = true; + Trial_Start = iter; + Trial_Rate = rate; + Trial_CFL = (CFL_Cap > 0.0) ? min(CFL_Cap, avgCFL) : avgCFL; + Trial_Ceiling = CFL_Ceiling; + Trial_Cap = CFL_Cap; + Trial_StallCap = CFL_StallCap; + CFL_Cap = max(trialCut * Trial_CFL, cflMin); CFL_Ceiling = CFL_Cap; CFL_StallCap = CFL_Cap; + CFL_LastStall = iter; + Stall_Streak = 0; if (rank == MASTER_NODE) cout << "CFL_ADAPT: residuals " << (frozen ? "frozen" : "stalled") << " at iteration " << iter - << ", CFL capped at " << CFL_Cap << "." << endl; + << ", falling " << rateText(rate) << " decades per 100 iterations, CFL capped at " << CFL_Cap + << " to probe." << endl; } } @@ -2279,7 +2304,7 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, /*--- A cap that has held the CFL through a quiet, converging stretch is raised, so that it does not * outlive the transient that caused it. A new event at the higher CFL brings it back down. It - * stays below the cap set at the last stall and below the flip-flop limit, which itself rises + * stays below the cap kept after a plateau probe and below the flip-flop limit, which itself rises * in small steps over quiet, converging stretches. ---*/ if ((CFL_OscLevel > 0.0) && (flowMean < Res_AtOsc - oscReset)) CFL_OscLevel = -1.0; if ((CFL_OscLevel > 0.0) && (iter > max(CFL_LastEvent, CFL_LastOscRelease) + oscQuiet) && ResTrend_Increase && From 865e2abf41bbe1fd67f94307f8bf25ff88f44f77 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sat, 7 Nov 2026 15:20:12 +0100 Subject: [PATCH 27/42] reuse the coarse residual of the forcing term as the first coarse pre-smoothing step The coarse residual for the forcing term and the first coarse pre-smoothing step were evaluated at the same state. The forcing term evaluation now also assembles the Jacobian and the time step, and the first pre-smoothing step on that level starts from them. This saves one preprocessing and one residual evaluation per coarse level and cycle, for the flow system when the coarse level has pre-smoothing steps. A second visit of a W-cycle evaluates again. SetForcing_Term is split in two. SetRestricted_Residual stores the restricted defect before the coarse residual is computed, so the coarse boundary conditions still act on it, and SetForcing_Term subtracts the coarse residual afterwards. Results are bitwise identical without symmetry planes or Euler walls (4_2DANW 65 MG3, flat plate with its symmetry marker as farfield). With them, the projection of the normal momentum acts on the two parts of the forcing term separately, which differs by round-off: 1.7e-6 (NACA0012 Euler) and 1.6e-5 (laminar flat plate) in log rms after 100 iterations. About 2-4% less time per iteration on the 273x193 flat plate with MG3. Co-Authored-By: Claude Opus 5.5 --- .../integration/CMultiGridIntegration.hpp | 20 +++-- .../src/integration/CMultiGridIntegration.cpp | 73 +++++++++++++------ 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/SU2_CFD/include/integration/CMultiGridIntegration.hpp b/SU2_CFD/include/integration/CMultiGridIntegration.hpp index 85afd105ddeb..9ccdd0680220 100644 --- a/SU2_CFD/include/integration/CMultiGridIntegration.hpp +++ b/SU2_CFD/include/integration/CMultiGridIntegration.hpp @@ -78,23 +78,28 @@ class CMultiGridIntegration final : public CIntegration { * \param[in] iMesh - Index of the mesh in multigrid computations. * \param[in] mu - Variable for controlling the kind of multigrid algorithm. * \param[in] RunTime_EqSystem - System of equations which is going to be solved. - * \param[in] Iteration - Current iteration. + * \param[in] residualReady - The residual and time step of iMesh are already computed at its current solution. */ void MultiGrid_Cycle(CGeometry ****geometry, CSolver *****solver_container, CNumerics ******numerics_container, CConfig **config, unsigned short iMesh, unsigned short mu, unsigned short RunTime_EqSystem, - unsigned short iZone, unsigned short iInst); + unsigned short iZone, unsigned short iInst, bool residualReady); /*! - * \brief Compute the forcing term. + * \brief Store the restricted fine-grid defect in the truncation error of the coarse grid. * \param[in] sol_fine - Pointer to the solution on the fine grid. * \param[in] sol_coarse - Pointer to the solution on the coarse grid. - * \param[in] geo_fine - Geometrical definition of the fine grid. * \param[in] geo_coarse - Geometrical definition of the coarse grid. * \param[in] config - Definition of the particular problem. */ - void SetForcing_Term(CSolver *sol_fine, CSolver *sol_coarse, CGeometry *geo_fine, - CGeometry *geo_coarse, CConfig *config, unsigned short iMesh); + void SetRestricted_Residual(CSolver *sol_fine, CSolver *sol_coarse, CGeometry *geo_coarse, CConfig *config); + + /*! + * \brief Subtract the coarse-grid residual from the restricted defect, which gives the forcing term. + * \param[in] sol_coarse - Pointer to the solution on the coarse grid. + * \param[in] geo_coarse - Geometrical definition of the coarse grid. + */ + void SetForcing_Term(CSolver *sol_coarse, CGeometry *geo_coarse); /*! * \brief Add the truncation error to the residual. @@ -193,11 +198,12 @@ class CMultiGridIntegration final : public CIntegration { * \param[in] iMesh - Index of the mesh in multigrid computations. * \param[in] iZone - Index of the zone. * \param[in] iRKLimit - Number of Runge-Kutta steps. + * \param[in] residualReady - The first step starts from the residual and time step already computed. */ void PreSmoothing(unsigned short RunTime_EqSystem, CGeometry**** geometry, CSolver***** solver_container, CConfig **config_container, CSolver* solver_fine, CNumerics** numerics_fine, CGeometry* geometry_fine, CSolver** solver_container_fine, CConfig *config, - unsigned short iMesh, unsigned short iZone, unsigned short iRKLimit); + unsigned short iMesh, unsigned short iZone, unsigned short iRKLimit, bool residualReady); /*! * \brief Compute the fine grid correction from the coarse solution. diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index fd4453bedee7..923d6fac234a 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -443,7 +443,7 @@ void CMultiGridIntegration::MultiGrid_Iteration(CGeometry ****geometry, /*--- Perform the Full Approximation Scheme multigrid ---*/ MultiGrid_Cycle(geometry, solver_container, numerics_container, config, - FinestMesh, RecursiveParam, RunTime_EqSystem, iZone, iInst); + FinestMesh, RecursiveParam, RunTime_EqSystem, iZone, iInst, false); if (!fmg_warmup && !fmg_mesh0_ramp) SetCoarseGridCFL(geometry, solver_container, config, RunTime_EqSystem, iZone, iInst, FinestMesh, FullMG, @@ -615,13 +615,15 @@ void CMultiGridIntegration::MultiGrid_Cycle(CGeometry ****geometry, unsigned short RecursiveParam, unsigned short RunTime_EqSystem, unsigned short iZone, - unsigned short iInst) { + unsigned short iInst, + bool residualReady) { SU2_ZONE_SCOPED CConfig* config = config_container[iZone]; const unsigned short Solver_Position = config->GetContainerPosition(RunTime_EqSystem); const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); + const bool classical_rk4 = (config->GetKind_TimeIntScheme() == CLASSICAL_RK4_EXPLICIT); /*--- Shorter names to refer to fine grid entities. ---*/ @@ -645,7 +647,7 @@ void CMultiGridIntegration::MultiGrid_Cycle(CGeometry ****geometry, /*--- Do a presmoothing on the grid iMesh to be restricted to the grid iMesh+1 ---*/ PreSmoothing(RunTime_EqSystem, geometry, solver_container, config_container, solver_fine, numerics_fine, - geometry_fine, solver_container_fine, config, iMesh, iZone, iRKLimit); + geometry_fine, solver_container_fine, config, iMesh, iZone, iRKLimit, residualReady); /*--- Compute Forcing Term $P_(k+1) = I^(k+1)_k(P_k+F_k(u_k))-F_(k+1)(I^(k+1)_k u_k)$ and update solution for multigrid ---*/ @@ -658,7 +660,7 @@ void CMultiGridIntegration::MultiGrid_Cycle(CGeometry ****geometry, CSolver* solver_coarse = solver_container_coarse[Solver_Position]; CNumerics** numerics_coarse = numerics_container[iZone][iInst][iMesh+1][Solver_Position]; - /*--- Temporarily disable implicit integration, for what follows we do not need the Jacobian. ---*/ + /*--- Temporarily disable implicit integration, the fine residual needs no Jacobian. ---*/ if (implicit) { SU2_OMP_SAFE_GLOBAL_ACCESS(config->SetKind_TimeIntScheme(EULER_EXPLICIT);) @@ -678,21 +680,38 @@ void CMultiGridIntegration::MultiGrid_Cycle(CGeometry ****geometry, SetResidual_Term(geometry_fine, solver_fine); - /*--- Compute $r_(k+1) = F_(k+1)(I^(k+1)_k u_k)$ ---*/ + /*--- The coarse residual is also the first coarse pre-smoothing step, so it gets its Jacobian. ---*/ + + const auto& mgOpts = config->GetMGOptions(); + const bool coarseReady = (RunTime_EqSystem == RUNTIME_FLOW_SYS) && (mgOpts.MG_PreSmooth[iMesh+1] > 0); + + if (implicit && coarseReady) { + SU2_OMP_SAFE_GLOBAL_ACCESS(config->SetKind_TimeIntScheme(EULER_IMPLICIT);) + } + + /*--- Compute $r_(k+1) = F_(k+1)(I^(k+1)_k u_k)$, whose boundary conditions also act on the restricted defect. ---*/ SetRestricted_Solution(RunTime_EqSystem, solver_fine, solver_coarse, geometry_fine, geometry_coarse, config); + SetRestricted_Residual(solver_fine, solver_coarse, geometry_coarse, config); + solver_coarse->Preprocessing(geometry_coarse, solver_container_coarse, config, iMesh+1, NO_RK_ITER, RunTime_EqSystem, false); + if (coarseReady) { + solver_coarse->Set_OldSolution(); + if (classical_rk4) solver_coarse->Set_NewSolution(); + solver_coarse->SetTime_Step(geometry_coarse, solver_container_coarse, config, iMesh+1, config->GetTimeIter()); + } + Space_Integration(geometry_coarse, solver_container_coarse, numerics_coarse, config, iMesh+1, NO_RK_ITER, RunTime_EqSystem); /*--- Compute $P_(k+1) = I^(k+1)_k(r_k) - r_(k+1) ---*/ - SetForcing_Term(solver_fine, solver_coarse, geometry_fine, geometry_coarse, config, iMesh+1); + SetForcing_Term(solver_coarse, geometry_coarse); /*--- Restore the time integration settings. ---*/ - if (implicit) { + if (implicit && !coarseReady) { SU2_OMP_SAFE_GLOBAL_ACCESS(config->SetKind_TimeIntScheme(EULER_IMPLICIT);) } @@ -707,7 +726,7 @@ void CMultiGridIntegration::MultiGrid_Cycle(CGeometry ****geometry, nextRecurseParam = 0; MultiGrid_Cycle(geometry, solver_container, numerics_container, config_container, - iMesh+1, nextRecurseParam, RunTime_EqSystem, iZone, iInst); + iMesh+1, nextRecurseParam, RunTime_EqSystem, iZone, iInst, coarseReady && (imu == 0)); } /*--- Compute prolongated solution, and smooth the correction $u^(new)_k = u_k + @@ -716,7 +735,6 @@ void CMultiGridIntegration::MultiGrid_Cycle(CGeometry ****geometry, GetProlongated_Correction(RunTime_EqSystem, solver_fine, solver_coarse, geometry_fine, geometry_coarse, config, iMesh+1); - const auto& mgOpts = config->GetMGOptions(); SmoothProlongated_Correction(RunTime_EqSystem, solver_fine, geometry_fine, mgOpts.MG_CorrecSmooth[iMesh], mgOpts.MG_Smooth_Coeff, config, iMesh); SetProlongated_Correction(solver_fine, solver_container_fine[FLOW_SOL], geometry_fine, config, iMesh); @@ -772,7 +790,8 @@ void CMultiGridIntegration::PreSmoothing(unsigned short RunTime_EqSystem, CConfig *config, unsigned short iMesh, unsigned short iZone, - unsigned short iRKLimit) { + unsigned short iRKLimit, + bool residualReady) { SU2_ZONE_SCOPED const auto& mgOpts = config->GetMGOptions(); @@ -793,21 +812,24 @@ void CMultiGridIntegration::PreSmoothing(unsigned short RunTime_EqSystem, /*--- Time and space integration ---*/ for (unsigned short iRKStep = 0; iRKStep < iRKLimit; iRKStep++) { - /*--- Send-Receive boundary conditions, and preprocessing ---*/ - solver_fine->Preprocessing(geometry_fine, solver_container_fine, config, iMesh, iRKStep, RunTime_EqSystem, false); + if (!residualReady || (iPreSmooth > 0) || (iRKStep > 0)) { - if (iRKStep == 0) { + /*--- Send-Receive boundary conditions, and preprocessing ---*/ + solver_fine->Preprocessing(geometry_fine, solver_container_fine, config, iMesh, iRKStep, RunTime_EqSystem, false); - /*--- Set the old solution ---*/ - solver_fine->Set_OldSolution(); + if (iRKStep == 0) { - if (classical_rk4) solver_fine->Set_NewSolution(); - solver_fine->SetTime_Step(geometry_fine, solver_container_fine, config, iMesh, timeIter); - Adjoint_Setup(geometry, solver_container, config_container, RunTime_EqSystem, timeIter, iZone); - } + /*--- Set the old solution ---*/ + solver_fine->Set_OldSolution(); - /*--- Space integration ---*/ - Space_Integration(geometry_fine, solver_container_fine, numerics_fine, config, iMesh, iRKStep, RunTime_EqSystem); + if (classical_rk4) solver_fine->Set_NewSolution(); + solver_fine->SetTime_Step(geometry_fine, solver_container_fine, config, iMesh, timeIter); + Adjoint_Setup(geometry, solver_container, config_container, RunTime_EqSystem, timeIter, iZone); + } + + /*--- Space integration ---*/ + Space_Integration(geometry_fine, solver_container_fine, numerics_fine, config, iMesh, iRKStep, RunTime_EqSystem); + } /*--- Time integration, update solution using the old solution plus the solution increment ---*/ Time_Integration(geometry_fine, solver_container_fine, config, iRKStep, RunTime_EqSystem); @@ -1687,8 +1709,8 @@ void CMultiGridIntegration::SetProlongated_ScalarSolution(CSolver *sol_fine, CSo } -void CMultiGridIntegration::SetForcing_Term(CSolver *sol_fine, CSolver *sol_coarse, CGeometry *geo_fine, - CGeometry *geo_coarse, CConfig *config, unsigned short iMesh) { +void CMultiGridIntegration::SetRestricted_Residual(CSolver *sol_fine, CSolver *sol_coarse, CGeometry *geo_coarse, + CConfig *config) { SU2_ZONE_SCOPED const unsigned short nVar = sol_coarse->GetnVar(); @@ -1726,6 +1748,11 @@ void CMultiGridIntegration::SetForcing_Term(CSolver *sol_fine, CSolver *sol_coar } } +} + +void CMultiGridIntegration::SetForcing_Term(CSolver *sol_coarse, CGeometry *geo_coarse) { + SU2_ZONE_SCOPED + SU2_OMP_FOR_STAT(roundUpDiv(geo_coarse->GetnPointDomain(), omp_get_num_threads())) for (auto Point_Coarse = 0ul; Point_Coarse < geo_coarse->GetnPointDomain(); Point_Coarse++) { sol_coarse->GetNodes()->SubtractRes_TruncError(Point_Coarse, sol_coarse->LinSysRes.GetBlock(Point_Coarse)); From 32142a29a4d13a524f222aa07aa78e5354422135 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sat, 14 Nov 2026 21:00:55 +0100 Subject: [PATCH 28/42] cap coarse-level linear iterations at 3, add TURB_SUBITER, fix coarse CFL bounds - MG_LINEAR_SOLVER_ITER defaults to 3 on the coarse levels. - TURB_SUBITER sets the number of turbulence iterations per flow iteration. - AdaptCFLNumber scales the CFL floor and cap of a coarse level with MG_CFL_SCALING, and loses the unused flip-flop detection. - MG_SMOOTH_OUTPUT prints the smoothing and correction gain of the finest level and the accumulated work in finest-grid equivalents. - The coarsest level is smoothed at least once. - Coarse residuals are reduced once per cycle with MG_SMOOTH_OUTPUT. Co-Authored-By: Claude Fable 5.2 --- Common/include/CConfig.hpp | 6 ++ Common/src/CConfig.cpp | 14 ++-- .../integration/CMultiGridIntegration.hpp | 14 ++++ .../src/integration/CMultiGridIntegration.cpp | 64 ++++++++++++------- .../integration/CSingleGridIntegration.cpp | 3 +- SU2_CFD/src/iteration/CFluidIteration.cpp | 5 +- SU2_CFD/src/solvers/CSolver.cpp | 60 +++-------------- 7 files changed, 84 insertions(+), 82 deletions(-) diff --git a/Common/include/CConfig.hpp b/Common/include/CConfig.hpp index 5b3dd507b34e..96921c5dff18 100644 --- a/Common/include/CConfig.hpp +++ b/Common/include/CConfig.hpp @@ -1150,6 +1150,7 @@ class CConfig { bool RelFrame_SlidingPlane; /*!< \brief option for relative frame slidingplane */ bool RampMotionFrame; /*!< \brief option for ramping up or down the motion Frame values */ bool RampOutlet; /*!< \brief option for ramping up or down the outlet values */ + unsigned short Turb_SubIter; /*!< \brief Turbulence iterations per flow iteration. */ bool RampMUSCL; bool RampRotatingFrame; /*!< \brief option for ramping up or down the motion Frame values */ bool RampTranslationFrame; /*!< \brief option for ramping up or down the outlet values */ @@ -7492,6 +7493,11 @@ class CConfig { */ su2double GetCFLRedCoeff_Turb(void) const { return CFLRedCoeff_Turb; } + /*! + * \brief Get the number of turbulence iterations per flow iteration. + */ + unsigned short GetTurb_SubIter(void) const { return Turb_SubIter; } + /*! * \brief Value of the CFL reduction in species problems. * \return Value of the CFL reduction in species problems. diff --git a/Common/src/CConfig.cpp b/Common/src/CConfig.cpp index 13269b272eb8..ec7286c0db65 100644 --- a/Common/src/CConfig.cpp +++ b/Common/src/CConfig.cpp @@ -1947,6 +1947,8 @@ void CConfig::SetConfig_Options() { addDoubleOption("CFL_REDUCTION_ADJFLOW", CFLRedCoeff_AdjFlow, 0.8); /* DESCRIPTION: Reduction factor of the CFL coefficient in the level set problem */ addDoubleOption("CFL_REDUCTION_TURB", CFLRedCoeff_Turb, 1.0); + /* DESCRIPTION: Number of turbulence iterations per flow iteration. */ + addUnsignedShortOption("TURB_SUBITER", Turb_SubIter, 1); /* DESCRIPTION: Reduction factor of the CFL coefficient in the turbulent adjoint problem */ addDoubleOption("CFL_REDUCTION_ADJTURB", CFLRedCoeff_AdjTurb, 1.0); /*!\brief CFL_REDUCTION_SPECIES \n DESCRIPTION: Reduction factor of the CFL coefficient in the species problem \n DEFAULT: 1.0 */ @@ -2109,11 +2111,11 @@ void CConfig::SetConfig_Options() { addUShortListOption("MG_POST_SMOOTH", nMG_PostSmooth_p, MG_PostSmooth_p); /*!\brief MG_CORRECTION_SMOOTH\n DESCRIPTION: Jacobi implicit smoothing of the correction \ingroup Config*/ addUShortListOption("MG_CORRECTION_SMOOTH", nMG_CorrecSmooth_p, MG_CorrecSmooth_p); - /*!\brief MG_DAMP_RESTRICTION\n DESCRIPTION: Damping factor for the residual restriction. DEFAULT: 0.75 \ingroup Config*/ + /*!\brief MG_DAMP_RESTRICTION\n DESCRIPTION: Damping factor for the residual restriction. DEFAULT: 0.5 \ingroup Config*/ addDoubleOption("MG_DAMP_RESTRICTION", Damp_Res_Restric, 0.5); - /*!\brief MG_DAMP_PROLONGATION\n DESCRIPTION: Damping factor for the correction prolongation. DEFAULT 0.75 \ingroup Config*/ + /*!\brief MG_DAMP_PROLONGATION\n DESCRIPTION: Damping factor for the correction prolongation. DEFAULT: 0.5 \ingroup Config*/ addDoubleOption("MG_DAMP_PROLONGATION", Damp_Correc_Prolong, 0.5); - /*!\brief MG_SMOOTH_EARLY_EXIT\n DESCRIPTION: Enable early exit for MG smoothing when RMS drops below threshold. DEFAULT: NO \ingroup Config*/ + /*!\brief MG_SMOOTH_EARLY_EXIT\n DESCRIPTION: Enable early exit for MG smoothing when RMS drops below threshold. DEFAULT: YES \ingroup Config*/ addBoolOption("MG_SMOOTH_EARLY_EXIT", MGOptions.MG_Smooth_EarlyExit, true); /*!\brief MG_SMOOTH_RES_THRESHOLD\n DESCRIPTION: Early exit smoothing when current_rms drops below threshold * initial_rms. DEFAULT: 0.9 \ingroup Config*/ addDoubleOption("MG_SMOOTH_RES_THRESHOLD", MGOptions.MG_Smooth_Res_Threshold, 0.9); @@ -2153,7 +2155,7 @@ void CConfig::SetConfig_Options() { * If fewer values than nMGLevels are given, the last value is repeated. DEFAULT: 0.25 (i.e., 1/4 per level) \ingroup Config*/ addDoubleListOption("MG_CFL_SCALING", nMG_CflScaling_p, MG_CflScaling_p); /*!\brief MG_LINEAR_SOLVER_ITER\n DESCRIPTION: Maximum linear solver iterations on coarse MG levels. Entry i applies to level i+1; - * the last value is repeated, and the cap never exceeds LINEAR_SOLVER_ITER. DEFAULT: LINEAR_SOLVER_ITER \ingroup Config*/ + * the last value is repeated, and the cap never exceeds LINEAR_SOLVER_ITER. DEFAULT: 3 \ingroup Config*/ addUShortListOption("MG_LINEAR_SOLVER_ITER", nMG_LinSolIter_p, MG_LinSolIter_p); /*!\par CONFIG_CATEGORY: Spatial Discretization \ingroup Config*/ @@ -5145,8 +5147,8 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i /*--- Linear solver iteration cap per level; level 0 always uses LINEAR_SOLVER_ITER. ---*/ MGOptions.MG_LinSolIter.assign(nMGLevels + 1, Linear_Solver_Iter); - for (unsigned short i = 1; i <= nMGLevels && nMG_LinSolIter_p != 0; ++i) { - const auto cap = MG_LinSolIter_p[min(i - 1, nMG_LinSolIter_p - 1)]; + for (unsigned short i = 1; i <= nMGLevels; ++i) { + const unsigned long cap = (nMG_LinSolIter_p != 0) ? MG_LinSolIter_p[min(i - 1, nMG_LinSolIter_p - 1)] : 3; MGOptions.MG_LinSolIter[i] = min(cap, Linear_Solver_Iter); } } diff --git a/SU2_CFD/include/integration/CMultiGridIntegration.hpp b/SU2_CFD/include/integration/CMultiGridIntegration.hpp index 9ccdd0680220..e0dc16d77db9 100644 --- a/SU2_CFD/include/integration/CMultiGridIntegration.hpp +++ b/SU2_CFD/include/integration/CMultiGridIntegration.hpp @@ -375,6 +375,20 @@ class CMultiGridIntegration final : public CIntegration { passivedouble mg_fine_rms_ema = 0.0; /*!< \brief EMA of fine-grid pre-smooth RMS across cycles; cross-cycle trend signal. */ passivedouble last_crossCycleRatio = 1.0; /*!< \brief crossCycleRatio from the most recent cycle; stored for display only. */ + /*--- Diagnostics of MG_SMOOTH_OUTPUT, with work in finest-grid equivalents. ---*/ + passivedouble mg_prev_cycle_defect = 0.0; /*!< \brief Finest-level defect after the previous cycle's pre-smoothing. */ + passivedouble mg_work_weight[MAX_MG_LEVELS+1] = {}; /*!< \brief Points of each level over those of the finest grid. */ + passivedouble mg_work_residual = 0.0; /*!< \brief Accumulated residual evaluations. */ + passivedouble mg_work_linear = 0.0; /*!< \brief Accumulated linear solver iterations. */ + + /*! + * \brief Add one residual evaluation and its linear iterations on a level to the work counters. + */ + void AddWork(const CConfig* config, unsigned short iMesh, unsigned long linIters) { + mg_work_residual += mg_work_weight[iMesh]; + if (config->GetKind_TimeIntScheme() == EULER_IMPLICIT) mg_work_linear += mg_work_weight[iMesh] * linIters; + } + /*--- Actual iteration counts per MG level, filled each cycle for the compact output summary. ---*/ unsigned short lastPreSmoothIters[MAX_MG_LEVELS+1] = {}; unsigned short lastPostSmoothIters[MAX_MG_LEVELS+1] = {}; diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index 923d6fac234a..9832e0aa4007 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -330,6 +330,10 @@ void CMultiGridIntegration::MultiGrid_Iteration(CGeometry ****geometry, if (config[iZone]->GetInnerIter() < mg_ramp_level_start_iter) mg_ramp_level_start_iter = config[iZone]->GetInnerIter(); + + for (unsigned short i = 0; i <= nMGLevels; ++i) + mg_work_weight[i] = passivedouble(geometry[iZone][iInst][i]->GetGlobal_nPointDomain()) / + passivedouble(geometry[iZone][iInst][MESH_0]->GetGlobal_nPointDomain()); } END_SU2_OMP_SAFE_GLOBAL_ACCESS @@ -417,6 +421,7 @@ void CMultiGridIntegration::MultiGrid_Iteration(CGeometry ****geometry, /*--- The EMA is measured on a different grid after a promotion. ---*/ mg_fine_rms_ema = 0.0; + mg_prev_cycle_defect = 0.0; config[iZone]->SetDamp_Res_Restric(mg_damp_restric_initial); config[iZone]->SetDamp_Correc_Prolong(mg_damp_prolong_initial); @@ -452,7 +457,8 @@ void CMultiGridIntegration::MultiGrid_Iteration(CGeometry ****geometry, /*--- Coarse-level residuals are per-rank partial sums; reduce once so the promotion criterion * agrees on every rank. The smoothing early exit already reduces when it is on. ---*/ - if (fmg_warmup && !config[iZone]->GetMGOptions().MG_Smooth_EarlyExit) { + if (fmg_warmup && !config[iZone]->GetMGOptions().MG_Smooth_EarlyExit && + !config[iZone]->GetMGOptions().MG_Smooth_Output) { solver_container[iZone][iInst][FinestMesh][Solver_Position]->SetResidual_RMS( geometry[iZone][iInst][FinestMesh], config[iZone], true); } @@ -596,8 +602,18 @@ void CMultiGridIntegration::MultiGrid_Iteration(CGeometry ****geometry, cout << std::fixed << std::setprecision(4) << "Damping [restrict | prolong] : " << config[iZone]->GetDamp_Res_Restric() << " | " << config[iZone]->GetDamp_Correc_Prolong() - << " cross-cycle: " << std::setprecision(3) << last_crossCycleRatio << "\n" - << std::defaultfloat << std::setprecision(6); + << " cross-cycle: " << std::setprecision(3) << last_crossCycleRatio << "\n"; + + /*--- Defect ratios of the finest level: over its pre-smoothing, and from there to the start of + * this cycle, which spans the coarse-grid correction and the scalar solvers. ---*/ + if (FinestMesh < nMGLevels) { + const passivedouble d0 = lastPreSmoothRMS[FinestMesh][0], d1 = lastPreSmoothRMS[FinestMesh][1]; + cout << "Gain [smoothing | correction] : " << ((d0 > 0.0) ? d1 / d0 : 0.0) << " | " + << ((mg_prev_cycle_defect > 0.0) ? d0 / mg_prev_cycle_defect : 0.0); + mg_prev_cycle_defect = d1; + } + cout << " work [residual | linear] : " << std::setprecision(1) << mg_work_residual << " | " << mg_work_linear; + cout << "\n" << std::defaultfloat << std::setprecision(6); } END_SU2_OMP_SAFE_GLOBAL_ACCESS } @@ -651,7 +667,7 @@ void CMultiGridIntegration::MultiGrid_Cycle(CGeometry ****geometry, /*--- Compute Forcing Term $P_(k+1) = I^(k+1)_k(P_k+F_k(u_k))-F_(k+1)(I^(k+1)_k u_k)$ and update solution for multigrid ---*/ - if ( iMesh < config->GetnMGLevels() ) { + if (iMesh < config->GetnMGLevels()) { /*--- Shorter names to refer to coarse grid entities. ---*/ @@ -672,17 +688,17 @@ void CMultiGridIntegration::MultiGrid_Cycle(CGeometry ****geometry, Space_Integration(geometry_fine, solver_container_fine, numerics_fine, config, iMesh, NO_RK_ITER, RunTime_EqSystem); - /*--- LinSysRes = R(u_N) here, before tau is added by SetResidual_Term. ---*/ - BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { - lastPreSmoothRMS[iMesh][1] = ComputeLinSysResRMS(solver_fine); - } - END_SU2_OMP_SAFE_GLOBAL_ACCESS - SetResidual_Term(geometry_fine, solver_fine); - /*--- The coarse residual is also the first coarse pre-smoothing step, so it gets its Jacobian. ---*/ - const auto& mgOpts = config->GetMGOptions(); + + /*--- Defect left by the pre-smoothing, forcing term included. ---*/ + if (mgOpts.MG_Smooth_Output) { + const su2double defect = sqrt(solver_fine->LinSysRes.squaredNorm() / geometry_fine->GetGlobal_nPointDomain()); + SU2_OMP_SAFE_GLOBAL_ACCESS(lastPreSmoothRMS[iMesh][1] = SU2_TYPE::GetValue(defect);) + } + + /*--- The coarse residual is also the first coarse pre-smoothing step, so it gets its Jacobian. ---*/ const bool coarseReady = (RunTime_EqSystem == RUNTIME_FLOW_SYS) && (mgOpts.MG_PreSmooth[iMesh+1] > 0); if (implicit && coarseReady) { @@ -709,6 +725,9 @@ void CMultiGridIntegration::MultiGrid_Cycle(CGeometry ****geometry, SetForcing_Term(solver_coarse, geometry_coarse); + /*--- The coarse evaluation is counted with the pre-smoothing step that reuses it. ---*/ + SU2_OMP_SAFE_GLOBAL_ACCESS(mg_work_residual += mg_work_weight[iMesh] + (coarseReady ? 0.0 : mg_work_weight[iMesh+1]);) + /*--- Restore the time integration settings. ---*/ if (implicit && !coarseReady) { @@ -796,7 +815,8 @@ void CMultiGridIntegration::PreSmoothing(unsigned short RunTime_EqSystem, const auto& mgOpts = config->GetMGOptions(); const bool classical_rk4 = (config->GetKind_TimeIntScheme() == CLASSICAL_RK4_EXPLICIT); - const unsigned short nPreSmooth = mgOpts.MG_PreSmooth[iMesh]; + /*--- The coarsest level is smoothed at least once. ---*/ + const unsigned short nPreSmooth = max(mgOpts.MG_PreSmooth[iMesh], (iMesh == config->GetnMGLevels()) ? 1 : 0); const unsigned long timeIter = config->GetTimeIter(); const bool early_exit = mgOpts.MG_Smooth_EarlyExit && (nPreSmooth > 1); const bool need_per_step_rms = early_exit || mgOpts.MG_Smooth_Output; @@ -834,13 +854,13 @@ void CMultiGridIntegration::PreSmoothing(unsigned short RunTime_EqSystem, /*--- Time integration, update solution using the old solution plus the solution increment ---*/ Time_Integration(geometry_fine, solver_container_fine, config, iRKStep, RunTime_EqSystem); - if (mgOpts.MG_Smooth_Output) { - BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { + if (mgOpts.MG_Smooth_Output) lastPreLinSol[iMesh].push_back({solver_fine->GetIterLinSolver(), SU2_TYPE::GetValue(solver_fine->GetResLinSolver())}); - } - END_SU2_OMP_SAFE_GLOBAL_ACCESS + AddWork(config, iMesh, solver_fine->GetIterLinSolver()); } + END_SU2_OMP_SAFE_GLOBAL_ACCESS /*--- At iRKStep==0 LinSysRes = R(u_k). ---*/ if (iRKStep == 0 && need_initial_rms) { @@ -915,13 +935,13 @@ void CMultiGridIntegration::PostSmoothing(unsigned short RunTime_EqSystem, /*--- Time integration, update solution using the old solution plus the solution increment ---*/ Time_Integration(geometry_fine, solver_container_fine, config, iRKStep, RunTime_EqSystem); - if (mgOpts.MG_Smooth_Output) { - BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { + if (mgOpts.MG_Smooth_Output) lastPostLinSol[iMesh].push_back({solver_fine->GetIterLinSolver(), - SU2_TYPE::GetValue(solver_fine->GetResLinSolver())}); - } - END_SU2_OMP_SAFE_GLOBAL_ACCESS + SU2_TYPE::GetValue(solver_fine->GetResLinSolver())}); + AddWork(config, iMesh, solver_fine->GetIterLinSolver()); } + END_SU2_OMP_SAFE_GLOBAL_ACCESS /*--- At iRKStep==0 LinSysRes = R(u_k) ---*/ if (iRKStep == 0 && need_per_step_rms) { diff --git a/SU2_CFD/src/integration/CSingleGridIntegration.cpp b/SU2_CFD/src/integration/CSingleGridIntegration.cpp index 1e712b5079b7..93dfffeebde1 100644 --- a/SU2_CFD/src/integration/CSingleGridIntegration.cpp +++ b/SU2_CFD/src/integration/CSingleGridIntegration.cpp @@ -90,7 +90,8 @@ void CSingleGridIntegration::SingleGrid_Iteration(CGeometry ****geometry, CSolve /*--- Coarse-level residuals are per-rank sums of squares unless reduced, which the smoothing * early exit already does. ---*/ - if ((FinestMesh != MESH_0) && !config[iZone]->GetMGOptions().MG_Smooth_EarlyExit) { + if ((FinestMesh != MESH_0) && !config[iZone]->GetMGOptions().MG_Smooth_EarlyExit && + !config[iZone]->GetMGOptions().MG_Smooth_Output) { solvers_fine[Solver_Position]->SetResidual_RMS(geometry_fine, config[iZone], true); } diff --git a/SU2_CFD/src/iteration/CFluidIteration.cpp b/SU2_CFD/src/iteration/CFluidIteration.cpp index f7d9350fe1a4..f02c1e5b1c34 100644 --- a/SU2_CFD/src/iteration/CFluidIteration.cpp +++ b/SU2_CFD/src/iteration/CFluidIteration.cpp @@ -132,8 +132,9 @@ void CFluidIteration::CommonAuxiliarySolvers(CIntegration**** integration, CGeom /*--- Solve the turbulence model ---*/ config[val_iZone]->SetGlobalParam(main_solver, RUNTIME_TURB_SYS); - integration[val_iZone][val_iInst][TURB_SOL]->SingleGrid_Iteration(geometry, solver, numerics, config, - RUNTIME_TURB_SYS, val_iZone, val_iInst); + for (auto iSub = 0u; iSub < max(config[val_iZone]->GetTurb_SubIter(), 1); iSub++) + integration[val_iZone][val_iInst][TURB_SOL]->SingleGrid_Iteration(geometry, solver, numerics, config, + RUNTIME_TURB_SYS, val_iZone, val_iInst); } if (config[val_iZone]->GetKind_Species_Model() != SPECIES_MODEL::NONE) { diff --git a/SU2_CFD/src/solvers/CSolver.cpp b/SU2_CFD/src/solvers/CSolver.cpp index f748911fd837..1cbf1d9ff172 100644 --- a/SU2_CFD/src/solvers/CSolver.cpp +++ b/SU2_CFD/src/solvers/CSolver.cpp @@ -1919,9 +1919,6 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, const su2double startingIter = config->GetCFL_AdaptParam(5); const bool fullComms = (config->GetComm_Level() == COMM_FULL); - /* Number of iterations considered to check for stagnation. */ - const auto Res_Count = min(100ul, config->GetnInner_Iter()-1); - static bool reduceCFL, resetCFL, canIncrease; for (unsigned short iMesh = 0; iMesh <= config->GetnMGLevels(); iMesh++) { @@ -1937,7 +1934,7 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, if (iMesh == MESH_0) { MGFactor[iMesh] = 1.0; } else { - const su2double CFLRatio = config->GetCFL(iMesh)/config->GetCFL(iMesh-1); + const su2double CFLRatio = max(su2double(1e-6), min(su2double(1.0), config->GetMGOptions().MG_CflScaling[iMesh-1])); MGFactor[iMesh] = MGFactor[iMesh-1]*CFLRatio; } @@ -1971,14 +1968,9 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, canIncrease = (linRes < linTol) && (iter >= startingIter); - /* Do not use the residual flip-flop criteria when we are mitigating outliers - * because the former was never very reliable for large cases where monotonic - * residual reduction is impossible to achieve. */ - if (!config->OptionIsSet("OUTLIER_MITIGATION_PARAM") && iMesh == MESH_0 && Res_Count > 0) { - Old_Func = New_Func; - if (NonLinRes_Series.empty()) NonLinRes_Series.resize(Res_Count,0.0); + if (!config->OptionIsSet("OUTLIER_MITIGATION_PARAM") && iMesh == MESH_0) { - /* Sum the RMS residuals for all equations. */ + /* Mean of the log RMS residuals of all equations. */ New_Func = 0.0; unsigned short totalVars = 0; @@ -1999,41 +1991,6 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, } } New_Func /= totalVars; - - /* Compute the difference in the nonlinear residuals between the - current and previous iterations, taking care with very low initial - residuals (due to initialization). */ - - if ((config->GetInnerIter() == 1) && (New_Func - Old_Func > 10)) { - Old_Func = New_Func; - } - NonLinRes_Series[NonLinRes_Counter] = New_Func - Old_Func; - - /* Increment the counter, if we hit the max size, then start over. */ - - NonLinRes_Counter++; - if (NonLinRes_Counter == Res_Count) NonLinRes_Counter = 0; - - /* Detect flip-flop convergence to reduce CFL and large increases - to reset to minimum value, in that case clear the history. */ - - if (config->GetInnerIter() >= Res_Count) { - unsigned long signChanges = 0; - su2double totalChange = 0.0; - auto prev = NonLinRes_Series.front(); - for (const auto& val : NonLinRes_Series) { - totalChange += val; - signChanges += (prev > 0) ^ (val > 0); - prev = val; - } - reduceCFL |= (signChanges > Res_Count/4) && (totalChange > -0.5); - - if (totalChange > 2.0) { // orders of magnitude - resetCFL = true; - NonLinRes_Counter = 0; - for (auto& val : NonLinRes_Series) val = 0.0; - } - } } /*--- The finest-grid nonlinear residuals drive the CFL, so the decision does not depend on how many @@ -2387,10 +2344,10 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, /* Check if we are hitting the min or max and adjust. */ - if (CFL * CFLFactor <= CFLMin) { + if (CFL * CFLFactor <= CFLMin * MGFactor[iMesh]) { CFL = CFLMin; CFLFactor = MGFactor[iMesh]; - } else if (CFL * CFLFactor >= CFLMax) { + } else if (CFL * CFLFactor >= CFLMax * MGFactor[iMesh]) { CFL = CFLMax; CFLFactor = MGFactor[iMesh]; } @@ -2453,9 +2410,10 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, void CSolver::SetResidual_RMS(const CGeometry *geometry, const CConfig *config, bool force) { SU2_ZONE_SCOPED - /*--- On coarse levels the reduction is skipped for performance, unless MG_Smooth_EarlyExit - * needs it or the caller asks for it. ---*/ - if (!force && geometry->GetMGLevel() != MESH_0 && !config->GetMGOptions().MG_Smooth_EarlyExit) return; + /*--- On coarse levels the reduction is skipped for performance, unless MG_Smooth_EarlyExit or + * MG_Smooth_Output needs it, or the caller asks for it. ---*/ + if (!force && geometry->GetMGLevel() != MESH_0 && !config->GetMGOptions().MG_Smooth_EarlyExit && + !config->GetMGOptions().MG_Smooth_Output) return; BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { From fbdd06b8dfd242147b806506eee4963f653eb6e0 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sun, 15 Nov 2026 09:35:37 +0100 Subject: [PATCH 29/42] default MG_CFL_SCALING 0.5, update multigrid regression references - Coarse levels run at half the CFL of the next finer level by default (was a quarter). On the six turbulence verification cases on fine meshes this lowers multigrid work relative to single grid, most on the flat plate (0.83 -> 0.68), the 2D bump (0.41 -> 0.35) and the NACA 4412 airfoil (0.99 -> 0.85); drag is unchanged. - Update the reference values of all regression tests that use multigrid without setting MG_CFL_SCALING. Most references were already stale from the earlier multigrid changes on this branch: with MG_CFL_SCALING= 0.25 only 2 of 38 tests reproduced them. - hybrid edge_VW now reaches CONV_RESIDUAL_MINVAL before iteration 25; test at iteration 20. - aarch64 references that differed from x86 are left unchanged. - Not regenerated locally (no MPI build of the Python wrapper, stale AD build): parallel pywrapper_naca0012, pywrapper_aeroelastic, pywrapper_unsteadyCHT, hybrid pywrapper translating/moving-frame file diffs, and the AD scripts' directdiff_euler_py / discadj_euler_py. Co-Authored-By: Claude Opus 5.5 --- Common/src/CConfig.cpp | 4 +- .../wedge/of_grad_combo.dat.ref | 8 +- TestCases/hybrid_regression.py | 52 +++++------ TestCases/parallel_regression.py | 80 ++++++++--------- TestCases/serial_regression.py | 90 +++++++++---------- config_template.cfg | 4 +- 6 files changed, 119 insertions(+), 119 deletions(-) diff --git a/Common/src/CConfig.cpp b/Common/src/CConfig.cpp index ec7286c0db65..707a5351b906 100644 --- a/Common/src/CConfig.cpp +++ b/Common/src/CConfig.cpp @@ -2152,7 +2152,7 @@ void CConfig::SetConfig_Options() { * on stagnation. 0 disables it, as MG_STARTUP_STAGNATION= 0 does. DEFAULT: 5 \ingroup Config*/ addUnsignedLongOption("MG_STARTUP_STAGNATION_ITER", MGOptions.MG_Startup_Stagnation_Iter, 5); /*!\brief MG_CFL_SCALING\n DESCRIPTION: Per-level CFL scaling factors for coarse MG levels. Entry i is the ratio CFL(i+1)/CFL(i). - * If fewer values than nMGLevels are given, the last value is repeated. DEFAULT: 0.25 (i.e., 1/4 per level) \ingroup Config*/ + * If fewer values than nMGLevels are given, the last value is repeated. DEFAULT: 0.5 \ingroup Config*/ addDoubleListOption("MG_CFL_SCALING", nMG_CflScaling_p, MG_CflScaling_p); /*!\brief MG_LINEAR_SOLVER_ITER\n DESCRIPTION: Maximum linear solver iterations on coarse MG levels. Entry i applies to level i+1; * the last value is repeated, and the cap never exceeds LINEAR_SOLVER_ITER. DEFAULT: 3 \ingroup Config*/ @@ -5142,7 +5142,7 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i MGOptions.MG_CflScaling[i] = (i < nMG_CflScaling_p) ? MG_CflScaling_p[i] : MG_CflScaling_p[nMG_CflScaling_p - 1]; } else { for (unsigned short i = 0; i < nMGLevels; ++i) - MGOptions.MG_CflScaling[i] = 0.25; + MGOptions.MG_CflScaling[i] = 0.5; } /*--- Linear solver iteration cap per level; level 0 always uses LINEAR_SOLVER_ITER. ---*/ diff --git a/TestCases/cont_adj_euler/wedge/of_grad_combo.dat.ref b/TestCases/cont_adj_euler/wedge/of_grad_combo.dat.ref index 916efa61b3cd..81fa5e5cfe00 100644 --- a/TestCases/cont_adj_euler/wedge/of_grad_combo.dat.ref +++ b/TestCases/cont_adj_euler/wedge/of_grad_combo.dat.ref @@ -1,5 +1,5 @@ VARIABLES="VARIABLE" , "GRADIENT" , "FINDIFF_STEP" - 0 , 0.00702689 , 0.0001 - 1 , 0.00485994 , 0.0001 - 2 , 0.0024459 , 0.0001 - 3 , 0.000872721 , 0.0001 + 0 , 0.00699944 , 0.0001 + 1 , 0.00484765 , 0.0001 + 2 , 0.00244252 , 0.0001 + 3 , 0.000872197 , 0.0001 diff --git a/TestCases/hybrid_regression.py b/TestCases/hybrid_regression.py index 21c63694f567..5bc1694f62ea 100644 --- a/TestCases/hybrid_regression.py +++ b/TestCases/hybrid_regression.py @@ -64,7 +64,7 @@ def main(): channel.cfg_dir = "euler/channel" channel.cfg_file = "inv_channel_RK.cfg" channel.test_iter = 20 - channel.test_vals = [3.601531, 0.116605, 0.168986, 1.000000] + channel.test_vals = [3.301777, 0.125985, 0.098809, 1.000000] test_list.append(channel) # NACA0012 @@ -72,7 +72,7 @@ def main(): naca0012.cfg_dir = "euler/naca0012" naca0012.cfg_file = "inv_NACA0012_Roe.cfg" naca0012.test_iter = 20 - naca0012.test_vals = [-4.029205, -3.521852, 0.272095, 0.009425] + naca0012.test_vals = [-4.561230, -3.981698, 0.297778, 0.026136] test_list.append(naca0012) # Supersonic wedge @@ -80,7 +80,7 @@ def main(): wedge.cfg_dir = "euler/wedge" wedge.cfg_file = "inv_wedge_HLLC.cfg" wedge.test_iter = 20 - wedge.test_vals = [-4.161881, 1.565415, -0.249526, 0.043953] + wedge.test_vals = [-4.160702, 1.568129, -0.249526, 0.043953] test_list.append(wedge) # ONERA M6 Wing @@ -88,7 +88,7 @@ def main(): oneram6.cfg_dir = "euler/oneram6" oneram6.cfg_file = "inv_ONERAM6.cfg" oneram6.test_iter = 10 - oneram6.test_vals = [0.277392, 0.006227] + oneram6.test_vals = [0.275457, 0.005917] test_list.append(oneram6) # Fixed CL NACA0012 @@ -96,7 +96,7 @@ def main(): fixedCL_naca0012.cfg_dir = "fixed_cl/naca0012" fixedCL_naca0012.cfg_file = "inv_NACA0012.cfg" fixedCL_naca0012.test_iter = 10 - fixedCL_naca0012.test_vals = [-3.943952, 1.585415, 0.300912, 0.019470] + fixedCL_naca0012.test_vals = [-3.890606, 1.641711, 0.300993, 0.019479] test_list.append(fixedCL_naca0012) # HYPERSONIC FLOW PAST BLUNT BODY @@ -116,7 +116,7 @@ def main(): flatplate.cfg_dir = "navierstokes/flatplate" flatplate.cfg_file = "lam_flatplate.cfg" flatplate.test_iter = 100 - flatplate.test_vals = [-8.265203, -2.790380, 0.001084, 0.036280, 2.361500, -2.325300, 0.000000, 0.000000] + flatplate.test_vals = [-9.050997, -3.573515, 0.001084, 0.036280, 2.361500, -2.325300, 0.000000, 0.000000] test_list.append(flatplate) # Laminar cylinder (steady) @@ -124,7 +124,7 @@ def main(): cylinder.cfg_dir = "navierstokes/cylinder" cylinder.cfg_file = "lam_cylinder.cfg" cylinder.test_iter = 25 - cylinder.test_vals = [-8.638753, -3.154563, 0.005584, 1.614194, 0.000000] + cylinder.test_vals = [-8.734576, -3.244748, -0.011923, 1.603493, 0.000000] test_list.append(cylinder) # Laminar cylinder (low Mach correction) @@ -132,7 +132,7 @@ def main(): cylinder_lowmach.cfg_dir = "navierstokes/cylinder" cylinder_lowmach.cfg_file = "cylinder_lowmach.cfg" cylinder_lowmach.test_iter = 25 - cylinder_lowmach.test_vals = [-8.730784, -3.268719, 0.318044, 1.770346, 0.000000] + cylinder_lowmach.test_vals = [-8.509047, -3.046622, 0.350589, 1.706592, 0.000000] cylinder_lowmach.test_vals_aarch64 = [-6.830996, -1.368850, -0.143956, 73.963354, 0] test_list.append(cylinder_lowmach) @@ -149,7 +149,7 @@ def main(): poiseuille_profile.cfg_dir = "navierstokes/poiseuille" poiseuille_profile.cfg_file = "profile_poiseuille.cfg" poiseuille_profile.test_iter = 10 - poiseuille_profile.test_vals = [-12.004080, -7.638116, -0.000000, 2.089953] + poiseuille_profile.test_vals = [-12.010770, -7.648389, -0.000000, 2.089953] poiseuille_profile.test_vals_aarch64 = [-12.004276, -7.636719, -0.000000, 2.089953] test_list.append(poiseuille_profile) @@ -170,7 +170,7 @@ def main(): rae2822_sa.cfg_dir = "rans/rae2822" rae2822_sa.cfg_file = "turb_SA_RAE2822.cfg" rae2822_sa.test_iter = 20 - rae2822_sa.test_vals = [-2.916839, -5.161263, 0.802145, 0.019586, 1000.000000] + rae2822_sa.test_vals = [-3.049836, -5.136050, 0.777961, 0.019531, 1000.000000] test_list.append(rae2822_sa) # RAE2822 SST @@ -178,7 +178,7 @@ def main(): rae2822_sst.cfg_dir = "rans/rae2822" rae2822_sst.cfg_file = "turb_SST_RAE2822.cfg" rae2822_sst.test_iter = 20 - rae2822_sst.test_vals = [-1.461774, 5.883885, 0.630267, 0.020404, 100.000000] + rae2822_sst.test_vals = [-1.369623, 5.889242, 0.632638, 0.019387, 100.000000] test_list.append(rae2822_sst) # RAE2822 SST_SUST @@ -186,7 +186,7 @@ def main(): rae2822_sst_sust.cfg_dir = "rans/rae2822" rae2822_sst_sust.cfg_file = "turb_SST_SUST_RAE2822.cfg" rae2822_sst_sust.test_iter = 20 - rae2822_sst_sust.test_vals = [-2.465534, 5.844290, 0.496763, 0.041047] + rae2822_sst_sust.test_vals = [-2.487953, 5.831332, 0.680095, 0.017768] test_list.append(rae2822_sst_sust) # Flat plate @@ -194,7 +194,7 @@ def main(): turb_flatplate.cfg_dir = "rans/flatplate" turb_flatplate.cfg_file = "turb_SA_flatplate.cfg" turb_flatplate.test_iter = 20 - turb_flatplate.test_vals = [-0.187373, 0.003723, 10.000000, -1.443902] + turb_flatplate.test_vals = [-0.187454, 0.003164, 10.000000, -1.844116] test_list.append(turb_flatplate) # ONERA M6 Wing @@ -279,7 +279,7 @@ def main(): turb_naca0012_sst_restart_mg.cfg_file = "turb_NACA0012_sst_multigrid_restart.cfg" turb_naca0012_sst_restart_mg.test_iter = 20 turb_naca0012_sst_restart_mg.ntest_vals = 5 - turb_naca0012_sst_restart_mg.test_vals = [-6.551665, -5.057150, 0.830240, -0.008811, 0.078187] + turb_naca0012_sst_restart_mg.test_vals = [-6.570032, -5.057151, 0.830239, -0.008807, 0.078143] test_list.append(turb_naca0012_sst_restart_mg) ############################# @@ -360,7 +360,7 @@ def main(): inc_euler_naca0012.cfg_dir = "incomp_euler/naca0012" inc_euler_naca0012.cfg_file = "incomp_NACA0012.cfg" inc_euler_naca0012.test_iter = 20 - inc_euler_naca0012.test_vals = [-6.668256, -5.851153, 0.531532, 0.008487] + inc_euler_naca0012.test_vals = [-6.911448, -6.089346, 0.531812, 0.008473] test_list.append(inc_euler_naca0012) # NACA0012 Hydrofoil, pressure-based. Exercises the OpenMP path of the Poisson @@ -403,7 +403,7 @@ def main(): inc_nozzle.cfg_dir = "incomp_euler/nozzle" inc_nozzle.cfg_file = "inv_nozzle.cfg" inc_nozzle.test_iter = 20 - inc_nozzle.test_vals = [-6.121917, -5.432144, 0.000056, 0.125551] + inc_nozzle.test_vals = [-6.335614, -5.591314, -0.026718, 0.126024] test_list.append(inc_nozzle) ############################# @@ -415,7 +415,7 @@ def main(): inc_lam_cylinder.cfg_dir = "incomp_navierstokes/cylinder" inc_lam_cylinder.cfg_file = "incomp_cylinder.cfg" inc_lam_cylinder.test_iter = 10 - inc_lam_cylinder.test_vals = [-4.814160, -5.008238, 0.001269, 3.114987] + inc_lam_cylinder.test_vals = [-4.806025, -4.879460, 0.003472, 3.111572] test_list.append(inc_lam_cylinder) # Buoyancy-driven cavity @@ -480,7 +480,7 @@ def main(): cavity.cfg_dir = "moving_wall/cavity" cavity.cfg_file = "lam_cavity.cfg" cavity.test_iter = 25 - cavity.test_vals = [-7.887109, -2.429088, 0.013598, 0.005372] + cavity.test_vals = [-8.105239, -2.649340, 0.011708, 0.007724] test_list.append(cavity) # Spinning cylinder @@ -488,7 +488,7 @@ def main(): spinning_cylinder.cfg_dir = "moving_wall/spinning_cylinder" spinning_cylinder.cfg_file = "spinning_cylinder.cfg" spinning_cylinder.test_iter = 25 - spinning_cylinder.test_vals = [-7.614070, -2.155206, 1.804022, 1.893004] + spinning_cylinder.test_vals = [-7.527408, -2.114712, 3.293156, 2.307064] spinning_cylinder.test_vals_aarch64 = [-8.008023, -2.611064, 1.497308, 1.487483] test_list.append(spinning_cylinder) @@ -510,7 +510,7 @@ def main(): sine_gust.cfg_dir = "gust" sine_gust.cfg_file = "inv_gust_NACA0012.cfg" sine_gust.test_iter = 5 - sine_gust.test_vals = [-1.977498, 3.481817, -0.010724, -0.005369] + sine_gust.test_vals = [-1.977498, 3.481817, -0.010741, -0.004763] sine_gust.unsteady = True test_list.append(sine_gust) @@ -539,7 +539,7 @@ def main(): aeroelastic.cfg_dir = "aeroelastic" aeroelastic.cfg_file = "aeroelastic_NACA64A010.cfg" aeroelastic.test_iter = 2 - aeroelastic.test_vals = [-1.876632, 4.021071, 0.080087, 0.027953, -0.001641, -0.000127, -1.052229] + aeroelastic.test_vals = [-1.876633, 4.021071, 0.080504, 0.027740, -0.001643, -0.000126, -1.133894] aeroelastic.unsteady = True aeroelastic.enabled_on_cpu_arch = ["x86_64"] # Requires AVX-capable architecture test_list.append(aeroelastic) @@ -567,7 +567,7 @@ def main(): unst_deforming_naca0012.cfg_dir = "disc_adj_euler/naca0012_pitching_def" unst_deforming_naca0012.cfg_file = "inv_NACA0012_pitching_deform.cfg" unst_deforming_naca0012.test_iter = 5 - unst_deforming_naca0012.test_vals = [-3.666867, -3.796806, -3.719022, -3.150288] + unst_deforming_naca0012.test_vals = [-3.665419, -3.794934, -3.717312, -3.148781] unst_deforming_naca0012.unsteady = True unst_deforming_naca0012.enabled_with_tsan = False test_list.append(unst_deforming_naca0012) @@ -580,8 +580,8 @@ def main(): edge_VW = TestCase('edge_VW') edge_VW.cfg_dir = "nicf/edge" edge_VW.cfg_file = "edge_VW.cfg" - edge_VW.test_iter = 25 - edge_VW.test_vals = [-11.723086, -5.536517, -0.000009, 0.000000] + edge_VW.test_iter = 20 + edge_VW.test_vals = [-11.087829, -4.888202, -0.000009, 0.000000] test_list.append(edge_VW) # Rarefaction shock wave edge_PPR @@ -589,7 +589,7 @@ def main(): edge_PPR.cfg_dir = "nicf/edge" edge_PPR.cfg_file = "edge_PPR.cfg" edge_PPR.test_iter = 20 - edge_PPR.test_vals = [-10.993286, -4.827527, -0.000034, 0.000000] + edge_PPR.test_vals = [-11.897441, -5.734478, -0.000034, 0.000000] edge_PPR.test_vals_aarch64 = [ -7.139211, -0.980821, -0.000034, 0.000000] test_list.append(edge_PPR) @@ -711,7 +711,7 @@ def main(): bars_SST_2D.cfg_dir = "sliding_interface/bars_SST_2D" bars_SST_2D.cfg_file = "bars.cfg" bars_SST_2D.test_iter = 13 - bars_SST_2D.test_vals = [13.000000, -0.455981, -1.541069] + bars_SST_2D.test_vals = [13.000000, -0.392000, -1.452625] bars_SST_2D.multizone = True test_list.append(bars_SST_2D) diff --git a/TestCases/parallel_regression.py b/TestCases/parallel_regression.py index 89bdeb0fe118..bd9e13a7fa1b 100755 --- a/TestCases/parallel_regression.py +++ b/TestCases/parallel_regression.py @@ -260,7 +260,7 @@ def main(): channel.cfg_dir = "euler/channel" channel.cfg_file = "inv_channel_RK.cfg" channel.test_iter = 20 - channel.test_vals = [3.612169, 0.104888, 0.172110, 1.000000] + channel.test_vals = [3.310505, 0.108396, 0.101621, 1.000000] test_list.append(channel) # NACA0012, native SU2 binary mesh format (.su2b) @@ -288,7 +288,7 @@ def main(): naca0012.cfg_dir = "euler/naca0012" naca0012.cfg_file = "inv_NACA0012_Roe_su2bin.cfg" naca0012.test_iter = 20 - naca0012.test_vals = [-4.024996, -3.520626, 0.275033, 0.009889] + naca0012.test_vals = [-4.543171, -3.970680, 0.298990, 0.025841] test_list.append(naca0012) # Supersonic wedge @@ -296,7 +296,7 @@ def main(): wedge.cfg_dir = "euler/wedge" wedge.cfg_file = "inv_wedge_HLLC.cfg" wedge.test_iter = 20 - wedge.test_vals = [-4.017956, 1.709065, -0.249527, 0.043953] + wedge.test_vals = [-4.068356, 1.661702, -0.249526, 0.043953] test_list.append(wedge) # ONERA M6 Wing @@ -304,7 +304,7 @@ def main(): oneram6.cfg_dir = "euler/oneram6" oneram6.cfg_file = "inv_ONERAM6.cfg" oneram6.test_iter = 10 - oneram6.test_vals = [-4.787340, -4.166981, 0.277687, 0.006533] + oneram6.test_vals = [-4.747714, -4.127329, 0.276470, 0.005884] oneram6.timeout = 3200 test_list.append(oneram6) @@ -313,7 +313,7 @@ def main(): fixedCL_naca0012.cfg_dir = "fixed_cl/naca0012" fixedCL_naca0012.cfg_file = "inv_NACA0012.cfg" fixedCL_naca0012.test_iter = 10 - fixedCL_naca0012.test_vals = [-3.887564, 1.642912, 0.300963, 0.019476] + fixedCL_naca0012.test_vals = [-3.881064, 1.650051, 0.300971, 0.019477] test_list.append(fixedCL_naca0012) # Polar sweep of the inviscid NACA0012 @@ -322,7 +322,7 @@ def main(): polar_naca0012.cfg_file = "inv_NACA0012.cfg" polar_naca0012.polar = True polar_naca0012.test_iter = 10 - polar_naca0012.test_vals = [-1.315882, 4.158313, 0.002698, 0.114644] + polar_naca0012.test_vals = [-1.254739, 4.196373, -0.000887, 0.083796] polar_naca0012.test_vals_aarch64 = [-1.083394, 4.386134, 0.001588, 0.033513] polar_naca0012.command = TestCase.Command(exec = "compute_polar.py", param = "-i 11") # flaky test on arm64 @@ -379,7 +379,7 @@ def main(): flatplate.cfg_dir = "navierstokes/flatplate" flatplate.cfg_file = "lam_flatplate.cfg" flatplate.test_iter = 100 - flatplate.test_vals = [-8.165135, -2.690978, 0.001084, 0.036277, 2.361500, -2.325300, 0.000000, 0.000000] + flatplate.test_vals = [-8.274411, -2.799354, 0.001084, 0.036279, 2.361500, -2.325300, 0.000000, 0.000000] test_list.append(flatplate) # Supersonic laminar flat plate @@ -412,7 +412,7 @@ def main(): cylinder.cfg_dir = "navierstokes/cylinder" cylinder.cfg_file = "lam_cylinder.cfg" cylinder.test_iter = 25 - cylinder.test_vals = [-8.557718, -3.072847, -0.018912, 1.610317, 0.000000] + cylinder.test_vals = [-8.587179, -3.100759, -0.015616, 1.610256, 0.000000] test_list.append(cylinder) # Laminar cylinder (low Mach correction) @@ -420,7 +420,7 @@ def main(): cylinder_lowmach.cfg_dir = "navierstokes/cylinder" cylinder_lowmach.cfg_file = "cylinder_lowmach.cfg" cylinder_lowmach.test_iter = 25 - cylinder_lowmach.test_vals = [-8.737675, -3.275569, 0.050297, 1.839111, 0.000000] + cylinder_lowmach.test_vals = [-8.538327, -3.075971, 0.118785, 1.723241, 0.000000] test_list.append(cylinder_lowmach) @@ -429,7 +429,7 @@ def main(): lam_naca0012_linelet.cfg_dir = "navierstokes/naca0012" lam_naca0012_linelet.cfg_file = "lam_NACA0012_LINELET.cfg" lam_naca0012_linelet.test_iter = 20 - lam_naca0012_linelet.test_vals = [-5.335764, -2.936176, -2.943918, 0.102456] + lam_naca0012_linelet.test_vals = [-5.384409, -2.896930, -2.972064, 0.147427] lam_naca0012_linelet.command = TestCase.Command("mpirun --oversubscribe -n 4", "SU2_CFD") test_list.append(lam_naca0012_linelet) @@ -447,7 +447,7 @@ def main(): poiseuille_profile.cfg_dir = "navierstokes/poiseuille" poiseuille_profile.cfg_file = "profile_poiseuille.cfg" poiseuille_profile.test_iter = 10 - poiseuille_profile.test_vals = [-12.003186, -7.623957, -0.000000, 2.089953] + poiseuille_profile.test_vals = [-12.010528, -7.640024, -0.000000, 2.089953] poiseuille_profile.test_vals_aarch64 = [-12.007498, -7.226926, -0.000000, 2.089953] poiseuille_profile.tol = [0.001, 0.001, 1e-5, 1e-5, 1e-5] test_list.append(poiseuille_profile) @@ -465,7 +465,7 @@ def main(): periodic2d_multigrid.cfg_dir = "navierstokes/periodic2D" periodic2d_multigrid.cfg_file = "multigrid.cfg" periodic2d_multigrid.test_iter = 300 - periodic2d_multigrid.test_vals = [-4.422778, -1.615251, -1.453736, 1.047350, -1.410225, -2060.600000] + periodic2d_multigrid.test_vals = [-5.338176, -2.795308, -2.414528, 0.120556, -1.314701, -2813.300000] test_list.append(periodic2d_multigrid) # 2D rotational periodic sector with limiter @@ -485,7 +485,7 @@ def main(): rae2822_sa.cfg_dir = "rans/rae2822" rae2822_sa.cfg_file = "turb_SA_RAE2822.cfg" rae2822_sa.test_iter = 20 - rae2822_sa.test_vals = [-3.030366, -5.142544, 0.790275, 0.019666, 1000.000000] + rae2822_sa.test_vals = [-3.006884, -5.132412, 0.788236, 0.019696, 1000.000000] test_list.append(rae2822_sa) # RAE2822 SST @@ -493,7 +493,7 @@ def main(): rae2822_sst.cfg_dir = "rans/rae2822" rae2822_sst.cfg_file = "turb_SST_RAE2822.cfg" rae2822_sst.test_iter = 20 - rae2822_sst.test_vals = [-1.485957, 5.891491, 0.675200, 0.023427, 100.000000] + rae2822_sst.test_vals = [-1.399619, 5.884460, 0.616355, 0.020132, 100.000000] test_list.append(rae2822_sst) # RAE2822 SST_SUST @@ -501,7 +501,7 @@ def main(): rae2822_sst_sust.cfg_dir = "rans/rae2822" rae2822_sst_sust.cfg_file = "turb_SST_SUST_RAE2822.cfg" rae2822_sst_sust.test_iter = 20 - rae2822_sst_sust.test_vals = [-2.465087, 5.851605, 0.496009, 0.041100] + rae2822_sst_sust.test_vals = [-2.490391, 5.829081, 0.681358, 0.017902] test_list.append(rae2822_sst_sust) # Flat plate @@ -509,7 +509,7 @@ def main(): turb_flatplate.cfg_dir = "rans/flatplate" turb_flatplate.cfg_file = "turb_SA_flatplate.cfg" turb_flatplate.test_iter = 20 - turb_flatplate.test_vals = [-0.187388, 0.003749, 10.000000, -1.406182] + turb_flatplate.test_vals = [-0.171203, 0.004017, 10.000000, -1.752822] test_list.append(turb_flatplate) # Flat plate (compressible) with species inlet @@ -517,7 +517,7 @@ def main(): turb_flatplate_species.cfg_dir = "rans/flatplate" turb_flatplate_species.cfg_file = "turb_SA_flatplate_species.cfg" turb_flatplate_species.test_iter = 20 - turb_flatplate_species.test_vals = [-5.359043, -1.881674, -3.075839, 0.124416, -3.602253, 2.000000, -1.239286, 1.000000, -1.158672, 3.000000, -0.849003, 0.999876, 0.999876] + turb_flatplate_species.test_vals = [-2.996137, -0.418684, -0.702492, 2.231474, -3.130507, 2.000000, -1.562193, 1.000000, -1.048237, 2.000000, -1.143723, 0.999580, 0.999580] test_list.append(turb_flatplate_species) # Flat plate SST compressibility correction Wilcox @@ -697,7 +697,7 @@ def main(): turb_naca0012_sst_restart_mg.cfg_file = "turb_NACA0012_sst_multigrid_restart.cfg" turb_naca0012_sst_restart_mg.test_iter = 20 turb_naca0012_sst_restart_mg.ntest_vals = 5 - turb_naca0012_sst_restart_mg.test_vals = [-6.560190, -5.057149, 0.830238, -0.008812, 0.078167] + turb_naca0012_sst_restart_mg.test_vals = [-6.576060, -5.057149, 0.830238, -0.008832, 0.078141] turb_naca0012_sst_restart_mg.timeout = 3200 turb_naca0012_sst_restart_mg.tol = 0.000001 test_list.append(turb_naca0012_sst_restart_mg) @@ -711,7 +711,7 @@ def main(): inc_euler_naca0012.cfg_dir = "incomp_euler/naca0012" inc_euler_naca0012.cfg_file = "incomp_NACA0012.cfg" inc_euler_naca0012.test_iter = 20 - inc_euler_naca0012.test_vals = [-6.920909, -6.189139, 0.531865, 0.008472] + inc_euler_naca0012.test_vals = [-6.911466, -6.188326, 0.531897, 0.008470] test_list.append(inc_euler_naca0012) # NACA0012 Hydrofoil @@ -735,7 +735,7 @@ def main(): inc_nozzle.cfg_dir = "incomp_euler/nozzle" inc_nozzle.cfg_file = "inv_nozzle.cfg" inc_nozzle.test_iter = 20 - inc_nozzle.test_vals = [-6.051005, -5.361765, 0.006999, 0.127295] + inc_nozzle.test_vals = [-6.192814, -5.483877, 0.006547, 0.126402] test_list.append(inc_nozzle) # Laminar wall mounted cylinder, Euler walls, cylinder wall diagonally split @@ -755,7 +755,7 @@ def main(): inc_lam_cylinder.cfg_dir = "incomp_navierstokes/cylinder" inc_lam_cylinder.cfg_file = "incomp_cylinder.cfg" inc_lam_cylinder.test_iter = 10 - inc_lam_cylinder.test_vals = [-4.816099, -5.029676, -0.000155, 3.113777] + inc_lam_cylinder.test_vals = [-4.808889, -4.846532, 0.001009, 3.110366] test_list.append(inc_lam_cylinder) # Laminar cylinder, pressure-based @@ -791,7 +791,7 @@ def main(): inc_lam_sphere.cfg_dir = "incomp_navierstokes/sphere" inc_lam_sphere.cfg_file = "sphere.cfg" inc_lam_sphere.test_iter = 5 - inc_lam_sphere.test_vals = [-7.599894, -8.023038, -8.135420, -8.783151, 0.121003, 25.782689, -1.574889] + inc_lam_sphere.test_vals = [-7.598349, -8.094328, -8.149899, -8.654136, 0.121002, 25.782692, -1.597724] test_list.append(inc_lam_sphere) # Laminar sphere, Re=1, pressure-based. Only 3D pressure-based case in the regression suite. @@ -971,7 +971,7 @@ def main(): turbmod_sa_bsl_rae2822.cfg_dir = "turbulence_models/sa/rae2822" turbmod_sa_bsl_rae2822.cfg_file = "turb_SA_BSL_RAE2822.cfg" turbmod_sa_bsl_rae2822.test_iter = 20 - turbmod_sa_bsl_rae2822.test_vals = [-3.062213, -0.409580, -0.834363, -5.133434, 0.790438, 0.018107] + turbmod_sa_bsl_rae2822.test_vals = [-3.095332, -0.396278, -0.802122, -5.121541, 0.779972, 0.017809] test_list.append(turbmod_sa_bsl_rae2822) # SA Negative @@ -988,7 +988,7 @@ def main(): turbmod_sa_comp_rae2822.cfg_dir = "turbulence_models/sa/rae2822" turbmod_sa_comp_rae2822.cfg_file = "turb_SA_COMP_RAE2822.cfg" turbmod_sa_comp_rae2822.test_iter = 20 - turbmod_sa_comp_rae2822.test_vals = [-3.063286, -0.408577, -0.834597, -5.159754, 0.790991, 0.018085] + turbmod_sa_comp_rae2822.test_vals = [-3.096581, -0.394990, -0.802385, -5.149198, 0.780649, 0.017786] test_list.append(turbmod_sa_comp_rae2822) # SA Edwards @@ -996,7 +996,7 @@ def main(): turbmod_sa_edw_rae2822.cfg_dir = "turbulence_models/sa/rae2822" turbmod_sa_edw_rae2822.cfg_file = "turb_SA_EDW_RAE2822.cfg" turbmod_sa_edw_rae2822.test_iter = 20 - turbmod_sa_edw_rae2822.test_vals = [-3.069523, -0.405788, -0.835321, -5.185709, 0.794436, 0.017856] + turbmod_sa_edw_rae2822.test_vals = [-3.132488, -0.361652, -0.802284, -4.867411, 0.800411, 0.017450] test_list.append(turbmod_sa_edw_rae2822) # SA Compressibility and Edwards @@ -1004,7 +1004,7 @@ def main(): turbmod_sa_comp_edw_rae2822.cfg_dir = "turbulence_models/sa/rae2822" turbmod_sa_comp_edw_rae2822.cfg_file = "turb_SA_COMP_EDW_RAE2822.cfg" turbmod_sa_comp_edw_rae2822.test_iter = 20 - turbmod_sa_comp_edw_rae2822.test_vals = [-3.067904, -0.338707, -0.811157, -5.279475, 0.809906, 0.019797] + turbmod_sa_comp_edw_rae2822.test_vals = [-3.082992, -0.347824, -0.796215, -5.283274, 0.800441, 0.019447] test_list.append(turbmod_sa_comp_edw_rae2822) # SA QCR @@ -1012,7 +1012,7 @@ def main(): turbmod_sa_qcr_rae2822.cfg_dir = "turbulence_models/sa/rae2822" turbmod_sa_qcr_rae2822.cfg_file = "turb_SA_QCR_RAE2822.cfg" turbmod_sa_qcr_rae2822.test_iter = 20 - turbmod_sa_qcr_rae2822.test_vals = [-3.028293, -0.418748, -0.797999, -5.088756, 0.761887, 0.016830] + turbmod_sa_qcr_rae2822.test_vals = [-3.077118, -0.443301, -0.826960, -5.072185, 0.780254, 0.017373] test_list.append(turbmod_sa_qcr_rae2822) ############################ @@ -1036,7 +1036,7 @@ def main(): contadj_naca0012.cfg_dir = "cont_adj_euler/naca0012" contadj_naca0012.cfg_file = "inv_NACA0012.cfg" contadj_naca0012.test_iter = 5 - contadj_naca0012.test_vals = [-9.547544, -15.069350, -0.726250, 0.020280] + contadj_naca0012.test_vals = [-9.528628, -15.088414, -0.726250, 0.020280] contadj_naca0012.test_vals_aarch64 = [-9.662546, -14.998818, -0.726250, 0.020280] test_list.append(contadj_naca0012) @@ -1045,7 +1045,7 @@ def main(): contadj_oneram6.cfg_dir = "cont_adj_euler/oneram6" contadj_oneram6.cfg_file = "inv_ONERAM6.cfg" contadj_oneram6.test_iter = 10 - contadj_oneram6.test_vals = [-12.085026, -12.651321, -1.086100, 0.007556] + contadj_oneram6.test_vals = [-12.029055, -12.586778, -1.086100, 0.007556] test_list.append(contadj_oneram6) # Inviscid WEDGE: tests averaged outflow total pressure adjoint @@ -1061,7 +1061,7 @@ def main(): contadj_fixed_CL_naca0012.cfg_dir = "fixed_cl/naca0012" contadj_fixed_CL_naca0012.cfg_file = "inv_NACA0012_ContAdj.cfg" contadj_fixed_CL_naca0012.test_iter = 100 - contadj_fixed_CL_naca0012.test_vals = [1.408903, -4.010709, 0.005808, 0.004028] + contadj_fixed_CL_naca0012.test_vals = [1.374798, -4.049551, 0.003812, 0.003544] test_list.append(contadj_fixed_CL_naca0012) ################################### @@ -1073,7 +1073,7 @@ def main(): contadj_ns_cylinder.cfg_dir = "cont_adj_navierstokes/cylinder" contadj_ns_cylinder.cfg_file = "lam_cylinder.cfg" contadj_ns_cylinder.test_iter = 20 - contadj_ns_cylinder.test_vals = [-3.626865, -9.079504, 2.056700, -0.000000] + contadj_ns_cylinder.test_vals = [-3.636183, -9.092363, 2.056700, -0.000000] test_list.append(contadj_ns_cylinder) # Adjoint laminar naca0012 subsonic @@ -1117,7 +1117,7 @@ def main(): contadj_rans_rae2822.cfg_dir = "cont_adj_rans/rae2822" contadj_rans_rae2822.cfg_file = "turb_SA_RAE2822.cfg" contadj_rans_rae2822.test_iter = 20 - contadj_rans_rae2822.test_vals = [-5.399270, -10.904277, -0.212470, 0.005448] + contadj_rans_rae2822.test_vals = [-5.400257, -10.905220, -0.212470, 0.005448] test_list.append(contadj_rans_rae2822) ############################# @@ -1197,7 +1197,7 @@ def main(): rot_naca0012.cfg_dir = "rotating/naca0012" rot_naca0012.cfg_file = "rot_NACA0012.cfg" rot_naca0012.test_iter = 25 - rot_naca0012.test_vals = [-0.023360, 0.082942, 2.000000, -1.182142] + rot_naca0012.test_vals = [-0.025558, 0.074675, 2.000000, -1.179395] test_list.append(rot_naca0012) # Lid-driven cavity @@ -1205,7 +1205,7 @@ def main(): cavity.cfg_dir = "moving_wall/cavity" cavity.cfg_file = "lam_cavity.cfg" cavity.test_iter = 25 - cavity.test_vals = [-7.770113, -2.308185, 0.011072, 0.008947] + cavity.test_vals = [-8.192883, -2.726835, 0.009911, 0.008952] test_list.append(cavity) # Spinning cylinder @@ -1213,7 +1213,7 @@ def main(): spinning_cylinder.cfg_dir = "moving_wall/spinning_cylinder" spinning_cylinder.cfg_file = "spinning_cylinder.cfg" spinning_cylinder.test_iter = 25 - spinning_cylinder.test_vals = [-7.471322, -2.007082, 2.183565, 1.847848] + spinning_cylinder.test_vals = [-7.497990, -2.042622, 3.055272, 2.100703] test_list.append(spinning_cylinder) ###################################### @@ -1247,7 +1247,7 @@ def main(): sine_gust.cfg_dir = "gust" sine_gust.cfg_file = "inv_gust_NACA0012.cfg" sine_gust.test_iter = 5 - sine_gust.test_vals = [-1.977498, 3.481817, -0.011360, -0.005241] + sine_gust.test_vals = [-1.977498, 3.481817, -0.011089, -0.004977] sine_gust.unsteady = True test_list.append(sine_gust) @@ -1298,7 +1298,7 @@ def main(): edge_VW.cfg_dir = "nicf/edge" edge_VW.cfg_file = "edge_VW.cfg" edge_VW.test_iter = 20 - edge_VW.test_vals = [-4.478306, 1.723006, -0.000009, 0.000000] + edge_VW.test_vals = [-11.161812, -4.959699, -0.000009, 0.000000] test_list.append(edge_VW) # Rarefaction shock wave edge_PPR @@ -1306,7 +1306,7 @@ def main(): edge_PPR.cfg_dir = "nicf/edge" edge_PPR.cfg_file = "edge_PPR.cfg" edge_PPR.test_iter = 20 - edge_PPR.test_vals = [-8.395110, -2.236894, -0.000034, 0.000000] + edge_PPR.test_vals = [-12.605332, -6.384486, -0.000034, 0.000000] test_list.append(edge_PPR) # Rarefaction Q1D nozzle, include CoolProp fluid model @@ -1345,7 +1345,7 @@ def main(): Aachen_3D_restart.cfg_file = "aachen_3D_MP_restart.cfg" Aachen_3D_restart.test_iter = 5 Aachen_3D_restart.tol = 0.00001 - Aachen_3D_restart.test_vals = [-7.688483, -8.466346, -6.035067, -6.425967, -5.820125, -4.597817, -5.528297, -5.301466, -3.819862, -5.242356, -5.738805, -3.630202, -2.213240, -2.857919, -0.576864] + Aachen_3D_restart.test_vals = [-7.689139, -8.447330, -6.048298, -6.408602, -5.833811, -4.582330, -5.531288, -5.312030, -3.828336, -5.244219, -5.787841, -3.645130, -2.211479, -2.863939, -0.584322] test_list.append(Aachen_3D_restart) # Jones APU Turbocharger restart @@ -1461,7 +1461,7 @@ def main(): bars_SST_2D.cfg_dir = "sliding_interface/bars_SST_2D" bars_SST_2D.cfg_file = "bars.cfg" bars_SST_2D.test_iter = 13 - bars_SST_2D.test_vals = [13.000000, -0.457912, -1.541047] + bars_SST_2D.test_vals = [13.000000, -0.391817, -1.452463] bars_SST_2D.multizone = True test_list.append(bars_SST_2D) diff --git a/TestCases/serial_regression.py b/TestCases/serial_regression.py index 1edd0378ab2a..9d47f56183a1 100755 --- a/TestCases/serial_regression.py +++ b/TestCases/serial_regression.py @@ -95,7 +95,7 @@ def main(): channel.cfg_dir = "euler/channel" channel.cfg_file = "inv_channel_RK.cfg" channel.test_iter = 10 - channel.test_vals = [-1.906687, 3.625653, -0.011054, 0.205254, 1.000000] + channel.test_vals = [-2.139147, 3.402856, 0.145706, 0.157472, 1.000000] test_list.append(channel) # NACA0012 @@ -103,7 +103,7 @@ def main(): naca0012.cfg_dir = "euler/naca0012" naca0012.cfg_file = "inv_NACA0012_Roe.cfg" naca0012.test_iter = 20 - naca0012.test_vals = [-4.031446, -3.524530, 0.273056, 0.009703] + naca0012.test_vals = [-4.561230, -3.981698, 0.297778, 0.026136] test_list.append(naca0012) # NACA0012 - FMG test @@ -111,7 +111,7 @@ def main(): naca0012_FMG.cfg_dir = "euler/naca0012" naca0012_FMG.cfg_file = "inv_NACA0012.cfg" naca0012_FMG.test_iter = 20 - naca0012_FMG.test_vals = [-4.160287, -3.553906, 0.296154, 0.016890] + naca0012_FMG.test_vals = [-4.106329, -3.503613, 0.275898, 0.015045] test_list.append(naca0012_FMG) # Supersonic wedge @@ -119,7 +119,7 @@ def main(): wedge.cfg_dir = "euler/wedge" wedge.cfg_file = "inv_wedge_HLLC.cfg" wedge.test_iter = 20 - wedge.test_vals = [-4.350066, 1.379784, -0.249526, 0.043953] + wedge.test_vals = [-4.160702, 1.568129, -0.249526, 0.043953] test_list.append(wedge) # ONERA M6 Wing @@ -127,7 +127,7 @@ def main(): oneram6.cfg_dir = "euler/oneram6" oneram6.cfg_file = "inv_ONERAM6.cfg" oneram6.test_iter = 10 - oneram6.test_vals = [-4.825509, -4.205271, 0.277086, 0.006619] + oneram6.test_vals = [-4.788523, -4.167974, 0.275457, 0.005917] oneram6.timeout = 9600 test_list.append(oneram6) @@ -136,7 +136,7 @@ def main(): fixedCL_naca0012.cfg_dir = "fixed_cl/naca0012" fixedCL_naca0012.cfg_file = "inv_NACA0012.cfg" fixedCL_naca0012.test_iter = 10 - fixedCL_naca0012.test_vals = [-3.886939, 1.644825, 0.300989, 0.019478] + fixedCL_naca0012.test_vals = [-3.890606, 1.641711, 0.300993, 0.019479] test_list.append(fixedCL_naca0012) # Polar sweep of the inviscid NACA0012 @@ -145,7 +145,7 @@ def main(): polar_naca0012.cfg_file = "inv_NACA0012.cfg" polar_naca0012.polar = True polar_naca0012.test_iter = 10 - polar_naca0012.test_vals = [-1.311796, 4.165508, 0.000092, 0.113306] + polar_naca0012.test_vals = [-1.250300, 4.202693, -0.002051, 0.082397] polar_naca0012.test_vals_aarch64 = [-1.063447, 4.401847, 0.000291, 0.031696] polar_naca0012.command = TestCase.Command(exec = "compute_polar.py", param = "-n 1 -i 11") # flaky test on arm64 @@ -176,7 +176,7 @@ def main(): flatplate.cfg_dir = "navierstokes/flatplate" flatplate.cfg_file = "lam_flatplate.cfg" flatplate.test_iter = 20 - flatplate.test_vals = [-5.623336, -0.144687, 0.001202, 0.028141, 2.361500, -2.333400, 0.000000, 0.000000] + flatplate.test_vals = [-5.694328, -0.217472, 0.001137, 0.030115, 2.361500, -2.331400, 0.000000, 0.000000] test_list.append(flatplate) # Laminar cylinder (steady) @@ -184,7 +184,7 @@ def main(): cylinder.cfg_dir = "navierstokes/cylinder" cylinder.cfg_file = "lam_cylinder.cfg" cylinder.test_iter = 25 - cylinder.test_vals = [-8.725171, -3.234867, -0.028017, 1.605526, 0.000000] + cylinder.test_vals = [-8.734576, -3.244748, -0.011923, 1.603493, 0.000000] test_list.append(cylinder) # Laminar cylinder (low Mach correction) @@ -192,7 +192,7 @@ def main(): cylinder_lowmach.cfg_dir = "navierstokes/cylinder" cylinder_lowmach.cfg_file = "cylinder_lowmach.cfg" cylinder_lowmach.test_iter = 25 - cylinder_lowmach.test_vals = [-8.698687, -3.236566, 0.401347, 1.754864, 0.000000] + cylinder_lowmach.test_vals = [-8.509047, -3.046622, 0.350589, 1.706592, 0.000000] test_list.append(cylinder_lowmach) # Laminar NACA0012 with linelet preconditioner (see #2877) @@ -200,7 +200,7 @@ def main(): lam_naca0012_linelet.cfg_dir = "navierstokes/naca0012" lam_naca0012_linelet.cfg_file = "lam_NACA0012_LINELET.cfg" lam_naca0012_linelet.test_iter = 20 - lam_naca0012_linelet.test_vals = [-5.345007, -2.936878, -2.943454, 0.096356] + lam_naca0012_linelet.test_vals = [-5.451331, -2.920403, -3.069534, 0.254143] test_list.append(lam_naca0012_linelet) # 2D Poiseuille flow (body force driven with periodic inlet / outlet) @@ -216,7 +216,7 @@ def main(): poiseuille_profile.cfg_dir = "navierstokes/poiseuille" poiseuille_profile.cfg_file = "profile_poiseuille.cfg" poiseuille_profile.test_iter = 10 - poiseuille_profile.test_vals = [-12.003115, -7.626023, -0.000000, 2.089953] + poiseuille_profile.test_vals = [-12.010770, -7.648389, -0.000000, 2.089953] poiseuille_profile.test_vals_aarch64 = [-12.009012, -7.262299, -0.000000, 2.089953] #last 4 columns test_list.append(poiseuille_profile) @@ -236,7 +236,7 @@ def main(): rae2822_sa.cfg_dir = "rans/rae2822" rae2822_sa.cfg_file = "turb_SA_RAE2822.cfg" rae2822_sa.test_iter = 20 - rae2822_sa.test_vals = [-3.117674, -5.153287, 0.777070, 0.019412, 1000.000000] + rae2822_sa.test_vals = [-3.049836, -5.136050, 0.777961, 0.019531, 1000.000000] test_list.append(rae2822_sa) # RAE2822 SST @@ -244,7 +244,7 @@ def main(): rae2822_sst.cfg_dir = "rans/rae2822" rae2822_sst.cfg_file = "turb_SST_RAE2822.cfg" rae2822_sst.test_iter = 20 - rae2822_sst.test_vals = [-1.916371, -1.461911, 5.894621, 0.611793, 0.016873, 100.000000] + rae2822_sst.test_vals = [-1.899720, -1.369623, 5.889242, 0.632638, 0.019387, 100.000000] test_list.append(rae2822_sst) # RAE2822 SST_SUST @@ -252,7 +252,7 @@ def main(): rae2822_sst_sust.cfg_dir = "rans/rae2822" rae2822_sst_sust.cfg_file = "turb_SST_SUST_RAE2822.cfg" rae2822_sst_sust.test_iter = 20 - rae2822_sst_sust.test_vals = [-2.464309, 5.852571, 0.490309, 0.042519] + rae2822_sst_sust.test_vals = [-2.487953, 5.831332, 0.680095, 0.017768] test_list.append(rae2822_sst_sust) # Flat plate @@ -260,7 +260,7 @@ def main(): turb_flatplate.cfg_dir = "rans/flatplate" turb_flatplate.cfg_file = "turb_SA_flatplate.cfg" turb_flatplate.test_iter = 20 - turb_flatplate.test_vals = [-5.286997, -6.483481, -0.187358, 0.003712, 10.000000, -2.181754] + turb_flatplate.test_vals = [-2.770068, -6.060857, -0.187454, 0.003164, 10.000000, -1.844116] test_list.append(turb_flatplate) # FLAT PLATE, WALL FUNCTIONS, COMPRESSIBLE SST @@ -385,7 +385,7 @@ def main(): axi_rans_air_nozzle_species.cfg_dir = "axisymmetric_rans/air_nozzle" axi_rans_air_nozzle_species.cfg_file = "air_nozzle_species.cfg" axi_rans_air_nozzle_species.test_iter = 10 - axi_rans_air_nozzle_species.test_vals = [-2.243181, 3.273075, -1.958732, 5.883857, -2.469621, 0.000000] + axi_rans_air_nozzle_species.test_vals = [-2.059329, 3.434529, -1.964673, 5.890841, -2.454023, 0.000000] axi_rans_air_nozzle_species.tol = 0.0001 test_list.append(axi_rans_air_nozzle_species) @@ -399,7 +399,7 @@ def main(): turb_naca0012_sst_restart_mg.cfg_file = "turb_NACA0012_sst_multigrid_restart.cfg" turb_naca0012_sst_restart_mg.test_iter = 50 turb_naca0012_sst_restart_mg.ntest_vals = 5 - turb_naca0012_sst_restart_mg.test_vals = [-6.570974, -5.081421, 0.810883, -0.008830, 0.077967] + turb_naca0012_sst_restart_mg.test_vals = [-6.627630, -5.081422, 0.810881, -0.008830, 0.077937] turb_naca0012_sst_restart_mg.timeout = 3200 turb_naca0012_sst_restart_mg.tol = 0.000001 test_list.append(turb_naca0012_sst_restart_mg) @@ -420,7 +420,7 @@ def main(): inc_euler_naca0012.cfg_dir = "incomp_euler/naca0012" inc_euler_naca0012.cfg_file = "incomp_NACA0012.cfg" inc_euler_naca0012.test_iter = 20 - inc_euler_naca0012.test_vals = [-6.814482, -6.001232, 0.531760, 0.008476] + inc_euler_naca0012.test_vals = [-6.911448, -6.089346, 0.531812, 0.008473] test_list.append(inc_euler_naca0012) # NACA0012 Hydrofoil, pressure-based @@ -436,7 +436,7 @@ def main(): inc_nozzle.cfg_dir = "incomp_euler/nozzle" inc_nozzle.cfg_file = "inv_nozzle.cfg" inc_nozzle.test_iter = 20 - inc_nozzle.test_vals = [-6.331969, -5.586818, -0.024387, 0.126306] + inc_nozzle.test_vals = [-6.335614, -5.591314, -0.026718, 0.126024] test_list.append(inc_nozzle) ############################# @@ -455,7 +455,7 @@ def main(): inc_lam_cylinder.cfg_dir = "incomp_navierstokes/cylinder" inc_lam_cylinder.cfg_file = "incomp_cylinder.cfg" inc_lam_cylinder.test_iter = 10 - inc_lam_cylinder.test_vals = [-4.809141, -5.026921, 0.000880, 3.118344] + inc_lam_cylinder.test_vals = [-4.806025, -4.879460, 0.003472, 3.111572] test_list.append(inc_lam_cylinder) # Laminar cylinder, pressure-based @@ -652,7 +652,7 @@ def main(): contadj_naca0012.cfg_dir = "cont_adj_euler/naca0012" contadj_naca0012.cfg_file = "inv_NACA0012.cfg" contadj_naca0012.test_iter = 5 - contadj_naca0012.test_vals = [-9.552105, -15.069398, -0.726250, 0.020280] + contadj_naca0012.test_vals = [-9.539894, -15.090678, -0.726250, 0.020280] contadj_naca0012.tol = 0.001 test_list.append(contadj_naca0012) @@ -661,7 +661,7 @@ def main(): contadj_oneram6.cfg_dir = "cont_adj_euler/oneram6" contadj_oneram6.cfg_file = "inv_ONERAM6.cfg" contadj_oneram6.test_iter = 10 - contadj_oneram6.test_vals = [-12.083324, -12.644564, -1.086100, 0.007556] + contadj_oneram6.test_vals = [-12.028731, -12.585757, -1.086100, 0.007556] test_list.append(contadj_oneram6) # Inviscid WEDGE: tests averaged outflow total pressure adjoint @@ -677,7 +677,7 @@ def main(): contadj_fixedCL_naca0012.cfg_dir = "fixed_cl/naca0012" contadj_fixedCL_naca0012.cfg_file = "inv_NACA0012_ContAdj.cfg" contadj_fixedCL_naca0012.test_iter = 100 - contadj_fixedCL_naca0012.test_vals = [1.409148, -4.006889, -0.025392, 0.004170] + contadj_fixedCL_naca0012.test_vals = [1.375481, -4.047324, -0.026869, 0.003641] test_list.append(contadj_fixedCL_naca0012) ################################### @@ -696,7 +696,7 @@ def main(): contadj_ns_cylinder.cfg_dir = "cont_adj_navierstokes/cylinder" contadj_ns_cylinder.cfg_file = "lam_cylinder.cfg" contadj_ns_cylinder.test_iter = 20 - contadj_ns_cylinder.test_vals = [-3.634026, -9.089553, 2.056700, -0.000000] + contadj_ns_cylinder.test_vals = [-3.633957, -9.089467, 2.056700, -0.000000] test_list.append(contadj_ns_cylinder) # Adjoint laminar naca0012 subsonic @@ -740,7 +740,7 @@ def main(): contadj_rans_rae2822.cfg_dir = "cont_adj_rans/rae2822" contadj_rans_rae2822.cfg_file = "turb_SA_RAE2822.cfg" contadj_rans_rae2822.test_iter = 20 - contadj_rans_rae2822.test_vals = [-5.399078, -10.904106, -0.212470, 0.005448] + contadj_rans_rae2822.test_vals = [-5.400074, -10.904964, -0.212470, 0.005448] test_list.append(contadj_rans_rae2822) ############################# @@ -818,7 +818,7 @@ def main(): rot_naca0012.cfg_dir = "rotating/naca0012" rot_naca0012.cfg_file = "rot_NACA0012.cfg" rot_naca0012.test_iter = 25 - rot_naca0012.test_vals = [-1.240352, 4.268727, -0.022164, 0.083891, 2.000000, -1.253214] + rot_naca0012.test_vals = [-1.260639, 4.246907, -0.025466, 0.076618, 2.000000, -1.267106] test_list.append(rot_naca0012) # Lid-driven cavity @@ -826,7 +826,7 @@ def main(): cavity.cfg_dir = "moving_wall/cavity" cavity.cfg_file = "lam_cavity.cfg" cavity.test_iter = 25 - cavity.test_vals = [-8.032742, -2.589249, 0.015257, 0.007688] + cavity.test_vals = [-8.105239, -2.649340, 0.011708, 0.007724] test_list.append(cavity) # Spinning cylinder @@ -834,7 +834,7 @@ def main(): spinning_cylinder.cfg_dir = "moving_wall/spinning_cylinder" spinning_cylinder.cfg_file = "spinning_cylinder.cfg" spinning_cylinder.test_iter = 25 - spinning_cylinder.test_vals = [-7.634797, -2.176937, 1.860210, 1.939647] + spinning_cylinder.test_vals = [-7.527408, -2.114712, 3.293156, 2.307064] test_list.append(spinning_cylinder) ###################################### @@ -855,7 +855,7 @@ def main(): sine_gust.cfg_dir = "gust" sine_gust.cfg_file = "inv_gust_NACA0012.cfg" sine_gust.test_iter = 5 - sine_gust.test_vals = [-1.977498, 3.481817, -0.010871, -0.005083] + sine_gust.test_vals = [-1.977498, 3.481817, -0.010741, -0.004763] sine_gust.unsteady = True test_list.append(sine_gust) @@ -864,7 +864,7 @@ def main(): aeroelastic.cfg_dir = "aeroelastic" aeroelastic.cfg_file = "aeroelastic_NACA64A010.cfg" aeroelastic.test_iter = 2 - aeroelastic.test_vals = [-1.876632, 4.021072, 0.080240, 0.027935, -0.001641, -0.000127, -1.133898] + aeroelastic.test_vals = [-1.876633, 4.021071, 0.080504, 0.027740, -0.001643, -0.000126, -1.133894] aeroelastic.unsteady = True test_list.append(aeroelastic) @@ -890,7 +890,7 @@ def main(): unst_pitching_naca64a010_rans.cfg_dir = "unsteady/pitching_naca64a010_rans" unst_pitching_naca64a010_rans.cfg_file = "turb_NACA64A010.cfg" unst_pitching_naca64a010_rans.test_iter = 2 - unst_pitching_naca64a010_rans.test_vals = [-1.299045, -3.951331, 0.011098, 0.008241] + unst_pitching_naca64a010_rans.test_vals = [-1.299045, -3.951348, 0.010378, 0.008239] unst_pitching_naca64a010_rans.unsteady = True test_list.append(unst_pitching_naca64a010_rans) # unsteady pitching NACA64A010, Euler @@ -898,7 +898,7 @@ def main(): unst_pitching_naca64a010_euler.cfg_dir = "unsteady/pitching_naca64a010_euler" unst_pitching_naca64a010_euler.cfg_file = "pitching_NACA64A010.cfg" unst_pitching_naca64a010_euler.test_iter = 2 - unst_pitching_naca64a010_euler.test_vals = [-1.186839, 4.280301, -0.039724, 0.000927] + unst_pitching_naca64a010_euler.test_vals = [-1.186839, 4.280301, -0.039611, 0.000918] unst_pitching_naca64a010_euler.unsteady = True test_list.append(unst_pitching_naca64a010_euler) # unsteady plunging NACA0012, Laminar NS @@ -906,7 +906,7 @@ def main(): unst_plunging_naca0012.cfg_dir = "unsteady/plunging_naca0012" unst_plunging_naca0012.cfg_file = "plunging_NACA0012.cfg" unst_plunging_naca0012.test_iter = 2 - unst_plunging_naca0012.test_vals = [-4.083462, 1.366757, -3.455802, -0.097062] + unst_plunging_naca0012.test_vals = [-4.083462, 1.366757, -3.714511, -0.094441] unst_plunging_naca0012.unsteady = True test_list.append(unst_plunging_naca0012) @@ -915,7 +915,7 @@ def main(): unst_deforming_naca0012.cfg_dir = "disc_adj_euler/naca0012_pitching_def" unst_deforming_naca0012.cfg_file = "inv_NACA0012_pitching_deform.cfg" unst_deforming_naca0012.test_iter = 5 - unst_deforming_naca0012.test_vals = [-3.667005, -3.796733, -3.719112, -3.150401] + unst_deforming_naca0012.test_vals = [-3.665419, -3.794934, -3.717312, -3.148781] unst_deforming_naca0012.unsteady = True test_list.append(unst_deforming_naca0012) @@ -928,7 +928,7 @@ def main(): ls89_sa.cfg_dir = "nicf/LS89" ls89_sa.cfg_file = "turb_SA_PR.cfg" ls89_sa.test_iter = 20 - ls89_sa.test_vals = [-5.041500, -13.379523, 0.179019, 0.420831] + ls89_sa.test_vals = [-5.232898, -13.598271, 0.191102, 0.404327] test_list.append(ls89_sa) # Rarefaction shock wave edge_VW @@ -936,7 +936,7 @@ def main(): edge_VW.cfg_dir = "nicf/edge" edge_VW.cfg_file = "edge_VW.cfg" edge_VW.test_iter = 20 - edge_VW.test_vals = [-8.901513, -2.707051, -0.000009, 0.000000] + edge_VW.test_vals = [-11.087829, -4.888202, -0.000009, 0.000000] test_list.append(edge_VW) # Rarefaction shock wave edge_PPR @@ -944,7 +944,7 @@ def main(): edge_PPR.cfg_dir = "nicf/edge" edge_PPR.cfg_file = "edge_PPR.cfg" edge_PPR.test_iter = 20 - edge_PPR.test_vals = [-12.051551, -5.877885, -0.000034, 0.000000] + edge_PPR.test_vals = [-11.897441, -5.734478, -0.000034, 0.000000] test_list.append(edge_PPR) @@ -957,7 +957,7 @@ def main(): Aachen_3D_restart.cfg_dir = "turbomachinery/Aachen_turbine" Aachen_3D_restart.cfg_file = "aachen_3D_MP_restart.cfg" Aachen_3D_restart.test_iter = 5 - Aachen_3D_restart.test_vals = [-7.689117, -8.476204, -6.036107, -6.427402, -5.831576, -4.599024, -5.530512, -5.305687, -3.821789, -5.243255, -5.754831, -3.631603, -2.213934, -2.895728, -0.578545] + Aachen_3D_restart.test_vals = [-7.691302, -8.448210, -6.054535, -6.412618, -5.832815, -4.591915, -5.534112, -5.313788, -3.835936, -5.246568, -5.792765, -3.651537, -2.214624, -2.878670, -0.593562] Aachen_3D_restart.enabled_with_asan = False test_list.append(Aachen_3D_restart) @@ -1086,7 +1086,7 @@ def main(): bars_SST_2D.cfg_dir = "sliding_interface/bars_SST_2D" bars_SST_2D.cfg_file = "bars.cfg" bars_SST_2D.test_iter = 13 - bars_SST_2D.test_vals = [13.000000, -0.456143, -1.541051] + bars_SST_2D.test_vals = [13.000000, -0.392000, -1.452625] bars_SST_2D.multizone = True test_list.append(bars_SST_2D) @@ -1593,7 +1593,7 @@ def main(): shape_opt_euler_py.cfg_dir = "optimization_euler/steady_naca0012" shape_opt_euler_py.cfg_file = "inv_NACA0012_adv.cfg" shape_opt_euler_py.test_iter = 1 - shape_opt_euler_py.test_vals = [1.000000, 1.000000, 0.000021, 0.003642] + shape_opt_euler_py.test_vals = [1.000000, 2.000000, 0.000013, 0.003642] shape_opt_euler_py.command = TestCase.Command(exec = "shape_optimization.py", param = "-g CONTINUOUS_ADJOINT -f") shape_opt_euler_py.timeout = 1600 shape_opt_euler_py.tol = 0.00001 @@ -1645,7 +1645,7 @@ def main(): opt_multiobj1surf_py.cfg_dir = "optimization_euler/multiobjective_wedge" opt_multiobj1surf_py.cfg_file = "inv_wedge_ROE_multiobj_1surf.cfg" opt_multiobj1surf_py.test_iter = 1 - opt_multiobj1surf_py.test_vals = [1.000000, 1.000000, 36.586730, 5.593636] + opt_multiobj1surf_py.test_vals = [1.000000, 2.000000, 12.125690, 5.935074] opt_multiobj1surf_py.command = TestCase.Command(exec = "shape_optimization.py", param = "-g CONTINUOUS_ADJOINT -f") opt_multiobj1surf_py.timeout = 1600 opt_multiobj1surf_py.tol = 0.00001 @@ -1658,7 +1658,7 @@ def main(): opt_2surf1obj_py.cfg_dir = "optimization_euler/multiobjective_wedge" opt_2surf1obj_py.cfg_file = "inv_wedge_ROE_2surf_1obj.cfg" opt_2surf1obj_py.test_iter = 1 - opt_2surf1obj_py.test_vals = [1.000000, 1.000000, 2.005039, 0.000462] + opt_2surf1obj_py.test_vals = [1.000000, 1.000000, 2.005580, 0.000531] opt_2surf1obj_py.command = TestCase.Command(exec = "shape_optimization.py", param = "-g CONTINUOUS_ADJOINT -f") opt_2surf1obj_py.timeout = 1600 opt_2surf1obj_py.tol = 0.00001 @@ -1675,7 +1675,7 @@ def main(): pywrapper_naca0012.cfg_dir = "euler/naca0012" pywrapper_naca0012.cfg_file = "inv_NACA0012_Roe.cfg" pywrapper_naca0012.test_iter = 20 - pywrapper_naca0012.test_vals = [-4.031446, -3.524530, 0.273056, 0.009703] + pywrapper_naca0012.test_vals = [-4.489721, -3.937702, 0.293347, 0.025228] pywrapper_naca0012.command = TestCase.Command(exec = "SU2_CFD.py", param = "-f") pywrapper_naca0012.timeout = 1600 pywrapper_naca0012.tol = 0.00001 @@ -1731,7 +1731,7 @@ def main(): pywrapper_unsteadyCHT.cfg_dir = "py_wrapper/flatPlate_unsteady_CHT" pywrapper_unsteadyCHT.cfg_file = "unsteady_CHT_FlatPlate_Conf.cfg" pywrapper_unsteadyCHT.test_iter = 5 - pywrapper_unsteadyCHT.test_vals = [-1.614168, 2.259817, -0.009951, 0.169563] + pywrapper_unsteadyCHT.test_vals = [-1.614169, 2.260215, -0.019432, 0.203751] pywrapper_unsteadyCHT.command = TestCase.Command(exec = "python", param = "launch_unsteady_CHT_FlatPlate.py -f") pywrapper_unsteadyCHT.timeout = 1600 pywrapper_unsteadyCHT.tol = 0.00001 diff --git a/config_template.cfg b/config_template.cfg index a4ff3cf86fa3..3062c4c78085 100644 --- a/config_template.cfg +++ b/config_template.cfg @@ -1864,8 +1864,8 @@ MG_IMPLICIT_LINES= NO % % Per-level CFL scaling factors for the coarse multigrid levels. Entry i is the ratio % CFL(i+1)/CFL(i). If fewer values than MGLEVEL are given the last one is repeated -% (default 0.25, i.e. a quarter of the CFL per level) -MG_CFL_SCALING= ( 0.25 ) +% (default 0.5, i.e. half the CFL per level) +MG_CFL_SCALING= ( 0.5 ) % % Number of iterations spent on each mesh during the Full Multigrid (FMG) startup phase. After % this many iterations the solution is prolongated to the next finer mesh. It is also the length From 83152eaff9c19334418ababacc1e5fbf52369ca1 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Mon, 16 Nov 2026 19:41:53 +0100 Subject: [PATCH 30/42] Fix the open CodeQL findings - CEulerSolver: the wall-end loops no longer redeclare iMarker. - CSysMatrix: LevelProgress gets a copy assignment to match its copy constructor. - CDriver, CMultiGridIntegration: the owner of a reduced maximum is found with >= instead of ==, and the NaN test uses std::isnan. Co-Authored-By: Claude Fable 5.2 --- Common/include/linear_algebra/CSysMatrix.hpp | 4 ++++ SU2_CFD/src/drivers/CDriver.cpp | 2 +- .../src/integration/CMultiGridIntegration.cpp | 5 +++-- SU2_CFD/src/solvers/CEulerSolver.cpp | 16 ++++++++-------- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Common/include/linear_algebra/CSysMatrix.hpp b/Common/include/linear_algebra/CSysMatrix.hpp index cccbbeb03a08..a02829351330 100644 --- a/Common/include/linear_algebra/CSysMatrix.hpp +++ b/Common/include/linear_algebra/CSysMatrix.hpp @@ -369,6 +369,10 @@ class CSysMatrix { std::atomic steps{0}; LevelProgress() = default; LevelProgress(const LevelProgress& other) : steps(other.steps.load()) {} + LevelProgress& operator=(const LevelProgress& other) { + steps.store(other.steps.load()); + return *this; + } }; /*!< \brief Steps each thread must see completed by every other thread, per (step, thread, other thread), diff --git a/SU2_CFD/src/drivers/CDriver.cpp b/SU2_CFD/src/drivers/CDriver.cpp index 969e84b00fa0..253e7f7c4f8f 100644 --- a/SU2_CFD/src/drivers/CDriver.cpp +++ b/SU2_CFD/src/drivers/CDriver.cpp @@ -870,7 +870,7 @@ void CDriver::InitializeGeometryFVM(CConfig *config, CGeometry **&geometry) { cout << " MG level " << iLevel << " CV closure: " << nBadGlobal << " CVs with a face normal sum above 1e-6 of the " << "face area, worst " << worstGlobal << "\n"; } - if ((worst == worstGlobal) && (worst > 1e-6)) { + if ((worst >= worstGlobal) && (worst > 1e-6)) { cout << " MG level " << iLevel << " worst closure on rank " << rank << ", global point " << grid->nodes->GetGlobalIndex(worstPoint) << ", volume " << grid->nodes->GetVolume(worstPoint) << ", " << grid->nodes->GetnPoint(worstPoint) << " neighbors, x ="; diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index a56e4438b0c3..2bc3983fc382 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -30,6 +30,7 @@ #include "../../../Common/include/toolboxes/printing_toolbox.hpp" #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" #include +#include #include #include "../../include/variables/CEulerVariable.hpp" @@ -1398,7 +1399,7 @@ void CMultiGridIntegration::SmoothProlongated_Correction(unsigned short RunTime_ } SU2_MPI::Allreduce(&local[0], &global[0], 1, MPI_DOUBLE, MPI_MAX, SU2_MPI::GetComm()); SU2_MPI::Allreduce(&local[1], &global[1], 1, MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm()); - if ((local[0] == global[0]) && (global[0] > peakShare * global[1])) { + if ((local[0] >= global[0]) && (global[0] > peakShare * global[1])) { std::cout << "Corr-peak level " << iMesh << ": rank " << SU2_MPI::GetRank() << ", global point " << geometry->nodes->GetGlobalIndex(peakPoint) << ", " << 100 * global[0] / global[1] << "% of the correction norm, volume " << geometry->nodes->GetVolume(peakPoint) << ", " @@ -1569,7 +1570,7 @@ void CMultiGridIntegration::SetProlongated_Correction(CSolver *sol_fine, CSolver /*--- Prevent a fine grid divergence due to a coarse grid divergence ---*/ for (auto iVar = 0u; iVar < nVar; iVar++) - if (Residual_Fine[iVar] != Residual_Fine[iVar]) Residual_Fine[iVar] = 0.0; + if (std::isnan(SU2_TYPE::GetValue(Residual_Fine[iVar]))) Residual_Fine[iVar] = 0.0; su2double relax = factor; if ((iMesh < correctionWeight.size()) && !correctionWeight[iMesh].empty()) relax *= correctionWeight[iMesh][Point_Fine]; diff --git a/SU2_CFD/src/solvers/CEulerSolver.cpp b/SU2_CFD/src/solvers/CEulerSolver.cpp index 9082249183bd..68c6babf023b 100644 --- a/SU2_CFD/src/solvers/CEulerSolver.cpp +++ b/SU2_CFD/src/solvers/CEulerSolver.cpp @@ -360,14 +360,14 @@ CEulerSolver::CEulerSolver(CGeometry *geometry, CConfig *config, su2double wallNormal[MAXNDIM] = {0.0}; unitNormal(iWall, wallVertex, wallNormal); - for (unsigned short iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++) { - const auto kindBC = config->GetMarker_All_KindBC(iMarker); - if (config->GetViscous_Wall(iMarker) || (kindBC == SEND_RECEIVE) || (kindBC == PERIODIC_BOUNDARY) || + for (unsigned short jMarker = 0; jMarker < config->GetnMarker_All(); jMarker++) { + const auto kindBC = config->GetMarker_All_KindBC(jMarker); + if (config->GetViscous_Wall(jMarker) || (kindBC == SEND_RECEIVE) || (kindBC == PERIODIC_BOUNDARY) || (kindBC == INTERNAL_BOUNDARY) || (kindBC == NEARFIELD_BOUNDARY) || (kindBC == FLUID_INTERFACE)) continue; - const auto iVertex = geometry->nodes->GetVertex(iPoint, iMarker); + const auto iVertex = geometry->nodes->GetVertex(iPoint, jMarker); if (iVertex < 0) continue; su2double normal[MAXNDIM] = {0.0}; - unitNormal(iMarker, iVertex, normal); + unitNormal(jMarker, iVertex, normal); if (fabs(GeometryToolbox::DotProduct(nDim, wallNormal, normal)) > minAlignment) wallEnds = true; } } @@ -381,10 +381,10 @@ CEulerSolver::CEulerSolver(CGeometry *geometry, CConfig *config, cout << "First-order reconstruction at " << nFlaggedGlobal << " points where a no-slip wall ends or has a sharp edge." << endl; /*--- A halo may lack one of the markers its owner has, so it takes the owner's flag. ---*/ - for (unsigned short iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++) { - if ((config->GetMarker_All_KindBC(iMarker) != SEND_RECEIVE) || (config->GetMarker_All_SendRecv(iMarker) <= 0)) + for (unsigned short markerS = 0; markerS < config->GetnMarker_All(); markerS++) { + if ((config->GetMarker_All_KindBC(markerS) != SEND_RECEIVE) || (config->GetMarker_All_SendRecv(markerS) <= 0)) continue; - const auto markerS = iMarker, markerR = static_cast(iMarker + 1); + const auto markerR = static_cast(markerS + 1); const int sendTo = config->GetMarker_All_SendRecv(markerS) - 1; const int receiveFrom = abs(config->GetMarker_All_SendRecv(markerR)) - 1; vector bufSend(geometry->nVertex[markerS]), bufRecv(geometry->nVertex[markerR]); From 5dc4e688179a41c51afef95c0d4a5988018ab53f Mon Sep 17 00:00:00 2001 From: bigfooted Date: Mon, 16 Nov 2026 21:37:46 +0100 Subject: [PATCH 31/42] Clean up options, diagnostics and portability - MUSCL_FIRST_ORDER_WALL_ENDS stops with an error for the incompressible and NEMO solvers, which do not implement it. - The coarse-grid face-closure report prints only with MG_SMOOTH_OUTPUT. - config_template.cfg describes the actual linear prolongation fallback and the wall-end fade, and lists TURB_SUBITER and MG_LINEAR_SOLVER_ITER. - Remove the comments left from the CFL_ADAPT_RESIDUAL option. - Use std::this_thread::yield instead of the POSIX sched_yield, and rename a local constant FAR, which is a macro on Windows. - Restore the C3DContainerDecorator member; the caller avoids sizing tests on an unsized container. - Fix a sign-compare warning in the adaptive CFL. Co-Authored-By: Claude Opus 5.5 --- Common/include/CConfig.hpp | 4 ---- .../containers/container_decorators.hpp | 3 +-- Common/src/CConfig.cpp | 5 ++++- Common/src/linear_algebra/CSysMatrix.cpp | 5 ++--- SU2_CFD/src/drivers/CDriver.cpp | 2 +- .../src/integration/CMultiGridIntegration.cpp | 11 +++++----- SU2_CFD/src/solvers/CSolver.cpp | 2 +- config_template.cfg | 20 +++++++++++++++---- 8 files changed, 30 insertions(+), 22 deletions(-) diff --git a/Common/include/CConfig.hpp b/Common/include/CConfig.hpp index e2b1fb152e28..0b82c93bdca5 100644 --- a/Common/include/CConfig.hpp +++ b/Common/include/CConfig.hpp @@ -1758,10 +1758,6 @@ class CConfig { */ bool GetCFL_Adapt(void) const { return CFL_Adapt; } - /*! - * \brief Whether the adaptive CFL follows the nonlinear residual trend instead of the linear solve. - */ - /*! * \brief Get the outlier mitigation parameters. */ diff --git a/Common/include/containers/container_decorators.hpp b/Common/include/containers/container_decorators.hpp index e05bbf4427e7..a80b1f71ad64 100644 --- a/Common/include/containers/container_decorators.hpp +++ b/Common/include/containers/container_decorators.hpp @@ -126,8 +126,7 @@ class C3DContainerDecorator { private: Storage m_storage; - /*--- One, not zero, so rows() on a container that was never resized does not divide by it. ---*/ - Index m_innerSz = 1; + Index m_innerSz; public: C3DContainerDecorator() = default; diff --git a/Common/src/CConfig.cpp b/Common/src/CConfig.cpp index c82f79b68b8e..c676707098e5 100644 --- a/Common/src/CConfig.cpp +++ b/Common/src/CConfig.cpp @@ -1930,7 +1930,6 @@ void CConfig::SetConfig_Options() { addULongArrayOption("OUTLIER_MITIGATION_PARAM", 4, true, outlierMitigationParam); /* DESCRIPTION: Activate The adaptive CFL number. */ addBoolOption("CFL_ADAPT", CFL_Adapt, false); - /* DESCRIPTION: Adapt the CFL on the finest-grid nonlinear residuals instead of the linear solve, with a cut on divergence. */ /* !\brief CFL_ADAPT_PARAM * DESCRIPTION: Parameters of the adaptive CFL number (factor down, factor up, CFL limit (min and max)[, acceptable linear residual][, starting iteration]). * Parameters in square brackets are optional, parameter "starting iteration" only valid with parameter "acceptable linear residual". @@ -4907,6 +4906,10 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i RampMUSCL = false; } + if (MUSCL_FirstOrderWallEnds && ((Kind_Regime == ENUM_REGIME::INCOMPRESSIBLE) || GetNEMOProblem())) { + SU2_MPI::Error("MUSCL_FIRST_ORDER_WALL_ENDS is only implemented for the compressible flow solver.", CURRENT_FUNCTION); + } + if(RampMUSCL && !DiscreteAdjoint){ if (RampMUSCLParam.RampMUSCLPower <= 0.0) SU2_MPI::Error("RAMP_MUSCL_POWER cannot be less than or equal to zero!", CURRENT_FUNCTION); rampMUSCLValue = 0.0; diff --git a/Common/src/linear_algebra/CSysMatrix.cpp b/Common/src/linear_algebra/CSysMatrix.cpp index 74bba457305d..199f2c9301de 100644 --- a/Common/src/linear_algebra/CSysMatrix.cpp +++ b/Common/src/linear_algebra/CSysMatrix.cpp @@ -31,11 +31,10 @@ #include "../../include/linear_algebra/CMatrixInverse.hpp" #include "../../include/toolboxes/allocation_toolbox.hpp" -#include - #include #include #include +#include #include #include @@ -1156,7 +1155,7 @@ void CSysMatrix::LevelSweep(bool forward, const F& row_func) const { if (wait[jThread] == 0) continue; const uint64_t target = base + wait[jThread]; for (unsigned spin = 0; level_progress[jThread].steps.load(std::memory_order_acquire) < target; ++spin) { - if (spin > 4096) sched_yield(); + if (spin > 4096) std::this_thread::yield(); } } diff --git a/SU2_CFD/src/drivers/CDriver.cpp b/SU2_CFD/src/drivers/CDriver.cpp index 253e7f7c4f8f..5be83024cdac 100644 --- a/SU2_CFD/src/drivers/CDriver.cpp +++ b/SU2_CFD/src/drivers/CDriver.cpp @@ -952,7 +952,7 @@ void CDriver::InitializeGeometryFVM(CConfig *config, CGeometry **&geometry) { geometry[iMGlevel]->SetBoundControlVolume(geometry[iMGlevel-1], config, ALLOCATE); - closureReport(geometry[iMGlevel], geometry[iMGlevel-1], iMGlevel); + if (config->GetMGOptions().MG_Smooth_Output) closureReport(geometry[iMGlevel], geometry[iMGlevel-1], iMGlevel); geometry[iMGlevel]->SetCoord(geometry[iMGlevel-1]); diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index 2bc3983fc382..740cdbfcd6b6 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -1188,8 +1188,6 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe return useSolution ? nodes->GetSolution(iPoint) : nodes->GetSolution_Old(iPoint); }; - /*--- Every thread of this rank takes this branch together, and the loops below would all be - * empty anyway. It also keeps the sizing test off a container that was never resized. ---*/ /*--- The coarse grid does not change, so each level is reported once. ---*/ auto reportIllConditioned = [&]() { BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS @@ -1207,6 +1205,7 @@ void CMultiGridIntegration::ComputeProlongationGradient(CSolver *sol_coarse, CGe END_SU2_OMP_SAFE_GLOBAL_ACCESS }; + /*--- All threads of this rank take this branch together; the sizing test below needs a sized container. ---*/ if (nPointDomain == 0) { reportIllConditioned(); return; @@ -1510,7 +1509,7 @@ void CMultiGridIntegration::ComputeCorrectionWeights(CGeometry** geometry, const for (auto iPoint = 0ul; iPoint < geometry[MESH_0]->GetnPointDomain(); iPoint++) wallEnd[iPoint] = flowNodes->SkipMGCorrection(iPoint); - constexpr auto FAR = std::numeric_limits::max(); + constexpr auto UNREACHED = std::numeric_limits::max(); vector hops, front, next; for (unsigned short iMesh = 0; iMesh < nLevels; iMesh++) { @@ -1518,7 +1517,7 @@ void CMultiGridIntegration::ComputeCorrectionWeights(CGeometry** geometry, const const auto* coarse = geometry[iMesh + 1]; vector coarseWallEnd(coarse->GetnPoint(), 0); - hops.assign(coarse->GetnPoint(), FAR); + hops.assign(coarse->GetnPoint(), UNREACHED); front.clear(); for (auto iCoarse = 0ul; iCoarse < coarse->GetnPointDomain(); iCoarse++) for (auto iChild = 0u; iChild < coarse->nodes->GetnChildren_CV(iCoarse); iChild++) @@ -1533,7 +1532,7 @@ void CMultiGridIntegration::ComputeCorrectionWeights(CGeometry** geometry, const next.clear(); for (auto iCoarse : front) for (auto jCoarse : coarse->nodes->GetPoints(iCoarse)) - if (hops[jCoarse] == FAR) { + if (hops[jCoarse] == UNREACHED) { hops[jCoarse] = d; next.push_back(jCoarse); } @@ -1543,7 +1542,7 @@ void CMultiGridIntegration::ComputeCorrectionWeights(CGeometry** geometry, const auto& weight = correctionWeight[iMesh]; weight.assign(fine->GetnPoint(), 1.0); for (auto iCoarse = 0ul; iCoarse < coarse->GetnPointDomain(); iCoarse++) { - if (hops[iCoarse] == FAR) continue; + if (hops[iCoarse] == UNREACHED) continue; for (auto iChild = 0u; iChild < coarse->nodes->GetnChildren_CV(iCoarse); iChild++) weight[coarse->nodes->GetChildren_CV(iCoarse, iChild)] = passivedouble(hops[iCoarse]) / passivedouble(nBlend); } diff --git a/SU2_CFD/src/solvers/CSolver.cpp b/SU2_CFD/src/solvers/CSolver.cpp index 53ee64aa3bde..b1e23942b835 100644 --- a/SU2_CFD/src/solvers/CSolver.cpp +++ b/SU2_CFD/src/solvers/CSolver.cpp @@ -2112,7 +2112,7 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, if (d0 * d1 < 0.0) nChanges++; } } - if ((nChanges + 1 >= flipWindow - 1) && (amplitude > flipAmplitude)) nAlternating++; + if ((size_t(nChanges) + 1 >= flipWindow - 1) && (amplitude > flipAmplitude)) nAlternating++; progress += (ResFlow_History[nHist - 1 - flipWindow][iVar] - ResFlow_History.back()[iVar]) / logRes.size(); } flip = (nAlternating * 4 >= logRes.size() * 3) && (progress < flipProgress); diff --git a/config_template.cfg b/config_template.cfg index 76406d0848fd..c9074a9362d8 100644 --- a/config_template.cfg +++ b/config_template.cfg @@ -1648,7 +1648,8 @@ MUSCL_FLOW= YES % continues its surface (a leading edge after a symmetry plane) or has a sharp edge (a sharp % trailing edge). The gradient is singular there, and MUSCL across it can stall or destabilize % the solver, multigrid in particular. With multigrid, the coarse-grid correction of the flow -% solution is also not prolongated to these points and their neighbours (NO, YES) +% solution is also not prolongated to these points and their neighbours, and fades in linearly +% over the 4 coarse control volumes around them. Compressible flow solver only (NO, YES) MUSCL_FIRST_ORDER_WALL_ENDS= NO % % Option to ramp the MUSCL reconstruction scheme gradually from first to second order @@ -1830,8 +1831,11 @@ MG_DAMP_PROLONGATION= 0.5 % Prolong the correction with a limited least-squares gradient over the coarse control % volume instead of injecting the parent value into every child. The reconstruction is % exact for a linear correction and the children still average back to the coarse value. -% Control volumes on walls and symmetry planes, and those where the gradient fit has a condition number -% above 1e5 (strongly stretched agglomerates, reported on screen), keep the constant operator (NO, YES) +% The gradient is limited so no child leaves the range of the coarse neighbours. On walls and +% symmetry planes only the velocity keeps the constant operator. A coarse control volume whose +% neighbour directions give a fit condition number above 1e3, or whose stencil aspect ratio exceeds +% 100, keeps the constant operator for all variables (reported on screen); between aspect ratios +% 10 and 100 the gradient is faded out (NO, YES) MG_LINEAR_PROLONGATION= NO % % Enable early exit from multigrid smoothing when the residual RMS drops @@ -1845,7 +1849,8 @@ MG_SMOOTH_RES_THRESHOLD= 0.9 % Smoothing coefficient for the Jacobi correction-prolongation smoother (default 1.25) MG_SMOOTH_COEFF= 1.25 % -% Print a compact per-cycle summary of smoothing iterations and residuals (NO, YES) +% Print a compact per-cycle summary of smoothing iterations, residuals and linear solver +% iterations, and the face-closure check of each coarse grid (NO, YES) MG_SMOOTH_OUTPUT= NO % % Stop smoothing when current_rms >= previous_rms * this value. Values below 1.0 exit @@ -1867,6 +1872,10 @@ MG_IMPLICIT_LINES= NO % (default 0.5, i.e. half the CFL per level) MG_CFL_SCALING= ( 0.5 ) % +% Maximum linear solver iterations on the coarse multigrid levels. Entry i applies to level i+1, +% the last value is repeated, and the cap never exceeds LINEAR_SOLVER_ITER (default 3) +MG_LINEAR_SOLVER_ITER= ( 3 ) +% % Number of iterations spent on each mesh during the Full Multigrid (FMG) startup phase. After % this many iterations the solution is prolongated to the next finer mesh. It is also the length % of the CFL ramp every level is brought up over, the finest grid included, which is what keeps @@ -2178,6 +2187,9 @@ TIME_DISCRE_TURB= EULER_IMPLICIT % % Reduction factor of the CFL coefficient in the turbulence problem CFL_REDUCTION_TURB= 1.0 +% +% Number of turbulence iterations per flow iteration (default 1) +TURB_SUBITER= 1 % Control lower limit constants of the SST model (C*phi_infinity) LOWER_LIMIT_K_FACTOR= 1e-15 From a0cb51ca35da77166717138a3e4d95924159cfda Mon Sep 17 00:00:00 2001 From: bigfooted Date: Mon, 16 Nov 2026 21:41:32 +0100 Subject: [PATCH 32/42] Move the point-to-point synchronized ILU level sweeps to their own branch They are independent of multigrid and go to a separate pull request. Co-Authored-By: Claude Opus 5.5 --- Common/include/linear_algebra/CSysMatrix.hpp | 37 ------ Common/src/linear_algebra/CSysMatrix.cpp | 126 +------------------ 2 files changed, 4 insertions(+), 159 deletions(-) diff --git a/Common/include/linear_algebra/CSysMatrix.hpp b/Common/include/linear_algebra/CSysMatrix.hpp index a02829351330..ed33589b31d2 100644 --- a/Common/include/linear_algebra/CSysMatrix.hpp +++ b/Common/include/linear_algebra/CSysMatrix.hpp @@ -34,7 +34,6 @@ #include "CPastixWrapper.hpp" #include "../toolboxes/graph_toolbox.hpp" -#include #include #include #include @@ -364,23 +363,6 @@ class CSysMatrix { * into ilu_level_ptr / d_precond_level_idx below for the GPU triangular solves. */ CCompressedSparsePatternUL levels_ilu; - /*!< \brief Per-thread progress counter, padded to a cache line. */ - struct alignas(64) LevelProgress { - std::atomic steps{0}; - LevelProgress() = default; - LevelProgress(const LevelProgress& other) : steps(other.steps.load()) {} - LevelProgress& operator=(const LevelProgress& other) { - steps.store(other.steps.load()); - return *this; - } - }; - - /*!< \brief Steps each thread must see completed by every other thread, per (step, thread, other thread), - * for the forward and backward level scheduled sweeps. Empty when barriers separate the levels. */ - std::vector level_waits_fwd, level_waits_bwd; - mutable std::vector level_progress; - unsigned long level_num_threads = 0; - /*!< \brief Coloring of the (domain-only) ILU dependency graph, used only by the GPU iterative * factorization (see IluFactorColorKernel and ilu_color_ptr / d_ilu_color_idx below). The * host/OMP path and the GPU triangular solves use levels_ilu instead. */ @@ -684,25 +666,6 @@ class CSysMatrix { void ComputeJacobiPreconditionerGPU(const CSysVector& vec, CSysVector& prod, CGeometry* geometry, const CConfig* config) const; - /*! - * \brief Compute the wait tables of the point-to-point synchronized level scheduled sweeps. - */ - void BuildLevelWaits(); - - /*! - * \brief Apply a function to the rows of all levels in increasing or decreasing order, waiting only for - * the threads owning the rows depended on. Must be called by all threads of the team. - */ - template - void LevelSweep(bool forward, const F& row_func) const; - - /*! - * \brief Whether the calling thread team matches the one the wait tables were built for. - */ - inline bool UseLevelWaits() const { - return !level_waits_fwd.empty() && static_cast(omp_get_num_threads()) == level_num_threads; - } - /*! * \brief Build the ILU preconditioner on the device, from the device copy of the matrix. * \note Requires the device matrix to be up to date, see HtDTransfer. diff --git a/Common/src/linear_algebra/CSysMatrix.cpp b/Common/src/linear_algebra/CSysMatrix.cpp index 199f2c9301de..1f46844c4918 100644 --- a/Common/src/linear_algebra/CSysMatrix.cpp +++ b/Common/src/linear_algebra/CSysMatrix.cpp @@ -31,10 +31,8 @@ #include "../../include/linear_algebra/CMatrixInverse.hpp" #include "../../include/toolboxes/allocation_toolbox.hpp" -#include #include #include -#include #include #include @@ -352,19 +350,9 @@ void CSysMatrix::Initialize(unsigned long npoint, unsigned long npoi /*--- The GPU triangular solves are level-scheduled (exact, one pass per level), so they need * levels_ilu unconditionally; the host/OMP path only needs it when both multi-threaded and * requested via config. ---*/ - if (useCuda) { + if (useCuda || (omp_get_max_threads() > 1 && config->GetIluOptions().LevelScheduling)) { levels_ilu = computeLevels(pat_ilu.l); - } else if (omp_get_max_threads() > 1 && config->GetIluOptions().LevelScheduling) { - /*--- The levels only cover the domain points, like the thread partitions. ---*/ - const auto& pat_l = pat_ilu.l; - su2vector outerPtr(nPointDomain + 1); - for (auto i = 0ul; i <= nPointDomain; ++i) outerPtr(i) = pat_l.outerPtr()[i]; - su2vector innerIdx(outerPtr(nPointDomain)); - for (auto k = 0ul; k < innerIdx.size(); ++k) innerIdx(k) = pat_l.innerIdx()[k]; - levels_ilu = computeLevels(CCompressedSparsePatternUL(std::move(outerPtr), std::move(innerIdx))); } - level_waits_fwd.clear(); - level_waits_bwd.clear(); /*--- Coloring for the GPU iterative factorization, see IluFactorColorKernel. Colors are * true independent sets of the (domain-only, symmetric) dependency graph, computed the same @@ -533,9 +521,7 @@ void CSysMatrix::Initialize(unsigned long npoint, unsigned long npoi } } - if (ilu_needed && !levels_ilu.empty() && !useCuda && num_threads > 1) BuildLevelWaits(); - - /*--- Generate MKL Kernels ---*/ + /*--- Generate MKL Kernels ---*/ #ifdef USE_MKL using mkl = mkl_jit_wrapper; @@ -1074,102 +1060,6 @@ void CSysMatrix::ComputeJacobiPreconditioner(const CSysVector -void CSysMatrix::BuildLevelWaits() { - const auto nThreads = static_cast(omp_get_max_threads()); - const auto nLevels = levels_ilu.getOuterSize(); - - /*--- Level and owning thread of each row, the rows of a level are split in equal contiguous slices. ---*/ - - std::vector level(nPointDomain, 0), owner(nPointDomain, 0); - for (unsigned long iLevel = 0; iLevel < nLevels; ++iLevel) { - const unsigned long n = levels_ilu.getNumNonZeros(iLevel); - for (unsigned long iThread = 0; iThread < nThreads; ++iThread) { - for (auto k = n * iThread / nThreads; k < n * (iThread + 1) / nThreads; ++k) { - const auto iPoint = levels_ilu.getInnerIdx(iLevel, k); - level[iPoint] = iLevel; - owner[iPoint] = iThread; - } - } - } - - std::vector fwd(nLevels * nThreads * nThreads, 0), bwd(fwd); - bool valid = true; - - for (unsigned long iLevel = 0; iLevel < nLevels; ++iLevel) { - const unsigned long n = levels_ilu.getNumNonZeros(iLevel); - const auto iStep = nLevels - 1 - iLevel; // Position in the backward sweep. - - for (unsigned long iThread = 0; iThread < nThreads; ++iThread) { - auto* wait_f = &fwd[(iLevel * nThreads + iThread) * nThreads]; - auto* wait_b = &bwd[(iStep * nThreads + iThread) * nThreads]; - - for (auto k = n * iThread / nThreads; k < n * (iThread + 1) / nThreads; ++k) { - const auto iPoint = levels_ilu.getInnerIdx(iLevel, k); - - for (auto kl = ilu.row_ptr_l[iPoint]; kl < ilu.row_ptr_l[iPoint + 1]; ++kl) { - const auto jPoint = ilu.col_ind_l[kl]; - if (level[jPoint] >= iLevel) valid = false; - wait_f[owner[jPoint]] = std::max(wait_f[owner[jPoint]], level[jPoint] + 1); - } - for (auto ku = ilu.row_ptr_u[iPoint]; ku < ilu.row_ptr_u[iPoint + 1]; ++ku) { - const auto jPoint = ilu.col_ind_u[ku]; - if (jPoint >= nPointDomain) break; - if (level[jPoint] <= iLevel) valid = false; - const auto jStep = nLevels - 1 - level[jPoint]; - wait_b[owner[jPoint]] = std::max(wait_b[owner[jPoint]], jStep + 1); - } - } - wait_f[iThread] = 0; - wait_b[iThread] = 0; - } - } - - /*--- The backward sweep needs a symmetric pattern, otherwise keep the barriers. ---*/ - if (!valid) return; - - level_waits_fwd = std::move(fwd); - level_waits_bwd = std::move(bwd); - level_num_threads = nThreads; - level_progress = std::vector(nThreads); -} - -template -template -void CSysMatrix::LevelSweep(bool forward, const F& row_func) const { - const auto nThreads = level_num_threads; - const auto iThread = static_cast(omp_get_thread_num()); - const auto nLevels = levels_ilu.getOuterSize(); - const auto& waits = forward ? level_waits_fwd : level_waits_bwd; - - /*--- All counters are equal at the start of a sweep. ---*/ - SU2_OMP_BARRIER - - auto& progress = level_progress[iThread].steps; - const uint64_t base = progress.load(std::memory_order_relaxed); - - for (unsigned long iStep = 0; iStep < nLevels; ++iStep) { - const auto* wait = &waits[(iStep * nThreads + iThread) * nThreads]; - - for (unsigned long jThread = 0; jThread < nThreads; ++jThread) { - if (wait[jThread] == 0) continue; - const uint64_t target = base + wait[jThread]; - for (unsigned spin = 0; level_progress[jThread].steps.load(std::memory_order_acquire) < target; ++spin) { - if (spin > 4096) std::this_thread::yield(); - } - } - - const auto iLevel = forward ? iStep : nLevels - 1 - iStep; - const unsigned long n = levels_ilu.getNumNonZeros(iLevel); - for (auto k = n * iThread / nThreads; k < n * (iThread + 1) / nThreads; ++k) { - row_func(levels_ilu.getInnerIdx(iLevel, k)); - } - progress.store(base + iStep + 1, std::memory_order_release); - } - - SU2_OMP_BARRIER -} - template void CSysMatrix::BuildILUPreconditioner() { SU2_ZONE_SCOPED @@ -1269,12 +1159,7 @@ void CSysMatrix::BuildILUPreconditioner() { InvertDiagonalBlockILUMatrix(iPoint); }; - if (UseLevelWaits()) { - LevelSweep(true, [&](const auto iPoint) { - InitIluRow(iPoint); - BuildIluRow(iPoint, 0ul, nPointDomain); - }); - } else if (levels_ilu.empty()) { + if (levels_ilu.empty()) { /*--- Each OMP thread will work on the submatrix defined from * row/col "begin" to row/col "end-1" (i.e. the range [begin,end[). * Which is exactly what the MPI-only implementation does. ---*/ @@ -1371,10 +1256,7 @@ void CSysMatrix::ComputeILUPreconditioner(const CSysVector Date: Mon, 16 Nov 2026 22:20:20 +0100 Subject: [PATCH 33/42] Compute the flow gradient on the active level of the full-multigrid startup Coarse levels zeroed the primitive gradient so the viscous flux matched its Jacobian. The output call on the active startup level zeroed it too, which left the turbulence model there without vorticity, strain rate and velocity gradient. That call now computes the gradient. Flat plate 273x193, MG_CFL_SCALING 1.0: SST reached muT/mu of 1e10 on the coarse levels without vorticity and about 300 with it, and converges in 497 instead of 744 iterations. Co-Authored-By: Claude Opus 5.5 --- SU2_CFD/src/solvers/CNSSolver.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SU2_CFD/src/solvers/CNSSolver.cpp b/SU2_CFD/src/solvers/CNSSolver.cpp index 666572258e52..c4d6dd10ac1c 100644 --- a/SU2_CFD/src/solvers/CNSSolver.cpp +++ b/SU2_CFD/src/solvers/CNSSolver.cpp @@ -101,9 +101,10 @@ void CNSSolver::Preprocessing(CGeometry *geometry, CSolver **solver_container, C } /*--- Compute gradient of the primitive variables. Coarse levels take the viscous flux from the edge - * difference only, as their Jacobian does. ---*/ + * difference only, as their Jacobian does, except for the output call that feeds the turbulence + * model on the active level of the full-multigrid startup. ---*/ - if (iMesh != MESH_0) { + if ((iMesh != MESH_0) && !Output) { SU2_OMP_FOR_STAT(omp_chunk_size) for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) for (unsigned short iVar = 0; iVar < nPrimVarGrad; iVar++) From 0bf8a1c1b20ebf211aad7e79a37835a4256d19d9 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Mon, 16 Nov 2026 22:24:36 +0100 Subject: [PATCH 34/42] Grow the wall-end correction fade across partition interfaces The distance from a wall end was counted on each rank without an exchange, so a fade that reached a partition interface stopped there and the correction weights depended on the number of ranks. The front now grows one layer per pass with a halo exchange after each pass. The weights are only computed with MUSCL_FIRST_ORDER_WALL_ENDS. Three-element airfoil, 4 ranks: level 3 had 42 and 68 coarse CVs at distance 2 and 3 instead of 46 and 77. On 1 and 2 ranks the counts are unchanged. Co-Authored-By: Claude Opus 5.5 --- .../integration/CMultiGridIntegration.hpp | 7 +- .../src/integration/CMultiGridIntegration.cpp | 96 +++++++++++-------- 2 files changed, 60 insertions(+), 43 deletions(-) diff --git a/SU2_CFD/include/integration/CMultiGridIntegration.hpp b/SU2_CFD/include/integration/CMultiGridIntegration.hpp index 75ab2e64f7e6..8d5ed92eff3d 100644 --- a/SU2_CFD/include/integration/CMultiGridIntegration.hpp +++ b/SU2_CFD/include/integration/CMultiGridIntegration.hpp @@ -435,14 +435,17 @@ class CMultiGridIntegration final : public CIntegration { * Allocated on first use, only when MG_LINEAR_PROLONGATION is on. */ vector prolongGradient; vector> correctionWeight; /*!< \brief Per level, weight of the correction near wall ends. */ + bool correctionWeightReady = false; /*!< \brief The weights have been computed. */ + CSysVector correctionHops; /*!< \brief Coarse CVs from the nearest wall end, with halos. */ /*! * \brief Weight each level's prolongated correction from zero where a wall ends to one a few coarse CVs away. + * Must be called by all threads. * \param[in] geometry - Geometry of all levels of this zone and instance. * \param[in] flowNodes - Flow variables of the finest grid, which flag the wall ends. - * \param[in] nLevels - Number of multigrid levels. + * \param[in] config - Definition of the particular problem. */ - void ComputeCorrectionWeights(CGeometry** geometry, const CEulerVariable* flowNodes, unsigned short nLevels); + void ComputeCorrectionWeights(CGeometry** geometry, const CEulerVariable* flowNodes, const CConfig* config); /*! \brief Coarse cells per level whose gradient fit is too ill-conditioned and keep the constant * operator, and whether that level has been reported. */ diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index 740cdbfcd6b6..02d573c06757 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -654,11 +654,9 @@ void CMultiGridIntegration::MultiGrid_Cycle(CGeometry ****geometry, unsigned short iRKLimit = config->GetnRKStep(); /*--- Wall end weights for every level, once the hierarchy exists. ---*/ - if ((iMesh == MESH_0) && correctionWeight.empty()) { + if ((iMesh == MESH_0) && !correctionWeightReady) { const auto* flowNodes = dynamic_cast(solver_container_fine[FLOW_SOL]->GetNodes()); - BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS - ComputeCorrectionWeights(geometry[iZone][iInst], flowNodes, config->GetnMGLevels()); - END_SU2_OMP_SAFE_GLOBAL_ACCESS + ComputeCorrectionWeights(geometry[iZone][iInst], flowNodes, config); } /*--- Do a presmoothing on the grid iMesh to be restricted to the grid iMesh+1 ---*/ @@ -1497,57 +1495,73 @@ void CMultiGridIntegration::SmoothProlongated_Correction(unsigned short RunTime_ } void CMultiGridIntegration::ComputeCorrectionWeights(CGeometry** geometry, const CEulerVariable* flowNodes, - unsigned short nLevels) { + const CConfig* config) { /*--- Coarse CVs over which the correction fades in from a wall end. ---*/ constexpr unsigned long nBlend = 4; + const auto nLevels = config->GetnMGLevels(); - correctionWeight.assign(nLevels, {}); - if (!flowNodes) return; + if (!flowNodes || !config->GetMUSCL_FirstOrderWallEnds()) { + SU2_OMP_SAFE_GLOBAL_ACCESS(correctionWeightReady = true;) + return; + } /*--- Points of each level holding a wall end, passed down from the finest grid. ---*/ - vector wallEnd(geometry[MESH_0]->GetnPoint(), 0); - for (auto iPoint = 0ul; iPoint < geometry[MESH_0]->GetnPointDomain(); iPoint++) - wallEnd[iPoint] = flowNodes->SkipMGCorrection(iPoint); + vector wallEnd; + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { + correctionWeight.assign(nLevels, {}); + wallEnd.assign(geometry[MESH_0]->GetnPoint(), 0); + for (auto iPoint = 0ul; iPoint < geometry[MESH_0]->GetnPointDomain(); iPoint++) + wallEnd[iPoint] = flowNodes->SkipMGCorrection(iPoint); + } + END_SU2_OMP_SAFE_GLOBAL_ACCESS - constexpr auto UNREACHED = std::numeric_limits::max(); - vector hops, front, next; + auto hopsOf = [&](unsigned long iPoint) { return static_cast(SU2_TYPE::Int(correctionHops(iPoint, 0))); }; + + /*--- The distance grows one layer per pass on every rank, and each pass hands the halos their + * owner's value, so a front crosses partition interfaces as if there were none. ---*/ for (unsigned short iMesh = 0; iMesh < nLevels; iMesh++) { - const auto* fine = geometry[iMesh]; - const auto* coarse = geometry[iMesh + 1]; - - vector coarseWallEnd(coarse->GetnPoint(), 0); - hops.assign(coarse->GetnPoint(), UNREACHED); - front.clear(); - for (auto iCoarse = 0ul; iCoarse < coarse->GetnPointDomain(); iCoarse++) - for (auto iChild = 0u; iChild < coarse->nodes->GetnChildren_CV(iCoarse); iChild++) - if (wallEnd[coarse->nodes->GetChildren_CV(iCoarse, iChild)]) { - coarseWallEnd[iCoarse] = 1; - hops[iCoarse] = 0; - front.push_back(iCoarse); - break; - } + auto* coarse = geometry[iMesh + 1]; + const auto nDomain = coarse->GetnPointDomain(); - for (unsigned long d = 1; (d < nBlend) && !front.empty(); d++) { - next.clear(); - for (auto iCoarse : front) - for (auto jCoarse : coarse->nodes->GetPoints(iCoarse)) - if (hops[jCoarse] == UNREACHED) { - hops[jCoarse] = d; - next.push_back(jCoarse); + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { + correctionHops.Initialize(coarse->GetnPoint(), nDomain, 1, su2double(nBlend)); + for (auto iCoarse = 0ul; iCoarse < nDomain; iCoarse++) + for (auto iChild = 0u; iChild < coarse->nodes->GetnChildren_CV(iCoarse); iChild++) + if (wallEnd[coarse->nodes->GetChildren_CV(iCoarse, iChild)]) correctionHops(iCoarse, 0) = 0.0; + } + END_SU2_OMP_SAFE_GLOBAL_ACCESS + + for (unsigned long d = 0; d < nBlend; d++) { + if (d > 0) { + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { + for (auto iCoarse = 0ul; iCoarse < nDomain; iCoarse++) { + if (hopsOf(iCoarse) < d) continue; + for (auto jCoarse : coarse->nodes->GetPoints(iCoarse)) + if (hopsOf(jCoarse) + 1 == d) correctionHops(iCoarse, 0) = d; } - front.swap(next); + } + END_SU2_OMP_SAFE_GLOBAL_ACCESS + } + CSysMatrixComms::Initiate(correctionHops, coarse, config); + CSysMatrixComms::Complete(correctionHops, coarse, config); } - auto& weight = correctionWeight[iMesh]; - weight.assign(fine->GetnPoint(), 1.0); - for (auto iCoarse = 0ul; iCoarse < coarse->GetnPointDomain(); iCoarse++) { - if (hops[iCoarse] == UNREACHED) continue; - for (auto iChild = 0u; iChild < coarse->nodes->GetnChildren_CV(iCoarse); iChild++) - weight[coarse->nodes->GetChildren_CV(iCoarse, iChild)] = passivedouble(hops[iCoarse]) / passivedouble(nBlend); + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { + auto& weight = correctionWeight[iMesh]; + weight.assign(geometry[iMesh]->GetnPoint(), 1.0); + for (auto iCoarse = 0ul; iCoarse < nDomain; iCoarse++) { + const auto w = SU2_TYPE::GetValue(correctionHops(iCoarse, 0)) / nBlend; + for (auto iChild = 0u; iChild < coarse->nodes->GetnChildren_CV(iCoarse); iChild++) + weight[coarse->nodes->GetChildren_CV(iCoarse, iChild)] = w; + } + wallEnd.assign(coarse->GetnPoint(), 0); + for (auto iCoarse = 0ul; iCoarse < coarse->GetnPoint(); iCoarse++) wallEnd[iCoarse] = (hopsOf(iCoarse) == 0); } - wallEnd.swap(coarseWallEnd); + END_SU2_OMP_SAFE_GLOBAL_ACCESS } + + SU2_OMP_SAFE_GLOBAL_ACCESS(correctionWeightReady = true;) } void CMultiGridIntegration::SetProlongated_Correction(CSolver *sol_fine, CSolver *sol_flow, CGeometry *geo_fine, From 05a5901af9135b63eca7d53a7134b4849c8b1436 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Mon, 16 Nov 2026 22:29:13 +0100 Subject: [PATCH 35/42] Keep anisotropic lines on one rank within the ParMETIS load tolerance Every split line moved to the partition holding most of it, whatever the load, so the imbalance grew with the rank count. Every rank now sees the split lines and processes them in root order, moving each to the partition with most of its points that stays within the load tolerance (1 + PARMETIS_TOLERANCE times the mean load) and leaves no partition empty. A line no partition can take stays split, and their number is reported. Flat plate 1089x769, 16 ranks: imbalance 1.057 before, 1.017 now, all lines kept whole. Co-Authored-By: Claude Opus 5.5 --- Common/include/geometry/CPhysicalGeometry.hpp | 10 +- Common/src/geometry/CPhysicalGeometry.cpp | 115 +++++++++++++----- 2 files changed, 89 insertions(+), 36 deletions(-) diff --git a/Common/include/geometry/CPhysicalGeometry.hpp b/Common/include/geometry/CPhysicalGeometry.hpp index 9896429e570b..1ea891139083 100644 --- a/Common/include/geometry/CPhysicalGeometry.hpp +++ b/Common/include/geometry/CPhysicalGeometry.hpp @@ -363,14 +363,18 @@ class CPhysicalGeometry final : public CGeometry { vector LinkAnisotropicLines(const vector& adjwgt, vector& lineEdge) const; /*! - * \brief Moves each line to the partition that holds most of its points. + * \brief Moves each split line to the partition that holds most of its points and stays within the load tolerance. * \param[in] root - Line roots from LinkAnisotropicLines. + * \param[in] vwgt - Vertex weight of every local point. + * \param[in] maxImbalance - Largest partition load over the mean load. * \param[in,out] part - Partition of every local point. * \param[out] longestLine - Number of points of the longest line. + * \param[out] nSplit - Number of lines left split. * \return Number of points that changed partition, summed over all ranks. */ - unsigned long KeepLinesTogether(const vector& root, vector& part, - unsigned long& longestLine) const; + unsigned long KeepLinesTogether(const vector& root, const vector& vwgt, + passivedouble maxImbalance, vector& part, unsigned long& longestLine, + unsigned long& nSplit) const; #endif /*! diff --git a/Common/src/geometry/CPhysicalGeometry.cpp b/Common/src/geometry/CPhysicalGeometry.cpp index 4172b571bc7a..5a87386c84f6 100644 --- a/Common/src/geometry/CPhysicalGeometry.cpp +++ b/Common/src/geometry/CPhysicalGeometry.cpp @@ -7449,14 +7449,14 @@ vector CPhysicalGeometry::LinkAnisotropicLines(const vector& root, vector& part, - unsigned long& longestLine) const { +unsigned long CPhysicalGeometry::KeepLinesTogether(const vector& root, const vector& vwgt, + passivedouble maxImbalance, vector& part, + unsigned long& longestLine, unsigned long& nSplit) const { CLinearPartitioner pointPartitioner(Global_nPointDomain, 0); - const unsigned long firstIndex = pointPartitioner.GetFirstIndexOnRank(rank); - /*--- The owner of each root counts in which partitions its line lies. ---*/ + /*--- The owner of each root collects, per partition, the points and vertex weight of its line. ---*/ vector nSend(size, 0), nRecv(size), sendDisp(size + 1, 0), recvDisp(size + 1, 0); - for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) nSend[pointPartitioner.GetRankContainingIndex(root[iPoint])] += 2; + for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) nSend[pointPartitioner.GetRankContainingIndex(root[iPoint])] += 3; SU2_MPI::Alltoall(nSend.data(), 1, MPI_INT, nRecv.data(), 1, MPI_INT, SU2_MPI::GetComm()); for (int iRank = 0; iRank < size; iRank++) { sendDisp[iRank + 1] = sendDisp[iRank] + nSend[iRank]; @@ -7468,47 +7468,94 @@ unsigned long CPhysicalGeometry::KeepLinesTogether(const vector& auto& slot = next[pointPartitioner.GetRankContainingIndex(root[iPoint])]; sendBuf[slot++] = root[iPoint]; sendBuf[slot++] = static_cast(part[iPoint]); + sendBuf[slot++] = static_cast(vwgt[iPoint]); } SU2_MPI::Alltoallv(sendBuf.data(), nSend.data(), sendDisp.data(), MPI_UNSIGNED_LONG, recvBuf.data(), nRecv.data(), recvDisp.data(), MPI_UNSIGNED_LONG, SU2_MPI::GetComm()); - map> votes; - for (auto k = 0ul; k < recvBuf.size(); k += 2) votes[recvBuf[k]][recvBuf[k + 1]]++; + map>> lines; + for (auto k = 0ul; k < recvBuf.size(); k += 3) { + auto& share = lines[recvBuf[k]][recvBuf[k + 1]]; + share.first++; + share.second += recvBuf[k + 2]; + } unsigned long longest = 0; - for (const auto& line : votes) { + for (const auto& line : lines) { unsigned long length = 0; - for (const auto& vote : line.second) length += vote.second; + for (const auto& share : line.second) length += share.second.first; longest = max(longest, length); } SU2_MPI::Allreduce(&longest, &longestLine, 1, MPI_UNSIGNED_LONG, MPI_MAX, SU2_MPI::GetComm()); - vector decision(nPoint); - for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) decision[iPoint] = static_cast(part[iPoint]); - for (const auto& line : votes) { - unsigned long best = 0, bestCount = 0; - for (const auto& vote : line.second) { - if (vote.second > bestCount) { - best = vote.first; - bestCount = vote.second; - } + /*--- Every rank gets the split lines, as root, number of partitions, then partition, points and + * weight per partition. Ranks own consecutive roots, so the gathered list is in root order. ---*/ + vector mine; + for (const auto& line : lines) { + if (line.second.size() < 2) continue; + mine.push_back(line.first); + mine.push_back(line.second.size()); + for (const auto& share : line.second) { + mine.push_back(share.first); + mine.push_back(share.second.first); + mine.push_back(share.second.second); + } + } + const int nMine = mine.size(); + vector nAll(size), allDisp(size + 1, 0); + SU2_MPI::Allgather(&nMine, 1, MPI_INT, nAll.data(), 1, MPI_INT, SU2_MPI::GetComm()); + for (int iRank = 0; iRank < size; iRank++) allDisp[iRank + 1] = allDisp[iRank] + nAll[iRank]; + vector all(allDisp[size]); + SU2_MPI::Allgatherv(mine.data(), nMine, MPI_UNSIGNED_LONG, all.data(), nAll.data(), allDisp.data(), MPI_UNSIGNED_LONG, + SU2_MPI::GetComm()); + + vector load(size, 0), loadGlobal(size); + for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) load[part[iPoint]] += vwgt[iPoint]; + SU2_MPI::Allreduce(load.data(), loadGlobal.data(), size, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm()); + const passivedouble maxLoad = + maxImbalance * passivedouble(accumulate(loadGlobal.begin(), loadGlobal.end(), 0ul)) / size; + + /*--- Each line goes to the partition holding most of it that stays within the load tolerance and + * leaves no partition empty. All ranks take the same decisions in the same order. ---*/ + unordered_map target; + vector> shares; + nSplit = 0; + for (auto k = 0ul; k < all.size();) { + const auto lineRoot = all[k]; + const auto nShares = all[k + 1]; + k += 2; + shares.resize(nShares); + unsigned long weight = 0; + for (auto& share : shares) { + share = {all[k], all[k + 1], all[k + 2]}; + weight += share[2]; + k += 3; + } + sort(shares.begin(), shares.end(), + [](const auto& a, const auto& b) { return (a[1] > b[1]) || ((a[1] == b[1]) && (a[0] < b[0])); }); + + bool placed = false; + for (const auto& to : shares) { + if (passivedouble(loadGlobal[to[0]] + weight - to[2]) > maxLoad) continue; + bool empties = false; + for (const auto& from : shares) empties = empties || ((from[0] != to[0]) && (loadGlobal[from[0]] == from[2])); + if (empties) continue; + + for (const auto& from : shares) loadGlobal[from[0]] -= from[2]; + loadGlobal[to[0]] += weight; + target[lineRoot] = to[0]; + placed = true; + break; } - decision[line.first - firstIndex] = best; + nSplit += !placed; } - /*--- Every point takes the partition of its line, unless that would leave a rank without points. ---*/ - const auto chosen = FetchFromOwners(root, decision); - vector count(size, 0), countGlobal(size); - for (const auto iPart : chosen) count[iPart]++; - SU2_MPI::Allreduce(count.data(), countGlobal.data(), size, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm()); - if (*min_element(countGlobal.begin(), countGlobal.end()) == 0) return 0; - unsigned long moved = 0, movedGlobal = 0; for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) { - if (static_cast(part[iPoint]) != chosen[iPoint]) { - part[iPoint] = static_cast(chosen[iPoint]); - moved++; - } + const auto it = target.find(root[iPoint]); + if ((it == target.end()) || (static_cast(part[iPoint]) == it->second)) continue; + part[iPoint] = static_cast(it->second); + moved++; } SU2_MPI::Allreduce(&moved, &movedGlobal, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm()); return movedGlobal; @@ -7720,8 +7767,8 @@ void CPhysicalGeometry::SetColorGrid_Parallel(const CConfig* config) { * fragments give tangled coarse control volumes. ---*/ if (anisotropic) { - unsigned long longestLine = 0; - const auto moved = KeepLinesTogether(lineRoot, part, longestLine); + unsigned long longestLine = 0, nSplit = 0; + const auto moved = KeepLinesTogether(lineRoot, vwgt, ubvec, part, longestLine, nSplit); /*--- The imbalance is measured in the vertex weights ParMETIS balances. ---*/ vector load(size, 0), loadGlobal(size); for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) load[part[iPoint]] += vwgt[iPoint]; @@ -7730,7 +7777,9 @@ void CPhysicalGeometry::SetColorGrid_Parallel(const CConfig* config) { const auto sumLoad = accumulate(loadGlobal.begin(), loadGlobal.end(), 0ul); if (rank == MASTER_NODE) { cout << "Longest anisotropic line " << longestLine << " points, moved " << moved - << " points to keep lines on one rank, load imbalance " << double(maxLoad) * size / sumLoad << "." << endl; + << " points to keep lines on one rank, " << nSplit + << " lines left split by the load tolerance, load imbalance " << double(maxLoad) * size / sumLoad << "." + << endl; } } From 70b242766b74318c5c210f0ef767eafc491be5d9 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Mon, 16 Nov 2026 22:58:16 +0100 Subject: [PATCH 36/42] Use the effective distance in the scalar compressible viscous Jacobians The vectorized viscous numerics take |d|^2/|d.n| as the distance in the Jacobian, which matches the normal derivative of the corrected gradient. CAvgGrad_Flow and CGeneralAvgGrad_Flow, used for the other upwind schemes and for non-ideal gases, now do the same. Three-element airfoil with HLLC: same convergence (467 iterations) and same converged solution. Co-Authored-By: Claude Opus 5.5 --- SU2_CFD/include/numerics/flow/flow_diffusion.hpp | 12 ++++++++++++ SU2_CFD/src/numerics/flow/flow_diffusion.cpp | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/SU2_CFD/include/numerics/flow/flow_diffusion.hpp b/SU2_CFD/include/numerics/flow/flow_diffusion.hpp index 562f15e8eb74..106923a87242 100644 --- a/SU2_CFD/include/numerics/flow/flow_diffusion.hpp +++ b/SU2_CFD/include/numerics/flow/flow_diffusion.hpp @@ -164,6 +164,18 @@ class CAvgGrad_Base : public CNumerics { su2double val_dist_ij_2, const unsigned short val_nPrimVar); + /*! + * \brief Distance for the Jacobian. With the corrected gradient it is |d|^2/|d.n|, which matches the normal + * derivative of the corrected gradient, bounded by 10|d| for edges nearly tangent to the face. + */ + su2double JacobianDistance(su2double dist_ij_2, const su2double* edge_vector, const su2double* unit_normal) const { + const su2double dist_ij = sqrt(dist_ij_2); + if (!correct_gradient) return dist_ij; + su2double proj = 0.0; + for (unsigned short iDim = 0; iDim < nDim; iDim++) proj += edge_vector[iDim] * unit_normal[iDim]; + return dist_ij_2 / fmax(fabs(proj), 0.1 * dist_ij); + } + public: /*! diff --git a/SU2_CFD/src/numerics/flow/flow_diffusion.cpp b/SU2_CFD/src/numerics/flow/flow_diffusion.cpp index eca315d00373..dcd0e06864d4 100644 --- a/SU2_CFD/src/numerics/flow/flow_diffusion.cpp +++ b/SU2_CFD/src/numerics/flow/flow_diffusion.cpp @@ -501,7 +501,7 @@ CNumerics::ResidualType<> CAvgGrad_Flow::ComputeResidual(const CConfig* config) } } } else { - const su2double dist_ij = sqrt(dist_ij_2); + const su2double dist_ij = JacobianDistance(dist_ij_2, Edge_Vector, UnitNormal); SetTauJacobian(Mean_PrimVar, Mean_Laminar_Viscosity, Mean_Eddy_Viscosity, dist_ij, UnitNormal); SetHeatFluxJacobian(Mean_PrimVar, Mean_Cp, Mean_Thermal_Conductivity, Mean_Eddy_Viscosity, dist_ij, UnitNormal); @@ -1019,7 +1019,7 @@ CNumerics::ResidualType<> CGeneralAvgGrad_Flow::ComputeResidual(const CConfig* c } } } else { - const su2double dist_ij = sqrt(dist_ij_2); + const su2double dist_ij = JacobianDistance(dist_ij_2, Edge_Vector, UnitNormal); SetTauJacobian(Mean_PrimVar, Mean_Laminar_Viscosity, Mean_Eddy_Viscosity, dist_ij, UnitNormal); From 977fd74b768d7023dcbb61a88474b98affa94f81 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Mon, 16 Nov 2026 22:59:39 +0100 Subject: [PATCH 37/42] Add regression cases for the new multigrid options On the 137x97 flat plate, serial and parallel: - turb_flatplate_mg_linear: SA with MG_LINEAR_PROLONGATION, MUSCL_FIRST_ORDER_WALL_ENDS and PARMETIS_ANISOTROPY_WEIGHT. - turb_flatplate_sst_fullmg: SST with the full-multigrid startup and TURB_SUBITER= 2, which runs the turbulence model on the coarse levels within the 20 tested iterations. Co-Authored-By: Claude Opus 5.5 --- TestCases/parallel_regression.py | 16 +++ .../flatplate/turb_SA_flatplate_mg_linear.cfg | 123 ++++++++++++++++++ .../flatplate/turb_SST_flatplate_fullmg.cfg | 122 +++++++++++++++++ TestCases/serial_regression.py | 16 +++ 4 files changed, 277 insertions(+) create mode 100644 TestCases/rans/flatplate/turb_SA_flatplate_mg_linear.cfg create mode 100644 TestCases/rans/flatplate/turb_SST_flatplate_fullmg.cfg diff --git a/TestCases/parallel_regression.py b/TestCases/parallel_regression.py index d7b1dc4471fa..8d1be9c995c2 100755 --- a/TestCases/parallel_regression.py +++ b/TestCases/parallel_regression.py @@ -514,6 +514,22 @@ def main(): turb_flatplate.test_vals = [-0.171203, 0.004017, 10.000000, -1.752822] test_list.append(turb_flatplate) + # FLAT PLATE, LINEAR MULTIGRID PROLONGATION, FIRST ORDER AT THE WALL END, ANISOTROPIC PARTITIONING + turb_flatplate_mg_linear = TestCase('turb_flatplate_mg_linear') + turb_flatplate_mg_linear.cfg_dir = "rans/flatplate" + turb_flatplate_mg_linear.cfg_file = "turb_SA_flatplate_mg_linear.cfg" + turb_flatplate_mg_linear.test_iter = 20 + turb_flatplate_mg_linear.test_vals = [-5.090006, -6.110316, -0.187162, 0.002996, 10.000000, -2.051853] + test_list.append(turb_flatplate_mg_linear) + + # FLAT PLATE, SST, FULL MULTIGRID STARTUP, TURBULENCE SUB-ITERATIONS + turb_flatplate_sst_fullmg = TestCase('turb_flatplate_sst_fullmg') + turb_flatplate_sst_fullmg.cfg_dir = "rans/flatplate" + turb_flatplate_sst_fullmg.cfg_file = "turb_SST_flatplate_fullmg.cfg" + turb_flatplate_sst_fullmg.test_iter = 20 + turb_flatplate_sst_fullmg.test_vals = [-4.774031, -2.108909, 8.479256, -0.187135, 0.003170] + test_list.append(turb_flatplate_sst_fullmg) + # Flat plate (compressible) with species inlet turb_flatplate_species = TestCase('turb_flatplate_species') turb_flatplate_species.cfg_dir = "rans/flatplate" diff --git a/TestCases/rans/flatplate/turb_SA_flatplate_mg_linear.cfg b/TestCases/rans/flatplate/turb_SA_flatplate_mg_linear.cfg new file mode 100644 index 000000000000..ae071786deb8 --- /dev/null +++ b/TestCases/rans/flatplate/turb_SA_flatplate_mg_linear.cfg @@ -0,0 +1,123 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% SU2 configuration file % +% Case description: Flat plate SA, linear multigrid prolongation % +% Author: Thomas D. Economon % +% Institution: Stanford University % +% Date: 2011.11.10 % +% File Version 8.6.0 "Harrier" % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% ------------- DIRECT, ADJOINT, AND LINEARIZED PROBLEM DEFINITION ------------% +% +SOLVER= RANS +KIND_TURB_MODEL= SA +MATH_PROBLEM= DIRECT +RESTART_SOL= NO + +% ----------- COMPRESSIBLE AND INCOMPRESSIBLE FREE-STREAM DEFINITION ----------% +% +MACH_NUMBER= 0.2 +AOA= 0.0 +SIDESLIP_ANGLE= 0.0 +FREESTREAM_TEMPERATURE= 300.0 +REYNOLDS_NUMBER= 5000000.0 +REYNOLDS_LENGTH= 1.0 + +% ---------------------- REFERENCE VALUE DEFINITION ---------------------------% +% +REF_ORIGIN_MOMENT_X = 0.25 +REF_ORIGIN_MOMENT_Y = 0.00 +REF_ORIGIN_MOMENT_Z = 0.00 +REF_LENGTH= 1.0 +REF_AREA= 2.0 + +% -------------------- BOUNDARY CONDITION DEFINITION --------------------------% +% +MARKER_HEATFLUX= ( wall, 0.0 ) +MARKER_INLET= ( inlet, 302.4, 118309.784, 1.0, 0.0, 0.0 ) +MARKER_OUTLET= ( outlet, 115056.0, farfield, 115056.0 ) +MARKER_SYM= ( symmetry ) +MARKER_PLOTTING= ( wall ) +MARKER_MONITORING= ( wall ) + +% ------------- COMMON PARAMETERS DEFINING THE NUMERICAL METHOD ---------------% +% +NUM_METHOD_GRAD= GREEN_GAUSS +CFL_NUMBER= 1000.0 +CFL_ADAPT= NO +CFL_ADAPT_PARAM= ( 1.5, 0.5, 1.0, 100.0 ) +RK_ALPHA_COEFF= ( 0.66667, 0.66667, 1.000000 ) +ITER= 1000 + +% ----------------------- SLOPE LIMITER DEFINITION ----------------------------% +% +VENKAT_LIMITER_COEFF= 0.1 +ADJ_SHARP_LIMITER_COEFF= 3.0 +REF_SHARP_EDGES= 3.0 +SENS_REMOVE_SHARP= NO + +% ------------------------ LINEAR SOLVER DEFINITION ---------------------------% +% +LINEAR_SOLVER= FGMRES +LINEAR_SOLVER_PREC= LU_SGS +LINEAR_SOLVER_ERROR= 1E-3 +LINEAR_SOLVER_ITER= 10 + +% -------------------------- MULTIGRID PARAMETERS -----------------------------% +% +MGLEVEL= 3 +MGCYCLE= V_CYCLE +MG_PRE_SMOOTH= ( 2, 2, 2, 2 ) +MG_POST_SMOOTH= ( 2, 2, 2, 2) +MG_CORRECTION_SMOOTH= ( 1, 1, 1, 1 ) +MG_DAMP_RESTRICTION= 0.75 +MG_DAMP_PROLONGATION= 0.75 +MG_IMPLICIT_LINES= YES +MG_LINEAR_PROLONGATION= YES + +% -------------------- FLOW NUMERICAL METHOD DEFINITION -----------------------% +% +CONV_NUM_METHOD_FLOW= ROE +MUSCL_FLOW= YES +MUSCL_FIRST_ORDER_WALL_ENDS= YES +SLOPE_LIMITER_FLOW= NONE +JST_SENSOR_COEFF= ( 0.5, 0.02 ) +TIME_DISCRE_FLOW= EULER_IMPLICIT + +% -------------------- TURBULENT NUMERICAL METHOD DEFINITION ------------------% +% +CONV_NUM_METHOD_TURB= SCALAR_UPWIND +MUSCL_TURB= NO +SLOPE_LIMITER_TURB= VENKATAKRISHNAN +TIME_DISCRE_TURB= EULER_IMPLICIT + +% --------------------------- CONVERGENCE PARAMETERS --------------------------% +% +CONV_RESIDUAL_MINVAL= -12 +CONV_STARTITER= 10 +CONV_CAUCHY_ELEMS= 100 +CONV_CAUCHY_EPS= 1E-6 + +% ------------------------- INPUT/OUTPUT INFORMATION --------------------------% +% +MESH_FILENAME= mesh_flatplate_turb_137x97.su2 +MESH_FORMAT= SU2 +MESH_OUT_FILENAME= mesh_out +SOLUTION_FILENAME= solution_flow +SOLUTION_ADJ_FILENAME= solution_adj +TABULAR_FORMAT= CSV +CONV_FILENAME= history +RESTART_FILENAME= restart_flow +RESTART_ADJ_FILENAME= restart_adj +VOLUME_FILENAME= flow +VOLUME_ADJ_FILENAME= adjoint +GRAD_OBJFUNC_FILENAME= of_grad +SURFACE_FILENAME= surface_flow +SURFACE_ADJ_FILENAME= surface_adjoint +OUTPUT_WRT_FREQ= 1000 +SCREEN_OUTPUT= (INNER_ITER, RMS_DENSITY, RMS_NU_TILDE, LIFT, DRAG, LINSOL_ITER,LINSOL_RESIDUAL) +% +% Weight the partitioning by cell anisotropy and keep wall-normal lines on one rank +PARMETIS_ANISOTROPY_WEIGHT= YES diff --git a/TestCases/rans/flatplate/turb_SST_flatplate_fullmg.cfg b/TestCases/rans/flatplate/turb_SST_flatplate_fullmg.cfg new file mode 100644 index 000000000000..e5bb085e9f0d --- /dev/null +++ b/TestCases/rans/flatplate/turb_SST_flatplate_fullmg.cfg @@ -0,0 +1,122 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% SU2 configuration file % +% Case description: Flat plate SST, full multigrid startup % +% Author: Thomas D. Economon % +% Institution: Stanford University % +% Date: 2011.11.10 % +% File Version 8.6.0 "Harrier" % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% ------------- DIRECT, ADJOINT, AND LINEARIZED PROBLEM DEFINITION ------------% +% +SOLVER= RANS +KIND_TURB_MODEL= SST +MATH_PROBLEM= DIRECT +RESTART_SOL= NO + +% ----------- COMPRESSIBLE AND INCOMPRESSIBLE FREE-STREAM DEFINITION ----------% +% +MACH_NUMBER= 0.2 +AOA= 0.0 +SIDESLIP_ANGLE= 0.0 +FREESTREAM_TEMPERATURE= 300.0 +REYNOLDS_NUMBER= 5000000.0 +REYNOLDS_LENGTH= 1.0 + +% ---------------------- REFERENCE VALUE DEFINITION ---------------------------% +% +REF_ORIGIN_MOMENT_X = 0.25 +REF_ORIGIN_MOMENT_Y = 0.00 +REF_ORIGIN_MOMENT_Z = 0.00 +REF_LENGTH= 1.0 +REF_AREA= 2.0 + +% -------------------- BOUNDARY CONDITION DEFINITION --------------------------% +% +MARKER_HEATFLUX= ( wall, 0.0 ) +MARKER_INLET= ( inlet, 302.4, 118309.784, 1.0, 0.0, 0.0 ) +MARKER_OUTLET= ( outlet, 115056.0, farfield, 115056.0 ) +MARKER_SYM= ( symmetry ) +MARKER_PLOTTING= ( wall ) +MARKER_MONITORING= ( wall ) + +% ------------- COMMON PARAMETERS DEFINING THE NUMERICAL METHOD ---------------% +% +NUM_METHOD_GRAD= GREEN_GAUSS +CFL_NUMBER= 1000.0 +CFL_ADAPT= NO +CFL_ADAPT_PARAM= ( 1.5, 0.5, 1.0, 100.0 ) +RK_ALPHA_COEFF= ( 0.66667, 0.66667, 1.000000 ) +ITER= 1000 + +% ----------------------- SLOPE LIMITER DEFINITION ----------------------------% +% +VENKAT_LIMITER_COEFF= 0.1 +ADJ_SHARP_LIMITER_COEFF= 3.0 +REF_SHARP_EDGES= 3.0 +SENS_REMOVE_SHARP= NO + +% ------------------------ LINEAR SOLVER DEFINITION ---------------------------% +% +LINEAR_SOLVER= FGMRES +LINEAR_SOLVER_PREC= LU_SGS +LINEAR_SOLVER_ERROR= 1E-3 +LINEAR_SOLVER_ITER= 10 + +% -------------------------- MULTIGRID PARAMETERS -----------------------------% +% +MGLEVEL= 3 +MGCYCLE= FULLMG_CYCLE +MG_STARTUP_ITER= 10 +MG_PRE_SMOOTH= ( 2, 2, 2, 2 ) +MG_POST_SMOOTH= ( 2, 2, 2, 2) +MG_CORRECTION_SMOOTH= ( 1, 1, 1, 1 ) +MG_DAMP_RESTRICTION= 0.75 +MG_DAMP_PROLONGATION= 0.75 +MG_IMPLICIT_LINES= YES + +% -------------------- FLOW NUMERICAL METHOD DEFINITION -----------------------% +% +CONV_NUM_METHOD_FLOW= ROE +MUSCL_FLOW= YES +SLOPE_LIMITER_FLOW= NONE +JST_SENSOR_COEFF= ( 0.5, 0.02 ) +TIME_DISCRE_FLOW= EULER_IMPLICIT + +% -------------------- TURBULENT NUMERICAL METHOD DEFINITION ------------------% +% +CONV_NUM_METHOD_TURB= SCALAR_UPWIND +MUSCL_TURB= NO +SLOPE_LIMITER_TURB= VENKATAKRISHNAN +TIME_DISCRE_TURB= EULER_IMPLICIT + +% --------------------------- CONVERGENCE PARAMETERS --------------------------% +% +CONV_RESIDUAL_MINVAL= -12 +CONV_STARTITER= 10 +CONV_CAUCHY_ELEMS= 100 +CONV_CAUCHY_EPS= 1E-6 + +% ------------------------- INPUT/OUTPUT INFORMATION --------------------------% +% +MESH_FILENAME= mesh_flatplate_turb_137x97.su2 +MESH_FORMAT= SU2 +MESH_OUT_FILENAME= mesh_out +SOLUTION_FILENAME= solution_flow +SOLUTION_ADJ_FILENAME= solution_adj +TABULAR_FORMAT= CSV +CONV_FILENAME= history +RESTART_FILENAME= restart_flow +RESTART_ADJ_FILENAME= restart_adj +VOLUME_FILENAME= flow +VOLUME_ADJ_FILENAME= adjoint +GRAD_OBJFUNC_FILENAME= of_grad +SURFACE_FILENAME= surface_flow +SURFACE_ADJ_FILENAME= surface_adjoint +OUTPUT_WRT_FREQ= 1000 +SCREEN_OUTPUT= (INNER_ITER, RMS_DENSITY, RMS_TKE, RMS_DISSIPATION, LIFT, DRAG) +% +% Turbulence iterations per flow iteration +TURB_SUBITER= 2 diff --git a/TestCases/serial_regression.py b/TestCases/serial_regression.py index b2c47e2eb883..04f5f5b1818a 100755 --- a/TestCases/serial_regression.py +++ b/TestCases/serial_regression.py @@ -271,6 +271,22 @@ def main(): turb_flatplate.test_vals = [-2.770068, -6.060857, -0.187454, 0.003164, 10.000000, -1.844116] test_list.append(turb_flatplate) + # FLAT PLATE, LINEAR MULTIGRID PROLONGATION, FIRST ORDER AT THE WALL END, ANISOTROPIC PARTITIONING + turb_flatplate_mg_linear = TestCase('turb_flatplate_mg_linear') + turb_flatplate_mg_linear.cfg_dir = "rans/flatplate" + turb_flatplate_mg_linear.cfg_file = "turb_SA_flatplate_mg_linear.cfg" + turb_flatplate_mg_linear.test_iter = 20 + turb_flatplate_mg_linear.test_vals = [-4.750399, -6.020779, -0.186911, 0.002849, 7.000000, -3.025969] + test_list.append(turb_flatplate_mg_linear) + + # FLAT PLATE, SST, FULL MULTIGRID STARTUP, TURBULENCE SUB-ITERATIONS + turb_flatplate_sst_fullmg = TestCase('turb_flatplate_sst_fullmg') + turb_flatplate_sst_fullmg.cfg_dir = "rans/flatplate" + turb_flatplate_sst_fullmg.cfg_file = "turb_SST_flatplate_fullmg.cfg" + turb_flatplate_sst_fullmg.test_iter = 20 + turb_flatplate_sst_fullmg.test_vals = [-5.436484, -2.103105, 7.808961, -0.187073, 0.003117] + test_list.append(turb_flatplate_sst_fullmg) + # FLAT PLATE, WALL FUNCTIONS, COMPRESSIBLE SST turb_wallfunction_flatplate_sst = TestCase('turb_sst_wallfunction_flatplate') turb_wallfunction_flatplate_sst.cfg_dir = "wallfunctions/flatplate/compressible_SST" From faf15360b7875e618700e4fefa78264bbc8e6aa7 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Tue, 17 Nov 2026 09:25:02 +0100 Subject: [PATCH 38/42] Restore the linear-solver CFL adaptation and run the active startup level at the level-0 CFL - AdaptCFLNumber is the develop version again. It keeps the coarse-level CFL bounds scaled with MG_CFL_SCALING. The residual-driven adaptation moves to its own pull request as an opt-in method. - During the full-multigrid startup the active level takes the level-0 CFL, and only the levels below it are scaled with MG_CFL_SCALING. The active level was given the coarse-level CFL of its depth before, 0.08 to 0.27 for CFL_NUMBER 10 on level 3. Co-Authored-By: Claude Opus 5.5 --- SU2_CFD/include/solvers/CSolver.hpp | 34 -- .../src/integration/CMultiGridIntegration.cpp | 5 +- SU2_CFD/src/solvers/CSolver.cpp | 339 ++---------------- config_template.cfg | 13 - 4 files changed, 42 insertions(+), 349 deletions(-) diff --git a/SU2_CFD/include/solvers/CSolver.hpp b/SU2_CFD/include/solvers/CSolver.hpp index 3706ae6e6284..9d7b8b0ca886 100644 --- a/SU2_CFD/include/solvers/CSolver.hpp +++ b/SU2_CFD/include/solvers/CSolver.hpp @@ -82,40 +82,6 @@ class CSolver { vector NonLinRes_Series; /*!< \brief Vector holding the nonlinear residual indicator series. */ su2double Old_Func, /*!< \brief Old value of the nonlinear residual indicator. */ New_Func; /*!< \brief Current value of the nonlinear residual indicator. */ - /*--- State of the residual-driven CFL adaption, a negative ceiling or cap means none is active. ---*/ - vector ResTrend_History; /*!< \brief Recent mean log residuals. */ - vector> ResJump_History; /*!< \brief Recent log residuals of the flow variables. */ - vector> ResFlow_History; /*!< \brief Recent log residuals of the flow variables. */ - vector ResMean_History; /*!< \brief Recent mean log residuals of the flow variables. */ - passivedouble ResRise = 0.0; /*!< \brief Rise of the flow residual above its recent best. */ - unsigned long CFL_LastFlip = 0; /*!< \brief Iteration of the last flip-flop. */ - unsigned long CFL_LastRegress = 0; /*!< \brief Iteration of the last residual regression. */ - bool ResTrend_Increase = false; /*!< \brief The residual trend allows a larger CFL. */ - bool ResTrend_Reduce = false; /*!< \brief The residual trend requires a smaller CFL. */ - bool CFL_Cut = false; /*!< \brief Halve the CFL in this update. */ - passivedouble CFL_Ceiling = -1.0; /*!< \brief Temporary ceiling after a cut. */ - passivedouble CFL_Cap = -1.0; /*!< \brief Lasting limit learned from repeated events. */ - vector CFL_EventValues; /*!< \brief CFL at each cut. */ - unsigned long CFL_LastEvent = 0; /*!< \brief Iteration of the last cut. */ - unsigned long CFL_LastCapProbe = 0; /*!< \brief Iteration of the last cap increase. */ - vector> ResStall_History; /*!< \brief Log flow residuals over two stall windows. */ - vector CFLStall_History; /*!< \brief Mean CFL over two stall windows. */ - unsigned long Stall_Streak = 0; /*!< \brief Consecutive iterations without envelope progress. */ - unsigned long CFL_LastStall = 0; /*!< \brief Iteration of the last plateau probe decision. */ - passivedouble CFL_StallCap = -1.0; /*!< \brief Cap kept after a plateau probe, which cap increases stay below. */ - passivedouble CFL_OscLevel = -1.0; /*!< \brief Lowest CFL at which the residuals flip-flopped. */ - unsigned long CFL_LastOscRelease = 0; /*!< \brief Iteration of the last flip-flop limit increase. */ - passivedouble Res_AtOsc = 0.0; /*!< \brief Mean log flow residual at that flip-flop. */ - bool Trial_Active = false; /*!< \brief A CFL cut at a residual plateau is being evaluated. */ - bool Trial_Off = false; /*!< \brief A probe showed slower convergence at the lower CFL, no more probes. */ - unsigned long Trial_Start = 0; /*!< \brief Iteration of the probe cut. */ - unsigned long Trial_Hold = 0; /*!< \brief No probe starts before this iteration. */ - passivedouble Trial_Rate = 0.0; /*!< \brief Residual fall before the probe, in decades per 100 iterations. */ - passivedouble Trial_CFL = 0.0; /*!< \brief CFL at the plateau, which sets how far a kept cut may grow back. */ - passivedouble Trial_MaxRate = 1e30; /*!< \brief A probe starts only below this residual fall. */ - passivedouble Trial_Ceiling = -1.0; /*!< \brief CFL ceiling before the probe. */ - passivedouble Trial_Cap = -1.0; /*!< \brief CFL cap before the probe. */ - passivedouble Trial_StallCap = -1.0; /*!< \brief Plateau cap before the probe. */ unsigned short nVar, /*!< \brief Number of variables of the problem. */ nPrimVar, /*!< \brief Number of primitive variables of the problem. */ nPrimVarGrad, /*!< \brief Number of primitive variables of the problem in the gradient computation. */ diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index 02d573c06757..cbc602fd3731 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -158,12 +158,13 @@ void CMultiGridIntegration::SetCoarseGridCFL(CGeometry ****geometry, CSolver *** mg_ramp_mesh0_active = FullMG_Mesh0Ramping(config[iZone], FinestMesh, FullMG); - /*--- Coarse targets are derived from the level-0 CFL via MG_CFL_SCALING. ---*/ + /*--- The active level takes the level-0 CFL, the levels below it are scaled via MG_CFL_SCALING. ---*/ passivedouble cfl_base = mesh0_ramp_window ? passivedouble{0.0} : SU2_TYPE::GetValue(sol_f->GetAvg_CFL_Local()); if (cfl_base < EPS) cfl_base = SU2_TYPE::GetValue(config[iZone]->GetCFL(MESH_0)); const auto& cflScaling = config[iZone]->GetMGOptions().MG_CflScaling; + const unsigned short activeLevel = FullMG ? FinestMesh : MESH_0; passivedouble CFL_target[MAX_MG_LEVELS+1]; passivedouble CFL_scale[MAX_MG_LEVELS+1]; @@ -176,7 +177,7 @@ void CMultiGridIntegration::SetCoarseGridCFL(CGeometry ****geometry, CSolver *** const passivedouble scale = max(passivedouble{1e-6}, min(passivedouble{1.0}, SU2_TYPE::GetValue(cflScaling[iScale]))); CFL_scale[lvl] = scale; - CFL_target[lvl] = CFL_target[lvl-1] * scale; + CFL_target[lvl] = (lvl <= activeLevel) ? cfl_base : CFL_target[lvl-1] * scale; } /*--- Ramp from the CFL the level below handed over at. The coarsest level has none and starts diff --git a/SU2_CFD/src/solvers/CSolver.cpp b/SU2_CFD/src/solvers/CSolver.cpp index b1e23942b835..25657493131a 100644 --- a/SU2_CFD/src/solvers/CSolver.cpp +++ b/SU2_CFD/src/solvers/CSolver.cpp @@ -1919,6 +1919,9 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, const su2double startingIter = config->GetCFL_AdaptParam(5); const bool fullComms = (config->GetComm_Level() == COMM_FULL); + /* Number of iterations considered to check for stagnation. */ + const auto Res_Count = min(100ul, config->GetnInner_Iter()-1); + static bool reduceCFL, resetCFL, canIncrease; for (unsigned short iMesh = 0; iMesh <= config->GetnMGLevels(); iMesh++) { @@ -1968,9 +1971,14 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, canIncrease = (linRes < linTol) && (iter >= startingIter); - if (!config->OptionIsSet("OUTLIER_MITIGATION_PARAM") && iMesh == MESH_0) { + /* Do not use the residual flip-flop criteria when we are mitigating outliers + * because the former was never very reliable for large cases where monotonic + * residual reduction is impossible to achieve. */ + if (!config->OptionIsSet("OUTLIER_MITIGATION_PARAM") && iMesh == MESH_0 && Res_Count > 0) { + Old_Func = New_Func; + if (NonLinRes_Series.empty()) NonLinRes_Series.resize(Res_Count,0.0); - /* Mean of the log RMS residuals of all equations. */ + /* Sum the RMS residuals for all equations. */ New_Func = 0.0; unsigned short totalVars = 0; @@ -1991,307 +1999,41 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, } } New_Func /= totalVars; - } - /*--- The finest-grid nonlinear residuals drive the CFL, so the decision does not depend on how many - * ranks split the preconditioner. The finest grid decides for all levels. ---*/ - - if (!config->OptionIsSet("OUTLIER_MITIGATION_PARAM")) { - constexpr size_t trendWindow = 5, jumpWindow = 3, spikeWindow = 5, frozenWindow = 30; - constexpr passivedouble growBelow = 0.01, shrinkAbove = 0.03, jumpAbove = 0.75, spikeAbove = 1.0; - constexpr passivedouble frozenSpread = 0.05, frozenProgress = 0.02; - constexpr passivedouble linearBrake = 0.5, linearFailure = 0.8; - constexpr unsigned long quietIters = 20, eventGap = 20, bestWindow = 100, regressGap = 5, regressEpisode = 30; - constexpr unsigned long capProbeQuiet = 50; - constexpr passivedouble capProbeFactor = 1.3, eventCapFactor = 0.8, eventMatch = 1.5, cutFactor = 0.7; - constexpr size_t flipWindow = 10, stuckWindow = 15; - constexpr passivedouble regressAbove = 1.0, regressCap = 0.3, growBelowBest = 0.5; - constexpr passivedouble stuckSpread = 0.15, flipAmplitude = 0.03, flipProgress = 0.15; - constexpr size_t stallWindow = 100; - constexpr unsigned long stallPersist = 20; - constexpr passivedouble stallProgress = 0.1, stallGrowth = 1.1; - constexpr size_t rateWindow = 100; - static_assert(rateWindow <= bestWindow, "The rate window must fit in the stored residual history."); - constexpr unsigned long trialHold = 300, trialTransient = 40; - constexpr passivedouble trialCut = 0.35, trialRegrow = 0.7, trialGain = 1.3, trialNoise = 0.03, trialRetry = 0.5; - constexpr passivedouble fallingSlope = 0.3; - constexpr passivedouble oscCap = 0.5, oscReset = 3.0, oscRelease = 1.2; - constexpr unsigned long oscQuiet = 100; - - if (iMesh == MESH_0) { - const passivedouble avgCFL = SU2_TYPE::GetValue(Avg_CFL_Local); - - /*--- Short-window trend of the mean log residual. ---*/ - ResTrend_History.push_back(SU2_TYPE::GetValue(New_Func)); - if (ResTrend_History.size() > trendWindow + 1) ResTrend_History.erase(ResTrend_History.begin()); - const bool full = (ResTrend_History.size() > trendWindow); - const passivedouble trend = full ? (ResTrend_History.back() - ResTrend_History.front()) / trendWindow : 0.0; - ResTrend_Increase = full && (trend < growBelow); - ResTrend_Reduce = full && (trend > shrinkAbove); - - /*--- A divergence raises all flow residuals together, a transient usually only one, so the jump - * is the median rise over the flow variables. ---*/ - vector logRes(solverFlow->GetnVar()); - for (auto iVar = 0u; iVar < solverFlow->GetnVar(); iVar++) - logRes[iVar] = log10(SU2_TYPE::GetValue(solverFlow->GetRes_RMS(iVar))); - ResJump_History.push_back(logRes); - if (ResJump_History.size() > spikeWindow + 1) ResJump_History.erase(ResJump_History.begin()); - bool jump = false; - if (ResJump_History.size() > jumpWindow) { - const auto& past = ResJump_History[ResJump_History.size() - 1 - jumpWindow]; - vector rise(logRes.size()); - for (auto iVar = 0u; iVar < logRes.size(); iVar++) rise[iVar] = logRes[iVar] - past[iVar]; - sort(rise.begin(), rise.end()); - const auto n = rise.size(); - jump = (0.5 * (rise[(n - 1) / 2] + rise[n / 2]) > jumpAbove); - } - /*--- A spike in a single equation, such as the energy at a stagnation corner, is the first sign of - * a CFL that is too high even when the other residuals do not move. ---*/ - if (ResJump_History.size() > spikeWindow) { - for (auto iVar = 0u; iVar < logRes.size(); iVar++) - jump = jump || (logRes[iVar] - ResJump_History.front()[iVar] > spikeAbove); - } + /* Compute the difference in the nonlinear residuals between the + current and previous iterations, taking care with very low initial + residuals (due to initialization). */ - /*--- Flow residuals that all stop falling are frozen. The turbulence residual may still fall, so it - * is left out. The CFL cannot go below its lower limit, so nothing is done there. ---*/ - const passivedouble cflMin = SU2_TYPE::GetValue(CFLMin); - ResFlow_History.push_back(logRes); - if (ResFlow_History.size() > frozenWindow + 1) ResFlow_History.erase(ResFlow_History.begin()); - bool frozen = (ResFlow_History.size() > frozenWindow) && (iter >= startingIter + frozenWindow) && - (iter > CFL_LastEvent + frozenWindow) && (iter > CFL_LastStall + frozenWindow) && - (avgCFL > 1.05 * cflMin); - for (auto iVar = 0u; frozen && (iVar < logRes.size()); iVar++) { - passivedouble lowest = ResFlow_History.front()[iVar], highest = lowest; - for (const auto& past : ResFlow_History) { - lowest = min(lowest, past[iVar]); - highest = max(highest, past[iVar]); - } - frozen = (ResFlow_History.front()[iVar] - ResFlow_History.back()[iVar] < frozenProgress) && - (highest - lowest < frozenSpread); - } + if ((config->GetInnerIter() == 1) && (New_Func - Old_Func > 10)) { + Old_Func = New_Func; + } + NonLinRes_Series[NonLinRes_Counter] = New_Func - Old_Func; - /*--- A divergence that grows slowly never looks like a jump from one iteration to the next, so the - * flow residual is also compared with its best value of the last bestWindow iterations. A residual - * far above it that no longer moves is stuck at a CFL that is too high. ---*/ - passivedouble flowMean = 0.0; - for (const auto value : logRes) flowMean += value / logRes.size(); - if (iter >= startingIter) { - ResMean_History.push_back(flowMean); - if (ResMean_History.size() > bestWindow + 1) ResMean_History.erase(ResMean_History.begin()); - } - passivedouble best = flowMean; - for (const auto value : ResMean_History) best = min(best, value); - ResRise = (iter >= startingIter) ? flowMean - best : 0.0; - bool regress = (ResRise > regressAbove) && (iter >= CFL_LastEvent + regressGap); - if (!regress && (ResMean_History.size() >= stuckWindow) && (ResRise > regressAbove) && - (iter >= CFL_LastEvent + stuckWindow)) { - passivedouble lowest = ResMean_History.back(), highest = lowest; - for (auto k = ResMean_History.size() - stuckWindow; k < ResMean_History.size(); ++k) { - lowest = min(lowest, ResMean_History[k]); - highest = max(highest, ResMean_History[k]); - } - regress = (highest - lowest < stuckSpread); - } + /* Increment the counter, if we hit the max size, then start over. */ - /*--- Most flow residuals that alternate up and down at every iteration without net progress are a - * flip-flop, which a CFL that is too high produces. ---*/ - bool flip = (ResFlow_History.size() > flipWindow) && (iter >= startingIter + flipWindow) && - (iter >= CFL_LastEvent + flipWindow) && (iter >= CFL_LastFlip + flipWindow); - if (flip) { - const auto nHist = ResFlow_History.size(); - unsigned short nAlternating = 0; - passivedouble progress = 0.0; - for (auto iVar = 0u; iVar < logRes.size(); iVar++) { - unsigned short nChanges = 0; - passivedouble amplitude = 0.0; - for (auto k = nHist - flipWindow; k < nHist; ++k) { - const auto d1 = ResFlow_History[k][iVar] - ResFlow_History[k - 1][iVar]; - amplitude += fabs(d1) / flipWindow; - if (k > nHist - flipWindow) { - const auto d0 = ResFlow_History[k - 1][iVar] - ResFlow_History[k - 2][iVar]; - if (d0 * d1 < 0.0) nChanges++; - } - } - if ((size_t(nChanges) + 1 >= flipWindow - 1) && (amplitude > flipAmplitude)) nAlternating++; - progress += (ResFlow_History[nHist - 1 - flipWindow][iVar] - ResFlow_History.back()[iVar]) / logRes.size(); - } - flip = (nAlternating * 4 >= logRes.size() * 3) && (progress < flipProgress); - } - if (flip) CFL_LastFlip = iter; - - /*--- Residuals that stop falling while the CFL no longer grows are stalled, whatever the shape of - * their oscillation. The upper envelope of each residual over a window is compared with that of - * the window before. ---*/ - ResStall_History.push_back(logRes); - CFLStall_History.push_back(avgCFL); - if (ResStall_History.size() > 2 * stallWindow) { - ResStall_History.erase(ResStall_History.begin()); - CFLStall_History.erase(CFLStall_History.begin()); - } - bool stall = false; - if ((ResStall_History.size() == 2 * stallWindow) && (iter >= startingIter + 2 * stallWindow) && - (iter >= max(CFL_LastEvent, CFL_LastStall) + stallWindow) && (avgCFL > 1.05 * cflMin)) { - passivedouble progress = 0.0; - for (auto iVar = 0u; iVar < logRes.size(); iVar++) { - passivedouble envOld = ResStall_History.front()[iVar], envNew = ResStall_History.back()[iVar]; - for (size_t k = 0; k < stallWindow; k++) { - envOld = max(envOld, ResStall_History[k][iVar]); - envNew = max(envNew, ResStall_History[k + stallWindow][iVar]); - } - progress += (envOld - envNew) / logRes.size(); - } - const bool cflFlat = (avgCFL < stallGrowth * CFLStall_History[stallWindow - 1]); - Stall_Streak = ((progress < stallProgress) && cflFlat) ? Stall_Streak + 1 : 0; - stall = (Stall_Streak >= stallPersist); - } else { - Stall_Streak = 0; - } - /*--- One CFL cut probes a plateau, and the residual fall after its transient decides what stays. ---*/ - const auto nMean = ResMean_History.size(); - auto meanRate = [&]() { /* Least-squares fall of the mean residual, in decades per 100 iterations. */ - passivedouble sumX = 0.0, sumY = 0.0, sumXY = 0.0, sumXX = 0.0; - for (size_t k = 0; k <= rateWindow; k++) { - const passivedouble y = ResMean_History[nMean - 1 - rateWindow + k]; - sumX += k; sumY += y; sumXY += k * y; sumXX += passivedouble(k) * k; - } - const passivedouble n = rateWindow + 1; - return -100.0 * (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX); - }; - auto rateText = [](passivedouble rate) { - std::ostringstream text; - text << std::fixed << std::setprecision(3) << rate; - return text.str(); - }; - bool probeEnded = false; - if (Trial_Active && (CFL_LastEvent > Trial_Start)) { - Trial_Active = false; - probeEnded = true; - CFL_StallCap = Trial_StallCap; - if (rank == MASTER_NODE) cout << "CFL_ADAPT: probe ended by the CFL cut at iteration " << CFL_LastEvent << "." << endl; - } - if (Trial_Active && (iter >= Trial_Start + trialTransient + rateWindow)) { - const passivedouble rate = meanRate(); - Trial_Active = false; - probeEnded = true; - CFL_LastStall = iter; - Stall_Streak = 0; - std::ostringstream verdict; - if (rate >= trialGain * max(Trial_Rate, passivedouble(0.0)) + trialNoise) { - CFL_StallCap = max(trialRegrow * Trial_CFL, CFL_Cap); - verdict << "CFL cut kept, its cap may grow to " << CFL_StallCap << "."; - } else { - CFL_Cap = Trial_Cap; - CFL_Ceiling = Trial_Ceiling; - CFL_StallCap = Trial_StallCap; - if (rate < Trial_Rate - trialNoise) { - Trial_Off = true; - CFL_StallCap = -1.0; - verdict << "CFL cut undone, no more probes."; - } else { - Trial_Hold = iter + trialHold; - Trial_MaxRate = min(trialRetry * Trial_Rate, Trial_Rate - trialNoise); - verdict << "CFL cut undone."; - } - } - if (rank == MASTER_NODE) - cout << "CFL_ADAPT: probe at iteration " << iter << ", residuals fall " << rateText(rate) << " against " - << rateText(Trial_Rate) << " decades per 100 iterations, " << verdict.str() << endl; - } - if ((frozen || stall) && !Trial_Active && !Trial_Off && !probeEnded && (iter >= Trial_Hold) && - (nMean > rateWindow)) { - const passivedouble rate = meanRate(); - /*--- No probe while the first flow residual reaches its target within the iteration limit. ---*/ - const passivedouble decades = logRes[0] - SU2_TYPE::GetValue(config->GetMinLogResidual()); - const unsigned long nIter = config->GetMultizone_Problem() ? config->GetnOuter_Iter() : config->GetnInner_Iter(); - const passivedouble remaining = (nIter > iter) ? passivedouble(nIter - iter) : 0.0; - const bool onTime = (decades <= 0.0) || ((rate > 0.0) && (100.0 * decades <= rate * remaining)); - if ((rate < min(fallingSlope, Trial_MaxRate)) && !onTime) { - Trial_Active = true; - Trial_Start = iter; - Trial_Rate = rate; - Trial_CFL = (CFL_Cap > 0.0) ? min(CFL_Cap, avgCFL) : avgCFL; - Trial_Ceiling = CFL_Ceiling; - Trial_Cap = CFL_Cap; - Trial_StallCap = CFL_StallCap; - CFL_Cap = max(trialCut * Trial_CFL, cflMin); - CFL_Ceiling = CFL_Cap; - CFL_StallCap = CFL_Cap; - CFL_LastStall = iter; - Stall_Streak = 0; - if (rank == MASTER_NODE) - cout << "CFL_ADAPT: residuals " << (frozen ? "frozen" : "stalled") << " at iteration " << iter - << ", falling " << rateText(rate) << " decades per 100 iterations, CFL capped at " << CFL_Cap - << " to probe." << endl; - } - } + NonLinRes_Counter++; + if (NonLinRes_Counter == Res_Count) NonLinRes_Counter = 0; - /*--- Halve the CFL on a jump or a failed linear solve and keep it below a ceiling. A second event - * near the CFL of an earlier one sets a lasting cap below both. ---*/ - CFL_Cut = (jump || regress || flip || (linRes > linearFailure)) && (iter >= CFL_LastEvent + jumpWindow) && - (avgCFL > 1.05 * cflMin); - if (CFL_Cut) { - /*--- Cuts that follow each other closely belong to one event, only its first CFL is recorded. ---*/ - if (iter >= CFL_LastEvent + eventGap) { - for (const auto eventCFL : CFL_EventValues) - if ((avgCFL < eventMatch * eventCFL) && (eventCFL < eventMatch * avgCFL)) { - const passivedouble cap = max(eventCapFactor * min(eventCFL, avgCFL), cflMin); - CFL_Cap = (CFL_Cap > 0.0) ? min(CFL_Cap, cap) : cap; - } - CFL_EventValues.push_back(avgCFL); - } - if (regress && (iter >= CFL_LastRegress + regressEpisode)) { - const passivedouble cap = max(regressCap * avgCFL, cflMin); - CFL_Cap = (CFL_Cap > 0.0) ? min(CFL_Cap, cap) : cap; - } - if (regress) CFL_LastRegress = iter; - /*--- Flip-flops bound the CFL below the lowest level that produced one. ---*/ - if (flip) { - CFL_OscLevel = (CFL_OscLevel > 0.0) ? min(CFL_OscLevel, avgCFL) : avgCFL; - Res_AtOsc = flowMean; - const passivedouble cap = max(oscCap * CFL_OscLevel, cflMin); - CFL_Cap = (CFL_Cap > 0.0) ? min(CFL_Cap, cap) : cap; - } - CFL_Ceiling = (CFL_Cap > 0.0) ? min(cutFactor * avgCFL, CFL_Cap) : cutFactor * avgCFL; - CFL_LastEvent = iter; - if (rank == MASTER_NODE) - cout << "CFL_ADAPT: " - << (jump ? "residual jump" : regress ? "residual regression" : flip ? "residual flip-flop" : "linear solver failure") - << " at iteration " << iter << ", CFL halved from " << avgCFL << "." << endl; - } + /* Detect flip-flop convergence to reduce CFL and large increases + to reset to minimum value, in that case clear the history. */ - /*--- A cap that has held the CFL through a quiet, converging stretch is raised, so that it does not - * outlive the transient that caused it. A new event at the higher CFL brings it back down. It - * stays below the cap kept after a plateau probe and below the flip-flop limit, which itself rises - * in small steps over quiet, converging stretches. ---*/ - if ((CFL_OscLevel > 0.0) && (flowMean < Res_AtOsc - oscReset)) CFL_OscLevel = -1.0; - if ((CFL_OscLevel > 0.0) && (iter > max(CFL_LastEvent, CFL_LastOscRelease) + oscQuiet) && ResTrend_Increase && - (ResRise < growBelowBest)) { - CFL_OscLevel *= oscRelease; - CFL_LastOscRelease = iter; - } - passivedouble probeLimit = (CFL_StallCap > 0.0) ? CFL_StallCap : 1e30; - if (CFL_OscLevel > 0.0) probeLimit = min(probeLimit, max(oscCap * CFL_OscLevel, cflMin)); - if ((CFL_Cap > 0.0) && (avgCFL > 0.95 * CFL_Cap) && (iter > max(CFL_LastEvent, CFL_LastStall) + capProbeQuiet) && - (iter > CFL_LastCapProbe + capProbeQuiet) && !Trial_Active && ResTrend_Increase && (ResRise < growBelowBest) && - (CFL_Cap < probeLimit)) { - CFL_Cap = min(CFL_Cap * capProbeFactor, probeLimit); - CFL_LastCapProbe = iter; - CFL_EventValues.clear(); + if (config->GetInnerIter() >= Res_Count) { + unsigned long signChanges = 0; + su2double totalChange = 0.0; + auto prev = NonLinRes_Series.front(); + for (const auto& val : NonLinRes_Series) { + totalChange += val; + signChanges += (prev > 0) ^ (val > 0); + prev = val; } + reduceCFL |= (signChanges > Res_Count/4) && (totalChange > -0.5); - /*--- Lift the ceiling again while the residuals fall, up to the cap. ---*/ - if ((CFL_Ceiling > 0.0) && (iter > CFL_LastEvent + quietIters) && !Trial_Active && ResTrend_Increase && (ResRise < growBelowBest)) { - CFL_Ceiling *= 1.05; - if (CFL_Cap > 0.0) CFL_Ceiling = min(CFL_Ceiling, CFL_Cap); - else if (CFL_Ceiling > SU2_TYPE::GetValue(CFLMax)) CFL_Ceiling = -1.0; + if (totalChange > 2.0) { // orders of magnitude + resetCFL = true; + NonLinRes_Counter = 0; + for (auto& val : NonLinRes_Series) val = 0.0; } } - - /*--- These replace the linear-residual and oscillation rules above. A poor linear solve holds the - * CFL back gently, a failed one halves it above. ---*/ - canIncrease = ResTrend_Increase && !Trial_Active && (linRes < linearBrake) && (iter >= startingIter) && (ResRise < growBelowBest); - reduceCFL = (ResTrend_Reduce || (linRes > linearBrake)) && (iter >= startingIter); - resetCFL = false; } } /* End safe global access, now all threads update the CFL number. */ END_SU2_OMP_SAFE_GLOBAL_ACCESS @@ -2342,12 +2084,12 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, CFLFactor = CFLFactorIncrease; } - /* Check if we are hitting the min or max and adjust. */ + /* Check if we are hitting the min or max and adjust, the limits scale with the level. */ - if (CFL * CFLFactor <= CFLMin * MGFactor[iMesh]) { - CFL = CFLMin; + if (CFL*CFLFactor <= CFLMin*MGFactor[iMesh]) { + CFL = CFLMin; CFLFactor = MGFactor[iMesh]; - } else if (CFL * CFLFactor >= CFLMax * MGFactor[iMesh]) { + } else if (CFL*CFLFactor >= CFLMax*MGFactor[iMesh]) { CFL = CFLMax; CFLFactor = MGFactor[iMesh]; } @@ -2362,10 +2104,7 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry, /* Apply the adjustment to the CFL and store local values. */ - if (CFL_Cut) CFLFactor = 0.5; CFL *= CFLFactor; - if (CFL_Cut) CFL = max(CFL, CFLMin * MGFactor[iMesh]); - if ((CFL_Ceiling > 0.0) && (CFL > CFL_Ceiling)) CFL = max(su2double(CFL_Ceiling), CFLMin); solverFlow->GetNodes()->SetLocalCFL(iPoint, CFL); if ((iMesh == MESH_0) && solverTurb) { solverTurb->GetNodes()->SetLocalCFL(iPoint, CFL * CFLTurbReduction); diff --git a/config_template.cfg b/config_template.cfg index c9074a9362d8..c8617b3268d1 100644 --- a/config_template.cfg +++ b/config_template.cfg @@ -1579,19 +1579,6 @@ NUM_METHOD_GRAD_RECON = LEAST_SQUARES CFL_NUMBER= 15.0 % % Adaptive CFL number (NO, YES) -% The CFL is adapted on the finest-grid nonlinear residuals, which makes it independent of the number -% of MPI ranks. It grows while the residuals do not rise and shrinks when they rise. The CFL is halved -% and kept below a ceiling that lifts while the residuals fall on: a sudden residual jump (also of a -% single flow equation), a flow residual more than one order of magnitude above its best value of the -% last 100 iterations (also when it stays there), most flow residuals alternating up and down at every -% iteration without progress (flip-flop), or a failed linear solve. The CFL does not grow while the -% residual is far above its best value. Repeated events, a regression, a flip-flop, or all flow -% residuals stalling for 30 iterations cap the CFL lasting below the level where that happened. Flow -% residuals whose upper envelope stops falling over 100 iterations while the CFL no longer grows cap -% the CFL at half its value, a quarter on a second such stall, an eighth on a third. A flip-flop caps -% the CFL at half the lowest CFL where one occurred, until the residuals fall three orders of magnitude. Uses -% factor up/down and the CFL limits of CFL_ADAPT_PARAM, and never goes below the lower limit. With -% OUTLIER_MITIGATION_PARAM the CFL is adapted on the linear solver convergence instead. CFL_ADAPT= NO % % Parameters of the adaptive CFL number (factor-down, factor-up, CFL min value, From 410ebd28a8635cf16728d428a73e9cbf271b24b4 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sat, 5 Dec 2026 12:10:05 +0100 Subject: [PATCH 39/42] Fix the AD build, bound the ParMETIS anisotropy weights, drop per-rank diagnostics The stiffness ratio of the front paving is passive, which fixes the AD compilation. The anisotropy edge weight is clamped in floating point before conversion to idx_t, and capped so that the sum of all weights stays within half the range of idx_t, with an error if the graph is too large for 32-bit indices. The correction-peak and per-rank closure dumps of MG_SMOOTH_OUTPUT are removed, the closure summary stays on the master rank. Co-Authored-By: Claude Sonnet 5.5 --- Common/src/geometry/CMultiGridGeometry.cpp | 16 ++++---- Common/src/geometry/CPhysicalGeometry.cpp | 21 +++++++++-- SU2_CFD/src/drivers/CDriver.cpp | 37 +++---------------- .../src/integration/CMultiGridIntegration.cpp | 36 ------------------ 4 files changed, 32 insertions(+), 78 deletions(-) diff --git a/Common/src/geometry/CMultiGridGeometry.cpp b/Common/src/geometry/CMultiGridGeometry.cpp index f6c4e24fe97f..6c9c902218a2 100644 --- a/Common/src/geometry/CMultiGridGeometry.cpp +++ b/Common/src/geometry/CMultiGridGeometry.cpp @@ -762,7 +762,8 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un auto removeChild = [&](unsigned long fromCV, unsigned long iFinePoint) { vector kept; for (auto iChildren = 0u; iChildren < nodes->GetnChildren_CV(fromCV); iChildren++) - if (nodes->GetChildren_CV(fromCV, iChildren) != iFinePoint) kept.push_back(nodes->GetChildren_CV(fromCV, iChildren)); + if (nodes->GetChildren_CV(fromCV, iChildren) != iFinePoint) + kept.push_back(nodes->GetChildren_CV(fromCV, iChildren)); nodes->SetChildren_CV(fromCV, kept); nodes->SetnChildren_CV(fromCV, kept.size()); }; @@ -940,7 +941,8 @@ CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, un vector group, around; auto isChildOf = [&](unsigned long iFinePoint, unsigned long iCV, unsigned long except) { - return (iFinePoint != except) && (iFinePoint < nFineDomain) && (fine_grid->nodes->GetParent_CV(iFinePoint) == iCV); + return (iFinePoint != except) && (iFinePoint < nFineDomain) && + (fine_grid->nodes->GetParent_CV(iFinePoint) == iCV); }; /*--- Whether the children of a CV other than one excluded point form one connected set. ---*/ @@ -2482,21 +2484,21 @@ string CMultiGridGeometry::PaveAdvancingFronts(unsigned long& Index_CoarseCV, co * stops only at a much thinner layer, so moderate stretching does not cut it short. ---*/ auto stiffStep = [&](const vector& set) { const passivedouble STIFF_FRACTION = (tierOf[iColumn] <= 1) ? 0.01 : 0.1; - su2double ratio = 0.0; + passivedouble ratio = 0.0; for (auto iPoint : layer[iColumn]) { - su2double wStep = 0.0, wMax = 0.0; + passivedouble wStep = 0.0, wMax = 0.0; for (auto iNeigh = 0u; iNeigh < fine_grid->nodes->GetnPoint(iPoint); ++iNeigh) { const auto jPoint = fine_grid->nodes->GetPoint(iPoint, iNeigh); const auto iEdge = fine_grid->nodes->GetEdge(iPoint, iNeigh); - const su2double w = + const passivedouble w = SU2_TYPE::GetValue( GeometryToolbox::Norm(nDim, fine_grid->edges->GetNormal(iEdge)) * - (1.0 / fine_grid->nodes->GetVolume(iPoint) + 1.0 / fine_grid->nodes->GetVolume(jPoint)); + (1.0 / fine_grid->nodes->GetVolume(iPoint) + 1.0 / fine_grid->nodes->GetVolume(jPoint))); wMax = std::max(wMax, w); if (std::find(set.begin(), set.end(), jPoint) != set.end()) wStep = std::max(wStep, w); } ratio += (wMax > 0.0) ? wStep / wMax : 1.0; } - return ratio >= STIFF_FRACTION * su2double(layer[iColumn].size()); + return ratio >= STIFF_FRACTION * passivedouble(layer[iColumn].size()); }; /*--- Whether every node of the step reaches a physical boundary within a few steps on the diff --git a/Common/src/geometry/CPhysicalGeometry.cpp b/Common/src/geometry/CPhysicalGeometry.cpp index 72b8a94fdc8f..03dcf5a81232 100644 --- a/Common/src/geometry/CPhysicalGeometry.cpp +++ b/Common/src/geometry/CPhysicalGeometry.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #ifdef _MSC_VER @@ -7671,9 +7672,9 @@ vector CPhysicalGeometry::ComputeAnisotropyEdgeWeights(long maxWeight) co const auto it = lower_bound(begin, end, jGlobal); if ((it == end) || (*it != jGlobal)) continue; - const auto ratio = static_cast(sqrt(maxDist2 / d2)); + const passivedouble ratio = min(passivedouble(maxWeight), max(1.0, sqrt(maxDist2 / d2))); auto& w = weight[it - adjacency.begin()]; - w = max(w, min(maxWeight, max(1, ratio))); + w = max(w, static_cast(ratio)); } } } @@ -7734,13 +7735,25 @@ void CPhysicalGeometry::SetColorGrid_Parallel(const CConfig* config) { /*--- Keep partition boundaries off the short edges of anisotropic cells. The edges that chain * points into wall-normal lines get the largest weight, so the graph coarsening merges each - * line before it balances. The cap keeps the total edge weight within the range of idx_t. ---*/ + * line before it balances. The cap keeps the sum of all edge weights within half the range of idx_t. ---*/ const bool anisotropic = config->GetParMETIS_AnisotropyWeight(); vector adjwgt; vector lineRoot; if (anisotropic) { - constexpr long maxWeight = (sizeof(idx_t) >= 8) ? 1000000 : 1000; + unsigned long nEntries = adjacency.size(), nEntriesGlobal = 0; + SU2_MPI::Allreduce(&nEntries, &nEntriesGlobal, 1, MPI_UNSIGNED_LONG, MPI_SUM, comm); + + constexpr long MAX_WEIGHT = 1000000; + constexpr long MIN_WEIGHT = 16; + const long maxWeight = min( + MAX_WEIGHT, static_cast(numeric_limits::max() / 2 / max(nEntriesGlobal, 1))); + if (maxWeight < MIN_WEIGHT) { + SU2_MPI::Error( + "PARMETIS_ANISOTROPY_WEIGHT needs 64-bit ParMETIS indices for a graph of this size, the edge weights " + "would overflow.", + CURRENT_FUNCTION); + } adjwgt = ComputeAnisotropyEdgeWeights(maxWeight); vector lineEdge; lineRoot = LinkAnisotropicLines(adjwgt, lineEdge); diff --git a/SU2_CFD/src/drivers/CDriver.cpp b/SU2_CFD/src/drivers/CDriver.cpp index 6e0c82efb50d..29b6eaa517cd 100644 --- a/SU2_CFD/src/drivers/CDriver.cpp +++ b/SU2_CFD/src/drivers/CDriver.cpp @@ -822,9 +822,9 @@ void CDriver::InitializeGeometryFVM(CConfig *config, CGeometry **&geometry) { return range; }; - /*--- The face normals of a closed control volume sum to zero. Reports the CV with the largest - * sum relative to the sum of the face areas, and how many CVs exceed a small tolerance. ---*/ - auto closureReport = [&](const CGeometry* grid, const CGeometry* fine, unsigned short iLevel) { + /*--- The face normals of a closed control volume sum to zero. Reports the largest sum + * relative to the sum of the face areas, and how many CVs exceed a small tolerance. ---*/ + auto closureReport = [&](const CGeometry* grid, unsigned short iLevel) { const auto nDomain = grid->GetnPointDomain(); const auto nDim = grid->GetnDim(); vector> boundary(nDomain, {0.0, 0.0, 0.0}); @@ -839,7 +839,7 @@ void CDriver::InitializeGeometryFVM(CConfig *config, CGeometry **&geometry) { } passivedouble worst = 0.0; - unsigned long worstPoint = 0, nBad = 0, nBadGlobal = 0; + unsigned long nBad = 0, nBadGlobal = 0; for (auto iPoint = 0ul; iPoint < nDomain; iPoint++) { std::array sum = boundary[iPoint]; passivedouble area = 0.0; @@ -859,10 +859,7 @@ void CDriver::InitializeGeometryFVM(CConfig *config, CGeometry **&geometry) { for (auto iDim = 0u; iDim < nDim; iDim++) defect += sum[iDim] * sum[iDim]; defect = sqrt(defect) / max(area, std::numeric_limits::min()); if (defect > 1e-6) nBad++; - if (defect > worst) { - worst = defect; - worstPoint = iPoint; - } + worst = std::max(worst, defect); } passivedouble worstGlobal = 0.0; CPassiveMPI::Allreduce(&worst, &worstGlobal, 1, MPI_DOUBLE, MPI_MAX, SU2_MPI::GetComm()); @@ -871,28 +868,6 @@ void CDriver::InitializeGeometryFVM(CConfig *config, CGeometry **&geometry) { cout << " MG level " << iLevel << " CV closure: " << nBadGlobal << " CVs with a face normal sum above 1e-6 of the " << "face area, worst " << worstGlobal << "\n"; } - if ((worst >= worstGlobal) && (worst > 1e-6)) { - cout << " MG level " << iLevel << " worst closure on rank " << rank << ", global point " - << grid->nodes->GetGlobalIndex(worstPoint) << ", volume " << grid->nodes->GetVolume(worstPoint) << ", " - << grid->nodes->GetnPoint(worstPoint) << " neighbors, x ="; - for (auto iDim = 0u; iDim < nDim; iDim++) cout << " " << grid->nodes->GetCoord(worstPoint, iDim); - cout << "\n"; - for (auto iChild = 0u; iChild < grid->nodes->GetnChildren_CV(worstPoint); iChild++) { - const auto iFine = grid->nodes->GetChildren_CV(worstPoint, iChild); - cout << " child " << fine->nodes->GetGlobalIndex(iFine) << " volume " << fine->nodes->GetVolume(iFine) - << ", neighbors (global index, h = halo, parent):"; - for (auto jFine : fine->nodes->GetPoints(iFine)) { - const auto parent = fine->nodes->GetParent_CV(jFine); - cout << " " << fine->nodes->GetGlobalIndex(jFine) << (fine->nodes->GetDomain(jFine) ? "" : "h") << ":"; - if (parent == std::numeric_limits::max()) cout << "none"; - else cout << parent; - } - cout << "\n"; - } - cout << " coarse neighbors:"; - for (auto jPoint : grid->nodes->GetPoints(worstPoint)) cout << " " << jPoint << (grid->nodes->GetDomain(jPoint) ? "" : "h"); - cout << " (this CV " << worstPoint << ")\n"; - } }; /*--- Agglomeration should not spread the CV volumes far wider than the fine grid already does. @@ -953,7 +928,7 @@ void CDriver::InitializeGeometryFVM(CConfig *config, CGeometry **&geometry) { geometry[iMGlevel]->SetBoundControlVolume(geometry[iMGlevel-1], config, ALLOCATE); - if (config->GetMGOptions().MG_Smooth_Output) closureReport(geometry[iMGlevel], geometry[iMGlevel-1], iMGlevel); + if (config->GetMGOptions().MG_Smooth_Output) closureReport(geometry[iMGlevel], iMGlevel); geometry[iMGlevel]->SetCoord(geometry[iMGlevel-1]); diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index cbc602fd3731..83b096545d89 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -1380,42 +1380,6 @@ void CMultiGridIntegration::SmoothProlongated_Correction(unsigned short RunTime_ if (config->GetMGOptions().MG_Smooth_Output) { const su2double res = sqrt(solver->LinSysRes.squaredNorm() / (nVar * geometry->GetGlobal_nPointDomain())); SU2_OMP_SAFE_GLOBAL_ACCESS(lastCorrecSmoothRMS[iMesh][0] = SU2_TYPE::GetValue(res);) - - /*--- Report a single point that carries a large share of the correction norm. ---*/ - BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { - constexpr passivedouble peakShare = 0.2; - passivedouble local[2] = {0.0, 0.0}, global[2]; - unsigned long peakPoint = 0; - for (auto iPoint = 0ul; iPoint < geometry->GetnPointDomain(); iPoint++) { - passivedouble sq = 0.0; - for (auto iVar = 0u; iVar < nVar; iVar++) sq += pow(SU2_TYPE::GetValue(solver->LinSysRes(iPoint, iVar)), 2); - local[1] += sq; - if (sq > local[0]) { - local[0] = sq; - peakPoint = iPoint; - } - } - SU2_MPI::Allreduce(&local[0], &global[0], 1, MPI_DOUBLE, MPI_MAX, SU2_MPI::GetComm()); - SU2_MPI::Allreduce(&local[1], &global[1], 1, MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm()); - if ((local[0] >= global[0]) && (global[0] > peakShare * global[1])) { - std::cout << "Corr-peak level " << iMesh << ": rank " << SU2_MPI::GetRank() << ", global point " - << geometry->nodes->GetGlobalIndex(peakPoint) << ", " << 100 * global[0] / global[1] - << "% of the correction norm, volume " << geometry->nodes->GetVolume(peakPoint) << ", " - << geometry->nodes->GetnPoint(peakPoint) << " neighbors, parent CV " - << geometry->nodes->GetParent_CV(peakPoint) << ", x ="; - for (auto iDim = 0u; iDim < geometry->GetnDim(); iDim++) - std::cout << " " << geometry->nodes->GetCoord(peakPoint, iDim); - std::cout << ", correction ="; - for (auto iVar = 0u; iVar < nVar; iVar++) std::cout << " " << solver->LinSysRes(peakPoint, iVar); - std::cout << "\n neighbor volumes (h = halo):"; - for (auto iNeigh = 0u; iNeigh < geometry->nodes->GetnPoint(peakPoint); iNeigh++) { - const auto jPoint = geometry->nodes->GetPoint(peakPoint, iNeigh); - std::cout << " " << geometry->nodes->GetVolume(jPoint) << (geometry->nodes->GetDomain(jPoint) ? "" : "h"); - } - std::cout << std::endl; - } - } - END_SU2_OMP_SAFE_GLOBAL_ACCESS } SU2_OMP_FOR_STAT(roundUpDiv(geometry->GetnPoint(), omp_get_num_threads())) From d23ce725a4f51baeab467de7c10cb3329808f50e Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sat, 5 Dec 2026 14:23:10 +0100 Subject: [PATCH 40/42] Fix the discrete adjoint with OpenMP and multigrid The coarse-grid coordinate and wall-distance exchanges ran inside a single-thread block, but CompleteComms has its own worksharing loop and barriers. In the discrete adjoint recording UpdateGeometry runs inside a parallel region, so the ranks deadlocked. All threads now call the exchanges, as for the fine grid. The discrete adjoint transposes every recorded linear solve with LINEAR_SOLVER_ITER. With MG_LINEAR_SOLVER_ITER capping the forward coarse solves, the reverse sweep had to grow the FGMRES basis inside the parallel region, which stopped the run with "If this class were constructed in parallel". The cap is no longer applied with the discrete adjoint. Co-Authored-By: Claude Opus 5.5 --- Common/src/CConfig.cpp | 8 +++++--- Common/src/geometry/CGeometry.cpp | 17 +++++------------ config_template.cfg | 3 ++- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Common/src/CConfig.cpp b/Common/src/CConfig.cpp index eba05d820c04..97f96dc231c2 100644 --- a/Common/src/CConfig.cpp +++ b/Common/src/CConfig.cpp @@ -2160,7 +2160,8 @@ void CConfig::SetConfig_Options() { * If fewer values than nMGLevels are given, the last value is repeated. DEFAULT: 0.5 \ingroup Config*/ addDoubleListOption("MG_CFL_SCALING", nMG_CflScaling_p, MG_CflScaling_p); /*!\brief MG_LINEAR_SOLVER_ITER\n DESCRIPTION: Maximum linear solver iterations on coarse MG levels. Entry i applies to level i+1; - * the last value is repeated, and the cap never exceeds LINEAR_SOLVER_ITER. DEFAULT: 3 \ingroup Config*/ + * the last value is repeated, and the cap never exceeds LINEAR_SOLVER_ITER. Not applied with the discrete adjoint. + * DEFAULT: 3 \ingroup Config*/ addUShortListOption("MG_LINEAR_SOLVER_ITER", nMG_LinSolIter_p, MG_LinSolIter_p); /*!\par CONFIG_CATEGORY: Spatial Discretization \ingroup Config*/ @@ -5329,9 +5330,10 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i MGOptions.MG_CflScaling[i] = 0.5; } - /*--- Linear solver iteration cap per level; level 0 always uses LINEAR_SOLVER_ITER. ---*/ + /*--- Linear solver iteration cap per level; level 0 always uses LINEAR_SOLVER_ITER. The discrete + * adjoint transposes each recorded solve with LINEAR_SOLVER_ITER, so it caps no level. ---*/ MGOptions.MG_LinSolIter.assign(nMGLevels + 1, Linear_Solver_Iter); - for (unsigned short i = 1; i <= nMGLevels; ++i) { + for (unsigned short i = 1; (i <= nMGLevels) && !DiscreteAdjoint; ++i) { const unsigned long cap = (nMG_LinSolIter_p != 0) ? MG_LinSolIter_p[min(i - 1, nMG_LinSolIter_p - 1)] : 3; MGOptions.MG_LinSolIter[i] = min(cap, Linear_Solver_Iter); } diff --git a/Common/src/geometry/CGeometry.cpp b/Common/src/geometry/CGeometry.cpp index 510c83ca22a7..c1bfc022a157 100644 --- a/Common/src/geometry/CGeometry.cpp +++ b/Common/src/geometry/CGeometry.cpp @@ -2905,14 +2905,10 @@ void CGeometry::UpdateGeometry(CGeometry** geometry_container, CConfig* config) geometry_container[iMesh]->UpdatePeriodicVolumes(config); /*--- SetCoord centred a halo agglomerate on the partial child list this rank holds. Take - the owner's coordinate, otherwise coarse stencils depend on the partitioning. Deformation - runs this inside a parallel region, so only one thread may reach the exchange. ---*/ + the owner's coordinate, otherwise coarse stencils depend on the partitioning. ---*/ - BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { - geometry_container[iMesh]->InitiateComms(geometry_container[iMesh], config, MPI_QUANTITIES::COORDINATES); - geometry_container[iMesh]->CompleteComms(geometry_container[iMesh], config, MPI_QUANTITIES::COORDINATES); - } - END_SU2_OMP_SAFE_GLOBAL_ACCESS + geometry_container[iMesh]->InitiateComms(geometry_container[iMesh], config, MPI_QUANTITIES::COORDINATES); + geometry_container[iMesh]->CompleteComms(geometry_container[iMesh], config, MPI_QUANTITIES::COORDINATES); } /*--- Compute the global surface areas for all markers. ---*/ @@ -4779,11 +4775,8 @@ void RestrictWallDistance(const CGeometry* geo_fine, CGeometry* geo_coarse, cons /*--- A halo agglomerate only holds the children on this rank, so take the owner's values. ---*/ - BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { - geo_coarse->InitiateComms(geo_coarse, config, MPI_QUANTITIES::WALL_DISTANCE); - geo_coarse->CompleteComms(geo_coarse, config, MPI_QUANTITIES::WALL_DISTANCE); - } - END_SU2_OMP_SAFE_GLOBAL_ACCESS + geo_coarse->InitiateComms(geo_coarse, config, MPI_QUANTITIES::WALL_DISTANCE); + geo_coarse->CompleteComms(geo_coarse, config, MPI_QUANTITIES::WALL_DISTANCE); for (unsigned short iMarker = 0; iMarker < config->GetnMarker_All(); ++iMarker) { const auto viscous = config->GetViscous_Wall(iMarker); diff --git a/config_template.cfg b/config_template.cfg index 610af80dd3df..e874b99c574d 100644 --- a/config_template.cfg +++ b/config_template.cfg @@ -1847,7 +1847,8 @@ MG_IMPLICIT_LINES= NO MG_CFL_SCALING= ( 0.5 ) % % Maximum linear solver iterations on the coarse multigrid levels. Entry i applies to level i+1, -% the last value is repeated, and the cap never exceeds LINEAR_SOLVER_ITER (default 3) +% the last value is repeated, and the cap never exceeds LINEAR_SOLVER_ITER. The discrete adjoint +% ignores it (default 3) MG_LINEAR_SOLVER_ITER= ( 3 ) % % Number of iterations spent on each mesh during the Full Multigrid (FMG) startup phase. After From 57b1dc38769ea0fc3521f3cc8cb573c2effecfa3 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sat, 5 Dec 2026 16:40:47 +0100 Subject: [PATCH 41/42] Update regression references for the multigrid changes Values regenerated in the CI containers for all suites. The gradient files of cont_adj_euler, multiple_ffd and the moving-frame pywrapper forces are regenerated from container runs. The unsteady NACA0012 adjoint gradient reference lives in the TestCases data repo and differs by at most 5e-4 % in 5 of 242 entries, so both tests get a 0.001 % file tolerance. Co-Authored-By: Claude Opus 5.5 --- .../naca0012/of_grad_cd_disc.dat.ref | 76 ++-- .../naca0012/of_grad_directdiff.dat.ref | 6 +- TestCases/hybrid_regression.py | 20 +- TestCases/hybrid_regression_AD.py | 6 +- .../multiple_ffd/naca0012/of_grad_cd.dat.ref | 4 +- .../naca0012/of_grad_directdiff.dat.ref | 4 +- TestCases/parallel_regression.py | 46 +- TestCases/parallel_regression_AD.py | 20 +- .../forces_0.csv.ref | 400 +++++++++--------- TestCases/serial_regression.py | 56 +-- TestCases/serial_regression_AD.py | 18 +- TestCases/tutorials.py | 16 +- TestCases/vandv.py | 10 +- 13 files changed, 342 insertions(+), 340 deletions(-) diff --git a/TestCases/cont_adj_euler/naca0012/of_grad_cd_disc.dat.ref b/TestCases/cont_adj_euler/naca0012/of_grad_cd_disc.dat.ref index 2ddfaff9e588..7a4e8fc71040 100644 --- a/TestCases/cont_adj_euler/naca0012/of_grad_cd_disc.dat.ref +++ b/TestCases/cont_adj_euler/naca0012/of_grad_cd_disc.dat.ref @@ -1,39 +1,39 @@ VARIABLES="VARIABLE" , "GRADIENT" , "FINDIFF_STEP" - 0 , -10743.0 , 0.001 - 1 , -12209.1 , 0.001 - 2 , -8820.43 , 0.001 - 3 , -4499.31 , 0.001 - 4 , -666.822 , 0.001 - 5 , 2295.31 , 0.001 - 6 , 4462.58 , 0.001 - 7 , 6094.72 , 0.001 - 8 , 7507.39 , 0.001 - 9 , 9016.3 , 0.001 - 10 , 10913.7 , 0.001 - 11 , 13452.7 , 0.001 - 12 , 16817.9 , 0.001 - 13 , 21036.1 , 0.001 - 14 , 25683.2 , 0.001 - 15 , 28962.7 , 0.001 - 16 , 24836.8 , 0.001 - 17 , -5455.66 , 0.001 - 18 , -105581.0 , 0.001 - 19 , -22082.4 , 0.001 - 20 , -19868.6 , 0.001 - 21 , -12630.5 , 0.001 - 22 , -6543.52 , 0.001 - 23 , -3097.77 , 0.001 - 24 , -2154.9 , 0.001 - 25 , -2997.33 , 0.001 - 26 , -4816.41 , 0.001 - 27 , -6961.91 , 0.001 - 28 , -9055.96 , 0.001 - 29 , -11020.7 , 0.001 - 30 , -13053.2 , 0.001 - 31 , -15554.9 , 0.001 - 32 , -18942.9 , 0.001 - 33 , -23075.0 , 0.001 - 34 , -25752.7 , 0.001 - 35 , -19717.7 , 0.001 - 36 , 11830.8 , 0.001 - 37 , 90755.6 , 0.001 + 0 , -9202.31 , 0.001 + 1 , -11788.8 , 0.001 + 2 , -8721.38 , 0.001 + 3 , -4114.08 , 0.001 + 4 , 305.267 , 0.001 + 5 , 3932.86 , 0.001 + 6 , 6717.6 , 0.001 + 7 , 8859.85 , 0.001 + 8 , 10646.5 , 0.001 + 9 , 12358.0 , 0.001 + 10 , 14207.2 , 0.001 + 11 , 16281.9 , 0.001 + 12 , 18462.1 , 0.001 + 13 , 20259.5 , 0.001 + 14 , 20447.0 , 0.001 + 15 , 16181.3 , 0.001 + 16 , 1015.71 , 0.001 + 17 , -38629.0 , 0.001 + 18 , -118966.0 , 0.001 + 19 , -22745.8 , 0.001 + 20 , -22327.9 , 0.001 + 21 , -15522.2 , 0.001 + 22 , -9357.91 , 0.001 + 23 , -5783.47 , 0.001 + 24 , -4829.0 , 0.001 + 25 , -5777.33 , 0.001 + 26 , -7736.69 , 0.001 + 27 , -9940.95 , 0.001 + 28 , -11887.3 , 0.001 + 29 , -13366.9 , 0.001 + 30 , -14427.0 , 0.001 + 31 , -15274.5 , 0.001 + 32 , -16043.2 , 0.001 + 33 , -16168.7 , 0.001 + 34 , -12980.4 , 0.001 + 35 , 252.815 , 0.001 + 36 , 34024.4 , 0.001 + 37 , 88513.5 , 0.001 diff --git a/TestCases/cont_adj_euler/naca0012/of_grad_directdiff.dat.ref b/TestCases/cont_adj_euler/naca0012/of_grad_directdiff.dat.ref index 34f9fdc4b499..e6dcad499894 100644 --- a/TestCases/cont_adj_euler/naca0012/of_grad_directdiff.dat.ref +++ b/TestCases/cont_adj_euler/naca0012/of_grad_directdiff.dat.ref @@ -1,4 +1,4 @@ VARIABLES="VARIABLE" , "DRAG" , "EFFICIENCY" , "FORCE_X" , "FORCE_Y" , "FORCE_Z" , "LIFT" , "MOMENT_X" , "MOMENT_Y" , "MOMENT_Z" , "SIDEFORCE" - 0 , -0.4822702617 , -33.47975893 , -0.4005061436 , -3.752457446 , 0.0 , -3.742827467 , 0.0 , 0.0 , 0.4901663445 , 0.0 - 1 , 0.4046369694 , -39.8358634 , 0.4806656813 , -3.479932458 , 0.0 , -3.489589995 , 0.0 , 0.0 , 0.2099434069 , 0.0 - 2 , 0.8857650012 , -37.46457348 , 0.9462916401 , -2.764234008 , 0.0 , -2.784219439 , 0.0 , 0.0 , -0.1102654457 , 0.0 + 0 , 0.2238017616 , -26.45441896 , 0.26355388 , -1.8193724 , 0.0 , -1.824688836 , 0.0 , 0.0 , 0.4757354463 , 0.0 + 1 , 0.4941215347 , -41.68837227 , 0.5532618619 , -2.704972581 , 0.0 , -2.716398215 , 0.0 , 0.0 , 0.236646489 , 0.0 + 2 , 0.7580150128 , -47.55455329 , 0.8206631815 , -2.862855937 , 0.0 , -2.880077328 , 0.0 , 0.0 , -0.06710325381 , 0.0 diff --git a/TestCases/hybrid_regression.py b/TestCases/hybrid_regression.py index 53be16ae8d3a..043fbd34f811 100644 --- a/TestCases/hybrid_regression.py +++ b/TestCases/hybrid_regression.py @@ -80,7 +80,7 @@ def main(): wedge.cfg_dir = "euler/wedge" wedge.cfg_file = "inv_wedge_HLLC.cfg" wedge.test_iter = 20 - wedge.test_vals = [-4.236378, 1.490996, -0.249527, 0.043953] + wedge.test_vals = [-3.891138, 1.834563, -0.249527, 0.043953] test_list.append(wedge) # ONERA M6 Wing @@ -149,7 +149,7 @@ def main(): poiseuille_profile.cfg_dir = "navierstokes/poiseuille" poiseuille_profile.cfg_file = "profile_poiseuille.cfg" poiseuille_profile.test_iter = 10 - poiseuille_profile.test_vals = [-12.010688, -7.647213, -0.000000, 2.089953] + poiseuille_profile.test_vals = [-12.010692, -7.646931, -0.000000, 2.089953] poiseuille_profile.test_vals_aarch64 = [-12.004276, -7.636719, -0.000000, 2.089953] test_list.append(poiseuille_profile) @@ -186,7 +186,7 @@ def main(): rae2822_sst.cfg_dir = "rans/rae2822" rae2822_sst.cfg_file = "turb_SST_RAE2822.cfg" rae2822_sst.test_iter = 20 - rae2822_sst.test_vals = [-1.386817, 5.882285, 0.618135, 0.019784, 100.000000] + rae2822_sst.test_vals = [-1.368201, 5.882410, 0.556244, 0.014039, 100.000000] test_list.append(rae2822_sst) # RAE2822 SST_SUST @@ -202,7 +202,7 @@ def main(): turb_flatplate.cfg_dir = "rans/flatplate" turb_flatplate.cfg_file = "turb_SA_flatplate.cfg" turb_flatplate.test_iter = 20 - turb_flatplate.test_vals = [-0.164454, 0.004203, 10.000000, -2.540209] + turb_flatplate.test_vals = [-0.165661, 0.004184, 10.000000, -2.554025] test_list.append(turb_flatplate) # ONERA M6 Wing @@ -218,7 +218,7 @@ def main(): turb_naca0012_sa.cfg_dir = "rans/naca0012" turb_naca0012_sa.cfg_file = "turb_NACA0012_sa.cfg" turb_naca0012_sa.test_iter = 5 - turb_naca0012_sa.test_vals = [-12.038092, -16.332088, 1.080346, 0.018385, 20.000000, -2.873167, 0.000000, -14.250270, 0.000000] + turb_naca0012_sa.test_vals = [-12.038050, -16.332089, 1.080346, 0.018385, 20.000000, -2.873679, 0.000000, -14.250270, 0.000000] turb_naca0012_sa.test_vals_aarch64 = [-12.038091, -16.332090, 1.080346, 0.018385, 20.000000, -2.873236, 0.000000, -14.250271, 0.000000] test_list.append(turb_naca0012_sa) @@ -273,7 +273,7 @@ def main(): axi_rans_air_nozzle_restart.cfg_dir = "axisymmetric_rans/air_nozzle" axi_rans_air_nozzle_restart.cfg_file = "air_nozzle_restart.cfg" axi_rans_air_nozzle_restart.test_iter = 10 - axi_rans_air_nozzle_restart.test_vals = [-5.066104, 0.510545, -1.715019, 2.920832, 0.000000] + axi_rans_air_nozzle_restart.test_vals = [-5.066093, 0.510552, -1.715310, 2.920425, 0.000000] axi_rans_air_nozzle_restart.test_vals_aarch64 = [-14.140441, -9.154674, -10.886121, -5.806594, 0.000000] test_list.append(axi_rans_air_nozzle_restart) @@ -604,7 +604,7 @@ def main(): edge_VW.cfg_dir = "nicf/edge" edge_VW.cfg_file = "edge_VW.cfg" edge_VW.test_iter = 25 - edge_VW.test_vals = [-11.771528, -5.584553, -0.000009, 0.000000] + edge_VW.test_vals = [-11.771824, -5.584805, -0.000009, 0.000000] test_list.append(edge_VW) # Rarefaction shock wave edge_PPR @@ -612,7 +612,7 @@ def main(): edge_PPR.cfg_dir = "nicf/edge" edge_PPR.cfg_file = "edge_PPR.cfg" edge_PPR.test_iter = 20 - edge_PPR.test_vals = [-8.243389, -2.088370, -0.000034, 0.000000] + edge_PPR.test_vals = [-8.242353, -2.087373, -0.000034, 0.000000] edge_PPR.test_vals_aarch64 = [ -7.139211, -0.980821, -0.000034, 0.000000] test_list.append(edge_PPR) @@ -625,7 +625,7 @@ def main(): Jones_tc_restart.cfg_dir = "turbomachinery/APU_turbocharger" Jones_tc_restart.cfg_file = "Jones_restart.cfg" Jones_tc_restart.test_iter = 5 - Jones_tc_restart.test_vals = [-0.151372, -0.171658, -8.195257, -2.499027, -7.362886, -1.883842, 73291.000000, 73291.000000, 0.020062, 82.380000] + Jones_tc_restart.test_vals = [-0.151371, -0.171559, -8.195256, -2.499027, -7.362867, -1.884111, 73291.000000, 73291.000000, 0.020062, 82.380000] test_list.append(Jones_tc_restart) # 2D axial stage @@ -796,7 +796,7 @@ def main(): fsi_cht_restart.cfg_dir = "fea_fsi/stat_fsi" fsi_cht_restart.cfg_file = "config_restart.cfg" fsi_cht_restart.test_iter = 0 - fsi_cht_restart.test_vals = [5.000000, 0.006352, -1.960362, -9.327033, -9.627371, -9.319273, 608.380000, -0.012974, 0.000000, 20.000000] + fsi_cht_restart.test_vals = [5.000000, 0.006352, -1.960362, -9.326975, -9.618699, -9.319644, 608.380000, -0.012974, 0.000000, 20.000000] fsi_cht_restart.multizone = True test_list.append(fsi_cht_restart) diff --git a/TestCases/hybrid_regression_AD.py b/TestCases/hybrid_regression_AD.py index 8860042f7303..e02fcf9ee61e 100644 --- a/TestCases/hybrid_regression_AD.py +++ b/TestCases/hybrid_regression_AD.py @@ -79,7 +79,7 @@ def main(): discadj_rans_naca0012_sa.cfg_dir = "disc_adj_rans/naca0012" discadj_rans_naca0012_sa.cfg_file = "turb_NACA0012_sa.cfg" discadj_rans_naca0012_sa.test_iter = 10 - discadj_rans_naca0012_sa.test_vals = [-2.987158, 0.533077, 0.000004, -0.000000, 5.000000, -2.939652, 5.000000, -5.503576] + discadj_rans_naca0012_sa.test_vals = [-2.987158, 0.533077, 0.000004, -0.000000, 5.000000, -2.939652, 5.000000, -5.493665] test_list.append(discadj_rans_naca0012_sa) # Adjoint turbulent NACA0012 SST @@ -100,7 +100,7 @@ def main(): discadj_incomp_NACA0012.cfg_dir = "disc_adj_incomp_euler/naca0012" discadj_incomp_NACA0012.cfg_file = "incomp_NACA0012_disc.cfg" discadj_incomp_NACA0012.test_iter = 20 - discadj_incomp_NACA0012.test_vals = [20.000000, -3.134641, -2.294877, 0.000000] + discadj_incomp_NACA0012.test_vals = [20.000000, -3.217505, -2.513785, 0.000000] test_list.append(discadj_incomp_NACA0012) ##################################### @@ -188,7 +188,7 @@ def main(): discadj_pitchingNACA0012.cfg_dir = "disc_adj_euler/naca0012_pitching" discadj_pitchingNACA0012.cfg_file = "inv_NACA0012_pitching.cfg" discadj_pitchingNACA0012.test_iter = 4 - discadj_pitchingNACA0012.test_vals = [-1.128086, -1.582652, -0.006613, 0.000011] + discadj_pitchingNACA0012.test_vals = [-1.144664, -1.593160, -0.006641, 0.000010] discadj_pitchingNACA0012.tol = 0.01 discadj_pitchingNACA0012.unsteady = True discadj_pitchingNACA0012.enabled_with_tsan = False diff --git a/TestCases/multiple_ffd/naca0012/of_grad_cd.dat.ref b/TestCases/multiple_ffd/naca0012/of_grad_cd.dat.ref index 23ceb1a6b5b3..9e1774be81bf 100644 --- a/TestCases/multiple_ffd/naca0012/of_grad_cd.dat.ref +++ b/TestCases/multiple_ffd/naca0012/of_grad_cd.dat.ref @@ -1,3 +1,3 @@ VARIABLES="VARIABLE" , "GRADIENT" , "FINDIFF_STEP" - 0 , 0.0441842 , 0.001 - 1 , -0.0851416 , 0.001 + 0 , 0.0427831 , 0.001 + 1 , -0.0829177 , 0.001 diff --git a/TestCases/multiple_ffd/naca0012/of_grad_directdiff.dat.ref b/TestCases/multiple_ffd/naca0012/of_grad_directdiff.dat.ref index c8cdfc2be3b8..ab6b6dcbbab7 100644 --- a/TestCases/multiple_ffd/naca0012/of_grad_directdiff.dat.ref +++ b/TestCases/multiple_ffd/naca0012/of_grad_directdiff.dat.ref @@ -1,3 +1,3 @@ VARIABLES="VARIABLE" , "DRAG" , "EFFICIENCY" , "FORCE_X" , "FORCE_Y" , "FORCE_Z" , "LIFT" , "MOMENT_X" , "MOMENT_Y" , "MOMENT_Z" , "SIDEFORCE" - 0 , 0.04764995291 , -0.4785284359 , 0.04801017457 , -0.01598892384 , 0.0 , -0.01703245534 , 0.0 , 0.0 , 0.02996605706 , 0.0 - 1 , -0.09288671545 , 0.3493425426 , -0.09225244369 , -0.03008154029 , 0.0 , -0.02806190524 , 0.0 , 0.0 , 0.06566823485 , 0.0 + 0 , 0.04664738027 , -0.5056424841 , 0.04695620131 , -0.01364420371 , 0.0 , -0.01466530089 , 0.0 , 0.0 , 0.02845302842 , 0.0 + 1 , -0.09019985946 , 0.4771773726 , -0.08972714712 , -0.02264806689 , 0.0 , -0.02068528987 , 0.0 , 0.0 , 0.06196955454 , 0.0 diff --git a/TestCases/parallel_regression.py b/TestCases/parallel_regression.py index 510b2a6a6743..e5174519bc06 100755 --- a/TestCases/parallel_regression.py +++ b/TestCases/parallel_regression.py @@ -47,7 +47,7 @@ def main(): cfd_cantera_dc_ch4.cfg_dir = "combustion/1step_methane_air" cfd_cantera_dc_ch4.cfg_file = "2d_slit_burner_fluid.cfg" cfd_cantera_dc_ch4.test_iter = 10 - cfd_cantera_dc_ch4.test_vals = [-12.897453, -15.198159, -12.810575, 10.000000, -1.881353, 1000.000000] + cfd_cantera_dc_ch4.test_vals = [-12.897452, -15.191976, -12.810575, 10.000000, -1.860548, 1000.000000] cfd_cantera_dc_ch4.new_output = True test_list.append(cfd_cantera_dc_ch4) @@ -56,7 +56,7 @@ def main(): cfd_cantera_dc_h2.cfg_dir = "combustion/h2o2_hydrogen_air" cfd_cantera_dc_h2.cfg_file = "2d_slit_burner_h2.cfg" cfd_cantera_dc_h2.test_iter = 10 - cfd_cantera_dc_h2.test_vals = [-15.993819, -17.134091, -32.000000, 5.000000, -2.029177, 100.000000] + cfd_cantera_dc_h2.test_vals = [-15.994221, -17.134244, -32.000000, 5.000000, -2.027264, 100.000000] cfd_cantera_dc_h2.new_output = True test_list.append(cfd_cantera_dc_h2) @@ -397,7 +397,7 @@ def main(): flatplate_wall_limiter.cfg_dir = "navierstokes/flatplate" flatplate_wall_limiter.cfg_file = "lam_flatplate_wall_limiter.cfg" flatplate_wall_limiter.test_iter = 20 - flatplate_wall_limiter.test_vals = [-5.373432, 0.105283, 0.001249, 0.027725, 2.361600, -2.333900, 0.000000, 0.000000] + flatplate_wall_limiter.test_vals = [-5.409896, 0.067894, 0.001183, 0.030453, 2.361700, -2.331200, 0.000000, 0.000000] test_list.append(flatplate_wall_limiter) # Supersonic laminar flat plate @@ -507,7 +507,7 @@ def main(): periodic3d_axis.cfg_dir = "navierstokes/periodic3D_axis" periodic3d_axis.cfg_file = "config.cfg" periodic3d_axis.test_iter = 100 - periodic3d_axis.test_vals = [-3.271569, -0.284345, 2.163829, -7.848400, -7.848400] + periodic3d_axis.test_vals = [-3.271759, -0.284720, 2.163574, -7.847600, -7.847600] test_list.append(periodic3d_axis) ########################## @@ -535,7 +535,7 @@ def main(): rae2822_sst_jst_mat.cfg_dir = "rans/rae2822" rae2822_sst_jst_mat.cfg_file = "turb_SST_JST_MAT_RAE2822.cfg" rae2822_sst_jst_mat.test_iter = 20 - rae2822_sst_jst_mat.test_vals = [-1.629500, 5.867810, 0.701293, 0.065872, 100.000000] + rae2822_sst_jst_mat.test_vals = [-1.474492, 5.881394, 0.675039, 0.062869, 100.000000] test_list.append(rae2822_sst_jst_mat) # RAE2822 SST_SUST @@ -575,7 +575,7 @@ def main(): turb_flatplate_species.cfg_dir = "rans/flatplate" turb_flatplate_species.cfg_file = "turb_SA_flatplate_species.cfg" turb_flatplate_species.test_iter = 20 - turb_flatplate_species.test_vals = [-1.633720, 1.169540, 0.370167, 3.520866, -2.600425, 3.000000, -1.023790, 3.000000, -0.897706, 3.000000, -0.842257, 0.999315, 0.999315] + turb_flatplate_species.test_vals = [-1.485399, 0.863236, 0.484692, 3.386697, -2.465371, 2.000000, -1.057746, 3.000000, -0.071163, 3.000000, -0.771473, 0.999411, 0.999411] test_list.append(turb_flatplate_species) # Flat plate SST compressibility correction Wilcox @@ -651,7 +651,7 @@ def main(): turb_naca0012_sa.cfg_dir = "rans/naca0012" turb_naca0012_sa.cfg_file = "turb_NACA0012_sa.cfg" turb_naca0012_sa.test_iter = 5 - turb_naca0012_sa.test_vals = [-12.037539, -16.376949, 1.080346, 0.018385, 20.000000, -1.564082, 20.000000, -4.180930, 0.000000] + turb_naca0012_sa.test_vals = [-12.037544, -16.376949, 1.080346, 0.018385, 20.000000, -1.564067, 20.000000, -4.180949, 0.000000] turb_naca0012_sa.test_vals_aarch64 = [-12.037489, -16.376949, 1.080346, 0.018385, 20.000000, -1.564143, 20.000000, -4.180945, 0.000000] turb_naca0012_sa.timeout = 3200 test_list.append(turb_naca0012_sa) @@ -775,7 +775,7 @@ def main(): axi_rans_air_nozzle_restart.cfg_dir = "axisymmetric_rans/air_nozzle" axi_rans_air_nozzle_restart.cfg_file = "air_nozzle_restart.cfg" axi_rans_air_nozzle_restart.test_iter = 10 - axi_rans_air_nozzle_restart.test_vals = [-5.126496, 0.450311, -1.628542, 2.883478, 0.000000] + axi_rans_air_nozzle_restart.test_vals = [-5.126504, 0.450297, -1.628749, 2.883154, 0.000000] axi_rans_air_nozzle_restart.test_vals_aarch64 = [-14.143310, -9.163287, -10.858232, -5.787715, 0.000000] axi_rans_air_nozzle_restart.tol = 0.0001 test_list.append(axi_rans_air_nozzle_restart) @@ -785,7 +785,7 @@ def main(): axi_rans_air_nozzle_density_velocity.cfg_dir = "axisymmetric_rans/air_nozzle" axi_rans_air_nozzle_density_velocity.cfg_file = "air_nozzle_density_velocity.cfg" axi_rans_air_nozzle_density_velocity.test_iter = 10 - axi_rans_air_nozzle_density_velocity.test_vals = [702.550000, -1.879323, 4.022709, 0.513957, 4.415534] + axi_rans_air_nozzle_density_velocity.test_vals = [702.550000, -1.879323, 4.022709, 0.513969, 4.415605] test_list.append(axi_rans_air_nozzle_density_velocity) ################################# @@ -1096,7 +1096,7 @@ def main(): turbmod_sa_neg_rae2822.cfg_dir = "turbulence_models/sa/rae2822" turbmod_sa_neg_rae2822.cfg_file = "turb_SA_NEG_RAE2822.cfg" turbmod_sa_neg_rae2822.test_iter = 10 - turbmod_sa_neg_rae2822.test_vals = [1.262984, 1.057729, -2.485714, 1.347422, 0.499608, 0.000000] + turbmod_sa_neg_rae2822.test_vals = [1.264766, 1.058838, -2.479388, 1.304799, 0.473631, 0.000000] turbmod_sa_neg_rae2822.test_vals_aarch64 = [-1.345593, 1.448310, 1.208721, -0.846597, 1.248410, 0.489117, 0.000000] test_list.append(turbmod_sa_neg_rae2822) @@ -1153,7 +1153,7 @@ def main(): contadj_naca0012.cfg_dir = "cont_adj_euler/naca0012" contadj_naca0012.cfg_file = "inv_NACA0012.cfg" contadj_naca0012.test_iter = 5 - contadj_naca0012.test_vals = [-9.528628, -15.088414, -0.726250, 0.020280] + contadj_naca0012.test_vals = [-9.528612, -15.088426, -0.726250, 0.020280] contadj_naca0012.test_vals_aarch64 = [-9.662546, -14.998818, -0.726250, 0.020280] test_list.append(contadj_naca0012) @@ -1330,7 +1330,7 @@ def main(): spinning_cylinder.cfg_dir = "moving_wall/spinning_cylinder" spinning_cylinder.cfg_file = "spinning_cylinder.cfg" spinning_cylinder.test_iter = 25 - spinning_cylinder.test_vals = [-7.504351, -2.048998, 3.021874, 2.098445] + spinning_cylinder.test_vals = [-7.502134, -2.046784, 3.034409, 2.100243] test_list.append(spinning_cylinder) ###################################### @@ -1378,10 +1378,10 @@ def main(): test_list.append(ddes_flatplate) # Hybrid RANS/LES models on the ONERA M6 wing, restarting from a RANS solution - ddes_oneram6_vals = {"sst_ddes": [-2.221793, -0.757244, 2.506727, 0.261418, 0.022680], - "sst_iddes": [-2.226164, 3.063400, 2.594574, 0.261433, 0.022683], - "sst_siddes": [-2.226164, 3.063400, 2.594625, 0.261418, 0.022680], - "sst_eddes": [-2.221792, 0.258725, 2.506711, 0.261418, 0.022680], + ddes_oneram6_vals = {"sst_ddes": [-2.221793, -0.757239, 2.506710, 0.261418, 0.022680], + "sst_iddes": [-2.226164, 3.063400, 2.594562, 0.261433, 0.022683], + "sst_siddes": [-2.226164, 3.063400, 2.594613, 0.261418, 0.022680], + "sst_eddes": [-2.221792, 0.258724, 2.506694, 0.261418, 0.022680], "sa_eddes": [-3.510007, -3.683557, 0.266420, 0.023471]} for model, vals in ddes_oneram6_vals.items(): ddes_oneram6 = TestCase('ddes_oneram6_' + model) @@ -1464,7 +1464,7 @@ def main(): datadriven_fluidModel.cfg_dir = "nicf/datadriven" datadriven_fluidModel.cfg_file = "datadriven_nozzle.cfg" datadriven_fluidModel.test_iter = 50 - datadriven_fluidModel.test_vals = [-5.772083, -2.793971, -3.757967, -0.619363, -1.476238, 1.691659] + datadriven_fluidModel.test_vals = [-5.769678, -2.799426, -3.747972, -0.609775, -1.488443, 1.616657] test_list.append(datadriven_fluidModel) ###################################### @@ -1477,7 +1477,7 @@ def main(): Aachen_3D_restart.cfg_file = "aachen_3D_MP_restart.cfg" Aachen_3D_restart.test_iter = 5 Aachen_3D_restart.tol = 0.00001 - Aachen_3D_restart.test_vals = [-7.689216, -8.447691, -6.049105, -6.408333, -5.833790, -4.582537, -5.531371, -5.312054, -3.829167, -5.243427, -5.787654, -3.644207, -2.211820, -2.864055, -0.585675] + Aachen_3D_restart.test_vals = [-7.689216, -8.447703, -6.049105, -6.408333, -5.833790, -4.582537, -5.531371, -5.312054, -3.829167, -5.243427, -5.787652, -3.644207, -2.211820, -2.864063, -0.585675] test_list.append(Aachen_3D_restart) # Jones APU Turbocharger restart @@ -1485,7 +1485,7 @@ def main(): Jones_tc_restart.cfg_dir = "turbomachinery/APU_turbocharger" Jones_tc_restart.cfg_file = "Jones_restart.cfg" Jones_tc_restart.test_iter = 5 - Jones_tc_restart.test_vals = [-0.151378, -0.171653, -8.195262, -2.499033, -7.362884, -1.883837, 73291.000000, 73291.000000, 0.020062, 82.380000] + Jones_tc_restart.test_vals = [-0.151377, -0.171554, -8.195262, -2.499033, -7.362866, -1.884107, 73291.000000, 73291.000000, 0.020062, 82.380000] # The second BGS residual is near the numerical floor and varies between builds. Jones_tc_restart.tol = [1e-5, 5e-4] + [1e-5] * 8 test_list.append(Jones_tc_restart) @@ -1503,7 +1503,7 @@ def main(): transonic_stator_restart.cfg_dir = "turbomachinery/transonic_stator_2D" transonic_stator_restart.cfg_file = "transonic_stator_restart.cfg" transonic_stator_restart.test_iter = 20 - transonic_stator_restart.test_vals = [-4.361988, -2.478653, -2.080473, 1.732234, -1.467441, 3.229155, -471620.000000, 94.838000, -0.064875] + transonic_stator_restart.test_vals = [-4.361997, -2.478636, -2.080514, 1.732226, -1.467385, 3.229118, -471620.000000, 94.838000, -0.064873] transonic_stator_restart.test_vals_aarch64 = [-4.437809, -2.553049, -2.164729, 1.657542, -1.356823, 3.178788, -471620.000000, 94.842000, -0.040365] test_list.append(transonic_stator_restart) @@ -1795,7 +1795,7 @@ def main(): pywrapper_naca0012.cfg_dir = "euler/naca0012" pywrapper_naca0012.cfg_file = "inv_NACA0012_Roe.cfg" pywrapper_naca0012.test_iter = 80 - pywrapper_naca0012.test_vals = [-5.701280, -5.186480, 0.334856, 0.023342] + pywrapper_naca0012.test_vals = [-4.842904, -4.165053, 0.335809, 0.023275] pywrapper_naca0012.command = TestCase.Command("mpirun -np 2", "SU2_CFD.py", "--parallel -f") test_list.append(pywrapper_naca0012) @@ -1825,7 +1825,7 @@ def main(): pywrapper_aeroelastic.cfg_dir = "aeroelastic" pywrapper_aeroelastic.cfg_file = "aeroelastic_NACA64A010.cfg" pywrapper_aeroelastic.test_iter = 2 - pywrapper_aeroelastic.test_vals = [-1.876625, 4.021087, 0.083271, 0.026787, -0.001638, -0.000130, -0.973891] + pywrapper_aeroelastic.test_vals = [-1.876622, 4.021100, 0.084667, 0.026652, -0.001636, -0.000131, -0.973885] pywrapper_aeroelastic.command = TestCase.Command("mpirun -np 2", "SU2_CFD.py", "--parallel -f") pywrapper_aeroelastic.unsteady = True test_list.append(pywrapper_aeroelastic) @@ -1866,7 +1866,7 @@ def main(): pywrapper_unsteadyCHT.cfg_dir = "py_wrapper/flatPlate_unsteady_CHT" pywrapper_unsteadyCHT.cfg_file = "unsteady_CHT_FlatPlate_Conf.cfg" pywrapper_unsteadyCHT.test_iter = 5 - pywrapper_unsteadyCHT.test_vals = [-1.614169, 2.260208, -0.008127, 0.201931] + pywrapper_unsteadyCHT.test_vals = [-1.614168, 2.260661, 0.000880, 0.102124] pywrapper_unsteadyCHT.command = TestCase.Command("mpirun -np 2", "python", "launch_unsteady_CHT_FlatPlate.py --parallel -f") pywrapper_unsteadyCHT.unsteady = True test_list.append(pywrapper_unsteadyCHT) diff --git a/TestCases/parallel_regression_AD.py b/TestCases/parallel_regression_AD.py index b9bf3f91468e..c9e4ae826201 100644 --- a/TestCases/parallel_regression_AD.py +++ b/TestCases/parallel_regression_AD.py @@ -104,7 +104,7 @@ def main(): discadj_incomp_NACA0012.cfg_dir = "disc_adj_incomp_euler/naca0012" discadj_incomp_NACA0012.cfg_file = "incomp_NACA0012_disc.cfg" discadj_incomp_NACA0012.test_iter = 20 - discadj_incomp_NACA0012.test_vals = [20.000000, -3.126844, -2.284292, 0.000000] + discadj_incomp_NACA0012.test_vals = [20.000000, -3.219759, -2.515120, 0.000000] test_list.append(discadj_incomp_NACA0012) ##################################### @@ -158,7 +158,7 @@ def main(): discadj_axisymmetric_rans_nozzle.cfg_dir = "axisymmetric_rans/air_nozzle" discadj_axisymmetric_rans_nozzle.cfg_file = "air_nozzle_restart.cfg" discadj_axisymmetric_rans_nozzle.test_iter = 10 - discadj_axisymmetric_rans_nozzle.test_vals = [9.738539, 5.135055, 7.100324, 2.487206] + discadj_axisymmetric_rans_nozzle.test_vals = [9.737649, 5.134194, 7.099939, 2.486935] discadj_axisymmetric_rans_nozzle.no_restart = True test_list.append(discadj_axisymmetric_rans_nozzle) @@ -171,7 +171,7 @@ def main(): discadj_cylinder.cfg_dir = "disc_adj_rans/cylinder" discadj_cylinder.cfg_file = "cylinder.cfg" discadj_cylinder.test_iter = 9 - discadj_cylinder.test_vals = [1.639372, -2.834293, -0.009538, 0.000020] + discadj_cylinder.test_vals = [1.639367, -2.834313, -0.009538, 0.000020] discadj_cylinder.unsteady = True test_list.append(discadj_cylinder) @@ -184,7 +184,7 @@ def main(): discadj_cylinder.cfg_dir = "disc_adj_rans/cylinder" discadj_cylinder.cfg_file = "cylinder_Windowing_AD.cfg" discadj_cylinder.test_iter = 9 - discadj_cylinder.test_vals = [2.183361] + discadj_cylinder.test_vals = [2.183345] discadj_cylinder.unsteady = True test_list.append(discadj_cylinder) @@ -212,7 +212,7 @@ def main(): discadj_DT_1ST_cylinder.cfg_dir = "disc_adj_rans/cylinder_DT_1ST" discadj_DT_1ST_cylinder.cfg_file = "cylinder.cfg" discadj_DT_1ST_cylinder.test_iter = 9 - discadj_DT_1ST_cylinder.test_vals = [1.196414, -3.339029, -0.006212, 0.000020] + discadj_DT_1ST_cylinder.test_vals = [1.196412, -3.339040, -0.006212, 0.000020] discadj_DT_1ST_cylinder.unsteady = True test_list.append(discadj_DT_1ST_cylinder) @@ -225,7 +225,7 @@ def main(): discadj_pitchingNACA0012.cfg_dir = "disc_adj_euler/naca0012_pitching" discadj_pitchingNACA0012.cfg_file = "inv_NACA0012_pitching.cfg" discadj_pitchingNACA0012.test_iter = 4 - discadj_pitchingNACA0012.test_vals = [-1.115587, -1.573317, -0.006474, 0.000010] + discadj_pitchingNACA0012.test_vals = [-1.141444, -1.588616, -0.006492, 0.000009] discadj_pitchingNACA0012.tol = 0.01 discadj_pitchingNACA0012.unsteady = True test_list.append(discadj_pitchingNACA0012) @@ -259,7 +259,7 @@ def main(): discadj_trans_stator.cfg_dir = "disc_adj_turbomachinery/transonic_stator_2D" discadj_trans_stator.cfg_file = "transonic_stator.cfg" discadj_trans_stator.test_iter = 79 - discadj_trans_stator.test_vals = [79.000000, -7.555093, -10.335187, -10.357771, -13.629182] + discadj_trans_stator.test_vals = [79.000000, -7.553958, -10.332913, -10.356693, -13.628002] discadj_trans_stator.test_vals_aarch64 = [79.000000, -7.555647, -10.335486, -10.356919, -13.629543] test_list.append(discadj_trans_stator) @@ -268,7 +268,7 @@ def main(): discadj_axial_stage.cfg_dir = "disc_adj_turbomachinery/axial_stage_2D" discadj_axial_stage.cfg_file = "Axial_stage2D.cfg" discadj_axial_stage.test_iter = 79 - discadj_axial_stage.test_vals = [79.000000, -6.500066, -6.635655] + discadj_axial_stage.test_vals = [79.000000, -6.500058, -6.635717] discadj_axial_stage.test_vals_aarch64 = [79.000000, -6.606356, -7.139726] test_list.append(discadj_axial_stage) @@ -315,7 +315,7 @@ def main(): discadj_fsi.cfg_dir = "disc_adj_fsi" discadj_fsi.cfg_file = "config.cfg" discadj_fsi.test_iter = 9 - discadj_fsi.test_vals = [-3.166421, -4.160938, 0.000439, -1.061900] + discadj_fsi.test_vals = [-3.166795, -4.161507, 0.000439, -1.061900] test_list.append(discadj_fsi) # Multi physics framework @@ -478,6 +478,7 @@ def main(): unsteady_naca0012.timeout = 1600 unsteady_naca0012.reference_file = "of_grad_cd.csv.ref" unsteady_naca0012.test_file = "of_grad_cd.csv" + unsteady_naca0012.tol_file_percent = 0.001 unsteady_naca0012.unsteady = True pass_list.append(unsteady_naca0012.run_filediff()) test_list.append(unsteady_naca0012) @@ -495,6 +496,7 @@ def main(): unsteady_naca0012.timeout = 1600 unsteady_naca0012.reference_file = "of_grad_cd.csv.ref" unsteady_naca0012.test_file = "of_grad_cd.csv" + unsteady_naca0012.tol_file_percent = 0.001 unsteady_naca0012.unsteady = True pass_list.append(unsteady_naca0012.run_filediff()) test_list.append(unsteady_naca0012) diff --git a/TestCases/py_wrapper/updated_moving_frame_NACA12/forces_0.csv.ref b/TestCases/py_wrapper/updated_moving_frame_NACA12/forces_0.csv.ref index 999eb13891e2..e487bb2c00d0 100644 --- a/TestCases/py_wrapper/updated_moving_frame_NACA12/forces_0.csv.ref +++ b/TestCases/py_wrapper/updated_moving_frame_NACA12/forces_0.csv.ref @@ -1,200 +1,200 @@ -199, -1.20, -0.00, 0.00 -0, -2.92, 20.11, 0.00 -1, -4.10, 28.24, 0.00 -2, -5.16, 35.61, 0.00 -3, -6.07, 41.96, 0.00 -4, -6.84, 47.48, 0.00 -5, -7.47, 51.99, 0.00 -6, -7.99, 55.84, 0.00 -7, -8.38, 58.85, 0.00 -8, -8.65, 61.11, 0.00 -9, -8.81, 62.62, 0.00 -10, -8.87, 63.45, 0.00 -11, -8.84, 63.65, 0.00 -12, -8.70, 63.17, 0.00 -13, -8.48, 62.07, 0.00 -14, -8.17, 60.33, 0.00 -15, -7.79, 58.00, 0.00 -16, -7.33, 55.14, 0.00 -17, -6.80, 51.70, 0.00 -18, -6.21, 47.72, 0.00 -19, -5.57, 43.25, 0.00 -20, -4.87, 38.31, 0.00 -21, -4.14, 32.93, 0.00 -22, -3.38, 27.21, 0.00 -23, -2.58, 21.06, 0.00 -24, -1.77, 14.67, 0.00 -25, -0.94, 7.90, 0.00 -26, -0.11, 0.90, 0.00 -27, 0.75, -6.47, 0.00 -28, 1.59, -13.99, 0.00 -29, 2.44, -21.72, 0.00 -30, 3.25, -29.47, 0.00 -31, 4.05, -37.38, 0.00 -32, 4.84, -45.40, 0.00 -33, 5.60, -53.55, 0.00 -34, 6.36, -61.97, 0.00 -35, 7.10, -70.62, 0.00 -36, 7.89, -80.20, 0.00 -37, 8.71, -90.57, 0.00 -38, 9.61, -102.26, 0.00 -39, 10.53, -114.86, 0.00 -40, 11.24, -125.87, 0.00 -41, 11.76, -135.57, 0.00 -42, 12.03, -142.86, 0.00 -43, 12.24, -150.07, 0.00 -44, 12.24, -155.39, 0.00 -45, 11.86, -156.46, 0.00 -46, 11.10, -152.43, 0.00 -47, 10.29, -147.82, 0.00 -48, 10.60, -159.90, 0.00 -49, 11.68, -185.89, 0.00 -50, 9.66, -163.27, 0.00 -51, 3.18, -57.51, 0.00 -52, -1.13, 21.95, 0.00 -53, 13.09, -277.45, 0.00 -54, 23.52, -549.90, 0.00 -55, 22.09, -578.95, 0.00 -56, 18.87, -566.71, 0.00 -57, 15.68, -555.98, 0.00 -58, 12.53, -547.86, 0.00 -59, 9.31, -538.89, 0.00 -60, 6.02, -528.41, 0.00 -61, 2.70, -516.97, 0.00 -62, -0.62, -504.20, 0.00 -63, -3.93, -490.25, 0.00 -64, -7.20, -475.69, 0.00 -65, -10.40, -460.25, 0.00 -66, -13.51, -443.76, 0.00 -67, -16.50, -426.61, 0.00 -68, -19.34, -408.66, 0.00 -69, -22.02, -390.17, 0.00 -70, -24.51, -371.23, 0.00 -71, -26.79, -351.77, 0.00 -72, -28.82, -331.86, 0.00 -73, -30.56, -311.45, 0.00 -74, -32.02, -290.76, 0.00 -75, -33.17, -269.89, 0.00 -76, -33.93, -248.58, 0.00 -77, -34.32, -227.14, 0.00 -78, -34.31, -205.74, 0.00 -79, -33.84, -184.21, 0.00 -80, -32.90, -162.78, 0.00 -81, -31.43, -141.41, 0.00 -82, -29.36, -120.14, 0.00 -83, -26.66, -99.11, 0.00 -84, -23.23, -78.36, 0.00 -85, -19.00, -57.99, 0.00 -86, -13.83, -38.07, 0.00 -87, -7.58, -18.73, 0.00 -88, -0.08, -0.17, 0.00 -89, 8.88, 17.37, 0.00 -90, 19.52, 33.49, 0.00 -91, 32.13, 47.77, 0.00 -92, 46.90, 59.39, 0.00 -93, 64.03, 67.52, 0.00 -94, 83.40, 70.85, 0.00 -95, 103.85, 67.64, 0.00 -96, 123.55, 56.63, 0.00 -97, 140.19, 37.94, 0.00 -98, 109.36, 14.67, 0.00 -99, 71.65, -0.00, 0.00 -100, 107.04, -14.36, 0.00 -101, 132.32, -35.81, 0.00 -102, 110.90, -50.83, 0.00 -103, 87.80, -57.19, 0.00 -104, 65.17, -55.36, 0.00 -105, 44.58, -47.01, 0.00 -106, 26.89, -34.05, 0.00 -107, 12.05, -17.91, 0.00 -108, -0.31, 0.53, 0.00 -109, -10.50, 20.54, 0.00 -110, -18.88, 41.66, 0.00 -111, -25.69, 63.51, 0.00 -112, -31.22, 85.95, 0.00 -113, -35.63, 108.76, 0.00 -114, -39.11, 131.90, 0.00 -115, -41.77, 155.28, 0.00 -116, -43.70, 178.80, 0.00 -117, -45.01, 202.51, 0.00 -118, -45.73, 226.24, 0.00 -119, -45.92, 249.93, 0.00 -120, -45.64, 273.69, 0.00 -121, -44.91, 297.20, 0.00 -122, -43.78, 320.72, 0.00 -123, -42.28, 344.01, 0.00 -124, -40.39, 366.73, 0.00 -125, -38.21, 389.37, 0.00 -126, -35.77, 411.98, 0.00 -127, -33.06, 434.11, 0.00 -128, -30.09, 455.66, 0.00 -129, -26.90, 476.54, 0.00 -130, -23.52, 496.93, 0.00 -131, -19.99, 516.80, 0.00 -132, -16.32, 535.94, 0.00 -133, -12.53, 554.54, 0.00 -134, -8.66, 572.15, 0.00 -135, -4.72, 588.94, 0.00 -136, -0.75, 605.28, 0.00 -137, 3.25, 620.52, 0.00 -138, 7.23, 634.61, 0.00 -139, 11.19, 648.16, 0.00 -140, 15.11, 660.74, 0.00 -141, 18.95, 671.89, 0.00 -142, 22.72, 682.27, 0.00 -143, 26.39, 691.85, 0.00 -144, 29.95, 700.18, 0.00 -145, 33.36, 707.21, 0.00 -146, 36.65, 713.40, 0.00 -147, 39.79, 718.51, 0.00 -148, 42.75, 722.25, 0.00 -149, 45.54, 724.84, 0.00 -150, 48.02, 724.24, 0.00 -151, 51.10, 733.90, 0.00 -152, 54.32, 746.21, 0.00 -153, 22.28, 293.80, 0.00 -154, -1.65, -20.95, 0.00 -155, 2.74, 33.57, 0.00 -156, 4.21, 49.97, 0.00 -157, 4.36, 50.23, 0.00 -158, 4.78, 53.56, 0.00 -159, 4.98, 54.36, 0.00 -160, 5.00, 53.19, 0.00 -161, 4.89, 50.85, 0.00 -162, 4.69, 47.62, 0.00 -163, 4.39, 43.67, 0.00 -164, 4.00, 39.02, 0.00 -165, 3.53, 33.75, 0.00 -166, 3.00, 28.14, 0.00 -167, 2.40, 22.09, 0.00 -168, 1.76, 15.92, 0.00 -169, 1.06, 9.46, 0.00 -170, 0.35, 3.03, 0.00 -171, -0.41, -3.52, 0.00 -172, -1.16, -9.89, 0.00 -173, -1.93, -16.22, 0.00 -174, -2.69, -22.27, 0.00 -175, -3.45, -28.15, 0.00 -176, -4.19, -33.74, 0.00 -177, -4.90, -39.00, 0.00 -178, -5.58, -43.85, 0.00 -179, -6.22, -48.33, 0.00 -180, -6.81, -52.34, 0.00 -181, -7.35, -55.89, 0.00 -182, -7.84, -58.94, 0.00 -183, -8.25, -61.43, 0.00 -184, -8.59, -63.43, 0.00 -185, -8.86, -64.81, 0.00 -186, -9.04, -65.58, 0.00 -187, -9.12, -65.71, 0.00 -188, -9.11, -65.16, 0.00 -189, -9.01, -63.99, 0.00 -190, -8.80, -62.16, 0.00 -191, -8.48, -59.60, 0.00 -192, -8.05, -56.31, 0.00 -193, -7.50, -52.22, 0.00 -194, -6.84, -47.48, 0.00 -195, -6.04, -41.77, 0.00 -196, -5.11, -35.28, 0.00 -197, -4.03, -27.80, 0.00 -198, -2.84, -19.56, 0.00 +199, -1.21, -0.00, 0.00 +0, -2.95, 20.31, 0.00 +1, -4.14, 28.56, 0.00 +2, -5.23, 36.07, 0.00 +3, -6.15, 42.56, 0.00 +4, -6.95, 48.22, 0.00 +5, -7.60, 52.88, 0.00 +6, -8.14, 56.88, 0.00 +7, -8.55, 60.05, 0.00 +8, -8.85, 62.47, 0.00 +9, -9.03, 64.15, 0.00 +10, -9.11, 65.17, 0.00 +11, -9.10, 65.57, 0.00 +12, -9.00, 65.29, 0.00 +13, -8.80, 64.41, 0.00 +14, -8.52, 62.91, 0.00 +15, -8.16, 60.82, 0.00 +16, -7.74, 58.26, 0.00 +17, -7.26, 55.15, 0.00 +18, -6.71, 51.55, 0.00 +19, -6.11, 47.48, 0.00 +20, -5.46, 42.92, 0.00 +21, -4.77, 37.96, 0.00 +22, -4.04, 32.56, 0.00 +23, -3.28, 26.75, 0.00 +24, -2.49, 20.59, 0.00 +25, -1.68, 14.05, 0.00 +26, -0.84, 7.16, 0.00 +27, 0.01, -0.05, 0.00 +28, 0.86, -7.58, 0.00 +29, 1.73, -15.40, 0.00 +30, 2.59, -23.50, 0.00 +31, 3.45, -31.85, 0.00 +32, 4.31, -40.48, 0.00 +33, 5.16, -49.33, 0.00 +34, 5.99, -58.37, 0.00 +35, 6.80, -67.63, 0.00 +36, 7.58, -77.07, 0.00 +37, 8.33, -86.61, 0.00 +38, 9.05, -96.30, 0.00 +39, 9.72, -106.03, 0.00 +40, 10.33, -115.73, 0.00 +41, 10.88, -125.33, 0.00 +42, 11.35, -134.83, 0.00 +43, 11.74, -144.02, 0.00 +44, 12.03, -152.80, 0.00 +45, 12.19, -160.80, 0.00 +46, 12.22, -167.88, 0.00 +47, 12.05, -173.14, 0.00 +48, 11.69, -176.34, 0.00 +49, 11.20, -178.21, 0.00 +50, 10.24, -172.94, 0.00 +51, 7.58, -136.87, 0.00 +52, 6.77, -131.80, 0.00 +53, 19.38, -410.91, 0.00 +54, 25.71, -601.18, 0.00 +55, 21.94, -575.27, 0.00 +56, 18.60, -558.71, 0.00 +57, 15.62, -553.59, 0.00 +58, 12.49, -546.26, 0.00 +59, 9.27, -536.95, 0.00 +60, 6.00, -526.55, 0.00 +61, 2.70, -515.32, 0.00 +62, -0.62, -502.79, 0.00 +63, -3.92, -489.02, 0.00 +64, -7.18, -474.61, 0.00 +65, -10.38, -459.26, 0.00 +66, -13.48, -442.84, 0.00 +67, -16.47, -425.74, 0.00 +68, -19.30, -407.83, 0.00 +69, -21.98, -389.37, 0.00 +70, -24.46, -370.46, 0.00 +71, -26.73, -351.02, 0.00 +72, -28.75, -331.13, 0.00 +73, -30.49, -310.72, 0.00 +74, -31.94, -290.04, 0.00 +75, -33.08, -269.18, 0.00 +76, -33.84, -247.89, 0.00 +77, -34.22, -226.47, 0.00 +78, -34.21, -205.11, 0.00 +79, -33.73, -183.59, 0.00 +80, -32.78, -162.18, 0.00 +81, -31.30, -140.83, 0.00 +82, -29.23, -119.59, 0.00 +83, -26.52, -98.59, 0.00 +84, -23.09, -77.87, 0.00 +85, -18.85, -57.53, 0.00 +86, -13.67, -37.65, 0.00 +87, -7.42, -18.34, 0.00 +88, 0.09, 0.19, 0.00 +89, 9.05, 17.69, 0.00 +90, 19.68, 33.77, 0.00 +91, 32.29, 48.01, 0.00 +92, 47.05, 59.58, 0.00 +93, 64.16, 67.65, 0.00 +94, 83.50, 70.93, 0.00 +95, 103.90, 67.68, 0.00 +96, 123.54, 56.62, 0.00 +97, 140.08, 37.91, 0.00 +98, 109.21, 14.66, 0.00 +99, 71.53, -0.00, 0.00 +100, 106.82, -14.33, 0.00 +101, 131.96, -35.72, 0.00 +102, 110.47, -50.63, 0.00 +103, 87.33, -56.88, 0.00 +104, 64.68, -54.95, 0.00 +105, 44.09, -46.49, 0.00 +106, 26.40, -33.44, 0.00 +107, 11.57, -17.20, 0.00 +108, -0.77, 1.32, 0.00 +109, -10.94, 21.41, 0.00 +110, -19.30, 42.60, 0.00 +111, -26.09, 64.50, 0.00 +112, -31.60, 87.00, 0.00 +113, -35.99, 109.87, 0.00 +114, -39.45, 133.06, 0.00 +115, -42.09, 156.48, 0.00 +116, -44.01, 180.06, 0.00 +117, -45.30, 203.81, 0.00 +118, -46.00, 227.59, 0.00 +119, -46.18, 251.33, 0.00 +120, -45.89, 275.15, 0.00 +121, -45.13, 298.70, 0.00 +122, -43.99, 322.26, 0.00 +123, -42.47, 345.60, 0.00 +124, -40.57, 368.36, 0.00 +125, -38.38, 391.04, 0.00 +126, -35.92, 413.69, 0.00 +127, -33.19, 435.86, 0.00 +128, -30.21, 457.44, 0.00 +129, -27.00, 478.36, 0.00 +130, -23.61, 498.79, 0.00 +131, -20.06, 518.70, 0.00 +132, -16.38, 537.89, 0.00 +133, -12.58, 556.52, 0.00 +134, -8.69, 574.17, 0.00 +135, -4.74, 591.00, 0.00 +136, -0.75, 607.39, 0.00 +137, 3.26, 622.66, 0.00 +138, 7.26, 636.80, 0.00 +139, 11.23, 650.40, 0.00 +140, 15.16, 663.02, 0.00 +141, 19.02, 674.22, 0.00 +142, 22.80, 684.65, 0.00 +143, 26.48, 694.28, 0.00 +144, 30.05, 702.63, 0.00 +145, 33.48, 709.70, 0.00 +146, 36.78, 715.92, 0.00 +147, 39.93, 721.11, 0.00 +148, 42.92, 725.06, 0.00 +149, 45.75, 728.21, 0.00 +150, 48.35, 729.16, 0.00 +151, 50.54, 725.91, 0.00 +152, 54.65, 750.78, 0.00 +153, 51.39, 677.66, 0.00 +154, 6.89, 87.55, 0.00 +155, -0.23, -2.86, 0.00 +156, 3.37, 40.04, 0.00 +157, 3.82, 43.99, 0.00 +158, 4.05, 45.34, 0.00 +159, 4.27, 46.63, 0.00 +160, 4.30, 45.71, 0.00 +161, 4.17, 43.33, 0.00 +162, 3.92, 39.87, 0.00 +163, 3.58, 35.59, 0.00 +164, 3.15, 30.68, 0.00 +165, 2.65, 25.33, 0.00 +166, 2.09, 19.62, 0.00 +167, 1.48, 13.68, 0.00 +168, 0.84, 7.61, 0.00 +169, 0.17, 1.48, 0.00 +170, -0.53, -4.65, 0.00 +171, -1.24, -10.70, 0.00 +172, -1.95, -16.63, 0.00 +173, -2.67, -22.41, 0.00 +174, -3.38, -27.97, 0.00 +175, -4.08, -33.26, 0.00 +176, -4.76, -38.32, 0.00 +177, -5.41, -43.03, 0.00 +178, -6.03, -47.39, 0.00 +179, -6.62, -51.39, 0.00 +180, -7.16, -54.97, 0.00 +181, -7.65, -58.12, 0.00 +182, -8.08, -60.82, 0.00 +183, -8.46, -63.00, 0.00 +184, -8.77, -64.74, 0.00 +185, -9.01, -65.93, 0.00 +186, -9.17, -66.52, 0.00 +187, -9.24, -66.54, 0.00 +188, -9.21, -65.89, 0.00 +189, -9.10, -64.66, 0.00 +190, -8.89, -62.77, 0.00 +191, -8.57, -60.17, 0.00 +192, -8.13, -56.85, 0.00 +193, -7.57, -52.71, 0.00 +194, -6.91, -47.93, 0.00 +195, -6.10, -42.17, 0.00 +196, -5.16, -35.60, 0.00 +197, -4.07, -28.05, 0.00 +198, -2.86, -19.72, 0.00 diff --git a/TestCases/serial_regression.py b/TestCases/serial_regression.py index 0e276f37db2a..3f181347db04 100755 --- a/TestCases/serial_regression.py +++ b/TestCases/serial_regression.py @@ -127,7 +127,7 @@ def main(): biparabolic.cfg_dir = "euler/biparabolic" biparabolic.cfg_file = "BIPARABOLIC.cfg" biparabolic.test_iter = 25 - biparabolic.test_vals = [-2.171577, 0.466003, 0.284966, 3.430832] + biparabolic.test_vals = [-2.188810, 0.428611, 0.270065, 3.418600] test_list.append(biparabolic) # ONERA M6 Wing @@ -173,7 +173,7 @@ def main(): inv_channel.cfg_dir = "euler/channel" inv_channel.cfg_file = "inv_channel.cfg" inv_channel.test_iter = 20 - inv_channel.test_vals = [-4.418376, -1.269655, -2.009395, 1.032228, 5.000000, -0.424585, 0.000080, -0.002653, 1000.000000] + inv_channel.test_vals = [-3.612713, -0.787561, -1.835495, 1.690293, 5.000000, -0.023068, -0.006001, -0.011194, 1000.000000] test_list.append(inv_channel) # CRM DPW4 wing-body, transonic @@ -181,7 +181,7 @@ def main(): inv_crm_jst.cfg_dir = "euler/CRM" inv_crm_jst.cfg_file = "inv_CRM_JST.cfg" inv_crm_jst.test_iter = 20 - inv_crm_jst.test_vals = [-2.057543, -1.908317, -1.902763, -1.770370, -1.455672] + inv_crm_jst.test_vals = [-2.054533, -1.906359, -1.899461, -1.760903, -1.452321] test_list.append(inv_crm_jst) ########################## @@ -240,7 +240,7 @@ def main(): poiseuille_profile.cfg_dir = "navierstokes/poiseuille" poiseuille_profile.cfg_file = "profile_poiseuille.cfg" poiseuille_profile.test_iter = 10 - poiseuille_profile.test_vals = [-12.010782, -7.649389, -0.000000, 2.089953] + poiseuille_profile.test_vals = [-12.010777, -7.648201, -0.000000, 2.089953] poiseuille_profile.test_vals_aarch64 = [-12.009012, -7.262299, -0.000000, 2.089953] #last 4 columns test_list.append(poiseuille_profile) @@ -249,7 +249,7 @@ def main(): lam_naca0012.cfg_dir = "navierstokes/naca0012" lam_naca0012.cfg_file = "lam_NACA0012.cfg" lam_naca0012.test_iter = 20 - lam_naca0012.test_vals = [-5.476452, -3.192160, -3.250578, -0.070055] + lam_naca0012.test_vals = [-5.560757, -3.216919, -3.356493, -0.150846] test_list.append(lam_naca0012) ########################## @@ -276,7 +276,7 @@ def main(): rae2822_sst.cfg_dir = "rans/rae2822" rae2822_sst.cfg_file = "turb_SST_RAE2822.cfg" rae2822_sst.test_iter = 20 - rae2822_sst.test_vals = [-2.027432, -1.348503, 5.895301, 0.631057, 0.015689, 100.000000] + rae2822_sst.test_vals = [-2.027466, -1.348503, 5.895325, 0.631054, 0.015689, 100.000000] test_list.append(rae2822_sst) # RAE2822 SST_SUST @@ -349,7 +349,7 @@ def main(): turb_naca0012_sa.cfg_dir = "rans/naca0012" turb_naca0012_sa.cfg_file = "turb_NACA0012_sa.cfg" turb_naca0012_sa.test_iter = 5 - turb_naca0012_sa.test_vals = [-12.037320, -16.384159, 1.080346, 0.018385, 20.000000, -3.457056, 20.000000, -4.641265, 0.000000] + turb_naca0012_sa.test_vals = [-12.037294, -16.384159, 1.080346, 0.018385, 20.000000, -3.456773, 20.000000, -4.641241, 0.000000] turb_naca0012_sa.test_vals_aarch64 = [-12.037297, -16.384158, 1.080346, 0.018385, 20.000000, -3.455886, 20.000000, -4.641247, 0.000000] turb_naca0012_sa.timeout = 3200 test_list.append(turb_naca0012_sa) @@ -419,7 +419,7 @@ def main(): turb_sst_flatplate.cfg_dir = "rans/flatplate" turb_sst_flatplate.cfg_file = "turb_SST_flatplate.cfg" turb_sst_flatplate.test_iter = 20 - turb_sst_flatplate.test_vals = [-5.355794, -2.389965, -2.978049, 0.128709, -2.673382, 5.640897] + turb_sst_flatplate.test_vals = [-5.237309, -2.258055, -2.652985, 0.248456, -1.445643, 6.813102] test_list.append(turb_sst_flatplate) # S809 wind turbine airfoil, SA @@ -439,7 +439,7 @@ def main(): axi_rans_air_nozzle_restart.cfg_dir = "axisymmetric_rans/air_nozzle" axi_rans_air_nozzle_restart.cfg_file = "air_nozzle_restart.cfg" axi_rans_air_nozzle_restart.test_iter = 10 - axi_rans_air_nozzle_restart.test_vals = [-5.118831, 0.457732, -1.640628, 2.890364, 0.000000] + axi_rans_air_nozzle_restart.test_vals = [-5.118839, 0.457719, -1.640848, 2.890044, 0.000000] axi_rans_air_nozzle_restart.test_vals_aarch64 = [-14.143715, -9.170705, -10.848554, -5.776746, 0.000000] axi_rans_air_nozzle_restart.tol = 0.0001 test_list.append(axi_rans_air_nozzle_restart) @@ -449,7 +449,7 @@ def main(): axi_rans_air_nozzle_density_velocity.cfg_dir = "axisymmetric_rans/air_nozzle" axi_rans_air_nozzle_density_velocity.cfg_file = "air_nozzle_density_velocity.cfg" axi_rans_air_nozzle_density_velocity.test_iter = 10 - axi_rans_air_nozzle_density_velocity.test_vals = [704.800000, -1.879849, 4.023872, 0.501073, 4.420427] + axi_rans_air_nozzle_density_velocity.test_vals = [704.800000, -1.879848, 4.023872, 0.501091, 4.420520] test_list.append(axi_rans_air_nozzle_density_velocity) # Axisymmetric air nozzle species @@ -950,10 +950,10 @@ def main(): test_list.append(ddes_flatplate) # Hybrid RANS/LES models on the ONERA M6 wing, restarting from a RANS solution - ddes_oneram6_vals = {"sst_ddes": [-2.221793, -0.757241, 2.506746, 0.261418, 0.022680], - "sst_iddes": [-2.226164, 3.063400, 2.594586, 0.261433, 0.022683], - "sst_siddes": [-2.226164, 3.063400, 2.594638, 0.261418, 0.022680], - "sst_eddes": [-2.221792, 0.258724, 2.506730, 0.261418, 0.022680], + ddes_oneram6_vals = {"sst_ddes": [-2.221793, -0.757237, 2.506728, 0.261418, 0.022680], + "sst_iddes": [-2.226164, 3.063400, 2.594574, 0.261433, 0.022683], + "sst_siddes": [-2.226164, 3.063400, 2.594626, 0.261418, 0.022680], + "sst_eddes": [-2.221792, 0.258723, 2.506713, 0.261418, 0.022680], "sa_eddes": [-3.510006, -3.683557, 0.266420, 0.023471]} for model, vals in ddes_oneram6_vals.items(): ddes_oneram6 = TestCase('ddes_oneram6_' + model) @@ -1031,7 +1031,7 @@ def main(): edge_PPR.cfg_dir = "nicf/edge" edge_PPR.cfg_file = "edge_PPR.cfg" edge_PPR.test_iter = 20 - edge_PPR.test_vals = [-11.793142, -5.626916, -0.000034, 0.000000] + edge_PPR.test_vals = [-11.792553, -5.626268, -0.000034, 0.000000] test_list.append(edge_PPR) @@ -1053,7 +1053,7 @@ def main(): Jones_tc_restart.cfg_dir = "turbomachinery/APU_turbocharger" Jones_tc_restart.cfg_file = "Jones_restart.cfg" Jones_tc_restart.test_iter = 5 - Jones_tc_restart.test_vals = [-0.151366, -0.171658, -8.195252, -2.499024, -7.362886, -1.883840, 73291.000000, 73291.000000, 0.020062, 82.380000] + Jones_tc_restart.test_vals = [-0.151365, -0.171559, -8.195251, -2.499024, -7.362867, -1.884109, 73291.000000, 73291.000000, 0.020062, 82.380000] test_list.append(Jones_tc_restart) # 2D axial stage @@ -1069,7 +1069,7 @@ def main(): transonic_stator_restart.cfg_dir = "turbomachinery/transonic_stator_2D" transonic_stator_restart.cfg_file = "transonic_stator_restart.cfg" transonic_stator_restart.test_iter = 20 - transonic_stator_restart.test_vals = [-4.364091, -2.489509, -2.081581, 1.729990, -1.467009, 3.223101, -471620.000000, 94.839000, -0.071910] + transonic_stator_restart.test_vals = [-4.364098, -2.489485, -2.081630, 1.729983, -1.466951, 3.223070, -471620.000000, 94.839000, -0.071907] transonic_stator_restart.test_vals_aarch64 = [-4.367784, -2.492912, -2.082414, 1.727491, -1.466974, 3.224730, -471620.000000, 94.839000, -0.052082] test_list.append(transonic_stator_restart) @@ -1099,7 +1099,7 @@ def main(): uniform_flow.cfg_dir = "sliding_interface/uniform_flow" uniform_flow.cfg_file = "uniform_NN.cfg" uniform_flow.test_iter = 2 - uniform_flow.test_vals = [2.000000, 0.000000, -0.230680, -13.250344] + uniform_flow.test_vals = [2.000000, 0.000000, -0.230680, -13.252537] uniform_flow.test_vals_aarch64 = [2.000000, 0.000000, -0.230641, -13.249000] uniform_flow.tol = 0.000001 uniform_flow.unsteady = True @@ -1241,7 +1241,7 @@ def main(): fsi2d.cfg_dir = "fea_fsi/WallChannel_2d" fsi2d.cfg_file = "configFSI.cfg" fsi2d.test_iter = 4 - fsi2d.test_vals = [4.000000, 0.000000, -3.725521, -4.278759] + fsi2d.test_vals = [4.000000, 0.000000, -3.725511, -4.278761] fsi2d.multizone = True fsi2d.unsteady = True test_list.append(fsi2d) @@ -1251,7 +1251,7 @@ def main(): fsi_cht.cfg_dir = "fea_fsi/stat_fsi" fsi_cht.cfg_file = "config.cfg" fsi_cht.test_iter = 20 - fsi_cht.test_vals = [5.000000, -5.077006, -5.379456, -9.247798, -9.319797, -9.184989, 608.350000, -0.012973, 0.000000, 29.000000] + fsi_cht.test_vals = [5.000000, -5.076664, -5.379765, -9.247797, -9.320280, -9.184828, 608.350000, -0.012973, 0.000000, 29.000000] fsi_cht.multizone = True test_list.append(fsi_cht) @@ -1260,7 +1260,7 @@ def main(): dyn_fsi.cfg_dir = "fea_fsi/dyn_fsi" dyn_fsi.cfg_file = "config.cfg" dyn_fsi.test_iter = 4 - dyn_fsi.test_vals = [-4.328792, -4.153004, 0.000000, 85.000000] + dyn_fsi.test_vals = [-4.328792, -4.153000, 0.000000, 86.000000] dyn_fsi.multizone = True dyn_fsi.unsteady = True test_list.append(dyn_fsi) @@ -1270,7 +1270,7 @@ def main(): airfoilRBF.cfg_dir = "fea_fsi/Airfoil_RBF" airfoilRBF.cfg_file = "config.cfg" airfoilRBF.test_iter = 1 - airfoilRBF.test_vals = [1.000000, 0.030416, -3.530954] + airfoilRBF.test_vals = [1.000000, 0.024591, -3.526663] airfoilRBF.tol = 0.0001 airfoilRBF.multizone = True test_list.append(airfoilRBF) @@ -1680,7 +1680,7 @@ def main(): shape_opt_euler_py.cfg_dir = "optimization_euler/steady_naca0012" shape_opt_euler_py.cfg_file = "inv_NACA0012_adv.cfg" shape_opt_euler_py.test_iter = 1 - shape_opt_euler_py.test_vals = [1.000000, 2.000000, 0.000013, 0.003642] + shape_opt_euler_py.test_vals = [1.000000, 1.000000, 0.000021, 0.003642] shape_opt_euler_py.command = TestCase.Command(exec = "shape_optimization.py", param = "-g CONTINUOUS_ADJOINT -f") shape_opt_euler_py.timeout = 1600 shape_opt_euler_py.tol = 0.00001 @@ -1732,7 +1732,7 @@ def main(): opt_multiobj1surf_py.cfg_dir = "optimization_euler/multiobjective_wedge" opt_multiobj1surf_py.cfg_file = "inv_wedge_ROE_multiobj_1surf.cfg" opt_multiobj1surf_py.test_iter = 1 - opt_multiobj1surf_py.test_vals = [1.000000, 2.000000, 12.125690, 5.935058] + opt_multiobj1surf_py.test_vals = [1.000000, 1.000000, 36.816070, 5.993726] opt_multiobj1surf_py.command = TestCase.Command(exec = "shape_optimization.py", param = "-g CONTINUOUS_ADJOINT -f") opt_multiobj1surf_py.timeout = 1600 opt_multiobj1surf_py.tol = 0.00001 @@ -1745,7 +1745,7 @@ def main(): opt_2surf1obj_py.cfg_dir = "optimization_euler/multiobjective_wedge" opt_2surf1obj_py.cfg_file = "inv_wedge_ROE_2surf_1obj.cfg" opt_2surf1obj_py.test_iter = 1 - opt_2surf1obj_py.test_vals = [1.000000, 1.000000, 2.005580, 0.000531] + opt_2surf1obj_py.test_vals = [1.000000, 1.000000, 2.005020, 0.000493] opt_2surf1obj_py.command = TestCase.Command(exec = "shape_optimization.py", param = "-g CONTINUOUS_ADJOINT -f") opt_2surf1obj_py.timeout = 1600 opt_2surf1obj_py.tol = 0.00001 @@ -1762,7 +1762,7 @@ def main(): pywrapper_naca0012.cfg_dir = "euler/naca0012" pywrapper_naca0012.cfg_file = "inv_NACA0012_Roe.cfg" pywrapper_naca0012.test_iter = 20 - pywrapper_naca0012.test_vals = [-4.489721, -3.937702, 0.293347, 0.025228] + pywrapper_naca0012.test_vals = [-4.561230, -3.981697, 0.297778, 0.026136] pywrapper_naca0012.command = TestCase.Command(exec = "SU2_CFD.py", param = "-f") pywrapper_naca0012.timeout = 1600 pywrapper_naca0012.tol = 0.00001 @@ -1803,7 +1803,7 @@ def main(): pywrapper_fsi2d.cfg_dir = "fea_fsi/WallChannel_2d" pywrapper_fsi2d.cfg_file = "configFSI.cfg" pywrapper_fsi2d.test_iter = 4 - pywrapper_fsi2d.test_vals = [4.000000, 0.000000, -3.725521, -4.278759] + pywrapper_fsi2d.test_vals = [4.000000, 0.000000, -3.725511, -4.278761] pywrapper_fsi2d.command = TestCase.Command(exec = "SU2_CFD.py", param = "--nZone 2 --fsi True -f") pywrapper_fsi2d.unsteady = True pywrapper_fsi2d.multizone = True @@ -1818,7 +1818,7 @@ def main(): pywrapper_unsteadyCHT.cfg_dir = "py_wrapper/flatPlate_unsteady_CHT" pywrapper_unsteadyCHT.cfg_file = "unsteady_CHT_FlatPlate_Conf.cfg" pywrapper_unsteadyCHT.test_iter = 5 - pywrapper_unsteadyCHT.test_vals = [-1.614169, 2.260215, -0.019432, 0.203751] + pywrapper_unsteadyCHT.test_vals = [-1.614168, 2.260661, 0.000055, 0.103058] pywrapper_unsteadyCHT.command = TestCase.Command(exec = "python", param = "launch_unsteady_CHT_FlatPlate.py -f") pywrapper_unsteadyCHT.timeout = 1600 pywrapper_unsteadyCHT.tol = 0.00001 diff --git a/TestCases/serial_regression_AD.py b/TestCases/serial_regression_AD.py index fc9bf1036935..a551fa277d2d 100644 --- a/TestCases/serial_regression_AD.py +++ b/TestCases/serial_regression_AD.py @@ -96,7 +96,7 @@ def main(): discadj_rans_naca0012_sst.cfg_dir = "disc_adj_rans/naca0012" discadj_rans_naca0012_sst.cfg_file = "turb_NACA0012_sst.cfg" discadj_rans_naca0012_sst.test_iter = 10 - discadj_rans_naca0012_sst.test_vals = [-2.096038, -0.178557, 0.351620, -0.023443] + discadj_rans_naca0012_sst.test_vals = [-2.096037, -0.178557, 0.351610, -0.023443] test_list.append(discadj_rans_naca0012_sst) ####################################### @@ -108,7 +108,7 @@ def main(): discadj_incomp_NACA0012.cfg_dir = "disc_adj_incomp_euler/naca0012" discadj_incomp_NACA0012.cfg_file = "incomp_NACA0012_disc.cfg" discadj_incomp_NACA0012.test_iter = 20 - discadj_incomp_NACA0012.test_vals = [20.000000, -3.134640, -2.294875, 0.000000] + discadj_incomp_NACA0012.test_vals = [20.000000, -3.217506, -2.513786, 0.000000] test_list.append(discadj_incomp_NACA0012) ##################################### @@ -132,7 +132,7 @@ def main(): discadj_cylinder.cfg_dir = "disc_adj_rans/cylinder" discadj_cylinder.cfg_file = "cylinder.cfg" discadj_cylinder.test_iter = 9 - discadj_cylinder.test_vals = [1.639373, -2.834286, -0.009537, 0.000020] + discadj_cylinder.test_vals = [1.639367, -2.834306, -0.009537, 0.000020] discadj_cylinder.unsteady = True test_list.append(discadj_cylinder) @@ -145,7 +145,7 @@ def main(): discadj_DT_1ST_cylinder.cfg_dir = "disc_adj_rans/cylinder_DT_1ST" discadj_DT_1ST_cylinder.cfg_file = "cylinder.cfg" discadj_DT_1ST_cylinder.test_iter = 9 - discadj_DT_1ST_cylinder.test_vals = [1.196421, -3.339044, -0.006211, 0.000020] + discadj_DT_1ST_cylinder.test_vals = [1.196419, -3.339055, -0.006211, 0.000020] discadj_DT_1ST_cylinder.unsteady = True test_list.append(discadj_DT_1ST_cylinder) @@ -158,7 +158,7 @@ def main(): discadj_pitchingNACA0012.cfg_dir = "disc_adj_euler/naca0012_pitching" discadj_pitchingNACA0012.cfg_file = "inv_NACA0012_pitching.cfg" discadj_pitchingNACA0012.test_iter = 4 - discadj_pitchingNACA0012.test_vals = [-1.140869, -1.575299, -0.005305, 0.000003] + discadj_pitchingNACA0012.test_vals = [-1.150803, -1.584891, -0.005578, 0.000004] discadj_pitchingNACA0012.unsteady = True test_list.append(discadj_pitchingNACA0012) @@ -167,7 +167,7 @@ def main(): unst_deforming_naca0012.cfg_dir = "disc_adj_euler/naca0012_pitching_def" unst_deforming_naca0012.cfg_file = "inv_NACA0012_pitching_deform_ad.cfg" unst_deforming_naca0012.test_iter = 4 - unst_deforming_naca0012.test_vals = [-1.876120, -1.766274, 4314.900000, 0.000003] + unst_deforming_naca0012.test_vals = [-1.881846, -1.771958, 4469.400000, 0.000003] unst_deforming_naca0012.unsteady = True test_list.append(unst_deforming_naca0012) @@ -200,7 +200,7 @@ def main(): discadj_trans_stator.cfg_dir = "disc_adj_turbomachinery/transonic_stator_2D" discadj_trans_stator.cfg_file = "transonic_stator.cfg" discadj_trans_stator.test_iter = 79 - discadj_trans_stator.test_vals = [79.000000, -7.307361, -9.892466, -10.038191, -13.367660] + discadj_trans_stator.test_vals = [79.000000, -7.290460, -9.860576, -10.024735, -13.352842] discadj_trans_stator.test_vals_aarch64 = [79.000000, -7.308167, -9.891117, -10.038669, -13.368501] test_list.append(discadj_trans_stator) @@ -209,7 +209,7 @@ def main(): discadj_axial_stage.cfg_dir = "disc_adj_turbomachinery/axial_stage_2D" discadj_axial_stage.cfg_file = "Axial_stage2D.cfg" discadj_axial_stage.test_iter = 79 - discadj_axial_stage.test_vals = [79.000000, -6.499484, -6.634634] + discadj_axial_stage.test_vals = [79.000000, -6.499476, -6.634694] discadj_axial_stage.test_vals_aarch64 = [79.000000, -6.605593, -7.138207] test_list.append(discadj_axial_stage) @@ -248,7 +248,7 @@ def main(): discadj_fsi.cfg_dir = "disc_adj_fsi" discadj_fsi.cfg_file = "config.cfg" discadj_fsi.test_iter = 6 - discadj_fsi.test_vals = [6.000000, -1.956662, -3.071318, 0.000440, -1.062800] + discadj_fsi.test_vals = [6.000000, -1.957003, -3.071513, 0.000440, -1.062800] discadj_fsi.test_vals_aarch64 = [6.000000, -1.956662, -3.071318, 0.000440, -1.062800] test_list.append(discadj_fsi) diff --git a/TestCases/tutorials.py b/TestCases/tutorials.py index 707f08851a2f..c2cbec670ce5 100644 --- a/TestCases/tutorials.py +++ b/TestCases/tutorials.py @@ -187,7 +187,7 @@ def main(): tutorial_inv_bump.cfg_dir = "../Tutorials/compressible_flow/Inviscid_Bump" tutorial_inv_bump.cfg_file = "inv_channel.cfg" tutorial_inv_bump.test_iter = 0 - tutorial_inv_bump.test_vals = [-1.437425, 4.075857, 0.085905, 0.123625] + tutorial_inv_bump.test_vals = [-1.437425, 4.075857, 0.021702, 0.026792] test_list.append(tutorial_inv_bump) # Inviscid Wedge @@ -195,7 +195,7 @@ def main(): tutorial_inv_wedge.cfg_dir = "../Tutorials/compressible_flow/Inviscid_Wedge" tutorial_inv_wedge.cfg_file = "inv_wedge_HLLC.cfg" tutorial_inv_wedge.test_iter = 0 - tutorial_inv_wedge.test_vals = [-0.481460, 5.253008, -0.191841, 0.033699] + tutorial_inv_wedge.test_vals = [-0.481460, 5.253008, -0.233459, 0.041019] tutorial_inv_wedge.no_restart = True test_list.append(tutorial_inv_wedge) @@ -204,7 +204,7 @@ def main(): tutorial_inv_onera.cfg_dir = "../Tutorials/compressible_flow/Inviscid_ONERAM6" tutorial_inv_onera.cfg_file = "inv_ONERAM6.cfg" tutorial_inv_onera.test_iter = 0 - tutorial_inv_onera.test_vals = [-5.204928, -4.597762, 0.243858, 0.110778] + tutorial_inv_onera.test_vals = [-5.204928, -4.597762, 0.250116, 0.092787] tutorial_inv_onera.no_restart = True test_list.append(tutorial_inv_onera) @@ -213,7 +213,7 @@ def main(): tutorial_lam_cylinder.cfg_dir = "../Tutorials/compressible_flow/Laminar_Cylinder" tutorial_lam_cylinder.cfg_file = "lam_cylinder.cfg" tutorial_lam_cylinder.test_iter = 0 - tutorial_lam_cylinder.test_vals = [-6.162141, -0.699617, -0.080602, 42.990503] + tutorial_lam_cylinder.test_vals = [-6.162141, -0.699617, 0.730462, 38.465990] tutorial_lam_cylinder.no_restart = True test_list.append(tutorial_lam_cylinder) @@ -259,7 +259,7 @@ def main(): tutorial_trans_flatplate_T3Am.cfg_dir = "../Tutorials/compressible_flow/Transitional_Flat_Plate/Langtry_and_Menter/T3A-" tutorial_trans_flatplate_T3Am.cfg_file = "transitional_LM_model_ConfigFile.cfg" tutorial_trans_flatplate_T3Am.test_iter = 20 - tutorial_trans_flatplate_T3Am.test_vals = [-5.589221, -1.700900, -3.101441, -0.104205, -3.690983, 3.287539, -2.394493, 1.119670] + tutorial_trans_flatplate_T3Am.test_vals = [-5.589226, -1.700900, -3.101453, -0.104209, -3.690983, 3.287539, -2.394493, 1.119670] tutorial_trans_flatplate_T3Am.test_vals_aarch64 = [-5.540938, -1.681627, -2.878831, -0.058224, -3.695533, 3.413628, -2.385345, 1.103633] tutorial_trans_flatplate_T3Am.no_restart = True test_list.append(tutorial_trans_flatplate_T3Am) @@ -287,7 +287,7 @@ def main(): tutorial_turb_oneram6.cfg_dir = "../Tutorials/compressible_flow/Turbulent_ONERAM6" tutorial_turb_oneram6.cfg_file = "turb_ONERAM6.cfg" tutorial_turb_oneram6.test_iter = 0 - tutorial_turb_oneram6.test_vals = [-4.564441, -11.533717, 0.251049, 0.081260] + tutorial_turb_oneram6.test_vals = [-4.564441, -11.533673, 0.251049, 0.081260] test_list.append(tutorial_turb_oneram6) # NICFD Nozzle @@ -314,7 +314,7 @@ def main(): tutorial_unst_naca0012.cfg_dir = "../Tutorials/compressible_flow/Unsteady_NACA0012" tutorial_unst_naca0012.cfg_file = "unsteady_naca0012.cfg" tutorial_unst_naca0012.test_iter = 520 - tutorial_unst_naca0012.test_vals = [520.000000, 0.000000, -5.299902, 0.000000, 0.299247, 0.714557, 0.002870, 0.007029] + tutorial_unst_naca0012.test_vals = [520.000000, 0.000000, -5.295222, 0.000000, 0.299997, 0.798871, 0.002555, 0.007836] tutorial_unst_naca0012.test_vals_aarch64 = [520, 0, -5.292359, 0, 0.284720, 0.766329, 0.000954, 0.007565] tutorial_unst_naca0012.unsteady = True test_list.append(tutorial_unst_naca0012) @@ -335,7 +335,7 @@ def main(): tutorial_design_inv_naca0012.cfg_dir = "../Tutorials/design/Inviscid_2D_Unconstrained_NACA0012" tutorial_design_inv_naca0012.cfg_file = "inv_NACA0012_basic.cfg" tutorial_design_inv_naca0012.test_iter = 0 - tutorial_design_inv_naca0012.test_vals = [-3.585391, -2.989014, 0.142510, 0.172748] + tutorial_design_inv_naca0012.test_vals = [-3.585391, -2.989014, 0.156436, 0.193853] tutorial_design_inv_naca0012.no_restart = True test_list.append(tutorial_design_inv_naca0012) diff --git a/TestCases/vandv.py b/TestCases/vandv.py index c6ce2cb23828..a3aea1d0851e 100644 --- a/TestCases/vandv.py +++ b/TestCases/vandv.py @@ -45,7 +45,7 @@ def main(): p30n30.cfg_dir = "vandv/rans/30p30n" p30n30.cfg_file = "config.cfg" p30n30.test_iter = 5 - p30n30.test_vals = [-11.267106, -11.168215, -11.182822, -10.949673, -14.233489, 0.052235, 2.830394, 1.318894, -1.210646, 1.000000, 12.763000] + p30n30.test_vals = [-11.267231, -11.168332, -11.182969, -10.949857, -14.233489, 0.052235, 2.830394, 1.318894, -1.210500, 1.000000, 12.763000] test_list.append(p30n30) # This is not part of the V&V cases yet, its tested in this script because it is a relatively long test (~1 min). @@ -54,7 +54,7 @@ def main(): p30n30_ad.cfg_dir = "vandv/rans/30p30n" p30n30_ad.cfg_file = "config_ad.cfg" p30n30_ad.test_iter = 9 - p30n30_ad.test_vals = [-7.283709, -6.072615, -5.995304, -7.197048, -4.568373, -1.167146, -2.316777, 1.1791e-01, 3.4123e+01] + p30n30_ad.test_vals = [-7.448870, -6.332809, -6.255594, -7.455457, -4.760040, -1.167091, -2.316777, 0.117910, 34.123000] p30n30_ad.command = TestCase.Command("mpirun -n 2", "SU2_CFD_AD") test_list.append(p30n30_ad) @@ -72,7 +72,7 @@ def main(): bump_sst1994m.cfg_dir = "vandv/rans/bump_in_channel" bump_sst1994m.cfg_file = "turb_bump_sst.cfg" bump_sst1994m.test_iter = 5 - bump_sst1994m.test_vals = [-6.497322, -4.234388, -3.813607, -1.011693, -4.012643, 0.181789, 0.004933] + bump_sst1994m.test_vals = [-6.497142, -4.234210, -3.813559, -1.011510, -4.012312, 0.181606, 0.004933] bump_sst1994m.test_vals_aarch64 = [-13.042689, -10.812982, -10.604523, -7.655547, -10.816257, -5.308083, 0.004911] test_list.append(bump_sst1994m) @@ -91,7 +91,7 @@ def main(): swbli_sst.cfg_dir = "vandv/rans/swbli" swbli_sst.cfg_file = "config_sst.cfg" swbli_sst.test_iter = 5 - swbli_sst.test_vals = [-6.629003, -5.974424, -6.441377, -5.452202, -7.662611, 0.071744, 0.001815, -1.199321, -3.785268, 13.399000] + swbli_sst.test_vals = [-6.629007, -5.974427, -6.441393, -5.452208, -7.662648, 0.071811, 0.001815, -1.199326, -3.785344, 13.399000] test_list.append(swbli_sst) # DSMA661 - SA @@ -99,7 +99,7 @@ def main(): dsma661_sa.cfg_dir = "vandv/rans/dsma661" dsma661_sa.cfg_file = "dsma661_sa_config.cfg" dsma661_sa.test_iter = 5 - dsma661_sa.test_vals = [-11.240967, -8.243826, -8.958188, -5.895885, -10.737669, 0.155687, 0.024232] + dsma661_sa.test_vals = [-11.249578, -8.243691, -8.979211, -5.915958, -10.737668, 0.155687, 0.024232] dsma661_sa.test_vals_aarch64 = [-11.293183, -8.241775, -9.083761, -6.011398, -10.737680, 0.155687, 0.024232] test_list.append(dsma661_sa) From 1b95e76eff7f46d0b35ae4874bd0823469bff5b5 Mon Sep 17 00:00:00 2001 From: bigfooted Date: Sat, 5 Dec 2026 20:57:06 +0100 Subject: [PATCH 42/42] Fix the coarse linear-solver cap, wall-end flags and incompressible coarse viscous flux - Incompressible coarse levels keep the averaged viscous gradient. The edge-only coarse flux and the effective-distance Jacobian are compressible only, and the incompressible Jacobian has no effective distance, so the corrected coarse flux did not match it. - The active level of the Full-MG startup uses LINEAR_SOLVER_ITER; only the levels below it are capped by MG_LINEAR_SOLVER_ITER (CConfig::GetMG_LinSolIter). - MG_LINEAR_SOLVER_ITER entries of 0 and TURB_SUBITER= 0 are rejected. A 0 entry used to mean LINEAR_SOLVER_ITER, the opposite of a cap. - The MUSCL_FIRST_ORDER_WALL_ENDS flags move to CEulerSolver::SetWallEndFlags, exchange halos through InitiateComms with a new FIRST_ORDER_RECONSTRUCTION quantity instead of a hand-written Sendrecv loop, and are recomputed after mesh deformation. The multigrid correction weights are rebuilt when the flags change. References regenerated in the CI containers: inc_lam_cylinder, inc_lam_sphere and the cantera cases (incompressible MG), naca0012_FMG and turb_flatplate_sst_fullmg (Full-MG cap). Co-Authored-By: Claude Opus 5.5 --- Common/include/CConfig.hpp | 8 + Common/include/option_structure.hpp | 1 + Common/src/CConfig.cpp | 8 +- .../integration/CMultiGridIntegration.hpp | 2 +- SU2_CFD/include/solvers/CEulerSolver.hpp | 7 + .../include/solvers/CFVMFlowSolverBase.inl | 2 +- SU2_CFD/include/solvers/CScalarSolver.inl | 2 +- SU2_CFD/include/solvers/CSolver.hpp | 7 + SU2_CFD/include/variables/CEulerVariable.hpp | 12 ++ SU2_CFD/include/variables/CVariable.hpp | 6 + SU2_CFD/src/drivers/CDriver.cpp | 4 +- .../src/integration/CMultiGridIntegration.cpp | 13 +- SU2_CFD/src/iteration/CFluidIteration.cpp | 2 +- SU2_CFD/src/iteration/CIteration.cpp | 2 + SU2_CFD/src/solvers/CEulerSolver.cpp | 183 +++++++++--------- SU2_CFD/src/solvers/CSolver.cpp | 7 + TestCases/hybrid_regression.py | 2 +- TestCases/parallel_regression.py | 10 +- TestCases/serial_regression.py | 6 +- config_template.cfg | 6 +- 20 files changed, 175 insertions(+), 115 deletions(-) diff --git a/Common/include/CConfig.hpp b/Common/include/CConfig.hpp index 909dadac652d..1284de232919 100644 --- a/Common/include/CConfig.hpp +++ b/Common/include/CConfig.hpp @@ -3912,6 +3912,14 @@ class CConfig { */ const CMGOptions& GetMGOptions() const { return MGOptions; } + /*! + * \brief Linear solver iterations on a multigrid level. The finest active level, also during the + * full-multigrid startup, uses LINEAR_SOLVER_ITER. + */ + unsigned long GetMG_LinSolIter(unsigned short iMesh) const { + return (iMesh <= FinestMesh) ? Linear_Solver_Iter : MGOptions.MG_LinSolIter[iMesh]; + } + /*! * \brief plane of the FFD (I axis) that should be fixed. * \param[in] val_index - Index of the arrray with all the planes in the I direction that should be fixed. diff --git a/Common/include/option_structure.hpp b/Common/include/option_structure.hpp index c59d796272c2..850c31723e83 100644 --- a/Common/include/option_structure.hpp +++ b/Common/include/option_structure.hpp @@ -2971,6 +2971,7 @@ enum class MPI_QUANTITIES { MOM_COEFF , /*!< \brief Momentum coefficient for the Rhie-Chow scheme. */ MOM_CORRECTION , /*!< \brief Momentum correction for the pressure-based poisson solver (used when computing HbyA). */ HBYA_CORRECTION , /*!< \brief HbyA correction for the pressure-based poisson solver. */ + FIRST_ORDER_RECONSTRUCTION, /*!< \brief First-order reconstruction flag at wall ends. */ }; /*! diff --git a/Common/src/CConfig.cpp b/Common/src/CConfig.cpp index 97f96dc231c2..5ed0cc3ff514 100644 --- a/Common/src/CConfig.cpp +++ b/Common/src/CConfig.cpp @@ -2160,8 +2160,8 @@ void CConfig::SetConfig_Options() { * If fewer values than nMGLevels are given, the last value is repeated. DEFAULT: 0.5 \ingroup Config*/ addDoubleListOption("MG_CFL_SCALING", nMG_CflScaling_p, MG_CflScaling_p); /*!\brief MG_LINEAR_SOLVER_ITER\n DESCRIPTION: Maximum linear solver iterations on coarse MG levels. Entry i applies to level i+1; - * the last value is repeated, and the cap never exceeds LINEAR_SOLVER_ITER. Not applied with the discrete adjoint. - * DEFAULT: 3 \ingroup Config*/ + * the last value is repeated, and the cap never exceeds LINEAR_SOLVER_ITER. The active Full-MG startup level and + * the discrete adjoint are not capped. DEFAULT: 3 \ingroup Config*/ addUShortListOption("MG_LINEAR_SOLVER_ITER", nMG_LinSolIter_p, MG_LinSolIter_p); /*!\par CONFIG_CATEGORY: Spatial Discretization \ingroup Config*/ @@ -5064,6 +5064,8 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i RampMUSCL = false; } + if (Turb_SubIter == 0) SU2_MPI::Error("TURB_SUBITER must be at least 1.", CURRENT_FUNCTION); + if (MUSCL_FirstOrderWallEnds && ((Kind_Regime == ENUM_REGIME::INCOMPRESSIBLE) || GetNEMOProblem())) { SU2_MPI::Error("MUSCL_FIRST_ORDER_WALL_ENDS is only implemented for the compressible flow solver.", CURRENT_FUNCTION); } @@ -5332,6 +5334,8 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i /*--- Linear solver iteration cap per level; level 0 always uses LINEAR_SOLVER_ITER. The discrete * adjoint transposes each recorded solve with LINEAR_SOLVER_ITER, so it caps no level. ---*/ + for (unsigned short i = 0; i < nMG_LinSolIter_p; ++i) + if (MG_LinSolIter_p[i] == 0) SU2_MPI::Error("MG_LINEAR_SOLVER_ITER entries must be positive.", CURRENT_FUNCTION); MGOptions.MG_LinSolIter.assign(nMGLevels + 1, Linear_Solver_Iter); for (unsigned short i = 1; (i <= nMGLevels) && !DiscreteAdjoint; ++i) { const unsigned long cap = (nMG_LinSolIter_p != 0) ? MG_LinSolIter_p[min(i - 1, nMG_LinSolIter_p - 1)] : 3; diff --git a/SU2_CFD/include/integration/CMultiGridIntegration.hpp b/SU2_CFD/include/integration/CMultiGridIntegration.hpp index 8d5ed92eff3d..956e399f4466 100644 --- a/SU2_CFD/include/integration/CMultiGridIntegration.hpp +++ b/SU2_CFD/include/integration/CMultiGridIntegration.hpp @@ -435,7 +435,7 @@ class CMultiGridIntegration final : public CIntegration { * Allocated on first use, only when MG_LINEAR_PROLONGATION is on. */ vector prolongGradient; vector> correctionWeight; /*!< \brief Per level, weight of the correction near wall ends. */ - bool correctionWeightReady = false; /*!< \brief The weights have been computed. */ + unsigned long correctionWeightVersion = std::numeric_limits::max(); /*!< \brief Wall-end flag version the weights belong to. */ CSysVector correctionHops; /*!< \brief Coarse CVs from the nearest wall end, with halos. */ /*! diff --git a/SU2_CFD/include/solvers/CEulerSolver.hpp b/SU2_CFD/include/solvers/CEulerSolver.hpp index 869eac4d800c..6f50ffb3d02b 100644 --- a/SU2_CFD/include/solvers/CEulerSolver.hpp +++ b/SU2_CFD/include/solvers/CEulerSolver.hpp @@ -394,6 +394,13 @@ class CEulerSolver : public CFVMFlowSolverBase::ImplicitEuler_Iteration(CGeometry *geometry, CSol END_SU2_OMP_FOR auto iter = System.Solve(Jacobian, LinSysRes, LinSysSol, geometry, config, - config->GetMGOptions().MG_LinSolIter[geometry->GetMGLevel()]); + config->GetMG_LinSolIter(geometry->GetMGLevel())); BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { SetIterLinSolver(iter); diff --git a/SU2_CFD/include/solvers/CScalarSolver.inl b/SU2_CFD/include/solvers/CScalarSolver.inl index f8e1a73d9e91..1694f57d4dab 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.inl +++ b/SU2_CFD/include/solvers/CScalarSolver.inl @@ -607,7 +607,7 @@ void CScalarSolver::ImplicitEuler_Iteration(CGeometry* geometry, C END_SU2_OMP_FOR auto iter = System.Solve(Jacobian, LinSysRes, LinSysSol, geometry, config, - config->GetMGOptions().MG_LinSolIter[geometry->GetMGLevel()]); + config->GetMG_LinSolIter(geometry->GetMGLevel())); BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { SetIterLinSolver(iter); diff --git a/SU2_CFD/include/solvers/CSolver.hpp b/SU2_CFD/include/solvers/CSolver.hpp index 9446db1e7351..fe9436fb607f 100644 --- a/SU2_CFD/include/solvers/CSolver.hpp +++ b/SU2_CFD/include/solvers/CSolver.hpp @@ -665,6 +665,13 @@ class CSolver { */ inline virtual void SetPrimitive_Limiter(CGeometry *geometry, const CConfig *config) { } + /*! + * \brief Flag the points reconstructed to first order at no-slip wall ends and sharp wall edges. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] config - Definition of the particular problem. + */ + inline virtual void SetWallEndFlags(CGeometry *geometry, const CConfig *config) { } + /*! * \brief Copy PRIMITIVE sensor values from primitive variable array into Sensor_Adapt. * \param[in] geometry - Geometrical definition of the problem. diff --git a/SU2_CFD/include/variables/CEulerVariable.hpp b/SU2_CFD/include/variables/CEulerVariable.hpp index b8d1df6a5f84..e64971953db3 100644 --- a/SU2_CFD/include/variables/CEulerVariable.hpp +++ b/SU2_CFD/include/variables/CEulerVariable.hpp @@ -400,4 +400,16 @@ class CEulerVariable : public CFlowVariable { */ su2vector SkipMGCorrection; + /*! + * \brief Incremented each time the two flags above are recomputed. + */ + unsigned long WallEndFlagsVersion = 0; + + inline uint8_t GetFirstOrderReconstruction(unsigned long iPoint) const final { + return FirstOrderReconstruction(iPoint); + } + inline void SetFirstOrderReconstruction(unsigned long iPoint, uint8_t val) final { + FirstOrderReconstruction(iPoint) = val; + } + }; diff --git a/SU2_CFD/include/variables/CVariable.hpp b/SU2_CFD/include/variables/CVariable.hpp index af4167209705..27aaf6ab554d 100644 --- a/SU2_CFD/include/variables/CVariable.hpp +++ b/SU2_CFD/include/variables/CVariable.hpp @@ -970,6 +970,12 @@ class CVariable { * \return Value of the pressure sensor. */ inline su2double GetSensor(unsigned long iPoint) const { return Sensor(iPoint); } + + /*! + * \brief First-order reconstruction flag of a point (1) or MUSCL (0). + */ + inline virtual uint8_t GetFirstOrderReconstruction(unsigned long iPoint) const { return 0; } + inline virtual void SetFirstOrderReconstruction(unsigned long iPoint, uint8_t val) {} inline const VectorType& GetSensor() const { return Sensor; } /*! diff --git a/SU2_CFD/src/drivers/CDriver.cpp b/SU2_CFD/src/drivers/CDriver.cpp index 29b6eaa517cd..b270f7a5eacb 100644 --- a/SU2_CFD/src/drivers/CDriver.cpp +++ b/SU2_CFD/src/drivers/CDriver.cpp @@ -1890,8 +1890,10 @@ void CDriver::InitializeNumerics(CConfig *config, CGeometry **geometry, CSolver if (incompressible) { /*--- Incompressible flow, use preconditioning method ---*/ numerics[MESH_0][FLOW_SOL][visc_term] = new CAvgGradInc_Flow(nDim, nVar_Flow, true, config); + + /*--- Coarse levels keep the averaged gradient, the incompressible Jacobian has no effective distance. ---*/ for (iMGlevel = 1; iMGlevel <= config->GetnMGLevels(); iMGlevel++) - numerics[iMGlevel][FLOW_SOL][visc_term] = new CAvgGradInc_Flow(nDim, nVar_Flow, true, config); + numerics[iMGlevel][FLOW_SOL][visc_term] = new CAvgGradInc_Flow(nDim, nVar_Flow, false, config); /*--- Definition of the boundary condition method ---*/ for (iMGlevel = 0; iMGlevel <= config->GetnMGLevels(); iMGlevel++) diff --git a/SU2_CFD/src/integration/CMultiGridIntegration.cpp b/SU2_CFD/src/integration/CMultiGridIntegration.cpp index 83b096545d89..4848b12ca4b6 100644 --- a/SU2_CFD/src/integration/CMultiGridIntegration.cpp +++ b/SU2_CFD/src/integration/CMultiGridIntegration.cpp @@ -465,7 +465,7 @@ void CMultiGridIntegration::MultiGrid_Iteration(CGeometry ****geometry, geometry[iZone][iInst][FinestMesh], config[iZone], true); } - /*--- The scalar solvers run on the active startup level and need its vorticity and strain rate. ---*/ + /*--- The friction forces and the scalar solvers on the active startup level need its gradients. ---*/ if (fmg_warmup) { solver_container[iZone][iInst][FinestMesh][Solver_Position]->Preprocessing(geometry[iZone][iInst][FinestMesh], @@ -655,9 +655,10 @@ void CMultiGridIntegration::MultiGrid_Cycle(CGeometry ****geometry, unsigned short iRKLimit = config->GetnRKStep(); /*--- Wall end weights for every level, once the hierarchy exists. ---*/ - if ((iMesh == MESH_0) && !correctionWeightReady) { + if (iMesh == MESH_0) { const auto* flowNodes = dynamic_cast(solver_container_fine[FLOW_SOL]->GetNodes()); - ComputeCorrectionWeights(geometry[iZone][iInst], flowNodes, config); + const unsigned long version = flowNodes ? flowNodes->WallEndFlagsVersion : 0; + if (version != correctionWeightVersion) ComputeCorrectionWeights(geometry[iZone][iInst], flowNodes, config); } /*--- Do a presmoothing on the grid iMesh to be restricted to the grid iMesh+1 ---*/ @@ -1465,8 +1466,10 @@ void CMultiGridIntegration::ComputeCorrectionWeights(CGeometry** geometry, const constexpr unsigned long nBlend = 4; const auto nLevels = config->GetnMGLevels(); + const unsigned long version = flowNodes ? flowNodes->WallEndFlagsVersion : 0; + if (!flowNodes || !config->GetMUSCL_FirstOrderWallEnds()) { - SU2_OMP_SAFE_GLOBAL_ACCESS(correctionWeightReady = true;) + SU2_OMP_SAFE_GLOBAL_ACCESS(correctionWeightVersion = version;) return; } @@ -1526,7 +1529,7 @@ void CMultiGridIntegration::ComputeCorrectionWeights(CGeometry** geometry, const END_SU2_OMP_SAFE_GLOBAL_ACCESS } - SU2_OMP_SAFE_GLOBAL_ACCESS(correctionWeightReady = true;) + SU2_OMP_SAFE_GLOBAL_ACCESS(correctionWeightVersion = version;) } void CMultiGridIntegration::SetProlongated_Correction(CSolver *sol_fine, CSolver *sol_flow, CGeometry *geo_fine, diff --git a/SU2_CFD/src/iteration/CFluidIteration.cpp b/SU2_CFD/src/iteration/CFluidIteration.cpp index 1ce3eac11d64..283f0174d57e 100644 --- a/SU2_CFD/src/iteration/CFluidIteration.cpp +++ b/SU2_CFD/src/iteration/CFluidIteration.cpp @@ -133,7 +133,7 @@ void CFluidIteration::CommonAuxiliarySolvers(CIntegration**** integration, CGeom /*--- Solve the turbulence model ---*/ config[val_iZone]->SetGlobalParam(main_solver, RUNTIME_TURB_SYS); - for (auto iSub = 0u; iSub < max(config[val_iZone]->GetTurb_SubIter(), 1); iSub++) + for (auto iSub = 0u; iSub < config[val_iZone]->GetTurb_SubIter(); iSub++) integration[val_iZone][val_iInst][TURB_SOL]->SingleGrid_Iteration(geometry, solver, numerics, config, RUNTIME_TURB_SYS, val_iZone, val_iInst); } diff --git a/SU2_CFD/src/iteration/CIteration.cpp b/SU2_CFD/src/iteration/CIteration.cpp index f4c4cec104f1..ae52f81a4ae8 100644 --- a/SU2_CFD/src/iteration/CIteration.cpp +++ b/SU2_CFD/src/iteration/CIteration.cpp @@ -203,6 +203,8 @@ void CIteration::SetMesh_Deformation(CGeometry** geometry, CSolver** solver, CNu solver[MESH_SOL]->DeformMesh(geometry, numerics[MESH_SOL], config); + if (solver[FLOW_SOL] != nullptr) solver[FLOW_SOL]->SetWallEndFlags(geometry[MESH_0], config); + /*--- Continue recording. ---*/ AD::EndPassive(wasActive); } diff --git a/SU2_CFD/src/solvers/CEulerSolver.cpp b/SU2_CFD/src/solvers/CEulerSolver.cpp index 5e7a4b1ed09f..e909ed5ca35c 100644 --- a/SU2_CFD/src/solvers/CEulerSolver.cpp +++ b/SU2_CFD/src/solvers/CEulerSolver.cpp @@ -326,10 +326,86 @@ CEulerSolver::CEulerSolver(CGeometry *geometry, CConfig *config, nodes->NonPhysicalEdgeCounter.resize(geometry->GetnEdge()) = 0; } + if ((iMesh == MESH_0) && config->GetMUSCL_Flow() && config->GetMUSCL_FirstOrderWallEnds()) { + SetWallEndFlags(geometry, config); + + unsigned long nFlagged = 0, nFlaggedGlobal = 0; + for (iPoint = 0; iPoint < nPointDomain; iPoint++) nFlagged += nodes->FirstOrderReconstruction(iPoint); + SU2_MPI::Allreduce(&nFlagged, &nFlaggedGlobal, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm()); + if (rank == MASTER_NODE) + cout << "First-order reconstruction at " << nFlaggedGlobal << " points where a no-slip wall ends or has a sharp edge." << endl; + } + + /*--- Check that the initial solution is physical, report any non-physical nodes ---*/ + + counter_local = 0; + + for (iPoint = 0; iPoint < nPoint; iPoint++) { + + Density = nodes->GetDensity(iPoint); + + Velocity2 = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + Velocity2 += pow(nodes->GetSolution(iPoint,iDim+1)/Density,2); + + StaticEnergy= nodes->GetEnergy(iPoint) - 0.5*Velocity2; + if (tkeNeeded) StaticEnergy -= TKE_Inf; + + GetFluidModel()->SetTDState_rhoe(Density, StaticEnergy); + Pressure= GetFluidModel()->GetPressure(); + Temperature= GetFluidModel()->GetTemperature(); + + /*--- Use the values at the infinity ---*/ + + su2double Solution[MAXNVAR] = {0.0}; + if ((Pressure < 0.0) || (Density < 0.0) || (Temperature < 0.0)) { + Solution[0] = Density_Inf; + for (iDim = 0; iDim < nDim; iDim++) + Solution[iDim+1] = Velocity_Inf[iDim]*Density_Inf; + Solution[nDim+1] = Energy_Inf*Density_Inf; + nodes->SetSolution(iPoint,Solution); + nodes->SetSolution_Old(iPoint,Solution); + counter_local++; + } + + } + + /*--- Warning message about non-physical points ---*/ + + if (config->GetComm_Level() == COMM_FULL) { + + SU2_MPI::Reduce(&counter_local, &counter_global, 1, MPI_UNSIGNED_LONG, MPI_SUM, MASTER_NODE, SU2_MPI::GetComm()); + + if ((rank == MASTER_NODE) && (counter_global != 0)) + cout << "Warning. The original solution contains " << counter_global << " points that are not physical." << endl; + } + + /*--- Initial comms. ---*/ + + CommunicateInitialState(geometry, config); + + /*--- Sizing edge mass flux array, padded to a multiple of the SIMD size since the vectorized + * numerics write to it with contiguous (unmasked) SIMD stores, same as CEdge's Normal. ---*/ + if (config->GetBounded_Scalar()) { + EdgeMassFluxes.resize(nextMultiple(geometry->GetnEdge(), simd::preferredLen())) = su2double(0.0); + } + + /*--- Add the solver name.. ---*/ + SolverName = "C.FLOW"; + + /*--- Finally, check that the static arrays will be large enough (keep this + * check at the bottom to make sure we consider the "final" values). ---*/ + if((nDim > MAXNDIM) || (nPrimVar > MAXNVAR) || (nSecondaryVar > MAXNVAR)) + SU2_MPI::Error("Oops! The CEulerSolver static array sizes are not large enough.",CURRENT_FUNCTION); +} + +void CEulerSolver::SetWallEndFlags(CGeometry* geometry, const CConfig* config) { + if (!config->GetMUSCL_Flow() || !config->GetMUSCL_FirstOrderWallEnds()) return; + /*--- The gradient is singular where a no-slip wall meets another kind of boundary. Unlimited * reconstruction across it gives a defect the first-order multigrid levels cannot correct. ---*/ - if ((iMesh == MESH_0) && config->GetMUSCL_Flow() && config->GetMUSCL_FirstOrderWallEnds()) { + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { /*--- Only where the other boundary continues the wall surface does the condition jump along a * smooth surface. Where they meet at an angle, as at a wing root on a symmetry plane, the * flow is smooth. Halfway between parallel and perpendicular separates the two. ---*/ @@ -372,7 +448,7 @@ CEulerSolver::CEulerSolver(CGeometry *geometry, CConfig *config, } const su2double minFlatness = cos(PI_NUMBER / 8); - for (iPoint = 0; iPoint < nPoint; iPoint++) { + for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) { bool wallEnds = false; for (unsigned short iWall = 0; iWall < config->GetnMarker_All(); iWall++) { const auto wallVertex = geometry->nodes->GetVertex(iPoint, iWall); @@ -397,100 +473,25 @@ CEulerSolver::CEulerSolver(CGeometry *geometry, CConfig *config, } nodes->FirstOrderReconstruction(iPoint) = wallEnds; } - - unsigned long nFlagged = 0, nFlaggedGlobal = 0; - for (iPoint = 0; iPoint < nPointDomain; iPoint++) nFlagged += nodes->FirstOrderReconstruction(iPoint); - SU2_MPI::Allreduce(&nFlagged, &nFlaggedGlobal, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm()); - if (rank == MASTER_NODE) - cout << "First-order reconstruction at " << nFlaggedGlobal << " points where a no-slip wall ends or has a sharp edge." << endl; - - /*--- A halo may lack one of the markers its owner has, so it takes the owner's flag. ---*/ - for (unsigned short markerS = 0; markerS < config->GetnMarker_All(); markerS++) { - if ((config->GetMarker_All_KindBC(markerS) != SEND_RECEIVE) || (config->GetMarker_All_SendRecv(markerS) <= 0)) - continue; - const auto markerR = static_cast(markerS + 1); - const int sendTo = config->GetMarker_All_SendRecv(markerS) - 1; - const int receiveFrom = abs(config->GetMarker_All_SendRecv(markerR)) - 1; - vector bufSend(geometry->nVertex[markerS]), bufRecv(geometry->nVertex[markerR]); - for (auto iVertex = 0ul; iVertex < geometry->nVertex[markerS]; iVertex++) - bufSend[iVertex] = nodes->FirstOrderReconstruction(geometry->vertex[markerS][iVertex]->GetNode()); - SU2_MPI::Sendrecv(bufSend.data(), bufSend.size(), MPI_UNSIGNED_SHORT, sendTo, 0, bufRecv.data(), bufRecv.size(), - MPI_UNSIGNED_SHORT, receiveFrom, 0, SU2_MPI::GetComm(), MPI_STATUS_IGNORE); - for (auto iVertex = 0ul; iVertex < geometry->nVertex[markerR]; iVertex++) - nodes->FirstOrderReconstruction(geometry->vertex[markerR][iVertex]->GetNode()) = bufRecv[iVertex]; - } - - /*--- The coarse grid cannot represent the singular flow there, its correction is not prolongated to - * those points and their neighbours. ---*/ - for (iPoint = 0; iPoint < nPointDomain; iPoint++) { - bool skip = nodes->FirstOrderReconstruction(iPoint); - for (auto iNeigh = 0u; !skip && (iNeigh < geometry->nodes->GetnPoint(iPoint)); iNeigh++) - skip = nodes->FirstOrderReconstruction(geometry->nodes->GetPoint(iPoint, iNeigh)); - nodes->SkipMGCorrection(iPoint) = skip; - } } + END_SU2_OMP_SAFE_GLOBAL_ACCESS - /*--- Check that the initial solution is physical, report any non-physical nodes ---*/ - - counter_local = 0; - - for (iPoint = 0; iPoint < nPoint; iPoint++) { - - Density = nodes->GetDensity(iPoint); - - Velocity2 = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - Velocity2 += pow(nodes->GetSolution(iPoint,iDim+1)/Density,2); - - StaticEnergy= nodes->GetEnergy(iPoint) - 0.5*Velocity2; - if (tkeNeeded) StaticEnergy -= TKE_Inf; - - GetFluidModel()->SetTDState_rhoe(Density, StaticEnergy); - Pressure= GetFluidModel()->GetPressure(); - Temperature= GetFluidModel()->GetTemperature(); - - /*--- Use the values at the infinity ---*/ - - su2double Solution[MAXNVAR] = {0.0}; - if ((Pressure < 0.0) || (Density < 0.0) || (Temperature < 0.0)) { - Solution[0] = Density_Inf; - for (iDim = 0; iDim < nDim; iDim++) - Solution[iDim+1] = Velocity_Inf[iDim]*Density_Inf; - Solution[nDim+1] = Energy_Inf*Density_Inf; - nodes->SetSolution(iPoint,Solution); - nodes->SetSolution_Old(iPoint,Solution); - counter_local++; - } - - } - - /*--- Warning message about non-physical points ---*/ - - if (config->GetComm_Level() == COMM_FULL) { - - SU2_MPI::Reduce(&counter_local, &counter_global, 1, MPI_UNSIGNED_LONG, MPI_SUM, MASTER_NODE, SU2_MPI::GetComm()); - - if ((rank == MASTER_NODE) && (counter_global != 0)) - cout << "Warning. The original solution contains " << counter_global << " points that are not physical." << endl; - } - - /*--- Initial comms. ---*/ - - CommunicateInitialState(geometry, config); + /*--- A halo may lack one of the markers its owner has, so it takes the owner's flag. ---*/ + InitiateComms(geometry, config, MPI_QUANTITIES::FIRST_ORDER_RECONSTRUCTION); + CompleteComms(geometry, config, MPI_QUANTITIES::FIRST_ORDER_RECONSTRUCTION); - /*--- Sizing edge mass flux array, padded to a multiple of the SIMD size since the vectorized - * numerics write to it with contiguous (unmasked) SIMD stores, same as CEdge's Normal. ---*/ - if (config->GetBounded_Scalar()) { - EdgeMassFluxes.resize(nextMultiple(geometry->GetnEdge(), simd::preferredLen())) = su2double(0.0); + /*--- The coarse grid cannot represent the singular flow there, its correction is not prolongated to + * those points and their neighbours. ---*/ + SU2_OMP_FOR_STAT(omp_chunk_size) + for (auto iPoint = 0ul; iPoint < nPointDomain; iPoint++) { + bool skip = nodes->FirstOrderReconstruction(iPoint); + for (auto iNeigh = 0u; !skip && (iNeigh < geometry->nodes->GetnPoint(iPoint)); iNeigh++) + skip = nodes->FirstOrderReconstruction(geometry->nodes->GetPoint(iPoint, iNeigh)); + nodes->SkipMGCorrection(iPoint) = skip; } + END_SU2_OMP_FOR - /*--- Add the solver name.. ---*/ - SolverName = "C.FLOW"; - - /*--- Finally, check that the static arrays will be large enough (keep this - * check at the bottom to make sure we consider the "final" values). ---*/ - if((nDim > MAXNDIM) || (nPrimVar > MAXNVAR) || (nSecondaryVar > MAXNVAR)) - SU2_MPI::Error("Oops! The CEulerSolver static array sizes are not large enough.",CURRENT_FUNCTION); + SU2_OMP_SAFE_GLOBAL_ACCESS(++nodes->WallEndFlagsVersion;) } CEulerSolver::~CEulerSolver() { diff --git a/SU2_CFD/src/solvers/CSolver.cpp b/SU2_CFD/src/solvers/CSolver.cpp index 8b5aa919150a..a6eac78943e1 100644 --- a/SU2_CFD/src/solvers/CSolver.cpp +++ b/SU2_CFD/src/solvers/CSolver.cpp @@ -1597,6 +1597,7 @@ void CSolver::GetCommCountAndType(const CConfig* config, break; case MPI_QUANTITIES::MAX_EIGENVALUE: case MPI_QUANTITIES::SENSOR: + case MPI_QUANTITIES::FIRST_ORDER_RECONSTRUCTION: COUNT_PER_POINT = 1; MPI_TYPE = COMM_TYPE::DOUBLE; break; @@ -1802,6 +1803,9 @@ void CSolver::InitiateComms(CGeometry *geometry, case MPI_QUANTITIES::SENSOR: bufDSend[buf_offset] = base_nodes->GetSensor(iPoint); break; + case MPI_QUANTITIES::FIRST_ORDER_RECONSTRUCTION: + bufDSend[buf_offset] = base_nodes->GetFirstOrderReconstruction(iPoint); + break; case MPI_QUANTITIES::SENSOR_ADAPT: for (iVar = 0; iVar < GetnAdaptiveMetricSensor(); iVar++) bufDSend[buf_offset+iVar] = base_nodes->GetSensor_Adapt(iPoint, iVar); @@ -1981,6 +1985,9 @@ void CSolver::CompleteComms(CGeometry *geometry, case MPI_QUANTITIES::SENSOR: base_nodes->SetSensor(iPoint,bufDRecv[buf_offset]); break; + case MPI_QUANTITIES::FIRST_ORDER_RECONSTRUCTION: + base_nodes->SetFirstOrderReconstruction(iPoint, SU2_TYPE::GetValue(bufDRecv[buf_offset]) > 0.5); + break; case MPI_QUANTITIES::SENSOR_ADAPT: for (iVar = 0; iVar < GetnAdaptiveMetricSensor(); iVar++) base_nodes->SetSensor_Adapt(iPoint, iVar, bufDRecv[buf_offset+iVar]); diff --git a/TestCases/hybrid_regression.py b/TestCases/hybrid_regression.py index 043fbd34f811..a00d728de90d 100644 --- a/TestCases/hybrid_regression.py +++ b/TestCases/hybrid_regression.py @@ -423,7 +423,7 @@ def main(): inc_lam_cylinder.cfg_dir = "incomp_navierstokes/cylinder" inc_lam_cylinder.cfg_file = "incomp_cylinder.cfg" inc_lam_cylinder.test_iter = 10 - inc_lam_cylinder.test_vals = [-4.801777, -4.780412, 0.006108, 3.113616] + inc_lam_cylinder.test_vals = [-4.835169, -4.799421, 0.005368, 3.098376] test_list.append(inc_lam_cylinder) # Buoyancy-driven cavity diff --git a/TestCases/parallel_regression.py b/TestCases/parallel_regression.py index e5174519bc06..39deaff4533c 100755 --- a/TestCases/parallel_regression.py +++ b/TestCases/parallel_regression.py @@ -47,7 +47,7 @@ def main(): cfd_cantera_dc_ch4.cfg_dir = "combustion/1step_methane_air" cfd_cantera_dc_ch4.cfg_file = "2d_slit_burner_fluid.cfg" cfd_cantera_dc_ch4.test_iter = 10 - cfd_cantera_dc_ch4.test_vals = [-12.897452, -15.191976, -12.810575, 10.000000, -1.860548, 1000.000000] + cfd_cantera_dc_ch4.test_vals = [-12.897452, -15.193280, -12.810575, 10.000000, -1.863535, 1000.000000] cfd_cantera_dc_ch4.new_output = True test_list.append(cfd_cantera_dc_ch4) @@ -56,7 +56,7 @@ def main(): cfd_cantera_dc_h2.cfg_dir = "combustion/h2o2_hydrogen_air" cfd_cantera_dc_h2.cfg_file = "2d_slit_burner_h2.cfg" cfd_cantera_dc_h2.test_iter = 10 - cfd_cantera_dc_h2.test_vals = [-15.994221, -17.134244, -32.000000, 5.000000, -2.027264, 100.000000] + cfd_cantera_dc_h2.test_vals = [-15.994240, -17.134241, -32.000000, 5.000000, -2.027407, 100.000000] cfd_cantera_dc_h2.new_output = True test_list.append(cfd_cantera_dc_h2) @@ -567,7 +567,7 @@ def main(): turb_flatplate_sst_fullmg.cfg_dir = "rans/flatplate" turb_flatplate_sst_fullmg.cfg_file = "turb_SST_flatplate_fullmg.cfg" turb_flatplate_sst_fullmg.test_iter = 20 - turb_flatplate_sst_fullmg.test_vals = [-5.218681, -2.349133, 8.437472, -0.187261, 0.001298] + turb_flatplate_sst_fullmg.test_vals = [-5.466644, -2.316828, 7.155791, -0.187269, 0.001171] test_list.append(turb_flatplate_sst_fullmg) # Flat plate (compressible) with species inlet @@ -856,7 +856,7 @@ def main(): inc_lam_cylinder.cfg_dir = "incomp_navierstokes/cylinder" inc_lam_cylinder.cfg_file = "incomp_cylinder.cfg" inc_lam_cylinder.test_iter = 10 - inc_lam_cylinder.test_vals = [-4.808889, -4.846532, 0.001009, 3.110366] + inc_lam_cylinder.test_vals = [-4.843553, -4.882219, -0.000244, 3.093746] test_list.append(inc_lam_cylinder) # Laminar cylinder, pressure-based @@ -892,7 +892,7 @@ def main(): inc_lam_sphere.cfg_dir = "incomp_navierstokes/sphere" inc_lam_sphere.cfg_file = "sphere.cfg" inc_lam_sphere.test_iter = 5 - inc_lam_sphere.test_vals = [-7.598349, -8.094328, -8.149899, -8.654136, 0.121002, 25.782692, -1.597724] + inc_lam_sphere.test_vals = [-7.598353, -7.960253, -8.024160, -8.631574, 0.121002, 25.782692, -1.529291] test_list.append(inc_lam_sphere) # Laminar sphere, Re=1, pressure-based. Only 3D pressure-based case in the regression suite. diff --git a/TestCases/serial_regression.py b/TestCases/serial_regression.py index 3f181347db04..937172686873 100755 --- a/TestCases/serial_regression.py +++ b/TestCases/serial_regression.py @@ -111,7 +111,7 @@ def main(): naca0012_FMG.cfg_dir = "euler/naca0012" naca0012_FMG.cfg_file = "inv_NACA0012.cfg" naca0012_FMG.test_iter = 20 - naca0012_FMG.test_vals = [-4.112147, -3.515737, 0.278348, 0.015066] + naca0012_FMG.test_vals = [-4.079993, -3.483233, 0.283691, 0.015265] test_list.append(naca0012_FMG) # Supersonic wedge @@ -308,7 +308,7 @@ def main(): turb_flatplate_sst_fullmg.cfg_dir = "rans/flatplate" turb_flatplate_sst_fullmg.cfg_file = "turb_SST_flatplate_fullmg.cfg" turb_flatplate_sst_fullmg.test_iter = 20 - turb_flatplate_sst_fullmg.test_vals = [-5.515931, -2.232865, 6.168625, -0.187250, 0.001316] + turb_flatplate_sst_fullmg.test_vals = [-5.615986, -2.397263, 6.169223, -0.187272, 0.001153] test_list.append(turb_flatplate_sst_fullmg) # FLAT PLATE, WALL FUNCTIONS, COMPRESSIBLE SST @@ -527,7 +527,7 @@ def main(): inc_lam_cylinder.cfg_dir = "incomp_navierstokes/cylinder" inc_lam_cylinder.cfg_file = "incomp_cylinder.cfg" inc_lam_cylinder.test_iter = 10 - inc_lam_cylinder.test_vals = [-4.806034, -4.879479, 0.003472, 3.111567] + inc_lam_cylinder.test_vals = [-4.838457, -4.926058, 0.002655, 3.096925] test_list.append(inc_lam_cylinder) # Laminar cylinder, pressure-based diff --git a/config_template.cfg b/config_template.cfg index e874b99c574d..00730ca9d97d 100644 --- a/config_template.cfg +++ b/config_template.cfg @@ -1847,8 +1847,8 @@ MG_IMPLICIT_LINES= NO MG_CFL_SCALING= ( 0.5 ) % % Maximum linear solver iterations on the coarse multigrid levels. Entry i applies to level i+1, -% the last value is repeated, and the cap never exceeds LINEAR_SOLVER_ITER. The discrete adjoint -% ignores it (default 3) +% the last value is repeated, and the cap never exceeds LINEAR_SOLVER_ITER. The active level of the +% Full Multigrid startup and the discrete adjoint are not capped. Entries must be positive (default 3) MG_LINEAR_SOLVER_ITER= ( 3 ) % % Number of iterations spent on each mesh during the Full Multigrid (FMG) startup phase. After @@ -2158,7 +2158,7 @@ TIME_DISCRE_TURB= EULER_IMPLICIT % Reduction factor of the CFL coefficient in the turbulence problem CFL_REDUCTION_TURB= 1.0 % -% Number of turbulence iterations per flow iteration (default 1) +% Number of turbulence iterations per flow iteration, at least 1 (default 1) TURB_SUBITER= 1 % Control lower limit constants of the SST model (C*phi_infinity)