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
Bilinear Least Squares Particle Interpolation Scheme #1554
Conversation
/run-tests |
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? |
b4a7054
to
c9943cb
Compare
There was a problem hiding this 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); |
There was a problem hiding this comment.
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>()) |
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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] + |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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. ") |
There was a problem hiding this comment.
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
118bca2
to
576bea0
Compare
It doesn't currently compile :-( The error message is this:
|
3280953
to
6bea2d6
Compare
*/ | ||
A.Tmmult(B, A, false); | ||
A.Tvmult(c_ATr,r); | ||
B_inverse.compute_svd(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.") |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); | ||
|
||
/** |
There was a problem hiding this comment.
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.
PR is ready to be reviewed. I have resolved all code review comments thus far. |
There was a problem hiding this 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] + |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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());
Can you squash it all into one commit? |
ce8e74c
to
36586c0
Compare
@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.