]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix set particle positions. 9890/head
authorLuca Heltai <luca.heltai@sissa.it>
Tue, 14 Apr 2020 22:53:53 +0000 (00:53 +0200)
committerLuca Heltai <luca.heltai@sissa.it>
Wed, 15 Apr 2020 08:38:58 +0000 (10:38 +0200)
include/deal.II/particles/particle_handler.h
tests/particles/set_particle_positions_03.cc [new file with mode: 0644]
tests/particles/set_particle_positions_03.with_p4est=true.mpirun=1.output [new file with mode: 0644]

index fa9822991c0370f67a6342e530993c76c16912d6..24404e0cd2b7b14588aaf777cc7adfb539c2c6d9 100644 (file)
@@ -334,7 +334,8 @@ namespace Particles
      * @authors Luca Heltai, Bruno Blais, 2019.
      */
     template <class VectorType>
-    void
+    typename boost::disable_if<
+      std::is_convertible<VectorType *, Function<spacedim> *>>::type
     set_particle_positions(const VectorType &input_vector,
                            const bool        displace_particles = true);
 
@@ -794,7 +795,8 @@ namespace Particles
 
   template <int dim, int spacedim>
   template <class VectorType>
-  void
+  typename boost::disable_if<
+    std::is_convertible<VectorType *, Function<spacedim> *>>::type
   ParticleHandler<dim, spacedim>::set_particle_positions(
     const VectorType &input_vector,
     const bool        displace_particles)
diff --git a/tests/particles/set_particle_positions_03.cc b/tests/particles/set_particle_positions_03.cc
new file mode 100644 (file)
index 0000000..4be1659
--- /dev/null
@@ -0,0 +1,120 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2017 - 2019 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.
+//
+// ---------------------------------------------------------------------
+
+// Test insert_global_particles and set_particles_positions using a
+// Function<spacedim>
+
+#include <deal.II/base/mpi.h>
+#include <deal.II/base/utilities.h>
+
+#include <deal.II/distributed/tria.h>
+
+#include <deal.II/fe/mapping_q.h>
+
+#include <deal.II/grid/filtered_iterator.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_tools.h>
+
+#include <deal.II/particles/particle_handler.h>
+
+#include "../tests.h"
+
+template <int spacedim>
+class Positions : public Function<spacedim>
+{
+public:
+  Positions(unsigned int n_components)
+    : Function<spacedim>(n_components)
+  {}
+
+  virtual double
+  value(const Point<spacedim> &p, unsigned int component = 0) const
+  {
+    if (component == 0)
+      return p[component] + 0.2;
+    else
+      return p[component];
+  }
+
+private:
+};
+
+template <int dim, int spacedim>
+void
+test()
+{
+  parallel::distributed::Triangulation<dim, spacedim> tr(MPI_COMM_WORLD);
+
+  GridGenerator::hyper_cube(tr);
+  tr.refine_global(2);
+
+  MappingQ<dim, spacedim> mapping(1);
+
+  Particles::ParticleHandler<dim, spacedim> particle_handler(tr, mapping);
+
+  const unsigned int n_points = 2;
+  const unsigned int my_cpu = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
+  const unsigned int n_cpus = Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD);
+  Testing::srand(my_cpu + 1);
+
+  // Create the bounding boxes for the global insertion
+  auto my_bounding_box = GridTools::compute_mesh_predicate_bounding_box(
+    tr, IteratorFilters::LocallyOwnedCell());
+
+  auto global_bounding_boxes =
+    Utilities::MPI::all_gather(MPI_COMM_WORLD, my_bounding_box);
+
+  std::vector<Point<spacedim>> points(n_points);
+  for (auto &p : points)
+    p = random_point<spacedim>(0.1, 0.2);
+
+  auto cpu_to_index =
+    particle_handler.insert_global_particles(points, global_bounding_boxes);
+
+  for (const auto &particle : particle_handler)
+    {
+      deallog << "Particle id : " << particle.get_id();
+      deallog << " Particle location: " << particle.get_location() << std::endl;
+    }
+
+  Positions<spacedim> new_positions(spacedim);
+
+  particle_handler.set_particle_positions(new_positions, false);
+
+  deallog << "Displacement" << std::endl;
+  for (const auto &particle : particle_handler)
+    {
+      deallog << "Particle id : " << particle.get_id();
+      deallog << " Particle location: " << particle.get_location() << std::endl;
+    }
+}
+
+
+
+int
+main(int argc, char *argv[])
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+
+  MPILogInitAll all;
+
+  deallog.push("2d/2d");
+  test<2, 2>();
+  deallog.pop();
+  deallog << "---" << std::endl;
+  deallog.push("3d/3d");
+  test<3, 3>();
+  deallog.pop();
+}
diff --git a/tests/particles/set_particle_positions_03.with_p4est=true.mpirun=1.output b/tests/particles/set_particle_positions_03.with_p4est=true.mpirun=1.output
new file mode 100644 (file)
index 0000000..1555384
--- /dev/null
@@ -0,0 +1,12 @@
+
+DEAL:0:2d/2d::Particle id : 0 Particle location: 0.184019 0.139438
+DEAL:0:2d/2d::Particle id : 1 Particle location: 0.178310 0.179844
+DEAL:0:2d/2d::Displacement
+DEAL:0:2d/2d::Particle id : 0 Particle location: 0.384019 0.139438
+DEAL:0:2d/2d::Particle id : 1 Particle location: 0.378310 0.179844
+DEAL:0::---
+DEAL:0:3d/3d::Particle id : 0 Particle location: 0.184019 0.139438 0.178310
+DEAL:0:3d/3d::Particle id : 1 Particle location: 0.179844 0.191165 0.119755
+DEAL:0:3d/3d::Displacement
+DEAL:0:3d/3d::Particle id : 0 Particle location: 0.384019 0.139438 0.178310
+DEAL:0:3d/3d::Particle id : 1 Particle location: 0.379844 0.191165 0.119755

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.