faceSetOption.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) 2019-2021 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 
28 #include "faceSetOption.H"
29 #include "areaFields.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  namespace fa
36  {
37  defineTypeNameAndDebug(faceSetOption, 0);
38  }
39 }
40 
41 
42 const Foam::Enum
43 <
45 >
47 ({
48  { selectionModeType::smAll, "all" },
49  { selectionModeType::smVolFaceZone, "volFaceZone" }
50 });
51 
52 
53 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
54 
56 {
57  switch (selectionMode_)
58  {
59  case smAll:
60  {
61  break;
62  }
63  case smVolFaceZone:
64  {
65  dict.readEntry("faceZone", faceSetName_);
66  break;
67  }
68  default:
69  {
71  << "Unknown selectionMode "
73  << ". Valid selectionMode types : "
75  << exit(FatalError);
76  }
77  }
78 }
79 
80 
82 {
83  // Set area information
84 
85  scalar sumArea = 0.0;
86  for (const label facei : faces_)
87  {
88  sumArea += regionMesh().S()[facei];
89  }
90  reduce(sumArea, sumOp<scalar>());
91 
92  const scalar AOld = A_;
93  A_ = sumArea;
94 
95  // Convert both areas to representation using current writeprecision
98 
99  if (AName != AOldName)
100  {
101  Info<< indent
102  << "- selected " << returnReduce(faces_.size(), sumOp<label>())
103  << " face(s) with area " << A_ << endl;
104  }
105 }
106 
107 
109 {
110  switch (selectionMode_)
111  {
112  case smVolFaceZone:
113  {
114  Info<< indent
115  << "- selecting faces using volume-mesh faceZone "
116  << faceSetName_ << endl;
117 
118  label zoneID = mesh_.faceZones().findZoneID(faceSetName_);
119  if (zoneID == -1)
120  {
122  << "Cannot find faceZone " << faceSetName_ << endl
123  << "Valid faceZones are " << mesh_.faceZones().names()
124  << exit(FatalError);
125  }
126 
127  const faceZone& addr = mesh_.faceZones()[zoneID];
128 
129  const bitSet isZoneFace(mesh_.nFaces(), addr);
130 
131  // Do we loop over faMesh faces or over faceZone faces?
132  const labelUList& faceLabels = regionMesh().faceLabels();
133 
134  label n = 0;
135  for (const label facei : faceLabels)
136  {
137  if (isZoneFace[facei])
138  {
139  n++;
140  }
141  }
142  faces_.setSize(n);
143  n = 0;
144  for (const label facei : faceLabels)
145  {
146  if (isZoneFace[facei])
147  {
148  faces_[n++] = facei;
149  }
150  }
151  break;
152  }
153 
154  case smAll:
155  {
156  Info<< indent << "- selecting all faces" << endl;
157  faces_ = identity(regionMesh().nFaces());
158 
159  break;
160  }
161  default:
162  {
164  << "Unknown selectionMode "
165  << selectionModeTypeNames_[selectionMode_]
166  << ". Valid selectionMode types are "
167  << selectionModeTypeNames_
168  << exit(FatalError);
169  }
170  }
171 }
172 
173 
174 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
175 
177 (
178  const word& name,
179  const word& modelType,
180  const dictionary& dict,
181  const fvPatch& patch
182 )
183 :
184  fa::option(name, modelType, dict, patch),
185  timeStart_(-1),
186  duration_(0),
187  selectionMode_(selectionModeTypeNames_.get("selectionMode", coeffs_)),
188  faceSetName_("none"),
189  A_(0)
190 {
191  if (isActive())
192  {
193  Info<< incrIndent;
194  read(dict);
195  setSelection(coeffs_);
196  setFaceSelection();
197  setArea();
198  Info<< decrIndent;
199  }
200 }
201 
202 
203 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
204 
206 {
207  if (fa::option::isActive() && inTimeLimits(mesh_.time().value()))
208  {
209  // Update the face set if the mesh is changing
210  if (mesh_.changing())
211  {
212  if (mesh_.topoChanging())
213  {
214  setArea();
215  // Force printing of new set area
216  A_ = -GREAT;
217  }
218 
219  // Report new area (if changed)
220  setArea();
221  }
222 
223  return true;
224  }
225 
226  return false;
227 }
228 
229 
231 {
232  if (fa::option::read(dict))
233  {
234  if (coeffs_.readIfPresent("timeStart", timeStart_))
235  {
236  coeffs_.readEntry("duration", duration_);
237  }
238 
239  return true;
240  }
241 
242  return false;
243 }
244 
245 
246 // ************************************************************************* //
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:346
Foam::fa::defineTypeNameAndDebug
defineTypeNameAndDebug(limitVelocity, 0)
Foam::sumOp
Definition: ops.H:213
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::Time::timeName
virtual word timeName() const
Return current time name.
Definition: Time.C:790
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::fa::faceSetOption::selectionModeType
selectionModeType
Enumeration for selection mode types.
Definition: faceSetOption.H:143
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::fa::faceSetOption::selectionModeTypeNames_
static const Enum< selectionModeType > selectionModeTypeNames_
List of selection mode type names.
Definition: faceSetOption.H:150
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
areaFields.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
zoneID
const labelIOList & zoneID
Definition: interpolatedFaces.H:22
Foam::fa::faceSetOption::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: faceSetOption.C:230
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:353
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:339
faceSetOption.H
Foam::fa::option::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: faOptionIO.C:54
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::fa::option::isActive
virtual bool isActive()
Is the source active?
Definition: faOption.C:119
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:342
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::fa::faceSetOption::selectionMode_
selectionModeType selectionMode_
Face selection mode.
Definition: faceSetOption.H:164
Foam::fa::faceSetOption::smVolFaceZone
Definition: faceSetOption.H:146
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::fa::option
Base abstract class for handling finite area options (i.e. faOption).
Definition: faOption.H:133
Foam::fa::faceSetOption::faceSetOption
faceSetOption(const word &name, const word &modelType, const dictionary &dict, const fvPatch &patch)
Construct from components.
Definition: faceSetOption.C:177
Foam::UList< label >
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
Foam::fa::faceSetOption::smAll
Definition: faceSetOption.H:145
Foam::fa::faceSetOption::setArea
void setArea()
Recalculate the area.
Definition: faceSetOption.C:81
Foam::fa::faceSetOption::isActive
virtual bool isActive()
Is the source active?
Definition: faceSetOption.C:205
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::fa::faceSetOption::faceSetName_
word faceSetName_
Name of "volFaceZone" selection.
Definition: faceSetOption.H:167
Foam::fa::faceSetOption::setSelection
void setSelection(const dictionary &dict)
Set face selection name from dictionary input.
Definition: faceSetOption.C:55
Foam::fa::faceSetOption::setFaceSelection
void setFaceSelection()
Set face selection based on user input selection mode.
Definition: faceSetOption.C:108