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)
*/
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
/**
* 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:
* 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.
* 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
* 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
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);
/**
* 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 ();
/**
*
* @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:
/**
* 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);
+
}
}
* 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
* 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.
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
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.
*/
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>
* (e.g. to allow for varying number of properties per handle) without
* affecting its interface.
*/
- template <typename PropertyType = double>
class PropertyPool
{
public:
* 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.
/**
* 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:
/**
const unsigned int n_properties;
};
+
}
DEAL_II_NAMESPACE_CLOSE
+++ /dev/null
-// ---------------------------------------------------------------------
-//
-// 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
particle.inst.in
particle_accessor.inst.in
particle_iterator.inst.in
- property_pool.inst.in
)
FILE(GLOB _header
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]);
}
- 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++;
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),
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)
{
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)
{
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;
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)
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);
}
}
// ---------------------------------------------------------------------
-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
}
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)
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());
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;
}
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();
}
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)
}
+ 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
// ---------------------------------------------------------------------
-#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
+++ /dev/null
-// ---------------------------------------------------------------------
-//
-// 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>;
- \}
-}
{
{
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;
#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;
int main ()
{
initlog();
- test<double>();
- test<float>();
+ test();
}
DEAL::Pool properties: 2.50000
DEAL::OK
-DEAL::Pool properties: 2.50000
-DEAL::OK
#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;
int main ()
{
initlog();
- test<double>();
- test<float>();
+ test();
}
DEAL::Pool properties: 1.20000 2.50000 2.70000
DEAL::OK
-DEAL::Pool properties: 1.20000 2.50000 2.70000
-DEAL::OK
+++ /dev/null
-// ---------------------------------------------------------------------
-//
-// 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();
-}
+++ /dev/null
-
-DEAL::Pool properties: 2.50000 2.00000 f 1.30000
-DEAL::OK