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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2012-2015 OpenFOAM Foundation
9  Copyright (C) 2018-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
31 #include "volumeType.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(surfaceOffsetLinearDistance, 0);
41  (
42  cellSizeFunction,
43  surfaceOffsetLinearDistance,
44  dictionary
45  );
46 }
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
51 (
52  const dictionary& initialPointsDict,
53  const searchableSurface& surface,
54  const scalar& defaultCellSize,
55  const labelList regionIndices
56 )
57 :
58  cellSizeFunction
59  (
60  typeName,
61  initialPointsDict,
62  surface,
63  defaultCellSize,
64  regionIndices
65  ),
66  distanceCellSize_
67  (
68  coeffsDict().get<scalar>("distanceCellSizeCoeff") * defaultCellSize
69  ),
70  surfaceOffset_
71  (
72  coeffsDict().get<scalar>("surfaceOffsetCoeff") * defaultCellSize
73  ),
74  totalDistance_(),
75  totalDistanceSqr_()
76 {
77  if (coeffsDict().readIfPresent("totalDistanceCoeff", totalDistance_))
78  {
79  totalDistance_ *= defaultCellSize;
80 
81  if (coeffsDict().found("linearDistanceCoeff"))
82  {
84  << "totalDistanceCoeff and linearDistanceCoeff found, "
85  << "specify one or other, not both."
86  << nl << exit(FatalError) << endl;
87  }
88  }
89  else if (coeffsDict().readIfPresent("linearDistanceCoeff", totalDistance_))
90  {
91  totalDistance_ *= defaultCellSize;
92  totalDistance_ += surfaceOffset_;
93  }
94  else
95  {
97  << "totalDistanceCoeff or linearDistanceCoeff not found."
98  << nl << exit(FatalError) << endl;
99  }
100 
101  totalDistanceSqr_ = sqr(totalDistance_);
102 }
103 
104 
105 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
106 
107 Foam::scalar Foam::surfaceOffsetLinearDistance::sizeFunction
108 (
109  const point& pt,
110  scalar d,
111  label index
112 ) const
113 {
114  const scalar interpolatedSize
115  = surfaceCellSizeFunction_().interpolate(pt, index);
116 
117  if (d <= surfaceOffset_)
118  {
119  return interpolatedSize;
120  }
121 
122  scalar gradient =
123  (distanceCellSize_ - interpolatedSize)
124  /(totalDistance_ - surfaceOffset_);
125 
126  scalar intercept = interpolatedSize - gradient*surfaceOffset_;
127 
128  return gradient*d + intercept;
129 }
130 
131 
132 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
133 
135 (
136  const pointIndexHit& hitPt,
137  const vector& n,
138  pointField& shapePts,
139  scalarField& shapeSizes
140 ) const
141 {
142  const Foam::point& pt = hitPt.hitPoint();
143 
144  const scalar offsetCellSize =
145  surfaceCellSizeFunction_().interpolate(pt, hitPt.index());
146 
147  if (sideMode_ == rmBothsides)
148  {
149  shapePts.resize(4);
150  shapeSizes.resize(4);
151 
152  shapePts[0] = pt - n*surfaceOffset_;
153  shapeSizes[0] = offsetCellSize;
154  shapePts[1] = pt - n*totalDistance_;
155  shapeSizes[1] = distanceCellSize_;
156 
157  shapePts[2] = pt + n*surfaceOffset_;
158  shapeSizes[2] = offsetCellSize;
159  shapePts[3] = pt + n*totalDistance_;
160  shapeSizes[3] = distanceCellSize_;
161  }
162  else if (sideMode_ == smInside)
163  {
164  shapePts.resize(2);
165  shapeSizes.resize(2);
166 
167  shapePts[0] = pt - n*surfaceOffset_;
168  shapeSizes[0] = offsetCellSize;
169  shapePts[1] = pt - n*totalDistance_;
170  shapeSizes[1] = distanceCellSize_;
171  }
172  else if (sideMode_ == smOutside)
173  {
174  shapePts.resize(2);
175  shapeSizes.resize(2);
176 
177  shapePts[0] = pt + n*surfaceOffset_;
178  shapeSizes[0] = offsetCellSize;
179  shapePts[1] = pt + n*totalDistance_;
180  shapeSizes[1] = distanceCellSize_;
181  }
182 
183  return true;
184 }
185 
186 
188 (
189  const point& pt,
190  scalar& size
191 ) const
192 {
193  size = 0;
194 
195  List<pointIndexHit> hits;
196 
197  surface_.findNearest
198  (
199  pointField(1, pt),
200  scalarField(1, totalDistanceSqr_),
201  regionIndices_,
202  hits
203  );
204 
205  const pointIndexHit& hitInfo = hits[0];
206 
207  if (hitInfo.hit())
208  {
209  const point& hitPt = hitInfo.point();
210  const label hitIndex = hitInfo.index();
211 
212  const scalar dist = hitPt.dist(pt);
213 
214  if (sideMode_ == rmBothsides)
215  {
216  size = sizeFunction(hitPt, dist, hitIndex);
217 
218  return true;
219  }
220 
221  // If the nearest point is essentially on the surface, do not do a
222  // getVolumeType calculation, as it will be prone to error.
223  if (hitInfo.point().dist(pt) < snapToSurfaceTol_)
224  {
225  size = sizeFunction(hitPt, 0, hitIndex);
226 
227  return true;
228  }
229 
230  pointField ptF(1, pt);
231  List<volumeType> vTL;
232 
233  surface_.getVolumeType(ptF, vTL);
234 
235  bool functionApplied = false;
236 
237  if
238  (
239  sideMode_ == smInside
240  && vTL[0] == volumeType::INSIDE
241  )
242  {
243  size = sizeFunction(hitPt, dist, hitIndex);
244 
245  functionApplied = true;
246  }
247  else if
248  (
249  sideMode_ == smOutside
250  && vTL[0] == volumeType::OUTSIDE
251  )
252  {
253  size = sizeFunction(hitPt, dist, hitIndex);
254 
255  functionApplied = true;
256  }
257 
258  return functionApplied;
259  }
260 
261  return false;
262 }
263 
264 
265 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
virtual bool sizeLocations(const pointIndexHit &hitPt, const vector &n, pointField &shapePts, scalarField &shapeSizes) const
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
dimensionedSymmTensor sqr(const dimensionedVector &dv)
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
Definition: pointIndexHit.H:58
Macros for easy insertion into run-time selection tables.
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:100
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:38
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const dictionary & coeffsDict() const
Const access to the details dictionary.
Vector< scalar > vector
Definition: vector.H:57
A location inside the volume.
Definition: volumeType.H:65
A location outside the volume.
Definition: volumeType.H:66
const wordList surface
Standard surface field types (scalar, vector, tensor, etc)
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
defineTypeNameAndDebug(combustionModel, 0)
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
vector point
Point is a vector.
Definition: point.H:37
label n
List< label > labelList
A List of labels.
Definition: List.H:62
virtual bool cellSize(const point &pt, scalar &size) const
Modify scalar argument to the cell size specified by function.
Namespace for OpenFOAM.