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