1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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
29 Generic GeometricField class.
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 // Forward declaration of friend functions and operators
58 template<class Type, template<class> class PatchField, class GeoMesh>
61 template<class Type, template<class> class PatchField, class GeoMesh>
65 const GeometricField<Type, PatchField, GeoMesh>&
68 template<class Type, template<class> class PatchField, class GeoMesh>
72 const tmp<GeometricField<Type, PatchField, GeoMesh> >&
76 /*---------------------------------------------------------------------------*\
77 Class GeometricField Declaration
78 \*---------------------------------------------------------------------------*/
80 template<class Type, template<class> class PatchField, class GeoMesh>
83 public DimensionedField<Type, GeoMesh>
85 // Private member functions
87 //- Read from file if it is present
90 //- Read old time field from file if it is present
91 bool readOldTimeIfPresent();
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
108 public FieldField<PatchField, Type>
112 //- Reference to BoundaryMesh for which this field is defined
113 const BoundaryMesh& bmesh_;
120 //- Construct from a BoundaryMesh,
121 // reference to the internal field
123 GeometricBoundaryField
126 const DimensionedInternalField&,
130 //- Construct from a BoundaryMesh,
131 // reference to the internal field
132 // and a wordList of patch types
133 GeometricBoundaryField
136 const DimensionedInternalField&,
140 //- Construct from a BoundaryMesh,
141 // reference to the internal field
142 // and a PtrList<PatchField<Type> >
143 GeometricBoundaryField
146 const DimensionedInternalField&,
147 const PtrList<PatchField<Type> >&
150 //- Construct as copy setting the reference to the internal field
151 GeometricBoundaryField
153 const DimensionedInternalField&,
154 const GeometricBoundaryField&
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
164 const GeometricBoundaryField&
167 //- Construct from dictionary
168 GeometricBoundaryField
171 const DimensionedInternalField&,
178 //- Update the boundary condition coefficients
181 //- Evaluate boundary conditions
184 //- Return a list of the patch types
185 wordList types() const;
187 //- Return BoundaryField of the cell values neighbouring
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;
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&);
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);
252 //- Runtime type information
253 TypeName("GeometricField");
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();
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
276 const word& patchFieldType=PatchField<Type>::calculatedType()
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
287 const wordList& patchFieldTypes
290 //- Constructor given IOobject, mesh, dimensioned<Type> and patch type.
295 const dimensioned<Type>&,
296 const word& patchFieldType=PatchField<Type>::calculatedType()
299 //- Constructor given IOobject, mesh, dimensioned<Type> and patch types.
304 const dimensioned<Type>&,
305 const wordList& patchFieldTypes
308 //- Constructor from components
315 const PtrList<PatchField<Type> >&
318 //- Construct and read given IOobject
325 //- Construct and read from given stream
333 //- Construct from dictionary
341 //- Construct as copy
344 const GeometricField<Type, PatchField, GeoMesh>&
347 //- Construct as copy of tmp<GeometricField> deleting argument
348 #ifdef ConstructFromTmp
351 const tmp<GeometricField<Type, PatchField, GeoMesh> >&
355 //- Construct as copy resetting IO parameters
359 const GeometricField<Type, PatchField, GeoMesh>&
362 //- Construct as copy resetting name
366 const GeometricField<Type, PatchField, GeoMesh>&
369 //- Construct as copy resetting name
370 #ifdef ConstructFromTmp
374 const tmp<GeometricField<Type, PatchField, GeoMesh> >&
378 //- Construct as copy resetting IO parameters and patch type
382 const GeometricField<Type, PatchField, GeoMesh>&,
383 const word& patchFieldType
386 //- Construct as copy resetting IO parameters and boundary types
390 const GeometricField<Type, PatchField, GeoMesh>&,
391 const wordList& patchFieldTypes
396 virtual ~GeometricField();
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
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
476 // Member function *this operators
483 const GeometricField<cmptType, PatchField, GeoMesh>&
489 const dimensioned<cmptType>&
492 void max(const dimensioned<Type>&);
493 void min(const dimensioned<Type>&);
497 const GeometricField<Type, PatchField, GeoMesh>&,
498 const dimensioned<Type>&
503 const GeometricField<Type, PatchField, GeoMesh>&,
504 const dimensioned<Type>&
509 const GeometricField<Type, PatchField, GeoMesh>&,
510 const GeometricField<Type, PatchField, GeoMesh>&
515 const GeometricField<Type, PatchField, GeoMesh>&,
516 const dimensioned<Type>&
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>&);
550 friend Ostream& operator<< <Type, PatchField, GeoMesh>
553 const GeometricField<Type, PatchField, GeoMesh>&
556 friend Ostream& operator<< <Type, PatchField, GeoMesh>
559 const tmp<GeometricField<Type, PatchField, GeoMesh> >&
564 template<class Type, template<class> class PatchField, class GeoMesh>
568 const typename GeometricField<Type, PatchField, GeoMesh>::
569 GeometricBoundaryField&
573 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
575 } // End namespace Foam
577 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
579 #include "GeometricFieldI.H"
582 # include "GeometricField.C"
585 #include "GeometricFieldFunctions.H"
587 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
591 // ************************************************************************* //