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-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
33namespace Foam
34{
35 namespace fa
36 {
38 }
39}
40
41
42const 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", zoneName_);
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 << zoneName_ << nl;
117
118 // Also handles groups, multiple zones (as wordRe match) ...
119 labelList zoneIDs = mesh_.faceZones().indices(zoneName_);
120
121 if (zoneIDs.empty())
122 {
124 << "No matching faceZones: " << zoneName_ << nl
125 << "Valid zones : "
126 << flatOutput(mesh_.faceZones().names()) << nl
127 << "Valid groups: "
128 << flatOutput(mesh_.faceZones().groupNames())
129 << nl
130 << exit(FatalError);
131 }
132
133 const bitSet isZoneFace(mesh_.faceZones().selection(zoneIDs));
134
135 const labelUList& faceLabels = regionMesh().faceLabels();
136
137 faces_.resize_nocopy(faceLabels.size());
138
139 label nUsed = 0;
140 for (const label facei : faceLabels)
141 {
142 if (isZoneFace[facei])
143 {
144 faces_[nUsed] = facei;
145 ++nUsed;
146 }
147 }
148 faces_.resize(nUsed);
149 break;
150 }
151
152 case smAll:
153 {
154 Info<< indent << "- selecting all faces" << endl;
155 faces_ = identity(regionMesh().nFaces());
156
157 break;
158 }
159 default:
160 {
162 << "Unknown selectionMode "
163 << selectionModeTypeNames_[selectionMode_]
164 << ". Valid selectionMode types are "
165 << selectionModeTypeNames_
166 << exit(FatalError);
167 }
168 }
169}
170
171
172// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
173
175(
176 const word& name,
177 const word& modelType,
178 const dictionary& dict,
179 const fvPatch& patch
180)
181:
182 fa::option(name, modelType, dict, patch),
183 timeStart_(-1),
184 duration_(0),
185 selectionMode_(selectionModeTypeNames_.get("selectionMode", coeffs_)),
186 zoneName_(),
187 A_(0)
188{
189 if (isActive())
190 {
192 read(dict);
195 setArea();
197 }
198}
199
200
201// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
202
204{
205 if (fa::option::isActive() && inTimeLimits(mesh_.time().value()))
206 {
207 // Update the face set if the mesh is changing
208 if (mesh_.changing())
209 {
210 if (mesh_.topoChanging())
211 {
212 setArea();
213 // Force printing of new set area
214 A_ = -GREAT;
215 }
216
217 // Report new area (if changed)
218 setArea();
219 }
220
221 return true;
222 }
223
224 return false;
225}
226
227
229{
231 {
232 if (coeffs_.readIfPresent("timeStart", timeStart_))
233 {
234 coeffs_.readEntry("duration", duration_);
235 }
236
237 return true;
238 }
239
240 return false;
241}
242
243
244// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:342
virtual bool read()
Re-read model coefficients if they have changed.
virtual word timeName() const
Return current time name.
Definition: Time.C:790
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Intermediate abstract class for handling face-set options for the derived faOptions.
void setFaceSelection()
Set face selection based on user input selection mode.
void setSelection(const dictionary &dict)
Set face selection name from dictionary input.
Definition: faceSetOption.C:55
selectionModeType
Enumeration for selection mode types.
virtual bool read(const dictionary &dict)
Read source dictionary.
virtual bool isActive()
Is the source active?
wordRe zoneName_
Name of zone for (volume) "faceZone" selection.
selectionModeType selectionMode_
Face selection mode.
static const Enum< selectionModeType > selectionModeTypeNames_
List of selection mode type names.
void setArea()
Recalculate the area.
Definition: faceSetOption.C:81
Base abstract class for handling finite area options (i.e. faOption).
Definition: faOption.H:134
dictionary coeffs_
Dictionary containing source coefficients.
Definition: faOption.H:161
virtual bool isActive()
Is the source active?
Definition: faOption.C:120
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:71
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const labelList nFaces(UPstream::listGatherValues< label >(aMesh.nFaces()))
const labelIOList & zoneIDs
Definition: correctPhi.H:59
Namespace for OpenFOAM.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
Definition: labelList.C:38
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:349
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:342
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:215
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:356
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict