From 937b4898ae8d36580a70bf9228d7b55a04619818 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 24 May 2022 20:34:19 +0200 Subject: [PATCH] ENH: geometric selection mode for cellSetOption - similar to the geometric decomposition constraint, allows a compositing selection of cells based on topoSet sources which also include various searchableSurface mechanisms. This makes for potentially easier placement of sources without resorting to defining a cellSet. ENH: support zone group selection for fv::cellSetOption and fa::faceSetOption --- src/faOptions/faceSetOption/faceSetOption.C | 44 ++++--- src/faOptions/faceSetOption/faceSetOption.H | 16 +-- src/faOptions/faceSetOption/faceSetOptionI.H | 6 - src/fvOptions/cellSetOption/cellSetOption.C | 118 ++++++++++++++---- src/fvOptions/cellSetOption/cellSetOption.H | 68 +++++++--- src/fvOptions/cellSetOption/cellSetOptionI.H | 6 - .../actuationDiskSource/actuationDiskSource.C | 23 ++-- ...irectionalPressureGradientExplicitSource.C | 2 +- .../explicitPorositySource.C | 13 +- .../explicitPorositySource.H | 6 +- .../RAS/mixerVessel2D/system/controlDict | 7 +- .../RAS/mixerVessel2D/system/fvSchemes | 3 +- .../RAS/mixerVessel2D/system/fvSolution | 28 +---- .../RAS/mixerVessel2D/system/scalarTransport | 45 +++++++ 14 files changed, 252 insertions(+), 133 deletions(-) create mode 100644 tutorials/compressible/rhoPimpleFoam/RAS/mixerVessel2D/system/scalarTransport diff --git a/src/faOptions/faceSetOption/faceSetOption.C b/src/faOptions/faceSetOption/faceSetOption.C index e2436cd854..aa33a78507 100644 --- a/src/faOptions/faceSetOption/faceSetOption.C +++ b/src/faOptions/faceSetOption/faceSetOption.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -62,7 +62,7 @@ void Foam::fa::faceSetOption::setSelection(const dictionary& dict) } case smVolFaceZone: { - dict.readEntry("faceZone", faceSetName_); + dict.readEntry("faceZone", zoneName_); break; } default: @@ -113,41 +113,39 @@ void Foam::fa::faceSetOption::setFaceSelection() { Info<< indent << "- selecting faces using volume-mesh faceZone " - << faceSetName_ << endl; + << zoneName_ << nl; - label zoneID = mesh_.faceZones().findZoneID(faceSetName_); - if (zoneID == -1) + // Also handles groups, multiple zones (as wordRe match) ... + labelList zoneIDs = mesh_.faceZones().indices(zoneName_); + + if (zoneIDs.empty()) { FatalErrorInFunction - << "Cannot find faceZone " << faceSetName_ << endl - << "Valid faceZones are " << mesh_.faceZones().names() + << "No matching faceZones: " << zoneName_ << nl + << "Valid zones : " + << flatOutput(mesh_.faceZones().names()) << nl + << "Valid groups: " + << flatOutput(mesh_.faceZones().groupNames()) + << nl << exit(FatalError); } - const faceZone& addr = mesh_.faceZones()[zoneID]; + const bitSet isZoneFace(mesh_.faceZones().selection(zoneIDs)); - const bitSet isZoneFace(mesh_.nFaces(), addr); - - // Do we loop over faMesh faces or over faceZone faces? const labelUList& faceLabels = regionMesh().faceLabels(); - label n = 0; + faces_.resize_nocopy(faceLabels.size()); + + label nUsed = 0; for (const label facei : faceLabels) { if (isZoneFace[facei]) { - n++; - } - } - faces_.setSize(n); - n = 0; - for (const label facei : faceLabels) - { - if (isZoneFace[facei]) - { - faces_[n++] = facei; + faces_[nUsed] = facei; + ++nUsed; } } + faces_.resize(nUsed); break; } @@ -185,7 +183,7 @@ Foam::fa::faceSetOption::faceSetOption timeStart_(-1), duration_(0), selectionMode_(selectionModeTypeNames_.get("selectionMode", coeffs_)), - faceSetName_("none"), + zoneName_(), A_(0) { if (isActive()) diff --git a/src/faOptions/faceSetOption/faceSetOption.H b/src/faOptions/faceSetOption/faceSetOption.H index 46abaed1ca..c67407270c 100644 --- a/src/faOptions/faceSetOption/faceSetOption.H +++ b/src/faOptions/faceSetOption/faceSetOption.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -81,8 +81,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef faceSetOption_H -#define faceSetOption_H +#ifndef Foam_fa_faceSetOption_H +#define Foam_fa_faceSetOption_H #include "faOption.H" #include "faceSet.H" @@ -132,8 +132,8 @@ protected: //- Face selection mode selectionModeType selectionMode_; - //- Name of "volFaceZone" selection - word faceSetName_; + //- Name of zone for (volume) "faceZone" selection + wordRe zoneName_; //- Set of faces to apply source to labelList faces_; @@ -195,9 +195,9 @@ public: //- True if sub-selection should be used inline bool useSubMesh() const noexcept; - //- Return const access to the name of face set for "faceZone" - //- selectionMode - inline const word& faceSetName() const noexcept; + //- Return const access to the name of (volume) face zone + //- for "faceZone" selection mode + const wordRe& zoneName() const noexcept { return zoneName_; } //- Return const access to the total face area inline scalar A() const noexcept; diff --git a/src/faOptions/faceSetOption/faceSetOptionI.H b/src/faOptions/faceSetOption/faceSetOptionI.H index 1bc9b5ed25..76afe7b5d5 100644 --- a/src/faOptions/faceSetOption/faceSetOptionI.H +++ b/src/faOptions/faceSetOption/faceSetOptionI.H @@ -66,12 +66,6 @@ inline bool Foam::fa::faceSetOption::useSubMesh() const noexcept } -inline const Foam::word& Foam::fa::faceSetOption::faceSetName() const noexcept -{ - return faceSetName_; -} - - inline Foam::scalar Foam::fa::faceSetOption::A() const noexcept { return A_; diff --git a/src/fvOptions/cellSetOption/cellSetOption.C b/src/fvOptions/cellSetOption/cellSetOption.C index bede9ebc04..326c122146 100644 --- a/src/fvOptions/cellSetOption/cellSetOption.C +++ b/src/fvOptions/cellSetOption/cellSetOption.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2021 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,6 +27,9 @@ License \*---------------------------------------------------------------------------*/ #include "cellSetOption.H" +#include "cellSet.H" +#include "cellBitSet.H" +#include "topoSetCellSource.H" #include "volFields.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -46,6 +49,7 @@ const Foam::Enum > Foam::fv::cellSetOption::selectionModeTypeNames_ ({ + { selectionModeType::smGeometric, "geometric" }, { selectionModeType::smPoints, "points" }, { selectionModeType::smCellSet, "cellSet" }, { selectionModeType::smCellZone, "cellZone" }, @@ -59,6 +63,11 @@ void Foam::fv::cellSetOption::setSelection(const dictionary& dict) { switch (selectionMode_) { + case smGeometric: + { + geometricSelection_ = dict.subDict("selection"); + break; + } case smPoints: { dict.readEntry("points", points_); @@ -66,12 +75,12 @@ void Foam::fv::cellSetOption::setSelection(const dictionary& dict) } case smCellSet: { - dict.readEntry("cellSet", cellSetName_); + dict.readEntry("cellSet", zoneName_); break; } case smCellZone: { - dict.readEntry("cellZone", cellSetName_); + dict.readEntry("cellZone", zoneName_); break; } case smAll: @@ -95,7 +104,7 @@ void Foam::fv::cellSetOption::setVol() { // Set volume information - scalar sumVol = 0.0; + scalar sumVol = 0; for (const label celli : cells_) { sumVol += mesh_.V()[celli]; @@ -122,28 +131,62 @@ void Foam::fv::cellSetOption::setCellSelection() { switch (selectionMode_) { + case smGeometric: + { + // Modify bitSet via topoSetCellSource + cellBitSet selectedCells(mesh_); + + Info<< indent << "- selecting cells geometrically" << endl; + + for (const entry& dEntry : geometricSelection_) + { + if (!dEntry.isDict()) + { + WarningInFunction + << "Ignoring non-dictionary entry " + << dEntry << endl; + continue; + } + + const dictionary& spec = dEntry.dict(); + + auto source = topoSetCellSource::New + ( + spec.get("source"), + mesh_, + spec.optionalSubDict("sourceInfo") + ); + // source->verbose(false); + + source->applyToSet(topoSetSource::ADD, selectedCells); + } + + // Retrieve bitSet + cells_ = selectedCells.addressing().sortedToc(); + break; + } case smPoints: { Info<< indent << "- selecting cells using points" << endl; labelHashSet selectedCells; - forAll(points_, i) + for (const point& p : points_) { - label celli = mesh_.findCell(points_[i]); - if (celli >= 0) + const label celli = mesh_.findCell(p); + + const bool found = (celli >= 0); + + if (found) { selectedCells.insert(celli); } - label globalCelli = returnReduce(celli, maxOp