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-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "uniform.H"
30#include "volumeType.H"
31
32// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34namespace Foam
35{
36
37// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38
39defineTypeNameAndDebug(uniform, 0);
40addToRunTimeSelectionTable(cellSizeFunction, uniform, dictionary);
41
42// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43
44uniform::uniform
45(
46 const dictionary& initialPointsDict,
47 const searchableSurface& surface,
48 const scalar& defaultCellSize,
49 const labelList regionIndices
50)
51:
52 cellSizeFunction
53 (
54 typeName,
55 initialPointsDict,
56 surface,
57 defaultCellSize,
58 regionIndices
59 )
60{}
61
62
63// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64
65bool uniform::sizeLocations
66(
67 const pointIndexHit& hitPt,
68 const vector& n,
69 pointField& shapePts,
70 scalarField& shapeSizes
71) const
72{
73 shapePts.setSize(0);
74 shapeSizes.setSize(0);
75
76 return true;
77}
78
79
80bool uniform::cellSize
81(
82 const point& pt,
83 scalar& size
84) const
85{
86 List<pointIndexHit> hits;
87
88 surface_.findNearest
89 (
90 pointField(1, pt),
91 scalarField(1, sqr(GREAT)),
92 regionIndices_,
93 hits
94 );
95
96 const pointIndexHit& hitInfo = hits[0];
97
98 if (hitInfo.hit())
99 {
100 const point& hitPt = hitInfo.hitPoint();
101 const label index = hitInfo.index();
102
103 if (sideMode_ == rmBothsides)
104 {
105 size = surfaceCellSizeFunction_().interpolate(hitPt, index);
106
107 return true;
108 }
109
110 size = 0;
111
112 List<pointIndexHit> closeToSurfaceHits;
113
114 surface_.findNearest
115 (
116 pointField(1, pt),
117 scalarField(1, sqr(snapToSurfaceTol_)),
118 regionIndices_,
119 closeToSurfaceHits
120 );
121
122 const pointIndexHit& closeToSurface = closeToSurfaceHits[0];
123
124 // If the nearest point is essentially on the surface, do not do a
125 // getVolumeType calculation, as it will be prone to error.
126 if (closeToSurface.hit())
127 {
128 size = surfaceCellSizeFunction_().interpolate(hitPt, index);
129
130 return true;
131 }
132
133 pointField ptF(1, pt);
134 List<volumeType> vTL(1);
135
136 surface_.getVolumeType(ptF, vTL);
137
138 bool functionApplied = false;
139
140 if
141 (
142 sideMode_ == smInside
143 && vTL[0] == volumeType::INSIDE
144 )
145 {
146 size = surfaceCellSizeFunction_().interpolate(hitPt, index);
147
148 functionApplied = true;
149 }
150 else if
151 (
152 sideMode_ == smOutside
153 && vTL[0] == volumeType::OUTSIDE
154 )
155 {
156 size = surfaceCellSizeFunction_().interpolate(hitPt, index);
157
158 functionApplied = true;
159 }
160
161 return functionApplied;
162 }
163
164 return false;
165}
166
167
168bool uniform::setCellSize
169(
170 const pointField& pts
171)
172{
173// labelHashSet surfaceAlreadyHit(cellSize_.size());
174//
175// forAll(pts, ptI)
176// {
177// const Foam::point& pt = pts[ptI];
178//
179// List<pointIndexHit> hits;
180//
181// surface_.findNearest
182// (
183// pointField(1, pt),
184// scalarField(1, sqr(GREAT)),
185// hits
186// );
187//
188// if (hits[0].hit() && !surfaceAlreadyHit.found(hits[0].index()))
189// {
190// surfaceCellSizeFunction_().refineCellSize(hits[0].index());
191//
192// surfaceAlreadyHit.insert(hits[0].index());
193// }
194// }
195
196 return true;
197}
198
199
200// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201
202} // End namespace Foam
203
204// ************************************************************************* //
label n
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
const wordList surface
Standard surface field types (scalar, vector, tensor, etc)
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
dimensionedSymmTensor sqr(const dimensionedVector &dv)
PointIndexHit< point > pointIndexHit
A PointIndexHit for 3D points.
Definition: pointIndexHit.H:46
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
vector point
Point is a vector.
Definition: point.H:43
Field< scalar > scalarField
Specialisation of Field<T> for scalar.