diff --git a/applications/solvers/incompressible/pimpleFoam/pEqn.H b/applications/solvers/incompressible/pimpleFoam/pEqn.H index c8d02ed281..1c3eb66259 100644 --- a/applications/solvers/incompressible/pimpleFoam/pEqn.H +++ b/applications/solvers/incompressible/pimpleFoam/pEqn.H @@ -53,6 +53,6 @@ while (pimple.correctNonOrthogonal()) // Explicitly relax pressure for momentum corrector p.relax(); -U = HbyA - rAtU()*fvc::grad(p); +U = HbyA - rAtU*fvc::grad(p); U.correctBoundaryConditions(); fvOptions.correct(U); diff --git a/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/createUf.H b/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/createUf.H new file mode 100644 index 0000000000..523a04b502 --- /dev/null +++ b/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/createUf.H @@ -0,0 +1,51 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Global + createUf + +Description + Creates and initialises the velocity field Uf if present. + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +autoPtr UfPtr; + +IOobject UfHeader +( + "Uf", + runTime.timeName(), + mesh, + IOobject::MUST_READ, + IOobject::AUTO_WRITE +); + +if (UfHeader.typeHeaderOk(true)) +{ + Info<< "Reading face velocity Uf\n" << endl; + UfPtr = new surfaceVectorField(UfHeader, mesh); +} + +// ************************************************************************* // diff --git a/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pEqn.H b/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pEqn.H index a53391a90b..df19741c50 100644 --- a/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pEqn.H +++ b/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pEqn.H @@ -4,7 +4,7 @@ surfaceScalarField phiHbyA ( "phiHbyA", fvc::flux(HbyA) - + fvc::interpolate(rAU)*fvc::ddtCorr(U, Uf) + + fvc::interpolate(rAU)*fvc::ddtCorr(U, phi, Uf) ); MRF.makeRelative(phiHbyA); @@ -61,11 +61,8 @@ U = HbyA - rAtU*fvc::grad(p); U.correctBoundaryConditions(); fvOptions.correct(U); -{ - 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); diff --git a/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pimpleDyMFoam.C b/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pimpleDyMFoam.C index d016fb18e7..468c017380 100644 --- a/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pimpleDyMFoam.C +++ b/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pimpleDyMFoam.C @@ -74,6 +74,8 @@ int main(int argc, char *argv[]) mesh.update(); + #include "updateUf.H" + if (mesh.changing()) { MRF.update(); diff --git a/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/updateUf.H b/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/updateUf.H new file mode 100644 index 0000000000..a38c30ac9b --- /dev/null +++ b/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/updateUf.H @@ -0,0 +1,57 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Global + updateUf + +Description + Constructs the velocity field Uf if not already constructed. + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +if (mesh.changing()) +{ + if (!UfPtr.valid()) + { + Info<< "Constructing face velocity Uf" << endl; + + UfPtr = new surfaceVectorField + ( + IOobject + ( + "Uf", + runTime.timeName(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::AUTO_WRITE + ), + fvc::interpolate(U) + ); + } +} + +surfaceVectorField& Uf = *UfPtr; + +// ************************************************************************* // diff --git a/src/OpenFOAM/memory/autoPtr/autoPtr.H b/src/OpenFOAM/memory/autoPtr/autoPtr.H index 76afd531c0..5b76c18114 100644 --- a/src/OpenFOAM/memory/autoPtr/autoPtr.H +++ b/src/OpenFOAM/memory/autoPtr/autoPtr.H @@ -116,6 +116,12 @@ public: //- Return const reference to the object data inline const T& operator()() const; + //- Return reference to the object data + inline T& operator*(); + + //- Return const reference to the object data + inline const T& operator*() const; + //- Const cast to the underlying type reference inline operator const T&() const; diff --git a/src/OpenFOAM/memory/autoPtr/autoPtrI.H b/src/OpenFOAM/memory/autoPtr/autoPtrI.H index 7eaa605a8f..7f07ccc188 100644 --- a/src/OpenFOAM/memory/autoPtr/autoPtrI.H +++ b/src/OpenFOAM/memory/autoPtr/autoPtrI.H @@ -161,6 +161,36 @@ inline const T& Foam::autoPtr::operator()() const } +template +inline T& Foam::autoPtr::operator*() +{ + if (!ptr_) + { + FatalErrorInFunction + << "object of type " << typeid(T).name() + << " is not allocated" + << abort(FatalError); + } + + return *ptr_; +} + + +template +inline const T& Foam::autoPtr::operator*() const +{ + if (!ptr_) + { + FatalErrorInFunction + << "object of type " << typeid(T).name() + << " is not allocated" + << abort(FatalError); + } + + return *ptr_; +} + + template inline Foam::autoPtr::operator const T&() const { diff --git a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.H b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.H index 6447ba5240..56dc4be0d1 100644 --- a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.H +++ b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.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 @@ -37,8 +37,6 @@ SourceFiles #define dynamicFvMesh_H #include "fvMesh.H" -#include "autoPtr.H" -#include "runTimeSelectionTables.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -111,7 +109,9 @@ public: // Selectors - //- Select null constructed + //- Select, construct and return the dynamicFvMesh + // If the constant/dynamicMeshDict does not exist + // a staticFvMesh is returned static autoPtr New(const IOobject& io); diff --git a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C index fa05cc2a59..10fc73e15e 100644 --- a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C +++ b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,9 +23,7 @@ License \*---------------------------------------------------------------------------*/ -#include "dynamicFvMesh.H" -#include "Time.H" -#include "dlLibraryTable.H" +#include "staticFvMesh.H" // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // @@ -36,52 +34,58 @@ Foam::autoPtr Foam::dynamicFvMesh::New(const IOobject& io) // - defaultRegion (region0) gets loaded from constant, other ones // get loaded from constant/. Normally we'd use // polyMesh::dbDir() but we haven't got a polyMesh yet ... - IOdictionary dict + IOobject dictHeader ( - IOobject + "dynamicMeshDict", + io.time().constant(), + (io.name() == polyMesh::defaultRegion ? "" : io.name()), + io.db(), + IOobject::MUST_READ_IF_MODIFIED, + IOobject::NO_WRITE, + false + ); + + if (dictHeader.typeHeaderOk(true)) + { + IOdictionary dict(dictHeader); + + const word dynamicFvMeshTypeName(dict.lookup("dynamicFvMesh")); + + Info<< "Selecting dynamicFvMesh " << dynamicFvMeshTypeName << endl; + + const_cast(io.time()).libs().open ( - "dynamicMeshDict", - io.time().constant(), - (io.name() == polyMesh::defaultRegion ? "" : io.name()), - io.db(), - IOobject::MUST_READ_IF_MODIFIED, - IOobject::NO_WRITE, - false - ) - ); + dict, + "dynamicFvMeshLibs", + IOobjectConstructorTablePtr_ + ); - const word dynamicFvMeshTypeName(dict.lookup("dynamicFvMesh")); + if (!IOobjectConstructorTablePtr_) + { + FatalErrorInFunction + << "dynamicFvMesh table is empty" + << exit(FatalError); + } - Info<< "Selecting dynamicFvMesh " << dynamicFvMeshTypeName << endl; + IOobjectConstructorTable::iterator cstrIter = + IOobjectConstructorTablePtr_->find(dynamicFvMeshTypeName); - const_cast(io.time()).libs().open - ( - dict, - "dynamicFvMeshLibs", - IOobjectConstructorTablePtr_ - ); + if (cstrIter == IOobjectConstructorTablePtr_->end()) + { + FatalErrorInFunction + << "Unknown dynamicFvMesh type " + << dynamicFvMeshTypeName << nl << nl + << "Valid dynamicFvMesh types are :" << endl + << IOobjectConstructorTablePtr_->sortedToc() + << exit(FatalError); + } - if (!IOobjectConstructorTablePtr_) - { - FatalErrorInFunction - << "dynamicFvMesh table is empty" - << exit(FatalError); + return autoPtr(cstrIter()(io)); } - - IOobjectConstructorTable::iterator cstrIter = - IOobjectConstructorTablePtr_->find(dynamicFvMeshTypeName); - - if (cstrIter == IOobjectConstructorTablePtr_->end()) + else { - FatalErrorInFunction - << "Unknown dynamicFvMesh type " - << dynamicFvMeshTypeName << nl << nl - << "Valid dynamicFvMesh types are :" << endl - << IOobjectConstructorTablePtr_->sortedToc() - << exit(FatalError); + return autoPtr(new staticFvMesh(io)); } - - return autoPtr(cstrIter()(io)); } diff --git a/src/finiteVolume/finiteVolume/fvc/fvcDdt.C b/src/finiteVolume/finiteVolume/fvc/fvcDdt.C index 6087724834..5d997015fa 100644 --- a/src/finiteVolume/finiteVolume/fvc/fvcDdt.C +++ b/src/finiteVolume/finiteVolume/fvc/fvcDdt.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 @@ -201,6 +201,31 @@ ddtCorr } +template +tmp::type, fvsPatchField, surfaceMesh>> +ddtCorr +( + const GeometricField& U, + const GeometricField + < + typename flux::type, + fvsPatchField, + surfaceMesh + >& phi, + const GeometricField& Uf +) +{ + if (U.mesh().changing()) + { + return ddtCorr(U, Uf); + } + else + { + return ddtCorr(U, phi); + } +} + + template tmp::type, fvsPatchField, surfaceMesh>> ddtCorr diff --git a/src/finiteVolume/finiteVolume/fvc/fvcDdt.H b/src/finiteVolume/finiteVolume/fvc/fvcDdt.H index 0c6ee4b35a..7b702c7d74 100644 --- a/src/finiteVolume/finiteVolume/fvc/fvcDdt.H +++ b/src/finiteVolume/finiteVolume/fvc/fvcDdt.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 @@ -154,6 +154,28 @@ namespace fvc >& phi ); + template + tmp + < + GeometricField + < + typename Foam::flux::type, + fvsPatchField, + surfaceMesh + > + > + ddtCorr + ( + const GeometricField& U, + const GeometricField + < + typename Foam::flux::type, + fvsPatchField, + surfaceMesh + >& phi, + const GeometricField& Uf + ); + template tmp < diff --git a/src/finiteVolume/finiteVolume/fvc/fvcMeshPhi.C b/src/finiteVolume/finiteVolume/fvc/fvcMeshPhi.C index c7c38d79e8..2307df455f 100644 --- a/src/finiteVolume/finiteVolume/fvc/fvcMeshPhi.C +++ b/src/finiteVolume/finiteVolume/fvc/fvcMeshPhi.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 @@ -219,4 +219,22 @@ Foam::tmp Foam::fvc::absolute } +void Foam::fvc::correctUf +( + surfaceVectorField& Uf, + const volVectorField& U, + const surfaceScalarField& phi +) +{ + const fvMesh& mesh = U.mesh(); + + if (phi.mesh().changing()) + { + Uf = fvc::interpolate(U); + surfaceVectorField n(mesh.Sf()/mesh.magSf()); + Uf += n*(phi/mesh.magSf() - (n & Uf)); + } +} + + // ************************************************************************* // diff --git a/src/finiteVolume/finiteVolume/fvc/fvcMeshPhi.H b/src/finiteVolume/finiteVolume/fvc/fvcMeshPhi.H index e055d4d970..ad17402545 100644 --- a/src/finiteVolume/finiteVolume/fvc/fvcMeshPhi.H +++ b/src/finiteVolume/finiteVolume/fvc/fvcMeshPhi.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -147,6 +147,13 @@ namespace fvc const volScalarField& rho, const volVectorField& U ); + + void correctUf + ( + surfaceVectorField& Uf, + const volVectorField& U, + const surfaceScalarField& phi + ); }