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 -------------------------------------------------------------------------------
10 License
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 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(cellCentreSet, 0);
40  addToRunTimeSelectionTable(sampledSet, cellCentreSet, word);
41 }
42 
43 
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 
46 void 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 :
129  sampledSet
130  (
131  name,
132  mesh,
133  searchEngine,
134  dict.getOrDefault<word>("axis", "xyz")
135  ),
136  bounds_(dict.getOrDefault("bounds", boundBox::null()))
137 {
138  genSamples();
139 }
140 
141 
142 // ************************************************************************* //
List< scalar > scalarList
List of scalar.
Definition: scalarList.H:32
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search...
Definition: meshSearch.H:56
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
bool contains(const point &pt) const
Contains point? (inside or on edge)
Definition: boundBoxI.H:455
bool empty() const
Bounding box is inverted, contains no points.
Definition: boundBoxI.H:144
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
Ostream & write(Ostream &) const
Output for debugging.
Definition: sampledSet.C:512
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:79
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
Definition: labelLists.C:44
A class for handling words, derived from Foam::string.
Definition: word.H:63
const polyMesh & mesh() const noexcept
Definition: sampledSet.H:373
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
volScalarField & C
label nCells() const noexcept
Number of mesh cells.
cellCentreSet(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const word &axis, const boundBox &bbox=boundBox::null())
Construct from components.
Definition: cellCentreSet.C:99
messageStream Info
Information stream (stdout output on master, null elsewhere)
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:363
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< label > labelList
A List of labels.
Definition: List.H:62
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127