FreeFOAM The Cross-Platform CFD Toolkit
cellToFace.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 "cellToFace.H"
27 #include <OpenFOAM/polyMesh.H>
28 #include <meshTools/cellSet.H>
29 #include <OpenFOAM/Time.H>
30 #include <OpenFOAM/syncTools.H>
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
38 defineTypeNameAndDebug(cellToFace, 0);
39 
40 addToRunTimeSelectionTable(topoSetSource, cellToFace, word);
41 
42 addToRunTimeSelectionTable(topoSetSource, cellToFace, istream);
43 
44 }
45 
46 
47 Foam::topoSetSource::addToUsageTable Foam::cellToFace::usage_
48 (
49  cellToFace::typeName,
50  "\n Usage: cellToFace <cellSet> all|both\n\n"
51  " Select -all : all faces of cells in the cellSet\n"
52  " -both: faces where both neighbours are in the cellSet\n\n"
53 );
54 
55 template<>
57 {
58  "all",
59  "both"
60 };
61 
63  Foam::cellToFace::cellActionNames_;
64 
65 
66 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
67 
68 void Foam::cellToFace::combine(topoSet& set, const bool add) const
69 {
70  // Load the set
71  if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName_)))
72  {
73  SeriousError<< "Cannot load set "
74  << setName_ << endl;
75  }
76 
77  cellSet loadedSet(mesh_, setName_);
78 
79  if (option_ == ALL)
80  {
81  // Add all faces from cell
82  for
83  (
84  cellSet::const_iterator iter = loadedSet.begin();
85  iter != loadedSet.end();
86  ++iter
87  )
88  {
89  label cellI = iter.key();
90 
91  const labelList& cFaces = mesh_.cells()[cellI];
92 
93  forAll(cFaces, cFaceI)
94  {
95  addOrDelete(set, cFaces[cFaceI], add);
96  }
97  }
98  }
99  else if (option_ == BOTH)
100  {
101  // Add all faces whose both neighbours are in set.
102 
103  label nInt = mesh_.nInternalFaces();
104  const labelList& own = mesh_.faceOwner();
105  const labelList& nei = mesh_.faceNeighbour();
106  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
107 
108 
109  // Check all internal faces
110  for (label faceI = 0; faceI < nInt; faceI++)
111  {
112  if (loadedSet.found(own[faceI]) && loadedSet.found(nei[faceI]))
113  {
114  addOrDelete(set, faceI, add);
115  }
116  }
117 
118 
119  // Get coupled cell status
120  boolList neiInSet(mesh_.nFaces()-nInt, false);
121 
122  forAll(patches, patchI)
123  {
124  const polyPatch& pp = patches[patchI];
125 
126  if (pp.coupled())
127  {
128  label faceI = pp.start();
129  forAll(pp, i)
130  {
131  neiInSet[faceI-nInt] = loadedSet.found(own[faceI]);
132  faceI++;
133  }
134  }
135  }
136  syncTools::swapBoundaryFaceList(mesh_, neiInSet, false);
137 
138 
139  // Check all boundary faces
140  forAll(patches, patchI)
141  {
142  const polyPatch& pp = patches[patchI];
143 
144  if (pp.coupled())
145  {
146  label faceI = pp.start();
147  forAll(pp, i)
148  {
149  if (loadedSet.found(own[faceI]) && neiInSet[faceI-nInt])
150  {
151  addOrDelete(set, faceI, add);
152  }
153  faceI++;
154  }
155  }
156  }
157  }
158 }
159 
160 
161 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
162 
163 // Construct from componenta
165 (
166  const polyMesh& mesh,
167  const word& setName,
168  const cellAction option
169 )
170 :
171  topoSetSource(mesh),
172  setName_(setName),
173  option_(option)
174 {}
175 
176 
177 // Construct from dictionary
179 (
180  const polyMesh& mesh,
181  const dictionary& dict
182 )
183 :
184  topoSetSource(mesh),
185  setName_(dict.lookup("set")),
186  option_(cellActionNames_.read(dict.lookup("option")))
187 {}
188 
189 
190 // Construct from Istream
192 (
193  const polyMesh& mesh,
194  Istream& is
195 )
196 :
197  topoSetSource(mesh),
198  setName_(checkIs(is)),
199  option_(cellActionNames_.read(checkIs(is)))
200 {}
201 
202 
203 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
204 
206 {}
207 
208 
209 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
210 
212 (
213  const topoSetSource::setAction action,
214  topoSet& set
215 ) const
216 {
217  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
218  {
219  Info<< " Adding faces according to cellSet " << setName_
220  << " ..." << endl;
221 
222  combine(set, true);
223  }
224  else if (action == topoSetSource::DELETE)
225  {
226  Info<< " Removing faces according to cellSet " << setName_
227  << " ..." << endl;
228 
229  combine(set, false);
230  }
231 }
232 
233 
234 // ************************ vim: set sw=4 sts=4 et: ************************ //