trixi-framework / PointNeighbors.jl

PointNeighbors.jl: Neighborhood search with fixed search radius in Julia
https://trixi-framework.github.io/PointNeighbors.jl/
MIT License
10 stars 1 forks source link

Figure out how to pass neighborhood search to a TrixiParticles.jl simulation #27

Open efaulhaber opened 4 weeks ago

efaulhaber commented 4 weeks ago

Currently, we only pass the type of the neighborhood search, e.g.:

semi = Semidiscretization(system1, system2, neighborhood_search=GridNeighborhoodSearch)

This comes with two major problems:

  1. To use a new neighborhood search in TrixiParticles.jl, one has to add a function create_neighborhood_search for this type, which calls the constructor of the neighborhood search and initializes it.
  2. Options for the neighborhood search can't be passed. Currently, we only have the threaded_update kwarg, which can be passed to Semidiscretization and is then passed through create_neighborhood_search to the constructor of the NHS. This doesn't work with multiple neighborhood search implementations with different kwargs.

We can't just call the constructor and pass a neighborhood search object because we need multiple objects (one for each pair of physics systems). My best idea so far is the following:

  1. Create and pass to the Semidiscretization an empty neighborhood search, setting all options in the constructor.
  2. Then, in PointNeighbors.jl, add a function copy_neighborhood_search, which takes a neighborhood search, a number of particles, and a search radius, and then creates a neighborhood search with the same type and options and the new size and search radius.
  3. In the NHS constructors, the number of particles is set to zero by default for convenience and the search radius to nothing or so. The resulting neighborhood search can't be actually used without a search radius, so it's only to be used with copy_neighborhood_search.

The line above would then become

semi = Semidiscretization(system1, system2, neighborhood_search=GridNeighborhoodSearch())

and setting options is easy and modular:

semi = Semidiscretization(system1, system2, neighborhood_search=GridNeighborhoodSearch(threaded_update=false))

For each pair of physics systems, TrixiParticles.jl would then call:

nhs = copy_neighborhood_search(dummy_nhs, search_radius, n_particles)

Does anyone have any other ideas? @LasNikas @svchb @sloede

LasNikas commented 3 weeks ago

I'm fine with this approach. I can't see any drawbacks.