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 -------------------------------------------------------------------------------
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 
50 Foam::pointZone::pointZone
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 
62 Foam::pointZone::pointZone
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 
75 Foam::pointZone::pointZone
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 
88 Foam::pointZone::pointZone
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 
101 Foam::pointZone::pointZone
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 
114 Foam::pointZone::pointZone
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 
129 Foam::label Foam::pointZone::whichPoint(const label globalPointID) const
130 {
131  return zone::localID(globalPointID);
132 }
133 
134 
135 bool Foam::pointZone::checkDefinition(const bool report) const
136 {
137  return zone::checkDefinition(zoneMesh_.mesh().points().size(), report);
138 }
139 
140 
141 bool 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();
219  labelList::operator=(addr);
220 }
221 
222 
224 {
225  clearAddressing();
226  labelList::transfer(addr);
227 }
228 
229 
230 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
231 
233 {
234  zn.write(os);
236  return os;
237 }
238 
239 
240 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1069
Foam::labelMax
constexpr label labelMax
Definition: label.H:61
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
pointZone.H
Foam::pointZone
A subset of mesh points.
Definition: pointZone.H:65
Foam::zone
Base class for mesh zones.
Definition: zone.H:63
primitiveMesh.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Ostream::beginBlock
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:91
polyMesh.H
syncTools.H
Foam::pointZone::operator=
void operator=(const pointZone &zn)
Assign addressing, clearing demand-driven data.
Definition: pointZone.C:209
Foam::pointZone::checkParallelSync
virtual bool checkParallelSync(const bool report=false) const
Check whether zone is synchronised across coupled boundaries.
Definition: pointZone.C:141
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::syncTools::syncPointList
static void syncPointList(const polyMesh &mesh, List< T > &pointValues, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
Definition: syncToolsTemplates.C:721
Foam::primitiveMesh::nPoints
label nPoints() const noexcept
Number of mesh points.
Definition: primitiveMeshI.H:37
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::minEqOp
Definition: ops.H:81
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::zone::write
virtual void write(Ostream &os) const
Write.
Definition: zone.C:208
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:456
Foam::ZoneMesh< pointZone, polyMesh >
Foam::List::operator=
void operator=(const UList< T > &a)
Assignment to UList operator. Takes linear time.
Definition: List.C:498
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::Ostream::endBlock
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:109
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
pointZoneMesh.H
Foam::pointZoneMesh.
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::maxEqOp
Definition: ops.H:80
Foam::pointZone::whichPoint
label whichPoint(const label globalPointID) const
Helper function to re-direct to zone::localID(...)
Definition: pointZone.C:129
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::zoneIdentifier::write
void write(Ostream &os) const
Definition: zoneIdentifier.C:95
Foam::List< label >
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::UList< label >
Foam::zone::localID
label localID(const label globalID) const
Lookup local address in zone for given global index.
Definition: zone.C:152
Foam::pointZone::labelsName
static const char *const labelsName
Definition: pointZone.H:87
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:236
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::pointZone::checkDefinition
virtual bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
Definition: pointZone.C:135
Foam::pointZone::writeDict
virtual void writeDict(Ostream &os) const
Write dictionary.
Definition: pointZone.C:195
Foam::zone::checkDefinition
virtual bool checkDefinition(const bool report=false) const =0
Check zone definition. Return true if in error.