Skip to content

Commit 08066aa

Browse files
author
Will Bainbridge
committed
sampledSets: Search for samples on demand
This change prevents functions from searching the mesh for sampling points every time the mesh changes. They are now searched for on demand; typically whenever a function executes and/or writes.
1 parent b7397b3 commit 08066aa

File tree

36 files changed

+402
-811
lines changed

36 files changed

+402
-811
lines changed

src/functionObjects/field/interfaceHeight/interfaceHeight.C

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void Foam::functionObjects::interfaceHeight::writePositions()
8585
// Find the height of the location above the boundary
8686
scalar hLB =
8787
set.size()
88-
? - gHat & (locations_[li] - set.pointCoord(0))
88+
? - gHat & (locations_[li] - set.coords().pointCoord(0))
8989
: - vGreat;
9090
reduce(hLB, maxOp<scalar>());
9191

@@ -97,7 +97,8 @@ void Foam::functionObjects::interfaceHeight::writePositions()
9797
{
9898
if (set.segments()[si] != set.segments()[si+1]) continue;
9999

100-
const vector& p0 = set.pointCoord(si), & p1 = set.pointCoord(si+1);
100+
const vector& p0 = set.coords().pointCoord(si);
101+
const vector& p1 = set.coords().pointCoord(si+1);
101102
const label c0 = set.cells()[si], c1 = set.cells()[si+1];
102103
const label f0 = set.faces()[si], f1 = set.faces()[si+1];
103104

src/functionObjects/field/streamlines/streamlines.C

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ void Foam::functionObjects::streamlines::movePoints(const polyMesh& mesh)
583583
if (&mesh == &mesh_)
584584
{
585585
searchEngine_.correct();
586+
586587
sampledSetPtr_->movePoints();
587588
}
588589
}

src/meshTools/meshSearch/meshSearch.H

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
========= |
33
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
44
\\ / O peration | Website: https://openfoam.org
5-
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
5+
\\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
66
\\/ M anipulation |
77
-------------------------------------------------------------------------------
88
License
@@ -259,9 +259,6 @@ public:
259259
bool isInside(const point&) const;
260260

261261

262-
//- Delete all storage
263-
void clearOut();
264-
265262
//- Correct for mesh geom/topo changes
266263
void correct();
267264

src/sampling/sampledSet/arcUniform/arcUniform.C

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
========= |
33
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
44
\\ / O peration | Website: https://openfoam.org
5-
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
5+
\\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
66
\\/ M anipulation |
77
-------------------------------------------------------------------------------
88
License
@@ -89,40 +89,6 @@ void Foam::sampledSets::arcUniform::calcSamples
8989
}
9090

9191

92-
void Foam::sampledSets::arcUniform::genSamples()
93-
{
94-
DynamicList<point> samplingPositions;
95-
DynamicList<scalar> samplingDistances;
96-
DynamicList<label> samplingSegments;
97-
DynamicList<label> samplingCells;
98-
DynamicList<label> samplingFaces;
99-
100-
calcSamples
101-
(
102-
samplingPositions,
103-
samplingDistances,
104-
samplingSegments,
105-
samplingCells,
106-
samplingFaces
107-
);
108-
109-
samplingPositions.shrink();
110-
samplingDistances.shrink();
111-
samplingSegments.shrink();
112-
samplingCells.shrink();
113-
samplingFaces.shrink();
114-
115-
setSamples
116-
(
117-
samplingPositions,
118-
samplingDistances,
119-
samplingSegments,
120-
samplingCells,
121-
samplingFaces
122-
);
123-
}
124-
125-
12692
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
12793

12894
Foam::sampledSets::arcUniform::arcUniform
@@ -140,9 +106,7 @@ Foam::sampledSets::arcUniform::arcUniform
140106
startAngle_(dict.lookup<scalar>("startAngle")),
141107
endAngle_(dict.lookup<scalar>("endAngle")),
142108
nPoints_(dict.lookup<scalar>("nPoints"))
143-
{
144-
genSamples();
145-
}
109+
{}
146110

147111

148112
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //

src/sampling/sampledSet/arcUniform/arcUniform.H

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
========= |
33
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
44
\\ / O peration | Website: https://openfoam.org
5-
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
5+
\\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
66
\\/ M anipulation |
77
-------------------------------------------------------------------------------
88
License
@@ -106,7 +106,7 @@ class arcUniform
106106
// Private Member Functions
107107

108108
//- Calculate all the sampling points
109-
void calcSamples
109+
virtual void calcSamples
110110
(
111111
DynamicList<point>& samplingPositions,
112112
DynamicList<scalar>& samplingDistances,
@@ -115,9 +115,6 @@ class arcUniform
115115
DynamicList<label>& samplingFaces
116116
) const;
117117

118-
//- Uses calcSamples to obtain samples and copies them into *this
119-
virtual void genSamples();
120-
121118

122119
public:
123120

src/sampling/sampledSet/boundaryPoints/boundaryPoints.C

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
========= |
33
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
44
\\ / O peration | Website: https://openfoam.org
5-
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
5+
\\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
66
\\/ M anipulation |
77
-------------------------------------------------------------------------------
88
License
@@ -49,6 +49,7 @@ namespace sampledSets
4949
void Foam::sampledSets::boundaryPoints::calcSamples
5050
(
5151
DynamicList<point>& samplingPositions,
52+
DynamicList<scalar>&,
5253
DynamicList<label>& samplingSegments,
5354
DynamicList<label>& samplingCells,
5455
DynamicList<label>& samplingFaces
@@ -179,36 +180,6 @@ void Foam::sampledSets::boundaryPoints::calcSamples
179180
}
180181

181182

182-
void Foam::sampledSets::boundaryPoints::genSamples()
183-
{
184-
DynamicList<point> samplingPositions;
185-
DynamicList<label> samplingSegments;
186-
DynamicList<label> samplingCells;
187-
DynamicList<label> samplingFaces;
188-
189-
calcSamples
190-
(
191-
samplingPositions,
192-
samplingSegments,
193-
samplingCells,
194-
samplingFaces
195-
);
196-
197-
samplingPositions.shrink();
198-
samplingSegments.shrink();
199-
samplingCells.shrink();
200-
samplingFaces.shrink();
201-
202-
setSamples
203-
(
204-
samplingPositions,
205-
samplingSegments,
206-
samplingCells,
207-
samplingFaces
208-
);
209-
}
210-
211-
212183
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
213184

214185
Foam::sampledSets::boundaryPoints::boundaryPoints
@@ -223,9 +194,7 @@ Foam::sampledSets::boundaryPoints::boundaryPoints
223194
points_(dict.lookup("points")),
224195
patches_(dict.lookup("patches")),
225196
maxDistance_(dict.lookup<scalar>("maxDistance"))
226-
{
227-
genSamples();
228-
}
197+
{}
229198

230199

231200
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //

src/sampling/sampledSet/boundaryPoints/boundaryPoints.H

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
========= |
33
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
44
\\ / O peration | Website: https://openfoam.org
5-
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
5+
\\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
66
\\/ M anipulation |
77
-------------------------------------------------------------------------------
88
License
@@ -95,18 +95,16 @@ class boundaryPoints
9595

9696
// Private Member Functions
9797

98-
//- Samples all points in sampleCoords
99-
void calcSamples
98+
//- Calculate all the sampling points
99+
virtual void calcSamples
100100
(
101101
DynamicList<point>& samplingPositions,
102+
DynamicList<scalar>&,
102103
DynamicList<label>& samplingSegments,
103104
DynamicList<label>& samplingCells,
104105
DynamicList<label>& samplingFaces
105106
) const;
106107

107-
//- Uses calcSamples to obtain samples. Copies them into *this.
108-
virtual void genSamples();
109-
110108

111109
public:
112110

src/sampling/sampledSet/boundaryRandom/boundaryRandom.C

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
========= |
33
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
44
\\ / O peration | Website: https://openfoam.org
5-
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
5+
\\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
66
\\/ M anipulation |
77
-------------------------------------------------------------------------------
88
License
@@ -53,6 +53,7 @@ namespace sampledSets
5353
void Foam::sampledSets::boundaryRandom::calcSamples
5454
(
5555
DynamicList<point>& samplingPositions,
56+
DynamicList<scalar>&,
5657
DynamicList<label>& samplingSegments,
5758
DynamicList<label>& samplingCells,
5859
DynamicList<label>& samplingFaces
@@ -161,36 +162,6 @@ void Foam::sampledSets::boundaryRandom::calcSamples
161162
}
162163

163164

164-
void Foam::sampledSets::boundaryRandom::genSamples()
165-
{
166-
DynamicList<point> samplingPositions;
167-
DynamicList<label> samplingSegments;
168-
DynamicList<label> samplingCells;
169-
DynamicList<label> samplingFaces;
170-
171-
calcSamples
172-
(
173-
samplingPositions,
174-
samplingSegments,
175-
samplingCells,
176-
samplingFaces
177-
);
178-
179-
samplingPositions.shrink();
180-
samplingSegments.shrink();
181-
samplingCells.shrink();
182-
samplingFaces.shrink();
183-
184-
setSamples
185-
(
186-
samplingPositions,
187-
samplingSegments,
188-
samplingCells,
189-
samplingFaces
190-
);
191-
}
192-
193-
194165
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
195166

196167
Foam::sampledSets::boundaryRandom::boundaryRandom
@@ -204,9 +175,7 @@ Foam::sampledSets::boundaryRandom::boundaryRandom
204175
sampledSet(name, mesh, searchEngine, dict),
205176
patches_(dict.lookup("patches")),
206177
nPoints_(dict.lookup<label>("nPoints"))
207-
{
208-
genSamples();
209-
}
178+
{}
210179

211180

212181
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //

src/sampling/sampledSet/boundaryRandom/boundaryRandom.H

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
========= |
33
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
44
\\ / O peration | Website: https://openfoam.org
5-
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
5+
\\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
66
\\/ M anipulation |
77
-------------------------------------------------------------------------------
88
License
@@ -84,18 +84,16 @@ class boundaryRandom
8484

8585
// Private Member Functions
8686

87-
//- Sample all points
88-
void calcSamples
87+
//- Calculate all the sampling points
88+
virtual void calcSamples
8989
(
9090
DynamicList<point>& samplingPositions,
91+
DynamicList<scalar>&,
9192
DynamicList<label>& samplingSegments,
9293
DynamicList<label>& samplingCells,
9394
DynamicList<label>& samplingFaces
9495
) const;
9596

96-
//- Use calcSamples to obtain samples and copy them into *this
97-
virtual void genSamples();
98-
9997

10098
public:
10199

src/sampling/sampledSet/boxUniform/boxUniform.C

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
========= |
33
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
44
\\ / O peration | Website: https://openfoam.org
5-
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
5+
\\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
66
\\/ M anipulation |
77
-------------------------------------------------------------------------------
88
License
@@ -49,6 +49,7 @@ namespace sampledSets
4949
void Foam::sampledSets::boxUniform::calcSamples
5050
(
5151
DynamicList<point>& samplingPositions,
52+
DynamicList<scalar>&,
5253
DynamicList<label>& samplingSegments,
5354
DynamicList<label>& samplingCells,
5455
DynamicList<label>& samplingFaces
@@ -85,36 +86,6 @@ void Foam::sampledSets::boxUniform::calcSamples
8586
}
8687

8788

88-
void Foam::sampledSets::boxUniform::genSamples()
89-
{
90-
DynamicList<point> samplingPositions;
91-
DynamicList<label> samplingSegments;
92-
DynamicList<label> samplingCells;
93-
DynamicList<label> samplingFaces;
94-
95-
calcSamples
96-
(
97-
samplingPositions,
98-
samplingSegments,
99-
samplingCells,
100-
samplingFaces
101-
);
102-
103-
samplingPositions.shrink();
104-
samplingSegments.shrink();
105-
samplingCells.shrink();
106-
samplingFaces.shrink();
107-
108-
setSamples
109-
(
110-
samplingPositions,
111-
samplingSegments,
112-
samplingCells,
113-
samplingFaces
114-
);
115-
}
116-
117-
11889
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
11990

12091
Foam::sampledSets::boxUniform::boxUniform
@@ -128,9 +99,7 @@ Foam::sampledSets::boxUniform::boxUniform
12899
sampledSet(name, mesh, searchEngine, dict),
129100
box_(dict.lookup("box")),
130101
nPoints_(dict.lookup("nPoints"))
131-
{
132-
genSamples();
133-
}
102+
{}
134103

135104

136105
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //

0 commit comments

Comments
 (0)