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::invertedBox))
137 {
138  genSamples();
139 }
140 
141 
142 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::sampledSet
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:83
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
volFields.H
Foam::scalarList
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:64
Foam::sampledSet::write
Ostream & write(Ostream &) const
Output for debugging.
Definition: sampledSet.C:554
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::meshSearch
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search.
Definition: meshSearch.H:60
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
globalIndex.H
Foam::boundBox::invertedBox
static const boundBox invertedBox
A large inverted boundBox: min/max == +/- ROOTVGREAT.
Definition: boundBox.H:86
Foam::cellCentreSet::cellCentreSet
cellCentreSet(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const word &axis, const boundBox &bbox=boundBox::invertedBox)
Construct from components.
Definition: cellCentreSet.C:106
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::primitiveMesh::nCells
label nCells() const noexcept
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::boundBox::empty
bool empty() const
Bounding box is inverted, contains no points.
Definition: boundBoxI.H:62
Foam::boundBox::contains
bool contains(const point &pt) const
Contains point? (inside or on edge)
Definition: boundBoxI.H:271
Foam::sampledSet::mesh
const polyMesh & mesh() const
Definition: sampledSet.H:281
meshSearch.H
Foam::sampledSet::setSamples
void setSamples(const List< point > &samplingPts, const labelList &samplingCells, const labelList &samplingFaces, const labelList &samplingSegments, const scalarList &samplingCurveDist)
Set sample data. Copy list contents.
Definition: sampledSet.C:382
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
cellCentreSet.H
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:148
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)