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-2021 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"
31#include "pointZoneMesh.H"
32#include "polyMesh.H"
33#include "primitiveMesh.H"
34#include "syncTools.H"
35
36// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37
38namespace Foam
39{
43}
44
45const char* const Foam::pointZone::labelsName = "pointLabels";
46
47
48// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49
51(
52 const word& name,
53 const label index,
54 const pointZoneMesh& zm
55)
56:
57 zone(name, index),
58 zoneMesh_(zm)
59{}
60
61
63(
64 const word& name,
65 const labelUList& addr,
66 const label index,
67 const pointZoneMesh& zm
68)
69:
70 zone(name, addr, index),
71 zoneMesh_(zm)
72{}
73
74
76(
77 const word& name,
78 labelList&& addr,
79 const label index,
80 const pointZoneMesh& zm
81)
82:
83 zone(name, std::move(addr), index),
84 zoneMesh_(zm)
85{}
86
87
89(
90 const word& name,
91 const dictionary& dict,
92 const label index,
93 const pointZoneMesh& zm
94)
95:
96 zone(name, dict, this->labelsName, index),
97 zoneMesh_(zm)
98{}
99
100
102(
103 const pointZone& origZone,
104 const labelUList& addr,
105 const label index,
106 const pointZoneMesh& zm
107)
108:
109 zone(origZone, addr, index),
110 zoneMesh_(zm)
111{}
112
113
115(
116 const pointZone& origZone,
117 labelList&& addr,
118 const label index,
119 const pointZoneMesh& zm
120)
121:
122 zone(origZone, std::move(addr), index),
123 zoneMesh_(zm)
124{}
125
126
127// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
128
129Foam::label Foam::pointZone::whichPoint(const label globalPointID) const
130{
131 return zone::localID(globalPointID);
132}
133
134
135bool Foam::pointZone::checkDefinition(const bool report) const
136{
137 return zone::checkDefinition(zoneMesh_.mesh().points().size(), report);
138}
139
140
141bool Foam::pointZone::checkParallelSync(const bool report) const
142{
143 const polyMesh& mesh = zoneMesh().mesh();
144
145 labelList maxZone(mesh.nPoints(), label(-1));
146 labelList minZone(mesh.nPoints(), labelMax);
147
148 const labelList& addr = *this;
149
150 for (const label pointi : addr)
151 {
152 maxZone[pointi] = index();
153 minZone[pointi] = index();
154 }
155 syncTools::syncPointList(mesh, maxZone, maxEqOp<label>(), label(-1));
157
158 bool hasError = false;
159
160 forAll(maxZone, pointi)
161 {
162 // Check point in same (or no) zone on all processors
163 if
164 (
165 (
166 maxZone[pointi] != -1
167 || minZone[pointi] != labelMax
168 )
169 && (maxZone[pointi] != minZone[pointi])
170 )
171 {
172 hasError = true;
173 if (report)
174 {
175 Info<< " ***Problem with pointZone " << index()
176 << " named " << name()
177 << ". Point " << pointi
178 << " at " << mesh.points()[pointi]
179 << " is in zone "
180 << (minZone[pointi] == labelMax ? -1 : minZone[pointi])
181 << " on some processors and in zone "
182 << maxZone[pointi]
183 << " on some other processors." << nl
184 << "(suppressing further warnings)"
185 << endl;
186 }
187 break; // Only report once
188 }
189 }
190
191 return hasError;
192}
193
194
196{
197 os.beginBlock(name());
198
199 os.writeEntry("type", type());
201 writeEntry(this->labelsName, os);
202
203 os.endBlock();
204}
205
206
207// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
208
210{
211 clearAddressing();
213}
214
215
217{
218 clearAddressing();
220}
221
222
224{
225 clearAddressing();
227}
228
229
230// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
231
233{
234 zn.write(os);
236 return os;
237}
238
239
240// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
void operator=(const UList< label > &a)
Assignment to UList operator. Takes linear time.
Definition: List.C:480
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:105
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:239
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:87
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
virtual bool write()
Write the output fields.
Foam::dictionary writeDict() const
Write to dictionary.
A subset of mesh points.
Definition: pointZone.H:68
virtual bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
Definition: pointZone.C:135
static const char *const labelsName
Definition: pointZone.H:87
void operator=(const pointZone &zn)
Assign addressing, clearing demand-driven data.
Definition: pointZone.C:209
label whichPoint(const label globalPointID) const
Helper function to re-direct to zone::localID(...)
Definition: pointZone.C:129
virtual bool checkParallelSync(const bool report=false) const
Check whether zone is synchronised across coupled boundaries.
Definition: pointZone.C:141
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1083
label nPoints() const noexcept
Number of mesh points.
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:68
Base class for mesh zones.
Definition: zone.H:67
label localID(const label globalID) const
Lookup local address in zone for given global index.
Definition: zone.C:154
virtual void write(Ostream &os) const
Write.
Definition: zone.C:210
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
constexpr label labelMax
Definition: label.H:61
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
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:333