Skip to content
This repository was archived by the owner on May 9, 2022. It is now read-only.

Commit 2e585a2

Browse files
author
David Blom
authored
RBF coarsening strategies: first selected points are deterministic (#337)
When increasing the number of cores, the selected points are always the same.
1 parent c6a7984 commit 2e585a2

File tree

3 files changed

+110
-6
lines changed

3 files changed

+110
-6
lines changed

src/RBFMeshMotionSolver/AdaptiveCoarsening.C

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,38 @@ namespace rbf
8282
{
8383
selectedPositions.clear();
8484

85-
selectedPositions.push_back( 0 );
86-
selectedPositions.push_back( 1 );
85+
// An initial selection is needed before the greedy algorithm starts
86+
// adding points to the selection.
87+
// The first point is the point with the largest disp/value
88+
// The second point is the point with the largest distance from the
89+
// first point.
90+
91+
{
92+
// Find first point: largest value
93+
El::DistMatrix<double, El::MC, El::STAR> norms;
94+
El::RowTwoNorms( *values, norms );
95+
El::Entry<double> locMax = El::MaxAbsLoc( norms );
96+
selectedPositions.push_back( locMax.i );
97+
98+
// Find second point: largest distance from the first point
99+
El::DistMatrix<double> distance = *positions;
100+
El::DistMatrix<double> tmp;
101+
El::Ones( tmp, distance.Height(), distance.Width() );
102+
103+
for ( int iColumn = 0; iColumn < tmp.Width(); iColumn++ )
104+
{
105+
El::DistMatrix<double> view;
106+
El::View( view, tmp, 0, iColumn, tmp.Height(), 1 );
107+
El::Scale( positions->Get( locMax.i, iColumn ), view );
108+
}
109+
110+
El::Axpy( -1, tmp, distance );
111+
112+
El::RowTwoNorms( distance, norms );
113+
locMax = El::MaxAbsLoc( norms );
114+
selectedPositions.push_back( locMax.i );
115+
}
116+
87117
int maxPoints = std::min( this->maxPoints, positions->Height() );
88118
int minPoints = std::min( this->minPoints, positions->Height() );
89119
double error = 0;

src/RBFMeshMotionSolver/RBFCoarsening.C

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,53 @@ namespace rbf
261261
rbf::vector errorList( positions.rows() );
262262
selectedPositions.resize( 2 );
263263

264-
for ( int i = 0; i < selectedPositions.rows(); i++ )
265-
selectedPositions( i ) = i;
264+
if ( livePointSelection )
265+
{
266+
// Select the point with the largest displacment
267+
int maxDisplacementIndex = -1;
268+
( values.rowwise().norm() ).maxCoeff( &maxDisplacementIndex );
269+
270+
// Add first point
271+
selectedPositions( 0 ) = maxDisplacementIndex;
272+
}
273+
else
274+
{
275+
// With unit displacement, first point is point with largest radius from origin and displacement > 0
276+
vector rad = positions.rowwise().norm();
277+
278+
int maxRadiusFromOriginIndex = -1;
279+
double maxRadius = -1;
280+
281+
for ( int i = 0; i < rad.rows(); i++ )
282+
{
283+
if ( rad( i ) > maxRadius && values.row( i ).norm() > SMALL )
284+
{
285+
maxRadius = rad( i );
286+
maxRadiusFromOriginIndex = i;
287+
}
288+
}
289+
290+
selectedPositions( 0 ) = maxRadiusFromOriginIndex;
291+
}
292+
293+
// Find point with largest distance from first point
294+
vector rad = ( positions - ( matrix::Constant( positions.rows(), 1, 1.0 ) * positions.row( selectedPositions( 0 ) ) ) ).rowwise().norm();
295+
int maxRadiusIndex = -1;
296+
double maxRadius = -1;
297+
298+
for ( int i = 0; i < rad.rows(); i++ )
299+
{
300+
if ( rad( i ) > maxRadius && (rad( i ) < 1.0 - SMALL || rad( i ) > 1.0 + SMALL) )
301+
{
302+
maxRadius = rad( i );
303+
maxRadiusIndex = i;
304+
}
305+
}
306+
307+
// Add second point
308+
selectedPositions( 1 ) = maxRadiusIndex;
266309

310+
assert( selectedPositions( 0 ) != selectedPositions( 1 ) );
267311
assert( positions.rows() >= selectedPositions.rows() );
268312

269313
rbf::matrix positionsInterpolationCoarse = positions;

src/RBFMeshMotionSolver/UnitCoarsening.C

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,38 @@ namespace rbf
3737

3838
selectedPositions.clear();
3939

40-
selectedPositions.push_back( 0 );
41-
selectedPositions.push_back( 1 );
40+
// An initial selection is needed before the greedy algorithm starts
41+
// adding points to the selection.
42+
// The first point is the point with the largest radius from the origin.
43+
// The second point is the point with the largest distance from the
44+
// first point.
45+
46+
{
47+
// Find first point: largest radius from origin
48+
El::DistMatrix<double, El::MC, El::STAR> norms;
49+
El::RowTwoNorms( *positions, norms );
50+
El::Entry<double> locMax = El::MaxAbsLoc( norms );
51+
selectedPositions.push_back( locMax.i );
52+
53+
// Find second point: largest distance from the first point
54+
El::DistMatrix<double> distance = *positions;
55+
El::DistMatrix<double> tmp;
56+
El::Ones( tmp, distance.Height(), distance.Width() );
57+
58+
for ( int iColumn = 0; iColumn < tmp.Width(); iColumn++ )
59+
{
60+
El::DistMatrix<double> view;
61+
El::View( view, tmp, 0, iColumn, tmp.Height(), 1 );
62+
El::Scale( positions->Get( locMax.i, iColumn ), view );
63+
}
64+
65+
El::Axpy( -1, tmp, distance );
66+
67+
El::RowTwoNorms( distance, norms );
68+
locMax = El::MaxAbsLoc( norms );
69+
selectedPositions.push_back( locMax.i );
70+
}
71+
4272
int maxPoints = std::min( this->maxPoints, positions->Height() );
4373
int minPoints = std::min( this->minPoints, positions->Height() );
4474

0 commit comments

Comments
 (0)