FIX: avoid questionable lookup and casting for interfaceTrackingFvMesh

This commit is contained in:
Mark Olesen
2023-12-04 13:58:09 +00:00
parent 149cd7042f
commit f377875bc8
4 changed files with 83 additions and 101 deletions

View File

@ -26,13 +26,14 @@ License
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
#include "writeFreeSurface.H" #include "writeFreeSurface.H"
#include "addToRunTimeSelectionTable.H"
#include "IOmanip.H"
#include "interfaceTrackingFvMesh.H" #include "interfaceTrackingFvMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{
namespace functionObjects
{ {
defineTypeNameAndDebug(writeFreeSurface, 0); defineTypeNameAndDebug(writeFreeSurface, 0);
@ -43,72 +44,62 @@ namespace Foam
dictionary dictionary
); );
} }
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::writeFreeSurface::writeData() void Foam::functionObjects::writeFreeSurface::writeData()
{ {
if (time_.writeTime()) // refCast<interfaceTrackingFvMesh>
auto* itm =
const_cast<interfaceTrackingFvMesh*>
(
isA<interfaceTrackingFvMesh>(mesh_)
);
if (!itm)
{ {
const fvMesh& mesh = // FatalError
time_.lookupObject<fvMesh>(polyMesh::defaultRegion); }
else
interfaceTrackingFvMesh& itm = {
refCast<interfaceTrackingFvMesh> itm->writeVTKControlPoints();
(
const_cast<dynamicFvMesh&>
(
mesh.lookupObject<dynamicFvMesh>("fvSolution")
)
);
itm.writeVTKControlPoints();
} }
return true;
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::writeFreeSurface::writeFreeSurface Foam::functionObjects::writeFreeSurface::writeFreeSurface
( (
const word& name, const word& name,
const Time& runTime, const Time& runTime,
const dictionary& dict const dictionary& dict
) )
: :
functionObject(name), fvMeshFunctionObject(name, runTime, dict)
name_(name),
time_(runTime),
regionName_(polyMesh::defaultRegion)
{ {
Info<< "Creating " << this->name() << " function object." << endl; Info<< "Creating " << this->name() << " function object." << endl;
dict.readIfPresent("region", regionName_);
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::writeFreeSurface::start() bool Foam::functionObjects::writeFreeSurface::execute()
{ {
return writeData(); if (time_.writeTime())
} {
writeData();
}
bool Foam::writeFreeSurface::execute()
{
return writeData();
}
bool Foam::writeFreeSurface::read(const dictionary& dict)
{
dict.readIfPresent("region", regionName_);
return true; return true;
} }
bool Foam::functionObjects::writeFreeSurface::write()
{
return true;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -24,7 +24,7 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::writeFreeSurface Foam::functionObjects::writeFreeSurface
Description Description
A function object to write the control points on the free surface A function object to write the control points on the free surface
@ -34,18 +34,17 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef writeFreeSurface_H #ifndef Foam_functionObjects_writeFreeSurface_H
#define writeFreeSurface_H #define Foam_functionObjects_writeFreeSurface_H
#include "functionObject.H" #include "fvMeshFunctionObject.H"
#include "dictionary.H"
#include "fvMesh.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
namespace functionObjects
{
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class writeFreeSurface Declaration Class writeFreeSurface Declaration
@ -53,30 +52,13 @@ namespace Foam
class writeFreeSurface class writeFreeSurface
: :
public functionObject public functionObjects::fvMeshFunctionObject
{ {
// Private Data
//- Name
const word name_;
//- Reference to main object registry
const Time& time_;
//- Region name
word regionName_;
// Private Member Functions // Private Member Functions
//- Write data //- Write data unconditionally
bool writeData(); void writeData();
//- No copy construct
writeFreeSurface(const writeFreeSurface&) = delete;
//- No copy assignment
void operator=(const writeFreeSurface&) = delete;
public: public:
@ -86,7 +68,7 @@ public:
// Constructors // Constructors
//- Construct from components //- Construct from Time and dictionary
writeFreeSurface writeFreeSurface
( (
const word& name, const word& name,
@ -95,27 +77,30 @@ public:
); );
//- No copy construct
writeFreeSurface(const writeFreeSurface&) = delete;
//- No copy assignment
void operator=(const writeFreeSurface&) = delete;
//- Destructor
virtual ~writeFreeSurface() = default;
// Member Functions // Member Functions
//- start is called at the start of the time-loop //- Called at each ++ or += of the time-loop
virtual bool start();
//- execute is called at each ++ or += of the time-loop
virtual bool execute(); virtual bool execute();
//- Read and set the function object if its data has changed
virtual bool read(const dictionary& dict);
//- No-op //- No-op
virtual bool write() virtual bool write();
{
return true;
}
}; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam } // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -137,21 +137,24 @@ void Foam::freeSurfacePressureFvPatchScalarField::updateCoeffs()
return; return;
} }
const fvMesh& mesh = patch().boundaryMesh().mesh(); // refCast<interfaceTrackingFvMesh>
auto* itm =
interfaceTrackingFvMesh& itm = const_cast<interfaceTrackingFvMesh*>
refCast<interfaceTrackingFvMesh>
( (
const_cast<dynamicFvMesh&> isA<interfaceTrackingFvMesh>(patch().boundaryMesh().mesh())
(
mesh.lookupObject<dynamicFvMesh>("fvSolution")
)
); );
operator== if (!itm)
( {
pa_ + itm.freeSurfacePressureJump() // FatalError
); }
else
{
operator==
(
pa_ + itm->freeSurfacePressureJump()
);
}
fixedValueFvPatchScalarField::updateCoeffs(); fixedValueFvPatchScalarField::updateCoeffs();
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019 Zeljko Tukovic, FSB Zagreb. Copyright (C) 2019 Zeljko Tukovic, FSB Zagreb.
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -95,18 +95,21 @@ void Foam::freeSurfaceVelocityFvPatchVectorField::updateCoeffs()
return; return;
} }
const fvMesh& mesh = patch().boundaryMesh().mesh(); // refCast<interfaceTrackingFvMesh>
auto* itm =
interfaceTrackingFvMesh& itm = const_cast<interfaceTrackingFvMesh*>
refCast<interfaceTrackingFvMesh>
( (
const_cast<dynamicFvMesh&> isA<interfaceTrackingFvMesh>(patch().boundaryMesh().mesh())
(
mesh.lookupObject<dynamicFvMesh>("fvSolution")
)
); );
gradient() = itm.freeSurfaceSnGradU(); if (!itm)
{
// FatalError
}
else
{
gradient() = itm->freeSurfaceSnGradU();
}
fixedGradientFvPatchVectorField::updateCoeffs(); fixedGradientFvPatchVectorField::updateCoeffs();
} }