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-2025 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"
30 #include "pointZoneMesh.H"
31 #include "polyMesh.H"
32 #include "syncTools.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(pointZone, 0);
42 }
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
48 :
49  zone(),
50  zoneMesh_(zm)
51 {}
52 
53 
55 (
56  const word& name,
57  const label index,
58  const pointZoneMesh& zm
59 )
60 :
61  zone(name, index),
62  zoneMesh_(zm)
63 {}
64 
65 
67 (
68  const word& name,
69  const labelUList& addr,
70  const label index,
71  const pointZoneMesh& zm
72 )
73 :
74  zone(name, addr, index),
75  zoneMesh_(zm)
76 {}
77 
78 
80 (
81  const word& name,
82  labelList&& addr,
83  const label index,
84  const pointZoneMesh& zm
85 )
86 :
87  zone(name, std::move(addr), index),
88  zoneMesh_(zm)
89 {}
90 
91 
93 (
94  const word& name,
95  const dictionary& dict,
96  const label index,
97  const pointZoneMesh& zm
98 )
99 :
100  zone(name, dict, pointZone::labelsName(), index),
101  zoneMesh_(zm)
102 {}
103 
104 
106 (
107  const pointZone& originalZone,
108  const pointZoneMesh& zm,
109  const label newIndex
110 )
111 :
112  zone(originalZone, newIndex),
113  zoneMesh_(zm)
114 {}
115 
116 
118 (
119  const pointZone& originalZone,
120  Foam::zero,
121  const pointZoneMesh& zm,
122  const label newIndex
123 )
124 :
125  zone(originalZone, labelList(), newIndex),
126  zoneMesh_(zm)
127 {}
128 
129 
131 (
132  const pointZone& originalZone,
133  Foam::zero,
134  const label newIndex,
135  const pointZoneMesh& zm
136 )
137 :
138  zone(originalZone, labelList(), newIndex),
139  zoneMesh_(zm)
140 {}
141 
142 
144 (
145  const pointZone& originalZone,
146  const labelUList& addr,
147  const label index,
148  const pointZoneMesh& zm
149 )
150 :
151  pointZone(originalZone, Foam::zero{}, index, zm)
152 {
153  labelList::operator=(addr);
154 }
155 
156 
158 (
159  const pointZone& originalZone,
160  labelList&& addr,
161  const label index,
162  const pointZoneMesh& zm
163 )
164 :
165  pointZone(originalZone, Foam::zero{}, index, zm)
166 {
167  labelList::transfer(addr);
168 }
169 
170 
171 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
172 
173 Foam::label Foam::pointZone::max_index() const noexcept
174 {
175  return zoneMesh_.mesh().nPoints();
176 }
177 
178 
179 // void Foam::pointZone::sort()
180 // {
181 // clearAddressing();
182 // Foam::sort(static_cast<labelList&>(*this));
183 // }
184 
185 
186 bool Foam::pointZone::checkParallelSync(const bool report) const
187 {
188  const polyMesh& mesh = zoneMesh().mesh();
189 
190  labelList maxZone(mesh.nPoints(), label(-1));
191  labelList minZone(mesh.nPoints(), labelMax);
192 
193  const labelList& addr = *this;
194 
195  for (const label pointi : addr)
196  {
197  maxZone[pointi] = index();
198  minZone[pointi] = index();
199  }
200  syncTools::syncPointList(mesh, maxZone, maxEqOp<label>(), label(-1));
202 
203  bool hasError = false;
204 
205  forAll(maxZone, pointi)
206  {
207  // Check point in same (or no) zone on all processors
208  if
209  (
210  (
211  maxZone[pointi] != -1
212  || minZone[pointi] != labelMax
213  )
214  && (maxZone[pointi] != minZone[pointi])
215  )
216  {
217  hasError = true;
218  if (report)
219  {
220  Info<< " ***Problem with pointZone " << index()
221  << " named " << name()
222  << ". Point " << pointi
223  << " at " << mesh.points()[pointi]
224  << " is in zone "
225  << (minZone[pointi] == labelMax ? -1 : minZone[pointi])
226  << " on some processors and in zone "
227  << maxZone[pointi]
228  << " on some other processors." << nl
229  << "(suppressing further warnings)"
230  << endl;
231  }
232  break; // Only report once
233  }
234  }
235 
236  return hasError;
237 }
238 
239 
240 void Foam::pointZone::resetAddressing(pointZone&& zn)
241 {
242  if (this == &zn)
243  {
244  return; // Self-assignment is a no-op
245  }
247  clearAddressing();
248  labelList::transfer(static_cast<labelList&>(zn));
249  zn.clearAddressing();
250 }
251 
252 
254 {
255  if (this == &zn)
256  {
257  return; // Self-assignment is a no-op
258  }
259 
260  clearAddressing();
261  labelList::operator=(static_cast<const labelList&>(zn));
262 }
263 
264 
266 {
267  clearAddressing();
268  labelList::operator=(addr);
269 }
270 
271 
273 {
274  clearAddressing();
275  labelList::transfer(addr);
276 }
277 
278 
279 void Foam::pointZone::write(Ostream& os) const
280 {
283 }
284 
285 
286 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
287 
289 {
290  if (this == &zn)
291  {
292  return; // Self-assignment is a no-op
293  }
294 
295  clearAddressing();
296  labelList::operator=(static_cast<const labelList&>(zn));
297 }
298 
299 
301 {
302  clearAddressing();
303  labelList::operator=(addr);
304 }
305 
306 
308 {
309  clearAddressing();
310  labelList::transfer(addr);
311 }
312 
313 
314 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
315 
316 Foam::Ostream& Foam::operator<<(Ostream& os, const pointZone& zn)
317 {
318  zn.write(os);
319  os.check(FUNCTION_NAME);
320  return os;
321 }
322 
323 
324 // ************************************************************************* //
dictionary dict
void operator=(const pointZone &zn)
Assign addressing, clearing demand-driven data.
Definition: pointZone.C:281
label max_index() const noexcept
The maximum index the zone may contain == mesh nPoints()
Definition: pointZone.C:166
void transfer(List< label > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition: List.C:347
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:130
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:518
Foam::pointZoneMesh.
Definition: FixedList.H:920
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:1063
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:400
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:381
Base class for mesh zones.
Definition: zone.H:59
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
ZoneMesh< pointZone, polyMesh > pointZoneMesh
A ZoneMesh with pointZone content on a polyMesh.
virtual bool checkParallelSync(const bool report=false) const
Check whether zone is synchronised across coupled boundaries.
Definition: pointZone.C:179
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:233
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: scalarImpl.H:265
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
#define FUNCTION_NAME
defineTypeNameAndDebug(combustionModel, 0)
auto & name
virtual void write(Ostream &os) const
Write (dictionary entries)
Definition: zone.C:218
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
A subset of mesh points.
Definition: pointZone.H:61
messageStream Info
Information stream (stdout output on master, null elsewhere)
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
void writeEntry(Ostream &os) const
Write the UList with its compound type.
Definition: UListIO.C:29
virtual void write(Ostream &os) const
Write (dictionary entries)
Definition: pointZone.C:272
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
List< label > labelList
A List of labels.
Definition: List.H:61
static constexpr const char * labelsName()
The name associated with the zone-labels dictionary entry.
Definition: pointZone.H:79
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)