FreeFOAM The Cross-Platform CFD Toolkit
faceSource.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd.
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 Class
25  Foam::fieldValues::faceSource
26 
27 Description
28  Face source variant of field value function object. Values of user-
29  specified fields reported for collections of faces.
30 
31  faceObj1 // Name also used to identify output folder
32  {
33  type faceSource;
34  functionObjectLibs ("libfieldValueFunctionObjects.so");
35  enabled true;
36  outputControl outputTime;
37  log true; // log to screen?
38  valueOutput true; // Write values at run-time output times?
39  source faceZone; // Type of face source:
40  // faceZone, patch, sampledSurface
41  sourceName f0; // faceZone or patch, see below
42  operation sum;
43  fields
44  (
45  p
46  phi
47  U
48  );
49  }
50 
51  source:
52  - faceZone : requires a 'sourceName' entry to specify the faceZone
53  - patch : "" patch
54  - sampledSurface : requires a 'sampledSurfaceDict' subdictionary. See e.g.
55  sampleDict.
56 
57  operation is one of:
58  - none
59  - sum
60  - areaAverage
61  - areaIntegrate
62  - weightedAverage
63  - min
64  - max
65 
66  Notes:
67  - faces on empty patches get ignored
68  - if the field is a volField the faceZone can only consist of boundary
69  faces.
70  - all fields get oriented according to the faceZone (so you might e.g. see
71  negative pressure)
72  - using sampledSurfaces:
73  - they do not do surface fields
74  - they use cell values - they do not do any interpolation.
75  - take care when using isoSurfaces - these might have duplicate
76  triangles so integration might be wrong
77 
78 SourceFiles
79  faceSource.C
80 
81 \*---------------------------------------------------------------------------*/
82 
83 #ifndef faceSource_H
84 #define faceSource_H
85 
86 #include <OpenFOAM/NamedEnum.H>
90 
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92 
93 namespace Foam
94 {
95 
96 class sampledSurface;
97 
98 namespace fieldValues
99 {
100 
101 /*---------------------------------------------------------------------------*\
102  Class faceSource Declaration
103 \*---------------------------------------------------------------------------*/
104 
106 :
107  public fieldValue
108 {
109 
110 public:
111 
112  // Public data types
113 
114  //- Source type enumeration
116  {
120  };
121 
122  //- Source type names
124 
125 
126  //- Operation type enumeration
128  {
136  };
137 
138  //- Operation type names
140 
141 
142 private:
143 
144  // Private member functions
145 
146  //- Set faces to evaluate based on a face zone
147  void setFaceZoneFaces();
148 
149  //- Set faces to evaluate based on a patch
150  void setPatchFaces();
151 
152  //- Set faces according to sampledSurface
153  void sampledSurfaceFaces(const dictionary&);
154 
155 
156 protected:
157 
158  // Protected data
159 
160  //- Source type
162 
163  //- Operation to apply to values
165 
166  //- Weight field name - only used for opWeightedAverage mode
168 
169  //- Global number of faces
170  label nFaces_;
171 
172  // If operating on mesh faces (faceZone,patch)
173 
174  //- Local list of face IDs
176 
177  //- Local list of patch ID per face
179 
180  //- List of +1/-1 representing face flip map (1 use as is, -1 negate)
182 
183  // If operating on sampledSurface
184 
185  //- underlying sampledSurface
187 
188 
189  // Protected member functions
190 
191  //- Initialise, e.g. face addressing
192  void initialise(const dictionary& dict);
193 
194  //- Return true if the field name is valid
195  template<class Type>
196  bool validField(const word& fieldName) const;
197 
198  //- Return field values by looking up field name
199  template<class Type>
200  tmp<Field<Type> > setFieldValues(const word& fieldName) const;
201 
202  //- Apply the 'operation' to the values
203  template<class Type>
204  Type processValues
205  (
206  const Field<Type>& values,
207  const scalarField& magSf,
208  const scalarField& weightField
209  ) const;
210 
211  //- Output file header information
212  virtual void writeFileHeader();
213 
214 
215 public:
216 
217  //- Run-time type information
218  TypeName("faceSource");
219 
220 
221  //- Construct from components
222  faceSource
223  (
224  const word& name,
225  const objectRegistry& obr,
226  const dictionary& dict,
227  const bool loadFromFiles = false
228  );
229 
230 
231  //- Destructor
232  virtual ~faceSource();
233 
234 
235  // Public member functions
236 
237  // Access
238 
239  //- Return the source type
240  inline const sourceType& source() const;
241 
242  //- Return the local list of face IDs
243  inline const labelList& faceId() const;
244 
245  //- Return the local list of patch ID per face
246  inline const labelList& facePatch() const;
247 
248  //- Return the list of +1/-1 representing face flip map
249  inline const labelList& faceSign() const;
250 
251 
252  // Function object functions
253 
254  //- Read from dictionary
255  virtual void read(const dictionary&);
256 
257  //- Calculate and write
258  virtual void write();
259 
260  //- Templated helper function to output field values
261  template<class Type>
262  bool writeValues(const word& fieldName);
263 
264  //- Filter a surface field according to faceIds
265  template<class Type>
267  (
269  const bool applyOrientation
270  ) const;
271 
272  //- Filter a volume field according to faceIds
273  template<class Type>
275  (
277  const bool applyOrientation
278  ) const;
279 };
280 
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 } // End namespace fieldValues
285 } // End namespace Foam
286 
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
288 
289 #include "faceSourceI.H"
290 
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 
293 #ifdef NoRepository
294  #include "faceSourceTemplates.C"
295 #endif
296 
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
298 
299 #endif
300 
301 // ************************ vim: set sw=4 sts=4 et: ************************ //