FreeFOAM The Cross-Platform CFD Toolkit
GeometricField.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) 1991-2010 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::GeometricField
26 
27 Description
28  Generic GeometricField class.
29 
30 SourceFiles
31  GeometricFieldI.H
32  GeometricField.C
33  GeometricBoundaryField.C
34  GeometricFieldFunctions.H
35  GeometricFieldFunctions.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef GeometricField_H
40 #define GeometricField_H
41 
42 #include <OpenFOAM/regIOobject.H>
45 #include <OpenFOAM/FieldField.H>
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 class dictionary;
54 
55 // Forward declaration of friend functions and operators
56 
57 template<class Type, template<class> class PatchField, class GeoMesh>
58 class GeometricField;
59 
60 template<class Type, template<class> class PatchField, class GeoMesh>
61 Ostream& operator<<
62 (
63  Ostream&,
64  const GeometricField<Type, PatchField, GeoMesh>&
65 );
66 
67 template<class Type, template<class> class PatchField, class GeoMesh>
68 Ostream& operator<<
69 (
70  Ostream&,
71  const tmp<GeometricField<Type, PatchField, GeoMesh> >&
72 );
73 
74 
75 /*---------------------------------------------------------------------------*\
76  Class GeometricField Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 template<class Type, template<class> class PatchField, class GeoMesh>
81 :
82  public DimensionedField<Type, GeoMesh>
83 {
84  // Private member functions
85 
86  //- Read from file if it is present
87  bool readIfPresent();
88 
89  //- Read old time field from file if it is present
90  bool readOldTimeIfPresent();
91 
92 
93 public:
94 
95  // Public typedefs
96 
97  typedef typename GeoMesh::Mesh Mesh;
99 
102  typedef PatchField<Type> PatchFieldType;
103 
104 
106  :
107  public FieldField<PatchField, Type>
108  {
109  // Private data
110 
111  //- Reference to BoundaryMesh for which this field is defined
112  const BoundaryMesh& bmesh_;
113 
114 
115  public:
116 
117  // Constructors
118 
119  //- Construct from a BoundaryMesh,
120  // reference to the internal field
121  // and a patch type
123  (
124  const BoundaryMesh&,
126  const word&
127  );
128 
129  //- Construct from a BoundaryMesh,
130  // reference to the internal field
131  // and a wordList of patch types
133  (
134  const BoundaryMesh&,
136  const wordList&
137  );
138 
139  //- Construct from a BoundaryMesh,
140  // reference to the internal field
141  // and a PtrList<PatchField<Type> >
143  (
144  const BoundaryMesh&,
146  const PtrList<PatchField<Type> >&
147  );
148 
149  //- Construct as copy setting the reference to the internal field
151  (
154  );
155 
156  //- Construct as copy
157  // Dangerous because Field may be set to a field which gets deleted
158  // Need new type of BoundaryField, one which is part of a geometric
159  // field for which snGrad etc. may be called and a free standing
160  // BoundaryField for which such operations are unavailable.
162  (
164  );
165 
166  //- Construct from dictionary
168  (
169  const BoundaryMesh&,
171  const dictionary&
172  );
173 
174 
175  // Member functions
176 
177  //- Update the boundary condition coefficients
178  void updateCoeffs();
179 
180  //- Evaluate boundary conditions
181  void evaluate();
182 
183  //- Return a list of the patch types
184  wordList types() const;
185 
186  //- Return BoundaryField of the cell values neighbouring
187  // the boundary
189 
190  //- Return a list of pointers for each patch field with only those
191  // pointing to interfaces being set
193 
194  //- Write boundary field as dictionary entry
195  void writeEntry(const word& keyword, Ostream& os) const;
196 
197 
198  // Member operators
199 
200  //- Assignment to BoundaryField<Type, PatchField, BoundaryMesh>
201  void operator=(const GeometricBoundaryField&);
202 
203  //- Assignment to FieldField<PatchField, Type>
205 
206  //- Assignment to Type
207  void operator=(const Type&);
208 
209 
210  //- Forced assignment to
211  // BoundaryField<Type, PatchField, BoundaryMesh>
212  void operator==(const GeometricBoundaryField&);
213 
214  //- Forced assignment to FieldField<PatchField, Type>
216 
217  //- Forced assignment to Type
218  void operator==(const Type&);
219  };
220 
221 
222 private:
223 
224  // Private data
225 
226  //- Current time index.
227  // Used to trigger the storing of the old-time value
228  mutable label timeIndex_;
229 
230  //- Pointer to old time field
231  mutable GeometricField<Type, PatchField, GeoMesh>* field0Ptr_;
232 
233  //- Pointer to previous iteration (used for under-relaxation)
234  mutable GeometricField<Type, PatchField, GeoMesh>* fieldPrevIterPtr_;
235 
236  //- Boundary Type field containing boundary field values
237  GeometricBoundaryField boundaryField_;
238 
239 
240  // Private member functions
241 
242  //- Read the field from the dictionary
243  tmp<GeometricBoundaryField> readField(const dictionary&);
244 
245  //- Read the field from the given stream
246  tmp<GeometricBoundaryField> readField(Istream& is);
247 
248 
249 public:
250 
251  //- Runtime type information
252  TypeName("GeometricField");
253 
254 
255  // Public typedefs
256 
257  typedef typename Field<Type>::cmptType cmptType;
258 
259  // Static Member Functions
260 
261  //- Return a null geometric field
262  inline static const GeometricField<Type, PatchField, GeoMesh>& null();
263 
264 
265  // Constructors
266 
267  //- Constructor given IOobject, mesh, dimensions and patch type.
268  // This allocates storage for the field but not values.
269  // Used only within this class to create TEMPORARY variables
271  (
272  const IOobject&,
273  const Mesh&,
274  const dimensionSet&,
275  const word& patchFieldType=PatchField<Type>::calculatedType()
276  );
277 
278  //- Constructor given IOobject, mesh, dimensions and patch types.
279  // This allocates storage for the field but not values.
280  // Used only within this class to create TEMPORARY variables
282  (
283  const IOobject&,
284  const Mesh&,
285  const dimensionSet&,
286  const wordList& patchFieldTypes
287  );
288 
289  //- Constructor given IOobject, mesh, dimensioned<Type> and patch type.
291  (
292  const IOobject&,
293  const Mesh&,
294  const dimensioned<Type>&,
295  const word& patchFieldType=PatchField<Type>::calculatedType()
296  );
297 
298  //- Constructor given IOobject, mesh, dimensioned<Type> and patch types.
300  (
301  const IOobject&,
302  const Mesh&,
303  const dimensioned<Type>&,
304  const wordList& patchFieldTypes
305  );
306 
307  //- Constructor from components
309  (
310  const IOobject&,
311  const Mesh&,
312  const dimensionSet&,
313  const Field<Type>&,
314  const PtrList<PatchField<Type> >&
315  );
316 
317  //- Construct and read given IOobject
319  (
320  const IOobject&,
321  const Mesh&
322  );
323 
324  //- Construct and read from given stream
326  (
327  const IOobject&,
328  const Mesh&,
329  Istream&
330  );
331 
332  //- Construct from dictionary
334  (
335  const IOobject&,
336  const Mesh&,
337  const dictionary&
338  );
339 
340  //- Construct as copy
342  (
344  );
345 
346  //- Construct as copy of tmp<GeometricField> deleting argument
347  #ifdef ConstructFromTmp
349  (
351  );
352  #endif
353 
354  //- Construct as copy resetting IO parameters
356  (
357  const IOobject&,
359  );
360 
361  //- Construct as copy resetting name
363  (
364  const word& newName,
366  );
367 
368  //- Construct as copy resetting name
369  #ifdef ConstructFromTmp
371  (
372  const word& newName,
374  );
375  #endif
376 
377  //- Construct as copy resetting IO parameters and patch type
379  (
380  const IOobject&,
382  const word& patchFieldType
383  );
384 
385  //- Construct as copy resetting IO parameters and boundary types
387  (
388  const IOobject&,
390  const wordList& patchFieldTypes
391  );
392 
393 
394  //- Destructor
395  virtual ~GeometricField();
396 
397 
398  // Member Functions
399 
400  //- Return dimensioned internal field
402 
403  //- Return dimensioned internal field
405 
406  //- Return internal field
408 
409  //- Return internal field
410  inline const InternalField& internalField() const;
411 
412  //- Return reference to GeometricBoundaryField
413  GeometricBoundaryField& boundaryField();
414 
415  //- Return reference to GeometricBoundaryField for const field
416  inline const GeometricBoundaryField& boundaryField() const;
417 
418  //- Return the time index of the field
419  inline label timeIndex() const;
420 
421  //- Return the time index of the field
422  inline label& timeIndex();
423 
424  //- Store the old-time fields
425  void storeOldTimes() const;
426 
427  //- Store the old-time field
428  void storeOldTime() const;
429 
430  //- Return the number of old time fields stored
431  label nOldTimes() const;
432 
433  //- Return old time field
435 
436  //- Return non-const old time field
437  // (Not a good idea but it is used for sub-cycling)
439 
440  //- Store the field as the previous iteration value
441  void storePrevIter() const;
442 
443  //- Return previous iteration field
445 
446  //- Correct boundary field
448 
449  //- Does the field need a reference level for solution
450  bool needReference() const;
451 
452  //- Return a component of the field
454  (
455  const direction
456  ) const;
457 
458  //- WriteData member function required by regIOobject
459  bool writeData(Ostream&) const;
460 
461  //- Return transpose (only if it is a tensor field)
463 
464  //- Relax field (for steady-state solution).
465  // alpha = 1 : no relaxation
466  // alpha < 1 : relaxation
467  // alpha = 0 : do nothing
468  void relax(const scalar alpha);
469 
470  //- Relax field (for steady-state solution).
471  // alpha is read from controlDict
472  void relax();
473 
474  //- Select the final iteration parameters if `final' is true
475  // by returning the field name + "Final"
476  // otherwise the standard parameters by returning the field name
477  word select(bool final) const;
478 
479 
480  // Member function *this operators
481 
482  void negate();
483 
484  void replace
485  (
486  const direction,
488  );
489 
490  void replace
491  (
492  const direction,
493  const dimensioned<cmptType>&
494  );
495 
496  void max(const dimensioned<Type>&);
497  void min(const dimensioned<Type>&);
498 
499  void max
500  (
502  const dimensioned<Type>&
503  );
504 
505  void min
506  (
508  const dimensioned<Type>&
509  );
510 
511  void scale
512  (
515  );
516 
517  void scale
518  (
520  const dimensioned<Type>&
521  );
522 
523 
524  // Member operators
525 
528  void operator=(const dimensioned<Type>&);
529 
531  void operator==(const dimensioned<Type>&);
532 
535 
538 
541 
544 
545  void operator+=(const dimensioned<Type>&);
546  void operator-=(const dimensioned<Type>&);
547 
548  void operator*=(const dimensioned<scalar>&);
549  void operator/=(const dimensioned<scalar>&);
550 
551 
552  // Ostream operators
553 
554  friend Ostream& operator<< <Type, PatchField, GeoMesh>
555  (
556  Ostream&,
558  );
559 
560  friend Ostream& operator<< <Type, PatchField, GeoMesh>
561  (
562  Ostream&,
564  );
565 };
566 
567 
568 template<class Type, template<class> class PatchField, class GeoMesh>
569 Ostream& operator<<
570 (
571  Ostream&,
573  GeometricBoundaryField&
574 );
575 
576 
577 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
578 
579 } // End namespace Foam
580 
581 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
582 
584 
585 #ifdef NoRepository
586 # include <OpenFOAM/GeometricField.C>
587 #endif
588 
590 
591 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
592 
593 #endif
594 
595 // ************************ vim: set sw=4 sts=4 et: ************************ //