refinementParameters.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2014 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 
33 Foam::refinementParameters::refinementParameters(const dictionary& dict)
34 :
35  maxGlobalCells_(readLabel(dict.lookup("maxGlobalCells"))),
36  maxLocalCells_(readLabel(dict.lookup("maxLocalCells"))),
37  minRefineCells_(readLabel(dict.lookup("minRefinementCells"))),
38  planarAngle_
39  (
40  dict.lookupOrDefault
41  (
42  "planarAngle",
43  readScalar(dict.lookup("resolveFeatureAngle"))
44  )
45  ),
46  nBufferLayers_(readLabel(dict.lookup("nCellsBetweenLevels"))),
47  keepPoints_(pointField(1, dict.lookup("locationInMesh"))),
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(readScalar(dict.lookup("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 
72 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
73 
75 const
76 {
77  // Force calculation of tet-diag decomposition (for use in findCell)
78  (void)mesh.tetBasePtIs();
79 
80  // Global calculation engine
81  globalIndex globalCells(mesh.nCells());
82 
83  // Cell label per point
84  labelList cellLabels(keepPoints_.size());
85 
86  forAll(keepPoints_, i)
87  {
88  const point& keepPoint = keepPoints_[i];
89 
90  label localCellI = mesh.findCell(keepPoint);
91 
92  label globalCellI = -1;
93 
94  if (localCellI != -1)
95  {
96  globalCellI = globalCells.toGlobal(localCellI);
97  }
98 
99  reduce(globalCellI, maxOp<label>());
100 
101  if (globalCellI == -1)
102  {
104  (
105  "refinementParameters::findCells(const polyMesh&) const"
106  ) << "Point " << keepPoint
107  << " is not inside the mesh or on a face or edge." << nl
108  << "Bounding box of the mesh:" << mesh.bounds()
109  << exit(FatalError);
110  }
111 
112 
113  label procI = globalCells.whichProcID(globalCellI);
114  label procCellI = globalCells.toLocal(procI, globalCellI);
115 
116  Info<< "Found point " << keepPoint << " in cell " << procCellI
117  << " on processor " << procI << endl;
118 
119 
120  if (globalCells.isLocal(globalCellI))
121  {
122  cellLabels[i] = localCellI;
123  }
124  else
125  {
126  cellLabels[i] = -1;
127  }
128  }
129  return cellLabels;
130 }
131 
132 
133 // ************************************************************************* //
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
#define readScalar
Definition: doubleScalar.C:38
const labelList & tetBasePtIs() const
Return the tetBasePtIs.
Definition: polyMesh.C:864
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
label nCells() const
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.
Definition: Switch.H:60
messageStream Info
dynamicFvMesh & mesh
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
label readLabel(Istream &is)
Definition: label.H:64
dictionary dict
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
stressControl lookup("compactNormalStress") >> compactNormalStress
#define forAll(list, i)
Definition: UList.H:421
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
dimensionedScalar cos(const dimensionedScalar &ds)
label findCell(const point &p, const cellDecomposition=CELL_TETS) const
Find cell enclosing this location and return index.
Definition: polyMesh.C:1476
Unit conversion functions.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:427
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.