pointZone.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "pointZone.H"
31 #include "pointZoneMesh.H"
32 #include "polyMesh.H"
33 #include "primitiveMesh.H"
34 #include "syncTools.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(pointZone, 0);
41  defineRunTimeSelectionTable(pointZone, dictionary);
42  addToRunTimeSelectionTable(pointZone, pointZone, dictionary);
43 }
44 
45 const char* const Foam::pointZone::labelsName = "pointLabels";
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
51 :
52  pointZone(word::null, 0, zm)
53 {}
54 
55 
57 (
58  const word& name,
59  const label index,
60  const pointZoneMesh& zm
61 )
62 :
63  zone(name, index),
64  zoneMesh_(zm)
65 {}
66 
67 
69 (
70  const word& name,
71  const labelUList& addr,
72  const label index,
73  const pointZoneMesh& zm
74 )
75 :
76  zone(name, addr, index),
77  zoneMesh_(zm)
78 {}
79 
80 
82 (
83  const word& name,
84  labelList&& addr,
85  const label index,
86  const pointZoneMesh& zm
87 )
88 :
89  zone(name, std::move(addr), index),
90  zoneMesh_(zm)
91 {}
92 
93 
95 (
96  const word& name,
97  const dictionary& dict,
98  const label index,
99  const pointZoneMesh& zm
100 )
101 :
102  zone(name, dict, this->labelsName, index),
103  zoneMesh_(zm)
104 {}
105 
106 
108 (
109  const pointZone& originalZone,
110  const Foam::zero,
111  const pointZoneMesh& zm,
112  const label newIndex
113 )
114 :
115  zone(originalZone, labelList(), newIndex),
116  zoneMesh_(zm)
117 {}
118 
119 
121 (
122  const pointZone& originalZone,
123  const Foam::zero,
124  const label index,
125  const pointZoneMesh& zm
126 )
127 :
128  zone(originalZone, labelList(), index),
129  zoneMesh_(zm)
130 {}
131 
132 
134 (
135  const pointZone& originalZone,
136  const labelUList& addr,
137  const label index,
138  const pointZoneMesh& zm
139 )
140 :
141  pointZone(originalZone, Foam::zero{}, index, zm)
142 {
143  labelList::operator=(addr);
144 }
145 
146 
148 (
149  const pointZone& originalZone,
150  labelList&& addr,
151  const label index,
152  const pointZoneMesh& zm
153 )
154 :
155  pointZone(originalZone, Foam::zero{}, index, zm)
156 {
157  labelList::transfer(addr);
158 }
159 
160 
161 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
163 Foam::label Foam::pointZone::whichPoint(const label globalPointID) const
164 {
165  return zone::localID(globalPointID);
166 }
167 
169 bool Foam::pointZone::checkDefinition(const bool report) const
170 {
171  return zone::checkDefinition(zoneMesh_.mesh().points().size(), report);
172 }
173 
174 
175 bool Foam::pointZone::checkParallelSync(const bool report) const
176 {
177  const polyMesh& mesh = zoneMesh().mesh();
178 
179  labelList maxZone(mesh.nPoints(), label(-1));
180  labelList minZone(mesh.nPoints(), labelMax);
181 
182  const labelList& addr = *this;
183 
184  for (const label pointi : addr)
185  {
186  maxZone[pointi] = index();
187  minZone[pointi] = index();
188  }
189  syncTools::syncPointList(mesh, maxZone, maxEqOp<label>(), label(-1));
190  syncTools::syncPointList(mesh, minZone, minEqOp<label>(), labelMax);
191 
192  bool hasError = false;
193 
194  forAll(maxZone, pointi)
195  {
196  // Check point in same (or no) zone on all processors
197  if
198  (
199  (
200  maxZone[pointi] != -1
201  || minZone[pointi] != labelMax
202  )
203  && (maxZone[pointi] != minZone[pointi])
204  )
205  {
206  hasError = true;
207  if (report)
208  {
209  Info<< " ***Problem with pointZone " << index()
210  << " named " << name()
211  << ". Point " << pointi
212  << " at " << mesh.points()[pointi]
213  << " is in zone "
214  << (minZone[pointi] == labelMax ? -1 : minZone[pointi])
215  << " on some processors and in zone "
216  << maxZone[pointi]
217  << " on some other processors." << nl
218  << "(suppressing further warnings)"
219  << endl;
220  }
221  break; // Only report once
222  }
223  }
224 
225  return hasError;
226 }
227 
228 
229 void Foam::pointZone::writeDict(Ostream& os) const
230 {
231  os.beginBlock(name());
232 
233  os.writeEntry("type", type());
235  writeEntry(this->labelsName, os);
236 
237  os.endBlock();
238 }
239 
240 
242 {
243  if (this == &zn)
244  {
245  return; // Self-assignment is a no-op
246  }
248  clearAddressing();
249  labelList::transfer(static_cast<labelList&>(zn));
250  zn.clearAddressing();
251 }
252 
253 
255 {
256  if (this == &zn)
257  {
258  return; // Self-assignment is a no-op
259  }
260 
261  clearAddressing();
262  labelList::operator=(static_cast<const labelList&>(zn));
263 }
264 
265 
267 {
268  clearAddressing();
269  labelList::operator=(addr);
270 }
271 
272 
274 {
275  clearAddressing();
276  labelList::transfer(addr);
277 }
278 
279 
280 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
281 
283 {
284  if (this == &zn)
285  {
286  return; // Self-assignment is a no-op
287  }
288 
289  clearAddressing();
290  labelList::operator=(static_cast<const labelList&>(zn));
291 }
292 
293 
295 {
296  clearAddressing();
297  labelList::operator=(addr);
298 }
299 
300 
302 {
303  clearAddressing();
304  labelList::transfer(addr);
305 }
306 
307 
308 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
309 
310 Foam::Ostream& Foam::operator<<(Ostream& os, const pointZone& zn)
311 {
312  zn.write(os);
314  return os;
315 }
316 
317 
318 // ************************************************************************* //
dictionary dict
void operator=(const pointZone &zn)
Assign addressing, clearing demand-driven data.
Definition: pointZone.C:275
label localID(const label globalID) const
Lookup local address in zone for given global index.
Definition: zone.C:140
void transfer(List< label > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition: List.C:326
label nPoints() const noexcept
Number of mesh points.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:45
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
Definition: pointZone.C:162
Foam::pointZoneMesh.
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:321
pointZone(const pointZone &)=delete
No copy construct.
Macros for easy insertion into run-time selection tables.
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1078
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
void operator=(const UList< label > &list)
Assignment to UList operator. Takes linear time.
Definition: List.C:360
Base class for mesh zones.
Definition: zone.H:59
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:108
virtual bool checkDefinition(const bool report=false) const =0
Check zone definition. Return true if in error.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
void write(Ostream &os) const
Write (physicalType, inGroups) dictionary entries (without surrounding braces)
ZoneMesh< pointZone, polyMesh > pointZoneMesh
A ZoneMesh with the type pointZone.
virtual bool checkParallelSync(const bool report=false) const
Check whether zone is synchronised across coupled boundaries.
Definition: pointZone.C:168
label whichPoint(const label globalPointID) const
Helper function to re-direct to zone::localID(...)
Definition: pointZone.C:156
static void syncPointList(const polyMesh &mesh, List< T > &pointValues, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
virtual void resetAddressing(pointZone &&zn)
Move reset addressing from another zone.
Definition: pointZone.C:234
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
defineTypeNameAndDebug(combustionModel, 0)
static const char *const labelsName
The name associated with the zone-labels dictionary entry ("pointLabels")
Definition: pointZone.H:80
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
virtual void writeDict(Ostream &os) const
Write dictionary.
Definition: pointZone.C:222
A subset of mesh points.
Definition: pointZone.H:61
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:90
constexpr label labelMax
Definition: label.H:55
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
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)