shapeToCell.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
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 "polyMesh.H"
28 #include "unitConversion.H"
29 #include "hexMatcher.H"
30 #include "cellFeatures.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
39 }
40 
42 
43 
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 
46 void Foam::shapeToCell::combine(topoSet& set, const bool add) const
47 {
48  if (shape_ == "splitHex")
49  {
50  for (label celli = 0; celli < mesh_.nCells(); celli++)
51  {
52  const cellFeatures superCell(mesh_, featureCos, celli);
53 
54  if (hexMatcher().isA(superCell.faces()))
55  {
56  addOrDelete(set, celli, add);
57  }
58  }
59  }
60  else
61  {
62  const cellModel& wantedModel = *(cellModeller::lookup(shape_));
63 
65 
66  forAll(cellShapes, celli)
67  {
68  if (cellShapes[celli].model() == wantedModel)
69  {
70  addOrDelete(set, celli, add);
71  }
72  }
73  }
74 }
75 
76 
77 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78 
80 (
81  const polyMesh& mesh,
82  const word& shape
83 )
84 :
85  topoSetSource(mesh),
86  shape_(shape)
87 {
88  if (!cellModeller::lookup(shape_) && (shape_ != "splitHex"))
89  {
91  << "Illegal cell shape " << shape_ << exit(FatalError);
92  }
93 }
94 
95 
97 (
98  const polyMesh& mesh,
99  const dictionary& dict
100 )
101 :
102  topoSetSource(mesh),
103  shape_(dict.lookup("shape"))
104 {
105  if (!cellModeller::lookup(shape_) && (shape_ != "splitHex"))
106  {
108  << "Illegal cell shape " << shape_ << exit(FatalError);
109  }
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
114 
116 {}
117 
118 
119 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 
122 (
123  const topoSetSource::setAction action,
124  topoSet& set
125 ) const
126 {
127  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
128  {
129  Info<< " Adding all cells of shape " << shape_ << " ..." << endl;
130 
131  combine(set, true);
132  }
133  else if (action == topoSetSource::DELETE)
134  {
135  Info<< " Removing all cells of shape " << shape_ << " ..." << endl;
136 
137  combine(set, false);
138  }
139 }
140 
141 
142 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or nullptr.
Definition: cellModeller.C:100
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
label nCells() const
const cellShapeList & cellShapes() const
Return cell shapes.
A topoSetSource to select cells based on cell shape.
Definition: shapeToCell.H:54
static scalar featureCos
Cos of feature angle for polyHedral to be splitHex.
Definition: shapeToCell.H:76
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: shapeToCell.C:122
virtual ~shapeToCell()
Destructor.
Definition: shapeToCell.C:115
shapeToCell(const polyMesh &mesh, const word &shape)
Construct from components.
Definition: shapeToCell.C:80
Base class of a source for a topoSet.
Definition: topoSetSource.H:64
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
Definition: topoSetSource.C:96
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh_
Definition: topoSetSource.H:99
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:65
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const cellShapeList & cellShapes
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< cellShape > cellShapeList
List of cellShapes and PtrList of List of cellShape.
Definition: cellShapeList.H:43
scalar degToRad(const scalar deg)
Convert degrees to radians.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
messageStream Info
bool isA(const Type &t)
Check if a dynamic_cast to typeid is possible.
Definition: typeInfo.H:166
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
defineTypeNameAndDebug(combustionModel, 0)
error FatalError
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
dimensionedScalar cos(const dimensionedScalar &ds)
dictionary dict