Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / OpenFOAM / fields / GeometricFields / GeometricField / GeometricField.H
blob9c04299593690ccb433cb16be9909934239c2fe4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2011 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 Class
25     Foam::GeometricField
27 Description
28     Generic GeometricField class.
30 SourceFiles
31     GeometricFieldI.H
32     GeometricField.C
33     GeometricBoundaryField.C
34     GeometricFieldFunctions.H
35     GeometricFieldFunctions.C
37 \*---------------------------------------------------------------------------*/
39 #ifndef GeometricField_H
40 #define GeometricField_H
42 #include "regIOobject.H"
43 #include "dimensionedTypes.H"
44 #include "DimensionedField.H"
45 #include "FieldField.H"
46 #include "lduInterfaceFieldPtrsList.H"
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 namespace Foam
53 class dictionary;
55 // Forward declaration of friend functions and operators
57 template<class Type, template<class> class PatchField, class GeoMesh>
58 class GeometricField;
60 template<class Type, template<class> class PatchField, class GeoMesh>
61 Ostream& operator<<
63     Ostream&,
64     const GeometricField<Type, PatchField, GeoMesh>&
67 template<class Type, template<class> class PatchField, class GeoMesh>
68 Ostream& operator<<
70     Ostream&,
71     const tmp<GeometricField<Type, PatchField, GeoMesh> >&
75 /*---------------------------------------------------------------------------*\
76                            Class GeometricField Declaration
77 \*---------------------------------------------------------------------------*/
79 template<class Type, template<class> class PatchField, class GeoMesh>
80 class GeometricField
82     public DimensionedField<Type, GeoMesh>
84     // Private Member Functions
86         //- Read from file if it is present
87         bool readIfPresent();
89         //- Read old time field from file if it is present
90         bool readOldTimeIfPresent();
93 public:
95     // Public typedefs
97         typedef typename GeoMesh::Mesh Mesh;
98         typedef typename GeoMesh::BoundaryMesh BoundaryMesh;
100         typedef DimensionedField<Type, GeoMesh> DimensionedInternalField;
101         typedef Field<Type> InternalField;
102         typedef PatchField<Type> PatchFieldType;
105     class GeometricBoundaryField
106     :
107         public FieldField<PatchField, Type>
108     {
109         // Private data
111             //- Reference to BoundaryMesh for which this field is defined
112             const BoundaryMesh& bmesh_;
115     public:
117         // Constructors
119             //- Construct from a BoundaryMesh,
120             //  reference to the internal field
121             //  and a patch type
122             GeometricBoundaryField
123             (
124                 const BoundaryMesh&,
125                 const DimensionedInternalField&,
126                 const word&
127             );
129             //- Construct from a BoundaryMesh,
130             //  reference to the internal field
131             //  and a wordList of patch types and optional the actual patch
132             //  types (to override constraint patches)
133             GeometricBoundaryField
134             (
135                 const BoundaryMesh&,
136                 const DimensionedInternalField&,
137                 const wordList& wantedPatchTypes,
138                 const wordList& actualPatchTypes = wordList()
139             );
141             //- Construct from a BoundaryMesh,
142             //  reference to the internal field
143             //  and a PtrList<PatchField<Type> >
144             GeometricBoundaryField
145             (
146                 const BoundaryMesh&,
147                 const DimensionedInternalField&,
148                 const PtrList<PatchField<Type> >&
149             );
151             //- Construct as copy setting the reference to the internal field
152             GeometricBoundaryField
153             (
154                 const DimensionedInternalField&,
155                 const GeometricBoundaryField&
156             );
158             //- Construct as copy
159             //  Dangerous because Field may be set to a field which gets deleted
160             //  Need new type of BoundaryField, one which is part of a geometric
161             //  field for which snGrad etc. may be called and a free standing
162             //  BoundaryField for which such operations are unavailable.
163             GeometricBoundaryField
164             (
165                 const GeometricBoundaryField&
166             );
168             //- Construct from dictionary
169             GeometricBoundaryField
170             (
171                 const BoundaryMesh&,
172                 const DimensionedInternalField&,
173                 const dictionary&
174             );
177         // Member functions
179             //- Update the boundary condition coefficients
180             void updateCoeffs();
182             //- Evaluate boundary conditions
183             void evaluate();
185             //- Return a list of the patch types
186             wordList types() const;
188             //- Return BoundaryField of the cell values neighbouring
189             //  the boundary
190             GeometricBoundaryField boundaryInternalField() const;
192             //- Return a list of pointers for each patch field with only those
193             //  pointing to interfaces being set
194             lduInterfaceFieldPtrsList interfaces() const;
196             //- Write boundary field as dictionary entry
197             void writeEntry(const word& keyword, Ostream& os) const;
200         // Member operators
202             //- Assignment to BoundaryField<Type, PatchField, BoundaryMesh>
203             void operator=(const GeometricBoundaryField&);
205             //- Assignment to FieldField<PatchField, Type>
206             void operator=(const FieldField<PatchField, Type>&);
208             //- Assignment to Type
209             void operator=(const Type&);
212             //- Forced assignment to
213             //  BoundaryField<Type, PatchField, BoundaryMesh>
214             void operator==(const GeometricBoundaryField&);
216             //- Forced assignment to FieldField<PatchField, Type>
217             void operator==(const FieldField<PatchField, Type>&);
219             //- Forced assignment to Type
220             void operator==(const Type&);
221     };
224 private:
226     // Private data
228         //- Current time index.
229         //  Used to trigger the storing of the old-time value
230         mutable label timeIndex_;
232         //- Pointer to old time field
233         mutable GeometricField<Type, PatchField, GeoMesh>* field0Ptr_;
235         //-  Pointer to previous iteration (used for under-relaxation)
236         mutable GeometricField<Type, PatchField, GeoMesh>* fieldPrevIterPtr_;
238         //- Boundary Type field containing boundary field values
239         GeometricBoundaryField boundaryField_;
242     // Private Member Functions
244         //- Read the field from the dictionary
245         tmp<GeometricBoundaryField> readField(const dictionary&);
247         //- Read the field from the given stream
248         tmp<GeometricBoundaryField> readField(Istream& is);
251 public:
253     //- Runtime type information
254     TypeName("GeometricField");
257     // Public typedefs
259         typedef typename Field<Type>::cmptType cmptType;
261     // Static Member Functions
263         //- Return a null geometric field
264         inline static const GeometricField<Type, PatchField, GeoMesh>& null();
267     // Constructors
269         //- Constructor given IOobject, mesh, dimensions and patch type.
270         //  This allocates storage for the field but not values.
271         //  Used only within this class to create TEMPORARY variables
272         GeometricField
273         (
274             const IOobject&,
275             const Mesh&,
276             const dimensionSet&,
277             const word& patchFieldType=PatchField<Type>::calculatedType()
278         );
280         //- Constructor given IOobject, mesh, dimensions and patch types.
281         //  This allocates storage for the field but not values.
282         //  Used only within this class to create TEMPORARY variables
283         GeometricField
284         (
285             const IOobject&,
286             const Mesh&,
287             const dimensionSet&,
288             const wordList& wantedPatchTypes,
289             const wordList& actualPatchTypes = wordList()
290         );
292         //- Constructor given IOobject, mesh, dimensioned<Type> and patch type.
293         GeometricField
294         (
295             const IOobject&,
296             const Mesh&,
297             const dimensioned<Type>&,
298             const word& patchFieldType=PatchField<Type>::calculatedType()
299         );
301         //- Constructor given IOobject, mesh, dimensioned<Type> and patch types.
302         GeometricField
303         (
304             const IOobject&,
305             const Mesh&,
306             const dimensioned<Type>&,
307             const wordList& wantedPatchTypes,
308             const wordList& actualPatchTypes = wordList()
309         );
311         //- Constructor from components
312         GeometricField
313         (
314             const IOobject&,
315             const Mesh&,
316             const dimensionSet&,
317             const Field<Type>&,
318             const PtrList<PatchField<Type> >&
319         );
321         //- Construct and read given IOobject
322         GeometricField
323         (
324             const IOobject&,
325             const Mesh&
326         );
328         //- Construct from dictionary
329         GeometricField
330         (
331             const IOobject&,
332             const Mesh&,
333             const dictionary&
334         );
336         //- Construct as copy
337         GeometricField
338         (
339             const GeometricField<Type, PatchField, GeoMesh>&
340         );
342         //- Construct as copy of tmp<GeometricField> deleting argument
343         #ifdef ConstructFromTmp
344         GeometricField
345         (
346             const tmp<GeometricField<Type, PatchField, GeoMesh> >&
347         );
348         #endif
350         //- Construct as copy resetting IO parameters
351         GeometricField
352         (
353             const IOobject&,
354             const GeometricField<Type, PatchField, GeoMesh>&
355         );
357         //- Construct as copy resetting name
358         GeometricField
359         (
360             const word& newName,
361             const GeometricField<Type, PatchField, GeoMesh>&
362         );
364         //- Construct as copy resetting name
365         #ifdef ConstructFromTmp
366         GeometricField
367         (
368             const word& newName,
369             const tmp<GeometricField<Type, PatchField, GeoMesh> >&
370         );
371         #endif
373         //- Construct as copy resetting IO parameters and patch type
374         GeometricField
375         (
376             const IOobject&,
377             const GeometricField<Type, PatchField, GeoMesh>&,
378             const word& patchFieldType
379         );
381         //- Construct as copy resetting IO parameters and boundary types
382         GeometricField
383         (
384             const IOobject&,
385             const GeometricField<Type, PatchField, GeoMesh>&,
386             const wordList& patchFieldTypes,
387             const wordList& actualPatchTypes = wordList()
388         );
391     //- Destructor
392     virtual ~GeometricField();
395     // Member Functions
397         //- Return dimensioned internal field
398         DimensionedInternalField& dimensionedInternalField();
400         //- Return dimensioned internal field
401         inline const DimensionedInternalField& dimensionedInternalField() const;
403         //- Return internal field
404         InternalField& internalField();
406         //- Return internal field
407         inline const InternalField& internalField() const;
409         //- Return reference to GeometricBoundaryField
410         GeometricBoundaryField& boundaryField();
412         //- Return reference to GeometricBoundaryField for const field
413         inline const GeometricBoundaryField& boundaryField() const;
415         //- Return the time index of the field
416         inline label timeIndex() const;
418         //- Return the time index of the field
419         inline label& timeIndex();
421         //- Store the old-time fields
422         void storeOldTimes() const;
424         //- Store the old-time field
425         void storeOldTime() const;
427         //- Return the number of old time fields stored
428         label nOldTimes() const;
430         //- Return old time field
431         const GeometricField<Type, PatchField, GeoMesh>& oldTime() const;
433         //- Return non-const old time field
434         //  (Not a good idea but it is used for sub-cycling)
435         GeometricField<Type, PatchField, GeoMesh>& oldTime();
437         //- Store the field as the previous iteration value
438         void storePrevIter() const;
440         //- Return previous iteration field
441         const GeometricField<Type, PatchField, GeoMesh>& prevIter() const;
443         //- Correct boundary field
444         void correctBoundaryConditions();
446         //- Does the field need a reference level for solution
447         bool needReference() const;
449         //- Return a component of the field
450         tmp<GeometricField<cmptType, PatchField, GeoMesh> > component
451         (
452             const direction
453         ) const;
455         //- WriteData member function required by regIOobject
456         bool writeData(Ostream&) const;
458         //- Return transpose (only if it is a tensor field)
459         tmp<GeometricField<Type, PatchField, GeoMesh> > T() const;
461         //- Relax field (for steady-state solution).
462         //  alpha = 1 : no relaxation
463         //  alpha < 1 : relaxation
464         //  alpha = 0 : do nothing
465         void relax(const scalar alpha);
467         //- Relax field (for steady-state solution).
468         //  alpha is read from controlDict
469         void relax();
471         //- Select the final iteration parameters if `final' is true
472         //  by returning the field name + "Final"
473         //  otherwise the standard parameters by returning the field name
474         word select(bool final) const;
477     // Member function *this operators
479         void negate();
481         void replace
482         (
483             const direction,
484             const GeometricField<cmptType, PatchField, GeoMesh>&
485         );
487         void replace
488         (
489             const direction,
490             const dimensioned<cmptType>&
491         );
493         void max(const dimensioned<Type>&);
494         void min(const dimensioned<Type>&);
496         void max
497         (
498             const GeometricField<Type, PatchField, GeoMesh>&,
499             const dimensioned<Type>&
500         );
502         void min
503         (
504             const GeometricField<Type, PatchField, GeoMesh>&,
505             const dimensioned<Type>&
506         );
508         void scale
509         (
510             const GeometricField<Type, PatchField, GeoMesh>&,
511             const GeometricField<Type, PatchField, GeoMesh>&
512         );
514         void scale
515         (
516             const GeometricField<Type, PatchField, GeoMesh>&,
517             const dimensioned<Type>&
518         );
521     // Member operators
523         void operator=(const GeometricField<Type, PatchField, GeoMesh>&);
524         void operator=(const tmp<GeometricField<Type, PatchField, GeoMesh> >&);
525         void operator=(const dimensioned<Type>&);
527         void operator==(const tmp<GeometricField<Type, PatchField, GeoMesh> >&);
528         void operator==(const dimensioned<Type>&);
530         void operator+=(const GeometricField<Type, PatchField, GeoMesh>&);
531         void operator+=(const tmp<GeometricField<Type, PatchField, GeoMesh> >&);
533         void operator-=(const GeometricField<Type, PatchField, GeoMesh>&);
534         void operator-=(const tmp<GeometricField<Type, PatchField, GeoMesh> >&);
536         void operator*=(const GeometricField<scalar, PatchField, GeoMesh>&);
537         void operator*=(const tmp<GeometricField<scalar,PatchField,GeoMesh> >&);
539         void operator/=(const GeometricField<scalar, PatchField, GeoMesh>&);
540         void operator/=(const tmp<GeometricField<scalar,PatchField,GeoMesh> >&);
542         void operator+=(const dimensioned<Type>&);
543         void operator-=(const dimensioned<Type>&);
545         void operator*=(const dimensioned<scalar>&);
546         void operator/=(const dimensioned<scalar>&);
549     // Ostream operators
551         friend Ostream& operator<< <Type, PatchField, GeoMesh>
552         (
553             Ostream&,
554             const GeometricField<Type, PatchField, GeoMesh>&
555         );
557         friend Ostream& operator<< <Type, PatchField, GeoMesh>
558         (
559             Ostream&,
560             const tmp<GeometricField<Type, PatchField, GeoMesh> >&
561         );
565 template<class Type, template<class> class PatchField, class GeoMesh>
566 Ostream& operator<<
568     Ostream&,
569     const typename GeometricField<Type, PatchField, GeoMesh>::
570     GeometricBoundaryField&
574 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
576 } // End namespace Foam
578 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
580 #include "GeometricFieldI.H"
582 #ifdef NoRepository
583 #   include "GeometricField.C"
584 #endif
586 #include "GeometricFieldFunctions.H"
588 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
590 #endif
592 // ************************************************************************* //