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-2021 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",
43  dict.lookup<scalar>("resolveFeatureAngle")
44  )
45  ),
46  nBufferLayers_(dict.lookup<label>("nCellsBetweenLevels")),
47  selectionPoints_(dict),
48  allowFreeStandingZoneFaces_(dict.lookup("allowFreeStandingZoneFaces")),
49  useTopologicalSnapDetection_
50  (
51  dict.lookupOrDefault<bool>("useTopologicalSnapDetection", true)
52  ),
53  maxLoadUnbalance_(dict.lookupOrDefault<scalar>("maxLoadUnbalance", 0)),
54  handleSnapProblems_
55  (
56  dict.lookupOrDefault<Switch>("handleSnapProblems", true)
57  )
58 {
59  scalar featAngle(dict.lookup<scalar>("resolveFeatureAngle"));
60 
61  if (featAngle < 0 || featAngle > 180)
62  {
63  curvature_ = -great;
64  }
65  else
66  {
67  curvature_ = Foam::cos(degToRad(featAngle));
68  }
69 }
70 
71 
73 (
74  const dictionary& dict
75 )
76 :
77  inside_
78  (
79  dict.found("insidePoints")
80  ? List<point>(dict.lookup("insidePoints"))
81  : dict.found("insidePoint")
82  ? List<point>(1, dict.lookup("insidePoint"))
83  : dict.found("locationInMesh")
84  ? List<point>(1, dict.lookup("locationInMesh"))
86  ),
87  outside_
88  (
89  dict.found("outsidePoints")
90  ? List<point>(dict.lookup("outsidePoints"))
91  : dict.found("outsidePoint")
92  ? List<point>(1, dict.lookup("outsidePoint"))
94  )
95 {
96  if (inside_.size())
97  {
98  Info << "Cell selection insidePoints: " << inside_ << endl;
99  }
100 
101  if (outside_.size())
102  {
103  Info << "Cell selection outsidePoints: " << outside_ << endl;
104  }
105 
106  if (!inside_.size() && !outside_.size())
107  {
109  << "Neither insidePoint/insidePoints nor "
110  "outsidePoint/outsidePoints specified: "
111  << "cannot select any cells."
112  << exit(FatalError);
113  }
114 }
115 
116 
117 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
118 
120 const
121 {
122  // Force calculation of tet-diag decomposition (for use in findCell)
123  (void)mesh.tetBasePtIs();
124 
125  // Global calculation engine
126  globalIndex globalCells(mesh.nCells());
127 
128  // Cell label per point
129  labelList cellLabels(selectionPoints_.inside().size());
130 
131  forAll(selectionPoints_.inside(), i)
132  {
133  const point& insidePoint = selectionPoints_.inside()[i];
134 
135  label localCelli = mesh.findCell(insidePoint);
136 
137  label globalCelli = -1;
138 
139  if (localCelli != -1)
140  {
141  globalCelli = globalCells.toGlobal(localCelli);
142  }
143 
144  reduce(globalCelli, maxOp<label>());
145 
146  if (globalCelli == -1)
147  {
149  << "Point " << insidePoint
150  << " is not inside the mesh or on a face or edge." << nl
151  << "Bounding box of the mesh:" << mesh.bounds()
152  << exit(FatalError);
153  }
154 
155 
156  label proci = globalCells.whichProcID(globalCelli);
157  label procCelli = globalCells.toLocal(proci, globalCelli);
158 
159  Info<< "Found point " << insidePoint << " in cell " << procCelli
160  << " on processor " << proci << endl;
161 
162 
163  if (globalCells.isLocal(globalCelli))
164  {
165  cellLabels[i] = localCelli;
166  }
167  else
168  {
169  cellLabels[i] = -1;
170  }
171  }
172  return cellLabels;
173 }
174 
175 
176 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:663
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
const labelIOList & tetBasePtIs() const
Return the tetBasePtIs.
Definition: polyMesh.C:928
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Unit conversion functions.
label nCells() const
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none/any.
Definition: Switch.H:60
fvMesh & mesh
scalar degToRad(const scalar deg)
Conversion from degrees to radians.
labelList findCells(const polyMesh &) const
Checks that cells are in mesh. Returns cells they are in.
cellSelectionPoints(const dictionary &dict)
Constructor.
const List< point > & inside() const
Return the points inside the surface regions to selected cells.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
stressControl lookup("compactNormalStress") >> compactNormalStress
dimensionedScalar cos(const dimensionedScalar &ds)
static const char nl
Definition: Ostream.H:260
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
refinementParameters(const dictionary &dict)
Construct from dictionary - new syntax.
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:459
label findCell(const point &p, const cellDecomposition=CELL_TETS) const
Find cell enclosing this location and return index.
Definition: polyMesh.C:1647
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864