surfaceOffsetLinearDistance.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 
28 #include "volumeType.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 defineTypeNameAndDebug(surfaceOffsetLinearDistance, 0);
39 (
40  cellSizeFunction,
41  surfaceOffsetLinearDistance,
42  dictionary
43 );
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
48 (
49  const dictionary& initialPointsDict,
50  const searchableSurface& surface,
51  const scalar& defaultCellSize,
52  const labelList regionIndices
53 )
54 :
55  cellSizeFunction
56  (
57  typeName,
58  initialPointsDict,
59  surface,
60  defaultCellSize,
61  regionIndices
62  ),
63  distanceCellSize_
64  (
65  readScalar(coeffsDict().lookup("distanceCellSizeCoeff"))
66  *defaultCellSize
67  ),
68  surfaceOffset_
69  (
70  readScalar(coeffsDict().lookup("surfaceOffsetCoeff"))*defaultCellSize
71  ),
72  totalDistance_(),
73  totalDistanceSqr_()
74 {
75  if
76  (
77  coeffsDict().found("totalDistanceCoeff")
78  || coeffsDict().found("linearDistanceCoeff")
79  )
80  {
81  if
82  (
83  coeffsDict().found("totalDistanceCoeff")
84  && coeffsDict().found("linearDistanceCoeff")
85  )
86  {
88  << "totalDistanceCoeff and linearDistanceCoeff found, "
89  << "specify one or other, not both."
90  << nl << exit(FatalError) << endl;
91  }
92 
93  if (coeffsDict().found("totalDistanceCoeff"))
94  {
95  totalDistance_ =
96  readScalar(coeffsDict().lookup("totalDistanceCoeff"))
97  *defaultCellSize;
98  }
99  else
100  {
101  totalDistance_ =
102  readScalar(coeffsDict().lookup("linearDistanceCoeff"))
103  *defaultCellSize
104  + surfaceOffset_;
105  }
106  }
107  else
108  {
110  << "totalDistanceCoeff or linearDistanceCoeff not found."
111  << nl << exit(FatalError) << endl;
112  }
113 
114  totalDistanceSqr_ = sqr(totalDistance_);
115 }
116 
117 
118 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
119 
120 scalar surfaceOffsetLinearDistance::sizeFunction
121 (
122  const point& pt,
123  scalar d,
124  label index
125 ) const
126 {
127  const scalar interpolatedSize
128  = surfaceCellSizeFunction_().interpolate(pt, index);
129 
130  if (d <= surfaceOffset_)
131  {
132  return interpolatedSize;
133  }
134 
135  scalar gradient =
136  (distanceCellSize_ - interpolatedSize)
137  /(totalDistance_ - surfaceOffset_);
138 
139  scalar intercept = interpolatedSize - gradient*surfaceOffset_;
140 
141  return gradient*d + intercept;
142 }
143 
144 
145 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
146 
148 (
149  const pointIndexHit& hitPt,
150  const vector& n,
151  pointField& shapePts,
152  scalarField& shapeSizes
153 ) const
154 {
155  const Foam::point& pt = hitPt.hitPoint();
156 
157  const scalar offsetCellSize =
158  surfaceCellSizeFunction_().interpolate(pt, hitPt.index());
159 
160  if (sideMode_ == rmBothsides)
161  {
162  shapePts.resize(4);
163  shapeSizes.resize(4);
164 
165  shapePts[0] = pt - n*surfaceOffset_;
166  shapeSizes[0] = offsetCellSize;
167  shapePts[1] = pt - n*totalDistance_;
168  shapeSizes[1] = distanceCellSize_;
169 
170  shapePts[2] = pt + n*surfaceOffset_;
171  shapeSizes[2] = offsetCellSize;
172  shapePts[3] = pt + n*totalDistance_;
173  shapeSizes[3] = distanceCellSize_;
174  }
175  else if (sideMode_ == smInside)
176  {
177  shapePts.resize(2);
178  shapeSizes.resize(2);
179 
180  shapePts[0] = pt - n*surfaceOffset_;
181  shapeSizes[0] = offsetCellSize;
182  shapePts[1] = pt - n*totalDistance_;
183  shapeSizes[1] = distanceCellSize_;
184  }
185  else if (sideMode_ == smOutside)
186  {
187  shapePts.resize(2);
188  shapeSizes.resize(2);
189 
190  shapePts[0] = pt + n*surfaceOffset_;
191  shapeSizes[0] = offsetCellSize;
192  shapePts[1] = pt + n*totalDistance_;
193  shapeSizes[1] = distanceCellSize_;
194  }
195 
196  return true;
197 }
198 
199 
201 (
202  const point& pt,
203  scalar& size
204 ) const
205 {
206  size = 0;
207 
208  List<pointIndexHit> hits;
209 
211  (
212  pointField(1, pt),
213  scalarField(1, totalDistanceSqr_),
215  hits
216  );
217 
218  const pointIndexHit& hitInfo = hits[0];
219 
220  if (hitInfo.hit())
221  {
222  const point& hitPt = hitInfo.hitPoint();
223  const label hitIndex = hitInfo.index();
224 
225  const scalar dist = mag(pt - hitPt);
226 
227  if (sideMode_ == rmBothsides)
228  {
229  size = sizeFunction(hitPt, dist, hitIndex);
230 
231  return true;
232  }
233 
234  // If the nearest point is essentially on the surface, do not do a
235  // getVolumeType calculation, as it will be prone to error.
236  if (mag(pt - hitInfo.hitPoint()) < snapToSurfaceTol_)
237  {
238  size = sizeFunction(hitPt, 0, hitIndex);
239 
240  return true;
241  }
242 
243  pointField ptF(1, pt);
244  List<volumeType> vTL;
245 
246  surface_.getVolumeType(ptF, vTL);
247 
248  bool functionApplied = false;
249 
250  if
251  (
253  && vTL[0] == volumeType::INSIDE
254  )
255  {
256  size = sizeFunction(hitPt, dist, hitIndex);
257 
258  functionApplied = true;
259  }
260  else if
261  (
263  && vTL[0] == volumeType::OUTSIDE
264  )
265  {
266  size = sizeFunction(hitPt, dist, hitIndex);
267 
268  functionApplied = true;
269  }
270 
271  return functionApplied;
272  }
273 
274  return false;
275 }
276 
277 
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 
280 } // End namespace Foam
281 
282 // ************************************************************************* //
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
autoPtr< surfaceCellSizeFunction > surfaceCellSizeFunction_
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
virtual bool sizeLocations(const pointIndexHit &hitPt, const vector &n, pointField &shapePts, scalarField &shapeSizes) const
const dictionary & coeffsDict() const
Const access to the details dictionary.
PointIndexHit< point > pointIndexHit
Definition: pointIndexHit.H:42
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
Macros for easy insertion into run-time selection tables.
const labelList regionIndices_
Index of the region of the surface that this cell size function.
surfaceOffsetLinearDistance(const dictionary &initialPointsDict, const searchableSurface &surface, const scalar &defaultCellSize, const labelList regionIndices)
Construct from components.
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.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
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)
static const char nl
Definition: Ostream.H:262
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 > &)
virtual bool cellSize(const point &pt, scalar &size) const
Modify scalar argument to the cell size specified by function.
const searchableSurface & surface_
Reference to the searchableSurface that cellSizeFunction.
sideMode sideMode_
Mode of size specification, i.e. inside, outside or bothSides.
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451