uniformDistance.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) 2012-2015 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 "uniformDistance.H"
28 #include "volumeType.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 defineTypeNameAndDebug(uniformDistance, 0);
38 addToRunTimeSelectionTable(cellSizeFunction, uniformDistance, dictionary);
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
43 (
44  const dictionary& initialPointsDict,
45  const searchableSurface& surface,
46  const scalar& defaultCellSize,
47  const labelList regionIndices
48 )
49 :
50  cellSizeFunction
51  (
52  typeName,
53  initialPointsDict,
54  surface,
55  defaultCellSize,
56  regionIndices
57  ),
58  distance_
59  (
60  readScalar(coeffsDict().lookup("distanceCoeff"))*defaultCellSize
61  ),
62  distanceSqr_(sqr(distance_))
63 {}
64 
65 
66 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67 
68 
70 (
71  const pointIndexHit& hitPt,
72  const vector& n,
73  pointField& shapePts,
74  scalarField& shapeSizes
75 ) const
76 {
77  const Foam::point& pt = hitPt.hitPoint();
78 
79  const scalar distanceCellSize =
80  surfaceCellSizeFunction_().interpolate(pt, hitPt.index());
81 
82  if (sideMode_ == rmBothsides)
83  {
84  shapePts.resize(2);
85  shapeSizes.resize(2);
86 
87  shapePts[0] = pt - n*distance_;
88  shapeSizes[0] = distanceCellSize;
89 
90  shapePts[1] = pt + n*distance_;
91  shapeSizes[1] = distanceCellSize;
92  }
93  else if (sideMode_ == smInside)
94  {
95  shapePts.resize(1);
96  shapeSizes.resize(1);
97 
98  shapePts[0] = pt - n*distance_;
99  shapeSizes[0] = distanceCellSize;
100  }
101  else if (sideMode_ == smOutside)
102  {
103  shapePts.resize(1);
104  shapeSizes.resize(1);
105 
106  shapePts[0] = pt - n*distance_;
107  shapeSizes[0] = distanceCellSize;
108  }
109 
110  return false;
111 }
112 
113 
115 (
116  const point& pt,
117  scalar& size
118 ) const
119 {
120  size = 0;
121 
122  List<pointIndexHit> hits;
123 
125  (
126  pointField(1, pt),
127  scalarField(1, distanceSqr_),
129  hits
130  );
131 
132  const pointIndexHit& hitInfo = hits[0];
133 
134  if (hitInfo.hit())
135  {
136  const point& hitPt = hitInfo.hitPoint();
137  const label index = hitInfo.index();
138 
139  if (sideMode_ == rmBothsides)
140  {
141  size = surfaceCellSizeFunction_().interpolate(hitPt, index);
142 
143  return true;
144  }
145 
146  // If the nearest point is essentially on the surface, do not do a
147  // getVolumeType calculation, as it will be prone to error.
148  if (mag(pt - hitInfo.hitPoint()) < snapToSurfaceTol_)
149  {
150  size = surfaceCellSizeFunction_().interpolate(hitPt, index);
151 
152  return true;
153  }
154 
155  pointField ptF(1, pt);
156  List<volumeType> vTL;
157 
158  surface_.getVolumeType(ptF, vTL);
159 
160  bool functionApplied = false;
161 
162  if
163  (
165  && vTL[0] == volumeType::INSIDE
166  )
167  {
168  size = surfaceCellSizeFunction_().interpolate(hitPt, index);
169 
170  functionApplied = true;
171  }
172  else if
173  (
175  && vTL[0] == volumeType::OUTSIDE
176  )
177  {
178  size = surfaceCellSizeFunction_().interpolate(hitPt, index);
179 
180  functionApplied = true;
181  }
182 
183  return functionApplied;
184  }
185 
186  return false;
187 }
188 
189 
191 (
192  const pointField& pts
193 )
194 {
195 // labelHashSet surfaceAlreadyHit(surface_.size());
196 //
197 // forAll(pts, ptI)
198 // {
199 // const Foam::point& pt = pts[ptI];
200 //
201 // List<pointIndexHit> hits;
202 //
203 // surface_.findNearest
204 // (
205 // pointField(1, pt),
206 // scalarField(1, distanceSqr_),
207 // regionIndices_,
208 // hits
209 // );
210 //
211 // if (hits[0].hit() && !surfaceAlreadyHit.found(hits[0].index()))
212 // {
213 // surfaceCellSizeFunction_().refineSurfaceSize(hits[0].index());
214 //
215 // surfaceAlreadyHit.insert(hits[0].index());
216 // }
217 // }
218 //
219 // return true;
220 
221  return false;
222 }
223 
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 } // End namespace Foam
228 
229 // ************************************************************************* //
uniformDistance(const dictionary &initialPointsDict, const searchableSurface &surface, const scalar &defaultCellSize, const labelList regionIndices)
Construct from components.
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
virtual bool setCellSize(const pointField &pts)
Adapt local cell size. Return true if anything changed.
autoPtr< surfaceCellSizeFunction > surfaceCellSizeFunction_
dimensionedSymmTensor sqr(const dimensionedVector &dv)
PointIndexHit< point > pointIndexHit
Definition: pointIndexHit.H:42
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
virtual bool cellSize(const point &pt, scalar &size) const
Modify scalar argument to the cell size specified by function.
Macros for easy insertion into run-time selection tables.
const labelList regionIndices_
Index of the region of the surface that this cell size function.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
stressControl lookup("compactNormalStress") >> compactNormalStress
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const =0
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
List< label > labelList
A List of labels.
Definition: labelList.H:56
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
vector point
Point is a vector.
Definition: point.H:41
virtual void getVolumeType(const pointField &, List< volumeType > &) const =0
Determine type (inside/outside) for point. unknown if.
static scalar snapToSurfaceTol_
Point closeness tolerance to a surface where the function "snaps" to.
dimensioned< scalar > mag(const dimensioned< Type > &)
const searchableSurface & surface_
Reference to the searchableSurface that cellSizeFunction.
sideMode sideMode_
Mode of size specification, i.e. inside, outside or bothSides.
Namespace for OpenFOAM.
virtual bool sizeLocations(const pointIndexHit &hitPt, const vector &n, pointField &shapePts, scalarField &shapeSizes) const