From b8ce733e4bf38e53376173d679d2d9e49d738370 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 8 Apr 2022 18:46:12 +0100 Subject: [PATCH] fvMesh: Separated fvMesh::move() and fvMesh::update() fvMesh::update() now executes at the beginning of the time-step, before time is incremented and handles topology change, mesh to mesh mapping and redistribution without point motion. Following each of these mesh changes fields are mapped from the previous mesh state to new mesh state in a conservative manner. These mesh changes not occur at most once per time-step. fvMesh::move() is executed after time is incremented and handles point motion mesh morphing during the time-step in an Arbitrary Lagrangian Eulerian approach requiring the mesh motion flux to match the cell volume change. fvMesh::move() can be called any number of times during the time-step to allow iterative update of the coupling between the mesh motion and field solution. --- .../solvers/combustion/XiFoam/XiFoam.C | 27 +++--- .../buoyantReactingFoam/buoyantReactingFoam.C | 25 +++--- .../combustion/reactingFoam/reactingFoam.C | 27 +++--- .../rhoCentralFoam/rhoCentralFoam.C | 10 ++- .../rhoPimpleFoam/rhoPimpleFoam.C | 25 +++--- .../heatTransfer/buoyantFoam/buoyantFoam.C | 25 +++--- .../incompressible/pimpleFoam/pimpleFoam.C | 12 ++- .../denseParticleFoam/denseParticleFoam.C | 8 +- .../lagrangian/particleFoam/particleFoam.C | 14 ++- .../rhoParticleFoam/rhoParticleFoam.C | 13 ++- .../cavitatingFoam/cavitatingFoam.C | 9 +- .../compressibleInterFoam.C | 36 +++++--- .../solvers/multiphase/interFoam/interFoam.C | 54 ++++++++---- .../interMixingFoam/interMixingFoam.C | 16 ++-- .../multiphaseEulerFoam/multiphaseEulerFoam.C | 42 ++++++--- .../phaseSystems/phaseSystem/phaseSystem.C | 2 +- .../multiphaseInterFoam/multiphaseInterFoam.C | 12 ++- .../potentialFreeSurfaceFoam.C | 27 +++--- .../manipulation/mirrorMesh/mirrorFvMesh.C | 8 +- .../moveDynamicMesh/moveDynamicMesh.C | 12 ++- .../engineCompRatio/engineCompRatio.C | 6 +- .../RAS/mixtureKEpsilon/mixtureKEpsilon.C | 5 +- .../points0/points0MotionSolver.C | 12 +++ .../points0/points0MotionSolver.H | 3 + .../solidBodyMotionSolver.C | 6 -- .../inletOutlet/inletOutletFvPatchField.H | 14 ++- src/finiteVolume/fvMesh/fvMesh.C | 86 +++++++++++-------- src/finiteVolume/fvMesh/fvMesh.H | 6 +- .../singleCellFvMesh/singleCellFvMesh.C | 10 +-- .../meshToMesh/fvMeshTopoChangersMeshToMesh.C | 8 +- .../laminar/titaniaSynthesis/0/p_rgh | 1 + .../laminar/titaniaSynthesisSurface/0/p_rgh | 1 + 32 files changed, 356 insertions(+), 206 deletions(-) diff --git a/applications/solvers/combustion/XiFoam/XiFoam.C b/applications/solvers/combustion/XiFoam/XiFoam.C index af5d04d3b4..5891e4a8d3 100644 --- a/applications/solvers/combustion/XiFoam/XiFoam.C +++ b/applications/solvers/combustion/XiFoam/XiFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -106,6 +106,18 @@ int main(int argc, char *argv[]) #include "compressibleCourantNo.H" #include "setDeltaT.H" + fvModels.preUpdateMesh(); + + // Store momentum to set rhoUf for introduced faces. + autoPtr rhoU; + if (rhoUf.valid()) + { + rhoU = new volVectorField("rhoU", rho*U); + } + + // Update the mesh for topology change, mesh to mesh mapping + mesh.update(); + runTime++; Info<< "Time = " << runTime.userTimeName() << nl << endl; @@ -117,17 +129,8 @@ int main(int argc, char *argv[]) { if (pimple.firstPimpleIter() || moveMeshOuterCorrectors) { - // Store momentum to set rhoUf for introduced faces. - autoPtr rhoU; - if (rhoUf.valid()) - { - rhoU = new volVectorField("rhoU", rho*U); - } - - fvModels.preUpdateMesh(); - - // Do any mesh changes - mesh.update(); + // Move the mesh + mesh.move(); if (mesh.changing()) { diff --git a/applications/solvers/combustion/reactingFoam/buoyantReactingFoam/buoyantReactingFoam.C b/applications/solvers/combustion/reactingFoam/buoyantReactingFoam/buoyantReactingFoam.C index f509052ca5..703a62df96 100644 --- a/applications/solvers/combustion/reactingFoam/buoyantReactingFoam/buoyantReactingFoam.C +++ b/applications/solvers/combustion/reactingFoam/buoyantReactingFoam/buoyantReactingFoam.C @@ -103,6 +103,18 @@ int main(int argc, char *argv[]) #include "setDeltaT.H" } + fvModels.preUpdateMesh(); + + // Store momentum to set rhoUf for introduced faces. + autoPtr rhoU; + if (rhoUf.valid()) + { + rhoU = new volVectorField("rhoU", rho*U); + } + + // Update the mesh for topology change, mesh to mesh mapping + mesh.update(); + runTime++; Info<< "Time = " << runTime.userTimeName() << nl << endl; @@ -127,17 +139,8 @@ int main(int argc, char *argv[]) { if (pimple.firstPimpleIter() || moveMeshOuterCorrectors) { - // Store momentum to set rhoUf for introduced faces. - autoPtr rhoU; - if (rhoUf.valid()) - { - rhoU = new volVectorField("rhoU", rho*U); - } - - fvModels.preUpdateMesh(); - - // Do any mesh changes - mesh.update(); + // Move the mesh + mesh.move(); if (mesh.changing()) { diff --git a/applications/solvers/combustion/reactingFoam/reactingFoam.C b/applications/solvers/combustion/reactingFoam/reactingFoam.C index 57c2562d94..e3276e0c17 100644 --- a/applications/solvers/combustion/reactingFoam/reactingFoam.C +++ b/applications/solvers/combustion/reactingFoam/reactingFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -101,6 +101,18 @@ int main(int argc, char *argv[]) #include "setDeltaT.H" } + fvModels.preUpdateMesh(); + + // Store momentum to set rhoUf for introduced faces. + autoPtr rhoU; + if (rhoUf.valid()) + { + rhoU = new volVectorField("rhoU", rho*U); + } + + // Update the mesh for topology change, mesh to mesh mapping + mesh.update(); + runTime++; Info<< "Time = " << runTime.userTimeName() << nl << endl; @@ -125,17 +137,8 @@ int main(int argc, char *argv[]) { if (pimple.firstPimpleIter() || moveMeshOuterCorrectors) { - // Store momentum to set rhoUf for introduced faces. - autoPtr rhoU; - if (rhoUf.valid()) - { - rhoU = new volVectorField("rhoU", rho*U); - } - - fvModels.preUpdateMesh(); - - // Do any mesh changes - mesh.update(); + // Move the mesh + mesh.move(); if (mesh.changing()) { diff --git a/applications/solvers/compressible/rhoCentralFoam/rhoCentralFoam.C b/applications/solvers/compressible/rhoCentralFoam/rhoCentralFoam.C index 53684f45c8..4d29416ab6 100644 --- a/applications/solvers/compressible/rhoCentralFoam/rhoCentralFoam.C +++ b/applications/solvers/compressible/rhoCentralFoam/rhoCentralFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -74,10 +74,14 @@ int main(int argc, char *argv[]) if (!LTS) { #include "setDeltaT.H" + + // Update the mesh for topology change, mesh to mesh mapping + mesh.update(); + runTime++; - // Do any mesh changes - mesh.update(); + // Move the mesh + mesh.move(); } // --- Directed interpolation of primitive fields onto faces diff --git a/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C b/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C index 109697e70b..1834cbfe6c 100644 --- a/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C +++ b/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C @@ -99,6 +99,18 @@ int main(int argc, char *argv[]) #include "setDeltaT.H" } + fvModels.preUpdateMesh(); + + // Store momentum to set rhoUf for introduced faces. + autoPtr rhoU; + if (rhoUf.valid()) + { + rhoU = new volVectorField("rhoU", rho*U); + } + + // Update the mesh for topology change, mesh to mesh mapping + mesh.update(); + runTime++; Info<< "Time = " << runTime.userTimeName() << nl << endl; @@ -108,17 +120,8 @@ int main(int argc, char *argv[]) { if (pimple.firstPimpleIter() || moveMeshOuterCorrectors) { - // Store momentum to set rhoUf for introduced faces. - autoPtr rhoU; - if (rhoUf.valid()) - { - rhoU = new volVectorField("rhoU", rho*U); - } - - fvModels.preUpdateMesh(); - - // Do any mesh changes - mesh.update(); + // Move the mesh + mesh.move(); if (mesh.changing()) { diff --git a/applications/solvers/heatTransfer/buoyantFoam/buoyantFoam.C b/applications/solvers/heatTransfer/buoyantFoam/buoyantFoam.C index b8b4977137..56c12c0956 100644 --- a/applications/solvers/heatTransfer/buoyantFoam/buoyantFoam.C +++ b/applications/solvers/heatTransfer/buoyantFoam/buoyantFoam.C @@ -101,6 +101,18 @@ int main(int argc, char *argv[]) #include "setDeltaT.H" } + fvModels.preUpdateMesh(); + + // Store momentum to set rhoUf for introduced faces. + autoPtr rhoU; + if (rhoUf.valid()) + { + rhoU = new volVectorField("rhoU", rho*U); + } + + // Update the mesh for topology change, mesh to mesh mapping + mesh.update(); + runTime++; Info<< "Time = " << runTime.userTimeName() << nl << endl; @@ -124,17 +136,8 @@ int main(int argc, char *argv[]) { if (pimple.firstPimpleIter() || moveMeshOuterCorrectors) { - // Store momentum to set rhoUf for introduced faces. - autoPtr rhoU; - if (rhoUf.valid()) - { - rhoU = new volVectorField("rhoU", rho*U); - } - - fvModels.preUpdateMesh(); - - // Do any mesh changes - mesh.update(); + // Move the mesh + mesh.move(); if (mesh.changing()) { diff --git a/applications/solvers/incompressible/pimpleFoam/pimpleFoam.C b/applications/solvers/incompressible/pimpleFoam/pimpleFoam.C index 5ad1fbe8a0..80c8a1fd3c 100644 --- a/applications/solvers/incompressible/pimpleFoam/pimpleFoam.C +++ b/applications/solvers/incompressible/pimpleFoam/pimpleFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -83,6 +83,11 @@ int main(int argc, char *argv[]) #include "setDeltaT.H" } + fvModels.preUpdateMesh(); + + // Update the mesh for topology change, mesh to mesh mapping + mesh.update(); + runTime++; Info<< "Time = " << runTime.userTimeName() << nl << endl; @@ -92,9 +97,8 @@ int main(int argc, char *argv[]) { if (pimple.firstPimpleIter() || moveMeshOuterCorrectors) { - fvModels.preUpdateMesh(); - - mesh.update(); + // Move the mesh + mesh.move(); if (mesh.changing()) { diff --git a/applications/solvers/lagrangian/denseParticleFoam/denseParticleFoam.C b/applications/solvers/lagrangian/denseParticleFoam/denseParticleFoam.C index 29eb69a281..e9bd197284 100644 --- a/applications/solvers/lagrangian/denseParticleFoam/denseParticleFoam.C +++ b/applications/solvers/lagrangian/denseParticleFoam/denseParticleFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2013-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -107,6 +107,9 @@ int main(int argc, char *argv[]) #include "CourantNo.H" #include "setDeltaT.H" + // Update the mesh for topology change, mesh to mesh mapping + mesh.update(); + runTime++; Info<< "Time = " << runTime.userTimeName() << nl << endl; @@ -114,7 +117,8 @@ int main(int argc, char *argv[]) // Store the particle positions clouds.storeGlobalPositions(); - mesh.update(); + // Move the mesh + mesh.move(); if (mesh.changing()) { diff --git a/applications/solvers/lagrangian/particleFoam/particleFoam.C b/applications/solvers/lagrangian/particleFoam/particleFoam.C index b641ef4b03..47f7ce505f 100644 --- a/applications/solvers/lagrangian/particleFoam/particleFoam.C +++ b/applications/solvers/lagrangian/particleFoam/particleFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -54,14 +54,20 @@ int main(int argc, char *argv[]) Info<< "\nStarting time loop\n" << endl; - while (runTime.loop()) + while (runTime.run()) { - Info<< "Time = " << runTime.userTimeName() << nl << endl; - clouds.storeGlobalPositions(); + // Update the mesh for topology change, mesh to mesh mapping mesh.update(); + runTime++; + + Info<< "Time = " << runTime.userTimeName() << nl << endl; + + // Move the mesh + mesh.move(); + if (mesh.changing()) { U.correctBoundaryConditions(); diff --git a/applications/solvers/lagrangian/rhoParticleFoam/rhoParticleFoam.C b/applications/solvers/lagrangian/rhoParticleFoam/rhoParticleFoam.C index 3cfba81199..393d8f5e28 100644 --- a/applications/solvers/lagrangian/rhoParticleFoam/rhoParticleFoam.C +++ b/applications/solvers/lagrangian/rhoParticleFoam/rhoParticleFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -53,14 +53,19 @@ int main(int argc, char *argv[]) Info<< "\nStarting time loop\n" << endl; - while (runTime.loop()) + while (runTime.run()) { - Info<< "Time = " << runTime.userTimeName() << nl << endl; - clouds.storeGlobalPositions(); mesh.update(); + runTime++; + + Info<< "Time = " << runTime.userTimeName() << nl << endl; + + // Move the mesh + mesh.move(); + if (mesh.changing()) { U.correctBoundaryConditions(); diff --git a/applications/solvers/multiphase/cavitatingFoam/cavitatingFoam.C b/applications/solvers/multiphase/cavitatingFoam/cavitatingFoam.C index d4c0abb216..536ff04261 100644 --- a/applications/solvers/multiphase/cavitatingFoam/cavitatingFoam.C +++ b/applications/solvers/multiphase/cavitatingFoam/cavitatingFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -70,12 +70,15 @@ int main(int argc, char *argv[]) #include "CourantNo.H" #include "setDeltaT.H" + // Update the mesh for topology change, mesh to mesh mapping + mesh.update(); + runTime++; Info<< "Time = " << runTime.userTimeName() << nl << endl; - // Do any mesh changes - mesh.update(); + // Move the mesh + mesh.move(); if (mesh.changing() && correctPhi) { diff --git a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFoam.C b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFoam.C index eda03ec719..1faeb863a3 100644 --- a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFoam.C +++ b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -91,6 +91,26 @@ int main(int argc, char *argv[]) #include "setDeltaT.H" } + fvModels.preUpdateMesh(); + + // Store divU from the previous mesh so that it can be mapped + // and used in correctPhi to ensure the corrected phi has the + // same divergence + tmp divU; + + if (correctPhi && mesh.topoChanging()) + { + // Construct and register divU for mapping + divU = new volScalarField + ( + "divU0", + fvc::div(fvc::absolute(phi, U)) + ); + } + + // Update the mesh for topology change, mesh to mesh mapping + mesh.update(); + runTime++; Info<< "Time = " << runTime.userTimeName() << nl << endl; @@ -100,14 +120,9 @@ int main(int argc, char *argv[]) { if (pimple.firstPimpleIter() || moveMeshOuterCorrectors) { - // Store divU from the previous mesh so that it can be mapped - // and used in correctPhi to ensure the corrected phi has the - // same divergence - tmp divU; - - if (correctPhi) + if (correctPhi && !divU.valid()) { - // Construct and register divU for mapping + // Construct and register divU for correctPhi divU = new volScalarField ( "divU0", @@ -115,9 +130,8 @@ int main(int argc, char *argv[]) ); } - fvModels.preUpdateMesh(); - - mesh.update(); + // Move the mesh + mesh.move(); if (mesh.changing()) { diff --git a/applications/solvers/multiphase/interFoam/interFoam.C b/applications/solvers/multiphase/interFoam/interFoam.C index 3a6e011722..67507e2a16 100644 --- a/applications/solvers/multiphase/interFoam/interFoam.C +++ b/applications/solvers/multiphase/interFoam/interFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -89,6 +89,38 @@ int main(int argc, char *argv[]) #include "setDeltaT.H" } + fvModels.preUpdateMesh(); + + // Store divU from the previous mesh so that it can be mapped + // and used in correctPhi to ensure the corrected phi has the + // same divergence + tmp divU; + + if + ( + correctPhi + && !isType(phaseChange) + && mesh.topoChanging() + ) + { + // Construct and register divU for correctPhi + divU = new volScalarField + ( + "divU0", + fvc::div(fvc::absolute(phi, U)) + ); + } + + // Update the mesh for topology change, mesh to mesh mapping + bool topoChanged = mesh.update(); + + // Do not apply previous time-step mesh compression flux + // if the mesh topology changed + if (topoChanged) + { + talphaPhi1Corr0.clear(); + } + runTime++; Info<< "Time = " << runTime.userTimeName() << nl << endl; @@ -98,18 +130,14 @@ int main(int argc, char *argv[]) { if (pimple.firstPimpleIter() || moveMeshOuterCorrectors) { - // Store divU from the previous mesh so that it can be mapped - // and used in correctPhi to ensure the corrected phi has the - // same divergence - tmp divU; - if ( correctPhi && !isType(phaseChange) + && !divU.valid() ) { - // Construct and register divU for mapping + // Construct and register divU for correctPhi divU = new volScalarField ( "divU0", @@ -117,19 +145,11 @@ int main(int argc, char *argv[]) ); } - fvModels.preUpdateMesh(); - - mesh.update(); + // Move the mesh + mesh.move(); if (mesh.changing()) { - // Do not apply previous time-step mesh compression flux - // if the mesh topology changed - if (mesh.topoChanging()) - { - talphaPhi1Corr0.clear(); - } - gh = (g & mesh.C()) - ghRef; ghf = (g & mesh.Cf()) - ghRef; diff --git a/applications/solvers/multiphase/interFoam/interMixingFoam/interMixingFoam.C b/applications/solvers/multiphase/interFoam/interMixingFoam/interMixingFoam.C index b6c1641d0b..366bb35a2f 100644 --- a/applications/solvers/multiphase/interFoam/interMixingFoam/interMixingFoam.C +++ b/applications/solvers/multiphase/interFoam/interMixingFoam/interMixingFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -88,6 +88,11 @@ int main(int argc, char *argv[]) #include "setDeltaT.H" } + fvModels.preUpdateMesh(); + + // Update the mesh for topology change, mesh to mesh mapping + mesh.update(); + runTime++; Info<< "Time = " << runTime.userTimeName() << nl << endl; @@ -97,9 +102,8 @@ int main(int argc, char *argv[]) { if (pimple.firstPimpleIter() || moveMeshOuterCorrectors) { - fvModels.preUpdateMesh(); - - mesh.update(); + // Move the mesh + mesh.move(); if (mesh.changing()) { @@ -111,10 +115,10 @@ int main(int argc, char *argv[]) if (correctPhi) { #include "correctPhi.H" - - mixture.correct(); } + mixture.correct(); + if (checkMeshCourantNo) { #include "meshCourantNo.H" diff --git a/applications/solvers/multiphase/multiphaseEulerFoam/multiphaseEulerFoam/multiphaseEulerFoam.C b/applications/solvers/multiphase/multiphaseEulerFoam/multiphaseEulerFoam/multiphaseEulerFoam.C index 7d4a33d0f7..0a91bcd129 100644 --- a/applications/solvers/multiphase/multiphaseEulerFoam/multiphaseEulerFoam/multiphaseEulerFoam.C +++ b/applications/solvers/multiphase/multiphaseEulerFoam/multiphaseEulerFoam/multiphaseEulerFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -98,7 +98,30 @@ int main(int argc, char *argv[]) #include "setDeltaT.H" } + fvModels.preUpdateMesh(); + + // Store divU from the previous mesh so that it can be + // mapped and used in correctPhi to ensure the corrected phi + // has the same divergence + tmp divU; + + if (correctPhi && mesh.topoChanging()) + { + // Construct and register divU for mapping + divU = new volScalarField + ( + "divU0", + fvc::div + ( + fvc::absolute(phi, fluid.movingPhases()[0].U()) + ) + ); + } + + mesh.update(); + runTime++; + Info<< "Time = " << runTime.userTimeName() << nl << endl; // --- Pressure-velocity PIMPLE corrector loop @@ -131,15 +154,7 @@ int main(int argc, char *argv[]) { if (pimple.firstPimpleIter() || moveMeshOuterCorrectors) { - // Store divU from the previous mesh so that it can be - // mapped and used in correctPhi to ensure the corrected phi - // has the same divergence - tmp divU; - - if - ( - correctPhi - ) + if (correctPhi && !divU.valid()) { // Construct and register divU for mapping divU = new volScalarField @@ -152,9 +167,8 @@ int main(int argc, char *argv[]) ); } - fvModels.preUpdateMesh(); - - mesh.update(); + // Move the mesh + mesh.move(); if (mesh.changing()) { @@ -179,6 +193,8 @@ int main(int argc, char *argv[]) #include "meshCourantNo.H" } } + + divU.clear(); } if (pimple.models()) diff --git a/applications/solvers/multiphase/multiphaseEulerFoam/phaseSystems/phaseSystem/phaseSystem.C b/applications/solvers/multiphase/multiphaseEulerFoam/phaseSystems/phaseSystem/phaseSystem.C index bd840684f8..912af832c1 100644 --- a/applications/solvers/multiphase/multiphaseEulerFoam/phaseSystems/phaseSystem/phaseSystem.C +++ b/applications/solvers/multiphase/multiphaseEulerFoam/phaseSystems/phaseSystem/phaseSystem.C @@ -235,7 +235,7 @@ Foam::phaseSystem::phaseSystem phaseModel::iNew(*this, referencePhaseName_) ), - phi_(calcPhi(phaseModels_)), + phi_("phi", calcPhi(phaseModels_)), dpdt_ ( diff --git a/applications/solvers/multiphase/multiphaseInterFoam/multiphaseInterFoam.C b/applications/solvers/multiphase/multiphaseInterFoam/multiphaseInterFoam.C index fd2730b262..ecfd090974 100644 --- a/applications/solvers/multiphase/multiphaseInterFoam/multiphaseInterFoam.C +++ b/applications/solvers/multiphase/multiphaseInterFoam/multiphaseInterFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -75,6 +75,11 @@ int main(int argc, char *argv[]) #include "alphaCourantNo.H" #include "setDeltaT.H" + fvModels.preUpdateMesh(); + + // Update the mesh for topology change, mesh to mesh mapping + mesh.update(); + runTime++; Info<< "Time = " << runTime.userTimeName() << nl << endl; @@ -86,9 +91,8 @@ int main(int argc, char *argv[]) { scalar timeBeforeMeshUpdate = runTime.elapsedCpuTime(); - fvModels.preUpdateMesh(); - - mesh.update(); + // Move the mesh + mesh.move(); if (mesh.changing()) { diff --git a/applications/solvers/multiphase/potentialFreeSurfaceFoam/potentialFreeSurfaceFoam.C b/applications/solvers/multiphase/potentialFreeSurfaceFoam/potentialFreeSurfaceFoam.C index 67b4aad457..de9601f488 100644 --- a/applications/solvers/multiphase/potentialFreeSurfaceFoam/potentialFreeSurfaceFoam.C +++ b/applications/solvers/multiphase/potentialFreeSurfaceFoam/potentialFreeSurfaceFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -90,6 +90,20 @@ int main(int argc, char *argv[]) #include "CourantNo.H" #include "setDeltaT.H" + fvModels.preUpdateMesh(); + + const scalar timeBeforeMeshUpdate = runTime.elapsedCpuTime(); + + // Update the mesh for topology change, mesh to mesh mapping + const bool topoChanged = mesh.update(); + + if (topoChanged) + { + Info<< "Execution time for mesh.update() = " + << runTime.elapsedCpuTime() - timeBeforeMeshUpdate + << " s" << endl; + } + runTime++; Info<< "Time = " << runTime.userTimeName() << nl << endl; @@ -99,18 +113,11 @@ int main(int argc, char *argv[]) { if (pimple.firstPimpleIter() || moveMeshOuterCorrectors) { - scalar timeBeforeMeshUpdate = runTime.elapsedCpuTime(); - - fvModels.preUpdateMesh(); - - mesh.update(); + // Move the mesh + mesh.move(); if (mesh.changing()) { - Info<< "Execution time for mesh.update() = " - << runTime.elapsedCpuTime() - timeBeforeMeshUpdate - << " s" << endl; - MRF.update(); if (correctPhi) diff --git a/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.C b/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.C index a435ed468e..423ad4d116 100644 --- a/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.C +++ b/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -382,9 +382,9 @@ Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io, const IOobject& dictIO) new fvMesh ( io, - move(newPoints), - move(newFaces), - move(newCells) + std::move(newPoints), + std::move(newFaces), + std::move(newCells) ) ); diff --git a/applications/utilities/mesh/manipulation/moveDynamicMesh/moveDynamicMesh.C b/applications/utilities/mesh/manipulation/moveDynamicMesh/moveDynamicMesh.C index f0e8611dd2..dae727ee30 100644 --- a/applications/utilities/mesh/manipulation/moveDynamicMesh/moveDynamicMesh.C +++ b/applications/utilities/mesh/manipulation/moveDynamicMesh/moveDynamicMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -95,15 +95,21 @@ int main(int argc, char *argv[]) pimple.dict().lookupOrDefault("moveMeshOuterCorrectors", false) ); - while (runTime.loop()) + while (runTime.run()) { + // Update the mesh for topology change, mesh to mesh mapping + mesh.update(); + + runTime++; + Info<< "Time = " << runTime.userTimeName() << endl; while (pimple.loop()) { if (pimple.firstPimpleIter() || moveMeshOuterCorrectors) { - mesh.update(); + // Move the mesh + mesh.move(); } } diff --git a/applications/utilities/postProcessing/miscellaneous/engineCompRatio/engineCompRatio.C b/applications/utilities/postProcessing/miscellaneous/engineCompRatio/engineCompRatio.C index 9e8761bf01..7bec497736 100644 --- a/applications/utilities/postProcessing/miscellaneous/engineCompRatio/engineCompRatio.C +++ b/applications/utilities/postProcessing/miscellaneous/engineCompRatio/engineCompRatio.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) runTime.setDeltaT(t0); runTime++; Info<< "CA = " << runTime.userTimeValue() << endl; - mesh.update(); + mesh.move(); } scalar Vmax = sum(mesh.V().field()); @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) runTime.setDeltaT(t1); runTime++; Info<< "CA = " << runTime.userTimeValue() << endl; - mesh.update(); + mesh.move(); } scalar Vmin = sum(mesh.V().field()); diff --git a/src/MomentumTransportModels/phaseCompressible/RAS/mixtureKEpsilon/mixtureKEpsilon.C b/src/MomentumTransportModels/phaseCompressible/RAS/mixtureKEpsilon/mixtureKEpsilon.C index 165bea8e9d..d4ce340123 100644 --- a/src/MomentumTransportModels/phaseCompressible/RAS/mixtureKEpsilon/mixtureKEpsilon.C +++ b/src/MomentumTransportModels/phaseCompressible/RAS/mixtureKEpsilon/mixtureKEpsilon.C @@ -220,6 +220,9 @@ void mixtureKEpsilon::correctInletOutlet (bf[patchi]).refValue() = refCast (refBf[patchi]).refValue(); + + refCast + (bf[patchi]).phiName() = "phim"; } } } @@ -311,6 +314,7 @@ void mixtureKEpsilon::initMixtureFields() epsilonBoundaryTypes(epsilonl) ) ); + correctInletOutlet(epsilonm_(), epsilonl); } @@ -703,7 +707,6 @@ void mixtureKEpsilon::correct() fvConstraints.constrain(epsilonm); bound(epsilonm, this->epsilonMin_); - // Turbulent kinetic energy equation tmp kmEqn ( diff --git a/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.C b/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.C index 7b589db463..7236544b5c 100644 --- a/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.C +++ b/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.C @@ -171,4 +171,16 @@ void Foam::points0MotionSolver::distribute {} +bool Foam::points0MotionSolver::write() const +{ + if (mesh().topoChanging()) + { + points0_.instance() = mesh().time().timeName(); + points0_.write(); + } + + return motionSolver::write(); +} + + // ************************************************************************* // diff --git a/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.H b/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.H index fa12bb6011..d40c0b56b4 100644 --- a/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.H +++ b/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.H @@ -115,6 +115,9 @@ public: //- Update corresponding to the given distribution map virtual void distribute(const polyDistributionMap&); + //- Write points0 if the mesh topology changed + virtual bool write() const; + // Member Operators diff --git a/src/dynamicMesh/motionSolvers/displacement/solidBody/solidBodyMotionSolver/solidBodyMotionSolver.C b/src/dynamicMesh/motionSolvers/displacement/solidBody/solidBodyMotionSolver/solidBodyMotionSolver.C index 76d0d8d596..6ddf5e030b 100644 --- a/src/dynamicMesh/motionSolvers/displacement/solidBody/solidBodyMotionSolver/solidBodyMotionSolver.C +++ b/src/dynamicMesh/motionSolvers/displacement/solidBody/solidBodyMotionSolver/solidBodyMotionSolver.C @@ -225,12 +225,6 @@ void Foam::solidBodyMotionSolver::topoChange(const polyTopoChangeMap& map) twoDCorrectPoints(newPoints0); points0_.transfer(newPoints0); - - // points0 changed - set to write and check-in to database - points0_.rename("points0"); - points0_.writeOpt() = IOobject::AUTO_WRITE; - points0_.instance() = mesh().time().timeName(); - points0_.checkIn(); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/inletOutlet/inletOutletFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/inletOutlet/inletOutletFvPatchField.H index ab59a9b561..264eed016a 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/inletOutlet/inletOutletFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/inletOutlet/inletOutletFvPatchField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -157,6 +157,18 @@ public: return true; } + //- Return the flux-field name + const word& phiName() const + { + return phiName_; + } + + //- Return access to the flux-field name + word& phiName() + { + return phiName_; + } + //- Update the coefficients associated with the patch field virtual void updateCoeffs(); diff --git a/src/finiteVolume/fvMesh/fvMesh.C b/src/finiteVolume/fvMesh/fvMesh.C index e59e2046c4..d30924740f 100644 --- a/src/finiteVolume/fvMesh/fvMesh.C +++ b/src/finiteVolume/fvMesh/fvMesh.C @@ -345,7 +345,7 @@ Foam::fvMesh::fvMesh polyMesh ( io, - move(points), + std::move(points), shapes, boundaryFaces, boundaryPatchNames, @@ -391,10 +391,10 @@ Foam::fvMesh::fvMesh polyMesh ( io, - move(points), - move(faces), - move(allOwner), - move(allNeighbour), + std::move(points), + std::move(faces), + std::move(allOwner), + std::move(allNeighbour), syncPar ), surfaceInterpolation(*this), @@ -430,7 +430,14 @@ Foam::fvMesh::fvMesh const bool syncPar ) : - polyMesh(io, move(points), move(faces), move(cells), syncPar), + polyMesh + ( + io, + std::move(points), + std::move(faces), + std::move(cells), + syncPar + ), surfaceInterpolation(*this), data(static_cast(*this)), boundary_(*this), @@ -475,44 +482,47 @@ bool Foam::fvMesh::update() { bool updated = false; - if (curTimeIndex_ < time().timeIndex()) + const bool hasV00 = V00Ptr_; + deleteDemandDrivenData(V00Ptr_); + + if (!hasV00) { - const bool hasV00 = V00Ptr_; - deleteDemandDrivenData(V00Ptr_); - - if (!hasV00) - { - deleteDemandDrivenData(V0Ptr_); - } - - updated = topoChanger_->update() || updated; - - // Register V0 for distribution - if (V0Ptr_) - { - V0Ptr_->checkIn(); - } - - updated = distributor_->update() || updated; - - // De-register V0 after distribution - if (V0Ptr_) - { - V0Ptr_->checkOut(); - } - - if (hasV00) - { - // If V00 had been set reset to the mapped V0 prior to mesh-motion - V00(); - } + deleteDemandDrivenData(V0Ptr_); } - updated = mover_->update() || updated; + updated = topoChanger_->update() || updated; + + // Register V0 for distribution + if (V0Ptr_) + { + V0Ptr_->checkIn(); + } + + updated = distributor_->update() || updated; + + // De-register V0 after distribution + if (V0Ptr_) + { + V0Ptr_->checkOut(); + } + + if (hasV00) + { + // If V00 had been set reset to the mapped V0 prior to mesh-motion + V00(); + } + + return updated; +} + + +bool Foam::fvMesh::move() +{ + const bool moved = mover_->update(); curTimeIndex_ = time().timeIndex(); - return updated; + return moved; } diff --git a/src/finiteVolume/fvMesh/fvMesh.H b/src/finiteVolume/fvMesh/fvMesh.H index f2d181f581..4314c14f25 100644 --- a/src/finiteVolume/fvMesh/fvMesh.H +++ b/src/finiteVolume/fvMesh/fvMesh.H @@ -374,9 +374,13 @@ public: //- Is mesh dynamic virtual bool dynamic() const; - //- Update the mesh for both mesh motion and topology change + //- Update the mesh for topology change, mesh to mesh mapping + // or redistribution virtual bool update(); + //- Move the mesh + virtual bool move(); + //- Clear all geometry and addressing void clearOut(); diff --git a/src/finiteVolume/fvMesh/singleCellFvMesh/singleCellFvMesh.C b/src/finiteVolume/fvMesh/singleCellFvMesh/singleCellFvMesh.C index fb9608fdf6..d625033fa3 100644 --- a/src/finiteVolume/fvMesh/singleCellFvMesh/singleCellFvMesh.C +++ b/src/finiteVolume/fvMesh/singleCellFvMesh/singleCellFvMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -276,10 +276,10 @@ void Foam::singleCellFvMesh::agglomerateMesh // actually change the mesh resetPrimitives ( - move(boundaryPoints), - move(patchFaces), - move(owner), - move(neighbour), + std::move(boundaryPoints), + std::move(patchFaces), + std::move(owner), + std::move(neighbour), patchSizes, patchStarts, true // syncPar diff --git a/src/fvMeshTopoChangers/meshToMesh/fvMeshTopoChangersMeshToMesh.C b/src/fvMeshTopoChangers/meshToMesh/fvMeshTopoChangersMeshToMesh.C index 3fc7d2b182..a42bf051cd 100644 --- a/src/fvMeshTopoChangers/meshToMesh/fvMeshTopoChangersMeshToMesh.C +++ b/src/fvMeshTopoChangers/meshToMesh/fvMeshTopoChangersMeshToMesh.C @@ -159,13 +159,11 @@ bool Foam::fvMeshTopoChangers::meshToMesh::update() bool hasChanged = false; - const scalar userTime0 = - mesh().time().userTimeValue() - - mesh().time().timeToUserTime(mesh().time().deltaTValue()); + const scalar userTime = mesh().time().userTimeValue(); - if (timeIndices_.found((userTime0 + timeDelta_/2)/timeDelta_)) + if (timeIndices_.found((userTime + timeDelta_/2)/timeDelta_)) { - const word meshDir = "meshToMesh_" + mesh().time().timeName(userTime0); + const word meshDir = "meshToMesh_" + mesh().time().timeName(userTime); Info << "Mapping to mesh " << meshDir << endl; diff --git a/tutorials/multiphase/multiphaseEulerFoam/laminar/titaniaSynthesis/0/p_rgh b/tutorials/multiphase/multiphaseEulerFoam/laminar/titaniaSynthesis/0/p_rgh index 5f512119d1..b0576592c5 100644 --- a/tutorials/multiphase/multiphaseEulerFoam/laminar/titaniaSynthesis/0/p_rgh +++ b/tutorials/multiphase/multiphaseEulerFoam/laminar/titaniaSynthesis/0/p_rgh @@ -31,6 +31,7 @@ boundaryField { type prghTotalPressure; U U.vapor; + phi phi.vapor; rho thermo:rho.vapor; p0 uniform 1e5; value $internalField; diff --git a/tutorials/multiphase/multiphaseEulerFoam/laminar/titaniaSynthesisSurface/0/p_rgh b/tutorials/multiphase/multiphaseEulerFoam/laminar/titaniaSynthesisSurface/0/p_rgh index 5f512119d1..b0576592c5 100644 --- a/tutorials/multiphase/multiphaseEulerFoam/laminar/titaniaSynthesisSurface/0/p_rgh +++ b/tutorials/multiphase/multiphaseEulerFoam/laminar/titaniaSynthesisSurface/0/p_rgh @@ -31,6 +31,7 @@ boundaryField { type prghTotalPressure; U U.vapor; + phi phi.vapor; rho thermo:rho.vapor; p0 uniform 1e5; value $internalField;