]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Ensure particle property initialization 7666/head
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Thu, 31 Jan 2019 18:24:06 +0000 (10:24 -0800)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Sat, 2 Feb 2019 00:12:02 +0000 (16:12 -0800)
source/particles/particle.cc
tests/particles/particle_07.cc [new file with mode: 0644]
tests/particles/particle_07.output [new file with mode: 0644]

index 03f90811b333584cb03f7ff17cf4d843bd551b27..b426aac4ccdb281715c8b95c624a7ba2d52d0ec8 100644 (file)
@@ -328,8 +328,16 @@ namespace Particles
   {
     Assert(property_pool != nullptr, ExcInternalError());
 
+    // If this particle has no properties yet, allocate and initialize them.
     if (properties == PropertyPool::invalid_handle)
-      properties = property_pool->allocate_properties_array();
+      {
+        properties = property_pool->allocate_properties_array();
+
+        ArrayView<double> my_properties =
+          property_pool->get_properties(properties);
+
+        std::fill(my_properties.begin(), my_properties.end(), 0.0);
+      }
 
     return property_pool->get_properties(properties);
   }
diff --git a/tests/particles/particle_07.cc b/tests/particles/particle_07.cc
new file mode 100644 (file)
index 0000000..0df754f
--- /dev/null
@@ -0,0 +1,64 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2017 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_03, but test property initialization.
+
+#include <deal.II/base/array_view.h>
+
+#include <deal.II/particles/particle.h>
+
+#include "../tests.h"
+
+
+template <int dim>
+void
+test()
+{
+  {
+    const unsigned int      n_properties_per_particle = 3;
+    Particles::PropertyPool pool(n_properties_per_particle);
+
+    Point<2> position;
+    position(0) = 0.3;
+    position(1) = 0.5;
+
+    Point<2> reference_position;
+    reference_position(0) = 0.2;
+    reference_position(1) = 0.4;
+
+    const types::particle_index index(7);
+
+    std::vector<double> properties = {0.15, 0.45, 0.75};
+
+    Particles::Particle<2> particle(position, reference_position, index);
+    particle.set_property_pool(pool);
+
+    for (unsigned int i = 0; i < n_properties_per_particle; ++i)
+      AssertThrow(particle.get_properties()[i] == 0.0, ExcInternalError());
+  }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int
+main()
+{
+  initlog();
+  test<2>();
+}
diff --git a/tests/particles/particle_07.output b/tests/particles/particle_07.output
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+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.