FreeFOAM The Cross-Platform CFD Toolkit
faceZoneToCell.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 "faceZoneToCell.H"
27 #include <OpenFOAM/polyMesh.H>
28 
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 defineTypeNameAndDebug(faceZoneToCell, 0);
37 
38 addToRunTimeSelectionTable(topoSetSource, faceZoneToCell, word);
39 
40 addToRunTimeSelectionTable(topoSetSource, faceZoneToCell, istream);
41 
42 }
43 
44 
45 Foam::topoSetSource::addToUsageTable Foam::faceZoneToCell::usage_
46 (
47  faceZoneToCell::typeName,
48  "\n Usage: faceZoneToCell zone master|slave\n\n"
49  " Select master or slave side of the faceZone."
50  " Note:accepts wildcards for zone.\n\n"
51 );
52 
53 
54 template<>
56 {
57  "master",
58  "slave"
59 };
60 
61 
63  Foam::faceZoneToCell::faceActionNames_;
64 
65 
66 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
67 
68 void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const
69 {
70  bool hasMatched = false;
71 
72  forAll(mesh_.faceZones(), i)
73  {
74  const faceZone& zone = mesh_.faceZones()[i];
75 
76  if (zoneName_.match(zone.name()))
77  {
78  const labelList& cellLabels =
79  (
80  option_ == MASTER
81  ? zone.masterCells()
82  : zone.slaveCells()
83  );
84 
85  Info<< " Found matching zone " << zone.name()
86  << " with " << cellLabels.size() << " cells on selected side."
87  << endl;
88 
89  hasMatched = true;
90 
91  forAll(cellLabels, i)
92  {
93  // Only do active cells
94  if (cellLabels[i] < mesh_.nCells())
95  {
96  addOrDelete(set, cellLabels[i], add);
97  }
98  }
99  }
100  }
101 
102  if (!hasMatched)
103  {
104  WarningIn("faceZoneToCell::combine(topoSet&, const bool)")
105  << "Cannot find any faceZone named " << zoneName_ << endl
106  << "Valid names are " << mesh_.faceZones().names() << endl;
107  }
108 }
109 
110 
111 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
112 
113 // Construct from components
115 (
116  const polyMesh& mesh,
117  const word& zoneName,
118  const faceAction option
119 )
120 :
121  topoSetSource(mesh),
122  zoneName_(zoneName),
123  option_(option)
124 {}
125 
126 
127 // Construct from dictionary
129 (
130  const polyMesh& mesh,
131  const dictionary& dict
132 )
133 :
134  topoSetSource(mesh),
135  zoneName_(dict.lookup("name")),
136  option_(faceActionNames_.read(dict.lookup("option")))
137 {}
138 
139 
140 // Construct from Istream
142 (
143  const polyMesh& mesh,
144  Istream& is
145 )
146 :
147  topoSetSource(mesh),
148  zoneName_(checkIs(is)),
149  option_(faceActionNames_.read(checkIs(is)))
150 {}
151 
152 
153 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
154 
156 {}
157 
158 
159 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
160 
162 (
163  const topoSetSource::setAction action,
164  topoSet& set
165 ) const
166 {
167  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
168  {
169  Info<< " Adding all " << faceActionNames_[option_]
170  << " cells of faceZone " << zoneName_ << " ..." << endl;
171 
172  combine(set, true);
173  }
174  else if (action == topoSetSource::DELETE)
175  {
176  Info<< " Removing all " << faceActionNames_[option_]
177  << " cells of faceZone " << zoneName_ << " ..." << endl;
178 
179  combine(set, false);
180  }
181 }
182 
183 
184 // ************************ vim: set sw=4 sts=4 et: ************************ //