/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2025-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 "cutLayerAverage.H" #include "OSspecific.H" #include "cellCutPlot.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(cutLayerAverage, 0); addToRunTimeSelectionTable ( functionObject, cutLayerAverage, dictionary ); } } // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // Foam::fileName Foam::functionObjects::cutLayerAverage::outputPath() const { return time_.globalPath() /writeFile::outputPrefix /(mesh_.name() != polyMesh::defaultRegion ? mesh_.name() : word()) /name() /time_.name(); } void Foam::functionObjects::cutLayerAverage::calcWeights() { const pointField& points = mesh_.points(); // Calculate or lookup the point coordinates tmp tdistance = distanceName_ == word::null ? tmp(nullptr) : mesh_.foundObject(distanceName_) ? volPointInterpolation::New(mesh_).interpolate ( mesh_.lookupObject(distanceName_) ) : tmp ( mesh_.lookupObject(distanceName_) ); tmp tpointXs = distanceName_ == word::null ? points & direction_ : tmp(tdistance().primitiveField()); const scalarField& pointXs = tpointXs(); // Calculate the cut coordinates and the weights const scalarField cutXs ( cellCutPlot::calcCutXs ( mesh(), zone_, pointXs, interpolate_, interpolate_ ? nLayers_ : nLayers_ + 1, nOptimiseIter_, debug, name(), formatter_() ) ); weights_.reset ( new List ( cellCutPlot::calcWeights ( mesh(), zone_, pointXs, cutXs, interpolate_ ) ) ); // Calculate plot 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_, mesh().cellCentres() ).ptr() ); if (debug) { cellCutPlot::writeLayers ( mesh(), cellCutPlot::calcWeights ( mesh(), zone_, pointXs, cutXs, interpolate_, false ), name() ); } } void Foam::functionObjects::cutLayerAverage::clear() { weights_.clear(); layerDistances_.clear(); layerThicknesses_.clear(); layerPositions_.clear(); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjects::cutLayerAverage::cutLayerAverage ( const word& name, const Time& runTime, const dictionary& dict ) : fvMeshFunctionObject(name, runTime, dict), zone_(mesh()) { read(dict); } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::functionObjects::cutLayerAverage::~cutLayerAverage() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool Foam::functionObjects::cutLayerAverage::read(const dictionary& dict) { zone_.read(dict); 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