Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bilinear Least Squares Particle Interpolation Scheme #1554

Conversation

hlokavarapu
Copy link
Contributor

@gassmoeller, New bilinear particle interpolation scheme contributed by @yinghe616 , @egpuckett . We plan to incrementally update this scheme in the near future introducing limiters to prevent overshoot and undershoot as well as implement the case for 3D models.

@hlokavarapu hlokavarapu changed the title Particle interpolation scheme bilinear Bilinear Particle Interpolation Scheme May 10, 2017
@hlokavarapu hlokavarapu changed the title Bilinear Particle Interpolation Scheme Bilinear Least Squares Particle Interpolation Scheme May 10, 2017
@gassmoeller
Copy link
Member

/run-tests

@gassmoeller
Copy link
Member

Just to make sure I understood you correctly: You want to get a review and merge this PR, and later update the scheme? Or is this a work in progress PR?

@hlokavarapu hlokavarapu force-pushed the particle_interpolation_scheme_bilinear branch 2 times, most recently from b4a7054 to c9943cb Compare May 10, 2017 12:59
Copy link
Member

@gassmoeller gassmoeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! I have a few comments about functionality and style, but I am looking forward to merging this! I suppose you have tested the accuracy and convergence in your paper? Maybe at some point we can add a benchmark to ASPECT as a follow-up PR, but for now the test is sufficient.

A(index,0) = 1;
A(index,1) = (position[0] - approximated_cell_midpoint[0])/cell_diameter;
A(index,2) = (position[1] - approximated_cell_midpoint[1])/cell_diameter;
A(index,3) = (position[0] - approximated_cell_midpoint[0]) * (position[1] - approximated_cell_midpoint[1])/std::pow(cell_diameter,2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will not work, because approximated_cell_midpoint is only set if the cell iterator is empty.

ExcMessage("The particle property interpolator was not given any "
"positions to evaluate the particle cell_properties at."));

approximated_cell_midpoint = std::accumulate (positions.begin(), positions.end(), Point<dim>())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment below. This will need to be moved outside of the if-loop. You might as well make it const in that case:

const Point<dim> approximated_cell_midpoint = std:: ... 


unsigned int property_index = 0;
for (unsigned int i=0; i < n_particle_properties; i++)
if (selected_properties[i])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this interpolator only works if only one property is selected in the component_mask? Please check that this is the case at the beginning of the function, currently you silently only compute the last selected component.

r = 0;

unsigned int index = 0;
double cell_diameter = found_cell->diameter();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

A.Tmmult(B, A, false);
A.Tvmult(c_ATr,r);
B_inverse.compute_svd();
B_inverse.compute_inverse_svd(threshold);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need both of the calls above? I am not expert in Least squares, and even less in SVD, so please check both calls are necessary and add a comment that explains what is happening in these four lines.


for (typename std::vector<Point<dim> >::const_iterator itr = positions.begin(); itr != positions.end(); ++itr, ++index_positions)
{
Point<dim> support_point = *itr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

for (typename std::vector<Point<dim> >::const_iterator itr = positions.begin(); itr != positions.end(); ++itr, ++index_positions)
{
Point<dim> support_point = *itr;
double interpolated_value = c[0] +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

namespace Interpolator
{
ASPECT_REGISTER_PARTICLE_INTERPOLATOR(BilinearLeastSquares,
"bilinear",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind changing the input file name to "bilinear least squares"? Somebody might have the idea to add a "bilinear nearest neighbor" or something similar later on.

"Interpolates particle properties onto a vector of points using a "
"bilinear least squares method. Currently only 2D models are "
"supported. Note that because no limiter is utilized this may "
"result in overshoot and/or undershoot of interpolated property. ")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the last space in the last line

@hlokavarapu hlokavarapu force-pushed the particle_interpolation_scheme_bilinear branch from 118bca2 to 576bea0 Compare May 11, 2017 01:04
@bangerth
Copy link
Contributor

It doesn't currently compile :-(

The error message is this:

/home/dealii/source/source/particle/interpolator/bilinear_least_squares.cc: In instantiation of ‘std::vector<std::vector<double> > aspect::Particle::Interpolator::BilinearLeastSquares<dim>::properties_at_points(const std::multimap<std::pair<int, int>, aspect::Particle::Particle<dim> >&, const std::vector<dealii::Point<dim> >&, const dealii::ComponentMask&, const typename dealii::parallel::distributed::Triangulation<dim>::active_cell_iterator&) const [with int dim = 2; typename dealii::parallel::distributed::Triangulation<dim>::active_cell_iterator = dealii::TriaActiveIterator<dealii::CellAccessor<2, 2> >]’:
/home/dealii/source/source/particle/interpolator/bilinear_least_squares.cc:151:7:   required from here
/home/dealii/source/source/particle/interpolator/bilinear_least_squares.cc:45:21: error: no matching function for call to ‘dealii::StandardExceptions::ExcMessage::ExcMessage()’
                     ExcMessage());
                     ^~~~~~~~~~~~

@hlokavarapu hlokavarapu force-pushed the particle_interpolation_scheme_bilinear branch 4 times, most recently from 3280953 to 6bea2d6 Compare May 13, 2017 00:41
*/
A.Tmmult(B, A, false);
A.Tvmult(c_ATr,r);
B_inverse.compute_svd();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove this line? compute_inverse_svd will call it automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, removed the line.

"Interpolates particle properties onto a vector of points using a "
"bilinear least squares method. Currently only 2D models are "
"supported. Note that because no limiter is utilized this may "
"result in overshoot and/or undershoot of interpolated property.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a note that this feature requires deal.II configured with blas/lapack?

@@ -0,0 +1,117 @@
# A description of the SolKZ benchmark using active particles
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update the description here.

* which usually is not a square matrix. Therefore, we solve Ax=r by
* solving A^TAx= A^Tr.
*/
A = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is A initialized to 0 automatically? If yes, remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A is initialized to 0. I checked that this was true by printing out the matrix to std::cout

dealii::LAPACKFullMatrix<double> A(n_particles, matrix_dimension);
Vector<double> r(n_particles);

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we usually use // comments inside functions; but even in cases where one may want to use /* ... */, we never use /** -- these are reserved for doxygen comments that document functions and classes (typically in .h files), not regular commentary.

@hlokavarapu
Copy link
Contributor Author

PR is ready to be reviewed. I have resolved all code review comments thus far.

Copy link
Member

@gassmoeller gassmoeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 comments, after that this is ready

{
const Point<dim> support_point = *itr;
// TODO: Removed const
double interpolated_value = c[0] +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix the TODO in the line above

{
const unsigned int n_particle_properties = particles.begin()->second.get_properties().size();

unsigned int property_index = selected_properties.first_selected_component(selected_properties.size());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be const.
Also does this mean the algorithm only works for one selected component? If so please make sure that is the case by inserting the following line (and check that it compiles):

AssertThrow(selected_properties.n_selected_components(n_particle_properties),ExcNotImplemented());

@bangerth
Copy link
Contributor

Can you squash it all into one commit?

@hlokavarapu hlokavarapu force-pushed the particle_interpolation_scheme_bilinear branch from ce8e74c to 36586c0 Compare May 14, 2017 01:14
@gassmoeller gassmoeller merged commit 22db212 into geodynamics:master May 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants