From 78c984f8f40bd813d7c3d0a0dc00554117d3417e Mon Sep 17 00:00:00 2001 From: Andrew Heather <> Date: Tue, 12 Apr 2022 16:03:14 +0100 Subject: [PATCH] ENH: binField: new field function object The new 'binField' function object calculates binned data, where specified patches are divided into segments according to various input bin characteristics, so that spatially-localised information can be output for each segment. Co-authored-by: Kutalmis Bercin --- src/functionObjects/field/Make/files | 6 + src/functionObjects/field/binField/binField.C | 128 +++++++ src/functionObjects/field/binField/binField.H | 221 ++++++++++++ .../binField/binModels/binModel/binModel.C | 205 ++++++++++++ .../binField/binModels/binModel/binModel.H | 243 ++++++++++++++ .../binField/binModels/binModel/binModelNew.C | 59 ++++ .../binModels/binModel/binModelTemplates.C | 102 ++++++ .../singleDirectionUniformBin.C | 186 +++++++++++ .../singleDirectionUniformBin.H | 186 +++++++++++ .../singleDirectionUniformBinTemplates.C | 195 +++++++++++ .../binModels/uniformBin/uniformBin.C | 315 ++++++++++++++++++ .../binModels/uniformBin/uniformBin.H | 222 ++++++++++++ .../uniformBin/uniformBinTemplates.C | 178 ++++++++++ 13 files changed, 2246 insertions(+) create mode 100644 src/functionObjects/field/binField/binField.C create mode 100644 src/functionObjects/field/binField/binField.H create mode 100644 src/functionObjects/field/binField/binModels/binModel/binModel.C create mode 100644 src/functionObjects/field/binField/binModels/binModel/binModel.H create mode 100644 src/functionObjects/field/binField/binModels/binModel/binModelNew.C create mode 100644 src/functionObjects/field/binField/binModels/binModel/binModelTemplates.C create mode 100644 src/functionObjects/field/binField/binModels/singleDirectionUniformBin/singleDirectionUniformBin.C create mode 100644 src/functionObjects/field/binField/binModels/singleDirectionUniformBin/singleDirectionUniformBin.H create mode 100644 src/functionObjects/field/binField/binModels/singleDirectionUniformBin/singleDirectionUniformBinTemplates.C create mode 100644 src/functionObjects/field/binField/binModels/uniformBin/uniformBin.C create mode 100644 src/functionObjects/field/binField/binModels/uniformBin/uniformBin.H create mode 100644 src/functionObjects/field/binField/binModels/uniformBin/uniformBinTemplates.C diff --git a/src/functionObjects/field/Make/files b/src/functionObjects/field/Make/files index 59fabd85cd..b7c2550efb 100644 --- a/src/functionObjects/field/Make/files +++ b/src/functionObjects/field/Make/files @@ -1,5 +1,11 @@ AMIWeights/AMIWeights.C +binField/binField.C +binField/binModels/binModel/binModel.C +binField/binModels/binModel/binModelNew.C +binField/binModels/uniformBin/uniformBin.C +binField/binModels/singleDirectionUniformBin/singleDirectionUniformBin.C + columnAverage/columnAverage.C continuityError/continuityError.C diff --git a/src/functionObjects/field/binField/binField.C b/src/functionObjects/field/binField/binField.C new file mode 100644 index 0000000000..b805afcd9a --- /dev/null +++ b/src/functionObjects/field/binField/binField.C @@ -0,0 +1,128 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2022 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 "binField.H" +#include "binModel.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(binField, 0); + addToRunTimeSelectionTable(functionObject, binField, dictionary); +} +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::binField::binField +( + const word& name, + const Time& runTime, + const dictionary& dict, + bool readFields +) +: + fvMeshFunctionObject(name, runTime, dict), + binModelPtr_(nullptr) +{ + if (readFields) + { + read(dict); + } +} + + +Foam::functionObjects::binField::binField +( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + bool readFields +) +: + fvMeshFunctionObject(name, obr, dict), + binModelPtr_(nullptr) +{ + if (readFields) + { + read(dict); + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::binField::read(const dictionary& dict) +{ + if (!fvMeshFunctionObject::read(dict)) + { + return false; + } + + Info<< type() << " " << name() << ":" << endl; + + binModelPtr_.reset(binModel::New(dict, mesh_, name())); + + return true; +} + + +bool Foam::functionObjects::binField::execute() +{ + Log << type() << " " << name() << ":" << nl + << " Calculating bins" << nl << endl; + + binModelPtr_->apply(); + + return true; +} + + +bool Foam::functionObjects::binField::write() +{ + return true; +} + + +void Foam::functionObjects::binField::updateMesh(const mapPolyMesh& mpm) +{ + binModelPtr_->updateMesh(mpm); +} + + +void Foam::functionObjects::binField::movePoints(const polyMesh& mesh) +{ + binModelPtr_->movePoints(mesh); +} + + +// ************************************************************************* // diff --git a/src/functionObjects/field/binField/binField.H b/src/functionObjects/field/binField/binField.H new file mode 100644 index 0000000000..1fd57a1aed --- /dev/null +++ b/src/functionObjects/field/binField/binField.H @@ -0,0 +1,221 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2022 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 . + +Class + Foam::functionObjects::binField + +Group + grpFieldFunctionObjects + +Description + Calculates binned data, where specified patches are divided into + segments according to various input bin characteristics, so that + spatially-localised information can be output for each segment. + + Operands: + \table + Operand | Type | Location + input | vol\Field(s) | \/\s + output file | dat | postProcessing/\/\/\ + output field | - | - + \endtable + + where \c \=Scalar/Vector/SphericalTensor/SymmTensor/Tensor. + +Usage + Minimal example by using \c system/controlDict.functions: + \verbatim + binField1 + { + // Mandatory entries + type binField; + libs (fieldFunctionObjects); + binModel ; + fields (); + patches (); + binData + { + // Entries of the chosen binModel + } + + // Optional entries + cellZones (); + decomposePatchValues ; + + // Conditional optional entries + + // Option-1, i.e. general coordinate system specification + coordinateSystem + { + type cartesian; + origin (0 0 0); + rotation + { + type axes; + e3 (0 0 1); + e1 (1 0 0); // (e1, e2) or (e2, e3) or (e3, e1) + } + } + + // Option-2, i.e. the centre of rotation + // by inherently using e3=(0 0 1) and e1=(1 0 0) + CofR (0 0 0); + + // Inherited entries + ... + } + \endverbatim + + where the entries mean: + \table + Property | Description | Type | Reqd | Deflt + type | Type name: binField | word | yes | - + libs | Library name: fieldFunctionObjects | word | yes | - + binModel | Name of the bin model | word | yes | - + fields | Names of operand fields | wordHasSet | yes | - + patches | Names of operand patches | wordRes | yes | - + binData | Entries of the chosen bin model | dict | yes | - + decomposePatchValues | Flag to output normal and tangential components | bool | no | false + cellZones | Names of operand cell zones | wordRes | no | - + coordinateSystem | Coordinate system specifier | dict | cndtnl | - + CofR | Centre of rotation | vector | cndtnl | - + \endtable + + Options for the \c binModel entry: + \verbatim + singleDirectionUniformBin | Segments in a single direction + uniformBin | Segments in multiple directions + \endverbatim + + The inherited entries are elaborated in: + - \link fvMeshFunctionObject.H \endlink + - \link writeFile.H \endlink + - \link coordinateSystem.H \endlink + +SourceFiles + binField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef Foam_functionObjects_binField_H +#define Foam_functionObjects_binField_H + +#include "fvMeshFunctionObject.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class binModel; + +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class binField Declaration +\*---------------------------------------------------------------------------*/ + +class binField +: + public fvMeshFunctionObject +{ +protected: + + // Protected Data + + //- Runtime-selectable bin model + autoPtr binModelPtr_; + + +public: + + //- Runtime type information + TypeName("binField"); + + + // Constructors + + //- Construct from Time and dictionary + binField + ( + const word& name, + const Time& runTime, + const dictionary& dict, + const bool readFields = true + ); + + //- Construct from objectRegistry and dictionary + binField + ( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool readFields = true + ); + + //- No copy construct + binField(const binField&) = delete; + + //- No copy assignment + void operator=(const binField&) = delete; + + + //- Destructor + virtual ~binField() = default; + + + // Member Functions + + //- Read the dictionary + virtual bool read(const dictionary& dict); + + //- Execute the function object + virtual bool execute(); + + //- Write to data files/fields and to streams + virtual bool write(); + + //- Update for changes of mesh + virtual void updateMesh(const mapPolyMesh& mpm); + + //- Update for changes of mesh + virtual void movePoints(const polyMesh& mesh); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/functionObjects/field/binField/binModels/binModel/binModel.C b/src/functionObjects/field/binField/binModels/binModel/binModel.C new file mode 100644 index 0000000000..5e351b0783 --- /dev/null +++ b/src/functionObjects/field/binField/binModels/binModel/binModel.C @@ -0,0 +1,205 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021-2022 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 "binModel.H" +#include "fvMesh.H" +#include "cartesianCS.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(binModel, 0); + defineRunTimeSelectionTable(binModel, dictionary); +} + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template<> +bool Foam::binModel::decomposePatchValues +( + List>& data, + const label bini, + const vector& v, + const vector& n +) const +{ + if (!decomposePatchValues_) + { + return false; + } + + #ifdef FULLDEBUG + if (data.size() != 3) + { + FatalErrorInFunction + << "Inconsistent data list size - expect size 3" + << abort(FatalError); + } + #endif + + data[1][bini] += n*(v & n); + data[2][bini] += v - n*(v & n); + + return true; +} + + +void Foam::binModel::setCoordinateSystem +( + const dictionary& dict, + const word& e3Name, + const word& e1Name +) +{ + coordSysPtr_.clear(); + + if (dict.found(coordinateSystem::typeName_())) + { + coordSysPtr_ = + coordinateSystem::New + ( + mesh_, + dict, + coordinateSystem::typeName_() + ); + + Info<< "Setting co-ordinate system:" << nl + << " - type : " << coordSysPtr_->name() << nl + << " - origin : " << coordSysPtr_->origin() << nl + << " - e3 : " << coordSysPtr_->e3() << nl + << " - e1 : " << coordSysPtr_->e1() << endl; + } + else if (dict.found("CofR")) + { + const vector origin(dict.get("CofR")); + + const vector e3 + ( + e3Name == word::null + ? vector(0, 0, 1) + : dict.get(e3Name) + ); + + const vector e1 + ( + e1Name == word::null + ? vector(1, 0, 0) + : dict.get(e1Name) + ); + + coordSysPtr_.reset(new coordSystem::cartesian(origin, e3, e1)); + } + else + { + coordSysPtr_.reset(new coordSystem::cartesian(dict)); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::binModel::binModel +( + const dictionary& dict, + const fvMesh& mesh, + const word& outputPrefix +) +: + writeFile(mesh, outputPrefix), + mesh_(mesh), + decomposePatchValues_(false), + cumulative_(false), + coordSysPtr_(), + nBin_(1), + patchSet_(), + fieldNames_(), + cellZoneIDs_(), + filePtrs_() +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +bool Foam::binModel::read(const dictionary& dict) +{ + patchSet_ = mesh_.boundaryMesh().patchSet(dict.get("patches")); + fieldNames_ = dict.get("fields").sortedToc(); + + if (dict.found("cellZones")) + { + DynamicList