sampledSurface.H 16.3 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
OpenFOAM bot's avatar
OpenFOAM bot committed
6 7
     \\/     M anipulation  |
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2011-2016 OpenFOAM Foundation
9
    Copyright (C) 2016-2020 OpenCFD Ltd.
10 11 12 13
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

14 15 16 17
    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.
18 19 20 21 22 23 24

    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
25
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
26 27

Class
28
    Foam::sampledSurface
29

30
Group
31
    grpUtilitiesFunctionObjects
32

33
Description
34
    An abstract class for surfaces with sampling.
35

36 37 38 39 40 41 42 43 44 45 46 47 48
    The constructors for the derived classes should generally start in a
    'expired' condition (ie, needsUpdate() == true) and rely on a
    subsequent call to the update() method to complete the initialization.
    Delaying the final construction as late as possible allows the
    construction of surfaces that may depend on intermediate calculation
    results (eg, iso-surfaces) and also avoids the unnecessary
    reconstruction of surfaces between sampling intervals.

    It is the responsibility of the caller to ensure that the surface
    update() is called before the surface is used.  The update() method
    implementation should do nothing when the surface is already
    up-to-date.

49 50 51 52 53 54 55 56 57
    Any sampler is assumed to work for the standard volume field types.
    Some may also support surface fields.

    Dictionary entries:
    \table
        Property    | Description                           | Required | Default
        name        | Alternative name                      | no  |
        enabled     | Enable/disable the surface?           | no  | yes
        interpolate | Sample to nodes instead of faces      | no  | false
58
        invariant   | Invariant with geometry change (use with caution!) | no  | false
59 60
    \endtable

61 62 63 64 65 66
Note
    The invariant switch is an advanced feature to declare that the surface is
    unaffected by changes in the general mesh geometry.  For example, if sampling
    on a static patch while some other motion occurs elsewhere. If used improperly,
    there is a significant possibility for problems (caveat emptor).

67 68
SourceFiles
    sampledSurface.C
69
    sampledSurfaceTemplates.C
70 71 72 73 74 75

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

#ifndef sampledSurface_H
#define sampledSurface_H

76 77
#include "polySurface.H"
#include "surfMesh.H"
78 79 80
#include "typeInfo.H"
#include "runTimeSelectionTables.H"
#include "autoPtr.H"
81
#include "polyMesh.H"
82
#include "volFieldsFwd.H"
83 84
#include "surfaceFieldsFwd.H"
#include "surfaceMesh.H"
85 86 87 88 89 90 91 92
#include "interpolation.H"

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

namespace Foam
{

/*---------------------------------------------------------------------------*\
93
                       Class sampledSurface Declaration
94 95 96
\*---------------------------------------------------------------------------*/

class sampledSurface
97 98
:
    public meshedSurf
99
{
100 101 102 103 104 105 106 107
public:

    // Public Static Data

        //- Class names for surface field types
        static const wordList surfaceFieldTypes;


108 109
private:

110
    // Private Data
111

112
        //- The name of the sample surface
113 114
        word name_;

115 116 117
        //- Reference to mesh
        const polyMesh& mesh_;

118 119 120
        //- Should surface sampling be enabled?
        bool enabled_;

121 122 123
        //- Geometry is invariant (never changes)
        bool invariant_;

124 125
        //- Interpolate information to the nodes?
        bool interpolate_;
126

127 128
        //- Total surface area (demand-driven)
        mutable scalar area_;
129 130


131
protected:
132

133
    // Protected Member Functions
134

135
        //- Loop for sampling volume elements to faces.
136
        //  The defaultValue is used for invalid (negative) elements
137 138
        template<class Type>
        static tmp<Field<Type>> sampleOnFaces
139
        (
140 141 142
            const interpolation<Type>& sampler,
            const labelUList& elements,
            const faceList& fcs,
143 144
            const pointField& pts,
            const Type& defaultValue = Type(Zero)
145
        );
146

Andrew Heather's avatar
Andrew Heather committed
147

148 149 150 151 152 153 154 155 156 157 158
        //- Loop for interpolating volume elements to face points.
        template<class Type>
        static tmp<Field<Type>> sampleOnPoints
        (
            const interpolation<Type>& interpolator,
            const labelUList& elements,
            const faceList& fcs,
            const pointField& pts
        );


159 160 161 162 163 164
        //- Create cell values by averaging the point values
        template<class Type>
        static tmp<GeometricField<Type, fvPatchField, volMesh>> pointAverage
        (
            const GeometricField<Type, pointPatchField, pointMesh>& pfld
        );
165

166

167
        //- Additional cleanup when clearing the geometry
168 169
        virtual void clearGeom() const;

170 171
        //- Construct null
        explicit sampledSurface(const word& name, std::nullptr_t);
Andrew Heather's avatar
Andrew Heather committed
172

173

174 175 176
public:

    //- Runtime type information
Andrew Heather's avatar
Andrew Heather committed
177
    TypeName("sampledSurface");
178

Andrew Heather's avatar
Andrew Heather committed
179 180 181 182 183 184
    //- Declare run-time constructor selection table
    declareRunTimeSelectionTable
    (
        autoPtr,
        sampledSurface,
        word,
185
        (
Andrew Heather's avatar
Andrew Heather committed
186 187 188 189 190 191 192
            const word& name,
            const polyMesh& mesh,
            const dictionary& dict
        ),
        (name, mesh, dict)
    );

193

194
        //- PtrList read-construction helper
195 196 197 198 199 200 201 202 203 204 205 206 207 208
        class iNew
        {
            //- Reference to the volume mesh
            const polyMesh& mesh_;

        public:

            iNew(const polyMesh& mesh)
            :
                mesh_(mesh)
            {}

            autoPtr<sampledSurface> operator()(Istream& is) const
            {
209
                word name(is);
210 211
                dictionary dict(is);

212
                return sampledSurface::New(name, mesh_, dict);
213 214 215 216
            }
        };


217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
        //- PtrList read-construction helper that captures dictionaries used
        //- during creation.
        class iNewCapture
        {
            //- Reference to the volume mesh
            const polyMesh& mesh_;

            //- Captured (recorded) dictionaries
            DynamicList<dictionary>& capture_;

        public:

            iNewCapture(const polyMesh& mesh, DynamicList<dictionary>& capture)
            :
                mesh_(mesh),
                capture_(capture)
            {}

            autoPtr<sampledSurface> operator()(Istream& is) const
            {
                word name(is);
                capture_.append(dictionary(is));

                return sampledSurface::New(name, mesh_, capture_.last());
            }
        };


245 246
    // Constructors

247
        //- Construct from name, mesh
248 249 250
        sampledSurface
        (
            const word& name,
251
            const polyMesh& mesh,
252
            const bool interpolate = false
253 254 255 256 257
        );

        //- Construct from dictionary
        sampledSurface
        (
258
            const word& name,
259 260
            const polyMesh& mesh,
            const dictionary& dict
261 262 263 264 265
        );

        //- Clone
        autoPtr<sampledSurface> clone() const
        {
266
            NotImplemented;
267
            return nullptr;
268 269 270 271 272 273 274 275
        }


    // Selectors

        //- Return a reference to the selected surface
        static autoPtr<sampledSurface> New
        (
276
            const word& name,
277 278
            const polyMesh& mesh,
            const dictionary& dict
279 280 281
        );


282
    //- Destructor - calls clearGeom()
283
    virtual ~sampledSurface();
284 285 286 287


    // Member Functions

288
    // Access
289

290
        //- Access to the underlying mesh
291 292 293 294 295 296 297 298 299 300 301
        const polyMesh& mesh() const
        {
            return mesh_;
        }

        //- Name of surface
        const word& name() const
        {
            return name_;
        }

302
        //- Surface is enabled
303 304 305 306 307
        bool enabled() const
        {
            return enabled_;
        }

308 309 310 311 312 313 314
        //- Surface is invariant with geometry change (caution)
        bool invariant() const
        {
            return invariant_;
        }

        //- Interpolation to nodes requested for surface
315 316 317 318 319
        bool interpolate() const
        {
            return interpolate_;
        }

320 321 322 323 324 325 326 327 328 329 330 331
        //- Does the surface need an update?
        virtual bool needsUpdate() const = 0;

        //- Mark the surface as needing an update.
        //  May also free up unneeded data.
        //  Return false if surface was already marked as expired.
        virtual bool expire() = 0;

        //- Update the surface as required.
        //  Do nothing (and return false) if no update was required
        virtual bool update() = 0;

332 333 334 335 336 337
        //- Points of surface
        virtual const pointField& points() const = 0;

        //- Faces of surface
        virtual const faceList& faces() const = 0;

338 339
        //- Face area vectors
        virtual const vectorField& Sf() const = 0;
340

341 342
        //- Face area magnitudes
        virtual const scalarField& magSf() const = 0;
343

344 345
        //- Face centres
        virtual const vectorField& Cf() const = 0;
346

347 348 349
        //- The total surface area
        scalar area() const;

350 351 352 353 354 355 356
        //- If element ids/order of the original surface are available
        virtual bool hasFaceIds() const
        {
            return false;
        }


357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
    // General registry storage (optional)

        //- Get surface from registry if available.
        //  \param obr The objectRegistry to use
        //  \param lookupName Optional lookup name, use surface name if empty
        //  \return surface or nullptr
        polySurface* getRegistrySurface
        (
            const objectRegistry& obr,
            word lookupName = ""
        ) const;

        //- Copy surface into registry.
        //  \param obr The objectRegistry to use
        //  \param lookupName Optional lookup name, use surface name if empty
        //  \return surface or nullptr it surface should not be stored
        polySurface* storeRegistrySurface
        (
            objectRegistry& obr,
            word lookupName = ""
        ) const;

        //- Remove surface from registry.
        //  \param obr The objectRegistry to use
        //  \param lookupName Optional lookup name, use surface name if empty
        //  \return True if surface existed and was removed
        bool removeRegistrySurface
        (
            objectRegistry& obr,
            word lookupName = ""
        ) const;

        //- Copy/store sampled field onto registered surface (if it exists)
        template<class Type, class GeoMeshType>
        bool storeRegistryField
        (
            const objectRegistry& obr,
            const word& fieldName,
            const dimensionSet& dims,
            const Field<Type>& values,
            word lookupName = ""
        ) const;

        //- Move/store sampled field onto registered surface (if it exists)
        template<class Type, class GeoMeshType>
        bool storeRegistryField
        (
            const objectRegistry& obr,
            const word& fieldName,
            const dimensionSet& dims,
            Field<Type>&& values,
            word lookupName = ""
        ) const;


    // Specialized surfMesh storage (optional)

        //- Get surface from registry if available.
        //  \param lookupName Optional lookup name, use surface name if empty
        //  \return surface or nullptr
        surfMesh* getSurfMesh(word lookupName = "") const;

        //- Copy surface into registry.
        //  \param lookupName Optional lookup name, use surface name if empty
        //  \return surface or nullptr it surface should not be stored
        surfMesh* storeSurfMesh(word lookupName = "") const;

        //- Remove surface from registry.
        //  \param lookupName Optional lookup name, use surface name if empty
        //  \return True if surface existed and was removed
        bool removeSurfMesh(word lookupName = "") const;

        //- Copy/store sampled Face field onto surfMesh (if it exists)
        template<class Type, class GeoMeshType>
        bool storeSurfMeshField
        (
            const word& fieldName,
            const dimensionSet& dims,
            const Field<Type>& values,
            word lookupName = ""
        ) const;

        //- Move/store sampled Face field onto surfMesh (if it exists)
        template<class Type, class GeoMeshType>
        bool storeSurfMeshField
        (
            const word& fieldName,
            const dimensionSet& dims,
            Field<Type>&& values,
            word lookupName = ""
        ) const;


450
    // Sample (faces)
451

452
        //- Sample volume field onto surface faces
453 454
        virtual tmp<scalarField> sample
        (
455
            const interpolation<scalar>& sampler
456 457
        ) const = 0;

458
        //- Sample volume field onto surface faces
459 460
        virtual tmp<vectorField> sample
        (
461
            const interpolation<vector>& sampler
462 463
        ) const = 0;

464
        //- Sample volume field onto surface faces
465 466
        virtual tmp<sphericalTensorField> sample
        (
467
            const interpolation<sphericalTensor>& sampler
468 469
        ) const = 0;

470
        //- Sample volume field onto surface faces
471 472
        virtual tmp<symmTensorField> sample
        (
473
            const interpolation<symmTensor>& sampler
474 475
        ) const = 0;

476
        //- Sample volume field onto surface faces
477 478
        virtual tmp<tensorField> sample
        (
479
            const interpolation<tensor>& sampler
480 481
        ) const = 0;

482

483 484 485 486
        //- Can it sample surface-fields?
        virtual bool withSurfaceFields() const;


487
        //- Sample surface field onto surface
488 489
        virtual tmp<scalarField> sample
        (
490
            const surfaceScalarField& sField
491 492
        ) const;

493
        //- Sample surface field onto surface
494 495
        virtual tmp<vectorField> sample
        (
496
            const surfaceVectorField& sField
497 498
        ) const;

499
        //- Sample surface field onto surface
500 501
        virtual tmp<sphericalTensorField> sample
        (
502
            const surfaceSphericalTensorField& sField
503 504
        ) const;

505
        //- Sample surface field onto surface
506 507
        virtual tmp<symmTensorField> sample
        (
508
            const surfaceSymmTensorField& sField
509 510
        ) const;

511
        //- Sample surface field onto surface
512 513
        virtual tmp<tensorField> sample
        (
514
            const surfaceTensorField& sField
515
        ) const;
516

517

518 519
    // Interpolate (points)

520
        //- Interpolate volume field onto surface points
521 522
        virtual tmp<scalarField> interpolate
        (
523
            const interpolation<scalar>& interpolator
524 525
        ) const = 0;

526
        //- Interpolate volume field onto surface points
527 528
        virtual tmp<vectorField> interpolate
        (
529
            const interpolation<vector>& interpolator
530 531
        ) const = 0;

532
        //- Interpolate volume field onto surface points
533 534
        virtual tmp<sphericalTensorField> interpolate
        (
535
            const interpolation<sphericalTensor>& interpolator
536 537
        ) const = 0;

538
        //- Interpolate volume field onto surface points
539 540
        virtual tmp<symmTensorField> interpolate
        (
541
            const interpolation<symmTensor>& interpolator
542 543
        ) const = 0;

544
        //- Interpolate volume field onto surface points
545 546
        virtual tmp<tensorField> interpolate
        (
547
            const interpolation<tensor>& interpolator
548 549
        ) const = 0;

550

551
    // Edit
552

553 554 555 556 557 558
        //- Rename
        virtual void rename(const word& newName)
        {
            name_ = newName;
        }

559

560
    // Write
561

562 563
        //- Print information
        virtual void print(Ostream& os) const;
564 565 566
};


567 568 569 570 571
// Global Operators

//- Ostream operator
Ostream& operator<<(Ostream& os, const sampledSurface& s);

572 573 574 575 576 577 578
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

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

#ifdef NoRepository
579
    #include "sampledSurfaceTemplates.C"
580 581 582 583 584 585 586
#endif

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

#endif

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