GeometricField.H 21.4 KB
Newer Older
Henry's avatar
Henry committed
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
6
     \\/     M anipulation  | Copyright (C) 2015-2019 OpenCFD Ltd.
Henry's avatar
Henry committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Class
    Foam::GeometricField

Description
    Generic GeometricField class.

SourceFiles
    GeometricFieldI.H
    GeometricField.C
33
    Boundary.C
Henry's avatar
Henry committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
    GeometricFieldFunctions.H
    GeometricFieldFunctions.C

\*---------------------------------------------------------------------------*/

#ifndef GeometricField_H
#define GeometricField_H

#include "regIOobject.H"
#include "dimensionedTypes.H"
#include "DimensionedField.H"
#include "FieldField.H"
#include "lduInterfaceFieldPtrsList.H"
#include "LduInterfaceFieldPtrsList.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

54
// Forward declarations
Henry's avatar
Henry committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
class dictionary;

template<class Type, template<class> class PatchField, class GeoMesh>
class GeometricField;

template<class Type, template<class> class PatchField, class GeoMesh>
Ostream& operator<<
(
    Ostream&,
    const GeometricField<Type, PatchField, GeoMesh>&
);

template<class Type, template<class> class PatchField, class GeoMesh>
Ostream& operator<<
(
    Ostream&,
71
    const tmp<GeometricField<Type, PatchField, GeoMesh>>&
Henry's avatar
Henry committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
);


/*---------------------------------------------------------------------------*\
                           Class GeometricField Declaration
\*---------------------------------------------------------------------------*/

template<class Type, template<class> class PatchField, class GeoMesh>
class GeometricField
:
    public DimensionedField<Type, GeoMesh>
{
    // Private Member Functions

        //- Read from file if it is present
        bool readIfPresent();

        //- Read old time field from file if it is present
        bool readOldTimeIfPresent();


public:

    // Public typedefs

97
        //- Type of mesh on which this GeometricField is instantiated
Henry's avatar
Henry committed
98
        typedef typename GeoMesh::Mesh Mesh;
99 100

        //- Type of boundary mesh on which this
101
        //  GeometricField::Boundary is instantiated
Henry's avatar
Henry committed
102 103
        typedef typename GeoMesh::BoundaryMesh BoundaryMesh;

104 105 106 107
        //- Type of the internal field from which this GeometricField is derived
        typedef DimensionedField<Type, GeoMesh> Internal;

        //- Type of the patch field of which the
108
        //  GeometricField::Boundary is composed
109
        typedef PatchField<Type> Patch;
Henry's avatar
Henry committed
110 111


112
    class Boundary
Henry's avatar
Henry committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126
    :
        public FieldField<PatchField, Type>
    {
        // Private data

            //- Reference to BoundaryMesh for which this field is defined
            const BoundaryMesh& bmesh_;


    public:

        // Constructors

            //- Construct from a BoundaryMesh
127
            Boundary(const BoundaryMesh& bmesh);
Henry's avatar
Henry committed
128 129 130 131

            //- Construct from a BoundaryMesh,
            //  reference to the internal field
            //  and a patch type
132
            Boundary
Henry's avatar
Henry committed
133
            (
134 135 136
                const BoundaryMesh& bmesh,
                const Internal& field,
                const word& patchFieldType
Henry's avatar
Henry committed
137 138 139 140 141 142
            );

            //- Construct from a BoundaryMesh,
            //  reference to the internal field
            //  and a wordList of patch types and optional the actual patch
            //  types (to override constraint patches)
143
            Boundary
Henry's avatar
Henry committed
144
            (
145 146
                const BoundaryMesh& bmesh,
                const Internal& field,
Henry's avatar
Henry committed
147 148 149 150 151 152
                const wordList& wantedPatchTypes,
                const wordList& actualPatchTypes = wordList()
            );

            //- Construct from a BoundaryMesh,
            //  reference to the internal field
153
            //  and a PtrList<PatchField<Type>>
154
            Boundary
Henry's avatar
Henry committed
155
            (
156 157
                const BoundaryMesh& bmesh,
                const Internal& field,
158
                const PtrList<PatchField<Type>>&
Henry's avatar
Henry committed
159 160 161
            );

            //- Construct as copy setting the reference to the internal field
162
            Boundary
Henry's avatar
Henry committed
163
            (
164 165
                const Internal& field,
                const Boundary& btf
Henry's avatar
Henry committed
166 167 168 169 170 171 172
            );

            //- Construct as copy
            //  Dangerous because Field may be set to a field which gets deleted
            //  Need new type of BoundaryField, one which is part of a geometric
            //  field for which snGrad etc. may be called and a free standing
            //  BoundaryField for which such operations are unavailable.
173
            Boundary
Henry's avatar
Henry committed
174
            (
175
                const Boundary& btf
Henry's avatar
Henry committed
176 177 178
            );

            //- Construct from dictionary
179
            Boundary
Henry's avatar
Henry committed
180
            (
181 182
                const BoundaryMesh& bmesh,
                const Internal& field,
183
                const dictionary& dict
Henry's avatar
Henry committed
184 185 186
            );


187
        // Member Functions
Henry's avatar
Henry committed
188 189 190 191

            //- Read the boundary field
            void readField
            (
192
                const Internal& field,
Henry's avatar
Henry committed
193 194 195 196 197 198 199 200 201 202 203 204 205 206
                const dictionary& dict
            );

            //- Update the boundary condition coefficients
            void updateCoeffs();

            //- Evaluate boundary conditions
            void evaluate();

            //- Return a list of the patch types
            wordList types() const;

            //- Return BoundaryField of the cell values neighbouring
            //  the boundary
207
            Boundary boundaryInternalField() const;
Henry's avatar
Henry committed
208 209 210 211 212 213 214 215 216 217 218 219

            //- Return a list of pointers for each patch field with only those
            //  pointing to interfaces being set
            LduInterfaceFieldPtrsList<Type> interfaces() const;

            //- Return a list of pointers for each patch field with only those
            //  pointing to interfaces being set
            lduInterfaceFieldPtrsList scalarInterfaces() const;

            //- Write boundary field as dictionary entry
            void writeEntry(const word& keyword, Ostream& os) const;

220 221 222
            //- Write dictionary entries of the individual boundary fields.
            void writeEntries(Ostream& os) const;

Henry's avatar
Henry committed
223 224 225 226

        // Member operators

            //- Assignment to BoundaryField<Type, PatchField, BoundaryMesh>
227
            void operator=(const Boundary&);
Henry's avatar
Henry committed
228 229 230 231 232 233 234 235 236 237

            //- Assignment to FieldField<PatchField, Type>
            void operator=(const FieldField<PatchField, Type>&);

            //- Assignment to Type
            void operator=(const Type&);


            //- Forced assignment to
            //  BoundaryField<Type, PatchField, BoundaryMesh>
238
            void operator==(const Boundary&);
Henry's avatar
Henry committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262

            //- Forced assignment to FieldField<PatchField, Type>
            void operator==(const FieldField<PatchField, Type>&);

            //- Forced assignment to Type
            void operator==(const Type&);
    };


private:

    // Private data

        //- Current time index.
        //  Used to trigger the storing of the old-time value
        mutable label timeIndex_;

        //- Pointer to old time field
        mutable GeometricField<Type, PatchField, GeoMesh>* field0Ptr_;

        //-  Pointer to previous iteration (used for under-relaxation)
        mutable GeometricField<Type, PatchField, GeoMesh>* fieldPrevIterPtr_;

        //- Boundary Type field containing boundary field values
263
        Boundary boundaryField_;
Henry's avatar
Henry committed
264 265 266 267 268


    // Private Member Functions

        //- Read the field from the dictionary
269
        void readFields(const dictionary& dict);
Henry's avatar
Henry committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292

        //- Read the field - create the field dictionary on-the-fly
        void readFields();


public:

    //- Runtime type information
    TypeName("GeometricField");


    // Public typedefs

        typedef typename Field<Type>::cmptType cmptType;

    // Static Member Functions

        //- Return a null geometric field
        inline static const GeometricField<Type, PatchField, GeoMesh>& null();


    // Constructors

293 294
        //- Construct given IOobject, mesh, dimensions and patch type.
        //  This allocates storage for the field but does not set values.
Henry's avatar
Henry committed
295 296 297
        //  Used only within this class to create TEMPORARY variables
        GeometricField
        (
298 299 300
            const IOobject& io,
            const Mesh& mesh,
            const dimensionSet& ds,
301
            const word& patchFieldType = PatchField<Type>::calculatedType()
Henry's avatar
Henry committed
302 303
        );

304 305
        //- Construct given IOobject, mesh, dimensions and patch types.
        //  This allocates storage for the field but does not set values.
Henry's avatar
Henry committed
306 307 308
        //  Used only within this class to create TEMPORARY variables
        GeometricField
        (
309 310 311
            const IOobject& io,
            const Mesh& mesh,
            const dimensionSet& ds,
Henry's avatar
Henry committed
312 313 314 315
            const wordList& wantedPatchTypes,
            const wordList& actualPatchTypes = wordList()
        );

316 317 318
        //- Construct given IOobject, mesh, dimensioned<Type> and patch type.
        //  This assigns both dimensions and values.
        //  The internal name for the dimensioned\<Type\> has no influence.
Henry's avatar
Henry committed
319 320
        GeometricField
        (
321 322 323
            const IOobject& io,
            const Mesh& mesh,
            const dimensioned<Type>& dt,
324
            const word& patchFieldType = PatchField<Type>::calculatedType()
Henry's avatar
Henry committed
325 326
        );

327 328 329
        //- Construct given IOobject, mesh, dimensioned<Type> and patch types.
        //  This assigns both dimensions and values.
        //  The internal name for the dimensioned\<Type\> has no influence.
Henry's avatar
Henry committed
330 331
        GeometricField
        (
332 333 334
            const IOobject& io,
            const Mesh& mesh,
            const dimensioned<Type>& dt,
Henry's avatar
Henry committed
335 336 337 338
            const wordList& wantedPatchTypes,
            const wordList& actualPatchTypes = wordList()
        );

339
        //- Copy construct from components
340 341
        GeometricField
        (
342 343 344
            const IOobject& io,
            const Internal& diField,
            const PtrList<PatchField<Type>>& ptfl
345 346
        );

347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
        //- Copy construct from internal field, with specified patch type
        GeometricField
        (
            const IOobject& io,
            const Mesh& mesh,
            const dimensionSet& ds,
            const Field<Type>& iField,
            const word& patchFieldType = PatchField<Type>::calculatedType()
        );

        //- Move construct from internal field, with specified patch type
        GeometricField
        (
            const IOobject& io,
            const Mesh& mesh,
            const dimensionSet& ds,
            Field<Type>&& iField,
            const word& patchFieldType = PatchField<Type>::calculatedType()
        );

367
        //- Copy construct from components
Henry's avatar
Henry committed
368 369
        GeometricField
        (
370 371 372 373 374
            const IOobject& io,
            const Mesh& mesh,
            const dimensionSet& ds,
            const Field<Type>& iField,
            const PtrList<PatchField<Type>>& ptfl
Henry's avatar
Henry committed
375 376 377 378 379
        );

        //- Construct and read given IOobject
        GeometricField
        (
380 381
            const IOobject& io,
            const Mesh& mesh,
382
            const bool readOldTime = true
Henry's avatar
Henry committed
383 384 385 386 387
        );

        //- Construct from dictionary
        GeometricField
        (
388 389 390
            const IOobject& io,
            const Mesh& mesh,
            const dictionary& dict
Henry's avatar
Henry committed
391 392
        );

393
        //- Copy construct
Henry's avatar
Henry committed
394 395
        GeometricField
        (
396
            const GeometricField<Type, PatchField, GeoMesh>& gf
Henry's avatar
Henry committed
397 398
        );

399
        //- Construct from tmp\<GeometricField\> deleting argument
Henry's avatar
Henry committed
400 401
        GeometricField
        (
402
            const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf
Henry's avatar
Henry committed
403 404 405 406 407
        );

        //- Construct as copy resetting IO parameters
        GeometricField
        (
408 409
            const IOobject& io,
            const GeometricField<Type, PatchField, GeoMesh>& gf
Henry's avatar
Henry committed
410 411
        );

412 413 414
        //- Construct as copy of tmp<GeometricField> resetting IO parameters
        GeometricField
        (
415 416
            const IOobject& io,
            const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf
417 418
        );

419
        //- Copy construct with a new name
Henry's avatar
Henry committed
420 421 422
        GeometricField
        (
            const word& newName,
423
            const GeometricField<Type, PatchField, GeoMesh>& gf
Henry's avatar
Henry committed
424 425
        );

426
        //- Construct with a new name from tmp\<GeometricField\>
Henry's avatar
Henry committed
427 428 429
        GeometricField
        (
            const word& newName,
430
            const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf
Henry's avatar
Henry committed
431 432 433 434 435
        );

        //- Construct as copy resetting IO parameters and patch type
        GeometricField
        (
436 437
            const IOobject& io,
            const GeometricField<Type, PatchField, GeoMesh>& gf,
Henry's avatar
Henry committed
438 439 440 441 442 443
            const word& patchFieldType
        );

        //- Construct as copy resetting IO parameters and boundary types
        GeometricField
        (
444 445
            const IOobject& io,
            const GeometricField<Type, PatchField, GeoMesh>& gf,
Henry's avatar
Henry committed
446 447 448 449
            const wordList& patchFieldTypes,
            const wordList& actualPatchTypes = wordList()
        );

450 451 452
        //- Construct as copy resetting IO parameters and boundary types
        GeometricField
        (
453 454
            const IOobject& io,
            const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf,
455 456 457 458
            const wordList& patchFieldTypes,
            const wordList& actualPatchTypes = wordList()
        );

459 460 461
        //- Clone
        tmp<GeometricField<Type, PatchField, GeoMesh>> clone() const;

Henry's avatar
Henry committed
462 463 464 465 466 467 468

    //- Destructor
    virtual ~GeometricField();


    // Member Functions

469
        //- Return a reference to the dimensioned internal field
470 471 472 473 474
        //  \param updateAccessTime update event counter and check
        //      old-time fields
        //
        //  \note Should avoid using updateAccessTime = true within loops.
        Internal& ref(const bool updateAccessTime = true);
Henry's avatar
Henry committed
475

476
        //- Return a const-reference to the dimensioned internal field
477
        inline const Internal& internalField() const;
Henry's avatar
Henry committed
478

479
        //- Return a const-reference to the dimensioned internal field
480 481
        //- of a "vol" field.
        //  Useful in the formulation of source-terms for FV equations
482 483
        //
        //  \note definition in finiteVolume/fields/volFields/volFieldsI.H
484
        inline const Internal& v() const;
Henry's avatar
Henry committed
485

486
        //- Return a reference to the internal field
487 488 489 490 491 492 493 494
        //  \param updateAccessTime update event counter and check
        //      old-time fields
        //
        //  \note Should avoid using updateAccessTime = true within loops.
        typename Internal::FieldType& primitiveFieldRef
        (
            const bool updateAccessTime = true
        );
Henry's avatar
Henry committed
495

496
        //- Return a const-reference to the  internal field
497
        inline const typename Internal::FieldType& primitiveField() const;
Henry's avatar
Henry committed
498

499
        //- Return a reference to the boundary field
500 501 502 503 504
        //  \param updateAccessTime update event counter and check
        //      old-time fields
        //
        //  \note Should avoid using updateAccessTime = true within loops.
        Boundary& boundaryFieldRef(const bool updateAccessTime = true);
505

506
        //- Return const-reference to the boundary field
507
        inline const Boundary& boundaryField() const;
Henry's avatar
Henry committed
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543

        //- Return the time index of the field
        inline label timeIndex() const;

        //- Return the time index of the field
        inline label& timeIndex();

        //- Store the old-time fields
        void storeOldTimes() const;

        //- Store the old-time field
        void storeOldTime() const;

        //- Return the number of old time fields stored
        label nOldTimes() const;

        //- Return old time field
        const GeometricField<Type, PatchField, GeoMesh>& oldTime() const;

        //- Return non-const old time field
        //  (Not a good idea but it is used for sub-cycling)
        GeometricField<Type, PatchField, GeoMesh>& oldTime();

        //- Store the field as the previous iteration value
        void storePrevIter() const;

        //- Return previous iteration field
        const GeometricField<Type, PatchField, GeoMesh>& prevIter() const;

        //- Correct boundary field
        void correctBoundaryConditions();

        //- Does the field need a reference level for solution
        bool needReference() const;

        //- Return a component of the field
544
        tmp<GeometricField<cmptType, PatchField, GeoMesh>> component
Henry's avatar
Henry committed
545 546 547 548 549 550 551 552
        (
            const direction
        ) const;

        //- WriteData member function required by regIOobject
        bool writeData(Ostream&) const;

        //- Return transpose (only if it is a tensor field)
553
        tmp<GeometricField<Type, PatchField, GeoMesh>> T() const;
Henry's avatar
Henry committed
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575

        //- Relax field (for steady-state solution).
        //  alpha = 1 : no relaxation
        //  alpha < 1 : relaxation
        //  alpha = 0 : do nothing
        void relax(const scalar alpha);

        //- Relax field (for steady-state solution).
        //  alpha is read from controlDict
        void relax();

        //- Select the final iteration parameters if `final' is true
        //  by returning the field name + "Final"
        //  otherwise the standard parameters by returning the field name
        word select(bool final) const;

        //- Helper function to write the min and max to an Ostream
        void writeMinMax(Ostream& os) const;


    // Member function *this operators

576
        //- Negate the field inplace
Henry's avatar
Henry committed
577 578
        void negate();

579
        //- Replace specified field component with content from another field
Henry's avatar
Henry committed
580 581
        void replace
        (
582 583
            const direction d,
            const GeometricField<cmptType, PatchField, GeoMesh>& gcf
Henry's avatar
Henry committed
584 585
        );

586
        //- Replace specified field component with specified value
Henry's avatar
Henry committed
587 588
        void replace
        (
589 590
            const direction d,
            const dimensioned<cmptType>& ds
Henry's avatar
Henry committed
591 592
        );

593 594 595 596 597 598 599
        //- Use the minimum of the field and specified value
        //  This sets the \em ceiling on the field values
        void min(const dimensioned<Type>& dt);

        //- Use the maximum of the field and specified value
        //  This sets the \em floor on the field values
        void max(const dimensioned<Type>& dt);
Henry's avatar
Henry committed
600

601 602 603 604 605
        //- Clip the field to be bounded within the specified range
        void clip(const dimensioned<MinMax<Type>>& range);

        //- Clip the field to be bounded within the specified range
        void clip
606
        (
607 608
            const dimensioned<Type>& minVal,
            const dimensioned<Type>& maxVal
609 610
        );

611 612 613 614 615 616 617 618
        //- Deprecated(2019-01) identical to clip()
        //  \deprecated(2019-01) identical to clip()
        void maxMin
        (
            const dimensioned<Type>& minVal,
            const dimensioned<Type>& maxVal
        ) FOAM_DEPRECATED_FOR(2019-01, "clip() method");

Henry's avatar
Henry committed
619

620
    // Member Operators
Henry's avatar
Henry committed
621

622
        //- Return a const-reference to the dimensioned internal field
623 624
        //  Useful in the formulation of source-terms for FV equations
        inline const Internal& operator()() const;
625

Henry's avatar
Henry committed
626
        void operator=(const GeometricField<Type, PatchField, GeoMesh>&);
627
        void operator=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);
Henry's avatar
Henry committed
628 629
        void operator=(const dimensioned<Type>&);

630
        void operator==(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);
Henry's avatar
Henry committed
631 632 633
        void operator==(const dimensioned<Type>&);

        void operator+=(const GeometricField<Type, PatchField, GeoMesh>&);
634
        void operator+=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);
Henry's avatar
Henry committed
635 636

        void operator-=(const GeometricField<Type, PatchField, GeoMesh>&);
637
        void operator-=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);
Henry's avatar
Henry committed
638 639

        void operator*=(const GeometricField<scalar, PatchField, GeoMesh>&);
640
        void operator*=(const tmp<GeometricField<scalar,PatchField,GeoMesh>>&);
Henry's avatar
Henry committed
641 642

        void operator/=(const GeometricField<scalar, PatchField, GeoMesh>&);
643
        void operator/=(const tmp<GeometricField<scalar,PatchField,GeoMesh>>&);
Henry's avatar
Henry committed
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662

        void operator+=(const dimensioned<Type>&);
        void operator-=(const dimensioned<Type>&);

        void operator*=(const dimensioned<scalar>&);
        void operator/=(const dimensioned<scalar>&);


    // Ostream operators

        friend Ostream& operator<< <Type, PatchField, GeoMesh>
        (
            Ostream&,
            const GeometricField<Type, PatchField, GeoMesh>&
        );

        friend Ostream& operator<< <Type, PatchField, GeoMesh>
        (
            Ostream&,
663
            const tmp<GeometricField<Type, PatchField, GeoMesh>>&
Henry's avatar
Henry committed
664 665 666 667 668 669 670 671 672
        );
};


template<class Type, template<class> class PatchField, class GeoMesh>
Ostream& operator<<
(
    Ostream&,
    const typename GeometricField<Type, PatchField, GeoMesh>::
673
    Boundary&
Henry's avatar
Henry committed
674 675 676 677 678 679 680 681 682 683 684 685
);


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#include "GeometricFieldI.H"

#ifdef NoRepository
686
    #include "GeometricField.C"
Henry's avatar
Henry committed
687 688 689 690 691 692 693 694 695
#endif

#include "GeometricFieldFunctions.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //