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 "addToRunTimeSelectionTable.H"
#include "IOmanip.H"
#include "interfaceTrackingFvMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(writeFreeSurface, 0);
@ -43,72 +44,62 @@ namespace Foam
dictionary
);
}
}
// * * * * * * * * * * * * * 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 =
time_.lookupObject<fvMesh>(polyMesh::defaultRegion);
interfaceTrackingFvMesh& itm =
refCast<interfaceTrackingFvMesh>
(
const_cast<dynamicFvMesh&>
(
mesh.lookupObject<dynamicFvMesh>("fvSolution")
)
);
itm.writeVTKControlPoints();
// FatalError
}
else
{
itm->writeVTKControlPoints();
}
return true;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::writeFreeSurface::writeFreeSurface
Foam::functionObjects::writeFreeSurface::writeFreeSurface
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
functionObject(name),
name_(name),
time_(runTime),
regionName_(polyMesh::defaultRegion)
fvMeshFunctionObject(name, runTime, dict)
{
Info<< "Creating " << this->name() << " function object." << endl;
dict.readIfPresent("region", regionName_);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::writeFreeSurface::start()
bool Foam::functionObjects::writeFreeSurface::execute()
{
return writeData();
}
bool Foam::writeFreeSurface::execute()
{
return writeData();
}
bool Foam::writeFreeSurface::read(const dictionary& dict)
{
dict.readIfPresent("region", regionName_);
if (time_.writeTime())
{
writeData();
}
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/>.
Class
Foam::writeFreeSurface
Foam::functionObjects::writeFreeSurface
Description
A function object to write the control points on the free surface
@ -34,18 +34,17 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef writeFreeSurface_H
#define writeFreeSurface_H
#ifndef Foam_functionObjects_writeFreeSurface_H
#define Foam_functionObjects_writeFreeSurface_H
#include "functionObject.H"
#include "dictionary.H"
#include "fvMesh.H"
#include "OFstream.H"
#include "fvMeshFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class writeFreeSurface Declaration
@ -53,30 +52,13 @@ namespace Foam
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
//- Write data
bool writeData();
//- Write data unconditionally
void writeData();
//- No copy construct
writeFreeSurface(const writeFreeSurface&) = delete;
//- No copy assignment
void operator=(const writeFreeSurface&) = delete;
public:
@ -86,7 +68,7 @@ public:
// Constructors
//- Construct from components
//- Construct from Time and dictionary
writeFreeSurface
(
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
//- start is called at the start of the time-loop
virtual bool start();
//- execute is called at each ++ or += of the time-loop
//- Called at each ++ or += of the time-loop
virtual bool execute();
//- Read and set the function object if its data has changed
virtual bool read(const dictionary& dict);
//- No-op
virtual bool write()
{
return true;
}
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

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

View File

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