FreeFOAM The Cross-Platform CFD Toolkit
shapeToCell.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 "shapeToCell.H"
27 #include <OpenFOAM/polyMesh.H>
29 #include <OpenFOAM/hexMatcher.H>
30 #include <meshTools/cellFeatures.H>
31 
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 defineTypeNameAndDebug(shapeToCell, 0);
40 
41 addToRunTimeSelectionTable(topoSetSource, shapeToCell, word);
42 
43 addToRunTimeSelectionTable(topoSetSource, shapeToCell, istream);
44 
45 }
46 
47 
48 Foam::topoSetSource::addToUsageTable Foam::shapeToCell::usage_
49 (
50  shapeToCell::typeName,
51  "\n Usage: shapeToCell tet|pyr|prism|hex|tetWedge|wedge|splitHex\n\n"
52  " Select all cells of given cellShape.\n"
53  " (splitHex hardcoded with internal angle < 10 degrees)\n"
54 );
55 
56 
57 // Angle for polys to be considered splitHexes.
58 Foam::scalar Foam::shapeToCell::featureCos =
59  Foam::cos(10.0 * mathematicalConstant::pi/180.0);
60 
61 
62 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
63 
64 void Foam::shapeToCell::combine(topoSet& set, const bool add) const
65 {
66  if (type_ == "splitHex")
67  {
68  for (label cellI = 0; cellI < mesh_.nCells(); cellI++)
69  {
70  cellFeatures superCell(mesh_, featureCos, cellI);
71 
72  if (hexMatcher().isA(superCell.faces()))
73  {
74  addOrDelete(set, cellI, add);
75  }
76  }
77  }
78  else
79  {
80  const cellModel& wantedModel = *(cellModeller::lookup(type_));
81 
83 
84  forAll(cellShapes, cellI)
85  {
86  if (cellShapes[cellI].model() == wantedModel)
87  {
88  addOrDelete(set, cellI, add);
89  }
90  }
91  }
92 }
93 
94 
95 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
96 
97 // Construct from components
99 (
100  const polyMesh& mesh,
101  const word& type
102 )
103 :
104  topoSetSource(mesh),
105  type_(type)
106 {
107  if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
108  {
110  (
111  "shapeToCell::shapeToCell(const polyMesh&, const word&)"
112  ) << "Illegal cell type " << type_ << exit(FatalError);
113  }
114 }
115 
116 
117 // Construct from dictionary
119 (
120  const polyMesh& mesh,
121  const dictionary& dict
122 )
123 :
124  topoSetSource(mesh),
125  type_(dict.lookup("type"))
126 {
127  if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
128  {
130  (
131  "shapeToCell::shapeToCell(const polyMesh&, const dictionary&)"
132  ) << "Illegal cell type " << type_ << exit(FatalError);
133  }
134 }
135 
136 
137 // Construct from Istream
139 (
140  const polyMesh& mesh,
141  Istream& is
142 )
143 :
144  topoSetSource(mesh),
145  type_(checkIs(is))
146 {
147  if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
148  {
150  (
151  "shapeToCell::shapeToCell(const polyMesh&, Istream&)"
152  ) << "Illegal cell type " << type_ << exit(FatalError);
153  }
154 }
155 
156 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
157 
159 {}
160 
161 
162 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
163 
165 (
166  const topoSetSource::setAction action,
167  topoSet& set
168 ) const
169 {
170  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
171  {
172  Info<< " Adding all cells of type " << type_ << " ..." << endl;
173 
174  combine(set, true);
175  }
176  else if (action == topoSetSource::DELETE)
177  {
178  Info<< " Removing all cells of type " << type_ << " ..." << endl;
179 
180  combine(set, false);
181  }
182 }
183 
184 
185 // ************************ vim: set sw=4 sts=4 et: ************************ //