/**
* Destructor.
*/
- virtual ~ParticleHandler() override = default;
+ virtual ~ParticleHandler() override
+ {
+ connection.disconnect();
+ }
/**
* Initialize the particle handler. This function does not clear the
void
serialize(Archive &ar, const unsigned int version);
+ /**
+ * Updates the structures that were generated to search in which cells the
+ * particles belong to. The call to this function updates the
+ * vertex_to_cells and the vertex_to_cell_centers data structure. This
+ * function is called every time the triangulation is altered.
+ *
+ */
+ void
+ update_triangulation_cache();
+
private:
/**
* Address of the triangulation to work on.
*/
unsigned int handle;
+ /**
+ * A connection to the corresponding any_changes signal of the Triangulation
+ * which is attached to the particle_handler
+ */
+ boost::signals2::connection connection;
+
+ /** This variable stores a set from vertices to adjacent cells. It is used
+ * to locate the cells in which the particle reside. This structured is kept
+ * in memory to prevent its recalculation every time we
+ * sort_into_subdomain_and_cells(). This structure is updated everytime
+ * we call update_triangulation_cache.
+ */
+ std::vector<
+ std::set<typename Triangulation<dim, spacedim>::active_cell_iterator>>
+ vertex_to_cells;
+
+
+ /** This variable stores a vector of vectors to cell centers. It is used
+ * to locate the cells in which the particle reside. This structured is kept
+ * in memory to prevent its recalculation every time we
+ * sort_into_subdomain_and_cells(). This structure is updated everytime
+ * we call update_triangulation_cache.
+ */
+ std::vector<std::vector<Tensor<1, spacedim>>> vertex_to_cell_centers;
+
#ifdef DEAL_II_WITH_MPI
/**
* Transfer particles that have crossed subdomain boundaries to other
, store_callback()
, load_callback()
, handle(numbers::invalid_unsigned_int)
- {}
+ {
+ // Update the triangulation cache to ensure that you can sort the particles
+ // correctly
+ update_triangulation_cache();
+
+ connection = triangulation.signals.any_change.connect(
+ std::bind(&ParticleHandler<dim, spacedim>::update_triangulation_cache,
+ std::ref(*this)));
+ }
// Create the memory pool that will store all particle properties
property_pool = std_cxx14::make_unique<PropertyPool>(n_properties);
+
+ // Update the triangulation cache to ensure that you can sort the particles
+ // correctly
+ update_triangulation_cache();
+
+ connection = triangulation->signals.any_change.connect(
+ std::bind(&ParticleHandler<dim, spacedim>::update_triangulation_cache,
+ std::ref(*this)));
}
static_cast<vector_size>(particles_out_of_cell.size() * 0.25));
{
- // Create a map from vertices to adjacent cells
- const std::vector<
- std::set<typename Triangulation<dim, spacedim>::active_cell_iterator>>
- vertex_to_cells(GridTools::vertex_to_cell_map(*triangulation));
-
- // Create a corresponding map of vectors from vertex to cell center
- const std::vector<std::vector<Tensor<1, spacedim>>>
- vertex_to_cell_centers(
- GridTools::vertex_to_cell_centers_directions(*triangulation,
- vertex_to_cells));
-
+ // update_triangulation_cache();
std::vector<unsigned int> neighbor_permutation;
// Find the cells that the particles moved to.
break;
}
}
+
+ template <int dim, int spacedim>
+ void
+ ParticleHandler<dim, spacedim>::update_triangulation_cache()
+ {
+ // Create a map from vertices to adjacent cells
+ vertex_to_cells = GridTools::vertex_to_cell_map(*triangulation);
+
+ // Create a corresponding map of vectors from vertex to cell center
+ vertex_to_cell_centers =
+ GridTools::vertex_to_cell_centers_directions(*triangulation,
+ vertex_to_cells);
+ }
+
+
} // namespace Particles
#include "particle_handler.inst"