]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Update classes for new structure.
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Fri, 22 Sep 2017 16:47:41 +0000 (10:47 -0600)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Fri, 22 Sep 2017 19:12:30 +0000 (13:12 -0600)
20 files changed:
doc/news/changes/major/20170922ReneGassmoeller [moved from doc/news/changes/major/20170809ReneGassmoeller with 78% similarity]
include/deal.II/particles/particle.h
include/deal.II/particles/particle_accessor.h
include/deal.II/particles/particle_iterator.h
include/deal.II/particles/property_pool.h
include/deal.II/particles/property_pool.templates.h [deleted file]
source/particles/CMakeLists.txt
source/particles/particle.cc
source/particles/particle.inst.in
source/particles/particle_accessor.cc
source/particles/particle_iterator.cc
source/particles/property_pool.cc
source/particles/property_pool.inst.in [deleted file]
tests/particles/particle_03.cc
tests/particles/property_pool_01.cc
tests/particles/property_pool_01.output
tests/particles/property_pool_02.cc
tests/particles/property_pool_02.output
tests/particles/property_pool_03.cc [deleted file]
tests/particles/property_pool_03.output [deleted file]

similarity index 78%
rename from doc/news/changes/major/20170809ReneGassmoeller
rename to doc/news/changes/major/20170922ReneGassmoeller
index 354eda6d6aa6ec13ccd2e01e2426680f29ded5a6..088e68a3e3113553e5e9389d90189cf7f83cf8e1 100644 (file)
@@ -1,4 +1,4 @@
 New: There is now support for the storage of Particles and their
 properties in the new namespace Particles.  
 <br>
-(Rene Gassmoeller, 2017/08/09)
+(Rene Gassmoeller, 2017/09/22)
index d27082cb92cc205a39099ae594f9212dc5c00063..dcf5480de81f1855d408046999efd5b5a4188b5a 100644 (file)
@@ -35,14 +35,14 @@ namespace Particles
    */
   namespace types
   {
-    /* Type definitions */
-
     /**
      * Typedef of cell level/index pair. TODO: replace this by the
-     * active_cell_index from deal.II 8.3 onwards.
+     * active_cell_index.
      */
     typedef std::pair<int, int> LevelInd;
 
+    /* Type definitions */
+
 #ifdef DEAL_II_WITH_64BIT_INDICES
     /**
      * The type used for indices of particles. While in
@@ -87,15 +87,14 @@ namespace Particles
   /**
    * Base class of particles - represents a particle with position,
    * an ID number and a variable number of properties. This class
-   * can be extended to include arbitrary data related to a particle by
-   * attaching a property pool class to the particle.
-   *
+   * can be extended to include data related to a particle by the property
+   * manager.
    *
    * @ingroup Particle
    * @author Rene Gassmoeller, 2017
    *
    */
-  template <int dim, int spacedim=dim, typename PropertyType = double>
+  template <int dim, int spacedim=dim>
   class Particle
   {
   public:
@@ -127,7 +126,7 @@ namespace Particles
      * for registering and freeing this memory in the property pool this
      * constructor registers a new chunk, and copies the properties.
      */
-    Particle (const Particle<dim,spacedim,PropertyType> &particle);
+    Particle (const Particle<dim,spacedim> &particle);
 
     /**
      * Constructor for Particle, creates a particle from a data vector.
@@ -146,23 +145,23 @@ namespace Particles
      * by @p property_pool.
      */
     Particle (const void *&begin_data,
-              PropertyPool<PropertyType> *property_pool = NULL);
+              PropertyPool &property_pool);
 
     /**
      * Move constructor for Particle, creates a particle from an existing
-     * one by stealing its state and properties.
+     * one by stealing its state.
      */
-    Particle (Particle<dim,spacedim,PropertyType> &&particle);
+    Particle (Particle<dim,spacedim> &&particle);
 
     /**
      * Copy assignment operator.
      */
-    Particle<dim,spacedim,PropertyType> &operator=(const Particle<dim,spacedim,PropertyType> &particle);
+    Particle<dim,spacedim> &operator=(const Particle<dim,spacedim> &particle);
 
     /**
      * Move assignment operator.
      */
-    Particle<dim,spacedim,PropertyType> &operator=(Particle<dim,spacedim,PropertyType> &&particle);
+    Particle<dim,spacedim> &operator=(Particle<dim,spacedim> &&particle);
 
     /**
      * Destructor. Releases the property handle if it is valid, and
@@ -178,7 +177,7 @@ namespace Particles
      * point to the first element in which the data should be written. This
      * function is meant for serializing all particle properties and
      * afterwards de-serializing the properties by calling the appropriate
-     * constructor Particle(void *&data, PropertyPool<PropertyType> *property_pool = NULL);
+     * constructor Particle(void *&data, PropertyPool *property_pool = NULL);
      *
      * @param [in,out] data The memory location to write particle data
      * into. This pointer points to the begin of the memory, in which the
@@ -189,19 +188,11 @@ namespace Particles
     write_data(void *&data) const;
 
     /**
-     * Returns the size in bytes this particle occupies if all of its data is
-     * serialized (i.e. the number of bytes that is written by the write_data
-     * function of this class).
-     */
-    std::size_t
-    size() const;
-
-    /**
-     * Set the location of this particle. Note that this does not check
-     * whether this is a valid location in the simulation domain.
-     *
-     * @param [in] new_location The new location for this particle.
-     */
+      * Set the location of this particle. Note that this does not check
+      * whether this is a valid location in the simulation domain.
+      *
+      * @param [in] new_location The new location for this particle.
+      */
     void
     set_location (const Point<spacedim> &new_location);
 
@@ -237,35 +228,35 @@ namespace Particles
     /**
      * Tell the particle where to store its properties (even if it does not
      * own properties). Usually this is only done once per particle, but
-     * since the particle does not know about the properties
-     * we do not want to do it at construction time. Another use for this
+     * since the particle does not know about the properties,
+     * we want to do it not at construction time. Another use for this
      * function is after particle transfer to a new process.
      */
     void
-    set_property_pool(PropertyPool<PropertyType> &property_pool);
+    set_property_pool(PropertyPool &property_pool);
 
     /**
-     * Returns whether this particle has a valid property pool and a valid
-     * handle to properties.
-     */
+      * Returns whether this particle has a valid property pool and a valid
+      * handle to properties.
+      */
     bool
     has_properties () const;
 
     /**
      * Set the properties of this particle.
      *
-     * @param [in] new_properties An ArrayView of the new
-     * properties that will be copied into the property pool.
+     * @param [in] new_properties An ArrayView containing the
+     * new properties for this particle.
      */
     void
-    set_properties (const ArrayView<const PropertyType> &new_properties);
+    set_properties (const ArrayView<const double> &new_properties);
 
     /**
      * Get write-access to properties of this particle.
      *
      * @return An ArrayView of the properties of this particle.
      */
-    const ArrayView<PropertyType>
+    const ArrayView<double>
     get_properties ();
 
     /**
@@ -273,14 +264,32 @@ namespace Particles
      *
      * @return An ArrayView of the properties of this particle.
      */
-    const ArrayView<const PropertyType>
+    const ArrayView<const double>
     get_properties () const;
 
     /**
-     * Serialize the contents of this class.
+     * Returns the size in bytes this particle occupies if all of its data is
+     * serialized (i.e. the number of bytes that is written by the write_data
+     * function of this class).
+     */
+    std::size_t
+    serialized_size_in_bytes() const;
+
+    /**
+     * Write the data of this object to a stream for the purpose of
+     * serialization.
+     */
+    template <class Archive>
+    void save (Archive &ar, const unsigned int version) const;
+
+    /**
+     * Read the data of this object from a stream for the purpose of
+     * serialization.
      */
     template <class Archive>
-    void serialize (Archive &ar, const unsigned int version);
+    void load (Archive &ar, const unsigned int version);
+
+    BOOST_SERIALIZATION_SPLIT_MEMBER()
 
   private:
     /**
@@ -302,24 +311,50 @@ namespace Particles
      * A pointer to the property pool. Necessary to translate from the
      * handle to the actual memory locations.
      */
-    PropertyPool<PropertyType> *property_pool;
+    PropertyPool *property_pool;
 
     /**
-     * A handle to all particle properties.
+     * A handle to all particle properties
      */
-    typename PropertyPool<PropertyType>::Handle properties;
+    PropertyPool::Handle properties;
   };
 
   /* -------------------------- inline and template functions ---------------------- */
 
-  template <int dim, int spacedim, typename PropertyType>
+  template <int dim, int spacedim>
   template <class Archive>
-  void Particle<dim,spacedim,PropertyType>::serialize (Archive &ar, const unsigned int)
+  void Particle<dim,spacedim>::load (Archive &ar, const unsigned int)
   {
+    unsigned int n_properties = 0;
+
     ar &location
+    & reference_location
     & id
-    & properties
-    ;
+    & n_properties;
+
+    if (n_properties > 0)
+      {
+        properties = new double[n_properties];
+        ar &boost::serialization::make_array(properties, n_properties);
+      }
+  }
+
+  template <int dim, int spacedim>
+  template <class Archive>
+  void Particle<dim,spacedim>::save (Archive &ar, const unsigned int) const
+  {
+    unsigned int n_properties = 0;
+    if ((property_pool != NULL) && (properties != PropertyPool::invalid_handle))
+      n_properties = get_properties().size();
+
+    ar &location
+    & reference_location
+    & id
+    & n_properties;
+
+    if (n_properties > 0)
+      ar &boost::serialization::make_array(properties, n_properties);
+
   }
 }
 
index 94c51422c537c323fdf6133bc8e07d9267b112c9..0336063e5e293c40c46714372760f1a16c973b61 100644 (file)
@@ -93,7 +93,7 @@ namespace Particles
      * function is after particle transfer to a new process.
      */
     void
-    set_property_pool(PropertyPool<double> &property_pool);
+    set_property_pool(PropertyPool &property_pool);
 
     /**
       * Returns whether this particle has a valid property pool and a valid
@@ -133,7 +133,7 @@ namespace Particles
      * function of this class).
      */
     std::size_t
-    size() const;
+    serialized_size_in_bytes() const;
 
     /**
      * Get a cell iterator to the cell surrounding the current particle.
@@ -171,6 +171,11 @@ namespace Particles
     bool operator == (const ParticleAccessor<dim,spacedim> &other) const;
 
   protected:
+    /**
+     * Construct an invalid accessor. Such an object is not usable.
+     */
+    ParticleAccessor ();
+
     /**
      * Construct an accessor from a reference to a map and an iterator to the map.
      * This constructor is protected so that it can only be accessed by friend
index 83941dd6b63414c09acd790906dbb5026877a5dc..c75f2b44b53936fc8d5b11490fbd21c303e87917 100644 (file)
@@ -31,6 +31,11 @@ namespace Particles
   class ParticleIterator: public std::iterator<std::bidirectional_iterator_tag,ParticleAccessor<dim,spacedim> >
   {
   public:
+    /**
+     * Empty constructor. Such an object is not usable!
+     */
+    ParticleIterator ();
+
     /**
      * Constructor of the iterator. Takes a reference to the particle
      * container, and an iterator the the cell-particle pair.
@@ -49,6 +54,11 @@ namespace Particles
      */
     ParticleAccessor<dim,spacedim> &operator * ();
 
+    /**
+     * Assignment operator.
+     */
+    ParticleIterator &operator = (const ParticleIterator &);
+
     /**
      * Dereferencing operator, returns a pointer of the particle pointed to. Usage
      * is thus like <tt>i->get_id ();</tt>
index 176f1bfb0bb18fba3a8f34bb7adde5a73cd8fc9b..1cc406145328de3a581b94c4cf7c70bfde0cc302 100644 (file)
@@ -38,7 +38,6 @@ namespace Particles
    * (e.g. to allow for varying number of properties per handle) without
    * affecting its interface.
    */
-  template <typename PropertyType = double>
   class PropertyPool
   {
   public:
@@ -47,7 +46,7 @@ namespace Particles
      * uniquely identifies the slot of memory that is reserved for this
      * particle.
      */
-    typedef PropertyType *Handle;
+    typedef double *Handle;
 
     /**
      * Define a default (invalid) value for handles.
@@ -56,37 +55,38 @@ namespace Particles
 
     /**
      * Constructor. Stores the number of properties per reserved slot.
-     * By default this class assumes the template parameter PropertyType
-     * completely describes all properties of the particle.
      */
-    PropertyPool (const unsigned int n_properties_per_slot = 1);
+    PropertyPool (const unsigned int n_properties_per_slot=1);
 
     /**
      * Returns a new handle that allows accessing the reserved block
-     * of memory. The returned memory block is not initialized.
+     * of memory.
      */
     Handle allocate_properties_array ();
 
     /**
      * Mark the properties corresponding to the handle @p handle as
-     * deleted. After calling this function @p handle is invalid and
-     * can not longer be used to access properties.
+     * deleted. Calling this function more than once for the same
+     * handle causes undefined behavior.
      */
-    void deallocate_properties_array (Handle &handle);
+    void deallocate_properties_array (const Handle handle);
 
     /**
      * Return an ArrayView to the properties that correspond to the given
-     * handle @p handle. This function allows read-write access to the
-     * underlying properties.
+     * handle @p handle.
      */
-    const ArrayView<PropertyType> get_properties (const Handle handle);
+    ArrayView<double> get_properties (const Handle handle);
 
     /**
-     * Return an ArrayView to the properties that correspond to the given
-     * handle @p handle. This function only allows read access to the underlying
-     * properties.
+     * Reserves the dynamic memory needed for storing the properties of
+     * @p size particles.
      */
-    const ArrayView<const PropertyType> get_properties (const Handle handle) const;
+    void reserve(const std::size_t size);
+
+    /**
+     * Returns how many properties are stored per slot in the pool.
+     */
+    unsigned int n_properties_per_slot() const;
 
   private:
     /**
@@ -95,6 +95,7 @@ namespace Particles
     const unsigned int n_properties;
   };
 
+
 }
 
 DEAL_II_NAMESPACE_CLOSE
diff --git a/include/deal.II/particles/property_pool.templates.h b/include/deal.II/particles/property_pool.templates.h
deleted file mode 100644 (file)
index 7d76c9c..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-// ---------------------------------------------------------------------
-//
-// 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 at
-// the top level of the deal.II distribution.
-//
-// ---------------------------------------------------------------------
-
-#ifndef dealii__particles_property_pool_templates_h
-#define dealii__particles_property_pool_templates_h
-
-#include <deal.II/particles/property_pool.h>
-#include <deal.II/base/exceptions.h>
-
-DEAL_II_NAMESPACE_OPEN
-
-namespace Particles
-{
-  template <typename PropertyType>
-  const typename PropertyPool<PropertyType>::Handle PropertyPool<PropertyType>::invalid_handle = NULL;
-
-
-
-  template <typename PropertyType>
-  PropertyPool<PropertyType>::PropertyPool (const unsigned int n_properties_per_slot)
-    :
-    n_properties (n_properties_per_slot)
-  {}
-
-
-
-  template <typename PropertyType>
-  typename PropertyPool<PropertyType>::Handle
-  PropertyPool<PropertyType>::allocate_properties_array ()
-  {
-    return new PropertyType[n_properties];
-  }
-
-
-  template <typename PropertyType>
-  void
-  PropertyPool<PropertyType>::deallocate_properties_array (Handle &handle)
-  {
-    delete[] handle;
-    handle = invalid_handle;
-  }
-
-
-
-  template <typename PropertyType>
-  const ArrayView<PropertyType>
-  PropertyPool<PropertyType>::get_properties (const Handle handle)
-  {
-    Assert(handle != PropertyPool<PropertyType>::invalid_handle,
-           ExcMessage("PropertyPool was asked for the properties that belong to an invalid handle. "
-                      "Either this handle was never validly created, or it was deallocated before use."));
-
-    return ArrayView<PropertyType>(handle, n_properties);
-  }
-
-
-
-  template <typename PropertyType>
-  const ArrayView<const PropertyType>
-  PropertyPool<PropertyType>::get_properties (const Handle handle) const
-  {
-    Assert(handle != PropertyPool<PropertyType>::invalid_handle,
-           ExcMessage("PropertyPool was asked for the properties that belong to an invalid handle. "
-                      "Either this handle was never validly created, or it was deallocated before use."));
-
-    return ArrayView<const PropertyType>(handle, n_properties);
-  }
-}
-
-DEAL_II_NAMESPACE_CLOSE
-
-#endif
index 8eaa91767d1eb5a1535e309edcc9f52d5b70e49b..9b0dc52ed96bd050465f3678b73df49bff235137 100644 (file)
@@ -27,7 +27,6 @@ SET(_inst
   particle.inst.in
   particle_accessor.inst.in
   particle_iterator.inst.in
-  property_pool.inst.in
   )
 
 FILE(GLOB _header
index b898f21193f8930d26257b75633d8f6de20b1e52..2c4ad4515f8d1b8ac32bdb591f4ae2a61d101a32 100644 (file)
@@ -19,50 +19,50 @@ DEAL_II_NAMESPACE_OPEN
 
 namespace Particles
 {
-  template <int dim, int spacedim, typename PropertyType>
-  Particle<dim,spacedim,PropertyType>::Particle ()
+  template <int dim, int spacedim>
+  Particle<dim,spacedim>::Particle ()
     :
     location (),
     reference_location(),
     id (0),
     property_pool(NULL),
-    properties(PropertyPool<PropertyType>::invalid_handle)
+    properties(PropertyPool::invalid_handle)
   {
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
-  Particle<dim,spacedim,PropertyType>::Particle (const Point<spacedim> &location,
-                                                 const Point<dim> &reference_location,
-                                                 const types::particle_index id)
+  template <int dim, int spacedim>
+  Particle<dim,spacedim>::Particle (const Point<spacedim> &location,
+                                    const Point<dim> &reference_location,
+                                    const types::particle_index id)
     :
     location (location),
     reference_location (reference_location),
     id (id),
     property_pool(NULL),
-    properties (PropertyPool<PropertyType>::invalid_handle)
+    properties (PropertyPool::invalid_handle)
   {
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
-  Particle<dim,spacedim,PropertyType>::Particle (const Particle<dim,spacedim,PropertyType> &particle)
+  template <int dim, int spacedim>
+  Particle<dim,spacedim>::Particle (const Particle<dim,spacedim> &particle)
     :
     location (particle.get_location()),
     reference_location (particle.get_reference_location()),
     id (particle.get_id()),
     property_pool(particle.property_pool),
-    properties ((property_pool != NULL) ? property_pool->allocate_properties_array() : PropertyPool<PropertyType>::invalid_handle)
+    properties ((property_pool != NULL) ? property_pool->allocate_properties_array() : PropertyPool::invalid_handle)
   {
     if (property_pool != NULL)
       {
-        const ArrayView<PropertyType> my_properties = property_pool->get_properties(properties);
+        const ArrayView<double> my_properties = property_pool->get_properties(properties);
 
         if (my_properties.size() != 0)
           {
-            const ArrayView<const PropertyType> their_properties = particle.get_properties();
+            const ArrayView<const double> their_properties = particle.get_properties();
 
             std::copy(&their_properties[0],&their_properties[0]+their_properties.size(),&my_properties[0]);
           }
@@ -71,9 +71,9 @@ namespace Particles
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
-  Particle<dim,spacedim,PropertyType>::Particle (const void *&data,
-                                                 PropertyPool<PropertyType> *new_property_pool)
+  template <int dim, int spacedim>
+  Particle<dim,spacedim>::Particle (const void *&data,
+                                    PropertyPool &new_property_pool)
   {
     const types::particle_index *id_data = static_cast<const types::particle_index *> (data);
     id = *id_data++;
@@ -85,28 +85,21 @@ namespace Particles
     for (unsigned int i = 0; i < dim; ++i)
       reference_location(i) = *pdata++;
 
-    data = static_cast<const void *> (pdata);
+    property_pool = &new_property_pool;
+    properties = property_pool->allocate_properties_array();
 
     // See if there are properties to load
-    if (new_property_pool != NULL)
-      {
-        property_pool = new_property_pool;
-        properties = property_pool->allocate_properties_array();
-
-        const PropertyType *property_data = static_cast<const PropertyType *> (data);
+    const ArrayView<double> particle_properties = property_pool->get_properties(properties);
+    for (unsigned int i = 0; i < particle_properties.size(); ++i)
+      particle_properties[i] = *pdata++;
 
-        const ArrayView<PropertyType> particle_properties = property_pool->get_properties(properties);
-        for (unsigned int i = 0; i < particle_properties.size(); ++i)
-          particle_properties[i] = *property_data++;
-
-        data = static_cast<const void *> (property_data);
-      }
+    data = static_cast<const void *> (pdata);
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
-  Particle<dim,spacedim,PropertyType>::Particle (Particle<dim,spacedim,PropertyType> &&particle)
+  template <int dim, int spacedim>
+  Particle<dim,spacedim>::Particle (Particle<dim,spacedim> &&particle)
     :
     location (particle.location),
     reference_location(particle.reference_location),
@@ -114,14 +107,14 @@ namespace Particles
     property_pool(particle.property_pool),
     properties(particle.properties)
   {
-    particle.properties = PropertyPool<PropertyType>::invalid_handle;
+    particle.properties = PropertyPool::invalid_handle;
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
-  Particle<dim,spacedim,PropertyType> &
-  Particle<dim,spacedim,PropertyType>::operator=(const Particle<dim,spacedim,PropertyType> &particle)
+  template <int dim, int spacedim>
+  Particle<dim,spacedim> &
+  Particle<dim,spacedim>::operator=(const Particle<dim,spacedim> &particle)
   {
     if (this != &particle)
       {
@@ -133,25 +126,25 @@ namespace Particles
         if (property_pool != NULL)
           {
             properties = property_pool->allocate_properties_array();
-            const ArrayView<const PropertyType> their_properties = particle.get_properties();
+            const ArrayView<const double> their_properties = particle.get_properties();
 
             if (their_properties.size() != 0)
               {
-                const ArrayView<PropertyType> my_properties = property_pool->get_properties(properties);
+                const ArrayView<double> my_properties = property_pool->get_properties(properties);
                 std::copy(&their_properties[0],&their_properties[0]+their_properties.size(),&my_properties[0]);
               }
           }
         else
-          properties = PropertyPool<PropertyType>::invalid_handle;
+          properties = PropertyPool::invalid_handle;
       }
     return *this;
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
-  Particle<dim,spacedim,PropertyType> &
-  Particle<dim,spacedim,PropertyType>::operator=(Particle<dim,spacedim,PropertyType> &&particle)
+  template <int dim, int spacedim>
+  Particle<dim,spacedim> &
+  Particle<dim,spacedim>::operator=(Particle<dim,spacedim> &&particle)
   {
     if (this != &particle)
       {
@@ -160,25 +153,25 @@ namespace Particles
         id = particle.id;
         property_pool = particle.property_pool;
         properties = particle.properties;
-        particle.properties = PropertyPool<PropertyType>::invalid_handle;
+        particle.properties = PropertyPool::invalid_handle;
       }
     return *this;
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
-  Particle<dim,spacedim,PropertyType>::~Particle ()
+  template <int dim, int spacedim>
+  Particle<dim,spacedim>::~Particle ()
   {
-    if (properties != PropertyPool<PropertyType>::invalid_handle)
+    if (properties != PropertyPool::invalid_handle)
       property_pool->deallocate_properties_array(properties);
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
+  template <int dim, int spacedim>
   void
-  Particle<dim,spacedim,PropertyType>::write_data (void *&data) const
+  Particle<dim,spacedim>::write_data (void *&data) const
   {
     types::particle_index *id_data  = static_cast<types::particle_index *> (data);
     *id_data = id;
@@ -193,26 +186,19 @@ namespace Particles
     for (unsigned int i = 0; i < dim; ++i,++pdata)
       *pdata = reference_location(i);
 
-    data = static_cast<void *> (pdata);
-
     // Write property data
-    if (has_properties())
-      {
-        PropertyType *property_data = reinterpret_cast<PropertyType *> (data);
-
-        const ArrayView<PropertyType> particle_properties = property_pool->get_properties(properties);
-        for (unsigned int i = 0; i < particle_properties.size(); ++i,++property_data)
-          *property_data = particle_properties[i];
+    const ArrayView<double> particle_properties = property_pool->get_properties(properties);
+    for (unsigned int i = 0; i < particle_properties.size(); ++i,++pdata)
+      *pdata = particle_properties[i];
 
-        data = static_cast<void *> (pdata);
-      }
+    data = static_cast<void *> (pdata);
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
+  template <int dim, int spacedim>
   std::size_t
-  Particle<dim,spacedim,PropertyType>::size () const
+  Particle<dim,spacedim>::serialized_size_in_bytes () const
   {
     std::size_t size = sizeof(types::particle_index)
                        + sizeof(location)
@@ -220,118 +206,119 @@ namespace Particles
 
     if (has_properties())
       {
-        const ArrayView<PropertyType> particle_properties = property_pool->get_properties(properties);
-        size += sizeof(PropertyType) * particle_properties.size();
+        const ArrayView<double> particle_properties = property_pool->get_properties(properties);
+        size += sizeof(double) * particle_properties.size();
       }
     return size;
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
+  template <int dim, int spacedim>
   void
-  Particle<dim,spacedim,PropertyType>::set_location (const Point<spacedim> &new_loc)
+  Particle<dim,spacedim>::set_location (const Point<spacedim> &new_loc)
   {
     location = new_loc;
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
+  template <int dim, int spacedim>
   const Point<spacedim> &
-  Particle<dim,spacedim,PropertyType>::get_location () const
+  Particle<dim,spacedim>::get_location () const
   {
     return location;
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
+  template <int dim, int spacedim>
   void
-  Particle<dim,spacedim,PropertyType>::set_reference_location (const Point<dim> &new_loc)
+  Particle<dim,spacedim>::set_reference_location (const Point<dim> &new_loc)
   {
     reference_location = new_loc;
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
+  template <int dim, int spacedim>
   const Point<dim> &
-  Particle<dim,spacedim,PropertyType>::get_reference_location () const
+  Particle<dim,spacedim>::get_reference_location () const
   {
     return reference_location;
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
+  template <int dim, int spacedim>
   types::particle_index
-  Particle<dim,spacedim,PropertyType>::get_id () const
+  Particle<dim,spacedim>::get_id () const
   {
     return id;
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
+  template <int dim, int spacedim>
   void
-  Particle<dim,spacedim,PropertyType>::set_property_pool (PropertyPool<PropertyType> &new_property_pool)
+  Particle<dim,spacedim>::set_property_pool (PropertyPool &new_property_pool)
   {
     property_pool = &new_property_pool;
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
-  bool
-  Particle<dim,spacedim,PropertyType>::has_properties () const
+  template <int dim, int spacedim>
+  void
+  Particle<dim,spacedim>::set_properties (const ArrayView<const double> &new_properties)
   {
-    return (property_pool != NULL)
-           && (properties != PropertyPool<PropertyType>::invalid_handle);
+    if (properties == PropertyPool::invalid_handle)
+      properties = property_pool->allocate_properties_array();
+
+    const ArrayView<double> old_properties = property_pool->get_properties(properties);
+
+    Assert (new_properties.size() == old_properties.size(),
+            ExcMessage(std::string("You are trying to assign properties with an incompatible length. ")
+                       + "The particle has space to store " + Utilities::to_string(old_properties.size()) + " properties, "
+                       + "and this function tries to assign" + Utilities::to_string(new_properties.size()) + " properties. "
+                       + "This is not allowed."));
+
+    if (old_properties.size() > 0)
+      std::copy(new_properties.begin(),new_properties.end(),&old_properties[0]);
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
-  void
-  Particle<dim,spacedim,PropertyType>::set_properties (const ArrayView<const PropertyType> &new_properties)
+  template <int dim, int spacedim>
+  const ArrayView<const double>
+  Particle<dim,spacedim>::get_properties () const
   {
     Assert(property_pool != NULL,
-           ExcMessage("A particle was asked to set its properties without an "
-                      "associated PropertyPool."))
-
-    if (properties == PropertyPool<PropertyType>::invalid_handle)
-      properties = property_pool->allocate_properties_array();
+           ExcInternalError());
 
-    const ArrayView<PropertyType> old_properties = property_pool->get_properties(properties);
-
-    std::copy(new_properties.begin(),new_properties.end(),&old_properties[0]);
+    return property_pool->get_properties(properties);
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
-  const ArrayView<const PropertyType>
-  Particle<dim,spacedim,PropertyType>::get_properties () const
+  template <int dim, int spacedim>
+  const ArrayView<double>
+  Particle<dim,spacedim>::get_properties ()
   {
-    Assert(has_properties(),
-           ExcMessage("A particle without additional properties was asked for "
-                      "its properties."));
+    Assert(property_pool != NULL,
+           ExcInternalError());
 
     return property_pool->get_properties(properties);
   }
 
 
 
-  template <int dim, int spacedim, typename PropertyType>
-  const ArrayView<PropertyType>
-  Particle<dim,spacedim,PropertyType>::get_properties ()
+  template <int dim, int spacedim>
+  bool
+  Particle<dim,spacedim>::has_properties () const
   {
-    Assert(has_properties(),
-           ExcMessage("A particle without additional properties was asked for "
-                      "its properties."));
-
-    return property_pool->get_properties(properties);
+    return (property_pool != NULL)
+           && (properties != PropertyPool::invalid_handle);
   }
 }
 
index 1f1327202ada708e3577ea79b3b756c0597d648a..bf686755936ad4aeefe187d8887b1ccf94c78f06 100644 (file)
 // ---------------------------------------------------------------------
 
 
-for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS; number : REAL_SCALARS)
+for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS)
 {
 #if deal_II_dimension <= deal_II_space_dimension
     namespace Particles
     \{
     template
-    class Particle <deal_II_dimension,deal_II_space_dimension,number>;
+    class Particle <deal_II_dimension,deal_II_space_dimension>;
     \}
 #endif
 }
index 16bbd14c653f1b9f87416d2eb4983a41059b2720..ea82fedfd16441f2fec827db3e2a6f08abefe451 100644 (file)
@@ -19,6 +19,15 @@ DEAL_II_NAMESPACE_OPEN
 
 namespace Particles
 {
+  template <int dim, int spacedim>
+  ParticleAccessor<dim,spacedim>::ParticleAccessor ()
+    :
+    map (NULL),
+    particle ()
+  {}
+
+
+
   template <int dim, int spacedim>
   ParticleAccessor<dim,spacedim>::ParticleAccessor (const std::multimap<types::LevelInd, Particle<dim,spacedim> > &map,
                                                     const typename std::multimap<types::LevelInd, Particle<dim,spacedim> >::iterator &particle)
@@ -103,7 +112,7 @@ namespace Particles
 
   template <int dim, int spacedim>
   void
-  ParticleAccessor<dim,spacedim>::set_property_pool (PropertyPool<double> &new_property_pool)
+  ParticleAccessor<dim,spacedim>::set_property_pool (PropertyPool &new_property_pool)
   {
     Assert(particle != map->end(),
            ExcInternalError());
@@ -120,7 +129,7 @@ namespace Particles
     Assert(particle != map->end(),
            ExcInternalError());
 
-    particle->second.set_properties(ArrayView<const double>(&(new_properties[0]),new_properties.size()));
+    particle->second.set_properties(new_properties);
     return;
   }
 
@@ -167,12 +176,12 @@ namespace Particles
 
   template <int dim, int spacedim>
   std::size_t
-  ParticleAccessor<dim,spacedim>::size () const
+  ParticleAccessor<dim,spacedim>::serialized_size_in_bytes () const
   {
     Assert(particle != map->end(),
            ExcInternalError());
 
-    return particle->second.size();
+    return particle->second.serialized_size_in_bytes();
   }
 
 
index 4fa787338250d888fe01f8a2e66c7fb1f1e16301..bdcba3020ad56a6a52b2e6fc72c1ab180add0728 100644 (file)
@@ -19,6 +19,14 @@ DEAL_II_NAMESPACE_OPEN
 
 namespace Particles
 {
+  template <int dim, int spacedim>
+  ParticleIterator<dim,spacedim>::ParticleIterator ()
+    :
+    accessor ()
+  {}
+
+
+
   template <int dim, int spacedim>
   ParticleIterator<dim,spacedim>::ParticleIterator (const std::multimap<types::LevelInd, Particle<dim,spacedim> > &map,
                                                     const typename std::multimap<types::LevelInd, Particle<dim,spacedim> >::iterator &particle)
@@ -63,6 +71,15 @@ namespace Particles
   }
 
 
+  template <int dim, int spacedim>
+  ParticleIterator<dim,spacedim> &
+  ParticleIterator<dim,spacedim>::operator =(const ParticleIterator &other)
+  {
+    accessor = other.accessor;
+    return *this;
+  }
+
+
 
   template <int dim, int spacedim>
   bool
index a11d773c86a2e0d7d46e4e253de134a2c8e5ed8c..68b13ed19252fb59308d8cd37ea1e501e3e666b6 100644 (file)
 // ---------------------------------------------------------------------
 
 
-#include <deal.II/particles/property_pool.templates.h>
+#include <deal.II/particles/property_pool.h>
 
 DEAL_II_NAMESPACE_OPEN
 
-#include "property_pool.inst"
+namespace Particles
+{
+  const PropertyPool::Handle PropertyPool::invalid_handle = nullptr;
 
+
+  PropertyPool::PropertyPool (const unsigned int n_properties_per_slot)
+    :
+    n_properties (n_properties_per_slot)
+  {}
+
+
+
+  PropertyPool::Handle
+  PropertyPool::allocate_properties_array ()
+  {
+    return new double[n_properties];
+  }
+
+
+
+  void
+  PropertyPool::deallocate_properties_array (Handle handle)
+  {
+    delete[] handle;
+  }
+
+
+
+  ArrayView<double>
+  PropertyPool::get_properties (const Handle handle)
+  {
+    return ArrayView<double>(handle, n_properties);
+  }
+
+
+
+  void
+  PropertyPool::reserve(const std::size_t size)
+  {
+    (void)size;
+  }
+
+
+
+  unsigned int
+  PropertyPool::n_properties_per_slot() const
+  {
+    return n_properties;
+  }
+}
 DEAL_II_NAMESPACE_CLOSE
diff --git a/source/particles/property_pool.inst.in b/source/particles/property_pool.inst.in
deleted file mode 100644 (file)
index 974d142..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// ---------------------------------------------------------------------
-//
-// 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 at
-// the top level of the deal.II distribution.
-//
-// ---------------------------------------------------------------------
-
-
-for (number : REAL_SCALARS)
-{
-    namespace Particles
-    \{
-    template
-    class PropertyPool <number>;
-    \}
-}
index 9a9e04d2ce1afac0c31d36b0c989fe5ad809e1b3..aaa6a882bf06c20741133bf07da660c48df186a5 100644 (file)
@@ -27,7 +27,7 @@ void test ()
 {
   {
     const unsigned int n_properties_per_particle = 3;
-    Particles::PropertyPool<> pool(n_properties_per_particle);
+    Particles::PropertyPool pool(n_properties_per_particle);
 
     Point<2> position;
     position(0) = 0.3;
index e178ca870571f8975edf5944c0022a68177afc3c..e078ed98ecd5441729cd7ca3cd6f2be13973d784 100644 (file)
 #include <iomanip>
 
 
-template <typename PropertyType>
 void test ()
 {
   {
-    Particles::PropertyPool<PropertyType> pool;
+    Particles::PropertyPool pool;
 
-    typename Particles::PropertyPool<PropertyType>::Handle handle = pool.allocate_properties_array();
+    typename Particles::PropertyPool::Handle handle = pool.allocate_properties_array();
 
     pool.get_properties(handle)[0] = 2.5;
 
@@ -46,6 +45,5 @@ void test ()
 int main ()
 {
   initlog();
-  test<double>();
-  test<float>();
+  test();
 }
index fdb9accf31721923700ea1e19d36c376dda60099..0fb52adf900d9f8f1c8c8b27e1f1475657fbf839 100644 (file)
@@ -1,5 +1,3 @@
 
 DEAL::Pool properties: 2.50000
 DEAL::OK
-DEAL::Pool properties: 2.50000
-DEAL::OK
index f60f69b8e6e88d21f8904dfd9c35d00326ec463d..256721e9f3fc89c32157046a5edb8e5927a2979c 100644 (file)
 #include <iomanip>
 
 
-template <typename PropertyType>
 void test ()
 {
   {
     const unsigned int n_properties = 3;
-    Particles::PropertyPool<PropertyType> pool(n_properties);
+    Particles::PropertyPool pool(n_properties);
 
-    typename Particles::PropertyPool<PropertyType>::Handle handle = pool.allocate_properties_array();
+    typename Particles::PropertyPool::Handle handle = pool.allocate_properties_array();
 
     pool.get_properties(handle)[0] = 1.2;
     pool.get_properties(handle)[1] = 2.5;
@@ -55,6 +54,5 @@ void test ()
 int main ()
 {
   initlog();
-  test<double>();
-  test<float>();
+  test();
 }
index 80f767455cffaa04675114eacd49a1ccd302d4e7..f514eabca233f4e239c5800e4b672b654918e377 100644 (file)
@@ -1,5 +1,3 @@
 
 DEAL::Pool properties: 1.20000 2.50000 2.70000
 DEAL::OK
-DEAL::Pool properties: 1.20000 2.50000 2.70000
-DEAL::OK
diff --git a/tests/particles/property_pool_03.cc b/tests/particles/property_pool_03.cc
deleted file mode 100644 (file)
index 4857096..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-// ---------------------------------------------------------------------
-//
-// 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 at
-// the top level of the deal.II distribution.
-//
-// ---------------------------------------------------------------------
-
-
-
-// test a property pool that uses a custom type as storage container
-
-#include "../tests.h"
-#include <deal.II/particles/property_pool.templates.h>
-#include <fstream>
-#include <iomanip>
-
-
-
-struct DataType
-{
-  double a[2];
-  char c;
-  double *pointer;
-};
-
-void test ()
-{
-  {
-    double b[2] = {0.7,1.3};
-
-    Particles::PropertyPool<DataType> pool;
-
-    typename Particles::PropertyPool<DataType>::Handle handle = pool.allocate_properties_array();
-
-    DataType &properties_in = pool.get_properties(handle)[0];
-    properties_in.a[0] = 2.5;
-    properties_in.a[1] = 2.0;
-    properties_in.c = 'f';
-    properties_in.pointer = &b[1];
-
-    const DataType &properties_out = pool.get_properties(handle)[0];
-
-    deallog << "Pool properties: " << properties_out.a[0] << ' '
-            << properties_out.a[1] << ' '
-            << properties_out.c << ' '
-            << *properties_out.pointer
-            << std::endl;
-
-    pool.deallocate_properties_array(handle);
-  }
-
-  deallog << "OK" << std::endl;
-}
-
-
-
-int main ()
-{
-  initlog();
-  ;
-
-  test();
-}
diff --git a/tests/particles/property_pool_03.output b/tests/particles/property_pool_03.output
deleted file mode 100644 (file)
index bf8cb58..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-
-DEAL::Pool properties: 2.50000 2.00000 f 1.30000
-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.