Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
35namespace Foam
36{
37
38// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39
42
43// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44
46(
47 const dictionary& initialPointsDict,
48 const searchableSurface& surface,
49 const scalar& defaultCellSize,
50 const labelList regionIndices
51)
52:
54 (
56 initialPointsDict,
57 surface,
58 defaultCellSize,
59 regionIndices
60 )
61{}
62
63
64// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
65
66bool uniform::sizeLocations
67(
68 const pointIndexHit& hitPt,
69 const vector& n,
70 pointField& shapePts,
71 scalarField& shapeSizes
72) const
73{
74 shapePts.clear();
75 shapeSizes.clear();
76
77 return true;
78}
79
80
81bool uniform::cellSize
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
169bool uniform::setCellSize
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// ************************************************************************* //
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.
Abstract base class for specifying target cell sizes.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
void clear()
Clear the dictionary.
Definition dictionary.C:862
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
uniform(const dictionary &initialPointsDict, const searchableSurface &surface, const scalar &defaultCellSize, const labelList regionIndices)
Construct from components.
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:142
const wordList surface
Standard surface field types (scalar, vector, tensor, etc).
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
vector point
Point is a vector.
Definition point.H:37
vectorField pointField
pointField is a vectorField.
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
const pointField & pts