]> https://gitweb.dealii.org/ - dealii.git/commitdiff
temp
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Mon, 14 Aug 2017 21:33:58 +0000 (15:33 -0600)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Fri, 22 Sep 2017 15:59:07 +0000 (09:59 -0600)
include/deal.II/particles/particle.h
source/particles/particle.cc

index cedf7c4055ee6f18511e32c498d6507042f423d9..9a2de57d1120ea896ddbbc60f668c2cebcc11714 100644 (file)
@@ -133,11 +133,14 @@ namespace Particles
      * class then de-serializes its data from this memory location and
      * advance the pointer accordingly.
      *
-     * @param[in,out] new_property_pool A property pool that is used to
-     * allocate the property data used by this particle.
+     * @param[in,out] property_pool An optional pointer to a property pool
+     * that is used to manage the property data used by this particle. Note that
+     * if a non-null pointer is handed over this constructor assumes @p begin_data
+     * contains serialized data of the same length and type that is allocated
+     * by @p property_pool.
      */
     Particle (const void *&begin_data,
-              PropertyPool<PropertyType> &new_property_pool);
+              PropertyPool<PropertyType> *property_pool = NULL);
 
     /**
      * Move constructor for Particle, creates a particle from an existing
@@ -169,7 +172,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, const unsigned int data_size);
+     * constructor Particle(void *&data, PropertyPool<PropertyType> *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
@@ -179,6 +182,14 @@ namespace Particles
     void
     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.
index 9ea08746a361c642d753468086f235c051747130..e2917c5f00d65f40ab509d50ea52f54c2bc04dc9 100644 (file)
@@ -73,7 +73,7 @@ namespace Particles
 
   template <int dim, int spacedim, typename PropertyType>
   Particle<dim,spacedim,PropertyType>::Particle (const void *&data,
-                                                 PropertyPool<PropertyType> &new_property_pool)
+                                                 PropertyPool<PropertyType> *new_property_pool)
   {
     const types::particle_index *id_data = static_cast<const types::particle_index *> (data);
     id = *id_data++;
@@ -85,16 +85,22 @@ namespace Particles
     for (unsigned int i = 0; i < dim; ++i)
       reference_location(i) = *pdata++;
 
-    property_pool = &new_property_pool;
-    properties = property_pool->allocate_properties_array();
+    data = static_cast<const void *> (pdata);
 
-    // TODO reinterpret cast pdata to PropertyType
     // See if there are properties to load
-    const ArrayView<PropertyType> particle_properties = property_pool->get_properties(properties);
-    for (unsigned int i = 0; i < particle_properties.size(); ++i)
-      particle_properties[i] = *pdata++;
+    if (new_property_pool != NULL)
+      {
+        property_pool = new_property_pool;
+        properties = property_pool->allocate_properties_array();
 
-    data = static_cast<const void *> (pdata);
+        const PropertyType *property_data = static_cast<const PropertyType *> (data);
+
+        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);
+      }
   }
 
 
@@ -187,13 +193,37 @@ namespace Particles
     for (unsigned int i = 0; i < dim; ++i,++pdata)
       *pdata = reference_location(i);
 
-    // TODO reinterpret cast pdata to PropertyType
+    data = static_cast<void *> (pdata);
+
     // Write property data
-    const ArrayView<PropertyType> particle_properties = property_pool->get_properties(properties);
-    for (unsigned int i = 0; i < particle_properties.size(); ++i,++pdata)
-      *pdata = particle_properties[i];
+    if (has_properties())
+      {
+        PropertyType *property_data = reinterpret_cast<PropertyType *> (data);
 
-    data = static_cast<void *> (pdata);
+        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];
+
+        data = static_cast<void *> (pdata);
+      }
+  }
+
+
+
+  template <int dim, int spacedim, typename PropertyType>
+  std::size_t
+  Particle<dim,spacedim,PropertyType>::size () const
+  {
+    std::size_t size = sizeof(types::particle_index)
+        + sizeof(location)
+        + sizeof(reference_location);
+
+    if (has_properties())
+      {
+        const ArrayView<PropertyType> particle_properties = property_pool->get_properties(properties);
+        size += sizeof(PropertyType) * particle_properties.size();
+      }
+    return size;
   }
 
 
@@ -266,6 +296,10 @@ namespace Particles
   void
   Particle<dim,spacedim,PropertyType>::set_properties (const ArrayView<const PropertyType> &new_properties)
   {
+    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();
 
@@ -280,8 +314,9 @@ namespace Particles
   const ArrayView<const PropertyType>
   Particle<dim,spacedim,PropertyType>::get_properties () const
   {
-    Assert(property_pool != NULL,
-           ExcInternalError());
+    Assert(has_properties(),
+           ExcMessage("A particle without additional properties was asked for "
+               "its properties."));
 
     return property_pool->get_properties(properties);
   }
@@ -292,8 +327,9 @@ namespace Particles
   const ArrayView<PropertyType>
   Particle<dim,spacedim,PropertyType>::get_properties ()
   {
-    Assert(property_pool != NULL,
-           ExcInternalError());
+    Assert(has_properties(),
+           ExcMessage("A particle without additional properties was asked for "
+               "its properties."));
 
     return property_pool->get_properties(properties);
   }

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.