points.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) 2011-2025 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 "points.H"
27 #include "meshSearch.H"
28 #include "sampledSetCloud.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace sampledSets
36 {
39 }
40 }
41 
42 
43 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
44 
45 void Foam::sampledSets::points::calcSamples
46 (
47  const polyMesh& mesh,
48  const pointField& points,
49  DynamicList<point>& samplingPositions,
50  DynamicList<scalar>& samplingDistances,
51  DynamicList<label>& samplingSegments,
52  DynamicList<label>& samplingCells,
53  DynamicList<label>& samplingFaces
54 )
55 {
56  const meshSearch& searchEngine = meshSearch::New(mesh);
57 
58  // Create a cloud with which to track segments
59  sampledSetCloud particles
60  (
61  mesh,
64  );
65 
66  // Consider each point
67  label segmenti = 0, samplei = 0, pointi0 = labelMax, pointi = 0;
68  label nLocateBoundaryHits = 0;
69  scalar distance = 0;
70  while (pointi < points.size())
71  {
72  // Sum the distance to the start of the track
73  for (label pointj = pointi0; pointj < pointi; ++ pointj)
74  {
75  distance += mag(points[pointj + 1] - points[pointj]);
76  }
77 
78  // Update the old point index
79  pointi0 = pointi;
80 
81  // Get unique processor and cell that this sample point is in
82  const labelPair procAndCelli = returnReduce
83  (
84  labelPair
85  (
87  searchEngine.findCell(points[pointi])
88  ),
89  [](const labelPair& a, const labelPair& b)
90  {
91  return
92  a.second() != -1 && b.second() != -1
93  ? a.first() < b.first() ? a : b
94  : a.second() != -1 ? a : b;
95  }
96  );
97 
98  // Skip this point if it is not in the global mesh
99  if (procAndCelli.second() == -1)
100  {
101  ++ pointi;
102  }
103 
104  // If the point is in the global mesh then track to create a segment
105  else
106  {
108  (
109  particles,
110  points,
111  true,
112  false,
113  false,
114  samplingPositions,
115  samplingDistances,
116  samplingCells,
117  samplingFaces
118  );
119 
120  // Clear the cloud, then, if the point is in this local mesh,
121  // initialise a particle at the point
122  particles.clear();
123  if (procAndCelli.first() == Pstream::myProcNo())
124  {
125  particles.addParticle
126  (
128  (
129  searchEngine,
130  points[pointi],
131  procAndCelli.second(),
132  nLocateBoundaryHits,
133  pointi,
134  1,
135  distance
136  )
137  );
138 
139  particles.first()->store(particles, td);
140  }
141 
142  // Track to create this segment
143  particles.move(particles, td);
144 
145  // Set the segment indices
146  samplingSegments.append
147  (
148  labelList
149  (
150  samplingPositions.size() - samplingSegments.size(),
151  segmenti
152  )
153  );
154 
155  // Move on to the next segment
156  ++ segmenti;
157 
158  // Determine the global number of samples completed
159  const label samplei0 = samplei;
160  samplei = returnReduce(samplingPositions.size(), sumOp<label>());
161 
162  // Move to the next unsampled point
163  pointi += samplei - samplei0;
164  }
165  }
166 }
167 
168 
169 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
170 
171 bool Foam::sampledSets::points::calcSamples
172 (
173  DynamicList<point>& samplingPositions,
174  DynamicList<scalar>& samplingDistances,
175  DynamicList<label>& samplingSegments,
176  DynamicList<label>& samplingCells,
177  DynamicList<label>& samplingFaces
178 ) const
179 {
180  if (!ordered_)
181  {
182  const meshSearch& searchEngine = meshSearch::New(mesh());
183 
184  forAll(points_, i)
185  {
186  const point& pt = points_[i];
187  const label celli = searchEngine.findCell(pt);
188 
189  if (celli != -1)
190  {
191  samplingPositions.append(pt);
192  samplingSegments.append(i);
193  samplingCells.append(celli);
194  samplingFaces.append(-1);
195  }
196  }
197  }
198  else
199  {
200  calcSamples
201  (
202  mesh(),
203  pointField(points_),
204  samplingPositions,
205  samplingDistances,
206  samplingSegments,
207  samplingCells,
208  samplingFaces
209  );
210  }
211 
212  // Return whether or not distances have been created
213  return ordered_;
214 }
215 
216 
217 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
218 
220 (
221  const word& name,
222  const polyMesh& mesh,
223  const dictionary& dict
224 )
225 :
227  points_(dict.lookup("points")),
228  ordered_(dict.lookup<bool>("ordered"))
229 {}
230 
231 
232 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
233 
235 {}
236 
237 
238 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
Template class for intrusive linked lists.
Definition: ILList.H:67
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
const Type & second() const
Return second.
Definition: PairI.H:121
const Type & first() const
Return first.
Definition: PairI.H:107
T * first()
Return the first entry.
Definition: UILList.H:109
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:429
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
void addParticle(ParticleType *pPtr)
Transfer particle to cloud.
Definition: Cloud.C:227
void move(TrackCloudType &cloud, typename ParticleType::trackingData &td)
Move the particles.
Definition: Cloud.C:292
Mesh object that implements searches within the local cells and faces.
Definition: meshSearch.H:59
label findCell(const point &p, const pointInCellShapes=pointInCellShapes::tets) const
Find the cell containing the given point.
Definition: meshSearch.C:173
static const meshSearch & New(const polyMesh &mesh, const pointInCellShapes=pointInCellShapes::tets)
Lookup or construct from mesh and cell decomposition option.
Definition: meshSearch.C:61
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
A Cloud of sampledSet particles.
Particle for generating line-type sampled sets.
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:64
const polyMesh & mesh() const
Access the mesh.
Definition: sampledSetI.H:36
label size() const
Return the size.
Definition: sampledSetI.H:52
Specified point samples. Optionally ordered into a continuous path. Ordering is an optimisation; it e...
Definition: points.H:106
virtual ~points()
Destructor.
Definition: points.C:234
points(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: points.C:220
Set of sets to sample. Call sampledSets.write() to sample&write files.
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
volScalarField & b
Definition: createFields.H:27
defineTypeNameAndDebug(arcUniform, 0)
addToRunTimeSelectionTable(sampledSet, arcUniform, word)
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Namespace for OpenFOAM.
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
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
static const label labelMax
Definition: label.H:62
dictionary dict