edgeMeshFeatureProximity.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) 2017 OpenCFD Ltd.
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 "edgeMeshTools.H"
29
30#include "extendedEdgeMesh.H"
31#include "triSurface.H"
32#include "triSurfaceFields.H"
33#include "pointIndexHit.H"
34#include "MeshedSurface.H"
35#include "OFstream.H"
36
37// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38
39namespace Foam
40{
41
43(
44 const List<pointIndexHit>& hitList,
45 const scalar defaultCellSize
46)
47{
48 scalar minDist = defaultCellSize;
49
50 for
51 (
52 label hI1 = 0;
53 hI1 < hitList.size() - 1;
54 ++hI1
55 )
56 {
57 const pointIndexHit& pHit1 = hitList[hI1];
58
59 if (pHit1.hit())
60 {
61 for
62 (
63 label hI2 = hI1 + 1;
64 hI2 < hitList.size();
65 ++hI2
66 )
67 {
68 const pointIndexHit& pHit2 = hitList[hI2];
69
70 if (pHit2.hit())
71 {
72 scalar curDist = mag(pHit1.hitPoint() - pHit2.hitPoint());
73
74 minDist = min(curDist, minDist);
75 }
76 }
77 }
78 }
79
80 return minDist;
81}
82
83
85(
86 const edgeMesh& emesh,
87 const List<pointIndexHit>& hitList,
88 const scalar defaultCellSize
89)
90{
91 scalar minDist = defaultCellSize;
92
93 for
94 (
95 label hI1 = 0;
96 hI1 < hitList.size() - 1;
97 ++hI1
98 )
99 {
100 const pointIndexHit& pHit1 = hitList[hI1];
101
102 if (pHit1.hit())
103 {
104 const edge& e1 = emesh.edges()[pHit1.index()];
105
106 for
107 (
108 label hI2 = hI1 + 1;
109 hI2 < hitList.size();
110 ++hI2
111 )
112 {
113 const pointIndexHit& pHit2 = hitList[hI2];
114
115 if (pHit2.hit())
116 {
117 const edge& e2 = emesh.edges()[pHit2.index()];
118
119 // Don't refine if the edges are connected to each other
120 if (!e1.connects(e2))
121 {
122 scalar curDist =
123 mag(pHit1.hitPoint() - pHit2.hitPoint());
124
125 minDist = min(curDist, minDist);
126 }
127 }
128 }
129 }
130 }
131
132 return minDist;
133}
134
135} // End namespace Foam
136
137
138// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
139
141(
142 const extendedEdgeMesh& emesh,
143 const triSurface& surf,
144 const scalar searchDistance
145)
146{
147 tmp<scalarField> tfld(new scalarField(surf.size(), searchDistance));
149
150 Info<< "Extracting proximity of close feature points and "
151 << "edges to the surface" << endl;
152
153 forAll(surf, fI)
154 {
155 const triPointRef& tri = surf[fI].tri(surf.points());
156 const point& triCentre = tri.circumCentre();
157
158 const scalar radiusSqr = min
159 (
160 sqr(4*tri.circumRadius()),
161 sqr(searchDistance)
162 );
163
164 List<pointIndexHit> hitList;
165
166 emesh.allNearestFeatureEdges(triCentre, radiusSqr, hitList);
167
168 featureProximity[fI] =
170 (
171 emesh,
172 hitList,
174 );
175
176 emesh.allNearestFeaturePoints(triCentre, radiusSqr, hitList);
177
178 featureProximity[fI] =
180 (
181 hitList,
183 );
184 }
185
186 return tfld;
187}
188
189
191(
192 const Time& runTime,
193 const word& basename,
194 const extendedEdgeMesh& emesh,
195 const triSurface& surf,
196 const scalar searchDistance
197)
198{
199 Info<< nl << "Extracting curvature of surface at the points."
200 << endl;
201
202
203 tmp<scalarField> tfld =
204 edgeMeshTools::featureProximity(emesh, surf, searchDistance);
206
207 triSurfaceScalarField outputField
208 (
210 (
211 basename + ".featureProximity",
212 runTime.constant(),
213 "triSurface",
214 runTime,
215 IOobject::NO_READ,
216 IOobject::NO_WRITE
217 ),
218 surf,
219 dimLength,
221 );
222
223 outputField.swap(featureProximity);
224 outputField.write();
225 outputField.swap(featureProximity);
226
227 return tfld;
228}
229
230// ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:66
label index() const noexcept
Return the hit index.
bool hit() const noexcept
Is there a hit?
const point_type & hitPoint() const
Return hit point. Fatal if not hit.
const Field< point_type > & points() const noexcept
Return reference to global points.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
void swap(UList< T > &list)
Swap content with another UList of the same type in constant time.
Definition: UListI.H:434
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Mesh data needed to do the Finite Area discretisation.
Definition: edgeFaMesh.H:56
const edgeList & edges() const noexcept
Return edges.
Definition: edgeMeshI.H:105
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
bool connects(const edge &other) const
Do the edges share a common vertex index?
Definition: edgeI.H:166
Description of feature edges and points.
void allNearestFeaturePoints(const point &sample, scalar searchRadiusSqr, List< pointIndexHit > &info) const
Find all the feature points within searchDistSqr of sample.
void allNearestFeatureEdges(const point &sample, const scalar searchRadiusSqr, List< pointIndexHit > &info) const
Find all the feature edges within searchDistSqr of sample.
virtual bool write(const bool valid=true) const
Write using setting from DB.
A class for managing temporary objects.
Definition: tmp.H:65
T & ref() const
Definition: tmpI.H:227
Triangulated surface description with patch information.
Definition: triSurface.H:79
A triangle primitive used to calculate face normals and swept volumes.
Definition: triangle.H:80
Point circumCentre() const
Return circum-centre.
Definition: triangleI.H:135
scalar circumRadius() const
Return circum-radius.
Definition: triangleI.H:162
A class for handling words, derived from Foam::string.
Definition: word.H:68
engineTime & runTime
tmp< scalarField > writeFeatureProximity(const Time &runTime, const word &basename, const extendedEdgeMesh &emesh, const triSurface &surf, const scalar searchDistance)
Calculate proximity of the features to the surface and write the field.
tmp< scalarField > featureProximity(const extendedEdgeMesh &emesh, const triSurface &surf, const scalar searchDistance)
Calculate proximity of the features to the surface.
Namespace for OpenFOAM.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:52
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
static scalar calcProximityOfFeaturePoints(const List< pointIndexHit > &hitList, const scalar defaultCellSize)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
scalar calcProximityOfFeatureEdges(const edgeMesh &emesh, const List< pointIndexHit > &hitList, const scalar defaultCellSize)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
Fields for triSurface.