Added constructor from dictionary.
[OpenFOAM-1.6.x.git] / src / OpenFOAM / fields / GeometricFields / GeometricField / GeometricField.H
blobf9ac079b0fcf69735d14ff33a402bbe78fb68afa
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::GeometricField
28 Description
29     Generic GeometricField class.
31 SourceFiles
32     GeometricFieldI.H
33     GeometricField.C
34     GeometricBoundaryField.C
35     GeometricFieldFunctions.H
36     GeometricFieldFunctions.C
38 \*---------------------------------------------------------------------------*/
40 #ifndef GeometricField_H
41 #define GeometricField_H
43 #include "regIOobject.H"
44 #include "dimensionedTypes.H"
45 #include "DimensionedField.H"
46 #include "FieldField.H"
47 #include "lduInterfaceFieldPtrsList.H"
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 namespace Foam
54 class dictionary;
56 // Forward declaration of friend functions and operators
58 template<class Type, template<class> class PatchField, class GeoMesh>
59 class GeometricField;
61 template<class Type, template<class> class PatchField, class GeoMesh>
62 Ostream& operator<<
64     Ostream&,
65     const GeometricField<Type, PatchField, GeoMesh>&
68 template<class Type, template<class> class PatchField, class GeoMesh>
69 Ostream& operator<<
71     Ostream&,
72     const tmp<GeometricField<Type, PatchField, GeoMesh> >&
76 /*---------------------------------------------------------------------------*\
77                            Class GeometricField Declaration
78 \*---------------------------------------------------------------------------*/
80 template<class Type, template<class> class PatchField, class GeoMesh>
81 class GeometricField
83     public DimensionedField<Type, GeoMesh>
85     // Private member functions
87         //- Read from file if it is present
88         bool readIfPresent();
90         //- Read old time field from file if it is present
91         bool readOldTimeIfPresent();
94 public:
96     // Public typedefs
98         typedef typename GeoMesh::Mesh Mesh;
99         typedef typename GeoMesh::BoundaryMesh BoundaryMesh;
101         typedef DimensionedField<Type, GeoMesh> DimensionedInternalField;
102         typedef Field<Type> InternalField;
103         typedef PatchField<Type> PatchFieldType;
106     class GeometricBoundaryField
107     :
108         public FieldField<PatchField, Type>
109     {
110         // Private data
112             //- Reference to BoundaryMesh for which this field is defined
113             const BoundaryMesh& bmesh_;
116     public:
118         // Constructors
120             //- Construct from a BoundaryMesh,
121             //  reference to the internal field
122             //  and a patch type
123             GeometricBoundaryField
124             (
125                 const BoundaryMesh&,
126                 const DimensionedInternalField&,
127                 const word&
128             );
130             //- Construct from a BoundaryMesh,
131             //  reference to the internal field
132             //  and a wordList of patch types
133             GeometricBoundaryField
134             (
135                 const BoundaryMesh&,
136                 const DimensionedInternalField&,
137                 const wordList&
138             );
140             //- Construct from a BoundaryMesh,
141             //  reference to the internal field
142             //  and a PtrList<PatchField<Type> >
143             GeometricBoundaryField
144             (
145                 const BoundaryMesh&,
146                 const DimensionedInternalField&,
147                 const PtrList<PatchField<Type> >&
148             );
150             //- Construct as copy setting the reference to the internal field
151             GeometricBoundaryField
152             (
153                 const DimensionedInternalField&,
154                 const GeometricBoundaryField&
155             );
157             //- Construct as copy
158             //  Dangerous because Field may be set to a field which gets deleted
159             //  Need new type of BoundaryField, one which is part of a geometric
160             //  field for which snGrad etc. may be called and a free standing
161             //  BoundaryField for which such operations are unavailable.
162             GeometricBoundaryField
163             (
164                 const GeometricBoundaryField&
165             );
167             //- Construct from dictionary
168             GeometricBoundaryField
169             (
170                 const BoundaryMesh&,
171                 const DimensionedInternalField&,
172                 const dictionary&
173             );
176         // Member functions
178             //- Update the boundary condition coefficients
179             void updateCoeffs();
181             //- Evaluate boundary conditions
182             void evaluate();
184             //- Return a list of the patch types
185             wordList types() const;
187             //- Return BoundaryField of the cell values neighbouring
188             //  the boundary
189             GeometricBoundaryField boundaryInternalField() const;
191             //- Return a list of pointers for each patch field with only those
192             //  pointing to interfaces being set
193             lduInterfaceFieldPtrsList interfaces() const;
195             //- Write boundary field as dictionary entry
196             void writeEntry(const word& keyword, Ostream& os) const;
199         // Member operators
201             //- Assignment to BoundaryField<Type, PatchField, BoundaryMesh>
202             void operator=(const GeometricBoundaryField&);
204             //- Assignment to FieldField<PatchField, Type>
205             void operator=(const FieldField<PatchField, Type>&);
207             //- Assignment to Type
208             void operator=(const Type&);
211             //- Forced assignment to
212             //  BoundaryField<Type, PatchField, BoundaryMesh>
213             void operator==(const GeometricBoundaryField&);
215             //- Forced assignment to FieldField<PatchField, Type>
216             void operator==(const FieldField<PatchField, Type>&);
218             //- Forced assignment to Type
219             void operator==(const Type&);
220     };
223 private:
225     // Private data
227         //- Current time index.
228         //  Used to trigger the storing of the old-time value
229         mutable label timeIndex_;
231         //- Pointer to old time field
232         mutable GeometricField<Type, PatchField, GeoMesh>* field0Ptr_;
234         //-  Pointer to previous iteration (used for under-relaxation)
235         mutable GeometricField<Type, PatchField, GeoMesh>* fieldPrevIterPtr_;
237         //- Boundary Type field containing boundary field values
238         GeometricBoundaryField boundaryField_;
241     // Private member functions
243         //- Read the field from the dictionary
244         tmp<GeometricBoundaryField> readField(const dictionary&);
246         //- Read the field from the given stream
247         tmp<GeometricBoundaryField> readField(Istream& is);
250 public:
252     //- Runtime type information
253     TypeName("GeometricField");
256     // Public typedefs
258         typedef typename Field<Type>::cmptType cmptType;
260     // Static Member Functions
262         //- Return a null geometric field
263         inline static const GeometricField<Type, PatchField, GeoMesh>& null();
266     // Constructors
268         //- Constructor given IOobject, mesh, dimensions and patch type.
269         //  This allocates storage for the field but not values.
270         //  Used only within this class to create TEMPORARY variables
271         GeometricField
272         (
273             const IOobject&,
274             const Mesh&,
275             const dimensionSet&,
276             const word& patchFieldType=PatchField<Type>::calculatedType()
277         );
279         //- Constructor given IOobject, mesh, dimensions and patch types.
280         //  This allocates storage for the field but not values.
281         //  Used only within this class to create TEMPORARY variables
282         GeometricField
283         (
284             const IOobject&,
285             const Mesh&,
286             const dimensionSet&,
287             const wordList& patchFieldTypes
288         );
290         //- Constructor given IOobject, mesh, dimensioned<Type> and patch type.
291         GeometricField
292         (
293             const IOobject&,
294             const Mesh&,
295             const dimensioned<Type>&,
296             const word& patchFieldType=PatchField<Type>::calculatedType()
297         );
299         //- Constructor given IOobject, mesh, dimensioned<Type> and patch types.
300         GeometricField
301         (
302             const IOobject&,
303             const Mesh&,
304             const dimensioned<Type>&,
305             const wordList& patchFieldTypes
306         );
308         //- Constructor from components
309         GeometricField
310         (
311             const IOobject&,
312             const Mesh&,
313             const dimensionSet&,
314             const Field<Type>&,
315             const PtrList<PatchField<Type> >&
316         );
318         //- Construct and read given IOobject
319         GeometricField
320         (
321             const IOobject&,
322             const Mesh&
323         );
325         //- Construct and read from given stream
326         GeometricField
327         (
328             const IOobject&,
329             const Mesh&,
330             Istream&
331         );
333         //- Construct from dictionary
334         GeometricField
335         (
336             const IOobject&,
337             const Mesh&,
338             const dictionary&
339         );
341         //- Construct as copy
342         GeometricField
343         (
344             const GeometricField<Type, PatchField, GeoMesh>&
345         );
347         //- Construct as copy of tmp<GeometricField> deleting argument
348         #ifdef ConstructFromTmp
349         GeometricField
350         (
351             const tmp<GeometricField<Type, PatchField, GeoMesh> >&
352         );
353         #endif
355         //- Construct as copy resetting IO parameters
356         GeometricField
357         (
358             const IOobject&,
359             const GeometricField<Type, PatchField, GeoMesh>&
360         );
362         //- Construct as copy resetting name
363         GeometricField
364         (
365             const word& newName,
366             const GeometricField<Type, PatchField, GeoMesh>&
367         );
369         //- Construct as copy resetting name
370         #ifdef ConstructFromTmp
371         GeometricField
372         (
373             const word& newName,
374             const tmp<GeometricField<Type, PatchField, GeoMesh> >&
375         );
376         #endif
378         //- Construct as copy resetting IO parameters and patch type
379         GeometricField
380         (
381             const IOobject&,
382             const GeometricField<Type, PatchField, GeoMesh>&,
383             const word& patchFieldType
384         );
386         //- Construct as copy resetting IO parameters and boundary types
387         GeometricField
388         (
389             const IOobject&,
390             const GeometricField<Type, PatchField, GeoMesh>&,
391             const wordList& patchFieldTypes
392         );
395     //- Destructor
396     virtual ~GeometricField();
399     // Member Functions
401         //- Return dimensioned internal field
402         DimensionedInternalField& dimensionedInternalField();
404         //- Return dimensioned internal field
405         inline const DimensionedInternalField& dimensionedInternalField() const;
407         //- Return internal field
408         InternalField& internalField();
410         //- Return internal field
411         inline const InternalField& internalField() const;
413         //- Return reference to GeometricBoundaryField
414         GeometricBoundaryField& boundaryField();
416         //- Return reference to GeometricBoundaryField for const field
417         inline const GeometricBoundaryField& boundaryField() const;
419         //- Return the time index of the field
420         inline label timeIndex() const;
422         //- Return the time index of the field
423         inline label& timeIndex();
425         //- Store the old-time fields
426         void storeOldTimes() const;
428         //- Store the old-time field
429         void storeOldTime() const;
431         //- Return the number of old time fields stored
432         label nOldTimes() const;
434         //- Return old time field
435         const GeometricField<Type, PatchField, GeoMesh>& oldTime() const;
437         //- Return non-const old time field
438         //  (Not a good idea but it is used for sub-cycling)
439         GeometricField<Type, PatchField, GeoMesh>& oldTime();
441         //- Store the field as the previous iteration value
442         void storePrevIter() const;
444         //- Return previous iteration field
445         const GeometricField<Type, PatchField, GeoMesh>& prevIter() const;
447         //- Correct boundary field
448         void correctBoundaryConditions();
450         //- Does the field need a reference level for solution
451         bool needReference() const;
453         //- Return a component of the field
454         tmp<GeometricField<cmptType, PatchField, GeoMesh> > component
455         (
456             const direction
457         ) const;
459         //- WriteData member function required by regIOobject
460         bool writeData(Ostream&) const;
462         //- Return transpose (only if it is a tensor field)
463         tmp<GeometricField<Type, PatchField, GeoMesh> > T() const;
465         //- Relax field (for steady-state solution).
466         //  alpha = 1 : no relaxation
467         //  alpha < 1 : relaxation
468         //  alpha = 0 : do nothing
469         void relax(const scalar alpha);
471         //- Relax field (for steady-state solution).
472         //  alpha is read from controlDict
473         void relax();
476     // Member function *this operators
478         void negate();
480         void replace
481         (
482             const direction,
483             const GeometricField<cmptType, PatchField, GeoMesh>&
484         );
486         void replace
487         (
488             const direction,
489             const dimensioned<cmptType>&
490         );
492         void max(const dimensioned<Type>&);
493         void min(const dimensioned<Type>&);
495         void max
496         (
497             const GeometricField<Type, PatchField, GeoMesh>&,
498             const dimensioned<Type>&
499         );
501         void min
502         (
503             const GeometricField<Type, PatchField, GeoMesh>&,
504             const dimensioned<Type>&
505         );
507         void scale
508         (
509             const GeometricField<Type, PatchField, GeoMesh>&,
510             const GeometricField<Type, PatchField, GeoMesh>&
511         );
513         void scale
514         (
515             const GeometricField<Type, PatchField, GeoMesh>&,
516             const dimensioned<Type>&
517         );
520     // Member operators
522         void operator=(const GeometricField<Type, PatchField, GeoMesh>&);
523         void operator=(const tmp<GeometricField<Type, PatchField, GeoMesh> >&);
524         void operator=(const dimensioned<Type>&);
526         void operator==(const tmp<GeometricField<Type, PatchField, GeoMesh> >&);
527         void operator==(const dimensioned<Type>&);
529         void operator+=(const GeometricField<Type, PatchField, GeoMesh>&);
530         void operator+=(const tmp<GeometricField<Type, PatchField, GeoMesh> >&);
532         void operator-=(const GeometricField<Type, PatchField, GeoMesh>&);
533         void operator-=(const tmp<GeometricField<Type, PatchField, GeoMesh> >&);
535         void operator*=(const GeometricField<scalar, PatchField, GeoMesh>&);
536         void operator*=(const tmp<GeometricField<scalar,PatchField,GeoMesh> >&);
538         void operator/=(const GeometricField<scalar, PatchField, GeoMesh>&);
539         void operator/=(const tmp<GeometricField<scalar,PatchField,GeoMesh> >&);
541         void operator+=(const dimensioned<Type>&);
542         void operator-=(const dimensioned<Type>&);
544         void operator*=(const dimensioned<scalar>&);
545         void operator/=(const dimensioned<scalar>&);
548     // Ostream operators
550         friend Ostream& operator<< <Type, PatchField, GeoMesh>
551         (
552             Ostream&,
553             const GeometricField<Type, PatchField, GeoMesh>&
554         );
556         friend Ostream& operator<< <Type, PatchField, GeoMesh>
557         (
558             Ostream&,
559             const tmp<GeometricField<Type, PatchField, GeoMesh> >&
560         );
564 template<class Type, template<class> class PatchField, class GeoMesh>
565 Ostream& operator<<
567     Ostream&,
568     const typename GeometricField<Type, PatchField, GeoMesh>::
569     GeometricBoundaryField&
573 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
575 } // End namespace Foam
577 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
579 #include "GeometricFieldI.H"
581 #ifdef NoRepository
582 #   include "GeometricField.C"
583 #endif
585 #include "GeometricFieldFunctions.H"
587 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
589 #endif
591 // ************************************************************************* //