Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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"
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
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
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
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
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
99:
101 zoneMesh_(zm)
102{}
103
104
106(
107 const pointZone& originalZone,
108 const pointZoneMesh& zm,
109 const label newIndex
111:
112 zone(originalZone, newIndex),
113 zoneMesh_(zm)
114{}
115
116
118(
119 const pointZone& originalZone,
121 const pointZoneMesh& zm,
122 const label newIndex
124:
125 zone(originalZone, labelList(), newIndex),
126 zoneMesh_(zm)
127{}
128
129
131(
132 const pointZone& originalZone,
134 const label newIndex,
135 const pointZoneMesh& zm
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)
151 pointZone(originalZone, Foam::zero{}, index, zm)
152{
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)
168}
169
170
171// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
172
173Foam::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
186bool 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
234 }
235
236 return hasError;
237}
238
239
241{
242 if (this == &zn)
243 {
244 return; // Self-assignment is a no-op
245 }
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
259
260 clearAddressing();
261 labelList::operator=(static_cast<const labelList&>(zn));
262}
263
264
270
271
277
278
280{
283}
284
285
286// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
287
289{
290 if (this == &zn)
291 {
292 return; // Self-assignment is a no-op
294
295 clearAddressing();
296 labelList::operator=(static_cast<const labelList&>(zn));
297}
298
299
301{
304}
305
306
308{
309 clearAddressing();
311}
312
313
314// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
315
316Foam::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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
void transfer(List< label > &list)
void operator=(const UList< label > &list)
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
void writeEntry(Ostream &os) const
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A subset of mesh points.
Definition pointZone.H:64
static constexpr const char * labelsName()
The name associated with the zone-labels dictionary entry.
Definition pointZone.H:79
virtual void write(Ostream &os) const
Write (dictionary entries).
Definition pointZone.C:272
const pointZoneMesh & zoneMesh() const noexcept
Return reference to the zone mesh.
Definition pointZone.H:285
label max_index() const noexcept
The maximum index the zone may contain == mesh nPoints().
Definition pointZone.C:166
void operator=(const pointZone &zn)
Assign addressing, clearing demand-driven data.
Definition pointZone.C:281
virtual void resetAddressing(pointZone &&zn)
Move reset addressing from another zone.
Definition pointZone.C:233
virtual bool checkParallelSync(const bool report=false) const
Check whether zone is synchronised across coupled boundaries.
Definition pointZone.C:179
pointZone(const pointZone &)=delete
No copy construct.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
static void syncPointList(const polyMesh &mesh, List< T > &pointValues, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
A class for handling words, derived from Foam::string.
Definition word.H:66
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
label index() const noexcept
The index of this zone in the zone list.
virtual void write(Ostream &os) const
Write (dictionary entries).
Definition zone.C:218
zone()
Default construct: empty zone with name="", index=0.
Definition zone.C:37
virtual void clearAddressing()
Clear addressing (remove lookup maps and other auxiliary information).
Definition zone.C:162
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
auto & name
#define FUNCTION_NAME
Namespace for OpenFOAM.
ZoneMesh< pointZone, polyMesh > pointZoneMesh
A ZoneMesh with pointZone content on a polyMesh.
List< label > labelList
A List of labels.
Definition List.H:62
messageStream Info
Information stream (stdout output on master, null elsewhere).
constexpr label labelMax
Definition label.H:55
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
const direction noexcept
Definition scalarImpl.H:265
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
UList< label > labelUList
A UList of labels.
Definition UList.H:75
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::pointZoneMesh.
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299