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-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 
39 namespace Foam
40 {
41 
42 static scalar calcProximityOfFeaturePoints
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 = pHit1.point().dist(pHit2.point());
73 
74  minDist = min(minDist, curDist);
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.connected(e2))
121  {
122  scalar curDist = pHit1.point().dist(pHit2.point());
123 
124  minDist = min(minDist, curDist);
125  }
126  }
127  }
128  }
129  }
130 
131  return minDist;
132 }
134 } // End namespace Foam
135 
136 
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 
140 (
141  const extendedEdgeMesh& emesh,
142  const triSurface& surf,
143  const scalar searchDistance
144 )
145 {
146  tmp<scalarField> tfld(new scalarField(surf.size(), searchDistance));
147  scalarField& featureProximity = tfld.ref();
148 
149  Info<< "Extracting proximity of close feature points and "
150  << "edges to the surface" << endl;
151 
152  forAll(surf, fI)
153  {
154  const triPointRef& tri = surf[fI].tri(surf.points());
155  const point& triCentre = tri.circumCentre();
156 
157  const scalar radiusSqr = min
158  (
159  sqr(4*tri.circumRadius()),
160  sqr(searchDistance)
161  );
162 
163  List<pointIndexHit> hitList;
164 
165  emesh.allNearestFeatureEdges(triCentre, radiusSqr, hitList);
166 
167  featureProximity[fI] =
169  (
170  emesh,
171  hitList,
172  featureProximity[fI]
173  );
174 
175  emesh.allNearestFeaturePoints(triCentre, radiusSqr, hitList);
176 
177  featureProximity[fI] =
179  (
180  hitList,
181  featureProximity[fI]
182  );
183  }
184 
185  return tfld;
186 }
187 
188 
190 (
191  const Time& runTime,
192  const word& basename,
193  const extendedEdgeMesh& emesh,
194  const triSurface& surf,
195  const scalar searchDistance
196 )
197 {
198  Info<< nl << "Extracting curvature of surface at the points."
199  << endl;
200 
201 
202  tmp<scalarField> tfld =
203  edgeMeshTools::featureProximity(emesh, surf, searchDistance);
204  scalarField& featureProximity = tfld.ref();
205 
206  triSurfaceScalarField outputField
207  (
208  IOobject
209  (
210  basename + ".featureProximity",
211  runTime.constant(),
212  "triSurface",
213  runTime,
214  IOobject::NO_READ,
215  IOobject::NO_WRITE
216  ),
217  surf,
218  dimLength,
219  scalarField()
220  );
221 
222  outputField.swap(featureProximity);
223  outputField.write();
224  outputField.swap(featureProximity);
225 
226  return tfld;
227 }
228 
229 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
A triangle primitive used to calculate face normals and swept volumes. Uses referred points...
Definition: triangle.H:217
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
Fields for triSurface.
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition: tmpI.H:235
dimensionedSymmTensor sqr(const dimensionedVector &dv)
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Description of feature edges and points.
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
Definition: pointIndexHit.H:58
This class describes the interaction of an object (often a face) and a point. It carries the info of ...
Definition: pointIndexHit.H:44
static scalar calcProximityOfFeaturePoints(const List< pointIndexHit > &hitList, const scalar defaultCellSize)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
const point_type & point() const noexcept
Return point, no checks.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const Field< point_type > & points() const noexcept
Return reference to global points.
scalar circumRadius() const
Return circum-radius.
Definition: triangleI.H:314
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Point circumCentre() const
Return circum-centre.
Definition: triangleI.H:287
bool hit() const noexcept
Is there a hit?
tmp< scalarField > featureProximity(const extendedEdgeMesh &emesh, const triSurface &surf, const scalar searchDistance)
Calculate proximity of the features to the surface.
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
scalar calcProximityOfFeatureEdges(const edgeMesh &emesh, const List< pointIndexHit > &hitList, const scalar defaultCellSize)
messageStream Info
Information stream (stdout output on master, null elsewhere)
void allNearestFeatureEdges(const point &sample, const scalar searchRadiusSqr, List< pointIndexHit > &info) const
Find all the feature edges within searchDistSqr of sample.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Triangulated surface description with patch information.
Definition: triSurface.H:71
Foam::DimensionedField< scalar, triSurfaceGeoMesh > triSurfaceScalarField
Namespace for OpenFOAM.
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.
void allNearestFeaturePoints(const point &sample, scalar searchRadiusSqr, List< pointIndexHit > &info) const
Find all the feature points within searchDistSqr of sample.