From 79987e566ff6825ff4edac9c81a0f9a0b0a42b46 Mon Sep 17 00:00:00 2001 From: BLACKNIGHT-cloud12 Date: Sat, 5 Dec 2026 20:15:57 +0530 Subject: [PATCH] Fix MOVING_WALL grid velocity overwritten by mesh deformation --- Common/src/geometry/CGeometry.cpp | 3 + SU2_CFD/src/drivers/CDriver.cpp | 2 +- SU2_CFD/src/solvers/CMeshSolver.cpp | 24 +++++-- UnitTests/Common/geometry/CGeometry_test.cpp | 64 +++++++++++++++++ .../SU2_CFD/solvers/moving_wall_tests.cpp | 68 +++++++++++++++++++ 5 files changed, 156 insertions(+), 5 deletions(-) diff --git a/Common/src/geometry/CGeometry.cpp b/Common/src/geometry/CGeometry.cpp index f7179721bbd4..4e8880df9260 100644 --- a/Common/src/geometry/CGeometry.cpp +++ b/Common/src/geometry/CGeometry.cpp @@ -4243,6 +4243,7 @@ void CGeometry::SetWallVelocity(const CConfig* config, bool print) { const auto Marker_Tag = config->GetMarker_All_TagBound(iMarker); const auto jMarker = config->GetMarker_Moving(Marker_Tag); + if (config->GetKind_SurfaceMovement(jMarker) != MOVING_WALL) continue; su2double xDot[MAXNDIM], Center[MAXNDIM], Omega[MAXNDIM]; @@ -4315,6 +4316,8 @@ void CGeometry::SetGridVelocity(const CConfig* config) { nodes->SetGridVel(iPoint, iDim, GridVel); } } + + if (config->GetSurface_Movement(MOVING_WALL)) SetWallVelocity(config, false); } const CGeometry::LDUSparsePattern& CGeometry::GetSparsePattern(ConnectivityType type, unsigned long fillLvl) { diff --git a/SU2_CFD/src/drivers/CDriver.cpp b/SU2_CFD/src/drivers/CDriver.cpp index fb39f5dd7805..8cbc5ce819ba 100644 --- a/SU2_CFD/src/drivers/CDriver.cpp +++ b/SU2_CFD/src/drivers/CDriver.cpp @@ -2575,7 +2575,7 @@ void CDriver::PreprocessStaticMesh(const CConfig *config, CGeometry** geometry){ if (!fem_solver) { - if (config->GetnMarker_Moving() > 0) { + if (config->GetSurface_Movement(MOVING_WALL)) { /*--- Fixed wall velocities: set the grid velocities only one time before the first iteration flow solver. ---*/ diff --git a/SU2_CFD/src/solvers/CMeshSolver.cpp b/SU2_CFD/src/solvers/CMeshSolver.cpp index 1a2fd662a58b..02ea26712494 100644 --- a/SU2_CFD/src/solvers/CMeshSolver.cpp +++ b/SU2_CFD/src/solvers/CMeshSolver.cpp @@ -33,6 +33,24 @@ using namespace GeometryToolbox; +namespace { +/*! + * \brief Re-apply prescribed MOVING_WALL velocities on MESH_0 after volume grid velocity + * updates and restrict all grid velocities to coarser multigrid levels. + */ +void ApplyMovingWallAndRestrictGridVel(CGeometry** geometry, const CConfig* config) { + if (config->GetSurface_Movement(MOVING_WALL)) { + BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS { + geometry[MESH_0]->SetWallVelocity(config, false); + } + END_SU2_OMP_SAFE_GLOBAL_ACCESS + } + + for (auto iMGlevel = 1u; iMGlevel <= config->GetnMGLevels(); iMGlevel++) + geometry[iMGlevel]->SetRestricted_GridVelocity(geometry[iMGlevel - 1]); +} +} // namespace + CMeshSolver::CMeshSolver(CGeometry *geometry, CConfig *config) : CFEASolver(LINEAR_SOLVER_MODE::MESH_DEFORM) { SU2_ZONE_SCOPED @@ -609,8 +627,7 @@ void CMeshSolver::ComputeGridVelocity_FromBoundary(CGeometry **geometry, CNumeri geometry[MESH_0]->nodes->SetGridVel(iPoint, iDim, LinSysSol(iPoint,iDim)*invVelRef); END_SU2_OMP_FOR - for (auto iMGlevel = 1u; iMGlevel <= config->GetnMGLevels(); iMGlevel++) - geometry[iMGlevel]->SetRestricted_GridVelocity(geometry[iMGlevel-1]); + ApplyMovingWallAndRestrictGridVel(geometry, config); } END_SU2_OMP_PARALLEL @@ -649,8 +666,7 @@ void CMeshSolver::ComputeGridVelocity(CGeometry **geometry, const CConfig *confi } END_SU2_OMP_FOR - for (auto iMGlevel = 1u; iMGlevel <= config->GetnMGLevels(); iMGlevel++) - geometry[iMGlevel]->SetRestricted_GridVelocity(geometry[iMGlevel-1]); + ApplyMovingWallAndRestrictGridVel(geometry, config); } diff --git a/UnitTests/Common/geometry/CGeometry_test.cpp b/UnitTests/Common/geometry/CGeometry_test.cpp index 3197ceb89cc1..ab88ab8d8abe 100644 --- a/UnitTests/Common/geometry/CGeometry_test.cpp +++ b/UnitTests/Common/geometry/CGeometry_test.cpp @@ -263,3 +263,67 @@ TEST_CASE("Wall-normal edge spacing", "[Geometry]") { CHECK(GeometryToolbox::WallNormalEdgeLength(2, origin, skewEdge, normal) == Approx(0.5)); CHECK(GeometryToolbox::WallNormalEdgeLength(3, skewEdge, origin, normal) == Approx(0.5)); } + +TEST_CASE("Moving wall and deforming surface grid velocities", "[Geometry]") { + UnitQuadTestCase test; + test.SetOption("KIND_VERIFICATION_SOLUTION= NO_VERIFICATION_SOLUTION"); + test.SetOption("MESH_FORMAT= RECTANGLE"); + test.SetOption("MARKER_HEATFLUX= (y_minus, 0.0, y_plus, 0.0)"); + test.SetOption("MARKER_CUSTOM= (x_minus, x_plus)"); + test.AddOption("REF_DIMENSIONALIZATION= DIMENSIONAL"); + test.AddOption("TIME_DOMAIN= YES"); + test.AddOption("TIME_MARCHING= DUAL_TIME_STEPPING-1ST_ORDER"); + test.AddOption("TIME_STEP= 0.5"); + test.AddOption("TIME_ITER= 2"); + test.AddOption("SURFACE_MOVEMENT= MOVING_WALL DEFORMING"); + test.AddOption("MARKER_MOVING= (y_plus, y_minus)"); + test.AddOption("SURFACE_TRANSLATION_RATE= 10.0 0.0 0.0 0.0 2.0 0.0"); + test.InitConfig(); + test.InitGeometry(); + test.InitSolver(); + + auto* geom = test.geometry.get(); + const auto* cfg = test.config.get(); + geom->SetWallVelocity(cfg, false); + + auto findMarker = [&](const std::string& tag) { + for (auto m = 0u; m < cfg->GetnMarker_All(); ++m) { + if (cfg->GetMarker_All_TagBound(m) == tag) return m; + } + return static_cast(cfg->GetnMarker_All()); + }; + const auto upper = findMarker("y_plus"); + const auto lower = findMarker("y_minus"); + REQUIRE(upper < cfg->GetnMarker_All()); + REQUIRE(lower < cfg->GetnMarker_All()); + + const su2double expectedVel = 10.0 / cfg->GetVelocity_Ref(); + for (auto v = 0ul; v < geom->nVertex[upper]; ++v) { + const auto pt = geom->vertex[upper][v]->GetNode(); + CHECK(geom->nodes->GetGridVel(pt)[0] == Approx(expectedVel)); + CHECK(geom->nodes->GetGridVel(pt)[1] == Approx(0.0).margin(1e-12)); + } + for (auto v = 0ul; v < geom->nVertex[lower]; ++v) { + const auto pt = geom->vertex[lower][v]->GetNode(); + CHECK(geom->nodes->GetGridVel(pt)[0] == Approx(0.0).margin(1e-12)); + CHECK(geom->nodes->GetGridVel(pt)[1] == Approx(0.0).margin(1e-12)); + } + + geom->nodes->SetCoord_n(); + for (auto v = 0ul; v < geom->nVertex[lower]; ++v) { + const auto pt = geom->vertex[lower][v]->GetNode(); + geom->nodes->SetCoord(pt, 1, geom->nodes->GetCoord(pt, 1) + 1.0); + } + geom->SetGridVelocity(cfg); + + for (auto v = 0ul; v < geom->nVertex[upper]; ++v) { + const auto pt = geom->vertex[upper][v]->GetNode(); + CHECK(geom->nodes->GetGridVel(pt)[0] == Approx(expectedVel)); + CHECK(geom->nodes->GetGridVel(pt)[1] == Approx(0.0).margin(1e-12)); + } + for (auto v = 0ul; v < geom->nVertex[lower]; ++v) { + const auto pt = geom->vertex[lower][v]->GetNode(); + CHECK(geom->nodes->GetGridVel(pt)[1] == Approx(2.0)); + } + delete test.solver[MESH_SOL]; +} diff --git a/UnitTests/SU2_CFD/solvers/moving_wall_tests.cpp b/UnitTests/SU2_CFD/solvers/moving_wall_tests.cpp index 1baf0c271428..b5d83a236585 100644 --- a/UnitTests/SU2_CFD/solvers/moving_wall_tests.cpp +++ b/UnitTests/SU2_CFD/solvers/moving_wall_tests.cpp @@ -29,6 +29,8 @@ #include #include "../../UnitQuadTestCase.hpp" #include "../../../SU2_CFD/include/numerics/flow/convection/hllc.hpp" +#include "../../../SU2_CFD/include/numerics/elasticity/CFEALinearElasticity.hpp" +#include "../../../SU2_CFD/include/solvers/CMeshSolver.hpp" #include "../../../SU2_CFD/include/fluid/CPengRobinson.hpp" TEST_CASE("Compressible wall projection commutes with a Galilean boost", "[HLLC-wall]") { @@ -180,3 +182,69 @@ TEST_CASE("Compressible wall projection commutes with a Galilean boost", "[HLLC- } } } + +TEST_CASE("Moving wall velocity is preserved during mesh deformation", "[MovingWall]") { + UnitQuadTestCase test; + test.SetOption("KIND_VERIFICATION_SOLUTION= NO_VERIFICATION_SOLUTION"); + test.SetOption("MESH_FORMAT= RECTANGLE"); + test.SetOption("MARKER_HEATFLUX= (y_minus, 0.0, y_plus, 0.0)"); + test.SetOption("MARKER_CUSTOM= (x_minus, x_plus)"); + test.AddOption("REF_DIMENSIONALIZATION= DIMENSIONAL"); + test.AddOption("TIME_DOMAIN= YES"); + test.AddOption("TIME_MARCHING= DUAL_TIME_STEPPING-1ST_ORDER"); + test.AddOption("TIME_STEP= 0.5"); + test.AddOption("TIME_ITER= 2"); + test.AddOption("SURFACE_MOVEMENT= MOVING_WALL DEFORMING"); + test.AddOption("MARKER_MOVING= (y_plus, y_minus)"); + test.AddOption("SURFACE_TRANSLATION_RATE= 10.0 0.0 0.0 0.0 0.2 0.0"); + test.AddOption("DEFORM_STIFFNESS_TYPE= WALL_DISTANCE"); + test.InitConfig(); + test.InitGeometry(); + test.InitSolver(); + + auto* geom = test.geometry.get(); + auto* cfg = test.config.get(); + auto* meshSolver = static_cast(test.solver[MESH_SOL]); + REQUIRE(meshSolver != nullptr); + + std::unique_ptr meshElast( + new CFEAMeshElasticity(geom->GetnDim(), geom->GetnDim(), geom->GetnElem(), cfg)); + std::vector meshNum(omp_get_max_threads(), meshElast.get()); + CGeometry* meshes[] = {geom}; + + geom->SetWallVelocity(cfg, false); + cfg->SetTimeIter(1); + meshSolver->GetNodes()->Set_Solution_time_n(); + meshSolver->SetMesh_Stiffness(meshNum.data(), cfg); + meshSolver->DeformMesh(meshes, meshNum.data(), cfg); + + auto findMarker = [&](const std::string& tag) { + for (auto m = 0u; m < cfg->GetnMarker_All(); ++m) { + if (cfg->GetMarker_All_TagBound(m) == tag) return m; + } + return static_cast(cfg->GetnMarker_All()); + }; + const auto upper = findMarker("y_plus"); + const auto lower = findMarker("y_minus"); + REQUIRE(upper < cfg->GetnMarker_All()); + REQUIRE(lower < cfg->GetnMarker_All()); + + const su2double expectedUpperVel = 10.0 / cfg->GetVelocity_Ref(); + const su2double expectedLowerVel = 0.2 / cfg->GetVelocity_Ref(); + for (auto v = 0ul; v < geom->nVertex[upper]; ++v) { + const auto pt = geom->vertex[upper][v]->GetNode(); + CHECK(geom->nodes->GetGridVel(pt)[0] == Approx(expectedUpperVel)); + CHECK(geom->nodes->GetGridVel(pt)[1] == Approx(0.0).margin(1e-12)); + } + auto interiorLowerCount = 0u; + for (auto v = 0ul; v < geom->nVertex[lower]; ++v) { + const auto pt = geom->vertex[lower][v]->GetNode(); + const auto x = geom->nodes->GetCoord(pt)[0]; + if (x > 0.0 && x < 1.0) { + ++interiorLowerCount; + CHECK(geom->nodes->GetGridVel(pt)[1] == Approx(expectedLowerVel).margin(1e-8)); + } + } + REQUIRE(interiorLowerCount > 0); + delete meshSolver; +}