FreeFOAM The Cross-Platform CFD Toolkit
patchToFace.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 "patchToFace.H"
27 #include <OpenFOAM/polyMesh.H>
28 
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 defineTypeNameAndDebug(patchToFace, 0);
37 
38 addToRunTimeSelectionTable(topoSetSource, patchToFace, word);
39 
40 addToRunTimeSelectionTable(topoSetSource, patchToFace, istream);
41 
42 }
43 
44 
45 Foam::topoSetSource::addToUsageTable Foam::patchToFace::usage_
46 (
47  patchToFace::typeName,
48  "\n Usage: patchToFace patch\n\n"
49  " Select all faces in the patch. Note:accepts wildcards for patch.\n\n"
50 );
51 
52 
53 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
54 
55 void Foam::patchToFace::combine(topoSet& set, const bool add) const
56 {
57  bool hasMatched = false;
58 
59  forAll(mesh_.boundaryMesh(), patchI)
60  {
61  const polyPatch& pp = mesh_.boundaryMesh()[patchI];
62 
63  if (patchName_.match(pp.name()))
64  {
65  Info<< " Found matching patch " << pp.name()
66  << " with " << pp.size() << " faces." << endl;
67 
68  hasMatched = true;
69 
70 
71  for
72  (
73  label faceI = pp.start();
74  faceI < pp.start() + pp.size();
75  faceI++
76  )
77  {
78  addOrDelete(set, faceI, add);
79  }
80  }
81  }
82 
83  if (!hasMatched)
84  {
85  WarningIn("patchToFace::combine(topoSet&, const bool)")
86  << "Cannot find any patch named " << patchName_ << endl
87  << "Valid names are " << mesh_.boundaryMesh().names() << endl;
88  }
89 }
90 
91 
92 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
93 
94 // Construct from components
96 (
97  const polyMesh& mesh,
98  const word& patchName
99 )
100 :
101  topoSetSource(mesh),
102  patchName_(patchName)
103 {}
104 
105 
106 // Construct from dictionary
108 (
109  const polyMesh& mesh,
110  const dictionary& dict
111 )
112 :
113  topoSetSource(mesh),
114  patchName_(dict.lookup("name"))
115 {}
116 
117 
118 // Construct from Istream
120 (
121  const polyMesh& mesh,
122  Istream& is
123 )
124 :
125  topoSetSource(mesh),
126  patchName_(checkIs(is))
127 {}
128 
129 
130 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
131 
133 {}
134 
135 
136 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
137 
139 (
140  const topoSetSource::setAction action,
141  topoSet& set
142 ) const
143 {
144  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
145  {
146  Info<< " Adding all faces of patch " << patchName_ << " ..." << endl;
147 
148  combine(set, true);
149  }
150  else if (action == topoSetSource::DELETE)
151  {
152  Info<< " Removing all faces of patch " << patchName_ << " ..."
153  << endl;
154 
155  combine(set, false);
156  }
157 }
158 
159 
160 // ************************ vim: set sw=4 sts=4 et: ************************ //