cloudFunctionObjectTools.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) 2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
33 (
34  const dictionary& dict,
35  const polyMesh& mesh
36 )
37 :
38  isPatch_(false),
39  IDs_(),
40  names_(),
41  BBs_()
42 {
43  wordRes matcher;
44 
45  if (dict.readIfPresent("patches", matcher) && !matcher.empty())
46  {
47  isPatch_ = true;
48 
49  IDs_ = mesh.boundaryMesh().indices(matcher);
50 
51  names_.resize(IDs_.size());
52 
53  label count = 0;
54  for (const label patchi : IDs_)
55  {
56  names_[count] = mesh.boundaryMesh()[patchi].name();
57  ++count;
58  }
59  }
60  else if (dict.readIfPresent("faceZones", matcher))
61  {
62  const faceZoneMesh& fzm = mesh.faceZones();
63 
64  IDs_ = fzm.indices(matcher);
65 
66  BBs_.resize(IDs_.size());
67  names_.resize(IDs_.size());
68 
69  label count = 0;
70  for (const label zonei : IDs_)
71  {
72  const faceZone& fz = fzm[zonei];
73  names_[count] = fz.name();
74 
75  auto& bb = BBs_[count];
76  ++count;
77 
78  bb.reset();
79 
80  const auto& faces = mesh.faces();
81  const auto& points = mesh.points();
82  for (const label facei : fz)
83  {
84  bb.add(points, faces[facei]);
85  }
86  bb.reduce();
87  bb.inflate(0.05);
88  }
89  }
90 
91  if (matcher.empty() || IDs_.size() < 1)
92  {
94  << "No matching patches or face zones found: "
95  << flatOutput(matcher) << nl
96  << exit(FatalIOError);
97  }
98 }
99 
100 
102 (
103  const collector& phc
104 )
105 :
106  isPatch_(phc.isPatch_),
107  IDs_(phc.IDs_),
108  names_(phc.names_),
109  BBs_(phc.BBs_)
110 {}
111 
112 
113 // ************************************************************************* //
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
dynamicFvMesh & mesh
const pointField & points
labelList indices(const wordRe &matcher, const bool useGroups=true) const
Return (sorted) zone indices for all matches.
Definition: ZoneMesh.C:435
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
const word & name() const noexcept
The zone name.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:60
collector(const dictionary &dict, const polyMesh &mesh)
Construct from dictionary.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...