cellToFace.C 5.91 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
Mark Olesen's avatar
Mark Olesen committed
5
    \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6
7
8
9
10
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

11
12
13
14
    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.
15
16
17
18
19
20
21

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

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

#include "cellToFace.H"
#include "polyMesh.H"
#include "cellSet.H"
#include "Time.H"
mattijs's avatar
mattijs committed
30
#include "syncTools.H"
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "addToRunTimeSelectionTable.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{

defineTypeNameAndDebug(cellToFace, 0);

addToRunTimeSelectionTable(topoSetSource, cellToFace, word);

addToRunTimeSelectionTable(topoSetSource, cellToFace, istream);

}


Foam::topoSetSource::addToUsageTable Foam::cellToFace::usage_
(
    cellToFace::typeName,
    "\n    Usage: cellToFace <cellSet> all|both\n\n"
    "    Select -all : all faces of cells in the cellSet\n"
    "           -both: faces where both neighbours are in the cellSet\n\n"
);

template<>
const char* Foam::NamedEnum<Foam::cellToFace::cellAction, 2>::names[] =
{
    "all",
    "both"
};

const Foam::NamedEnum<Foam::cellToFace::cellAction, 2>
    Foam::cellToFace::cellActionNames_;


// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //

void Foam::cellToFace::combine(topoSet& set, const bool add) const
{
    // Load the set
    if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName_)))
    {
        SeriousError<< "Cannot load set "
            << setName_ << endl;
    }
76

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    cellSet loadedSet(mesh_, setName_);

    if (option_ == ALL)
    {
        // Add all faces from cell
        for
        (
            cellSet::const_iterator iter = loadedSet.begin();
            iter != loadedSet.end();
            ++iter
        )
        {
            label cellI = iter.key();

            const labelList& cFaces = mesh_.cells()[cellI];

            forAll(cFaces, cFaceI)
            {
                addOrDelete(set, cFaces[cFaceI], add);
            }
        }
    }
    else if (option_ == BOTH)
    {
        // Add all faces whose both neighbours are in set.

mattijs's avatar
mattijs committed
103
104
105
106
        label nInt = mesh_.nInternalFaces();
        const labelList& own = mesh_.faceOwner();
        const labelList& nei = mesh_.faceNeighbour();
        const polyBoundaryMesh& patches = mesh_.boundaryMesh();
107

mattijs's avatar
mattijs committed
108
109
110

        // Check all internal faces
        for (label faceI = 0; faceI < nInt; faceI++)
111
        {
mattijs's avatar
mattijs committed
112
113
114
115
116
            if (loadedSet.found(own[faceI]) && loadedSet.found(nei[faceI]))
            {
                addOrDelete(set, faceI, add);
            }
        }
117
118


mattijs's avatar
mattijs committed
119
120
        // Get coupled cell status
        boolList neiInSet(mesh_.nFaces()-nInt, false);
121

mattijs's avatar
mattijs committed
122
123
124
        forAll(patches, patchI)
        {
            const polyPatch& pp = patches[patchI];
125

mattijs's avatar
mattijs committed
126
127
128
129
            if (pp.coupled())
            {
                label faceI = pp.start();
                forAll(pp, i)
130
                {
mattijs's avatar
mattijs committed
131
132
                    neiInSet[faceI-nInt] = loadedSet.found(own[faceI]);
                    faceI++;
133
134
135
                }
            }
        }
mattijs's avatar
mattijs committed
136
        syncTools::swapBoundaryFaceList(mesh_, neiInSet, false);
137

mattijs's avatar
mattijs committed
138
139
140

        // Check all boundary faces
        forAll(patches, patchI)
141
        {
mattijs's avatar
mattijs committed
142
143
144
            const polyPatch& pp = patches[patchI];

            if (pp.coupled())
145
            {
mattijs's avatar
mattijs committed
146
147
148
149
150
151
152
153
154
                label faceI = pp.start();
                forAll(pp, i)
                {
                    if (loadedSet.found(own[faceI]) && neiInSet[faceI-nInt])
                    {
                        addOrDelete(set, faceI, add);
                    }
                    faceI++;
                }
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
            }
        }
    }
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

// Construct from componenta
Foam::cellToFace::cellToFace
(
    const polyMesh& mesh,
    const word& setName,
    const cellAction option
)
:
    topoSetSource(mesh),
    setName_(setName),
173
    option_(option)
174
175
176
177
178
179
180
{}


// Construct from dictionary
Foam::cellToFace::cellToFace
(
    const polyMesh& mesh,
181
    const dictionary& dict
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
)
:
    topoSetSource(mesh),
    setName_(dict.lookup("set")),
    option_(cellActionNames_.read(dict.lookup("option")))
{}


// Construct from Istream
Foam::cellToFace::cellToFace
(
    const polyMesh& mesh,
    Istream& is
)
:
    topoSetSource(mesh),
    setName_(checkIs(is)),
    option_(cellActionNames_.read(checkIs(is)))
{}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

Foam::cellToFace::~cellToFace()
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

void Foam::cellToFace::applyToSet
(
    const topoSetSource::setAction action,
    topoSet& set
) const
{
    if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
    {
mattijs's avatar
mattijs committed
219
        Info<< "    Adding faces according to cellSet " << setName_
220
221
222
223
224
225
            << " ..." << endl;

        combine(set, true);
    }
    else if (action == topoSetSource::DELETE)
    {
mattijs's avatar
mattijs committed
226
        Info<< "    Removing faces according to cellSet " << setName_
227
228
229
230
231
232
233
234
            << " ..." << endl;

        combine(set, false);
    }
}


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