]> https://gitweb.dealii.org/ - dealii.git/commitdiff
New set id method in particle. 9124/head
authorLuca Heltai <luca.heltai@sissa.it>
Mon, 2 Dec 2019 17:00:31 +0000 (18:00 +0100)
committerLuca Heltai <luca.heltai@sissa.it>
Tue, 3 Dec 2019 07:28:48 +0000 (08:28 +0100)
doc/news/changes/minor/20191202LucaHeltai2 [new file with mode: 0644]
include/deal.II/particles/particle.h
source/particles/particle.cc
tests/particles/particle_08.cc [new file with mode: 0644]
tests/particles/particle_08.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20191202LucaHeltai2 b/doc/news/changes/minor/20191202LucaHeltai2
new file mode 100644 (file)
index 0000000..548bfda
--- /dev/null
@@ -0,0 +1,3 @@
+New: Particles::Particle::set_id() allows to set a particle ID number.
+<br>
+(Luca Heltai, 2019/12/02)
index fc5f4cf811af251b8496dbb4a1c6d5d20a51a7fb..230cbcdb785c815e7b5a71d67df1c845b7a43b2b 100644 (file)
@@ -270,6 +270,14 @@ namespace Particles
     types::particle_index
     get_id() const;
 
+    /**
+     * Set the ID number of this particle.
+     *
+     * @param[in] new_id The new ID number for this particle.
+     */
+    void
+    set_id(const types::particle_index &new_id);
+
     /**
      * Tell the particle where to store its properties (even if it does not
      * own properties). Usually this is only done once per particle, but
index b08f23983cd74590292aafecd129017bce91b932..d421719f9f29e32990325615629b5abe23e913bd 100644 (file)
@@ -272,6 +272,15 @@ namespace Particles
 
 
 
+  template <int dim, int spacedim>
+  void
+  Particle<dim, spacedim>::set_id(const types::particle_index &new_id)
+  {
+    id = new_id;
+  }
+
+
+
   template <int dim, int spacedim>
   void
   Particle<dim, spacedim>::set_property_pool(PropertyPool &new_property_pool)
diff --git a/tests/particles/particle_08.cc b/tests/particles/particle_08.cc
new file mode 100644 (file)
index 0000000..531896c
--- /dev/null
@@ -0,0 +1,53 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 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 set/get id.
+
+#include <deal.II/particles/particle.h>
+
+#include "../tests.h"
+
+
+template <int dim>
+void
+test()
+{
+  {
+    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);
+
+    Particles::Particle<2> particle(position, reference_position, index);
+
+    deallog << "ID: " << particle.get_id() << std::endl;
+    particle.set_id(9);
+    deallog << "New ID: " << particle.get_id() << std::endl;
+  }
+}
+
+int
+main()
+{
+  initlog();
+  test<2>();
+}
diff --git a/tests/particles/particle_08.output b/tests/particles/particle_08.output
new file mode 100644 (file)
index 0000000..2a5d9d3
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::ID: 7
+DEAL::New ID: 9

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.