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-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 "refinementParameters.H"
27 #include "unitConversion.H"
28 #include "polyMesh.H"
29 #include "globalIndex.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 :
35  maxGlobalCells_(dict.lookup<label>("maxGlobalCells")),
36  maxLocalCells_(dict.lookup<label>("maxLocalCells")),
37  minRefineCells_(dict.lookup<label>("minRefinementCells")),
38  planarAngle_
39  (
40  dict.lookupOrDefault
41  (
42  "planarAngle",
44  dict.lookup<scalar>("resolveFeatureAngle", unitDegrees)
45  )
46  ),
47  nBufferLayers_(dict.lookup<label>("nCellsBetweenLevels")),
48  selectionPoints_(dict),
49  allowFreeStandingZoneFaces_(dict.lookup("allowFreeStandingZoneFaces")),
50  useTopologicalSnapDetection_
51  (
52  dict.lookupOrDefault<bool>("useTopologicalSnapDetection", true)
53  ),
54  maxLoadUnbalance_(dict.lookupOrDefault<scalar>("maxLoadUnbalance", 0)),
55  handleSnapProblems_
56  (
57  dict.lookupOrDefault<Switch>("handleSnapProblems", true)
58  )
59 {
60  scalar featAngle(dict.lookup<scalar>("resolveFeatureAngle", unitDegrees));
61 
62  if (featAngle < 0 || featAngle > degToRad(180))
63  {
64  curvature_ = -great;
65  }
66  else
67  {
68  curvature_ = Foam::cos(featAngle);
69  }
70 }
71 
72 
74 (
75  const dictionary& dict
76 )
77 :
78  inside_
79  (
80  dict.found("insidePoints")
81  ? dict.lookup<List<point>>("insidePoints", dimLength)
82  : dict.found("insidePoint")
83  ? List<point>(1, dict.lookup<point>("insidePoint", dimLength))
84  : dict.found("locationInMesh")
85  ? List<point>(1, dict.lookup<point>("locationInMesh", dimLength))
86  : List<point>::null()
87  ),
88  outside_
89  (
90  dict.found("outsidePoints")
91  ? dict.lookup<List<point>>("outsidePoints", dimLength)
92  : dict.found("outsidePoint")
93  ? List<point>(1, dict.lookup<point>("outsidePoint", dimLength))
94  : List<point>::null()
95  )
96 {
97  if (inside_.size())
98  {
99  Info << "Cell selection insidePoints: " << inside_ << endl;
100  }
101 
102  if (outside_.size())
103  {
104  Info << "Cell selection outsidePoints: " << outside_ << endl;
105  }
106 
107  if (!inside_.size() && !outside_.size())
108  {
110  << "Neither insidePoint/insidePoints nor "
111  "outsidePoint/outsidePoints specified: "
112  << "cannot select any cells."
113  << exit(FatalError);
114  }
115 }
116 
117 
118 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
119 
121 const
122 {
123  // Force calculation of tet-diag decomposition (for use in findCell)
124  (void)mesh.tetBasePtIs();
125 
126  // Global calculation engine
127  globalIndex globalCells(mesh.nCells());
128 
129  // Cell label per point
130  labelList cellLabels(selectionPoints_.inside().size());
131 
132  forAll(selectionPoints_.inside(), i)
133  {
134  const point& insidePoint = selectionPoints_.inside()[i];
135 
136  label localCelli = mesh.findCell(insidePoint);
137 
138  label globalCelli = -1;
139 
140  if (localCelli != -1)
141  {
142  globalCelli = globalCells.toGlobal(localCelli);
143  }
144 
145  reduce(globalCelli, maxOp<label>());
146 
147  if (globalCelli == -1)
148  {
150  << "Point " << insidePoint
151  << " is not inside the mesh or on a face or edge." << nl
152  << "Bounding box of the mesh:" << mesh.bounds()
153  << exit(FatalError);
154  }
155 
156 
157  label proci = globalCells.whichProcID(globalCelli);
158  label procCelli = globalCells.toLocal(proci, globalCelli);
159 
160  Info<< "Found point " << insidePoint << " in cell " << procCelli
161  << " on processor " << proci << endl;
162 
163 
164  if (globalCells.isLocal(globalCelli))
165  {
166  cellLabels[i] = localCelli;
167  }
168  else
169  {
170  cellLabels[i] = -1;
171  }
172  }
173  return cellLabels;
174 }
175 
176 
177 // ************************************************************************* //
bool found
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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 keyword definitions, which are a keyword followed by any number of values (e....
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 consisting of general polyhedral cells.
Definition: polyMesh.H:80
label findCell(const point &p, const cellDecomposition=CELL_TETS) const
Find cell enclosing this location and return index.
Definition: polyMesh.C:1727
const labelIOList & tetBasePtIs() const
Return the tetBasePtIs.
Definition: polyMesh.C:1023
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:410
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.
#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:257
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:266
dimensionedScalar cos(const dimensionedScalar &ds)
const unitConversion unitDegrees
dictionary dict