]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add test 16675/head
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Tue, 20 Feb 2024 18:46:50 +0000 (13:46 -0500)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Tue, 20 Feb 2024 20:10:49 +0000 (15:10 -0500)
include/deal.II/particles/particle.h
tests/particles/particle_10.cc [new file with mode: 0644]
tests/particles/particle_10.output [new file with mode: 0644]
tests/particles/particle_iterator_03.cc [new file with mode: 0644]
tests/particles/particle_iterator_03.output [new file with mode: 0644]

index 1d60e894a4e6f56df39705b5e9f2a897710d2ffe..6a9f975a95454ee813f4e3a5ca1ecaf2dc442e2e 100644 (file)
@@ -251,7 +251,23 @@ namespace Particles
     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.
      */
diff --git a/tests/particles/particle_10.cc b/tests/particles/particle_10.cc
new file mode 100644 (file)
index 0000000..7f79da2
--- /dev/null
@@ -0,0 +1,51 @@
+// ---------------------------------------------------------------------
+//
+// 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>();
+}
diff --git a/tests/particles/particle_10.output b/tests/particles/particle_10.output
new file mode 100644 (file)
index 0000000..b466e15
--- /dev/null
@@ -0,0 +1,5 @@
+
+DEAL::Particle location: 1.00000 0.00000
+DEAL::OK
+DEAL::Particle location: 1.00000 0.00000 0.00000
+DEAL::OK
diff --git a/tests/particles/particle_iterator_03.cc b/tests/particles/particle_iterator_03.cc
new file mode 100644 (file)
index 0000000..d81ca4c
--- /dev/null
@@ -0,0 +1,101 @@
+// ---------------------------------------------------------------------
+//
+// 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>();
+}
diff --git a/tests/particles/particle_iterator_03.output b/tests/particles/particle_iterator_03.output
new file mode 100644 (file)
index 0000000..bf65839
--- /dev/null
@@ -0,0 +1,6 @@
+
+DEAL::Particle position: 0.300000 0.500000
+DEAL::Particle properties: 0.150000 0.450000 0.750000
+DEAL::Particle position: 0.0500000 0.500000
+DEAL::Particle properties: 0.150000 0.450000 0.750000
+DEAL::OK

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.