pimpleDyMFoam: Improved efficiency and consistency when running on a static mesh

Now pimpleDyMFoam is exactly equivalent to pimpleFoam when running on a
staticFvMesh.  Also when the constant/dynamicMeshDict is not present a
staticFvMesh is automatically constructed so that the pimpleDyMFoam solver can
run any pimpleFoam case without change.
This commit is contained in:
Henry Weller
2017-11-18 01:13:48 +00:00
parent 16ba55100a
commit 9c48042e85
13 changed files with 275 additions and 56 deletions

View File

@ -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);

View File

@ -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 <http://www.gnu.org/licenses/>.
Global
createUf
Description
Creates and initialises the velocity field Uf if present.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
autoPtr<surfaceVectorField> UfPtr;
IOobject UfHeader
(
"Uf",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
);
if (UfHeader.typeHeaderOk<surfaceVectorField>(true))
{
Info<< "Reading face velocity Uf\n" << endl;
UfPtr = new surfaceVectorField(UfHeader, mesh);
}
// ************************************************************************* //

View File

@ -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);

View File

@ -74,6 +74,8 @@ int main(int argc, char *argv[])
mesh.update();
#include "updateUf.H"
if (mesh.changing())
{
MRF.update();

View File

@ -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 <http://www.gnu.org/licenses/>.
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;
// ************************************************************************* //

View File

@ -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;

View File

@ -161,6 +161,36 @@ inline const T& Foam::autoPtr<T>::operator()() const
}
template<class T>
inline T& Foam::autoPtr<T>::operator*()
{
if (!ptr_)
{
FatalErrorInFunction
<< "object of type " << typeid(T).name()
<< " is not allocated"
<< abort(FatalError);
}
return *ptr_;
}
template<class T>
inline const T& Foam::autoPtr<T>::operator*() const
{
if (!ptr_)
{
FatalErrorInFunction
<< "object of type " << typeid(T).name()
<< " is not allocated"
<< abort(FatalError);
}
return *ptr_;
}
template<class T>
inline Foam::autoPtr<T>::operator const T&() const
{

View File

@ -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<dynamicFvMesh> New(const IOobject& io);

View File

@ -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> Foam::dynamicFvMesh::New(const IOobject& io)
// - defaultRegion (region0) gets loaded from constant, other ones
// get loaded from constant/<regionname>. 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<IOdictionary>(true))
{
IOdictionary dict(dictHeader);
const word dynamicFvMeshTypeName(dict.lookup("dynamicFvMesh"));
Info<< "Selecting dynamicFvMesh " << dynamicFvMeshTypeName << endl;
const_cast<Time&>(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<Time&>(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<dynamicFvMesh>(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<dynamicFvMesh>(new staticFvMesh(io));
}
return autoPtr<dynamicFvMesh>(cstrIter()(io));
}

View File

@ -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<class Type>
tmp<GeometricField<typename flux<Type>::type, fvsPatchField, surfaceMesh>>
ddtCorr
(
const GeometricField<Type, fvPatchField, volMesh>& U,
const GeometricField
<
typename flux<Type>::type,
fvsPatchField,
surfaceMesh
>& phi,
const GeometricField<Type, fvsPatchField, surfaceMesh>& Uf
)
{
if (U.mesh().changing())
{
return ddtCorr(U, Uf);
}
else
{
return ddtCorr(U, phi);
}
}
template<class Type>
tmp<GeometricField<typename flux<Type>::type, fvsPatchField, surfaceMesh>>
ddtCorr

View File

@ -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<class Type>
tmp
<
GeometricField
<
typename Foam::flux<Type>::type,
fvsPatchField,
surfaceMesh
>
>
ddtCorr
(
const GeometricField<Type, fvPatchField, volMesh>& U,
const GeometricField
<
typename Foam::flux<Type>::type,
fvsPatchField,
surfaceMesh
>& phi,
const GeometricField<Type, fvsPatchField, surfaceMesh>& Uf
);
template<class Type>
tmp
<

View File

@ -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::surfaceScalarField> 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));
}
}
// ************************************************************************* //

View File

@ -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
);
}