From 36e83444296111b7d00787cb44bf8a1e961a3a99 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Tue, 6 Jun 2023 18:36:46 +0100 Subject: [PATCH] functionObjects::checkMesh: New functionObject to check mesh changes Class Foam::functionObjects::checkMesh Description Executes primitiveMesh::checkMesh(true) every execute time for which the mesh changed, i.e. moved or changed topology. Useful to check the correctness of changing and morphing meshes. Example of checkMesh specification: \verbatim checkMesh { type checkMesh; libs ("libutilityFunctionObjects.so"); executeControl timeStep; executeInterval 10; } \endverbatim or using the standard configuration file: \verbatim #includeFunc checkMesh(executeInterval=10) \endverbatim Can be used with any solver supporting mesh-motion, in particular the movingMesh solver module, to check the mesh quality following morphing and/or topology change. --- etc/caseDicts/postProcessing/mesh/checkMesh | 19 +++ src/functionObjects/utilities/Make/files | 1 + .../utilities/checkMesh/checkMesh.C | 84 ++++++++++++ .../utilities/checkMesh/checkMesh.H | 122 ++++++++++++++++++ 4 files changed, 226 insertions(+) create mode 100644 etc/caseDicts/postProcessing/mesh/checkMesh create mode 100644 src/functionObjects/utilities/checkMesh/checkMesh.C create mode 100644 src/functionObjects/utilities/checkMesh/checkMesh.H diff --git a/etc/caseDicts/postProcessing/mesh/checkMesh b/etc/caseDicts/postProcessing/mesh/checkMesh new file mode 100644 index 0000000000..5d2dfa5079 --- /dev/null +++ b/etc/caseDicts/postProcessing/mesh/checkMesh @@ -0,0 +1,19 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +------------------------------------------------------------------------------- +Description + Writes the time step to a file for monitoring. + +\*---------------------------------------------------------------------------*/ + +type checkMesh; +libs ("libutilityFunctionObjects.so"); + +executeControl timeStep; +executeInterval 1; + +// ************************************************************************* // diff --git a/src/functionObjects/utilities/Make/files b/src/functionObjects/utilities/Make/files index 2a91fc2123..05c9fbb68c 100644 --- a/src/functionObjects/utilities/Make/files +++ b/src/functionObjects/utilities/Make/files @@ -13,5 +13,6 @@ removeRegisteredObject/removeRegisteredObject.C writeDictionary/writeDictionary.C writeObjects/writeObjects.C time/timeFunctionObject.C +checkMesh/checkMesh.C LIB = $(FOAM_LIBBIN)/libutilityFunctionObjects diff --git a/src/functionObjects/utilities/checkMesh/checkMesh.C b/src/functionObjects/utilities/checkMesh/checkMesh.C new file mode 100644 index 0000000000..1fc5cc4e31 --- /dev/null +++ b/src/functionObjects/utilities/checkMesh/checkMesh.C @@ -0,0 +1,84 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2023 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 . + +\*---------------------------------------------------------------------------*/ + +#include "checkMesh.H" +#include "fvMesh.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(checkMesh, 0); + addToRunTimeSelectionTable(functionObject, checkMesh, dictionary); +} +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::checkMesh::checkMesh +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + fvMeshFunctionObject(name, runTime, dict) +{ + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::checkMesh::~checkMesh() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::checkMesh::execute() +{ + if (mesh_.changing()) + { + return mesh_.checkMesh(true); + } + else + { + return true; + } +} + + +bool Foam::functionObjects::checkMesh::write() +{ + return true; +} + + +// ************************************************************************* // diff --git a/src/functionObjects/utilities/checkMesh/checkMesh.H b/src/functionObjects/utilities/checkMesh/checkMesh.H new file mode 100644 index 0000000000..5dae115d37 --- /dev/null +++ b/src/functionObjects/utilities/checkMesh/checkMesh.H @@ -0,0 +1,122 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2023 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 . + +Class + Foam::functionObjects::checkMesh + +Description + Executes primitiveMesh::checkMesh(true) every execute time for which the + mesh changed, i.e. moved or changed topology. + + Useful to check the correctness of changing and morphing meshes. + + Example of checkMesh specification: + \verbatim + checkMesh + { + type checkMesh; + libs ("libutilityFunctionObjects.so"); + + executeControl timeStep; + executeInterval 10; + } + \endverbatim + or using the standard configuration file: + \verbatim + #includeFunc checkMesh(executeInterval=10) + \endverbatim + +SourceFiles + checkMesh.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_checkMesh_H +#define functionObjects_checkMesh_H + +#include "fvMeshFunctionObject.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class checkMesh Declaration +\*---------------------------------------------------------------------------*/ + +class checkMesh +: + public fvMeshFunctionObject +{ + // Private Data + +public: + + //- Runtime type information + TypeName("checkMesh"); + + + // Constructors + + //- Construct from Time and dictionary + checkMesh + ( + const word& name, + const Time&, + const dictionary& + ); + + + //- Destructor + virtual ~checkMesh(); + + + // Member Functions + + //- Return the list of fields required + virtual wordList fields() const + { + return wordList::null(); + } + + //- Execute primitiveMesh::checkMesh(true) + virtual bool execute(); + + //- Do nothing + virtual bool write(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //