fvMeshSubsetProxy.H 7.94 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 14 15 16 17 18 19 20 21 22 23 24 25 26 27
-------------------------------------------------------------------------------
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
28
    Foam::fvMeshSubsetProxy
29 30

Description
31 32
    Simple proxy for holding a mesh, or mesh-subset.
    The subMeshes are currently limited to cellSet or cellZone definitions.
33 34

SourceFiles
35 36
    fvMeshSubsetProxy.C
    fvMeshSubsetProxyTemplates.C
37 38 39

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

40 41
#ifndef fvMeshSubsetProxy_H
#define fvMeshSubsetProxy_H
42

43
#include "wordRes.H"
44 45 46 47 48 49 50 51 52
#include "fvMeshSubset.H"
#include "zeroGradientFvPatchField.H"

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

namespace Foam
{

/*---------------------------------------------------------------------------*\
53
                      Class fvMeshSubsetProxy Declaration
54 55
\*---------------------------------------------------------------------------*/

56
class fvMeshSubsetProxy
57
{
58 59
public:

60 61
    // Data Types

62
        //- Internal bookkeeping for subset type
63 64
        enum subsetType
        {
65 66 67 68
            NONE,       //<! No subset
            SET,        //<! Subset with a cellSet
            ZONE,       //<! Subset with a cellZone
            ZONES       //<! Subset with multiple cellZones
69 70 71
        };


72 73
private:

74
    // Private Data
75 76 77 78

        //- Reference to mesh
        fvMesh& baseMesh_;

79
        //- Subsetting engine
80 81
        fvMeshSubset subsetter_;

82 83
        //- Patch ID for exposed internal faces
        label exposedPatchId_;
84

85 86
        //- The subsetting type
        subsetType type_;
87

88 89 90 91 92
        //- Name of the cellSet/cellZone (or empty)
        word name_;

        //- Selection for multiple cell zones
        wordRes names_;
93

94 95 96
        //- The (cached) cell selection
        bitSet selectedCells_;

97 98 99

    // Private Member Functions

100
        //- No copy construct
101
        fvMeshSubsetProxy(const fvMeshSubsetProxy&) = delete;
102

103
        //- No copy assignment
104
        void operator=(const fvMeshSubsetProxy&) = delete;
105 106 107 108 109 110


public:

    // Constructors

111 112
        //- Construct a pass-through proxy. No correct() invoked or required.
        explicit fvMeshSubsetProxy(fvMesh& baseMesh);
113

114
        //- Construct from components
115
        fvMeshSubsetProxy
116 117
        (
            fvMesh& baseMesh,
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
            const subsetType type,
            const word& selectionName,
            label exposedPatchId = -1
        );

        //- Construct from components. The subsetType is ZONES.
        fvMeshSubsetProxy
        (
            fvMesh& baseMesh,
            const wordRes& zoneNames,
            label exposedPatchId = -1
        );

        //- Construct from components. The subsetType is ZONES.
        fvMeshSubsetProxy
        (
            fvMesh& baseMesh,
            wordRes&& zoneNames,
            label exposedPatchId = -1
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
        );


    // Member Functions

    // Access

        //- The entire base mesh
        inline const fvMesh& baseMesh() const
        {
            return baseMesh_;
        }

        //- The mesh subsetter
        inline const fvMeshSubset& subsetter() const
        {
            return subsetter_;
        }

156
        //- Check if a sub-mesh is being used
157 158
        inline bool useSubMesh() const
        {
159
            return type_ != NONE;
160 161
        }

162
        //- Access either base-mesh or sub-mesh
163 164 165 166 167 168
        inline const fvMesh& mesh() const
        {
            if (useSubMesh())
            {
                return subsetter_.subMesh();
            }
169 170 171 172 173 174 175 176

            return baseMesh_;
        }

        //- The associated (set or zone) name if any.
        inline const word& name() const
        {
            return name_;
177 178
        }

179 180 181 182 183 184
        //- The current cell selection, when subsetting is active
        inline const bitSet& selectedCells() const
        {
            return selectedCells_;
        }

185 186 187

    // Edit

188 189 190
        //- Update of mesh subset.
        //  Return true if the subset changed from previous call.
        bool correct(bool verbose = false);
191

192
        //- Read mesh. Correct on topo-change
193 194 195
        polyMesh::readUpdateState readUpdate();


196 197
    // Fields

198 199 200 201 202
        //- Construct volField (with zeroGradient) from an internal field
        template<class Type>
        static tmp<GeometricField<Type, fvPatchField, volMesh>>
        zeroGradientField
        (
203 204 205 206 207 208 209 210 211 212
            const DimensionedField<Type, volMesh>& df
        );

        //- Convert an internal field to a volume field (with zeroGradient)
        template<class Type>
        static tmp<GeometricField<Type, fvPatchField, volMesh>>
        interpolateInternal
        (
            const fvMeshSubset& subsetter,
            const DimensionedField<Type, volMesh>& df
213 214
        );

215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
        //- Convert an internal field to a volume field (with zeroGradient)
        //  Currently no proper memory reuse
        template<class Type>
        static tmp<GeometricField<Type, fvPatchField, volMesh>>
        interpolateInternal
        (
            const fvMeshSubset& subsetter,
            const tmp<DimensionedField<Type, volMesh>>& tdf
        );

        //- Wrapper for field or the subsetted field.
        //  Pass through or forward to fvMeshSubset::interpolate()
        template<class GeoField>
        static tmp<GeoField> interpolate
        (
            const fvMeshSubset& subsetter,
            const GeoField& fld
        );
233 234

        //- Wrapper for field or the subsetted field.
235 236 237 238 239 240 241 242 243 244 245 246
        //  Pass through or forward to fvMeshSubset::interpolate()
        template<class GeoField>
        static tmp<GeoField> interpolate
        (
            const fvMeshSubset& subsetter,
            const tmp<GeoField>& fld
        );


    // Fields

        //- Convert an internal field to a volume field (with zeroGradient)
247 248
        template<class Type>
        tmp<GeometricField<Type, fvPatchField, volMesh>>
249
        interpolateInternal
250
        (
251
            const DimensionedField<Type, volMesh>& df
252 253
        ) const;

254 255
        //- Convert an internal field to a volume field (with zeroGradient)
        //  Currently no proper memory reuse
256 257
        template<class Type>
        tmp<GeometricField<Type, fvPatchField, volMesh>>
258
        interpolateInternal
259
        (
260
            const tmp<DimensionedField<Type, volMesh>>& tdf
261 262
        ) const;

263

264 265
        //- Wrapper for field or the subsetted field.
        //  Pass through or forward to fvMeshSubset::interpolate()
266 267
        template<class GeoField>
        tmp<GeoField> interpolate(const GeoField& fld) const;
268 269 270 271 272

        //- Wrapper for field or the subsetted field.
        //  Pass through or forward to fvMeshSubset::interpolate()
        template<class GeoField>
        tmp<GeoField> interpolate(const tmp<GeoField>& fld) const;
273 274 275 276 277 278 279 280 281 282
};


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

} // End namespace Foam

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

#ifdef NoRepository
283
    #include "fvMeshSubsetProxyTemplates.C"
284 285 286 287 288
#endif

#endif

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