pointZone.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "pointZone.H"
28 #include "pointZoneMesh.H"
29 #include "polyMesh.H"
30 #include "primitiveMesh.H"
31 #include "demandDrivenData.H"
32 #include "syncTools.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(pointZone, 0);
39  defineRunTimeSelectionTable(pointZone, dictionary);
40  addToRunTimeSelectionTable(pointZone, pointZone, dictionary);
41 }
42 
43 const char* const Foam::pointZone::labelsName = "pointLabels";
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
48 (
49  const word& name,
50  const labelUList& addr,
51  const label index,
52  const pointZoneMesh& zm
53 )
54 :
55  zone(name, addr, index),
56  zoneMesh_(zm)
57 {}
58 
59 
61 (
62  const word& name,
63  labelList&& addr,
64  const label index,
65  const pointZoneMesh& zm
66 )
67 :
68  zone(name, move(addr), index),
69  zoneMesh_(zm)
70 {}
71 
72 
74 (
75  const word& name,
76  const dictionary& dict,
77  const label index,
78  const pointZoneMesh& zm
79 )
80 :
81  zone(name, dict, this->labelsName, index),
82  zoneMesh_(zm)
83 {}
84 
85 
87 (
88  const pointZone& pz,
89  const labelUList& addr,
90  const label index,
91  const pointZoneMesh& zm
92 )
93 :
94  zone(pz, addr, index),
95  zoneMesh_(zm)
96 {}
97 
98 
100 (
101  const pointZone& pz,
102  labelList&& addr,
103  const label index,
104  const pointZoneMesh& zm
105 )
106 :
107  zone(pz, move(addr), index),
108  zoneMesh_(zm)
109 {}
110 
111 
112 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
113 
115 {}
116 
117 
118 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
119 
121 {
122  return zoneMesh_;
123 }
124 
125 
127 {
128  return zone::localID(globalPointID);
129 }
130 
131 
132 bool Foam::pointZone::checkDefinition(const bool report) const
133 {
134  return zone::checkDefinition(zoneMesh_.mesh().points().size(), report);
135 }
136 
137 
138 bool Foam::pointZone::checkParallelSync(const bool report) const
139 {
140  const polyMesh& mesh = zoneMesh().mesh();
141 
142  labelList maxZone(mesh.nPoints(), -1);
143  labelList minZone(mesh.nPoints(), labelMax);
144  forAll(*this, i)
145  {
146  label pointi = operator[](i);
147  maxZone[pointi] = index();
148  minZone[pointi] = index();
149  }
150  syncTools::syncPointList(mesh, maxZone, maxEqOp<label>(), label(-1));
152 
153  bool error = false;
154 
155  forAll(maxZone, pointi)
156  {
157  // Check point in same (or no) zone on all processors
158  if
159  (
160  (
161  maxZone[pointi] != -1
162  || minZone[pointi] != labelMax
163  )
164  && (maxZone[pointi] != minZone[pointi])
165  )
166  {
167  if (report && !error)
168  {
169  Info<< " ***Problem with pointZone " << index()
170  << " named " << name()
171  << ". Point " << pointi
172  << " at " << mesh.points()[pointi]
173  << " is in zone "
174  << (minZone[pointi] == labelMax ? -1 : minZone[pointi])
175  << " on some processors and in zone "
176  << maxZone[pointi]
177  << " on some other processors." << nl
178  << "(suppressing further warnings)"
179  << endl;
180  }
181  error = true;
182  }
183  }
184 
185  return error;
186 }
187 
188 
190 {
191  os << nl << name_ << nl << token::BEGIN_BLOCK << nl
192  << " type " << type() << token::END_STATEMENT << nl;
193 
194  writeEntry(os, this->labelsName, *this);
195 
196  os << token::END_BLOCK << endl;
197 }
198 
199 
200 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
201 
203 {
204  clearAddressing();
205  zone::operator=(zn);
206 }
207 
208 
210 {
211  clearAddressing();
212  zone::operator=(move(zn));
213 }
214 
215 
217 {
218  clearAddressing();
219  zone::operator=(addr);
220 }
221 
222 
224 {
225  clearAddressing();
226  zone::operator=(move(addr));
227 }
228 
229 
230 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
231 
233 {
234  zn.write(os);
235  os.check("Ostream& operator<<(Ostream&, const pointZone&");
236  return os;
237 }
238 
239 
240 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
label localID(const label globalID) const
Map storing the local index for every global index. Used to find.
Definition: zone.C:166
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
Definition: pointZone.C:132
Foam::pointZoneMesh.
const pointZoneMesh & zoneMesh() const
Return zoneMesh reference.
Definition: pointZone.C:120
void operator=(const pointZone &)
Assignment to zone, clearing demand-driven data.
Definition: pointZone.C:202
Macros for easy insertion into run-time selection tables.
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1131
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:66
dynamicFvMesh & mesh
Base class for zones.
Definition: zone.H:57
A class for handling words, derived from string.
Definition: word.H:59
virtual bool checkDefinition(const bool report=false) const =0
Check zone definition. Return true if in error.
static const label labelMax
Definition: label.H:62
virtual bool checkParallelSync(const bool report=false) const
Check whether zone is synchronised across coupled boundaries. Return.
Definition: pointZone.C:138
label whichPoint(const label globalPointID) const
Helper function to re-direct to zone::localID(...)
Definition: pointZone.C:126
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
static const char nl
Definition: Ostream.H:260
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
static const char *const labelsName
The name associated with the zone-labels dictionary entry.
Definition: pointZone.H:80
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Template functions to aid in the implementation of demand driven data.
A subset of mesh points. The labels of points in the zone can be obtained from the addressing() list...
Definition: pointZone.H:62
Ostream & operator<<(Ostream &, const ensightPart &)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
virtual void writeDict(Ostream &) const
Write dictionary.
Definition: pointZone.C:189
static void syncPointList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
virtual void write(Ostream &) const
Write.
Definition: zone.C:233
messageStream Info
label nPoints() const
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
pointZone(const word &name, const labelUList &addr, const label index, const pointZoneMesh &)
Construct from components.
Definition: pointZone.C:48
virtual ~pointZone()
Destructor.
Definition: pointZone.C:114
void operator=(const zone &)
Assignment operator.
Definition: zone.C:242
Namespace for OpenFOAM.