diff --git a/src/dynamicFaMesh/interfaceTrackingFvMesh/functionObjects/writeFreeSurface/writeFreeSurface.C b/src/dynamicFaMesh/interfaceTrackingFvMesh/functionObjects/writeFreeSurface/writeFreeSurface.C index 70e56a95d1..93277dbaa3 100644 --- a/src/dynamicFaMesh/interfaceTrackingFvMesh/functionObjects/writeFreeSurface/writeFreeSurface.C +++ b/src/dynamicFaMesh/interfaceTrackingFvMesh/functionObjects/writeFreeSurface/writeFreeSurface.C @@ -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 + auto* itm = + const_cast + ( + isA(mesh_) + ); + + if (!itm) { - const fvMesh& mesh = - time_.lookupObject(polyMesh::defaultRegion); - - interfaceTrackingFvMesh& itm = - refCast - ( - const_cast - ( - mesh.lookupObject("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; +} + + // ************************************************************************* // diff --git a/src/dynamicFaMesh/interfaceTrackingFvMesh/functionObjects/writeFreeSurface/writeFreeSurface.H b/src/dynamicFaMesh/interfaceTrackingFvMesh/functionObjects/writeFreeSurface/writeFreeSurface.H index 48d6d6a0fb..2c7dd593c8 100644 --- a/src/dynamicFaMesh/interfaceTrackingFvMesh/functionObjects/writeFreeSurface/writeFreeSurface.H +++ b/src/dynamicFaMesh/interfaceTrackingFvMesh/functionObjects/writeFreeSurface/writeFreeSurface.H @@ -24,7 +24,7 @@ License along with OpenFOAM. If not, see . 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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/dynamicFaMesh/interfaceTrackingFvMesh/fvPatchFields/freeSurfacePressure/freeSurfacePressureFvPatchScalarField.C b/src/dynamicFaMesh/interfaceTrackingFvMesh/fvPatchFields/freeSurfacePressure/freeSurfacePressureFvPatchScalarField.C index 727ffac8db..a659bcf4c9 100644 --- a/src/dynamicFaMesh/interfaceTrackingFvMesh/fvPatchFields/freeSurfacePressure/freeSurfacePressureFvPatchScalarField.C +++ b/src/dynamicFaMesh/interfaceTrackingFvMesh/fvPatchFields/freeSurfacePressure/freeSurfacePressureFvPatchScalarField.C @@ -137,21 +137,24 @@ void Foam::freeSurfacePressureFvPatchScalarField::updateCoeffs() return; } - const fvMesh& mesh = patch().boundaryMesh().mesh(); - - interfaceTrackingFvMesh& itm = - refCast + // refCast + auto* itm = + const_cast ( - const_cast - ( - mesh.lookupObject("fvSolution") - ) + isA(patch().boundaryMesh().mesh()) ); - operator== - ( - pa_ + itm.freeSurfacePressureJump() - ); + if (!itm) + { + // FatalError + } + else + { + operator== + ( + pa_ + itm->freeSurfacePressureJump() + ); + } fixedValueFvPatchScalarField::updateCoeffs(); } diff --git a/src/dynamicFaMesh/interfaceTrackingFvMesh/fvPatchFields/freeSurfaceVelocity/freeSurfaceVelocityFvPatchVectorField.C b/src/dynamicFaMesh/interfaceTrackingFvMesh/fvPatchFields/freeSurfaceVelocity/freeSurfaceVelocityFvPatchVectorField.C index 64a3d3136a..dcf18c7e79 100644 --- a/src/dynamicFaMesh/interfaceTrackingFvMesh/fvPatchFields/freeSurfaceVelocity/freeSurfaceVelocityFvPatchVectorField.C +++ b/src/dynamicFaMesh/interfaceTrackingFvMesh/fvPatchFields/freeSurfaceVelocity/freeSurfaceVelocityFvPatchVectorField.C @@ -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 + // refCast + auto* itm = + const_cast ( - const_cast - ( - mesh.lookupObject("fvSolution") - ) + isA(patch().boundaryMesh().mesh()) ); - gradient() = itm.freeSurfaceSnGradU(); + if (!itm) + { + // FatalError + } + else + { + gradient() = itm->freeSurfaceSnGradU(); + } fixedGradientFvPatchVectorField::updateCoeffs(); }