mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: improve volRegion handling of moving meshes (#1194)
- implemented as lazy evaluation with an additional update() method. This avoids unnecessary changes until the values are actually required. - apply mesh motion changes for momentum, volFieldValue, specieReactionRates function objects
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -229,12 +229,6 @@ Foam::functionObjects::fieldValues::volFieldValue::volFieldValue
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fieldValues::volFieldValue::~volFieldValue()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::fieldValues::volFieldValue::read
|
||||
@ -251,6 +245,8 @@ bool Foam::functionObjects::fieldValues::volFieldValue::read
|
||||
|
||||
bool Foam::functionObjects::fieldValues::volFieldValue::write()
|
||||
{
|
||||
volRegion::update(); // Ensure cached values are valid
|
||||
|
||||
fieldValue::write();
|
||||
|
||||
if (Pstream::master())
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -272,7 +272,7 @@ public:
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~volFieldValue();
|
||||
virtual ~volFieldValue() = default;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -260,14 +260,12 @@ Foam::functionObjects::fieldValues::volFieldValue::filterField
|
||||
const Field<Type>& field
|
||||
) const
|
||||
{
|
||||
if (isNull(cellIDs()))
|
||||
if (volRegion::vrtAll == this->volRegion::regionType())
|
||||
{
|
||||
return field;
|
||||
}
|
||||
else
|
||||
{
|
||||
return tmp<Field<Type>>::New(field, cellIDs());
|
||||
}
|
||||
|
||||
return tmp<Field<Type>>::New(field, cellIDs());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -44,6 +44,16 @@ namespace functionObjects
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::momentum::purgeFields()
|
||||
{
|
||||
objectRegistry& obr = const_cast<objectRegistry&>(obr_);
|
||||
|
||||
obr.erase(scopedName("momentum"));
|
||||
obr.erase(scopedName("angularMomentum"));
|
||||
obr.erase(scopedName("angularVelocity"));
|
||||
}
|
||||
|
||||
|
||||
template<class GeoField>
|
||||
Foam::autoPtr<GeoField>
|
||||
Foam::functionObjects::momentum::newField
|
||||
@ -75,6 +85,13 @@ void Foam::functionObjects::momentum::calc()
|
||||
{
|
||||
initialise();
|
||||
|
||||
// Ensure volRegion is properly up-to-date.
|
||||
// Purge old fields if anything has changed (eg, mesh size etc)
|
||||
if (volRegion::update())
|
||||
{
|
||||
purgeFields();
|
||||
}
|
||||
|
||||
// When field writing is not enabled we need our local storage
|
||||
// for the momentum and angular velocity fields
|
||||
autoPtr<volVectorField> tmomentum, tAngularMom, tAngularVel;
|
||||
@ -292,22 +309,27 @@ void Foam::functionObjects::momentum::initialise()
|
||||
|
||||
void Foam::functionObjects::momentum::writeValues(Ostream& os)
|
||||
{
|
||||
Log << type() << " " << name() << " write:" << nl;
|
||||
|
||||
Log << " Sum of Momentum";
|
||||
|
||||
if (regionType_ != vrtAll)
|
||||
if (log)
|
||||
{
|
||||
Log << ' ' << regionTypeNames_[regionType_]
|
||||
<< ' ' << regionName_;
|
||||
}
|
||||
Info<< type() << " " << name() << " write:" << nl;
|
||||
|
||||
Log << nl
|
||||
<< " linear : " << sumMomentum_ << nl;
|
||||
Info<< " Sum of Momentum";
|
||||
|
||||
if (hasCsys_)
|
||||
{
|
||||
Log << " angular : " << sumAngularMom_ << nl;
|
||||
if (regionType_ != vrtAll)
|
||||
{
|
||||
Info<< ' ' << regionTypeNames_[regionType_]
|
||||
<< ' ' << regionName_;
|
||||
}
|
||||
|
||||
Info<< " (volume " << volRegion::V() << ')' << nl
|
||||
<< " linear : " << sumMomentum_ << nl;
|
||||
|
||||
if (hasCsys_)
|
||||
{
|
||||
Info<< " angular : " << sumAngularMom_ << nl;
|
||||
}
|
||||
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
if (writeToFile())
|
||||
@ -323,8 +345,6 @@ void Foam::functionObjects::momentum::writeValues(Ostream& os)
|
||||
|
||||
os << tab << volRegion::V() << endl;
|
||||
}
|
||||
|
||||
Log << endl;
|
||||
}
|
||||
|
||||
|
||||
@ -496,7 +516,7 @@ bool Foam::functionObjects::momentum::write()
|
||||
{
|
||||
if (writeMomentum_ || (hasCsys_ && (writeVelocity_ || writePosition_)))
|
||||
{
|
||||
Log <<"Writing fields" << nl;
|
||||
Log << "Writing fields" << nl;
|
||||
|
||||
const volVectorField* fieldPtr;
|
||||
|
||||
@ -572,12 +592,14 @@ bool Foam::functionObjects::momentum::write()
|
||||
void Foam::functionObjects::momentum::updateMesh(const mapPolyMesh& mpm)
|
||||
{
|
||||
volRegion::updateMesh(mpm);
|
||||
purgeFields(); // Mesh motion makes calculated fields dubious
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::momentum::movePoints(const polyMesh& pm)
|
||||
{
|
||||
volRegion::movePoints(pm);
|
||||
purgeFields(); // Mesh motion makes calculated fields dubious
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -134,6 +134,9 @@ class momentum
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Remove calculated fields from the registry
|
||||
void purgeFields();
|
||||
|
||||
//- Calculate the fields and integral values
|
||||
void calc();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user