From c57fe2b5fdb67b82b4038e0e773174ae99bcf23e Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 18 Aug 2017 22:22:47 +0100 Subject: [PATCH] MRF: Added support for mesh refinement/unrefinement and other topology changes --- .../rhoPimpleDyMFoam/rhoPimpleDyMFoam.C | 27 ++-- .../sonicFoam/sonicDyMFoam/sonicDyMFoam.C | 27 ++-- .../pimpleFoam/pimpleDyMFoam/pimpleDyMFoam.C | 27 ++-- .../sprayFoam/sprayDyMFoam/sprayDyMFoam.C | 27 ++-- .../compressibleInterDyMFoam.C | 30 ++-- .../interFoam/interDyMFoam/interDyMFoam.C | 29 ++-- .../potentialFreeSurfaceDyMFoam.C | 29 ++-- .../cfdTools/general/MRF/MRFZone.C | 11 +- .../cfdTools/general/MRF/MRFZone.H | 130 +++++++++--------- .../cfdTools/general/MRF/MRFZoneList.C | 14 +- .../cfdTools/general/MRF/MRFZoneList.H | 9 +- 11 files changed, 205 insertions(+), 155 deletions(-) diff --git a/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleDyMFoam/rhoPimpleDyMFoam.C b/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleDyMFoam/rhoPimpleDyMFoam.C index 1d20c3f10..24fa208d4 100644 --- a/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleDyMFoam/rhoPimpleDyMFoam.C +++ b/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleDyMFoam/rhoPimpleDyMFoam.C @@ -108,23 +108,28 @@ int main(int argc, char *argv[]) // Do any mesh changes mesh.update(); - if (mesh.changing() && correctPhi) + if (mesh.changing()) { - // Calculate absolute flux from the mapped surface velocity - phi = mesh.Sf() & rhoUf; + MRF.update(); - #include "correctPhi.H" + if (correctPhi) + { + // Calculate absolute flux from the mapped surface velocity + phi = mesh.Sf() & rhoUf; - // Make the fluxes relative to the mesh-motion - fvc::makeRelative(phi, rho, U); + #include "correctPhi.H" + + // Make the fluxes relative to the mesh-motion + fvc::makeRelative(phi, rho, U); + } + + if (checkMeshCourantNo) + { + #include "meshCourantNo.H" + } } } - if (mesh.changing() && checkMeshCourantNo) - { - #include "meshCourantNo.H" - } - #include "rhoEqn.H" Info<< "rhoEqn max/min : " << max(rho).value() << " " << min(rho).value() << endl; diff --git a/applications/solvers/compressible/sonicFoam/sonicDyMFoam/sonicDyMFoam.C b/applications/solvers/compressible/sonicFoam/sonicDyMFoam/sonicDyMFoam.C index 31b0a6e61..63feefddd 100644 --- a/applications/solvers/compressible/sonicFoam/sonicDyMFoam/sonicDyMFoam.C +++ b/applications/solvers/compressible/sonicFoam/sonicDyMFoam/sonicDyMFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -93,21 +93,26 @@ int main(int argc, char *argv[]) // Do any mesh changes mesh.update(); - if (mesh.changing() && correctPhi) + if (mesh.changing()) { - // Calculate absolute flux from the mapped surface velocity - phi = mesh.Sf() & rhoUf; + MRF.update(); - #include "correctPhi.H" + if (correctPhi) + { + // Calculate absolute flux from the mapped surface velocity + phi = mesh.Sf() & rhoUf; - // Make the fluxes relative to the mesh-motion - fvc::makeRelative(phi, rho, U); + #include "correctPhi.H" + + // Make the fluxes relative to the mesh-motion + fvc::makeRelative(phi, rho, U); + } } - } - if (mesh.changing() && checkMeshCourantNo) - { - #include "meshCourantNo.H" + if (checkMeshCourantNo) + { + #include "meshCourantNo.H" + } } #include "rhoEqn.H" diff --git a/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pimpleDyMFoam.C b/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pimpleDyMFoam.C index f5e6a0e0c..e1810d05d 100644 --- a/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pimpleDyMFoam.C +++ b/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pimpleDyMFoam.C @@ -75,20 +75,25 @@ int main(int argc, char *argv[]) mesh.update(); - // Calculate absolute flux from the mapped surface velocity - phi = mesh.Sf() & Uf; - - if (mesh.changing() && correctPhi) + if (mesh.changing()) { - #include "correctPhi.H" - } + MRF.update(); - // Make the flux relative to the mesh motion - fvc::makeRelative(phi, U); + if (correctPhi) + { + // Calculate absolute flux from the mapped surface velocity + phi = mesh.Sf() & Uf; - if (mesh.changing() && checkMeshCourantNo) - { - #include "meshCourantNo.H" + #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 diff --git a/applications/solvers/lagrangian/sprayFoam/sprayDyMFoam/sprayDyMFoam.C b/applications/solvers/lagrangian/sprayFoam/sprayDyMFoam/sprayDyMFoam.C index 0b6d880f3..7796e4de8 100644 --- a/applications/solvers/lagrangian/sprayFoam/sprayDyMFoam/sprayDyMFoam.C +++ b/applications/solvers/lagrangian/sprayFoam/sprayDyMFoam/sprayDyMFoam.C @@ -94,23 +94,28 @@ int main(int argc, char *argv[]) // Do any mesh changes mesh.update(); - if (mesh.changing() && correctPhi) + if (mesh.changing()) { - // Calculate absolute flux from the mapped surface velocity - phi = mesh.Sf() & rhoUf; + MRF.update(); - #include "correctPhi.H" + if (correctPhi) + { + // Calculate absolute flux from the mapped surface velocity + phi = mesh.Sf() & rhoUf; - // Make the fluxes relative to the mesh-motion - fvc::makeRelative(phi, rho, U); + #include "correctPhi.H" + + // Make the fluxes relative to the mesh-motion + fvc::makeRelative(phi, rho, U); + } + + if (checkMeshCourantNo) + { + #include "meshCourantNo.H" + } } } - if (mesh.changing() && checkMeshCourantNo) - { - #include "meshCourantNo.H" - } - parcels.evolve(); #include "rhoEqn.H" diff --git a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/compressibleInterDyMFoam.C b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/compressibleInterDyMFoam.C index 52cb3c92e..e2fa94c74 100644 --- a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/compressibleInterDyMFoam.C +++ b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/compressibleInterDyMFoam.C @@ -116,30 +116,34 @@ int main(int argc, char *argv[]) if (mesh.changing()) { + + MRF.update(); + Info<< "Execution time for mesh.update() = " << runTime.elapsedCpuTime() - timeBeforeMeshUpdate << " s" << endl; gh = (g & mesh.C()) - ghRef; ghf = (g & mesh.Cf()) - ghRef; - } - if (mesh.changing() && correctPhi) - { - // Calculate absolute flux from the mapped surface velocity - phi = mesh.Sf() & Uf; + if (correctPhi) + { + // Calculate absolute flux + // from the mapped surface velocity + phi = mesh.Sf() & Uf; - #include "correctPhi.H" + #include "correctPhi.H" - // Make the fluxes relative to the mesh motion - fvc::makeRelative(phi, U); + // Make the fluxes relative to the mesh motion + fvc::makeRelative(phi, U); - mixture.correct(); - } + mixture.correct(); + } - if (mesh.changing() && checkMeshCourantNo) - { - #include "meshCourantNo.H" + if (checkMeshCourantNo) + { + #include "meshCourantNo.H" + } } } diff --git a/applications/solvers/multiphase/interFoam/interDyMFoam/interDyMFoam.C b/applications/solvers/multiphase/interFoam/interDyMFoam/interDyMFoam.C index b8cab61e4..d21390ce5 100644 --- a/applications/solvers/multiphase/interFoam/interDyMFoam/interDyMFoam.C +++ b/applications/solvers/multiphase/interFoam/interDyMFoam/interDyMFoam.C @@ -134,24 +134,27 @@ int main(int argc, char *argv[]) gh = (g & mesh.C()) - ghRef; ghf = (g & mesh.Cf()) - ghRef; - } - if (mesh.changing() && correctPhi) - { - // Calculate absolute flux from the mapped surface velocity - phi = mesh.Sf() & Uf; + MRF.update(); - #include "correctPhi.H" + if (correctPhi) + { + // Calculate absolute flux + // from the mapped surface velocity + phi = mesh.Sf() & Uf; - // Make the flux relative to the mesh motion - fvc::makeRelative(phi, U); + #include "correctPhi.H" - mixture.correct(); - } + // Make the flux relative to the mesh motion + fvc::makeRelative(phi, U); - if (mesh.changing() && checkMeshCourantNo) - { - #include "meshCourantNo.H" + mixture.correct(); + } + + if (checkMeshCourantNo) + { + #include "meshCourantNo.H" + } } } diff --git a/applications/solvers/multiphase/potentialFreeSurfaceFoam/potentialFreeSurfaceDyMFoam/potentialFreeSurfaceDyMFoam.C b/applications/solvers/multiphase/potentialFreeSurfaceFoam/potentialFreeSurfaceDyMFoam/potentialFreeSurfaceDyMFoam.C index e89ca8ab7..137d728c2 100644 --- a/applications/solvers/multiphase/potentialFreeSurfaceFoam/potentialFreeSurfaceDyMFoam/potentialFreeSurfaceDyMFoam.C +++ b/applications/solvers/multiphase/potentialFreeSurfaceFoam/potentialFreeSurfaceDyMFoam/potentialFreeSurfaceDyMFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2014-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -109,22 +109,25 @@ int main(int argc, char *argv[]) Info<< "Execution time for mesh.update() = " << runTime.elapsedCpuTime() - timeBeforeMeshUpdate << " s" << endl; - } - if (mesh.changing() && correctPhi) - { - // Calculate absolute flux from the mapped surface velocity - phi = mesh.Sf() & Uf; + MRF.update(); - #include "correctPhi.H" + if (correctPhi) + { + // Calculate absolute flux + // from the mapped surface velocity + phi = mesh.Sf() & Uf; - // Make the flux relative to the mesh motion - fvc::makeRelative(phi, U); - } + #include "correctPhi.H" - if (mesh.changing() && checkMeshCourantNo) - { - #include "meshCourantNo.H" + // Make the flux relative to the mesh motion + fvc::makeRelative(phi, U); + } + + if (checkMeshCourantNo) + { + #include "meshCourantNo.H" + } } } diff --git a/src/finiteVolume/cfdTools/general/MRF/MRFZone.C b/src/finiteVolume/cfdTools/general/MRF/MRFZone.C index b1f64847c..93f1c2efa 100644 --- a/src/finiteVolume/cfdTools/general/MRF/MRFZone.C +++ b/src/finiteVolume/cfdTools/general/MRF/MRFZone.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -601,4 +601,13 @@ bool Foam::MRFZone::read(const dictionary& dict) } +void Foam::MRFZone::update() +{ + if (mesh_.topoChanging()) + { + setMRFFaces(); + } +} + + // ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/MRF/MRFZone.H b/src/finiteVolume/cfdTools/general/MRF/MRFZone.H index 0bcbcfd93..9f5d8a723 100644 --- a/src/finiteVolume/cfdTools/general/MRF/MRFZone.H +++ b/src/finiteVolume/cfdTools/general/MRF/MRFZone.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -180,87 +180,85 @@ public: // Member Functions - // Access + //- Return const access to the MRF region name + inline const word& name() const; - //- Return const access to the MRF region name - inline const word& name() const; + //- Return const access to the MRF active flag + inline bool active() const; - //- Return const access to the MRF active flag - inline bool active() const; + //- Return the current Omega vector + vector Omega() const; - //- Return the current Omega vector - vector Omega() const; + //- Update the mesh corresponding to given map + void updateMesh(const mapPolyMesh& mpm) + { + // Only updates face addressing + setMRFFaces(); + } + //- Add the Coriolis force contribution to the acceleration field + void addCoriolis + ( + const volVectorField& U, + volVectorField& ddtU + ) const; - // Evaluation + //- Add the Coriolis force contribution to the momentum equation + // Adds to the lhs of the equation; optionally add to rhs + void addCoriolis + ( + fvVectorMatrix& UEqn, + const bool rhs = false + ) const; - //- Update the mesh corresponding to given map - void updateMesh(const mapPolyMesh& mpm) - { - // Only updates face addressing - setMRFFaces(); - } + //- Add the Coriolis force contribution to the momentum equation + // Adds to the lhs of the equation; optionally add to rhs + void addCoriolis + ( + const volScalarField& rho, + fvVectorMatrix& UEqn, + const bool rhs = false + ) const; - //- Add the Coriolis force contribution to the acceleration field - void addCoriolis - ( - const volVectorField& U, - volVectorField& ddtU - ) const; + //- Make the given absolute velocity relative within the MRF region + void makeRelative(volVectorField& U) const; - //- Add the Coriolis force contribution to the momentum equation - // Adds to the lhs of the equation; optionally add to rhs - void addCoriolis - ( - fvVectorMatrix& UEqn, - const bool rhs = false - ) const; + //- Make the given absolute flux relative within the MRF region + void makeRelative(surfaceScalarField& phi) const; - //- Add the Coriolis force contribution to the momentum equation - // Adds to the lhs of the equation; optionally add to rhs - void addCoriolis - ( - const volScalarField& rho, - fvVectorMatrix& UEqn, - const bool rhs = false - ) const; + //- Make the given absolute boundary flux relative + // within the MRF region + void makeRelative(FieldField& phi) const; - //- Make the given absolute velocity relative within the MRF region - void makeRelative(volVectorField& U) const; + //- Make the given absolute patch flux relative + // within the MRF region + void makeRelative(Field& phi, const label patchi) const; - //- Make the given absolute flux relative within the MRF region - void makeRelative(surfaceScalarField& phi) const; + //- Make the given absolute mass-flux relative within the MRF region + void makeRelative + ( + const surfaceScalarField& rho, + surfaceScalarField& phi + ) const; - //- Make the given absolute boundary flux relative - // within the MRF region - void makeRelative(FieldField& phi) const; + //- Make the given relative velocity absolute within the MRF region + void makeAbsolute(volVectorField& U) const; - //- Make the given absolute patch flux relative - // within the MRF region - void makeRelative(Field& phi, const label patchi) const; + //- Make the given relative flux absolute within the MRF region + void makeAbsolute(surfaceScalarField& phi) const; - //- Make the given absolute mass-flux relative within the MRF region - void makeRelative - ( - const surfaceScalarField& rho, - surfaceScalarField& phi - ) const; + //- Make the given relative mass-flux absolute within the MRF region + void makeAbsolute + ( + const surfaceScalarField& rho, + surfaceScalarField& phi + ) const; - //- Make the given relative velocity absolute within the MRF region - void makeAbsolute(volVectorField& U) const; + //- Correct the boundary velocity for the rotation of the MRF region + void correctBoundaryVelocity(volVectorField& U) const; - //- Make the given relative flux absolute within the MRF region - void makeAbsolute(surfaceScalarField& phi) const; - - //- Make the given relative mass-flux absolute within the MRF region - void makeAbsolute - ( - const surfaceScalarField& rho, - surfaceScalarField& phi - ) const; - - //- Correct the boundary velocity for the rotation of the MRF region - void correctBoundaryVelocity(volVectorField& U) const; + //- Update MRFZone faces if the mesh topology changes + void update(); // I-O diff --git a/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.C b/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.C index 93fe6728b..d09e4d409 100644 --- a/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.C +++ b/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.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 @@ -414,6 +414,18 @@ void Foam::MRFZoneList::correctBoundaryFlux } +void Foam::MRFZoneList::update() +{ + if (mesh_.topoChanging()) + { + forAll(*this, i) + { + operator[](i).update(); + } + } +} + + // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // Foam::Ostream& Foam::operator<< diff --git a/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.H b/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.H index fb36e689e..4c0fffbe2 100644 --- a/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.H +++ b/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.H @@ -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 @@ -55,10 +55,8 @@ Ostream& operator<<(Ostream& os, const MRFZoneList& models); class MRFZoneList : - PtrList + public PtrList { -private: - // Private Member Functions //- Disallow default bitwise copy construct @@ -186,6 +184,9 @@ public: surfaceScalarField& phi ) const; + //- Update MRFZone faces if the mesh topology changes + void update(); + // I-O