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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "shapeToCell.H"
30 #include "polyMesh.H"
31 #include "unitConversion.H"
32 #include "hexMatcher.H"
33 #include "cellFeatures.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(shapeToCell, 0);
41  addToRunTimeSelectionTable(topoSetSource, shapeToCell, word);
42  addToRunTimeSelectionTable(topoSetSource, shapeToCell, istream);
43  addToRunTimeSelectionTable(topoSetCellSource, shapeToCell, word);
44  addToRunTimeSelectionTable(topoSetCellSource, shapeToCell, istream);
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.
59 
60 
61 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
62 
63 void Foam::shapeToCell::combine(topoSet& set, const bool add) const
64 {
65  if (shape_ == "splitHex")
66  {
67  for (label celli = 0; celli < mesh_.nCells(); ++celli)
68  {
69  cellFeatures superCell(mesh_, featureCos, celli);
70 
71  if (hexMatcher::test(superCell.faces()))
72  {
73  addOrDelete(set, celli, add);
74  }
75  }
76  }
77  else
78  {
79  const cellModel& wantedModel = cellModel::ref(shape_);
80 
82 
83  forAll(cellShapes, celli)
84  {
85  if (cellShapes[celli].model() == wantedModel)
86  {
87  addOrDelete(set, celli, add);
88  }
89  }
90  }
91 }
92 
93 
94 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
95 
97 (
98  const polyMesh& mesh,
99  const word& shapeName
100 )
101 :
103  shape_(shapeName)
104 {
105  if (!cellModel::ptr(shape_) && shape_ != "splitHex")
106  {
108  << "Illegal cell shape " << shape_ << exit(FatalError);
109  }
110 }
111 
112 
114 (
115  const polyMesh& mesh,
116  const dictionary& dict
117 )
118 :
119  shapeToCell(mesh, dict.getCompat<word>("shape", {{"type", 1806}}))
120 {}
121 
122 
124 (
125  const polyMesh& mesh,
126  Istream& is
127 )
128 :
130  shape_(checkIs(is))
131 {
132  if (!cellModel::ptr(shape_) && shape_ != "splitHex")
133  {
135  << "Illegal cell shape " << shape_ << exit(FatalError);
136  }
137 }
138 
139 
140 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
141 
143 (
144  const topoSetSource::setAction action,
145  topoSet& set
146 ) const
147 {
148  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
149  {
150  if (verbose_)
151  {
152  Info<< " Adding all " << shape_ << " cells ..." << endl;
153  }
154 
155  combine(set, true);
156  }
157  else if (action == topoSetSource::SUBTRACT)
158  {
159  if (verbose_)
160  {
161  Info<< " Removing all " << shape_ << " cells ..." << endl;
162  }
163 
164  combine(set, false);
165  }
166 }
167 
168 
169 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::topoSetSource::ADD
Add elements to current set.
Definition: topoSetSource.H:103
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:129
hexMatcher.H
Foam::cellShapeList
List< cellShape > cellShapeList
List of cellShapes and PtrList of List of cellShape.
Definition: cellShapeList.H:45
Foam::hexMatcher::test
static bool test(const UList< face > &faces)
Definition: hexMatcher.C:87
unitConversion.H
Unit conversion functions.
Foam::shapeToCell::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: shapeToCell.C:143
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:100
Foam::dictionary::getCompat
T getCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option=keyType::REGEX) const
Definition: dictionaryTemplates.C:134
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:104
Foam::cellModel::ptr
static const cellModel * ptr(const modelType model)
Look up pointer to cellModel by enumeration, or nullptr on failure.
Definition: cellModels.C:120
polyMesh.H
Foam::shapeToCell
A topoSetCellSource to select cells based on the type of their cell shapes.
Definition: shapeToCell.H:156
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::primitiveMesh::nCells
label nCells() const noexcept
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::ListListOps::combine
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:69
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
Foam::cellModel::ref
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
Definition: cellModels.C:157
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::topoSetSource::SUBTRACT
Subtract elements from current set.
Definition: topoSetSource.H:105
cellFeatures.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::primitiveMesh::cellShapes
const cellShapeList & cellShapes() const
Return cell shapes.
Definition: primitiveMesh.C:353
Foam::degToRad
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
Definition: unitConversion.H:48
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
shapeToCell.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::topoSetCellSource
The topoSetCellSource is a intermediate class for handling topoSet sources for selecting cells.
Definition: topoSetCellSource.H:54
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
Definition: topoSetSource.C:171
cellShapes
cellShapeList cellShapes
Definition: createBlockMesh.H:3
Foam::shapeToCell::featureCos
static scalar featureCos
Cos of feature angle for polyHedral to be splitHex.
Definition: shapeToCell.H:183
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:156
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::shapeToCell::shapeToCell
shapeToCell(const polyMesh &mesh, const word &shapeName)
Construct from components.
Definition: shapeToCell.C:97
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:265