Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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 = 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;
133
134} // End namespace Foam
135
136
137// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138
140(
141 const extendedEdgeMesh& emesh,
142 const triSurface& surf,
143 const scalar searchDistance
144)
145{
146 auto tfld = tmp<scalarField>::New(surf.size(), searchDistance);
147 auto& 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] =
168 calcProximityOfFeatureEdges
169 (
170 emesh,
171 hitList,
172 featureProximity[fI]
173 );
174
175 emesh.allNearestFeaturePoints(triCentre, radiusSqr, hitList);
176
177 featureProximity[fI] =
178 calcProximityOfFeaturePoints
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 swap(List< T > &other)
Swap with plain List content. Implies shrink_to_fit().
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
label index() const noexcept
Return the hit index.
bool hit() const noexcept
Is there a hit?
const point_type & point() const noexcept
Return point, no checks.
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:75
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
scalar dist(const Vector< Cmpt > &v2) const
The L2-norm distance from another vector. The mag() of the difference.
Definition VectorI.H:107
Mesh data needed to do the Finite Area discretisation.
Definition edgeFaMesh.H:50
const edgeList & edges() const noexcept
Return edges.
Definition edgeMeshI.H:98
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
Definition edge.H:62
bool connected(const edge &other) const
True if the edge has at least one vertex in common with other.
Definition edgeI.H:152
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 writeOnProc=true) const
Write using setting from DB.
A class for managing temporary objects.
Definition tmp.H:75
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition tmp.H:215
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition tmpI.H:235
Triangulated surface description with patch information.
Definition triSurface.H:74
Point circumCentre() const
Return circum-centre.
Definition triangleI.H:329
scalar circumRadius() const
Return circum-radius.
Definition triangleI.H:356
A class for handling words, derived from Foam::string.
Definition word.H:66
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)
messageStream Info
Information stream (stdout output on master, null elsewhere).
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
static scalar calcProximityOfFeaturePoints(const List< pointIndexHit > &hitList, const scalar defaultCellSize)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:26
vector point
Point is a vector.
Definition point.H:37
triangle< point, const point & > triPointRef
A triangle using referred points.
Definition triangleFwd.H:46
scalar calcProximityOfFeatureEdges(const edgeMesh &emesh, const List< pointIndexHit > &hitList, const scalar defaultCellSize)
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
DimensionedField< scalar, triSurfaceGeoMesh > triSurfaceScalarField
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299
Fields for triSurface.