1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2011 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
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
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/>.
28 Generic GeometricField class.
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 // Forward declaration of friend functions and operators
57 template<class Type, template<class> class PatchField, class GeoMesh>
60 template<class Type, template<class> class PatchField, class GeoMesh>
64 const GeometricField<Type, PatchField, GeoMesh>&
67 template<class Type, template<class> class PatchField, class GeoMesh>
71 const tmp<GeometricField<Type, PatchField, GeoMesh> >&
75 /*---------------------------------------------------------------------------*\
76 Class GeometricField Declaration
77 \*---------------------------------------------------------------------------*/
79 template<class Type, template<class> class PatchField, class GeoMesh>
82 public DimensionedField<Type, GeoMesh>
84 // Private Member Functions
86 //- Read from file if it is present
89 //- Read old time field from file if it is present
90 bool readOldTimeIfPresent();
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
107 public FieldField<PatchField, Type>
111 //- Reference to BoundaryMesh for which this field is defined
112 const BoundaryMesh& bmesh_;
119 //- Construct from a BoundaryMesh,
120 // reference to the internal field
122 GeometricBoundaryField
125 const DimensionedInternalField&,
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
136 const DimensionedInternalField&,
137 const wordList& wantedPatchTypes,
138 const wordList& actualPatchTypes = wordList()
141 //- Construct from a BoundaryMesh,
142 // reference to the internal field
143 // and a PtrList<PatchField<Type> >
144 GeometricBoundaryField
147 const DimensionedInternalField&,
148 const PtrList<PatchField<Type> >&
151 //- Construct as copy setting the reference to the internal field
152 GeometricBoundaryField
154 const DimensionedInternalField&,
155 const GeometricBoundaryField&
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
165 const GeometricBoundaryField&
168 //- Construct from dictionary
169 GeometricBoundaryField
172 const DimensionedInternalField&,
179 //- Update the boundary condition coefficients
182 //- Evaluate boundary conditions
185 //- Return a list of the patch types
186 wordList types() const;
188 //- Return BoundaryField of the cell values neighbouring
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;
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&);
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);
253 //- Runtime type information
254 TypeName("GeometricField");
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();
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
277 const word& patchFieldType=PatchField<Type>::calculatedType()
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
288 const wordList& wantedPatchTypes,
289 const wordList& actualPatchTypes = wordList()
292 //- Constructor given IOobject, mesh, dimensioned<Type> and patch type.
297 const dimensioned<Type>&,
298 const word& patchFieldType=PatchField<Type>::calculatedType()
301 //- Constructor given IOobject, mesh, dimensioned<Type> and patch types.
306 const dimensioned<Type>&,
307 const wordList& wantedPatchTypes,
308 const wordList& actualPatchTypes = wordList()
311 //- Constructor from components
318 const PtrList<PatchField<Type> >&
321 //- Construct and read given IOobject
328 //- Construct from dictionary
336 //- Construct as copy
339 const GeometricField<Type, PatchField, GeoMesh>&
342 //- Construct as copy of tmp<GeometricField> deleting argument
343 #ifdef ConstructFromTmp
346 const tmp<GeometricField<Type, PatchField, GeoMesh> >&
350 //- Construct as copy resetting IO parameters
354 const GeometricField<Type, PatchField, GeoMesh>&
357 //- Construct as copy resetting name
361 const GeometricField<Type, PatchField, GeoMesh>&
364 //- Construct as copy resetting name
365 #ifdef ConstructFromTmp
369 const tmp<GeometricField<Type, PatchField, GeoMesh> >&
373 //- Construct as copy resetting IO parameters and patch type
377 const GeometricField<Type, PatchField, GeoMesh>&,
378 const word& patchFieldType
381 //- Construct as copy resetting IO parameters and boundary types
385 const GeometricField<Type, PatchField, GeoMesh>&,
386 const wordList& patchFieldTypes,
387 const wordList& actualPatchTypes = wordList()
392 virtual ~GeometricField();
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
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
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
484 const GeometricField<cmptType, PatchField, GeoMesh>&
490 const dimensioned<cmptType>&
493 void max(const dimensioned<Type>&);
494 void min(const dimensioned<Type>&);
498 const GeometricField<Type, PatchField, GeoMesh>&,
499 const dimensioned<Type>&
504 const GeometricField<Type, PatchField, GeoMesh>&,
505 const dimensioned<Type>&
510 const GeometricField<Type, PatchField, GeoMesh>&,
511 const GeometricField<Type, PatchField, GeoMesh>&
516 const GeometricField<Type, PatchField, GeoMesh>&,
517 const dimensioned<Type>&
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>&);
551 friend Ostream& operator<< <Type, PatchField, GeoMesh>
554 const GeometricField<Type, PatchField, GeoMesh>&
557 friend Ostream& operator<< <Type, PatchField, GeoMesh>
560 const tmp<GeometricField<Type, PatchField, GeoMesh> >&
565 template<class Type, template<class> class PatchField, class GeoMesh>
569 const typename GeometricField<Type, PatchField, GeoMesh>::
570 GeometricBoundaryField&
574 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
576 } // End namespace Foam
578 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
580 #include "GeometricFieldI.H"
583 # include "GeometricField.C"
586 #include "GeometricFieldFunctions.H"
588 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
592 // ************************************************************************* //