FreeFOAM The Cross-Platform CFD Toolkit
setsToFaceZone.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "setsToFaceZone.H"
27 #include <OpenFOAM/polyMesh.H>
28 #include <meshTools/faceZoneSet.H>
29 #include <meshTools/cellSet.H>
30 
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(setsToFaceZone, 0);
38  addToRunTimeSelectionTable(topoSetSource, setsToFaceZone, word);
39  addToRunTimeSelectionTable(topoSetSource, setsToFaceZone, istream);
40 }
41 
42 
43 Foam::topoSetSource::addToUsageTable Foam::setsToFaceZone::usage_
44 (
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"
49 );
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
54 // Construct from components
56 (
57  const polyMesh& mesh,
58  const word& faceSetName,
59  const word& cellSetName
60 )
61 :
62  topoSetSource(mesh),
63  faceSetName_(faceSetName),
64  cellSetName_(cellSetName)
65 {}
66 
67 
68 // Construct from dictionary
70 (
71  const polyMesh& mesh,
72  const dictionary& dict
73 )
74 :
75  topoSetSource(mesh),
76  faceSetName_(dict.lookup("faceSet")),
77  cellSetName_(dict.lookup("cellSet"))
78 {}
79 
80 
81 // Construct from Istream
83 (
84  const polyMesh& mesh,
85  Istream& is
86 )
87 :
88  topoSetSource(mesh),
89  faceSetName_(checkIs(is)),
90  cellSetName_(checkIs(is))
91 {}
92 
93 
94 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
95 
97 {}
98 
99 
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101 
103 (
104  const topoSetSource::setAction action,
105  topoSet& set
106 ) const
107 {
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);
119 
120  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
121  {
122  Info<< " Adding all faces from faceSet " << faceSetName_
123  << " ..." << endl;
124 
125  // Load the sets
126  faceSet fSet(mesh_, faceSetName_);
127  cellSet cSet(mesh_, cellSetName_);
128 
129  // Start off from copy
130  DynamicList<label> newAddressing(fzSet.addressing());
131  DynamicList<bool> newFlipMap(fzSet.flipMap());
132 
133  forAllConstIter(faceSet, fSet, iter)
134  {
135  label faceI = iter.key();
136 
137  if (!fzSet.found(faceI))
138  {
139  bool flip = false;
140 
141  label own = mesh_.faceOwner()[faceI];
142  bool ownFound = cSet.found(own);
143 
144  if (mesh_.isInternalFace(faceI))
145  {
146  label nei = mesh_.faceNeighbour()[faceI];
147  bool neiFound = cSet.found(nei);
148 
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  }
179 
180  newAddressing.append(faceI);
181  newFlipMap.append(flip);
182  }
183  }
184 
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;
193 
194  // Load the set
195  faceZoneSet loadedSet(mesh_, faceSetName_);
196 
197  // Start off empty
198  DynamicList<label> newAddressing(fzSet.addressing().size());
199  DynamicList<bool> newFlipMap(fzSet.flipMap().size());
200 
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  }
214 }
215 
216 
217 // ************************ vim: set sw=4 sts=4 et: ************************ //