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-2026 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 "units.H"
29 #include "hexMatcher.H"
30 #include "cellFeatures.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(shapeToCell, 0);
38  addToRunTimeSelectionTable(topoSetSource, shapeToCell, word);
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:449
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
const cellShapeList & cellShapes() const
Return cell shapes.
label nCells() const
static scalar featureCos
Cos of feature angle for polyHedral to be splitHex.
Definition: shapeToCell.H:76
virtual ~shapeToCell()
Destructor.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
shapeToCell(const polyMesh &mesh, const word &shape)
Construct from components.
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh_
Definition: topoSetSource.H:99
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const cellShapeList & cellShapes
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
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.
Definition: units.C:364
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)
void add(GeometricField< typename typeOfSum< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
bool isA(const Type &t)
Check if a dynamic_cast to typeid is possible.
Definition: typeInfo.H:178
error FatalError
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
dimensionedScalar cos(const dimensionedScalar &ds)
dictionary dict
Useful unit conversions.