get_location() const;
/**
- * Get the location of this particle.
+ * Get read- and write-access to the location of this particle.
+ * Note that changing the location does not check
+ * whether this is a valid location in the simulation domain.
+ *
+ * @note In parallel programs, the ParticleHandler class stores particles
+ * on both the locally owned cells, as well as on ghost cells. The
+ * particles on the latter are *copies* of particles owned on other
+ * processors, and should therefore be treated in the same way as
+ * ghost entries in
+ * @ref GlossGhostedVector "vectors with ghost elements"
+ * or
+ * @ref GlossGhostCell "ghost cells":
+ * In both cases, one should
+ * treat the ghost elements or cells as `const` objects that shouldn't
+ * be modified even if the objects allow for calls that modify
+ * properties. Rather, properties should only be modified on processors
+ * that actually *own* the particle.
*
* @return The location of this particle.
*/
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2014 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+
+// A copy of test particle_01.cc but using the get_location
+// function to retrieve a writable reference to the location.
+
+#include <deal.II/particles/particle.h>
+
+#include "../tests.h"
+
+
+template <int dim>
+void
+test()
+{
+ {
+ Particles::Particle<dim> particle;
+
+ Point<dim> position;
+ position[0] = 1.0;
+ particle.get_location() = position;
+
+ deallog << "Particle location: " << particle.get_location() << std::endl;
+ }
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int
+main()
+{
+ initlog();
+ test<2>();
+ test<3>();
+}
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2017 - 2021 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+
+// Like particle_iterator_01, but changes the location through the
+// particle iterator.
+
+#include <deal.II/base/array_view.h>
+
+#include <deal.II/fe/mapping_q.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria.h>
+
+#include <deal.II/particles/particle.h>
+#include <deal.II/particles/particle_handler.h>
+#include <deal.II/particles/particle_iterator.h>
+
+#include "../tests.h"
+
+
+template <int dim>
+void
+test()
+{
+ {
+ Triangulation<dim> tr;
+
+ GridGenerator::hyper_cube(tr);
+ MappingQ<dim> mapping(1);
+ const unsigned int n_properties_per_particle = 3;
+
+ Particles::ParticleHandler<dim> particle_handler(tr,
+ mapping,
+ n_properties_per_particle);
+
+ Point<dim> position;
+ position[0] = 0.3;
+
+ if (dim > 1)
+ position[1] = 0.5;
+
+ Point<dim> reference_position;
+ reference_position[0] = 0.2;
+
+ if (dim > 1)
+ reference_position[1] = 0.4;
+
+ const types::particle_index index(7);
+
+ std::vector<double> properties = {0.15, 0.45, 0.75};
+
+ Particles::Particle<dim> particle(position, reference_position, index);
+
+ // Insert two identical particles
+ Particles::ParticleIterator<dim> particle_it =
+ particle_handler.insert_particle(particle, tr.begin());
+ particle_it->set_properties(
+ ArrayView<double>(&properties[0], properties.size()));
+
+ particle_it = particle_handler.insert_particle(particle, tr.begin());
+ particle_it->set_properties(
+ ArrayView<double>(&properties[0], properties.size()));
+
+ // Modify the location of the second particle
+ particle_it->get_location()[0] = 0.05;
+
+ for (const auto &particle : particle_handler)
+ {
+ deallog << "Particle position: " << particle.get_location() << std::endl
+ << "Particle properties: "
+ << std::vector<double>(particle.get_properties().begin(),
+ particle.get_properties().end())
+ << std::endl;
+ }
+ }
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int
+main()
+{
+ initlog();
+ test<2>();
+}