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

Commit

Permalink
Use El::VR, El::STAR distribution for elemental matrices (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Blom authored Sep 1, 2016
1 parent 911c08f commit c4dedb8
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 129 deletions.
42 changes: 21 additions & 21 deletions src/RBFMeshMotionSolver/AdaptiveCoarsening.C
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace rbf

void AdaptiveCoarsening::compute(
std::shared_ptr<RBFFunctionInterface> function,
std::unique_ptr<El::DistMatrix<double> > pos,
std::unique_ptr<El::DistMatrix<double> > posInterpolation
std::unique_ptr<ElDistVector> pos,
std::unique_ptr<ElDistVector> posInterpolation
)
{
// Selection is performed as necessary. It is only performed when interpolate()
Expand All @@ -45,24 +45,24 @@ namespace rbf
this->positionsInterpolation = std::move( posInterpolation );
}

std::pair<int, double> AdaptiveCoarsening::computeError( const std::unique_ptr<El::DistMatrix<double> > & values )
std::pair<int, double> AdaptiveCoarsening::computeError( const std::unique_ptr<ElDistVector> & values )
{
// Select a subset of values based on the selected points

std::unique_ptr<El::DistMatrix<double> > valuesCoarse( new El::DistMatrix<double>() );
std::unique_ptr<ElDistVector> valuesCoarse( new ElDistVector() );
El::Zeros( *valuesCoarse, selectedPositions.size(), values->Width() );
selectData( values, valuesCoarse );

// Perform the interpolation

std::unique_ptr<El::DistMatrix<double> > result = rbfCoarse->interpolate( valuesCoarse );
std::unique_ptr<ElDistVector> result = rbfCoarse->interpolate( valuesCoarse );

assert( values->Height() == result->Height() );

// Compute error
El::DistMatrix<double> diff = *values;
ElDistVector diff = *values;
El::Axpy( -1, *result, diff );
El::DistMatrix<double, El::MC, El::STAR> errors;
ElDistVector errors;
El::RowTwoNorms( diff, errors );

// Get location of max error
Expand All @@ -78,7 +78,7 @@ namespace rbf
return std::pair<int, double>( locMax.i, locMax.value );
}

void AdaptiveCoarsening::greedySelection( const std::unique_ptr<El::DistMatrix<double> > & values )
void AdaptiveCoarsening::greedySelection( const std::unique_ptr<ElDistVector> & values )
{
selectedPositions.clear();

Expand All @@ -90,19 +90,19 @@ namespace rbf

{
// Find first point: largest value
El::DistMatrix<double, El::MC, El::STAR> norms;
ElDistVector norms;
El::RowTwoNorms( *values, norms );
El::Entry<double> locMax = El::MaxAbsLoc( norms );
selectedPositions.push_back( locMax.i );

// Find second point: largest distance from the first point
El::DistMatrix<double> distance = *positions;
El::DistMatrix<double> tmp;
ElDistVector distance = *positions;
ElDistVector tmp;
El::Ones( tmp, distance.Height(), distance.Width() );

for ( int iColumn = 0; iColumn < tmp.Width(); iColumn++ )
{
El::DistMatrix<double> view;
ElDistVector view;
El::View( view, tmp, 0, iColumn, tmp.Height(), 1 );
El::Scale( positions->Get( locMax.i, iColumn ), view );
}
Expand All @@ -121,12 +121,12 @@ namespace rbf
for ( int i = 0; i < maxPoints; i++ )
{
// Build the matrices for the RBF interpolation
std::unique_ptr<El::DistMatrix<double> > positionsCoarse( new El::DistMatrix<double>() );
std::unique_ptr<ElDistVector> positionsCoarse( new ElDistVector() );
El::Zeros( *positionsCoarse, selectedPositions.size(), positions->Width() );
selectData( positions, positionsCoarse );

// Perform the RBF interpolation
std::unique_ptr<El::DistMatrix<double> > positionsInterpolationCoarse( new El::DistMatrix<double>() );
std::unique_ptr<ElDistVector> positionsInterpolationCoarse( new ElDistVector() );
*positionsInterpolationCoarse = *positions;
rbfCoarse = std::unique_ptr<ElRBFInterpolation>( new ElRBFInterpolation( rbfFunction, std::move( positionsCoarse ), std::move( positionsInterpolationCoarse ) ) );

Expand Down Expand Up @@ -154,14 +154,14 @@ namespace rbf

// Initialize interpolator

std::unique_ptr<El::DistMatrix<double> > positionsCoarse( new El::DistMatrix<double>() );
std::unique_ptr<ElDistVector> positionsCoarse( new ElDistVector() );
El::Zeros( *positionsCoarse, selectedPositions.size(), positions->Width() );

selectData( positions, positionsCoarse );

rbf = std::unique_ptr<ElRBFInterpolation>( new ElRBFInterpolation() );

std::unique_ptr<El::DistMatrix<double> > positionsInterpolationTmp( new El::DistMatrix<double>( *positionsInterpolation ) );
std::unique_ptr<ElDistVector> positionsInterpolationTmp( new ElDistVector( *positionsInterpolation ) );

rbf->compute( rbfFunction, std::move( positionsCoarse ), std::move( positionsInterpolationTmp ) );
}
Expand All @@ -171,7 +171,7 @@ namespace rbf
return rbf->initialized();
}

std::unique_ptr<El::DistMatrix<double> > AdaptiveCoarsening::interpolate( const std::unique_ptr<El::DistMatrix<double> > & values )
std::unique_ptr<ElDistVector> AdaptiveCoarsening::interpolate( const std::unique_ptr<ElDistVector> & values )
{
values->ProcessQueues();

Expand All @@ -190,7 +190,7 @@ namespace rbf
}
else
{
std::unique_ptr<El::DistMatrix<double> > result( new El::DistMatrix<double>() );
std::unique_ptr<ElDistVector> result( new ElDistVector() );
El::Zeros( *result, positionsInterpolation->Height(), positionsInterpolation->Width() );
return result;
}
Expand Down Expand Up @@ -219,7 +219,7 @@ namespace rbf
greedySelection( values );
}

std::unique_ptr<El::DistMatrix<double> > selectedValues( new El::DistMatrix<double>() );
std::unique_ptr<ElDistVector> selectedValues( new ElDistVector() );
El::Zeros( *selectedValues, selectedPositions.size(), values->Width() );

selectData( values, selectedValues );
Expand All @@ -228,8 +228,8 @@ namespace rbf
}

void AdaptiveCoarsening::selectData(
const std::unique_ptr<El::DistMatrix<double> > & data,
std::unique_ptr<El::DistMatrix<double> > & selection
const std::unique_ptr<ElDistVector> & data,
std::unique_ptr<ElDistVector> & selection
)
{
assert( selection->Height() == int( selectedPositions.size() ) );
Expand Down
18 changes: 9 additions & 9 deletions src/RBFMeshMotionSolver/AdaptiveCoarsening.H
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ namespace rbf

void compute(
std::shared_ptr<RBFFunctionInterface> rbfFunction,
std::unique_ptr<El::DistMatrix<double> > positions,
std::unique_ptr<El::DistMatrix<double> > positionsInterpolation
std::unique_ptr<ElDistVector> positions,
std::unique_ptr<ElDistVector> positionsInterpolation
);

void greedySelection( const std::unique_ptr<El::DistMatrix<double> > & values );
void greedySelection( const std::unique_ptr<ElDistVector> & values );

bool initialized();

std::unique_ptr<El::DistMatrix<double> > interpolate( const std::unique_ptr<El::DistMatrix<double> > & values );
std::unique_ptr<ElDistVector> interpolate( const std::unique_ptr<ElDistVector> & values );

private:
std::pair<int, double> computeError( const std::unique_ptr<El::DistMatrix<double> > & values );
std::pair<int, double> computeError( const std::unique_ptr<ElDistVector> & values );

void selectData(
const std::unique_ptr<El::DistMatrix<double> > & data,
std::unique_ptr<El::DistMatrix<double> > & selection
const std::unique_ptr<ElDistVector> & data,
std::unique_ptr<ElDistVector> & selection
);

const double tol;
Expand All @@ -51,7 +51,7 @@ namespace rbf
std::vector<size_t> selectedPositions;

std::shared_ptr<RBFFunctionInterface> rbfFunction;
std::unique_ptr<El::DistMatrix<double> > positions;
std::unique_ptr<El::DistMatrix<double> > positionsInterpolation;
std::unique_ptr<ElDistVector> positions;
std::unique_ptr<ElDistVector> positionsInterpolation;
};
}
6 changes: 3 additions & 3 deletions src/RBFMeshMotionSolver/Coarsener.H
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ namespace rbf

virtual void compute(
std::shared_ptr<RBFFunctionInterface> rbfFunction,
std::unique_ptr<El::DistMatrix<double> > positions,
std::unique_ptr<El::DistMatrix<double> > positionsInterpolation
std::unique_ptr<ElDistVector> positions,
std::unique_ptr<ElDistVector> positionsInterpolation
) = 0;

virtual bool initialized() = 0;

virtual std::unique_ptr<El::DistMatrix<double> > interpolate( const std::unique_ptr<El::DistMatrix<double> > & values ) = 0;
virtual std::unique_ptr<ElDistVector> interpolate( const std::unique_ptr<ElDistVector> & values ) = 0;
};
}
12 changes: 6 additions & 6 deletions src/RBFMeshMotionSolver/ElRBFInterpolation.C
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace rbf

ElRBFInterpolation::ElRBFInterpolation(
std::shared_ptr<RBFFunctionInterface> rbfFunction,
std::unique_ptr<El::DistMatrix<double> > positions,
std::unique_ptr<El::DistMatrix<double> > positionsInterpolation
std::unique_ptr<ElDistVector> positions,
std::unique_ptr<ElDistVector> positionsInterpolation
)
:
H( new El::DistMatrix<double>() ),
Expand All @@ -32,8 +32,8 @@ namespace rbf

void ElRBFInterpolation::compute(
std::shared_ptr<RBFFunctionInterface> rbfFunction,
std::unique_ptr<El::DistMatrix<double> > positions,
std::unique_ptr<El::DistMatrix<double> > positionsInterpolation
std::unique_ptr<ElDistVector> positions,
std::unique_ptr<ElDistVector> positionsInterpolation
)
{
assert( Phi->Height() == 0 );
Expand Down Expand Up @@ -139,13 +139,13 @@ namespace rbf
return Phi->Height() > 0;
}

std::unique_ptr<El::DistMatrix<double> > ElRBFInterpolation::interpolate( const std::unique_ptr<El::DistMatrix<double> > & values )
std::unique_ptr<ElDistVector> ElRBFInterpolation::interpolate( const std::unique_ptr<ElDistVector> & values )
{
assert( Phi->Height() > 0 );
assert( H->Height() > 0 );
assert( values->Height() == Phi->Width() );

std::unique_ptr<El::DistMatrix<double> > result( new El::DistMatrix<double>() );
std::unique_ptr<ElDistVector> result( new ElDistVector() );

values->ProcessQueues();

Expand Down
12 changes: 7 additions & 5 deletions src/RBFMeshMotionSolver/ElRBFInterpolation.H
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,30 @@

namespace rbf
{
typedef El::DistMatrix<double, El::VR, El::STAR> ElDistVector;

class ElRBFInterpolation
{
public:
explicit ElRBFInterpolation();

explicit ElRBFInterpolation(
std::shared_ptr<RBFFunctionInterface> rbfFunction,
std::unique_ptr<El::DistMatrix<double> > positions,
std::unique_ptr<El::DistMatrix<double> > positionsInterpolation
std::unique_ptr<ElDistVector> positions,
std::unique_ptr<ElDistVector> positionsInterpolation
);

~ElRBFInterpolation();

void compute(
std::shared_ptr<RBFFunctionInterface> rbfFunction,
std::unique_ptr<El::DistMatrix<double> > positions,
std::unique_ptr<El::DistMatrix<double> > positionsInterpolation
std::unique_ptr<ElDistVector> positions,
std::unique_ptr<ElDistVector> positionsInterpolation
);

bool initialized();

std::unique_ptr<El::DistMatrix<double> > interpolate( const std::unique_ptr<El::DistMatrix<double> > & values );
std::unique_ptr<ElDistVector> interpolate( const std::unique_ptr<ElDistVector> & values );

private:
std::unique_ptr<El::DistMatrix<double> > H;
Expand Down
8 changes: 4 additions & 4 deletions src/RBFMeshMotionSolver/ElRBFMeshMotionSolver.C
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ void ElRBFMeshMotionSolver::solve()

boundaryData.resize( std::distance( boundaryData.begin(), it ) );

std::unique_ptr<El::DistMatrix<double> > positions( new El::DistMatrix<double>() );
std::unique_ptr<El::DistMatrix<double> > positionsInterpolation( new El::DistMatrix<double> () );
std::unique_ptr<rbf::ElDistVector> positions( new rbf::ElDistVector() );
std::unique_ptr<rbf::ElDistVector> positionsInterpolation( new rbf::ElDistVector() );

std::vector<size_t> allBoundaryPoints = mxx::allgather( boundaryData.size() );
size_t totalNbBoundaryPoints = 0;
Expand Down Expand Up @@ -442,7 +442,7 @@ void ElRBFMeshMotionSolver::solve()
for ( size_t n : allBoundaryPoints )
totalNbBoundaryPoints += n;

std::unique_ptr<El::DistMatrix<double> > data( new El::DistMatrix<double>() );
std::unique_ptr<rbf::ElDistVector> data( new rbf::ElDistVector() );
El::Zeros( *data, totalNbBoundaryPoints, mesh().nGeometricD() );

data->Reserve( boundaryPoints.size() * mesh().nGeometricD() );
Expand All @@ -467,7 +467,7 @@ void ElRBFMeshMotionSolver::solve()
}
}

std::unique_ptr<El::DistMatrix<double> > result = rbf->interpolate( data );
std::unique_ptr<rbf::ElDistVector> result = rbf->interpolate( data );

vectorField valuesInterpolationField( mesh().points().size(), Foam::vector::zero );

Expand Down
6 changes: 3 additions & 3 deletions src/RBFMeshMotionSolver/NoCoarsening.C
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace rbf

void NoCoarsening::compute(
std::shared_ptr<RBFFunctionInterface> rbfFunction,
std::unique_ptr<El::DistMatrix<double> > positions,
std::unique_ptr<El::DistMatrix<double> > positionsInterpolation
std::unique_ptr<ElDistVector> positions,
std::unique_ptr<ElDistVector> positionsInterpolation
)
{
rbf->compute( rbfFunction, std::move( positions ), std::move( positionsInterpolation ) );
Expand All @@ -29,7 +29,7 @@ namespace rbf
return rbf->initialized();
}

std::unique_ptr<El::DistMatrix<double> > NoCoarsening::interpolate( const std::unique_ptr<El::DistMatrix<double> > & values )
std::unique_ptr<ElDistVector> NoCoarsening::interpolate( const std::unique_ptr<ElDistVector> & values )
{
return rbf->interpolate( values );
}
Expand Down
6 changes: 3 additions & 3 deletions src/RBFMeshMotionSolver/NoCoarsening.H
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ namespace rbf

void compute(
std::shared_ptr<RBFFunctionInterface> rbfFunction,
std::unique_ptr<El::DistMatrix<double> > positions,
std::unique_ptr<El::DistMatrix<double> > positionsInterpolation
std::unique_ptr<ElDistVector> positions,
std::unique_ptr<ElDistVector> positionsInterpolation
);

bool initialized();

std::unique_ptr<El::DistMatrix<double> > interpolate( const std::unique_ptr<El::DistMatrix<double> > & values );
std::unique_ptr<ElDistVector> interpolate( const std::unique_ptr<ElDistVector> & values );

private:
std::unique_ptr<ElRBFInterpolation> rbf;
Expand Down
Loading

0 comments on commit c4dedb8

Please sign in to comment.