Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / meshTools / sets / faceZoneSources / setsToFaceZone / setsToFaceZone.C
blob1a8bc972454ff52a7e2c12f09b308fb102959b1a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "setsToFaceZone.H"
27 #include "polyMesh.H"
28 #include "faceZoneSet.H"
29 #include "cellSet.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 namespace Foam
37     defineTypeNameAndDebug(setsToFaceZone, 0);
38     addToRunTimeSelectionTable(topoSetSource, setsToFaceZone, word);
39     addToRunTimeSelectionTable(topoSetSource, setsToFaceZone, istream);
43 Foam::topoSetSource::addToUsageTable Foam::setsToFaceZone::usage_
45     setsToFaceZone::typeName,
46     "\n    Usage: setsToFaceZone <faceSet> <slaveCellSet>\n\n"
47     "    Select all faces in the faceSet."
48     " Orientated so slave side is in cellSet.\n\n"
52 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
54 // Construct from components
55 Foam::setsToFaceZone::setsToFaceZone
57     const polyMesh& mesh,
58     const word& faceSetName,
59     const word& cellSetName
62     topoSetSource(mesh),
63     faceSetName_(faceSetName),
64     cellSetName_(cellSetName)
68 // Construct from dictionary
69 Foam::setsToFaceZone::setsToFaceZone
71     const polyMesh& mesh,
72     const dictionary& dict
75     topoSetSource(mesh),
76     faceSetName_(dict.lookup("faceSet")),
77     cellSetName_(dict.lookup("cellSet"))
81 // Construct from Istream
82 Foam::setsToFaceZone::setsToFaceZone
84     const polyMesh& mesh,
85     Istream& is
88     topoSetSource(mesh),
89     faceSetName_(checkIs(is)),
90     cellSetName_(checkIs(is))
94 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
96 Foam::setsToFaceZone::~setsToFaceZone()
100 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
102 void Foam::setsToFaceZone::applyToSet
104     const topoSetSource::setAction action,
105     topoSet& set
106 ) const
108     if (!isA<faceZoneSet>(set))
109     {
110         WarningIn
111         (
112             "setsToFaceZone::applyToSet(const topoSetSource::setAction"
113             ", topoSet"
114         )   << "Operation only allowed on a faceZoneSet." << endl;
115     }
116     else
117     {
118         faceZoneSet& fzSet = refCast<faceZoneSet>(set);
120         if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
121         {
122             Info<< "    Adding all faces from faceSet " << faceSetName_
123                 << " ..." << endl;
125             // Load the sets
126             faceSet fSet(mesh_, faceSetName_);
127             cellSet cSet(mesh_, cellSetName_);
129             // Start off from copy
130             DynamicList<label> newAddressing(fzSet.addressing());
131             DynamicList<bool> newFlipMap(fzSet.flipMap());
133             forAllConstIter(faceSet, fSet, iter)
134             {
135                 label faceI = iter.key();
137                 if (!fzSet.found(faceI))
138                 {
139                     bool flip = false;
141                     label own = mesh_.faceOwner()[faceI];
142                     bool ownFound = cSet.found(own);
144                     if (mesh_.isInternalFace(faceI))
145                     {
146                         label nei = mesh_.faceNeighbour()[faceI];
147                         bool neiFound = cSet.found(nei);
149                         if (ownFound && !neiFound)
150                         {
151                             flip = false;
152                         }
153                         else if (!ownFound && neiFound)
154                         {
155                             flip = true;
156                         }
157                         else
158                         {
159                             WarningIn
160                             (
161                                 "setsToFaceZone::applyToSet"
162                                 "(const topoSetSource::setAction, topoSet)"
163                             )   << "One of owner or neighbour of internal face "
164                                 << faceI << " should be in cellSet "
165                                 << cSet.name()
166                                 << " to be able to determine orientation."
167                                 << endl
168                                 << "Face:" << faceI << " own:" << own
169                                 << " OwnInCellSet:" << ownFound
170                                 << " nei:" << nei
171                                 << " NeiInCellSet:" << neiFound
172                                 << endl;
173                         }
174                     }
175                     else
176                     {
177                         flip = !ownFound;
178                     }
180                     newAddressing.append(faceI);
181                     newFlipMap.append(flip);
182                 }
183             }
185             fzSet.addressing().transfer(newAddressing);
186             fzSet.flipMap().transfer(newFlipMap);
187             fzSet.updateSet();
188         }
189         else if (action == topoSetSource::DELETE)
190         {
191             Info<< "    Removing all faces from faceSet " << faceSetName_
192                 << " ..." << endl;
194             // Load the set
195             faceZoneSet loadedSet(mesh_, faceSetName_);
197             // Start off empty
198             DynamicList<label> newAddressing(fzSet.addressing().size());
199             DynamicList<bool> newFlipMap(fzSet.flipMap().size());
201             forAll(fzSet.addressing(), i)
202             {
203                 if (!loadedSet.found(fzSet.addressing()[i]))
204                 {
205                     newAddressing.append(fzSet.addressing()[i]);
206                     newFlipMap.append(fzSet.flipMap()[i]);
207                 }
208             }
209             fzSet.addressing().transfer(newAddressing);
210             fzSet.flipMap().transfer(newFlipMap);
211             fzSet.updateSet();
212         }
213     }
217 // ************************************************************************* //