]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Introduce ParticleAccessor::set_properties() taking a Tensor.
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 20 Aug 2021 01:36:59 +0000 (19:36 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 20 Aug 2021 01:36:59 +0000 (19:36 -0600)
include/deal.II/particles/particle_accessor.h

index cad3ca321c94e3b77ca9db01f00050677b4cf5d1..e9228cc5339a385a2928462e27cb3a9f506bec79 100644 (file)
@@ -198,6 +198,29 @@ namespace Particles
     void
     set_properties(const ArrayView<const double> &new_properties);
 
+    /**
+     * Set the properties of this particle, assuming that the properties
+     * stored on this particle correspond to a rank-1 Tensor object. In
+     * particular, this means that the number of properties stored on
+     * the particle must equal `dim`.
+     *
+     * @param [in] new_properties A Tensor containing the new properties for
+     *   this particle.
+     *
+     * @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.
+     */
+    void
+    set_properties(const Tensor<1, dim> &new_properties);
+
     /**
      * Get write-access to properties of this particle.
      *
@@ -680,6 +703,25 @@ namespace Particles
 
 
 
+  template <int dim, int spacedim>
+  inline void
+  ParticleAccessor<dim, spacedim>::set_properties(
+    const Tensor<1, dim> &new_properties)
+  {
+    Assert(state() == IteratorState::valid, ExcInternalError());
+
+    // A Tensor object is not an array, so we cannot just create an
+    // ArrayView object for it. Rather, copy the data into a true
+    // array and make the ArrayView from that.
+    double array[dim];
+    for (unsigned int d = 0; d < dim; ++d)
+      array[d] = new_properties[d];
+
+    set_properties(make_array_view(array));
+  }
+
+
+
   template <int dim, int spacedim>
   inline const ArrayView<const double>
   ParticleAccessor<dim, spacedim>::get_properties() const

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.