uniform.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 "uniform.H"
28 #include "volumeType.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 defineTypeNameAndDebug(uniform, 0);
38 addToRunTimeSelectionTable(cellSizeFunction, uniform, 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 {}
59 
60 
61 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
62 
64 (
65  const pointIndexHit& hitPt,
66  const vector& n,
67  pointField& shapePts,
68  scalarField& shapeSizes
69 ) const
70 {
71  shapePts.setSize(0);
72  shapeSizes.setSize(0);
73 
74  return true;
75 }
76 
77 
79 (
80  const point& pt,
81  scalar& size
82 ) const
83 {
84  List<pointIndexHit> hits;
85 
86  surface_.findNearest
87  (
88  pointField(1, pt),
89  scalarField(1, sqr(GREAT)),
90  regionIndices_,
91  hits
92  );
93 
94  const pointIndexHit& hitInfo = hits[0];
95 
96  if (hitInfo.hit())
97  {
98  const point& hitPt = hitInfo.hitPoint();
99  const label index = hitInfo.index();
100 
101  if (sideMode_ == rmBothsides)
102  {
103  size = surfaceCellSizeFunction_().interpolate(hitPt, index);
104 
105  return true;
106  }
107 
108  size = 0;
109 
110  List<pointIndexHit> closeToSurfaceHits;
111 
112  surface_.findNearest
113  (
114  pointField(1, pt),
115  scalarField(1, sqr(snapToSurfaceTol_)),
116  regionIndices_,
117  closeToSurfaceHits
118  );
119 
120  const pointIndexHit& closeToSurface = closeToSurfaceHits[0];
121 
122  // If the nearest point is essentially on the surface, do not do a
123  // getVolumeType calculation, as it will be prone to error.
124  if (closeToSurface.hit())
125  {
126  size = surfaceCellSizeFunction_().interpolate(hitPt, index);
127 
128  return true;
129  }
130 
131  pointField ptF(1, pt);
132  List<volumeType> vTL(1);
133 
134  surface_.getVolumeType(ptF, vTL);
135 
136  bool functionApplied = false;
137 
138  if
139  (
140  sideMode_ == smInside
141  && vTL[0] == volumeType::INSIDE
142  )
143  {
144  size = surfaceCellSizeFunction_().interpolate(hitPt, index);
145 
146  functionApplied = true;
147  }
148  else if
149  (
150  sideMode_ == smOutside
151  && vTL[0] == volumeType::OUTSIDE
152  )
153  {
154  size = surfaceCellSizeFunction_().interpolate(hitPt, index);
155 
156  functionApplied = true;
157  }
158 
159  return functionApplied;
160  }
161 
162  return false;
163 }
164 
165 
167 (
168  const pointField& pts
169 )
170 {
171 // labelHashSet surfaceAlreadyHit(cellSize_.size());
172 //
173 // forAll(pts, ptI)
174 // {
175 // const Foam::point& pt = pts[ptI];
176 //
177 // List<pointIndexHit> hits;
178 //
179 // surface_.findNearest
180 // (
181 // pointField(1, pt),
182 // scalarField(1, sqr(GREAT)),
183 // hits
184 // );
185 //
186 // if (hits[0].hit() && !surfaceAlreadyHit.found(hits[0].index()))
187 // {
188 // surfaceCellSizeFunction_().refineCellSize(hits[0].index());
189 //
190 // surfaceAlreadyHit.insert(hits[0].index());
191 // }
192 // }
193 
194  return true;
195 }
196 
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 } // End namespace Foam
201 
202 // ************************************************************************* //
virtual bool cellSize(const point &pt, scalar &size) const
Modify scalar argument to the cell size specified by function.
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
dimensionedSymmTensor sqr(const dimensionedVector &dv)
virtual bool sizeLocations(const pointIndexHit &hitPt, const vector &n, pointField &shapePts, scalarField &shapeSizes) const
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.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
uniform(const dictionary &initialPointsDict, const searchableSurface &surface, const scalar &defaultCellSize, const labelList regionIndices)
Construct from components.
List< label > labelList
A List of labels.
Definition: labelList.H:56
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
virtual bool setCellSize(const pointField &pts)
Adapt local cell size. Return true if anything changed.
vector point
Point is a vector.
Definition: point.H:41
Namespace for OpenFOAM.