ENH: cellSetOption: add new selectionMode for moving points

This commit is contained in:
Kutalmis Bercin 2023-07-18 09:21:02 +01:00 committed by Andrew Heather
parent f3d939fa10
commit f54400d5cc
2 changed files with 104 additions and 3 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -52,6 +52,7 @@ Foam::fv::cellSetOption::selectionModeTypeNames_
{ selectionModeType::smAll, "all" },
{ selectionModeType::smGeometric, "geometric" },
{ selectionModeType::smPoints, "points" },
{ selectionModeType::smMovingPoints, "movingPoints" },
{ selectionModeType::smCellSet, "cellSet" },
{ selectionModeType::smCellZone, "cellZone" },
{ selectionModeType::smCellType, "cellType" }
@ -80,6 +81,31 @@ void Foam::fv::cellSetOption::setSelection(const dictionary& dict)
dict.readEntry("points", points_);
break;
}
case smMovingPoints:
{
const dictionary& mpsDict = dict.subDict("movingPoints");
movingPoints_.resize_null(mpsDict.size());
label pointi = 0;
for (const entry& dEntry : mpsDict)
{
const word& key = dEntry.keyword();
movingPoints_.set
(
pointi,
Function1<point>::New
(
key,
mpsDict,
&mesh_
)
);
++pointi;
}
break;
}
case smCellSet:
{
selectionNames_.resize(1);
@ -196,6 +222,50 @@ void Foam::fv::cellSetOption::setCellSelection()
cells_ = selectedCells.sortedToc();
break;
}
case smMovingPoints:
{
Info<< indent << "- selecting cells using moving points" << endl;
const scalar t = mesh_.time().timeOutputValue();
labelHashSet selectedCells;
forAll(movingPoints_, i)
{
if (!movingPoints_.set(i))
{
continue;
}
const point p(movingPoints_[i].value(t));
const label celli = mesh_.findCell(p);
const bool found = (celli >= 0);
// Ensure that only one processor inserts this cell
label proci = -1;
if (found)
{
proci = Pstream::myProcNo();
}
reduce(proci, maxOp<label>());
if (found && (proci == Pstream::myProcNo()))
{
selectedCells.insert(celli);
}
if (!returnReduceOr(found))
{
WarningInFunction
<< "No owner cell found for point " << p << endl;
}
}
cells_ = selectedCells.sortedToc();
break;
}
case smCellSet:
{
Info<< indent
@ -266,7 +336,11 @@ void Foam::fv::cellSetOption::setCellSelection()
}
}
if (smAll != selectionMode_ && returnReduceAnd(cells_.empty()))
if
(
!(smAll == selectionMode_ || smMovingPoints == selectionMode_)
&& returnReduceAnd(cells_.empty())
)
{
WarningInFunction
<< "No cells selected!" << endl;
@ -290,6 +364,7 @@ Foam::fv::cellSetOption::cellSetOption
selectionMode_(selectionModeTypeNames_.get("selectionMode", coeffs_)),
selectionNames_(),
points_(),
movingPoints_(),
geometricSelection_(),
V_(0)
{
@ -322,6 +397,7 @@ bool Foam::fv::cellSetOption::isActive()
selectionMode_ == smGeometric
|| selectionMode_ == smPoints
|| selectionMode_ == smCellType
|| selectionMode_ == smMovingPoints
)
{
// Geometric selection mode(s)
@ -331,6 +407,12 @@ bool Foam::fv::cellSetOption::isActive()
// Report new volume (if changed)
setVol();
}
else if (selectionMode_ == smMovingPoints)
{
// Update the cell selection if it moves
setCellSelection();
setVol();
}
return true;
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -61,6 +61,16 @@ Usage
// when selectionMode=points
points (<point1> <point2> ... <pointN>);
// when selectionMode=movingPoints
movingPoints
(
<word> <Function1<vector>>;
// e.g.
point1 <Function1<vector>>;
pointN <Function1<vector>>;
...
);
// when selectionMode=geometric
selection
{
@ -98,6 +108,8 @@ Usage
cellZones | Name of operand cellZones | wordRes | cndtnl | -
points | Set of points in global coordinate <!--
--> system | vectorList | cndtnl | -
movingPoints | Set of moving points in global coordinate system <!--
--> | Function1\<vector\> | choice | -
selection | Dictionary of geometric selections | dict | cndtnl | -
\endtable
@ -107,11 +119,13 @@ Usage
cellZone | Use specified cellZone
cellSet | Use specified cellSet
points | Use cells containing a given set of points
movingPoints | Use cells containing a given set of moving points
geometric | Select cells based on topoSetCellSource actions
\endverbatim
The inherited entries are elaborated in:
- \link fvOption.H \endlink
- \link Function1.H \endlink
The geometric selection uses topoSetCellSource to select cells.
Any searchableSurface selections must describe a closed volume.
@ -135,6 +149,7 @@ SourceFiles
#include "fvMesh.H"
#include "dictionary.H"
#include "Time.H"
#include "Function1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -162,6 +177,7 @@ public:
smCellSet, //!< "cellSet"
smCellZone, //!< "cellZone"
smPoints, //!< "points"
smMovingPoints, //!< "movingPoints"
smGeometric, //!< "geometric"
smCellType //!< "overset type cells"
};
@ -189,6 +205,9 @@ protected:
//- List of points for "points" selectionMode
List<point> points_;
//- List of points for "movingPoints" selectionMode
PtrList<Function1<point>> movingPoints_;
//- Dictionary entries for "geometric" (topoSetCellSource) selection
dictionary geometricSelection_;