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-2025 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 "unitConversion.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",
45  dict.lookup<scalar>("resolveFeatureAngle", unitDegrees)
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  scalar featAngle(dict.lookup<scalar>("resolveFeatureAngle", unitDegrees));
62 
63  if (featAngle < 0 || featAngle > degToRad(180))
64  {
65  curvature_ = -great;
66  }
67  else
68  {
69  curvature_ = Foam::cos(featAngle);
70  }
71 }
72 
73 
75 (
76  const dictionary& dict
77 )
78 :
79  inside_
80  (
81  dict.found("insidePoints")
82  ? dict.lookup<List<point>>("insidePoints", dimLength)
83  : dict.found("insidePoint")
84  ? List<point>(1, dict.lookup<point>("insidePoint", dimLength))
85  : dict.found("locationInMesh")
86  ? List<point>(1, dict.lookup<point>("locationInMesh", dimLength))
87  : List<point>::null()
88  ),
89  outside_
90  (
91  dict.found("outsidePoints")
92  ? dict.lookup<List<point>>("outsidePoints", dimLength)
93  : dict.found("outsidePoint")
94  ? List<point>(1, dict.lookup<point>("outsidePoint", dimLength))
95  : List<point>::null()
96  )
97 {
98  if (inside_.size())
99  {
100  Info << "Cell selection insidePoints: " << inside_ << endl;
101  }
102 
103  if (outside_.size())
104  {
105  Info << "Cell selection outsidePoints: " << outside_ << endl;
106  }
107 
108  if (!inside_.size() && !outside_.size())
109  {
111  << "Neither insidePoint/insidePoints nor "
112  "outsidePoint/outsidePoints specified: "
113  << "cannot select any cells."
114  << exit(FatalError);
115  }
116 }
117 
118 
119 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 
122 (
123  const polyMesh& mesh
124 ) const
125 {
126  const meshSearch& searchEngine = meshSearch::New(mesh);
127 
128  // Global calculation engine
129  globalIndex globalCells(mesh.nCells());
130 
131  // Cell label per point
132  labelList cellLabels(selectionPoints_.inside().size());
133 
134  forAll(selectionPoints_.inside(), i)
135  {
136  const point& insidePoint = selectionPoints_.inside()[i];
137 
138  label localCelli = searchEngine.findCell(insidePoint);
139 
140  label globalCelli = -1;
141 
142  if (localCelli != -1)
143  {
144  globalCelli = globalCells.toGlobal(localCelli);
145  }
146 
147  reduce(globalCelli, maxOp<label>());
148 
149  if (globalCelli == -1)
150  {
152  << "Point " << insidePoint
153  << " is not inside the mesh or on a face or edge." << nl
154  << "Bounding box of the mesh:" << mesh.bounds()
155  << exit(FatalError);
156  }
157 
158 
159  label proci = globalCells.whichProcID(globalCelli);
160  label procCelli = globalCells.toLocal(proci, globalCelli);
161 
162  Info<< "Found point " << insidePoint << " in cell " << procCelli
163  << " on processor " << proci << endl;
164 
165 
166  if (globalCells.isLocal(globalCelli))
167  {
168  cellLabels[i] = localCelli;
169  }
170  else
171  {
172  cellLabels[i] = -1;
173  }
174  }
175  return cellLabels;
176 }
177 
178 
179 // ************************************************************************* //
bool found
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
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:388
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
messageStream Info
const dimensionSet dimLength
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:267
dimensionedScalar cos(const dimensionedScalar &ds)
const unitConversion unitDegrees
dictionary dict