/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2022-2026 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 "patchCutLayerAverage.H" #include "OSspecific.H" #include "patchCutPlot.H" #include "volPointInterpolation.H" #include "writeFile.H" #include "polyTopoChangeMap.H" #include "polyMeshMap.H" #include "polyDistributionMap.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { namespace functionObjects { defineTypeNameAndDebug(patchCutLayerAverage, 0); addToRunTimeSelectionTable ( functionObject, patchCutLayerAverage, dictionary ); } } // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // Foam::fileName Foam::functionObjects::patchCutLayerAverage::outputPath() const { return time_.globalPath() /writeFile::outputPrefix /(mesh_.name() != polyMesh::defaultRegion ? mesh_.name() : word()) /name() /time_.name(); } void Foam::functionObjects::patchCutLayerAverage::calcWeights() { const polyPatch& pp = mesh_.poly().boundary()[patchName_]; const pointField& points = pp.localPoints(); // Calculate or lookup the point coordinates tmp tpointXs = distanceName_ == word::null ? points & direction_ : ( mesh_.foundObject(distanceName_) ? volPointInterpolation::New(mesh_).interpolate ( mesh_.lookupObject(distanceName_) ) : tmp ( mesh_.lookupObject(distanceName_) ) )().boundaryField()[pp.index()].patchInternalField(); const scalarField& pointXs = tpointXs(); // Calculate the cut coordinates and the weights const scalarField cutXs ( patchCutPlot::calcCutXs ( pp, pointXs, interpolate_, interpolate_ ? nLayers_ : nLayers_ + 1, nOptimiseIter_, debug, name(), mesh(), formatter_() ) ); weights_.reset ( new List ( patchCutPlot::calcWeights ( pp, pointXs, cutXs, interpolate_ ) ) ); // Calculate layer coordinates and widths if (interpolate_) { layerDistances_.reset(new scalarField(cutXs)); } else { const SubField distance0s(cutXs, nLayers_); const SubField distance1s(cutXs, nLayers_, 1); layerDistances_.reset(eval((distance0s + distance1s)/2).ptr()); layerThicknesses_.reset(eval(distance1s - distance0s).ptr()); } // Calculate the layer positions layerPositions_.reset ( cutPlot::applyWeights ( nLayers_, weights_, pointField(pp.faceCentres()) ).ptr() ); // Write the layers as a tensor field for debugging if (debug) { patchCutPlot::writeLayers ( pp, patchCutPlot::calcWeights ( pp, pointXs, cutXs, interpolate_, false ), name(), mesh() ); } } void Foam::functionObjects::patchCutLayerAverage::clear() { weights_.clear(); layerDistances_.clear(); layerThicknesses_.clear(); layerPositions_.clear(); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjects::patchCutLayerAverage::patchCutLayerAverage ( const word& name, const Time& runTime, const dictionary& dict ) : fvMeshFunctionObject(name, runTime, dict) { read(dict); } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::functionObjects::patchCutLayerAverage::~patchCutLayerAverage() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool Foam::functionObjects::patchCutLayerAverage::read(const dictionary& dict) { patchName_ = dict.lookup("patch"); const bool haveDirection = dict.found("direction"); const bool haveDistance = dict.found("distance"); if (haveDirection == haveDistance) { FatalIOErrorInFunction(dict) << "keywords direction and distance both " << (haveDirection ? "" : "un") << "defined in " << "dictionary " << dict.name() << exit(FatalIOError); } else if (haveDirection) { direction_ = normalised(dict.lookup("direction")); distanceName_ = word::null; } else if (haveDistance) { direction_ = vector::nan; distanceName_ = dict.lookup("distance"); } nLayers_ = dict.lookup