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 -------------------------------------------------------------------------------
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 = 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));
148  scalarField& featureProximity = tfld.ref();
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,
173  featureProximity[fI]
174  );
175 
176  emesh.allNearestFeaturePoints(triCentre, radiusSqr, hitList);
177 
178  featureProximity[fI] =
180  (
181  hitList,
182  featureProximity[fI]
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);
205  scalarField& featureProximity = tfld.ref();
206 
207  triSurfaceScalarField outputField
208  (
209  IOobject
210  (
211  basename + ".featureProximity",
212  runTime.constant(),
213  "triSurface",
214  runTime,
215  IOobject::NO_READ,
216  IOobject::NO_WRITE
217  ),
218  surf,
219  dimLength,
220  scalarField()
221  );
222 
223  outputField.swap(featureProximity);
224  outputField.write();
225  outputField.swap(featureProximity);
226 
227  return tfld;
228 }
229 
230 // ************************************************************************* //
Foam::PrimitivePatch::points
const Field< point_type > & points() const noexcept
Return reference to global points.
Definition: PrimitivePatch.H:299
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
pointIndexHit.H
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::extendedEdgeMesh::allNearestFeatureEdges
void allNearestFeatureEdges(const point &sample, const scalar searchRadiusSqr, List< pointIndexHit > &info) const
Find all the feature edges within searchDistSqr of sample.
Definition: extendedEdgeMesh.C:771
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:52
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
triSurfaceFields.H
Fields for triSurface.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::PointIndexHit::hitPoint
const point_type & hitPoint() const
Return hit point. Fatal if not hit.
Definition: PointIndexHit.H:154
triSurface.H
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
OFstream.H
Foam::edge::connects
bool connects(const edge &other) const
Do the edges share a common vertex index?
Definition: edgeI.H:166
Foam::edgeMeshTools::writeFeatureProximity
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.
Definition: edgeMeshFeatureProximity.C:191
Foam::triangle
A triangle primitive used to calculate face normals and swept volumes.
Definition: triangle.H:59
Foam::PointIndexHit
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:52
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:227
Foam::PointIndexHit::hit
bool hit() const noexcept
Is there a hit?
Definition: PointIndexHit.H:130
Foam::Field< scalar >
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:76
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
extendedEdgeMesh.H
Foam::calcProximityOfFeatureEdges
scalar calcProximityOfFeatureEdges(const edgeMesh &emesh, const List< pointIndexHit > &hitList, const scalar defaultCellSize)
Definition: edgeMeshFeatureProximity.C:85
Foam::triangle::circumRadius
scalar circumRadius() const
Return circum-radius.
Definition: triangleI.H:162
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::edgeMesh::edges
const edgeList & edges() const noexcept
Return edges.
Definition: edgeMeshI.H:105
Foam::extendedEdgeMesh
Description of feature edges and points.
Definition: extendedEdgeMesh.H:85
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::Vector< scalar >
Foam::triangle::circumCentre
Point circumCentre() const
Return circum-centre.
Definition: triangleI.H:135
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::PointIndexHit::index
label index() const noexcept
Return the hit index.
Definition: PointIndexHit.H:136
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::calcProximityOfFeaturePoints
static scalar calcProximityOfFeaturePoints(const List< pointIndexHit > &hitList, const scalar defaultCellSize)
Definition: edgeMeshFeatureProximity.C:43
edgeMeshTools.H
Foam::extendedEdgeMesh::allNearestFeaturePoints
void allNearestFeaturePoints(const point &sample, scalar searchRadiusSqr, List< pointIndexHit > &info) const
Find all the feature points within searchDistSqr of sample.
Definition: extendedEdgeMesh.C:740
Foam::edgeMesh
Mesh data needed to do the Finite Area discretisation.
Definition: edgeFaMesh.H:53
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
MeshedSurface.H
Foam::edgeMeshTools::featureProximity
tmp< scalarField > featureProximity(const extendedEdgeMesh &emesh, const triSurface &surf, const scalar searchDistance)
Calculate proximity of the features to the surface.
Definition: edgeMeshFeatureProximity.C:141