faBoundaryMesh.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) 2016-2017 Wikki Ltd
9  Copyright (C) 2018-2020 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 "faBoundaryMesh.H"
30 #include "faMesh.H"
31 #include "primitiveMesh.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(faBoundaryMesh, 0);
38 }
39 
40 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44  // Templated implementation for types(), names(), etc - file-scope
45  template<class ListType, class GetOp>
46  static ListType getMethodImpl
47  (
48  const faPatchList& list,
49  const GetOp& getop
50  )
51  {
52  const label len = list.size();
53 
54  ListType output(len);
55 
56  for (label i = 0; i < len; ++i)
57  {
58  output[i] = getop(list[i]);
59  }
60 
61  return output;
62  }
63 
64 
65  // Templated implementation for indices() - file-scope
66  template<class UnaryMatchPredicate>
67  static labelList indicesImpl
68  (
69  const faPatchList& list,
70  const UnaryMatchPredicate& matcher
71  )
72  {
73  const label len = list.size();
74 
75  labelList output(len);
76 
77  label count = 0;
78  for (label i = 0; i < len; ++i)
79  {
80  if (matcher(list[i].name()))
81  {
82  output[count++] = i;
83  }
84  }
85 
86  output.resize(count);
87 
88  return output;
89  }
90 
91 
92  // Templated implementation for findIndex() - file-scope
93  template<class UnaryMatchPredicate>
94  label findIndexImpl
95  (
96  const faPatchList& list,
97  const UnaryMatchPredicate& matcher
98  )
99  {
100  const label len = list.size();
101 
102  for (label i = 0; i < len; ++i)
103  {
104  if (matcher(list[i].name()))
105  {
106  return i;
107  }
108  }
109 
110  return -1;
111  }
112 
113 } // End namespace Foam
114 
115 
116 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
117 
118 Foam::faBoundaryMesh::faBoundaryMesh
119 (
120  const IOobject& io,
121  const faMesh& mesh
122 )
123 :
124  faPatchList(),
125  regIOobject(io),
126  mesh_(mesh)
127 {
128  if (readOpt() == IOobject::MUST_READ)
129  {
130  faPatchList& patches = *this;
131 
132  // Read polyPatchList
133  Istream& is = readStream(typeName);
134 
135  PtrList<entry> patchEntries(is);
136  patches.setSize(patchEntries.size());
137 
138  forAll(patches, patchi)
139  {
140  patches.set
141  (
142  patchi,
144  (
145  patchEntries[patchi].keyword(),
146  patchEntries[patchi].dict(),
147  patchi,
148  *this
149  )
150  );
151  }
152 
153  is.check(FUNCTION_NAME);
154 
155  close();
156  }
157 }
158 
159 
160 Foam::faBoundaryMesh::faBoundaryMesh
161 (
162  const IOobject& io,
163  const faMesh& pm,
164  const label size
165 )
166 :
167  faPatchList(size),
168  regIOobject(io),
169  mesh_(pm)
170 {}
171 
172 
173 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
174 
176 {
177  // processorFaPatch geometry triggers calculation of pointNormals.
178  // This uses parallel comms and hence will not be trigggered
179  // on processors that do not have a processorFaPatch so instead
180  // force construction.
181  (void)mesh_.pointAreaNormals();
182 
183  forAll(*this, patchi)
184  {
185  operator[](patchi).initGeometry();
186  }
187 
188  forAll(*this, patchi)
189  {
190  operator[](patchi).calcGeometry();
191  }
192 }
193 
194 
196 {
197  return mesh_;
198 }
199 
200 
202 {
203  lduInterfacePtrsList interfaces(size());
204 
205  forAll(interfaces, patchi)
206  {
207  if (isA<lduInterface>(this->operator[](patchi)))
208  {
209  interfaces.set
210  (
211  patchi,
212  &refCast<const lduInterface>(this->operator[](patchi))
213  );
214  }
215  }
216 
217  return interfaces;
218 }
219 
220 
222 {
223  return getMethodImpl<wordList>(*this, getNameOp<faPatch>());
224 }
225 
226 
228 {
229  return getMethodImpl<wordList>(*this, getTypeOp<faPatch>());
230 }
231 
232 
234 (
235  const keyType& key,
236  const bool useGroups // ignored
237 ) const
238 {
239  if (key.empty())
240  {
241  return labelList();
242  }
243 
244  if (key.isPattern())
245  {
246  const regExp matcher(key);
247 
248  return indicesImpl(*this, matcher);
249  }
250  else
251  {
252  // Literal string.
253  // Special version of above for reduced memory footprint
254 
255  const word& matcher = key;
256 
257  const label patchId = findIndexImpl(*this, matcher);
258 
259  if (patchId >= 0)
260  {
261  return labelList(one{}, patchId);
262  }
263  }
264 
265  return labelList();
266 }
267 
268 
269 Foam::label Foam::faBoundaryMesh::findIndex(const keyType& key) const
270 {
271  if (key.empty())
272  {
273  return -1;
274  }
275  else if (key.isPattern())
276  {
277  // Find as regex
278  regExp matcher(key);
279  return findIndexImpl(*this, matcher);
280  }
281  else
282  {
283  // Find as literal string
284  const word& matcher = key;
285  return findIndexImpl(*this, matcher);
286  }
287 }
288 
289 
290 Foam::label Foam::faBoundaryMesh::findPatchID(const word& patchName) const
291 {
292  if (patchName.empty())
293  {
294  return -1;
295  }
296 
297  return findIndexImpl(*this, patchName);
298 }
299 
300 
301 Foam::label Foam::faBoundaryMesh::whichPatch(const label edgeIndex) const
302 {
303  // Find out which patch the current face belongs to by comparing label
304  // with patch start labels.
305  // If the face is internal, return -1;
306  // if it is off the end of the list, abort
307  if (edgeIndex < mesh().nInternalEdges())
308  {
309  return -1;
310  }
311  else if (edgeIndex >= mesh().nEdges())
312  {
314  << "Edge " << edgeIndex
315  << " out of bounds. Number of geometric edges " << mesh().nEdges()
316  << abort(FatalError);
317  }
318 
319  forAll(*this, patchi)
320  {
321  label start = mesh_.patchStarts()[patchi];
322  label size = operator[](patchi).faPatch::size();
323 
324  if
325  (
326  edgeIndex >= start
327  && edgeIndex < start + size
328  )
329  {
330  return patchi;
331  }
332  }
333 
334  // If not in any of above, it's trouble!
336  << "error in patch search algorithm"
337  << abort(FatalError);
338 
339  return -1;
340 }
341 
342 
343 bool Foam::faBoundaryMesh::checkDefinition(const bool report) const
344 {
345  label nextPatchStart = mesh().nInternalEdges();
346  const faBoundaryMesh& bm = *this;
347 
348  bool hasError = false;
349 
350  forAll(bm, patchi)
351  {
352  if (bm[patchi].start() != nextPatchStart && !hasError)
353  {
354  hasError = true;
355 
357  << " ****Problem with boundary patch " << patchi
358  << " named " << bm[patchi].name()
359  << " of type " << bm[patchi].type()
360  << ". The patch should start on face no " << nextPatchStart
361  << " and the patch specifies " << bm[patchi].start()
362  << "." << endl
363  << "Possibly consecutive patches have this same problem."
364  << " Suppressing future warnings." << endl;
365  }
366 
367  // Warn about duplicate boundary patches?
368 
369  nextPatchStart += bm[patchi].faPatch::size();
370  }
371 
372  if (hasError)
373  {
375  << "This mesh is not valid: boundary definition is in error."
376  << endl;
377  }
378  else
379  {
380  if (debug || report)
381  {
382  Info << "Boundary definition OK." << endl;
383  }
384  }
385 
386  return hasError;
387 }
388 
389 
391 {
392  // processorFaPatch geometry triggers calculation of pointNormals.
393  // This uses parallel comms and hence will not be trigggered
394  // on processors that do not have a processorFaPatch so instead
395  // force construction.
396  (void)mesh_.pointAreaNormals();
397 
398  faPatchList& patches = *this;
399 
400  forAll(patches, patchi)
401  {
402  patches[patchi].initMovePoints(p);
403  }
404 
405  forAll(patches, patchi)
406  {
407  patches[patchi].movePoints(p);
408  }
409 }
410 
411 
413 {
414  faPatchList& patches = *this;
415 
416  forAll(patches, patchi)
417  {
418  patches[patchi].initUpdateMesh();
419  }
420 
421  forAll(patches, patchi)
422  {
423  patches[patchi].updateMesh();
424  }
425 }
426 
427 
429 {
430  const faPatchList& patches = *this;
431 
432  os << patches.size() << nl << token::BEGIN_LIST << incrIndent << nl;
433 
434  for (const faPatch& p : patches)
435  {
436  os.beginBlock(p.name());
437  os << p;
438  os.endBlock();
439  }
440 
441  os << decrIndent << token::END_LIST;
442 
443  os.check(FUNCTION_NAME);
444  return os.good();
445 }
446 
447 
449 {
450  bm.writeData(os);
451  return os;
452 }
453 
454 
455 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::getTypeOp
General get operation to extract the 'type' from an object as a word.
Definition: ops.H:291
Foam::faBoundaryMesh::whichPatch
label whichPatch(const label edgeIndex) const
Return patch index for a given edge label.
Definition: faBoundaryMesh.C:301
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:325
Foam::faBoundaryMesh::updateMesh
void updateMesh()
Correct faBoundaryMesh after topology update.
Definition: faBoundaryMesh.C:412
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::output
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:70
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::faBoundaryMesh::checkDefinition
bool checkDefinition(const bool report=false) const
Check boundary definition.
Definition: faBoundaryMesh.C:343
Foam::keyType::isPattern
bool isPattern() const
The keyType is treated as a pattern, not as literal string.
Definition: keyTypeI.H:128
Foam::faBoundaryMesh::calcGeometry
void calcGeometry()
Calculate the geometry for the patches.
Definition: faBoundaryMesh.C:175
Foam::primitiveMesh::nEdges
label nEdges() const
Number of mesh edges.
Definition: primitiveMeshI.H:67
Foam::one
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:61
primitiveMesh.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::faBoundaryMesh::movePoints
void movePoints(const pointField &)
Correct faBoundaryMesh after moving points.
Definition: faBoundaryMesh.C:390
faMesh.H
Foam::faMesh::pointAreaNormals
const vectorField & pointAreaNormals() const
Return point area normals.
Definition: faMesh.C:1153
Foam::Ostream::beginBlock
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:91
Foam::faBoundaryMesh::findIndex
label findIndex(const keyType &key) const
Return patch index for the first match, return -1 if not found.
Definition: faBoundaryMesh.C:269
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:327
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::findIndexImpl
label findIndexImpl(const faPatchList &list, const UnaryMatchPredicate &matcher)
Definition: faBoundaryMesh.C:95
Foam::indicesImpl
static labelList indicesImpl(const faPatchList &list, const UnaryMatchPredicate &matcher)
Definition: faBoundaryMesh.C:68
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:60
Foam::faBoundaryMesh
Finite area boundary mesh.
Definition: faBoundaryMesh.H:66
Foam::Field< vector >
Foam::faBoundaryMesh::names
wordList names() const
Return a list of patch names.
Definition: faBoundaryMesh.C:221
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
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::primitiveMesh::nInternalEdges
label nInternalEdges() const
Internal edges using 0,1 or 2 boundary points.
Definition: primitiveMeshI.H:59
SeriousErrorInFunction
#define SeriousErrorInFunction
Report an error message using Foam::SeriousError.
Definition: messageStream.H:281
Foam::UPtrList< const lduInterface >
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:62
Foam::regExpCxx
Wrapper around C++11 regular expressions.
Definition: regExpCxx.H:72
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:51
Foam::FatalError
error FatalError
Foam::faBoundaryMesh::findPatchID
label findPatchID(const word &patchName) const
Find patch index given a name, return -1 if not found.
Definition: faBoundaryMesh.C:290
faBoundaryMesh.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::getNameOp
General get operation to extract the 'name' from an object as a word.
Definition: ops.H:278
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:334
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::polyBoundaryMesh::movePoints
void movePoints(const pointField &p)
Correct polyBoundaryMesh after moving points.
Definition: polyBoundaryMesh.C:1100
Foam::faBoundaryMesh::mesh
const faMesh & mesh() const
Return the mesh reference.
Definition: faBoundaryMesh.C:195
Foam::polyBoundaryMesh::updateMesh
void updateMesh()
Correct polyBoundaryMesh after topology update.
Definition: polyBoundaryMesh.C:1146
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::faBoundaryMesh::types
wordList types() const
Return a list of patch types.
Definition: faBoundaryMesh.C:227
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:71
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::UPtrList::set
const T * set(const label i) const
Return const pointer to element (can be nullptr),.
Definition: UPtrList.H:170
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:123
Foam::faMesh
Finite area mesh. Used for 2-D non-Euclidian finite area method.
Definition: faMesh.H:77
Foam::faBoundaryMesh::writeData
bool writeData(Ostream &) const
writeData member function required by regIOobject
Definition: faBoundaryMesh.C:428
patchId
label patchId(-1)
Foam::faPatchList
PtrList< faPatch > faPatchList
Definition: faPatchList.H:47
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:224
Foam::faBoundaryMesh::indices
labelList indices(const keyType &key, const bool useGroups=false) const
Return patch indices for all matches.
Definition: faBoundaryMesh.C:234
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:122
Foam::faPatch
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:68
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::getMethodImpl
static ListType getMethodImpl(const faPatchList &list, const GetOp &getop)
Definition: faBoundaryMesh.C:47
Foam::faBoundaryMesh::interfaces
lduInterfacePtrsList interfaces() const
Definition: faBoundaryMesh.C:201