/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2020-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 "layerAdditionRemoval.H" #include "polyTopoChanger.H" #include "polyMesh.H" #include "Time.H" #include "primitiveMesh.H" #include "polyTopoChange.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { defineTypeNameAndDebug(layerAdditionRemoval, 0); addToRunTimeSelectionTable ( polyMeshModifier, layerAdditionRemoval, dictionary ); } const Foam::scalar Foam::layerAdditionRemoval::addDelta_ = 0.3; const Foam::scalar Foam::layerAdditionRemoval::removeDelta_ = 0.1; // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::layerAdditionRemoval::checkDefinition() { if (!faceZoneID_.active()) { FatalErrorInFunction << "Master face zone named " << faceZoneID_.name() << " cannot be found." << abort(FatalError); } if ( minLayerThickness_ < VSMALL || maxLayerThickness_ < minLayerThickness_ ) { FatalErrorInFunction << "Incorrect layer thickness definition." << abort(FatalError); } if ( returnReduceAnd ( topoChanger().mesh().faceZones()[faceZoneID_.index()].empty() ) ) { FatalErrorInFunction << "Face extrusion zone contains no faces. " << "Please check your mesh definition." << abort(FatalError); } if (debug) { Pout<< "Cell layer addition/removal object " << name() << " :" << nl << " faceZoneID: " << faceZoneID_ << endl; } } void Foam::layerAdditionRemoval::clearAddressing() const { pointsPairingPtr_.reset(nullptr); facesPairingPtr_.reset(nullptr); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::layerAdditionRemoval::layerAdditionRemoval ( const word& name, const label index, const polyTopoChanger& ptc, const word& zoneName, const scalar minThickness, const scalar maxThickness, const bool thicknessFromVolume ) : polyMeshModifier(name, index, ptc, true), faceZoneID_(zoneName, ptc.mesh().faceZones()), minLayerThickness_(minThickness), maxLayerThickness_(maxThickness), thicknessFromVolume_(thicknessFromVolume), oldLayerThickness_(-1.0), pointsPairingPtr_(nullptr), facesPairingPtr_(nullptr), triggerRemoval_(-1), triggerAddition_(-1) { checkDefinition(); } Foam::layerAdditionRemoval::layerAdditionRemoval ( const word& name, const dictionary& dict, const label index, const polyTopoChanger& ptc ) : polyMeshModifier(name, index, ptc, dict.get("active")), faceZoneID_(dict.lookup("faceZoneName"), ptc.mesh().faceZones()), minLayerThickness_(dict.get("minLayerThickness")), maxLayerThickness_(dict.get("maxLayerThickness")), thicknessFromVolume_(dict.getOrDefault("thicknessFromVolume", true)), oldLayerThickness_(dict.getOrDefault("oldLayerThickness", -1)), pointsPairingPtr_(nullptr), facesPairingPtr_(nullptr), triggerRemoval_(-1), triggerAddition_(-1) { checkDefinition(); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool Foam::layerAdditionRemoval::changeTopology() const { // Protect from multiple calculation in the same time-step if (triggerRemoval_ > -1 || triggerAddition_ > -1) { return true; } // Go through all the cells in the master layer and calculate // approximate layer thickness as the ratio of the cell volume and // face area in the face zone. // Layer addition: // When the max thickness exceeds the threshold, trigger refinement. // Layer removal: // When the min thickness falls below the threshold, trigger removal. const polyMesh& mesh = topoChanger().mesh(); const faceZone& fz = mesh.faceZones()[faceZoneID_.index()]; const labelList& mc = fz.masterCells(); const scalarField& V = mesh.cellVolumes(); const vectorField& S = mesh.faceAreas(); if (min(V) < -VSMALL) { FatalErrorInFunction << "negative cell volume. Error in mesh motion before " << "topological change.\n V: " << V << abort(FatalError); } scalar avgDelta = 0; scalar minDelta = GREAT; scalar maxDelta = 0; label nDelta = 0; if (thicknessFromVolume_) { // Thickness calculated from cell volume/face area forAll(fz, facei) { scalar curDelta = V[mc[facei]]/mag(S[fz[facei]]); avgDelta += curDelta; minDelta = min(minDelta, curDelta); maxDelta = max(maxDelta, curDelta); } nDelta = fz.size(); } else { // Thickness calculated from edges on layer const Map