topoSet.H 11.4 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-2019 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 28 29 30 31 32 33 34

Class
    Foam::topoSet

Description
    General set of labels of mesh quantity (points, cells, faces).

SourceFiles
    topoSet.C
35
    topoSetTemplates.C
36 37 38 39 40 41

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

#ifndef topoSet_H
#define topoSet_H

42
#include "HashSet.H"
43 44 45 46 47 48 49 50 51 52 53
#include "regIOobject.H"
#include "labelList.H"
#include "typeInfo.H"
#include "autoPtr.H"
#include "pointField.H"

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

namespace Foam
{

54
// Forward Declarations
55 56 57
class mapPolyMesh;
class polyMesh;
class primitiveMesh;
58
class mapDistributePolyMesh;
59 60 61 62 63 64 65 66 67 68 69 70 71 72

/*---------------------------------------------------------------------------*\
                           Class topoSet Declaration
\*---------------------------------------------------------------------------*/

class topoSet
:
    public regIOobject,
    public labelHashSet
{
protected:

    // Protected Member Functions

73 74 75
        //- Update map from map.
        //  Used to update cell/face labels after morphing
        virtual void updateLabels(const labelUList& map);
76

77 78
        //- Check limits on addressable range.
        virtual void check(const label maxSize);
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

        //- Write part of contents nicely formatted. Prints labels only.
        void writeDebug
        (
            Ostream& os,
            const label maxElem,
            topoSet::const_iterator& iter,
            label& elemI
        ) const;

        //- Write part of contents nicely formatted. Prints label
        //  and corresponding coordinate.
        void writeDebug
        (
            Ostream& os,
            const pointField& coords,
            const label maxElem,
            topoSet::const_iterator& iter,
            label& elemI
        ) const;

        //- Write labels and coordinates columnwise to os. Truncate to maxLen.
        void writeDebug
        (
            Ostream& os,
            const pointField& coords,
            const label maxLen
        ) const;

108 109 110 111
        //- No copy construct
        topoSet(const topoSet&) = delete;


112 113 114 115 116 117 118 119
public:

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


    // Static

120 121 122
        //- Debug switch to disallow the use of generic sets
        static int disallowGenericSets;

123 124 125
        //- Name of file set will use.
        static fileName localPath(const polyMesh& mesh, const word& name);

126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
        //- Find IOobject in the polyMesh/sets (used as constructor helper)
        static IOobject findIOobject
        (
            const polyMesh& mesh,
            const word& name,
            readOption r=MUST_READ,
            writeOption w=NO_WRITE
        );

        //- Find IOobject in the polyMesh/sets (used as constructor helper)
        static IOobject findIOobject
        (
            const Time& runTime,
            const word& name,
            readOption r=MUST_READ,
            writeOption w=NO_WRITE
        );
143

144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176

    // Declare run-time constructor selection table

        // For the direct constructor
        declareRunTimeSelectionTable
        (
            autoPtr,
            topoSet,
            word,
            (
                const polyMesh& mesh,
                const word& name,
                readOption r,
                writeOption w
            ),
            (mesh, name, r, w)
        );

        // For the constructor from size
        declareRunTimeSelectionTable
        (
            autoPtr,
            topoSet,
            size,
            (
                const polyMesh& mesh,
                const word& name,
                const label size,
                writeOption w
            ),
            (mesh, name, size, w)
        );

mattijs's avatar
mattijs committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
        // For the constructor as copy
        declareRunTimeSelectionTable
        (
            autoPtr,
            topoSet,
            set,
            (
                const polyMesh& mesh,
                const word& name,
                const topoSet& set,
                writeOption w
            ),
            (mesh, name, set, w)
        );

192 193 194 195 196

    // Constructors

        //- Construct from IOobject as explicitly passed type.
        //  Can't use typeName info here since subclasses not yet instantiated
197
        topoSet(const IOobject& obj, const word& wantedType);
198

199 200 201
        //- Construct from polyMesh and name.
        //  Searches for a polyMesh/sets directory but not beyond the
        //  mesh.facesInstance().
202 203 204 205 206 207 208 209 210
        topoSet
        (
            const polyMesh& mesh,
            const word& wantedType,
            const word& name,
            readOption r=MUST_READ,
            writeOption w=NO_WRITE
        );

mattijs's avatar
mattijs committed
211
        //- Construct empty from additional size of labelHashSet.
212 213
        //  Searches for a polyMesh/sets directory but not beyond the
        //  mesh.facesInstance().
214 215 216 217
        topoSet
        (
            const polyMesh& mesh,
            const word& name,
218 219 220 221
            const label size,
            writeOption w=NO_WRITE
        );

222 223 224 225 226 227 228 229 230 231 232 233 234 235
        //- Construct (no-read) with copy of labelHashSet
        //  Searches for a polyMesh/sets directory but not beyond the
        //  mesh.facesInstance().
        topoSet
        (
            const polyMesh& mesh,
            const word& name,
            const labelHashSet& labels,
            writeOption w=NO_WRITE
        );

        //- Construct (no-read) with moving labelHashSet
        //  Searches for a polyMesh/sets directory but not beyond the
        //  mesh.facesInstance().
236 237 238 239
        topoSet
        (
            const polyMesh& mesh,
            const word& name,
240
            labelHashSet&& labels,
241 242 243
            writeOption w=NO_WRITE
        );

244 245 246
        //- Construct (no-read) with copy of labels
        //  Searches for a polyMesh/sets directory but not beyond the
        //  mesh.facesInstance().
247 248 249 250
        topoSet
        (
            const polyMesh& mesh,
            const word& name,
251
            const labelUList& labels,
252 253 254
            writeOption w=NO_WRITE
        );

255 256
        //- Construct empty from IOobject and HashSet size.
        topoSet(const IOobject& io, const label size);
257

258 259
        //- Construct from IOobject and copy of labelHashSet.
        topoSet(const IOobject& io, const labelHashSet& labels);
260

261 262
        //- Construct from IOobject and move labelHashSet.
        topoSet(const IOobject& io, labelHashSet&& labels);
263 264 265 266 267


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


    // Selectors

mattijs's avatar
mattijs committed
275
        //- Return a pointer to a toposet read from file
276 277 278 279 280 281 282 283 284
        static autoPtr<topoSet> New
        (
            const word& setType,
            const polyMesh& mesh,
            const word& name,
            readOption r=MUST_READ,
            writeOption w=NO_WRITE
        );

mattijs's avatar
mattijs committed
285
        //- Return a pointer to a new toposet of given size
286 287 288 289 290 291 292 293 294
        static autoPtr<topoSet> New
        (
            const word& setType,
            const polyMesh& mesh,
            const word& name,
            const label size,
            writeOption w=NO_WRITE
        );

mattijs's avatar
mattijs committed
295 296 297 298 299 300 301 302 303 304
        //- Return a pointer to a new toposet as copy of another toposet
        static autoPtr<topoSet> New
        (
            const word& setType,
            const polyMesh& mesh,
            const word& name,
            const topoSet& set,
            writeOption w=NO_WRITE
        );

305

306
    //- Destructor
307
    virtual ~topoSet() = default;
308 309


310 311
    // Member Functions

312 313 314
        //- Has the given index?
        virtual bool found(const label id) const;

315 316 317 318 319 320 321 322 323 324 325
        //- Set an index
        virtual bool set(const label id);

        //- Unset an index
        virtual bool unset(const label id);

        //- Set multiple indices
        virtual void set(const labelUList& labels);

        //- Unset multiple indices
        virtual void unset(const labelUList& labels);
326

327 328
        //- Invert contents.
        //  Insert all members [0,maxLen) which were not in set.
329 330 331 332 333 334 335 336
        virtual void invert(const label maxLen);

        //- Subset contents. Only elements present in both sets remain.
        virtual void subset(const topoSet& set);

        //- Add elements present in set.
        virtual void addSet(const topoSet& set);

337 338 339
        //- Subtract elements present in set.
        virtual void subtractSet(const topoSet& set);

340 341 342 343 344 345 346
        //- Sync set across coupled patches.
        virtual void sync(const polyMesh& mesh);

        //- Write labels columnwise to os. Truncate to maxLen.
        virtual void writeDebug(Ostream& os, const label maxLen) const;

        //- Like above but also writes mesh related quantity
347
        //- (usually coordinate).
348 349 350 351 352
        virtual void writeDebug
        (
            Ostream& os,
            const primitiveMesh&,
            const label maxLen
mattijs's avatar
mattijs committed
353
        ) const = 0;
354 355 356 357 358 359 360

        //- Write contents.
        virtual bool writeData(Ostream&) const;

        //- Update any stored data for new labels. Not implemented.
        virtual void updateMesh(const mapPolyMesh& morphMap);

361 362 363
        //- Update any stored data for mesh redistribution.
        virtual void distribute(const mapDistributePolyMesh&) = 0;

364
        //- Return max allowable index (+1). Not implemented.
mattijs's avatar
mattijs committed
365
        virtual label maxSize(const polyMesh& mesh) const = 0;
366

367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
        //- Helper: call updateMesh on all sets in container (and
        //  updates instance)
        template<class Container>
        static void updateMesh
        (
            const fileName& instance,
            const mapPolyMesh&,
            Container&
        );

        //- Helper: set instance on all sets in container
        template<class Container>
        static void setInstance(const fileName& instance, Container&);

        //- Helper: remove all sets files from mesh instance
        static void removeFiles(const polyMesh&);
383 384


385
    // Member Operators
386 387 388 389

        //- Copy labelHashSet part only
        void operator=(const topoSet&);

390 391 392 393 394 395

    // Housekeeping

        //- Deprecated(2018-10) subtract elements present in set.
        //  \deprecated(2018-10) - use subtractSet instead
        virtual void deleteSet(const topoSet& set);
396 397 398 399 400 401 402 403 404
};


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

} // End namespace Foam

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

405 406 407 408 409 410
#ifdef NoRepository
    #include "topoSetTemplates.C"
#endif

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

411 412 413
#endif

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