volRegion.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "volRegion.H"
27 #include "volMesh.H"
28 #include "globalMeshData.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace functionObjects
35 {
36  defineTypeNameAndDebug(volRegion, 0);
37 }
38 }
39 
40 template<>
41 const char*
43 <
45  2
46 >::names[] = {"cellZone", "all"};
47 
48 const Foam::NamedEnum
49 <
51  2
53 
54 
55 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
56 
58 (
59  const writeFile& wf,
60  Ostream& file
61 )
62 {
63  wf.writeCommented(file, "Region");
64  file<< setw(1) << ':' << setw(1) << ' '
65  << regionTypeNames_[regionType_] << " " << regionName_ << endl;
66  wf.writeHeaderValue(file, "Cells", nCells_);
67  wf.writeHeaderValue(file, "Volume", V_);
68 }
69 
70 
71 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
72 
74 (
75  const fvMesh& mesh,
76  const dictionary& dict
77 )
78 :
79  mesh_(mesh),
80  regionType_
81  (
82  dict.found("regionType")
83  ? regionTypeNames_.read(dict.lookup("regionType"))
84  : vrtAll
85  ),
86  regionID_(-1)
87 {
88  read(dict);
89 
90  // Cache integral properties of the region for writeFileHeader
91  nCells_ = nCells();
92  V_ = V();
93 }
94 
95 
96 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
97 
99 {}
100 
101 
102 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
103 
105 (
106  const dictionary& dict
107 )
108 {
109  switch (regionType_)
110  {
111  case vrtCellZone:
112  {
113  dict.lookup("name") >> regionName_;
114 
115  regionID_ = mesh_.cellZones().findZoneID(regionName_);
116 
117  if (regionID_ < 0)
118  {
120  << "Unknown cell zone name: " << regionName_
121  << ". Valid cell zones are: " << mesh_.cellZones().names()
122  << exit(FatalIOError);
123  }
124 
125  if (nCells() == 0)
126  {
128  << regionTypeNames_[regionType_]
129  << "(" << regionName_ << "):" << nl
130  << " Region has no cells"
131  << exit(FatalIOError);
132  }
133 
134  break;
135  }
136 
137  case vrtAll:
138  {
139  break;
140  }
141 
142  default:
143  {
145  << "Unknown region type. Valid region types are:"
146  << regionTypeNames_
147  << exit(FatalIOError);
148  }
149  }
150 
151  return true;
152 }
153 
154 
156 {
157  if (regionType_ == vrtAll)
158  {
159  return labelList::null();
160  }
161  else
162  {
163  return mesh_.cellZones()[regionID_];
164  }
165 }
166 
167 
169 {
170  if (regionType_ == vrtAll)
171  {
172  return mesh_.globalData().nTotalCells();
173  }
174  else
175  {
176  return returnReduce(cellIDs().size(), sumOp<label>());
177  }
178 }
179 
180 
182 {
183  if (regionType_ == vrtAll)
184  {
185  return gSum(mesh_.V());
186  }
187  else
188  {
189  return gSum(scalarField(mesh_.V(), cellIDs()));
190  }
191 }
192 
193 
194 // ************************************************************************* //
static const NamedEnum< regionTypes, 2 > regionTypeNames_
Region type names.
Definition: volRegion.H:125
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:643
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static const List< label > & null()
Return a null List.
Definition: ListI.H:118
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
bool read(const dictionary &)
Read from dictionary.
Definition: volRegion.C:105
label nCells() const
Return the number of cells in the region.
Definition: volRegion.C:168
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:110
bool read(const char *, int32_t &)
Definition: int32IO.C:85
Type gSum(const FieldField< Field, Type > &f)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
scalar V() const
Return total volume of the region.
Definition: volRegion.C:181
static const char nl
Definition: Ostream.H:260
defineTypeNameAndDebug(Qdot, 0)
volRegion(const fvMesh &mesh, const dictionary &dict)
Construct from fvMesh and dictionary.
Definition: volRegion.C:74
void writeFileHeader(const writeFile &wf, Ostream &file)
Output file header information.
Definition: volRegion.C:58
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:335
const labelList & cellIDs() const
Return the local list of cell IDs.
Definition: volRegion.C:155
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual ~volRegion()
Destructor.
Definition: volRegion.C:98
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
functionObject base class for writing single files
Definition: writeFile.H:55
regionTypes
Region type enumeration.
Definition: volRegion.H:118
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844
IOerror FatalIOError