pointDist.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2013-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "pointDist.H"
27 #include "pointEdgeDist.H"
28 #include "pointMesh.H"
29 #include "PointEdgeWave.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 (
35  const pointMesh& pMesh,
36  const labelHashSet& startPatchIDs,
37  const pointField& points,
38  const scalar maxDist
39 )
40 :
42  (
43  IOobject
44  (
45  "pointDistance",
46  pMesh.db().time().name(),
47  pMesh.db()
48  ),
49  pMesh,
51  ),
52  points_(points),
53  startPatchIDs_(startPatchIDs),
54  maxDist_(maxDist)
55 {
56  correct();
57 }
58 
59 
61 (
62  const pointMesh& pMesh,
63  const labelHashSet& startPatchIDs,
64  const labelHashSet& startZoneIDs,
65  const labelHashSet& endPatchIDs,
66  const labelHashSet& endZoneIDs,
67  const pointField& points,
68  const scalar maxDist
69 )
70 :
72  (
73  IOobject
74  (
75  "pointDistance",
76  pMesh.db().time().name(),
77  pMesh.db()
78  ),
79  pMesh,
81  ),
82  points_(points),
83  startPatchIDs_(startPatchIDs),
84  startZoneIDs_(startZoneIDs),
85  endPatchIDs_(endPatchIDs),
86  endZoneIDs_(endZoneIDs),
87  maxDist_(maxDist)
88 {
89  correct();
90 }
91 
92 
93 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
94 
96 {}
97 
98 
99 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
100 
102 {
103  const pointBoundaryMesh& pbm = mesh().boundary();
104 
105  label nKnownPoints = 0;
106 
107  forAllConstIter(labelHashSet, startPatchIDs_, iter)
108  {
109  nKnownPoints += pbm[iter.key()].meshPoints().size();
110  }
111 
112  forAllConstIter(labelHashSet, startZoneIDs_, iter)
113  {
114  nKnownPoints += mesh()().pointZones()[iter.key()].size();
115  }
116 
117  forAllConstIter(labelHashSet, endPatchIDs_, iter)
118  {
119  nKnownPoints += pbm[iter.key()].meshPoints().size();
120  }
121 
122  forAllConstIter(labelHashSet, endZoneIDs_, iter)
123  {
124  nKnownPoints += mesh()().pointZones()[iter.key()].size();
125  }
126 
127  pointEdgeDist::data pointEdgeData(points_, maxDist_);
128 
129  // Set the start points of the wave
130  List<pointEdgeDist> knownPointsInfo(nKnownPoints);
131  labelList knownPoints(nKnownPoints);
132  nKnownPoints = 0;
133 
134  // Add the patch start points to the knownPointsInfo
135  forAllConstIter(labelHashSet, startPatchIDs_, iter)
136  {
137  const label patchi = iter.key();
138  const labelList& mp = pbm[patchi].meshPoints();
139 
140  forAll(mp, ppi)
141  {
142  const label meshPointi = mp[ppi];
143  knownPoints[nKnownPoints] = meshPointi;
144  knownPointsInfo[nKnownPoints] = pointEdgeDist
145  (
146  pointEdgeData.points[meshPointi],
147  0
148  );
149  nKnownPoints++;
150  }
151  }
152 
153  // Add the zone start points to the knownPointsInfo
154  forAllConstIter(labelHashSet, startZoneIDs_, iter)
155  {
156  const label zonei = iter.key();
157  const labelList& zonePoints = mesh()().pointZones()[zonei];
158 
159  forAll(zonePoints, j)
160  {
161  const label meshPointi = zonePoints[j];
162  knownPoints[nKnownPoints] = meshPointi;
163  knownPointsInfo[nKnownPoints] = pointEdgeDist
164  (
165  pointEdgeData.points[meshPointi],
166  0
167  );
168  nKnownPoints++;
169  }
170  }
171 
172  // Add the patch end points to the knownPointsInfo
173  forAllConstIter(labelHashSet, endPatchIDs_, iter)
174  {
175  const label patchi = iter.key();
176  const labelList& mp = pbm[patchi].meshPoints();
177 
178  forAll(mp, ppi)
179  {
180  const label meshPointi = mp[ppi];
181  knownPoints[nKnownPoints] = meshPointi;
182  knownPointsInfo[nKnownPoints] = pointEdgeDist
183  (
184  pointEdgeData.points[meshPointi],
185  -great
186  );
187  nKnownPoints++;
188  }
189  }
190 
191  // Add the zone end points to the knownPointsInfo
192  forAllConstIter(labelHashSet, endZoneIDs_, iter)
193  {
194  const label zonei = iter.key();
195  const labelList& zonePoints = mesh()().pointZones()[zonei];
196 
197  forAll(zonePoints, j)
198  {
199  const label meshPointi = zonePoints[j];
200  knownPoints[nKnownPoints] = meshPointi;
201  knownPointsInfo[nKnownPoints] = pointEdgeDist
202  (
203  pointEdgeData.points[meshPointi],
204  -great
205  );
206  nKnownPoints++;
207  }
208  }
209 
210  // Current info on points
211  List<pointEdgeDist> allPointInfo(mesh()().nPoints());
212 
213  // Current info on edges
214  List<pointEdgeDist> allEdgeInfo(mesh()().nEdges());
215 
217  <
220  > patchCalc
221  (
222  mesh()(),
223  knownPoints,
224  knownPointsInfo,
225 
226  allPointInfo,
227  allEdgeInfo,
228  mesh().globalData().nTotalPoints(), // max iterations
229  pointEdgeData
230  );
231 
232  pointScalarField& psf = *this;
233 
234  forAll(allPointInfo, pointi)
235  {
236  if (allPointInfo[pointi].set(pointEdgeData))
237  {
238  psf[pointi] = sqrt(allPointInfo[pointi].distSqr());
239  }
240  else
241  {
242  psf[pointi] = maxDist_;
243  }
244  }
245 
246  forAllConstIter(labelHashSet, startZoneIDs_, iter)
247  {
248  const label zonei = iter.key();
249  const labelList& zonePoints = mesh()().pointZones()[zonei];
250 
251  forAll(zonePoints, j)
252  {
253  const label meshPointi = zonePoints[j];
254  psf[meshPointi] = 0;
255  }
256  }
257 }
258 
259 
260 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
Wave propagation of information through grid. Every iteration information goes through one layer of e...
Definition: PointEdgeWave.H:89
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:932
label size() const
Return fvMesh size.
Definition: fvMesh.H:468
Foam::pointBoundaryMesh.
pointDist(const pointMesh &pMesh, const labelHashSet &startPatchIDs, const pointField &points, const scalar maxDist=rootVGreat)
Construct from mesh and set of start patches.
Definition: pointDist.C:34
void correct()
Correct for mesh geom/topo changes.
Definition: pointDist.C:101
virtual ~pointDist()
Destructor.
Definition: pointDist.C:95
Class used to pass data into container.
Definition: pointEdgeDist.H:80
const pointField & points
Definition: pointEdgeDist.H:82
Holds information regarding nearest wall point. Used in PointEdgeWave. (so not standard FaceCellWave)...
Definition: pointEdgeDist.H:66
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:52
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
label patchi
const pointField & points
label nPoints
const dimensionedScalar mp
Proton mass.
const dimensionSet time
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const dimensionSet & dimLength
Definition: dimensions.C:141
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)