void Triangulation<dim, spacedim>::save(const std::string &filename) const
{
#ifdef DEAL_II_WITH_MPI
- //AssertThrow(this->cell_attached_data.pack_callbacks_variable.size() == 0,
+ // AssertThrow(this->cell_attached_data.pack_callbacks_variable.size() ==
+ // 0,
// ExcNotImplemented());
Assert(
template <int dim, int spacedim>
ParticleHandler<dim, spacedim>::ParticleHandler(
const Triangulation<dim, spacedim> &triangulation,
- const Mapping<dim, spacedim> &mapping,
+ const Mapping<dim, spacedim> & mapping,
const unsigned int n_properties)
: triangulation(&triangulation, typeid(*this).name())
, mapping(&mapping, typeid(*this).name())
void
ParticleHandler<dim, spacedim>::initialize(
const Triangulation<dim, spacedim> &new_triangulation,
- const Mapping<dim, spacedim> &new_mapping,
+ const Mapping<dim, spacedim> & new_mapping,
const unsigned int n_properties)
{
clear();
template <int dim, int spacedim>
typename ParticleHandler<dim, spacedim>::particle_iterator
ParticleHandler<dim, spacedim>::insert_particle(
- const Particle<dim, spacedim> &particle,
+ const Particle<dim, spacedim> & particle,
const typename Triangulation<dim, spacedim>::active_cell_iterator &cell)
{
return insert_particle(particle.get_location(),
template <int dim, int spacedim>
typename ParticleHandler<dim, spacedim>::particle_iterator
ParticleHandler<dim, spacedim>::insert_particle(
- const void *&data,
+ const void *& data,
const typename Triangulation<dim, spacedim>::active_cell_iterator &cell)
{
Assert(triangulation != nullptr, ExcInternalError());
template <int dim, int spacedim>
typename ParticleHandler<dim, spacedim>::particle_iterator
ParticleHandler<dim, spacedim>::insert_particle(
- const Point<spacedim> &position,
- const Point<dim> &reference_position,
+ const Point<spacedim> & position,
+ const Point<dim> & reference_position,
const types::particle_index particle_index,
const typename Triangulation<dim, spacedim>::active_cell_iterator &cell,
const ArrayView<const double> &properties)
ParticleHandler<dim, spacedim>::insert_global_particles(
const std::vector<Point<spacedim>> &positions,
const std::vector<std::vector<BoundingBox<spacedim>>>
- &global_bounding_boxes,
- const std::vector<std::vector<double>> &properties,
+ & global_bounding_boxes,
+ const std::vector<std::vector<double>> & properties,
const std::vector<types::particle_index> &ids)
{
if (!properties.empty())
compare_particle_association(
const unsigned int a,
const unsigned int b,
- const Tensor<1, dim> &particle_direction,
+ const Tensor<1, dim> & particle_direction,
const std::vector<Tensor<1, dim>> ¢er_directions)
{
const double scalar_product_a = center_directions[a] * particle_direction;
const std::map<
types::subdomain_id,
std::vector<typename Triangulation<dim, spacedim>::active_cell_iterator>>
- &send_cells,
+ & send_cells,
const bool build_cache)
{
Assert(triangulation != nullptr, ExcInternalError());
template <int dim, int spacedim>
void
ParticleHandler<dim, spacedim>::register_additional_store_load_functions(
- const std::function<std::size_t()> &size_callb,
+ const std::function<std::size_t()> & size_callb,
const std::function<void *(const particle_iterator &, void *)> &store_callb,
const std::function<const void *(const particle_iterator &, const void *)>
&load_callb)
const auto callback_function =
[this](
const typename Triangulation<dim, spacedim>::cell_iterator
- &cell_iterator,
+ & cell_iterator,
const typename Triangulation<dim, spacedim>::CellStatus cell_status) {
return this->pack_callback(cell_iterator, cell_status);
};
handle = distributed_triangulation->register_data_attach(
callback_function, /*returns_variable_size_data=*/true);
-
}
// First prepare container for insertion
clear();
-//#ifdef DEAL_II_WITH_P4EST
+ //#ifdef DEAL_II_WITH_P4EST
// If we are resuming from a checkpoint, we first have to register the
// store function again, to set the triangulation to the same state as
// before the serialization. Only afterwards we know how to deserialize the
handle = numbers::invalid_unsigned_int;
update_cached_numbers();
}
-//#else
-// (void)serialization;
-//#endif
+ //#else
+ // (void)serialization;
+ //#endif
}
template <int dim, int spacedim>
void
ParticleHandler<dim, spacedim>::unpack_callback(
- const typename Triangulation<dim, spacedim>::cell_iterator &cell,
+ const typename Triangulation<dim, spacedim>::cell_iterator & cell,
const typename Triangulation<dim, spacedim>::CellStatus status,
const boost::iterator_range<std::vector<char>::const_iterator> &data_range)
{
void
create_regular_particle_distribution(
Particles::ParticleHandler<dim, spacedim> &particle_handler,
- const Triangulation<dim, spacedim> &tr,
+ const Triangulation<dim, spacedim> & tr,
const unsigned int particles_per_direction = 3)
{
for (unsigned int i = 0; i < particles_per_direction; ++i)
#include "serialization.h"
-template <int dim, int spacedim>
-void
-create_regular_particle_distribution(
- Particles::ParticleHandler<dim, spacedim> &particle_handler,
- const parallel::fullydistributed::Triangulation<dim, spacedim> &tr,
- const unsigned int particles_per_direction = 3)
-{
- for (unsigned int i = 0; i < particles_per_direction; ++i)
- for (unsigned int j = 0; j < particles_per_direction; ++j)
- {
- Point<spacedim> position;
- Point<dim> reference_position;
- unsigned int id = i * particles_per_direction + j;
-
- position[0] = static_cast<double>(i) /
- static_cast<double>(particles_per_direction - 1);
- position[1] = static_cast<double>(j) /
- static_cast<double>(particles_per_direction - 1);
-
- if (dim > 2)
- for (unsigned int k = 0; k < particles_per_direction; ++k)
- {
- position[2] = static_cast<double>(j) /
- static_cast<double>(particles_per_direction - 1);
- id = i * particles_per_direction * particles_per_direction +
- j * particles_per_direction + k;
- Particles::Particle<dim, spacedim> particle(position,
- reference_position,
- id);
-
- typename parallel::fullydistributed::
- Triangulation<dim, spacedim>::active_cell_iterator cell =
- GridTools::find_active_cell_around_point(
- tr, particle.get_location());
-
- particle_handler.insert_particle(particle, cell);
- }
- else
- {
- Particles::Particle<dim, spacedim> particle(position,
- reference_position,
- id);
-
- typename parallel::fullydistributed::Triangulation<dim, spacedim>::
- active_cell_iterator cell =
- GridTools::find_active_cell_around_point(
- tr, particle.get_location());
-
- particle_handler.insert_particle(particle, cell);
- }
- }
-}
-
-
-
template <int dim, int spacedim>
void
test()
{
+ // Generate fulllydistributed triangulation from serial triangulation
Triangulation<dim, spacedim> basetria;
GridGenerator::hyper_cube(basetria);
basetria.refine_global(2);
MappingQ<dim, spacedim> mapping(1);
+ // Create ParticleHandler and insert two particles
Particles::ParticleHandler<dim, spacedim> particle_handler(tr, mapping);
- std::vector<Point<spacedim>> position(2);
- std::vector<Point<dim>> reference_position(2);
-
- for (unsigned int i = 0; i < dim; ++i)
- {
- position[0](i) = 0.125;
- position[1](i) = 0.525;
- }
-
- Particles::Particle<dim, spacedim> particle1(position[0],
- reference_position[0],
- 0);
- Particles::Particle<dim, spacedim> particle2(position[1],
- reference_position[1],
- 1);
-
- typename Triangulation<dim, spacedim>::active_cell_iterator cell1(&tr,
- 2,
- 0);
- typename Triangulation<dim, spacedim>::active_cell_iterator cell2(&tr,
- 2,
- 0);
+ std::vector<Point<spacedim>> position(2);
+ std::vector<Point<dim>> reference_position(2);
+
+ for (unsigned int i = 0; i < dim; ++i)
+ {
+ position[0](i) = 0.125;
+ position[1](i) = 0.525;
+ }
+
+ Particles::Particle<dim, spacedim> particle1(position[0],
+ reference_position[0],
+ 0);
+ Particles::Particle<dim, spacedim> particle2(position[1],
+ reference_position[1],
+ 1);
+
+ typename Triangulation<dim, spacedim>::active_cell_iterator cell1(&tr, 2, 0);
+ typename Triangulation<dim, spacedim>::active_cell_iterator cell2(&tr, 2, 0);
particle_handler.insert_particle(particle1, cell1);
particle_handler.insert_particle(particle2, cell2);
- //create_regular_particle_distribution(particle_handler, tr);
particle_handler.sort_particles_into_subdomains_and_cells();
for (auto particle = particle_handler.begin();
particle_handler.prepare_for_serialization();
- // save data to archive
- std::ofstream oss("data.particles");
+ // save additional particle data to archive
+ std::ostringstream oss;
{
boost::archive::text_oarchive oa(oss, boost::archive::no_header);
// archive and stream closed when
// destructors are called
}
- oss.close();
- //deallog << oss.str() << std::endl;
+ deallog << oss.str() << std::endl;
// Now remove all information in tr and particle_handler,
// this is like creating new objects after a restart
tr.clear();
- //GridGenerator::hyper_cube(tr);
particle_handler.clear();
particle_handler.initialize(tr, mapping);
deallog << "In between particle id " << particle->get_id() << " is in cell "
<< particle->get_surrounding_cell(tr) << std::endl;
- // verify correctness of the serialization. Note that the deserialization of
- // the particle handler has to happen before the triangulation (otherwise it
+ // verify correctness of the serialization. Note that the boost
+ // archive of the ParticleHandler has to be read before the triangulation (otherwise it
// does not know if something was stored in the user data of the
// triangulation).
{
- std::ifstream iss("data.particles");
+ std::istringstream iss(oss.str());
boost::archive::text_iarchive ia(iss, boost::archive::no_header);
ia >> particle_handler;
particle_handler.deserialize();
}
- deallog << "After deserialization global number of particles is: " << particle_handler.n_global_particles() << std::endl;
+ deallog << "After deserialization global number of particles is: "
+ << particle_handler.n_global_particles() << std::endl;
for (auto particle = particle_handler.begin();
particle != particle_handler.end();
++particle)
DEAL:0:2d/2d::Before serialization particle id 0 is in cell 2.0
DEAL:0:2d/2d::Before serialization particle id 1 is in cell 2.12
+DEAL:0:2d/2d::0 0 2 1 2
+
DEAL:0:2d/2d::After deserialization global number of particles is: 2
DEAL:0:2d/2d::After serialization particle id 0 is in cell 2.0
DEAL:0:2d/2d::After serialization particle id 1 is in cell 2.12
DEAL:0:2d/2d::
DEAL:0:2d/3d::Before serialization particle id 0 is in cell 2.0
DEAL:0:2d/3d::Before serialization particle id 1 is in cell 2.12
+DEAL:0:2d/3d::0 0 2 1 2
+
DEAL:0:2d/3d::After deserialization global number of particles is: 2
DEAL:0:2d/3d::After serialization particle id 0 is in cell 2.0
DEAL:0:2d/3d::After serialization particle id 1 is in cell 2.12
DEAL:0:2d/3d::
DEAL:0:3d/3d::Before serialization particle id 0 is in cell 2.0
DEAL:0:3d/3d::Before serialization particle id 1 is in cell 2.56
+DEAL:0:3d/3d::0 0 2 1 2
+
DEAL:0:3d/3d::After deserialization global number of particles is: 2
DEAL:0:3d/3d::After serialization particle id 0 is in cell 2.0
DEAL:0:3d/3d::After serialization particle id 1 is in cell 2.56