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-2018 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 "demandDrivenData.H"
35 #include "syncTools.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41  defineTypeNameAndDebug(pointZone, 0);
42  defineRunTimeSelectionTable(pointZone, dictionary);
43  addToRunTimeSelectionTable(pointZone, pointZone, dictionary);
44 }
45 
46 const char* const Foam::pointZone::labelsName = "pointLabels";
47 
48 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
52 (
53  const word& name,
54  const label index,
55  const pointZoneMesh& zm
56 )
57 :
58  zone(name, index),
59  zoneMesh_(zm)
60 {}
61 
62 
64 (
65  const word& name,
66  const labelUList& addr,
67  const label index,
68  const pointZoneMesh& zm
69 )
70 :
71  zone(name, addr, index),
72  zoneMesh_(zm)
73 {}
74 
75 
77 (
78  const word& name,
79  labelList&& addr,
80  const label index,
81  const pointZoneMesh& zm
82 )
83 :
84  zone(name, std::move(addr), index),
85  zoneMesh_(zm)
86 {}
87 
88 
90 (
91  const word& name,
92  const dictionary& dict,
93  const label index,
94  const pointZoneMesh& zm
95 )
96 :
97  zone(name, dict, this->labelsName, index),
98  zoneMesh_(zm)
99 {}
100 
101 
103 (
104  const pointZone& origZone,
105  const labelUList& addr,
106  const label index,
107  const pointZoneMesh& zm
108 )
109 :
110  zone(origZone, addr, index),
111  zoneMesh_(zm)
112 {}
113 
114 
116 (
117  const pointZone& origZone,
118  labelList&& addr,
119  const label index,
120  const pointZoneMesh& zm
121 )
122 :
123  zone(origZone, std::move(addr), index),
124  zoneMesh_(zm)
125 {}
126 
127 
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 
131 {
132  return zoneMesh_;
133 }
134 
135 
136 Foam::label Foam::pointZone::whichPoint(const label globalPointID) const
137 {
138  return zone::localID(globalPointID);
139 }
140 
141 
142 bool Foam::pointZone::checkDefinition(const bool report) const
143 {
144  return zone::checkDefinition(zoneMesh_.mesh().points().size(), report);
145 }
146 
147 
148 bool Foam::pointZone::checkParallelSync(const bool report) const
149 {
150  const polyMesh& mesh = zoneMesh().mesh();
151 
152  labelList maxZone(mesh.nPoints(), -1);
153  labelList minZone(mesh.nPoints(), labelMax);
154 
155  const labelList& addr = *this;
156 
157  for (const label pointi : addr)
158  {
159  maxZone[pointi] = index();
160  minZone[pointi] = index();
161  }
162  syncTools::syncPointList(mesh, maxZone, maxEqOp<label>(), label(-1));
164 
165  bool error = false;
166 
167  forAll(maxZone, pointi)
168  {
169  // Check point in same (or no) zone on all processors
170  if
171  (
172  (
173  maxZone[pointi] != -1
174  || minZone[pointi] != labelMax
175  )
176  && (maxZone[pointi] != minZone[pointi])
177  )
178  {
179  if (report && !error)
180  {
181  Info<< " ***Problem with pointZone " << index()
182  << " named " << name()
183  << ". Point " << pointi
184  << " at " << mesh.points()[pointi]
185  << " is in zone "
186  << (minZone[pointi] == labelMax ? -1 : minZone[pointi])
187  << " on some processors and in zone "
188  << maxZone[pointi]
189  << " on some other processors." << nl
190  << "(suppressing further warnings)"
191  << endl;
192  }
193  error = true;
194  }
195  }
196 
197  return error;
198 }
199 
200 
202 {
203  os << nl << name_ << nl << token::BEGIN_BLOCK << nl
204  << " type " << type() << token::END_STATEMENT << nl;
205 
206  writeEntry(this->labelsName, os);
207 
208  os << token::END_BLOCK << endl;
209 }
210 
211 
212 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
213 
215 {
216  clearAddressing();
218 }
219 
220 
222 {
223  clearAddressing();
224  labelList::operator=(addr);
225 }
226 
227 
229 {
230  clearAddressing();
231  labelList::transfer(addr);
232 }
233 
234 
235 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
236 
238 {
239  zn.write(os);
240  os.check(FUNCTION_NAME);
241  return os;
242 }
243 
244 
245 // ************************************************************************* //
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:62
Foam::pointZone::pointZone
pointZone(const pointZone &)=delete
No copy construct.
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
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:350
polyMesh.H
syncTools.H
Foam::pointZone::operator=
void operator=(const pointZone &zn)
Assign to zone, clearing demand-driven data.
Definition: pointZone.C:214
Foam::pointZone::checkParallelSync
virtual bool checkParallelSync(const bool report=false) const
Check whether zone is synchronised across coupled boundaries.
Definition: pointZone.C:148
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:724
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:228
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::List< label >::transfer
void transfer(List< label > &list)
Definition: List.C:459
Foam::ZoneMesh< pointZone, polyMesh >
Foam::pointZone::zoneMesh_
const pointZoneMesh & zoneMesh_
Reference to zone list.
Definition: pointZone.H:74
Foam::List< label >::operator=
void operator=(const UList< label > &a)
Assignment to UList operator. Takes linear time.
Definition: List.C:501
Foam::token::END_STATEMENT
End entry [isseparator].
Definition: token.H:121
Foam::pointZone::zoneMesh
const pointZoneMesh & zoneMesh() const
Return zoneMesh reference.
Definition: pointZone.C:130
Foam::token::END_BLOCK
End block [isseparator].
Definition: token.H:127
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
pointZoneMesh.H
Foam::pointZoneMesh.
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::token::BEGIN_BLOCK
Begin block [isseparator].
Definition: token.H:126
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:136
Foam::nl
constexpr char nl
Definition: Ostream.H:385
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::primitiveMesh::nPoints
label nPoints() const
Number of mesh points.
Definition: primitiveMeshI.H:37
Foam::zone::localID
label localID(const label globalID) const
Map storing the local index for every global index. Used to find.
Definition: zone.C:172
Foam::pointZone::labelsName
static const char *const labelsName
The name associated with the zone-labels dictionary entry.
Definition: pointZone.H:88
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
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::error
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:70
Foam::pointZone::checkDefinition
virtual bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
Definition: pointZone.C:142
Foam::pointZone::writeDict
virtual void writeDict(Ostream &os) const
Write dictionary.
Definition: pointZone.C:201
Foam::zone::checkDefinition
virtual bool checkDefinition(const bool report=false) const =0
Check zone definition. Return true if in error.