From 7d6b1be4b3331d96d41bb723de03c6b0916c3e77 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Thu, 30 Nov 2017 13:07:42 +0000 Subject: [PATCH] pimpleFoam, rhoPimpleFoam, interDyMFoam: Rationalized mesh-motion support Added support for mesh-motion update within PIMPLE loop in pimpleFoam and rhoPimpleFoam. --- .../compressible/rhoPimpleFoam/readControls.H | 10 -- .../rhoPimpleFoam/rhoPimpleFoam.C | 127 +++++++++--------- .../sonicFoam/sonicDyMFoam/sonicDyMFoam.C | 5 +- .../incompressible/pimpleFoam/pimpleFoam.C | 56 ++++---- .../incompressible/pimpleFoam/readControls.H | 5 - .../DPMFoam/DPMDyMFoam/DPMDyMFoam.C | 4 +- .../DPMFoam/DPMDyMFoam/createControls.H | 12 -- .../DPMFoam/DPMDyMFoam/readControls.H | 5 - .../sprayFoam/sprayDyMFoam/sprayDyMFoam.C | 5 +- .../cavitatingDyMFoam/cavitatingDyMFoam.C | 3 +- .../cavitatingDyMFoam/createControls.H | 7 +- .../cavitatingDyMFoam/readControls.H | 3 +- .../compressibleInterDyMFoam.C | 5 +- .../compressibleInterDyMFoam/createControls.H | 16 --- .../compressibleInterDyMFoam/readControls.H | 9 -- .../interFoam/interDyMFoam/correctPhi.H | 2 +- .../interDyMFoam/createDyMControls.H | 14 -- .../interFoam/interDyMFoam/interDyMFoam.C | 37 +++-- .../multiphase/interFoam/interDyMFoam/pEqn.H | 20 +-- .../interFoam/interDyMFoam/readControls.H | 9 -- .../interPhaseChangeDyMFoam.C | 6 +- .../multiphaseInterDyMFoam.C | 32 +++-- .../potentialFreeSurfaceDyMFoam.C | 4 +- src/OpenFOAM/meshes/polyMesh/polyMesh.H | 6 + .../dynamicFvMesh/dynamicFvMesh.H | 10 +- .../dynamicFvMesh/dynamicFvMeshNew.C | 2 +- .../dynamicFvMesh/include/createDyMControls.H | 7 +- src/dynamicFvMesh/include/readDyMControls.H | 19 +++ src/dynamicFvMesh/staticFvMesh/staticFvMesh.H | 8 +- .../compressible/createRhoUfIfPresent.H | 29 ++-- .../cfdTools/compressible/updateRhoUf.H | 21 +-- .../incompressible/createUfIfPresent.H | 29 ++-- .../cfdTools/incompressible/updateUf.H | 21 +-- src/finiteVolume/finiteVolume/fvc/fvcDdt.C | 4 +- .../finiteVolume/fvc/fvcMeshPhi.C | 4 +- .../constant/dynamicMeshDict | 2 +- 36 files changed, 237 insertions(+), 321 deletions(-) delete mode 100644 applications/solvers/compressible/rhoPimpleFoam/readControls.H delete mode 100644 applications/solvers/incompressible/pimpleFoam/readControls.H delete mode 100644 applications/solvers/lagrangian/DPMFoam/DPMDyMFoam/createControls.H delete mode 100644 applications/solvers/lagrangian/DPMFoam/DPMDyMFoam/readControls.H delete mode 100644 applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/createControls.H delete mode 100644 applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/readControls.H delete mode 100644 applications/solvers/multiphase/interFoam/interDyMFoam/createDyMControls.H delete mode 100644 applications/solvers/multiphase/interFoam/interDyMFoam/readControls.H rename applications/solvers/incompressible/pimpleFoam/createControls.H => src/dynamicFvMesh/include/createDyMControls.H (51%) create mode 100644 src/dynamicFvMesh/include/readDyMControls.H diff --git a/applications/solvers/compressible/rhoPimpleFoam/readControls.H b/applications/solvers/compressible/rhoPimpleFoam/readControls.H deleted file mode 100644 index 8a127d2bd..000000000 --- a/applications/solvers/compressible/rhoPimpleFoam/readControls.H +++ /dev/null @@ -1,10 +0,0 @@ -#include "readTimeControls.H" - -bool correctPhi = pimple.dict().lookupOrDefault -( - "correctPhi", - !isA(mesh) -); - -bool checkMeshCourantNo = - pimple.dict().lookupOrDefault("checkMeshCourantNo", false); diff --git a/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C b/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C index 754e95bfc..ec272f150 100644 --- a/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C +++ b/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C @@ -54,12 +54,11 @@ int main(int argc, char *argv[]) #include "setRootCase.H" #include "createTime.H" #include "createDynamicFvMesh.H" - #include "createControl.H" + #include "createDyMControls.H" #include "initContinuityErrs.H" #include "createFields.H" #include "createFieldRefs.H" #include "createRhoUfIfPresent.H" - #include "createTimeControls.H" turbulence->validate(); @@ -75,78 +74,78 @@ int main(int argc, char *argv[]) while (runTime.run()) { - #include "readControls.H" + #include "readDyMControls.H" + // Store divrhoU from the previous mesh so that it can be mapped + // and used in correctPhi to ensure the corrected phi has the + // same divergence + autoPtr divrhoU; + if (correctPhi) { - // Store divrhoU from the previous mesh so that it can be mapped - // and used in correctPhi to ensure the corrected phi has the - // same divergence - autoPtr divrhoU; - if (correctPhi) - { - divrhoU = new volScalarField - ( - "divrhoU", - fvc::div(fvc::absolute(phi, rho, U)) - ); - } - - if (LTS) - { - #include "setRDeltaT.H" - } - else - { - #include "compressibleCourantNo.H" - #include "setDeltaT.H" - } - - runTime++; - - Info<< "Time = " << runTime.timeName() << nl << endl; - - // Store momentum to set rhoUf for introduced faces. - autoPtr rhoU; - if (rhoUf.valid()) - { - rhoU = new volVectorField("rhoU", rho*U); - } - - // Do any mesh changes - mesh.update(); - - #include "updateRhoUf.H" - - if (mesh.changing()) - { - MRF.update(); - - if (correctPhi) - { - // Calculate absolute flux from the mapped surface velocity - phi = mesh.Sf() & rhoUf(); - - #include "correctPhi.H" - - // Make the fluxes relative to the mesh-motion - fvc::makeRelative(phi, rho, U); - } - - if (checkMeshCourantNo) - { - #include "meshCourantNo.H" - } - } + divrhoU = new volScalarField + ( + "divrhoU", + fvc::div(fvc::absolute(phi, rho, U)) + ); } - if (pimple.nCorrPIMPLE() <= 1) + if (LTS) { - #include "rhoEqn.H" + #include "setRDeltaT.H" } + else + { + #include "compressibleCourantNo.H" + #include "setDeltaT.H" + } + + runTime++; + + Info<< "Time = " << runTime.timeName() << nl << endl; // --- Pressure-velocity PIMPLE corrector loop while (pimple.loop()) { + if (pimple.firstIter() || moveMeshOuterCorrectors) + { + // Store momentum to set rhoUf for introduced faces. + autoPtr rhoU; + if (rhoUf.valid()) + { + rhoU = new volVectorField("rhoU", rho*U); + } + + // Do any mesh changes + mesh.update(); + + if (mesh.changing()) + { + MRF.update(); + + if (correctPhi) + { + // Calculate absolute flux + // from the mapped surface velocity + phi = mesh.Sf() & rhoUf(); + + #include "correctPhi.H" + + // Make the fluxes relative to the mesh-motion + fvc::makeRelative(phi, rho, U); + } + + if (checkMeshCourantNo) + { + #include "meshCourantNo.H" + } + } + } + + if (pimple.nCorrPIMPLE() <= 1) + { + #include "rhoEqn.H" + } + #include "UEqn.H" #include "EEqn.H" diff --git a/applications/solvers/compressible/sonicFoam/sonicDyMFoam/sonicDyMFoam.C b/applications/solvers/compressible/sonicFoam/sonicDyMFoam/sonicDyMFoam.C index 89b216a6a..0a826053b 100644 --- a/applications/solvers/compressible/sonicFoam/sonicDyMFoam/sonicDyMFoam.C +++ b/applications/solvers/compressible/sonicFoam/sonicDyMFoam/sonicDyMFoam.C @@ -50,8 +50,7 @@ int main(int argc, char *argv[]) #include "setRootCase.H" #include "createTime.H" #include "createDynamicFvMesh.H" - #include "createControl.H" - #include "createTimeControls.H" + #include "createDyMControls.H" #include "createFields.H" #include "createFieldRefs.H" #include "createRhoUf.H" @@ -67,7 +66,7 @@ int main(int argc, char *argv[]) while (runTime.run()) { - #include "readControls.H" + #include "readDyMControls.H" { // Store divrhoU from the previous mesh so that it can be mapped diff --git a/applications/solvers/incompressible/pimpleFoam/pimpleFoam.C b/applications/solvers/incompressible/pimpleFoam/pimpleFoam.C index b3ac3719c..5e29dc3aa 100644 --- a/applications/solvers/incompressible/pimpleFoam/pimpleFoam.C +++ b/applications/solvers/incompressible/pimpleFoam/pimpleFoam.C @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) #include "createTime.H" #include "createDynamicFvMesh.H" #include "initContinuityErrs.H" - #include "createControls.H" + #include "createDyMControls.H" #include "createFields.H" #include "createUfIfPresent.H" #include "CourantNo.H" @@ -64,7 +64,7 @@ int main(int argc, char *argv[]) while (runTime.run()) { - #include "readControls.H" + #include "readDyMControls.H" #include "CourantNo.H" #include "setDeltaT.H" @@ -72,34 +72,36 @@ int main(int argc, char *argv[]) Info<< "Time = " << runTime.timeName() << nl << endl; - mesh.update(); - - #include "updateUf.H" - - if (mesh.changing()) - { - MRF.update(); - - if (correctPhi) - { - // Calculate absolute flux from the mapped surface velocity - phi = mesh.Sf() & Uf(); - - #include "correctPhi.H" - - // Make the flux relative to the mesh motion - fvc::makeRelative(phi, U); - } - - if (checkMeshCourantNo) - { - #include "meshCourantNo.H" - } - } - // --- Pressure-velocity PIMPLE corrector loop while (pimple.loop()) { + if (pimple.firstIter() || moveMeshOuterCorrectors) + { + mesh.update(); + + if (mesh.changing()) + { + MRF.update(); + + if (correctPhi) + { + // Calculate absolute flux + // from the mapped surface velocity + phi = mesh.Sf() & Uf(); + + #include "correctPhi.H" + + // Make the flux relative to the mesh motion + fvc::makeRelative(phi, U); + } + + if (checkMeshCourantNo) + { + #include "meshCourantNo.H" + } + } + } + #include "UEqn.H" // --- Pressure corrector loop diff --git a/applications/solvers/incompressible/pimpleFoam/readControls.H b/applications/solvers/incompressible/pimpleFoam/readControls.H deleted file mode 100644 index 9f982e260..000000000 --- a/applications/solvers/incompressible/pimpleFoam/readControls.H +++ /dev/null @@ -1,5 +0,0 @@ -#include "readTimeControls.H" - -correctPhi = pimple.dict().lookupOrDefault("correctPhi", false); - -checkMeshCourantNo = pimple.dict().lookupOrDefault("checkMeshCourantNo", false); diff --git a/applications/solvers/lagrangian/DPMFoam/DPMDyMFoam/DPMDyMFoam.C b/applications/solvers/lagrangian/DPMFoam/DPMDyMFoam/DPMDyMFoam.C index ded2af139..df56530a7 100644 --- a/applications/solvers/lagrangian/DPMFoam/DPMDyMFoam/DPMDyMFoam.C +++ b/applications/solvers/lagrangian/DPMFoam/DPMDyMFoam/DPMDyMFoam.C @@ -60,7 +60,7 @@ int main(int argc, char *argv[]) #include "setRootCase.H" #include "createTime.H" #include "createDynamicFvMesh.H" - #include "createControls.H" + #include "createDyMControls.H" #include "createFields.H" #include "createUcf.H" #include "initContinuityErrs.H" @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) while (runTime.run()) { - #include "readControls.H" + #include "readDyMControls.H" #include "CourantNo.H" #include "setDeltaT.H" diff --git a/applications/solvers/lagrangian/DPMFoam/DPMDyMFoam/createControls.H b/applications/solvers/lagrangian/DPMFoam/DPMDyMFoam/createControls.H deleted file mode 100644 index bee8bd4f3..000000000 --- a/applications/solvers/lagrangian/DPMFoam/DPMDyMFoam/createControls.H +++ /dev/null @@ -1,12 +0,0 @@ -#include "createControl.H" -#include "createTimeControls.H" - -bool correctPhi -( - pimple.dict().lookupOrDefault("correctPhi", false) -); - -bool checkMeshCourantNo -( - pimple.dict().lookupOrDefault("checkMeshCourantNo", false) -); diff --git a/applications/solvers/lagrangian/DPMFoam/DPMDyMFoam/readControls.H b/applications/solvers/lagrangian/DPMFoam/DPMDyMFoam/readControls.H deleted file mode 100644 index 9f982e260..000000000 --- a/applications/solvers/lagrangian/DPMFoam/DPMDyMFoam/readControls.H +++ /dev/null @@ -1,5 +0,0 @@ -#include "readTimeControls.H" - -correctPhi = pimple.dict().lookupOrDefault("correctPhi", false); - -checkMeshCourantNo = pimple.dict().lookupOrDefault("checkMeshCourantNo", false); diff --git a/applications/solvers/lagrangian/sprayFoam/sprayDyMFoam/sprayDyMFoam.C b/applications/solvers/lagrangian/sprayFoam/sprayDyMFoam/sprayDyMFoam.C index fc8ce4e1a..dcc751c18 100644 --- a/applications/solvers/lagrangian/sprayFoam/sprayDyMFoam/sprayDyMFoam.C +++ b/applications/solvers/lagrangian/sprayFoam/sprayDyMFoam/sprayDyMFoam.C @@ -50,8 +50,7 @@ int main(int argc, char *argv[]) #include "setRootCase.H" #include "createTime.H" #include "createDynamicFvMesh.H" - #include "createControl.H" - #include "createTimeControls.H" + #include "createDyMControls.H" #include "createFields.H" #include "createFieldRefs.H" #include "createRhoUf.H" @@ -67,7 +66,7 @@ int main(int argc, char *argv[]) while (runTime.run()) { - #include "readControls.H" + #include "readDyMControls.H" { // Store divrhoU from the previous time-step/mesh for the correctPhi diff --git a/applications/solvers/multiphase/cavitatingFoam/cavitatingDyMFoam/cavitatingDyMFoam.C b/applications/solvers/multiphase/cavitatingFoam/cavitatingDyMFoam/cavitatingDyMFoam.C index 5bda1454a..380ab3b8e 100644 --- a/applications/solvers/multiphase/cavitatingFoam/cavitatingDyMFoam/cavitatingDyMFoam.C +++ b/applications/solvers/multiphase/cavitatingFoam/cavitatingDyMFoam/cavitatingDyMFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -50,7 +50,6 @@ int main(int argc, char *argv[]) #include "setRootCase.H" #include "createTime.H" #include "createDynamicFvMesh.H" - #include "createControl.H" #include "createControls.H" #include "createFields.H" #include "createUf.H" diff --git a/applications/solvers/multiphase/cavitatingFoam/cavitatingDyMFoam/createControls.H b/applications/solvers/multiphase/cavitatingFoam/cavitatingDyMFoam/createControls.H index fbda6ae1a..d47cf78b5 100644 --- a/applications/solvers/multiphase/cavitatingFoam/cavitatingDyMFoam/createControls.H +++ b/applications/solvers/multiphase/cavitatingFoam/cavitatingDyMFoam/createControls.H @@ -1,11 +1,6 @@ -#include "createTimeControls.H" +#include "createDyMControls.H" scalar maxAcousticCo ( readScalar(runTime.controlDict().lookup("maxAcousticCo")) ); - -bool correctPhi -( - pimple.dict().lookupOrDefault("correctPhi", true) -); diff --git a/applications/solvers/multiphase/cavitatingFoam/cavitatingDyMFoam/readControls.H b/applications/solvers/multiphase/cavitatingFoam/cavitatingDyMFoam/readControls.H index ad79c78c6..84ef52ce6 100644 --- a/applications/solvers/multiphase/cavitatingFoam/cavitatingDyMFoam/readControls.H +++ b/applications/solvers/multiphase/cavitatingFoam/cavitatingDyMFoam/readControls.H @@ -1,4 +1,3 @@ -#include "readTimeControls.H" +#include "readDyMControls.H" maxAcousticCo = readScalar(runTime.controlDict().lookup("maxAcousticCo")); -correctPhi = pimple.dict().lookupOrDefault("correctPhi", true); diff --git a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/compressibleInterDyMFoam.C b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/compressibleInterDyMFoam.C index 4fb00d98c..ada64bb5e 100644 --- a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/compressibleInterDyMFoam.C +++ b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/compressibleInterDyMFoam.C @@ -60,10 +60,9 @@ int main(int argc, char *argv[]) #include "createTime.H" #include "createDynamicFvMesh.H" #include "initContinuityErrs.H" - #include "createControl.H" + #include "createDyMControls.H" #include "createFields.H" #include "createUf.H" - #include "createControls.H" #include "CourantNo.H" #include "setInitialDeltaT.H" @@ -77,7 +76,7 @@ int main(int argc, char *argv[]) while (runTime.run()) { - #include "readControls.H" + #include "readDyMControls.H" // Store divU from the previous mesh so that it can be mapped // and used in correctPhi to ensure the corrected phi has the diff --git a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/createControls.H b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/createControls.H deleted file mode 100644 index f1930cdfc..000000000 --- a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/createControls.H +++ /dev/null @@ -1,16 +0,0 @@ -#include "createTimeControls.H" - -bool correctPhi -( - pimple.dict().lookupOrDefault("correctPhi", true) -); - -bool checkMeshCourantNo -( - pimple.dict().lookupOrDefault("checkMeshCourantNo", false) -); - -bool moveMeshOuterCorrectors -( - pimple.dict().lookupOrDefault("moveMeshOuterCorrectors", false) -); diff --git a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/readControls.H b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/readControls.H deleted file mode 100644 index d82dcecb8..000000000 --- a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/readControls.H +++ /dev/null @@ -1,9 +0,0 @@ -#include "readTimeControls.H" - -correctPhi = pimple.dict().lookupOrDefault("correctPhi", true); - -checkMeshCourantNo = - pimple.dict().lookupOrDefault("checkMeshCourantNo", false); - -moveMeshOuterCorrectors = - pimple.dict().lookupOrDefault("moveMeshOuterCorrectors", false); diff --git a/applications/solvers/multiphase/interFoam/interDyMFoam/correctPhi.H b/applications/solvers/multiphase/interFoam/interDyMFoam/correctPhi.H index 0c5ea13bb..fcb502058 100644 --- a/applications/solvers/multiphase/interFoam/interDyMFoam/correctPhi.H +++ b/applications/solvers/multiphase/interFoam/interDyMFoam/correctPhi.H @@ -3,7 +3,7 @@ CorrectPhi U, phi, p_rgh, - surfaceScalarField("rAUf", fvc::interpolate(rAU)), + surfaceScalarField("rAUf", fvc::interpolate(rAU())), geometricZeroField(), pimple ); diff --git a/applications/solvers/multiphase/interFoam/interDyMFoam/createDyMControls.H b/applications/solvers/multiphase/interFoam/interDyMFoam/createDyMControls.H deleted file mode 100644 index 5055ac090..000000000 --- a/applications/solvers/multiphase/interFoam/interDyMFoam/createDyMControls.H +++ /dev/null @@ -1,14 +0,0 @@ -bool correctPhi -( - pimple.dict().lookupOrDefault("correctPhi", true) -); - -bool checkMeshCourantNo -( - pimple.dict().lookupOrDefault("checkMeshCourantNo", false) -); - -bool moveMeshOuterCorrectors -( - pimple.dict().lookupOrDefault("moveMeshOuterCorrectors", false) -); diff --git a/applications/solvers/multiphase/interFoam/interDyMFoam/interDyMFoam.C b/applications/solvers/multiphase/interFoam/interDyMFoam/interDyMFoam.C index f5697b263..d7de40c53 100644 --- a/applications/solvers/multiphase/interFoam/interDyMFoam/interDyMFoam.C +++ b/applications/solvers/multiphase/interFoam/interDyMFoam/interDyMFoam.C @@ -56,28 +56,31 @@ int main(int argc, char *argv[]) #include "createTime.H" #include "createDynamicFvMesh.H" #include "initContinuityErrs.H" - #include "createControl.H" - #include "createTimeControls.H" #include "createDyMControls.H" #include "createFields.H" #include "createAlphaFluxes.H" - volScalarField rAU + tmp rAU; + + if (correctPhi) ( - IOobject + rAU = new volScalarField ( - "rAU", - runTime.timeName(), + IOobject + ( + "rAU", + runTime.timeName(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::AUTO_WRITE + ), mesh, - IOobject::READ_IF_PRESENT, - IOobject::AUTO_WRITE - ), - mesh, - dimensionedScalar("rAUf", dimTime/rho.dimensions(), 1.0) + dimensionedScalar("rAU", dimTime/dimDensity, 1) + ) ); #include "correctPhi.H" - #include "createUf.H" + #include "createUfIfPresent.H" turbulence->validate(); @@ -92,7 +95,7 @@ int main(int argc, char *argv[]) while (runTime.run()) { - #include "readControls.H" + #include "readDyMControls.H" if (LTS) { @@ -114,16 +117,10 @@ int main(int argc, char *argv[]) { if (pimple.firstIter() || moveMeshOuterCorrectors) { - scalar timeBeforeMeshUpdate = runTime.elapsedCpuTime(); - mesh.update(); if (mesh.changing()) { - Info<< "Execution time for mesh.update() = " - << runTime.elapsedCpuTime() - timeBeforeMeshUpdate - << " s" << endl; - // Do not apply previous time-step mesh compression flux // if the mesh topology changed if (mesh.topoChanging()) @@ -140,7 +137,7 @@ int main(int argc, char *argv[]) { // Calculate absolute flux // from the mapped surface velocity - phi = mesh.Sf() & Uf; + phi = mesh.Sf() & Uf(); #include "correctPhi.H" diff --git a/applications/solvers/multiphase/interFoam/interDyMFoam/pEqn.H b/applications/solvers/multiphase/interFoam/interDyMFoam/pEqn.H index aafc10bcc..8e60ede0d 100644 --- a/applications/solvers/multiphase/interFoam/interDyMFoam/pEqn.H +++ b/applications/solvers/multiphase/interFoam/interDyMFoam/pEqn.H @@ -1,12 +1,12 @@ { rAU = 1.0/UEqn.A(); - surfaceScalarField rAUf("rAUf", fvc::interpolate(rAU)); - volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p_rgh)); + surfaceScalarField rAUf("rAUf", fvc::interpolate(rAU())); + volVectorField HbyA(constrainHbyA(rAU()*UEqn.H(), U, p_rgh)); surfaceScalarField phiHbyA ( "phiHbyA", fvc::flux(HbyA) - + fvc::interpolate(rho*rAU)*fvc::ddtCorr(U, Uf) + + fvc::interpolate(rho*rAU())*fvc::ddtCorr(U, phi, Uf) ); MRF.makeRelative(phiHbyA); @@ -47,7 +47,7 @@ p_rgh.relax(); - U = HbyA + rAU*fvc::reconstruct((phig - p_rghEqn.flux())/rAUf); + U = HbyA + rAU()*fvc::reconstruct((phig - p_rghEqn.flux())/rAUf); U.correctBoundaryConditions(); fvOptions.correct(U); } @@ -55,11 +55,8 @@ #include "continuityErrs.H" - { - Uf = fvc::interpolate(U); - surfaceVectorField n(mesh.Sf()/mesh.magSf()); - Uf += n*(phi/mesh.magSf() - (n & Uf)); - } + // Correct Uf if the mesh is moving + fvc::correctUf(Uf, U, phi); // Make the fluxes relative to the mesh motion fvc::makeRelative(phi, U); @@ -76,4 +73,9 @@ ); p_rgh = p - rho*gh; } + + if (!correctPhi) + { + rAU.clear(); + } } diff --git a/applications/solvers/multiphase/interFoam/interDyMFoam/readControls.H b/applications/solvers/multiphase/interFoam/interDyMFoam/readControls.H deleted file mode 100644 index d82dcecb8..000000000 --- a/applications/solvers/multiphase/interFoam/interDyMFoam/readControls.H +++ /dev/null @@ -1,9 +0,0 @@ -#include "readTimeControls.H" - -correctPhi = pimple.dict().lookupOrDefault("correctPhi", true); - -checkMeshCourantNo = - pimple.dict().lookupOrDefault("checkMeshCourantNo", false); - -moveMeshOuterCorrectors = - pimple.dict().lookupOrDefault("moveMeshOuterCorrectors", false); diff --git a/applications/solvers/multiphase/interPhaseChangeFoam/interPhaseChangeDyMFoam/interPhaseChangeDyMFoam.C b/applications/solvers/multiphase/interPhaseChangeFoam/interPhaseChangeDyMFoam/interPhaseChangeDyMFoam.C index eb8d8816a..3d7bf2f54 100644 --- a/applications/solvers/multiphase/interPhaseChangeFoam/interPhaseChangeDyMFoam/interPhaseChangeDyMFoam.C +++ b/applications/solvers/multiphase/interPhaseChangeFoam/interPhaseChangeDyMFoam/interPhaseChangeDyMFoam.C @@ -61,9 +61,7 @@ int main(int argc, char *argv[]) #include "setRootCase.H" #include "createTime.H" #include "createDynamicFvMesh.H" - #include "createControl.H" - #include "createTimeControls.H" - #include "../interFoam/interDyMFoam/createDyMControls.H" + #include "createDyMControls.H" #include "initContinuityErrs.H" #include "createFields.H" @@ -93,7 +91,7 @@ int main(int argc, char *argv[]) while (runTime.run()) { - #include "../interFoam/interDyMFoam/readControls.H" + #include "readDyMControls.H" // Store divU from the previous mesh so that it can be mapped // and used in correctPhi to ensure the corrected phi has the diff --git a/applications/solvers/multiphase/multiphaseInterFoam/multiphaseInterDyMFoam/multiphaseInterDyMFoam.C b/applications/solvers/multiphase/multiphaseInterFoam/multiphaseInterDyMFoam/multiphaseInterDyMFoam.C index 467bfea93..b10f0ba38 100644 --- a/applications/solvers/multiphase/multiphaseInterFoam/multiphaseInterDyMFoam/multiphaseInterDyMFoam.C +++ b/applications/solvers/multiphase/multiphaseInterFoam/multiphaseInterDyMFoam/multiphaseInterDyMFoam.C @@ -51,27 +51,31 @@ int main(int argc, char *argv[]) #include "createTime.H" #include "createDynamicFvMesh.H" #include "initContinuityErrs.H" - #include "createControl.H" - #include "createTimeControls.H" #include "createDyMControls.H" #include "createFields.H" - volScalarField rAU + tmp rAU; + + if (correctPhi) ( - IOobject + rAU = new volScalarField ( - "rAU", - runTime.timeName(), + IOobject + ( + "rAU", + runTime.timeName(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::AUTO_WRITE + ), mesh, - IOobject::READ_IF_PRESENT, - IOobject::AUTO_WRITE - ), - mesh, - dimensionedScalar("rAUf", dimTime/rho.dimensions(), 1.0) + dimensionedScalar("rAU", dimTime/dimDensity, 1) + ) ); #include "correctPhi.H" - #include "createUf.H" + #include "createUfIfPresent.H" + #include "CourantNo.H" #include "setInitialDeltaT.H" @@ -85,7 +89,7 @@ int main(int argc, char *argv[]) while (runTime.run()) { - #include "readControls.H" + #include "readDyMControls.H" #include "CourantNo.H" #include "alphaCourantNo.H" @@ -117,7 +121,7 @@ int main(int argc, char *argv[]) if (mesh.changing() && correctPhi) { // Calculate absolute flux from the mapped surface velocity - phi = mesh.Sf() & Uf; + phi = mesh.Sf() & Uf(); #include "correctPhi.H" diff --git a/applications/solvers/multiphase/potentialFreeSurfaceFoam/potentialFreeSurfaceDyMFoam/potentialFreeSurfaceDyMFoam.C b/applications/solvers/multiphase/potentialFreeSurfaceFoam/potentialFreeSurfaceDyMFoam/potentialFreeSurfaceDyMFoam.C index b30b95817..70113ade7 100644 --- a/applications/solvers/multiphase/potentialFreeSurfaceFoam/potentialFreeSurfaceDyMFoam/potentialFreeSurfaceDyMFoam.C +++ b/applications/solvers/multiphase/potentialFreeSurfaceFoam/potentialFreeSurfaceDyMFoam/potentialFreeSurfaceDyMFoam.C @@ -56,8 +56,6 @@ int main(int argc, char *argv[]) #include "createTime.H" #include "createDynamicFvMesh.H" #include "initContinuityErrs.H" - #include "createControl.H" - #include "createTimeControls.H" #include "createDyMControls.H" #include "createFields.H" @@ -86,7 +84,7 @@ int main(int argc, char *argv[]) while (runTime.run()) { - #include "readControls.H" + #include "readDyMControls.H" #include "CourantNo.H" #include "setDeltaT.H" diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.H b/src/OpenFOAM/meshes/polyMesh/polyMesh.H index 00ff5aa2f..64cc48631 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.H @@ -493,6 +493,12 @@ public: // Mesh motion + //- Is mesh dynamic + virtual bool dynamic() const + { + return false; + } + //- Is mesh moving bool moving() const { diff --git a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.H b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.H index d7e71308b..92d0598be 100644 --- a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.H +++ b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.H @@ -121,6 +121,12 @@ public: // Member Functions + //- Is mesh dynamic + virtual bool dynamic() const + { + return true; + } + //- Update the mesh for both mesh motion and topology change virtual bool update() = 0; }; @@ -131,10 +137,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#include "staticFvMesh.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C index 0a18a49e5..10fc73e15 100644 --- a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C +++ b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C @@ -23,7 +23,7 @@ License \*---------------------------------------------------------------------------*/ -#include "dynamicFvMesh.H" +#include "staticFvMesh.H" // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // diff --git a/applications/solvers/incompressible/pimpleFoam/createControls.H b/src/dynamicFvMesh/include/createDyMControls.H similarity index 51% rename from applications/solvers/incompressible/pimpleFoam/createControls.H rename to src/dynamicFvMesh/include/createDyMControls.H index bee8bd4f3..193604f19 100644 --- a/applications/solvers/incompressible/pimpleFoam/createControls.H +++ b/src/dynamicFvMesh/include/createDyMControls.H @@ -3,10 +3,15 @@ bool correctPhi ( - pimple.dict().lookupOrDefault("correctPhi", false) + pimple.dict().lookupOrDefault("correctPhi", mesh.dynamic()) ); bool checkMeshCourantNo ( pimple.dict().lookupOrDefault("checkMeshCourantNo", false) ); + +bool moveMeshOuterCorrectors +( + pimple.dict().lookupOrDefault("moveMeshOuterCorrectors", false) +); diff --git a/src/dynamicFvMesh/include/readDyMControls.H b/src/dynamicFvMesh/include/readDyMControls.H new file mode 100644 index 000000000..1f96bedb3 --- /dev/null +++ b/src/dynamicFvMesh/include/readDyMControls.H @@ -0,0 +1,19 @@ +#include "readTimeControls.H" + +correctPhi = pimple.dict().lookupOrDefault +( + "correctPhi", + correctPhi +); + +checkMeshCourantNo = pimple.dict().lookupOrDefault +( + "checkMeshCourantNo", + checkMeshCourantNo +); + +moveMeshOuterCorrectors = pimple.dict().lookupOrDefault +( + "moveMeshOuterCorrectors", + moveMeshOuterCorrectors +); diff --git a/src/dynamicFvMesh/staticFvMesh/staticFvMesh.H b/src/dynamicFvMesh/staticFvMesh/staticFvMesh.H index bbbf1201b..942a350c3 100644 --- a/src/dynamicFvMesh/staticFvMesh/staticFvMesh.H +++ b/src/dynamicFvMesh/staticFvMesh/staticFvMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -77,6 +77,12 @@ public: // Member Functions + //- Is mesh dynamic + virtual bool dynamic() const + { + return false; + } + //- Dummy update function which does not change the mesh virtual bool update(); }; diff --git a/src/finiteVolume/cfdTools/compressible/createRhoUfIfPresent.H b/src/finiteVolume/cfdTools/compressible/createRhoUfIfPresent.H index 0c22396db..38445c3e2 100644 --- a/src/finiteVolume/cfdTools/compressible/createRhoUfIfPresent.H +++ b/src/finiteVolume/cfdTools/compressible/createRhoUfIfPresent.H @@ -25,7 +25,7 @@ Global createRhoUf Description - Creates and initialises the velocity field rhoUf if present. + Creates and initialises the velocity field rhoUf if required. \*---------------------------------------------------------------------------*/ @@ -33,19 +33,22 @@ Description autoPtr rhoUf; -IOobject rhoUfHeader -( - "rhoUf", - runTime.timeName(), - mesh, - IOobject::MUST_READ, - IOobject::AUTO_WRITE -); - -if (rhoUfHeader.typeHeaderOk(true)) +if (mesh.dynamic()) { - Info<< "Reading face momentum rhoUf\n" << endl; - rhoUf = new surfaceVectorField(rhoUfHeader, mesh); + Info<< "Constructing face momentum rhoUf" << endl; + + rhoUf = new surfaceVectorField + ( + IOobject + ( + "rhoUf", + runTime.timeName(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::AUTO_WRITE + ), + fvc::interpolate(rho*U) + ); } // ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/compressible/updateRhoUf.H b/src/finiteVolume/cfdTools/compressible/updateRhoUf.H index e3695732a..8a340b1a4 100644 --- a/src/finiteVolume/cfdTools/compressible/updateRhoUf.H +++ b/src/finiteVolume/cfdTools/compressible/updateRhoUf.H @@ -31,25 +31,6 @@ Description // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -if (mesh.changing()) -{ - if (!rhoUf.valid()) - { - Info<< "Constructing face momentum rhoUf" << endl; - - rhoUf = new surfaceVectorField - ( - IOobject - ( - "rhoUf", - runTime.timeName(), - mesh, - IOobject::READ_IF_PRESENT, - IOobject::AUTO_WRITE - ), - fvc::interpolate(rho*U) - ); - } -} +#error Remove rhoUpdateUf.H // ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/incompressible/createUfIfPresent.H b/src/finiteVolume/cfdTools/incompressible/createUfIfPresent.H index 79e6619ee..e19515ec8 100644 --- a/src/finiteVolume/cfdTools/incompressible/createUfIfPresent.H +++ b/src/finiteVolume/cfdTools/incompressible/createUfIfPresent.H @@ -25,7 +25,7 @@ Global createUf Description - Creates and initialises the velocity field Uf if present. + Creates and initialises the velocity field Uf if required. \*---------------------------------------------------------------------------*/ @@ -33,19 +33,22 @@ Description autoPtr Uf; -IOobject UfHeader -( - "Uf", - runTime.timeName(), - mesh, - IOobject::MUST_READ, - IOobject::AUTO_WRITE -); - -if (UfHeader.typeHeaderOk(true)) +if (mesh.dynamic()) { - Info<< "Reading face velocity Uf\n" << endl; - Uf = new surfaceVectorField(UfHeader, mesh); + Info<< "Constructing face velocity Uf\n" << endl; + + Uf = new surfaceVectorField + ( + IOobject + ( + "Uf", + runTime.timeName(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::AUTO_WRITE + ), + fvc::interpolate(U) + ); } // ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/incompressible/updateUf.H b/src/finiteVolume/cfdTools/incompressible/updateUf.H index e2cb0b90b..373d6cd82 100644 --- a/src/finiteVolume/cfdTools/incompressible/updateUf.H +++ b/src/finiteVolume/cfdTools/incompressible/updateUf.H @@ -31,25 +31,6 @@ Description // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -if (mesh.changing()) -{ - if (!Uf.valid()) - { - Info<< "Constructing face velocity Uf" << endl; - - Uf = new surfaceVectorField - ( - IOobject - ( - "Uf", - runTime.timeName(), - mesh, - IOobject::READ_IF_PRESENT, - IOobject::AUTO_WRITE - ), - fvc::interpolate(U) - ); - } -} +#error Remove updateUf.H // ************************************************************************* // diff --git a/src/finiteVolume/finiteVolume/fvc/fvcDdt.C b/src/finiteVolume/finiteVolume/fvc/fvcDdt.C index b83ffbfe5..b85c6b9a1 100644 --- a/src/finiteVolume/finiteVolume/fvc/fvcDdt.C +++ b/src/finiteVolume/finiteVolume/fvc/fvcDdt.C @@ -215,7 +215,7 @@ ddtCorr const autoPtr>& Uf ) { - if (U.mesh().changing()) + if (U.mesh().dynamic()) { return ddtCorr(U, Uf()); } @@ -280,7 +280,7 @@ ddtCorr const autoPtr>& Uf ) { - if (U.mesh().changing()) + if (U.mesh().dynamic()) { return ddtCorr(rho, U, Uf()); } diff --git a/src/finiteVolume/finiteVolume/fvc/fvcMeshPhi.C b/src/finiteVolume/finiteVolume/fvc/fvcMeshPhi.C index c082e54ec..287bbcfdb 100644 --- a/src/finiteVolume/finiteVolume/fvc/fvcMeshPhi.C +++ b/src/finiteVolume/finiteVolume/fvc/fvcMeshPhi.C @@ -228,7 +228,7 @@ void Foam::fvc::correctUf { const fvMesh& mesh = U.mesh(); - if (mesh.changing()) + if (mesh.dynamic()) { Uf() = fvc::interpolate(U); surfaceVectorField n(mesh.Sf()/mesh.magSf()); @@ -247,7 +247,7 @@ void Foam::fvc::correctRhoUf { const fvMesh& mesh = U.mesh(); - if (mesh.changing()) + if (mesh.dynamic()) { rhoUf() = fvc::interpolate(rho*U); surfaceVectorField n(mesh.Sf()/mesh.magSf()); diff --git a/tutorials/multiphase/interDyMFoam/laminar/damBreakWithObstacle/constant/dynamicMeshDict b/tutorials/multiphase/interDyMFoam/laminar/damBreakWithObstacle/constant/dynamicMeshDict index 6ea2c2030..577130323 100644 --- a/tutorials/multiphase/interDyMFoam/laminar/damBreakWithObstacle/constant/dynamicMeshDict +++ b/tutorials/multiphase/interDyMFoam/laminar/damBreakWithObstacle/constant/dynamicMeshDict @@ -47,7 +47,7 @@ correctFluxes (phi none) (nHatf none) (rhoPhi none) - (alphaPhi none) + (alphaPhi0.water none) (ghf none) );