From ef6fa8007a9d3faa613a81e88f928f64bf31244d Mon Sep 17 00:00:00 2001 From: Kutalmis Bercin Date: Mon, 17 Jul 2023 16:41:29 +0100 Subject: [PATCH] ENH: cellSetOption: enable dictionary-based updates of selections --- src/fvOptions/cellSetOption/cellSetOption.C | 33 ++++++---- src/fvOptions/cellSetOption/cellSetOption.H | 69 ++++++++++++--------- 2 files changed, 61 insertions(+), 41 deletions(-) diff --git a/src/fvOptions/cellSetOption/cellSetOption.C b/src/fvOptions/cellSetOption/cellSetOption.C index 297f13e8b7..87a9461a2a 100644 --- a/src/fvOptions/cellSetOption/cellSetOption.C +++ b/src/fvOptions/cellSetOption/cellSetOption.C @@ -359,9 +359,10 @@ Foam::fv::cellSetOption::cellSetOption ) : fv::option(name, modelType, dict, mesh), + selectionMode_(selectionModeTypeNames_.get("selectionMode", coeffs_)), + updateSelection_(false), timeStart_(-1), duration_(0), - selectionMode_(selectionModeTypeNames_.get("selectionMode", coeffs_)), selectionNames_(), points_(), movingPoints_(), @@ -423,19 +424,29 @@ bool Foam::fv::cellSetOption::isActive() bool Foam::fv::cellSetOption::read(const dictionary& dict) { - if (fv::option::read(dict)) + if (!fv::option::read(dict)) { - timeStart_ = -1; - - if (coeffs_.readIfPresent("timeStart", timeStart_)) - { - coeffs_.readEntry("duration", duration_); - } - - return true; + return false; } - return false; + timeStart_ = -1; + + if (coeffs_.readIfPresent("timeStart", timeStart_)) + { + coeffs_.readEntry("duration", duration_); + } + + // Do not read and set selections unless users request + updateSelection_ = coeffs_.getOrDefault("updateSelection", false); + + if (updateSelection_) + { + setSelection(coeffs_); + setCellSelection(); + setVol(); + } + + return true; } diff --git a/src/fvOptions/cellSetOption/cellSetOption.H b/src/fvOptions/cellSetOption/cellSetOption.H index 0157ccb5e4..aa020ef849 100644 --- a/src/fvOptions/cellSetOption/cellSetOption.H +++ b/src/fvOptions/cellSetOption/cellSetOption.H @@ -34,29 +34,27 @@ Description Usage Minimal example by using \c constant/fvOptions: \verbatim - + fvOption1 { - // Mandatory/Optional (inherited) entries - ... + // Mandatory entries + selectionMode ; - // Mandatory entries (unmodifiable) - selectionMode all; + // Optional entries + timeStart ; + updateSelection ; - // Optional entries (runtime modifiable) - timeStart 1.0; - - // Conditional mandatory entries (runtime modifiable) + // Conditional entries // when timeStart entry is present - duration 1.4; + duration ; // when selectionMode=cellSet - cellSet ; + cellSet ; // when selectionMode=cellZone - cellZone ; + cellZone ; - //OR: cellZones ( ...); + //OR: cellZones ( ...); // when selectionMode=points points ( ... ); @@ -74,6 +72,8 @@ Usage // when selectionMode=geometric selection { + topoSet1 ; + box1 { action use; @@ -91,26 +91,27 @@ Usage ... } - // Mandatory/Optional (derived) entries + // Inherited entries ... } \endverbatim where the entries mean: \table - Property | Description | Type | Reqd | Dflt + Property | Description | Type | Reqd | Deflt selectionMode | Mode of cell selection - see below | word | yes | - - timeStart | Start time of fvOption | scalar | no | -1 + timeStart | Start time of fvOption | scalar | no | -1 + updateSelection | Flag to enable selection updates | bool | no | false duration | Duration of fvOption execution starting from timeStart | scalar | cndtnl | 0 - cellSet | Name of operand cellSet | word | cndtnl | - - cellZone | Name of operand cellZone | wordRe | cndtnl | - - cellZones | Name of operand cellZones | wordRes | cndtnl | - + --> starting from timeStart | scalar | choice | 0 + cellSet | Name of operand cellSet | word | choice | - + cellZone | Name of operand cellZone | wordRe | choice | - + cellZones | Name of operand cellZones | wordRes | choice | - points | Set of points in global coordinate system | vectorList | cndtnl | - + --> system | vectorList | choice | - movingPoints | Set of moving points in global coordinate system | Function1\ | choice | - - selection | Dictionary of geometric selections | dict | cndtnl | - + selection | Dictionary of geometric selections | dict | choice | - \endtable Options for the \c selectionMode entry: @@ -127,12 +128,11 @@ Usage - \link fvOption.H \endlink - \link Function1.H \endlink - The geometric selection uses topoSetCellSource to select cells. - Any searchableSurface selections must describe a closed volume. - Ie, its hasVolumeType() method must be true. - Note - Source/sink options are to be added to the right-hand side of equations. + - The geometric selection uses \c topoSetCellSource to select cells. + Any \c searchableSurface selections must describe a closed volume. + Ie, its \c hasVolumeType() method must be \c true. See also Foam::cellBitSet::select @@ -171,7 +171,7 @@ public: // Public Data //- Enumeration for selection mode types - enum selectionModeType + enum selectionModeType : char { smAll, //!< "all" cells smCellSet, //!< "cellSet" @@ -190,15 +190,18 @@ protected: // Protected Data + //- Cell selection mode + selectionModeType selectionMode_; + + //- Flag to enable dictionary-based updates of selections + bool updateSelection_; + //- Start time of fvOption scalar timeStart_; //- Duration of fvOption execution starting from timeStart scalar duration_; - //- Cell selection mode - selectionModeType selectionMode_; - //- Face selection names (for set or zone selections) wordRes selectionNames_; @@ -284,6 +287,12 @@ public: //- Return const access to the cell selection inline const labelList& cells() const noexcept; + //- Return flag for selection updates + bool isSelectionUpdated() const noexcept + { + return updateSelection_; + } + // Edit