Commit 6090faed authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: additional topoSources, and consistency changes (#1060)

- faceBitSet, pointBitSet and faceBoolSet (similar to cellBitSet)
  * allows topo sources in a wider variety of places.
  * With copy or move constructors.

- cylinderToPoint, searchableSurfaceToFace, searchableSurfaceToPoint,
  sphereToFace, sphereToPoint sources

- optional innerRadius for sphere and cylinder sources to treat as hollow.

- support "sets" as well as "set" for cellToCell, faceToFace... sources.

  * convenience and avoids writing the set during processing.
parent 644c0f4a
......@@ -157,6 +157,12 @@ public:
selectedCells_(selectedCells)
{}
iNew(const fvMesh& mesh, labelList&& selectedCells)
:
mesh_(mesh),
selectedCells_(std::move(selectedCells))
{}
autoPtr<setCellField> operator()(Istream& fieldValues) const
{
word fieldType(fieldValues);
......@@ -348,6 +354,12 @@ public:
selectedFaces_(selectedFaces)
{}
iNew(const fvMesh& mesh, labelList&& selectedFaces)
:
mesh_(mesh),
selectedFaces_(std::move(selectedFaces))
{}
autoPtr<setFaceField> operator()(Istream& fieldValues) const
{
word fieldType(fieldValues);
......@@ -438,7 +450,7 @@ int main(int argc, char *argv[])
PtrList<setCellField> fieldValues
(
region.dict().lookup("fieldValues"),
setCellField::iNew(mesh, selectedCellSet.toc())
setCellField::iNew(mesh, selectedCellSet.sortedToc())
);
}
else if (source().setType() == topoSetSource::FACESETSOURCE)
......@@ -459,7 +471,7 @@ int main(int argc, char *argv[])
PtrList<setFaceField> fieldValues
(
region.dict().lookup("fieldValues"),
setFaceField::iNew(mesh, selectedFaceSet.toc())
setFaceField::iNew(mesh, selectedFaceSet.sortedToc())
);
}
}
......
......@@ -136,12 +136,17 @@ searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C
topoSets = sets/topoSets
$(topoSets)/cellBitSet.C
$(topoSets)/cellSet.C
$(topoSets)/topoSet.C
$(topoSets)/faceSet.C
$(topoSets)/pointSet.C
$(topoSets)/cellZoneSet.C
$(topoSets)/faceBitSet.C
$(topoSets)/faceBoolSet.C
$(topoSets)/faceSet.C
$(topoSets)/faceZoneSet.C
$(topoSets)/pointBitSet.C
$(topoSets)/pointSet.C
$(topoSets)/pointZoneSet.C
$(topoSets)/topoBoolSet.C
$(topoSets)/topoBitSet.C
$(topoSets)/topoSet.C
sets/topoSetSource/topoSetSource.C
......@@ -180,16 +185,21 @@ $(faceSources)/normalToFace/normalToFace.C
$(faceSources)/patchToFace/patchToFace.C
$(faceSources)/pointToFace/pointToFace.C
$(faceSources)/regionToFace/regionToFace.C
$(faceSources)/searchableSurfaceToFace/searchableSurfaceToFace.C
$(faceSources)/sphereToFace/sphereToFace.C
$(faceSources)/zoneToFace/zoneToFace.C
pointSources = sets/pointSources
$(pointSources)/topoSetPointSource/topoSetPointSource.C
$(pointSources)/boxToPoint/boxToPoint.C
$(pointSources)/cellToPoint/cellToPoint.C
$(pointSources)/cylinderToPoint/cylinderToPoint.C
$(pointSources)/faceToPoint/faceToPoint.C
$(pointSources)/labelToPoint/labelToPoint.C
$(pointSources)/nearestToPoint/nearestToPoint.C
$(pointSources)/pointToPoint/pointToPoint.C
$(pointSources)/searchableSurfaceToPoint/searchableSurfaceToPoint.C
$(pointSources)/sphereToPoint/sphereToPoint.C
$(pointSources)/surfaceToPoint/surfaceToPoint.C
$(pointSources)/zoneToPoint/zoneToPoint.C
......
......@@ -67,13 +67,13 @@ void Foam::boxToCell::combine(topoSet& set, const bool add) const
{
const pointField& ctrs = mesh_.cellCentres();
forAll(ctrs, celli)
forAll(ctrs, elemi)
{
for (const auto& bb : bbs_)
{
if (bb.contains(ctrs[celli]))
if (bb.contains(ctrs[elemi]))
{
addOrDelete(set, celli, add);
addOrDelete(set, elemi, add);
break;
}
}
......
......@@ -37,8 +37,8 @@ Description
\endtable
Note
In the order of highest to lowest precedence, must specify "boxes",
"box" or a "min/max" pair (compatibility with searchable box).
Must specify "boxes", "box" or a "min/max" pair
(compatibility with searchable box) - highest to lowest precedence.
SourceFiles
boxToCell.C
......
......@@ -57,7 +57,7 @@ Foam::cellToCell::cellToCell
)
:
topoSetCellSource(mesh),
setName_(setName)
names_(one(), setName)
{}
......@@ -67,12 +67,16 @@ Foam::cellToCell::cellToCell
const dictionary& dict
)
:
cellToCell
(
mesh,
dict.get<word>("set")
)
{}
topoSetCellSource(mesh),
names_()
{
// Look for 'sets' or 'set'
if (!dict.readIfPresent("sets", names_))
{
names_.resize(1);
dict.readEntry("set", names_.first());
}
}
Foam::cellToCell::cellToCell
......@@ -82,7 +86,7 @@ Foam::cellToCell::cellToCell
)
:
topoSetCellSource(mesh),
setName_(checkIs(is))
names_(one(), word(checkIs(is)))
{}
......@@ -98,27 +102,31 @@ void Foam::cellToCell::applyToSet
{
if (verbose_)
{
Info<< " Adding all elements of cellSet " << setName_
<< " ..." << endl;
Info<< " Adding all elements of cellSet "
<< flatOutput(names_) << nl;
}
// Load the set
cellSet loadedSet(mesh_, setName_);
for (const word& setName : names_)
{
cellSet loadedSet(mesh_, setName);
set.addSet(loadedSet);
set.addSet(loadedSet);
}
}
else if (action == topoSetSource::SUBTRACT)
{
if (verbose_)
{
Info<< " Removing all elements of cellSet " << setName_
<< " ..." << endl;
Info<< " Removing all elements of cellSet "
<< flatOutput(names_) << nl;
}
// Load the set
cellSet loadedSet(mesh_, setName_);
for (const word& setName : names_)
{
cellSet loadedSet(mesh_, setName);
set.subtractSet(loadedSet);
set.subtractSet(loadedSet);
}
}
}
......
......@@ -29,10 +29,14 @@ Description
\heading Dictionary parameters
\table
Property | Description | Required | Default
set | The cell set name | yes |
Property | Description | Required | Default
sets | The input cellSet names | possibly |
set | The input cellSet name | possibly |
\endtable
Note
Must specify "sets" or "set" (highest to lowest precedence).
SourceFiles
cellToCell.C
......@@ -61,8 +65,9 @@ class cellToCell
//- Add usage string
static addToUsageTable usage_;
//- Name of set to use
word setName_;
//- Names of sets to use
wordList names_;
public:
......
......@@ -76,16 +76,18 @@ Foam::topoSetSource::addToUsageTable Foam::cylinderAnnulusToCell::usage_
void Foam::cylinderAnnulusToCell::combine(topoSet& set, const bool add) const
{
const pointField& ctrs = mesh_.cellCentres();
const vector axis = (point2_ - point1_);
const scalar orad2 = sqr(outerRadius_);
const scalar irad2 = sqr(innerRadius_);
const scalar magAxis2 = magSqr(axis);
const scalar orad2 = sqr(radius_);
const scalar irad2 = innerRadius_ > 0 ? sqr(innerRadius_) : -1;
const pointField& ctrs = mesh_.cellCentres();
// Treat innerRadius == 0 like unspecified innerRadius (always accept)
forAll(ctrs, celli)
forAll(ctrs, elemi)
{
const vector d = ctrs[celli] - point1_;
const vector d = ctrs[elemi] - point1_;
const scalar magD = d & axis;
if ((magD > 0) && (magD < magAxis2))
......@@ -93,7 +95,7 @@ void Foam::cylinderAnnulusToCell::combine(topoSet& set, const bool add) const
const scalar d2 = (d & d) - sqr(magD)/magAxis2;
if ((d2 < orad2) && (d2 > irad2))
{
addOrDelete(set, celli, add);
addOrDelete(set, elemi, add);
}
}
}
......@@ -107,14 +109,14 @@ Foam::cylinderAnnulusToCell::cylinderAnnulusToCell
const polyMesh& mesh,
const point& point1,
const point& point2,
const scalar outerRadius,
const scalar radius,
const scalar innerRadius
)
:
topoSetCellSource(mesh),
point1_(point1),
point2_(point2),
outerRadius_(outerRadius),
radius_(radius),
innerRadius_(innerRadius)
{}
......@@ -145,7 +147,7 @@ Foam::cylinderAnnulusToCell::cylinderAnnulusToCell
topoSetCellSource(mesh),
point1_(checkIs(is)),
point2_(checkIs(is)),
outerRadius_(readScalar(checkIs(is))),
radius_(readScalar(checkIs(is))),
innerRadius_(readScalar(checkIs(is)))
{}
......@@ -164,7 +166,7 @@ void Foam::cylinderAnnulusToCell::applyToSet
{
Info<< " Adding cells with centre within cylinder annulus,"
<< " with p1 = " << point1_ << ", p2 = " << point2_
<< ", radius = " << outerRadius_
<< ", radius = " << radius_
<< ", inner radius = " << innerRadius_
<< endl;
}
......@@ -177,7 +179,7 @@ void Foam::cylinderAnnulusToCell::applyToSet
{
Info<< " Removing cells with centre within cylinder annulus,"
<< " with p1 = " << point1_ << ", p2 = " << point2_
<< ", radius = " << outerRadius_
<< ", radius = " << radius_
<< ", inner radius = " << innerRadius_
<< endl;
}
......
......@@ -31,10 +31,10 @@ Description
\heading Dictionary parameters
\table
Property | Description | Required | Default
p1 | coordinate of endpoint | yes |
p2 | coordinate of endpoint | yes |
outerRadius | cylinder outer radius | yes |
innerRadius | cylinder inner radius | yes |
p1 | Coordinate of endpoint | yes |
p2 | Coordinate of endpoint | yes |
outerRadius | Cylinder outer radius | yes |
innerRadius | Cylinder inner radius | yes |
\endtable
SourceFiles
......@@ -72,10 +72,10 @@ class cylinderAnnulusToCell
//- Second point on cylinder axis
point point2_;
//- Outer Radius
scalar outerRadius_;
//- Outer radius
scalar radius_;
//- Inner Radius
//- Inner radius
scalar innerRadius_;
......@@ -98,7 +98,7 @@ public:
const polyMesh& mesh,
const point& point1,
const point& point2,
const scalar outerRadius,
const scalar radius,
const scalar innerRadius = 0
);
......
......@@ -65,23 +65,26 @@ Foam::topoSetSource::addToUsageTable Foam::cylinderToCell::usage_
void Foam::cylinderToCell::combine(topoSet& set, const bool add) const
{
const pointField& ctrs = mesh_.cellCentres();
const vector axis = (point2_ - point1_);
const scalar rad2 = sqr(radius_);
const scalar magAxis2 = magSqr(axis);
const scalar orad2 = sqr(radius_);
const scalar irad2 = innerRadius_ > 0 ? sqr(innerRadius_) : -1;
const pointField& ctrs = mesh_.cellCentres();
// Treat innerRadius == 0 like unspecified innerRadius (always accept)
forAll(ctrs, celli)
forAll(ctrs, elemi)
{
const vector d = ctrs[celli] - point1_;
const vector d = ctrs[elemi] - point1_;
const scalar magD = d & axis;
if ((magD > 0) && (magD < magAxis2))
{
const scalar d2 = (d & d) - sqr(magD)/magAxis2;
if (d2 < rad2)
if ((d2 < orad2) && (d2 > irad2))
{
addOrDelete(set, celli, add);
addOrDelete(set, elemi, add);
}
}
}
......@@ -95,13 +98,15 @@ Foam::cylinderToCell::cylinderToCell
const polyMesh& mesh,
const point& point1,
const point& point2,
const scalar radius
const scalar radius,
const scalar innerRadius
)
:
topoSetCellSource(mesh),
point1_(point1),
point2_(point2),
radius_(radius)
radius_(radius),
innerRadius_(innerRadius)
{}
......@@ -116,7 +121,8 @@ Foam::cylinderToCell::cylinderToCell
mesh,
dict.get<point>("p1"),
dict.get<point>("p2"),
dict.get<scalar>("radius")
dict.get<scalar>("radius"),
dict.lookupOrDefault<scalar>("innerRadius", 0)
)
{}
......@@ -130,7 +136,8 @@ Foam::cylinderToCell::cylinderToCell
topoSetCellSource(mesh),
point1_(checkIs(is)),
point2_(checkIs(is)),
radius_(readScalar(checkIs(is)))
radius_(readScalar(checkIs(is))),
innerRadius_(0)
{}
......@@ -146,9 +153,16 @@ void Foam::cylinderToCell::applyToSet
{
if (verbose_)
{
Info<< " Adding cells with centre within cylinder, with p1 = "
<< point1_ << ", p2 = " << point2_ << ", radius = " << radius_
<< endl;
Info<< " Adding cells with centre within cylinder,"
<< " with p1 = " << point1_ << ", p2 = " << point2_
<< ", radius = " << radius_;
if (innerRadius_ > 0)
{
Info<< ", innerRadius = " << innerRadius_;
}
Info<< endl;
}
combine(set, true);
......@@ -157,9 +171,16 @@ void Foam::cylinderToCell::applyToSet
{
if (verbose_)
{
Info<< " Removing cells with centre within cylinder, with p1 = "
<< point1_ << ", p2 = " << point2_ << ", radius = " << radius_
<< endl;
Info<< " Removing cells with centre within cylinder,"
<< " with p1 = " << point1_ << ", p2 = " << point2_
<< ", radius = " << radius_;
if (innerRadius_ > 0)
{
Info<< ", innerRadius = " << innerRadius_;
}
Info<< endl;
}
combine(set, false);
......
......@@ -29,10 +29,11 @@ Description
\heading Dictionary parameters
\table
Property | Description | Required | Default
p1 | coordinate of endpoint | yes |
p2 | coordinate of endpoint | yes |
radius | cylinder radius | yes |
Property | Description | Required | Default
p1 | Coordinate of endpoint | yes |
p2 | Coordinate of endpoint | yes |
radius | Cylinder (outer) radius | yes |
innerRadius | Cylinder inner radius | no | 0
\endtable
SourceFiles
......@@ -70,9 +71,12 @@ class cylinderToCell
//- Second point on cylinder axis
point point2_;
//- Radius
//- Outer radius
scalar radius_;
//- Inner radius
scalar innerRadius_;
// Private Member Functions
......@@ -93,7 +97,8 @@ public:
const polyMesh& mesh,
const point& point1,
const point& point2,
const scalar radius
const scalar radius,
const scalar innerRadius = 0
);
//- Construct from dictionary
......
......@@ -63,10 +63,15 @@ Foam::faceToCell::faceActionNames_
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::faceToCell::combine(topoSet& set, const bool add) const
void Foam::faceToCell::combine
(
topoSet& set,
const bool add,
const word& setName
) const
{
// Load the set
faceSet loadedSet(mesh_, setName_);
faceSet loadedSet(mesh_, setName);
const labelHashSet& faceLabels = loadedSet;
......@@ -136,7 +141,7 @@ Foam::faceToCell::faceToCell
)
:
topoSetCellSource(mesh),
setName_(setName),
names_(one(), setName),
option_(option)
{}
......@@ -147,13 +152,17 @@ Foam::faceToCell::faceToCell
const dictionary& dict
)
:
faceToCell
(
mesh,
dict.get<word>("set"),
faceActionNames_.get("option", dict)
)
{}
topoSetCellSource(mesh),
names_(),
option_(faceActionNames_.get("option", dict))
{
// Look for 'sets' or 'set'
if (!dict.readIfPresent("sets", names_))
{
names_.resize(1);
dict.readEntry("set", names_.first());
}
}
Foam::faceToCell::faceToCell
......@@ -163,7 +172,7 @@ Foam::faceToCell::faceToCell
)
:
topoSetCellSource(mesh),
setName_(checkIs(is)),
names_(one(), word(checkIs(is))),
option_(faceActionNames_.read(checkIs(is)))
{}
......@@ -180,21 +189,27 @@ void Foam::faceToCell::applyToSet
{
if (verbose_)
{
Info<< " Adding cells according to faceSet " << setName_
<< " ..." << endl;
Info<< " Adding cells according to faceSet "
<< flatOutput(names_) << nl;
}
combine(set, true);
for (const word& setName : names_)
{
combine(set, true, setName);
}
}
else if (action == topoSetSource::SUBTRACT)
{
if (verbose_)
{
Info<< " Removing cells according to faceSet " << setName_
<< " ..." << endl;
Info<< " Removing cells according to faceSet "
<< flatOutput(names_) << nl;
}
combine(set, false);
for (const word& setName : names_)
{
combine(set, false, setName);
}
}
}
......
......@@ -29,11 +29,15 @@ Description
\heading Dictionary parameters
\table
Property | Description | Required | Default
set | The face set name to use | yes |
Property | Description | Required | Default
sets | The faceSet names to use | possibly |
set | The faceSet name to use | possibly |
option | Selection type (all/any/owner/neighbour) | yes |
\endtable
Note
Must specify "sets" or "set" (highest to lowest precedence).
SourceFiles
faceToCell.C
......@@ -76,8 +80,8 @@ private:
//- Add usage string
static addToUsageTable usage_;
//- Name of set to use