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

Add distance weighted particle interpolator #5815

Merged

Conversation

gassmoeller
Copy link
Member

This is not ready for review.

@anne-glerum: This PR adds a new particle interpolator that interpolates between particles based on a distance weighted average (similar to what radial basis functions would do). The interpolator in its current form produces worse errors (though the same convergence rate) as the 'cell average' interpolator. However, it should be smoother and less affected by small particle movements across cell boundaries.

This PR is currently in a very rough state, I only open this to remind myself to finish it after the hackathon.

@gassmoeller gassmoeller force-pushed the distance_weighted_particle_average branch from c7a14d4 to 3f0815b Compare June 9, 2024 18:32
@gassmoeller gassmoeller changed the title [WIP] Add distance weighted particle interpolator Add distance weighted particle interpolator Jun 9, 2024
@gassmoeller gassmoeller force-pushed the distance_weighted_particle_average branch 2 times, most recently from d6eda59 to 792e91f Compare June 9, 2024 18:39
@gassmoeller
Copy link
Member Author

I cleaned up the PR and made sure I can run the particle benchmarks to show the method is converging. In terms of accuracy this interpolator has a similar convergence rate as 'cell average', but because the particle contribution is weighted by distance and particles of neighbor cells are considered as well, it should be less sensitive to particles crossing cell boundaries.

Ready for review.

Copy link
Member

@MFraters MFraters left a comment

Choose a reason for hiding this comment

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

Some small comments, otherwise looks good to me.

{
/**
* Return the interpolated properties of all particles of the given cell using bilinear least squares method.
* Currently, only the two dimensional model is supported.
Copy link
Member

Choose a reason for hiding this comment

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

You say it work in 3d, but here it is stated it only works in 2d. Can you update this?

Copy link
Member

Choose a reason for hiding this comment

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

should work in 2d and 3d?

const typename parallel::distributed::Triangulation<dim>::active_cell_iterator &cell) const override;

// avoid -Woverloaded-virtual:
using Interface<dim>::properties_at_points;
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 check if you still need this?

Copy link
Member

@tjhei tjhei left a comment

Choose a reason for hiding this comment

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

Looks good. I have a few questions to make sure I understand things correctly.

{
namespace internal
{
double weight (const double distance, const double cell_width)
Copy link
Member

Choose a reason for hiding this comment

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

cell_width is not really the width of the cell but the width/radius of the hat function, maybe we should rename the argument?

{
/**
* Return the interpolated properties of all particles of the given cell using bilinear least squares method.
* Currently, only the two dimensional model is supported.
Copy link
Member

Choose a reason for hiding this comment

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

should work in 2d and 3d?

vertex_to_cell_map[vertex_index].end());
}

const double interpolation_support = 0.5 * 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.

Do you make an assumption here that any particle that is less than this far away, will be found in the containing cell or its direct neighbors? Is that a safe assumption? This should probably be documented.

@gassmoeller gassmoeller force-pushed the distance_weighted_particle_average branch from b4d6fd7 to c353b18 Compare June 14, 2024 01:55
@gassmoeller
Copy link
Member Author

I think I have addressed all comments, but let me run some more benchmarks with this before merging.

@gassmoeller gassmoeller force-pushed the distance_weighted_particle_average branch from c353b18 to fd60a17 Compare June 14, 2024 01:59
@gassmoeller gassmoeller force-pushed the distance_weighted_particle_average branch from fd60a17 to 7694803 Compare June 14, 2024 18:43
@gassmoeller
Copy link
Member Author

gassmoeller commented Jun 14, 2024

Ok, I am done benchmarking. I think this is ready. In the benchmark rigid_shear/transient it reaches the same convergence order as cell average at better accuracy:
error_over_resolution_end

If anyone used cell average regularly before, I would now recommend using distance weighted average instead.

Edit: Except that distance weighted average is slow, even slower than bilinear least squares. This is likely just an issue with the implementation though, I can fix that in a follow up PR.

@naliboff
Copy link
Contributor

@gassmoeller - thanks for the work to add this feature!

I did a bit of testing related to #4370 and ran into an issue when doing an initial adaptive refinement step on the first time step.

The model runs without issue if set Initial adaptive refinement = 0

The log.txt and a prm that be can quickly run on one processor are attached. Let me know how I can help with additional testing!

test_weighted_particle_average_refinement.prm.txt
log.txt

@gassmoeller
Copy link
Member Author

@naliboff: Sorry about that I clearly didnt do enough testing for this interpolator, adaptive refinement was broken. I think I fixed it now and added a test. Could you give your model another try? I encountered another problem with your model that might be a bug in deal.II. If you crash still try changing the number of particles per direction to 6 (from 7). I will look into that more.

@naliboff
Copy link
Contributor

@gassmoeller - Thanks for the fix and the model runs successfully now with both adaptive refinement and either 6 or 7 initial particles per direction. Is there any other additional testing I can do in the short term? I'll look more carefully at the effect of the weighted average scheme on convergence on the complex models in the coming weeks.

Copy link
Member

@tjhei tjhei left a comment

Choose a reason for hiding this comment

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

Looks good to me. Anything else you want to do here, @gassmoeller ?

@gassmoeller
Copy link
Member Author

This is ready from my side. Just a quick note that at present this interpolator is quite slow (about twice as slow than the linear least squares interpolator, which does a much more complicated operation). Presumably this is because it has to create the std::set of neighbor cells for every cell. I have some ideas for how to speed this up, but it is not a terrible cost at the moment and the functionality should be fine as is, so I think we can merge this PR and address the performance in a follow up.

@tjhei tjhei merged commit 65adc5d into geodynamics:main Jun 27, 2024
8 checks passed
@gassmoeller gassmoeller deleted the distance_weighted_particle_average branch June 28, 2024 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants