cellCentreSet.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2018-2020 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "cellCentreSet.H"
29#include "meshSearch.H"
30#include "polyMesh.H"
31#include "volFields.H"
32#include "globalIndex.H"
34
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
41}
42
43
44// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45
46void Foam::cellCentreSet::genSamples()
47{
48 const label len = mesh().nCells();
49
50 const globalIndex globalSampleNumbers(len);
51
52 const auto& cellCentres =
53 refCast<const fvMesh>(mesh()).C().primitiveField();
54
55 labelList selectedCells = identity(len);
56 List<point> selectedPoints;
57
58 if (bounds_.empty())
59 {
60 selectedPoints = cellCentres;
61 }
62 else
63 {
64 label count = 0;
65 for (label celli=0; celli < len; ++celli)
66 {
67 if (bounds_.contains(cellCentres[celli]))
68 {
69 selectedCells[count++] = celli;
70 }
71 }
72
73 selectedCells.resize(count);
74 selectedPoints = UIndirectList<point>(cellCentres, selectedCells);
75 }
76
77 labelList samplingFaces(selectedCells.size(), -1);
78 labelList samplingSegments(selectedCells.size(), Zero);
79 scalarList samplingCurveDist(selectedCells.size());
80
81 forAll(selectedCells, i)
82 {
83 samplingCurveDist[i] = globalSampleNumbers.toGlobal(selectedCells[i]);
84 }
85
86 // Move into *this
88 (
89 std::move(selectedPoints),
90 std::move(selectedCells),
91 std::move(samplingFaces),
92 std::move(samplingSegments),
93 std::move(samplingCurveDist)
94 );
95
96 if (debug)
97 {
98 write(Info);
99 }
100}
101
102
103// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
104
106(
107 const word& name,
108 const polyMesh& mesh,
109 const meshSearch& searchEngine,
110 const word& axis,
111 const boundBox& bbox
112)
113:
114 sampledSet(name, mesh, searchEngine, axis),
115 bounds_(bbox)
116{
117 genSamples();
118}
119
120
122(
123 const word& name,
124 const polyMesh& mesh,
125 const meshSearch& searchEngine,
126 const dictionary& dict
127)
128:
130 (
131 name,
132 mesh,
133 searchEngine,
134 dict.getOrDefault<word>("axis", "xyz")
135 ),
136 bounds_(dict.getOrDefault("bounds", boundBox::invertedBox))
137{
138 genSamples();
139}
140
141
142// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:64
bool contains(const point &pt) const
Contains point? (inside or on edge)
Definition: boundBoxI.H:271
bool empty() const
Bounding box is inverted, contains no points.
Definition: boundBoxI.H:62
A sampleSet based on cell centres.
Definition: cellCentreSet.H:82
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search.
Definition: meshSearch.H:61
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
label nCells() const noexcept
Number of mesh cells.
int count() const noexcept
Return the current reference count.
Definition: refCount.H:74
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:86
void setSamples(const List< point > &samplingPts, const labelList &samplingCells, const labelList &samplingFaces, const labelList &samplingSegments, const scalarList &samplingDistance)
Set sample data. Copy list contents.
Definition: sampledSet.C:379
const polyMesh & mesh() const noexcept
Definition: sampledSet.H:319
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
Namespace for OpenFOAM.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
Definition: labelList.C:38
List< label > labelList
A List of labels.
Definition: List.H:66
messageStream Info
Information stream (stdout output on master, null elsewhere)
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:64
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
runTime write()
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333