refinementParameters.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 "refinementParameters.H"
27 #include "units.H"
28 #include "polyMesh.H"
29 #include "globalIndex.H"
30 #include "meshSearch.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
35 :
36  maxGlobalCells_(dict.lookup<label>("maxGlobalCells")),
37  maxLocalCells_(dict.lookup<label>("maxLocalCells")),
38  minRefineCells_(dict.lookup<label>("minRefinementCells")),
39  planarAngle_
40  (
41  dict.lookupOrDefault
42  (
43  "planarAngle",
44  units::degrees,
45  dict.lookup<scalar>("resolveFeatureAngle", units::degrees)
46  )
47  ),
48  nBufferLayers_(dict.lookup<label>("nCellsBetweenLevels")),
49  selectionPoints_(dict),
50  allowFreeStandingZoneFaces_(dict.lookup("allowFreeStandingZoneFaces")),
51  useTopologicalSnapDetection_
52  (
53  dict.lookupOrDefault<bool>("useTopologicalSnapDetection", true)
54  ),
55  maxLoadUnbalance_(dict.lookupOrDefault<scalar>("maxLoadUnbalance", 0)),
56  handleSnapProblems_
57  (
58  dict.lookupOrDefault<Switch>("handleSnapProblems", true)
59  )
60 {
61  const scalar featAngle
62  (
63  dict.lookup<scalar>("resolveFeatureAngle", units::degrees)
64  );
65 
66  if (featAngle < 0 || featAngle > degToRad(180))
67  {
68  curvature_ = -great;
69  }
70  else
71  {
72  curvature_ = Foam::cos(featAngle);
73  }
74 }
75 
76 
78 (
79  const dictionary& dict
80 )
81 :
82  inside_
83  (
84  dict.found("insidePoints")
85  ? dict.lookup<List<point>>("insidePoints", dimLength)
86  : dict.found("insidePoint")
87  ? List<point>(1, dict.lookup<point>("insidePoint", dimLength))
88  : dict.found("locationInMesh")
89  ? List<point>(1, dict.lookup<point>("locationInMesh", dimLength))
90  : List<point>::null()
91  ),
92  outside_
93  (
94  dict.found("outsidePoints")
95  ? dict.lookup<List<point>>("outsidePoints", dimLength)
96  : dict.found("outsidePoint")
97  ? List<point>(1, dict.lookup<point>("outsidePoint", dimLength))
98  : List<point>::null()
99  )
100 {
101  if (inside_.size())
102  {
103  Info << "Cell selection insidePoints: " << inside_ << endl;
104  }
105 
106  if (outside_.size())
107  {
108  Info << "Cell selection outsidePoints: " << outside_ << endl;
109  }
110 
111  if (!inside_.size() && !outside_.size())
112  {
114  << "Neither insidePoint/insidePoints nor "
115  "outsidePoint/outsidePoints specified: "
116  << "cannot select any cells."
117  << exit(FatalError);
118  }
119 }
120 
121 
122 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
123 
125 (
126  const polyMesh& mesh
127 ) const
128 {
129  const meshSearch& searchEngine = meshSearch::New(mesh);
130 
131  // Global calculation engine
132  globalIndex globalCells(mesh.nCells());
133 
134  // Cell label per point
135  labelList cellLabels(selectionPoints_.inside().size());
136 
137  forAll(selectionPoints_.inside(), i)
138  {
139  const point& insidePoint = selectionPoints_.inside()[i];
140 
141  label localCelli = searchEngine.findCell(insidePoint);
142 
143  label globalCelli = -1;
144 
145  if (localCelli != -1)
146  {
147  globalCelli = globalCells.toGlobal(localCelli);
148  }
149 
150  reduce(globalCelli, maxOp<label>());
151 
152  if (globalCelli == -1)
153  {
155  << "Point " << insidePoint
156  << " is not inside the mesh or on a face or edge." << nl
157  << "Bounding box of the mesh:" << mesh.bounds()
158  << exit(FatalError);
159  }
160 
161 
162  label proci = globalCells.whichProcID(globalCelli);
163  label procCelli = globalCells.toLocal(proci, globalCelli);
164 
165  Info<< "Found point " << insidePoint << " in cell " << procCelli
166  << " on processor " << proci << endl;
167 
168 
169  if (globalCells.isLocal(globalCelli))
170  {
171  cellLabels[i] = localCelli;
172  }
173  else
174  {
175  cellLabels[i] = -1;
176  }
177  }
178  return cellLabels;
179 }
180 
181 
182 // ************************************************************************* //
bool found
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:64
label whichProcID(const label i) const
Which processor does global come from? Binary search.
Definition: globalIndexI.H:123
label toGlobal(const label i) const
From local to global.
Definition: globalIndexI.H:82
label toLocal(const label i) const
From global to local on current processor.
Definition: globalIndexI.H:117
bool isLocal(const label i) const
Is on local processor.
Definition: globalIndexI.H:95
Mesh object that implements searches within the local cells and faces.
Definition: meshSearch.H:59
label findCell(const point &p, const pointInCellShapes=pointInCellShapes::tets) const
Find the cell containing the given point.
Definition: meshSearch.C:173
static const meshSearch & New(const polyMesh &mesh, const pointInCellShapes=pointInCellShapes::tets)
Lookup or construct from mesh and cell decomposition option.
Definition: meshSearch.C:61
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:399
label nCells() const
cellSelectionPoints(const dictionary &dict)
Constructor.
const List< point > & inside() const
Return the points inside the surface regions to selected cells.
refinementParameters(const dictionary &dict)
Construct from dictionary - new syntax.
labelList findCells(const polyMesh &) const
Checks that cells are in mesh. Returns cells they are in.
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 unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
const unitSet degrees
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
const dimensionSet & dimLength
Definition: dimensions.C:141
messageStream Info
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
error FatalError
static const char nl
Definition: Ostream.H:297
dimensionedScalar cos(const dimensionedScalar &ds)
dictionary dict
Useful unit conversions.