From: Rene Gassmoeller Date: Fri, 22 Sep 2017 16:47:41 +0000 (-0600) Subject: Update classes for new structure. X-Git-Tag: v9.0.0-rc1~1013^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1acd38d22c696da5604dc8e092f7fd758c68b59;p=dealii.git Update classes for new structure. --- diff --git a/doc/news/changes/major/20170809ReneGassmoeller b/doc/news/changes/major/20170922ReneGassmoeller similarity index 78% rename from doc/news/changes/major/20170809ReneGassmoeller rename to doc/news/changes/major/20170922ReneGassmoeller index 354eda6d6a..088e68a3e3 100644 --- a/doc/news/changes/major/20170809ReneGassmoeller +++ b/doc/news/changes/major/20170922ReneGassmoeller @@ -1,4 +1,4 @@ New: There is now support for the storage of Particles and their properties in the new namespace Particles.
-(Rene Gassmoeller, 2017/08/09) +(Rene Gassmoeller, 2017/09/22) diff --git a/include/deal.II/particles/particle.h b/include/deal.II/particles/particle.h index d27082cb92..dcf5480de8 100644 --- a/include/deal.II/particles/particle.h +++ b/include/deal.II/particles/particle.h @@ -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 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 + template 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 &particle); + Particle (const Particle &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 *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 &&particle); + Particle (Particle &&particle); /** * Copy assignment operator. */ - Particle &operator=(const Particle &particle); + Particle &operator=(const Particle &particle); /** * Move assignment operator. */ - Particle &operator=(Particle &&particle); + Particle &operator=(Particle &&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 *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 &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 &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 &new_properties); + set_properties (const ArrayView &new_properties); /** * Get write-access to properties of this particle. * * @return An ArrayView of the properties of this particle. */ - const ArrayView + const ArrayView get_properties (); /** @@ -273,14 +264,32 @@ namespace Particles * * @return An ArrayView of the properties of this particle. */ - const ArrayView + const ArrayView 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 + void save (Archive &ar, const unsigned int version) const; + + /** + * Read the data of this object from a stream for the purpose of + * serialization. */ template - 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 *property_pool; + PropertyPool *property_pool; /** - * A handle to all particle properties. + * A handle to all particle properties */ - typename PropertyPool::Handle properties; + PropertyPool::Handle properties; }; /* -------------------------- inline and template functions ---------------------- */ - template + template template - void Particle::serialize (Archive &ar, const unsigned int) + void Particle::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 + template + void Particle::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); + } } diff --git a/include/deal.II/particles/particle_accessor.h b/include/deal.II/particles/particle_accessor.h index 94c51422c5..0336063e5e 100644 --- a/include/deal.II/particles/particle_accessor.h +++ b/include/deal.II/particles/particle_accessor.h @@ -93,7 +93,7 @@ namespace Particles * function is after particle transfer to a new process. */ void - set_property_pool(PropertyPool &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 &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 diff --git a/include/deal.II/particles/particle_iterator.h b/include/deal.II/particles/particle_iterator.h index 83941dd6b6..c75f2b44b5 100644 --- a/include/deal.II/particles/particle_iterator.h +++ b/include/deal.II/particles/particle_iterator.h @@ -31,6 +31,11 @@ namespace Particles class ParticleIterator: public std::iterator > { 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 &operator * (); + /** + * Assignment operator. + */ + ParticleIterator &operator = (const ParticleIterator &); + /** * Dereferencing operator, returns a pointer of the particle pointed to. Usage * is thus like i->get_id (); diff --git a/include/deal.II/particles/property_pool.h b/include/deal.II/particles/property_pool.h index 176f1bfb0b..1cc4061453 100644 --- a/include/deal.II/particles/property_pool.h +++ b/include/deal.II/particles/property_pool.h @@ -38,7 +38,6 @@ namespace Particles * (e.g. to allow for varying number of properties per handle) without * affecting its interface. */ - template 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 get_properties (const Handle handle); + ArrayView 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 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 index 7d76c9c0e1..0000000000 --- a/include/deal.II/particles/property_pool.templates.h +++ /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 -#include - -DEAL_II_NAMESPACE_OPEN - -namespace Particles -{ - template - const typename PropertyPool::Handle PropertyPool::invalid_handle = NULL; - - - - template - PropertyPool::PropertyPool (const unsigned int n_properties_per_slot) - : - n_properties (n_properties_per_slot) - {} - - - - template - typename PropertyPool::Handle - PropertyPool::allocate_properties_array () - { - return new PropertyType[n_properties]; - } - - - template - void - PropertyPool::deallocate_properties_array (Handle &handle) - { - delete[] handle; - handle = invalid_handle; - } - - - - template - const ArrayView - PropertyPool::get_properties (const Handle handle) - { - Assert(handle != PropertyPool::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(handle, n_properties); - } - - - - template - const ArrayView - PropertyPool::get_properties (const Handle handle) const - { - Assert(handle != PropertyPool::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(handle, n_properties); - } -} - -DEAL_II_NAMESPACE_CLOSE - -#endif diff --git a/source/particles/CMakeLists.txt b/source/particles/CMakeLists.txt index 8eaa91767d..9b0dc52ed9 100644 --- a/source/particles/CMakeLists.txt +++ b/source/particles/CMakeLists.txt @@ -27,7 +27,6 @@ SET(_inst particle.inst.in particle_accessor.inst.in particle_iterator.inst.in - property_pool.inst.in ) FILE(GLOB _header diff --git a/source/particles/particle.cc b/source/particles/particle.cc index b898f21193..2c4ad4515f 100644 --- a/source/particles/particle.cc +++ b/source/particles/particle.cc @@ -19,50 +19,50 @@ DEAL_II_NAMESPACE_OPEN namespace Particles { - template - Particle::Particle () + template + Particle::Particle () : location (), reference_location(), id (0), property_pool(NULL), - properties(PropertyPool::invalid_handle) + properties(PropertyPool::invalid_handle) { } - template - Particle::Particle (const Point &location, - const Point &reference_location, - const types::particle_index id) + template + Particle::Particle (const Point &location, + const Point &reference_location, + const types::particle_index id) : location (location), reference_location (reference_location), id (id), property_pool(NULL), - properties (PropertyPool::invalid_handle) + properties (PropertyPool::invalid_handle) { } - template - Particle::Particle (const Particle &particle) + template + Particle::Particle (const Particle &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::invalid_handle) + properties ((property_pool != NULL) ? property_pool->allocate_properties_array() : PropertyPool::invalid_handle) { if (property_pool != NULL) { - const ArrayView my_properties = property_pool->get_properties(properties); + const ArrayView my_properties = property_pool->get_properties(properties); if (my_properties.size() != 0) { - const ArrayView their_properties = particle.get_properties(); + const ArrayView 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 - Particle::Particle (const void *&data, - PropertyPool *new_property_pool) + template + Particle::Particle (const void *&data, + PropertyPool &new_property_pool) { const types::particle_index *id_data = static_cast (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 (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 (data); + const ArrayView particle_properties = property_pool->get_properties(properties); + for (unsigned int i = 0; i < particle_properties.size(); ++i) + particle_properties[i] = *pdata++; - const ArrayView 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 (property_data); - } + data = static_cast (pdata); } - template - Particle::Particle (Particle &&particle) + template + Particle::Particle (Particle &&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::invalid_handle; + particle.properties = PropertyPool::invalid_handle; } - template - Particle & - Particle::operator=(const Particle &particle) + template + Particle & + Particle::operator=(const Particle &particle) { if (this != &particle) { @@ -133,25 +126,25 @@ namespace Particles if (property_pool != NULL) { properties = property_pool->allocate_properties_array(); - const ArrayView their_properties = particle.get_properties(); + const ArrayView their_properties = particle.get_properties(); if (their_properties.size() != 0) { - const ArrayView my_properties = property_pool->get_properties(properties); + const ArrayView my_properties = property_pool->get_properties(properties); std::copy(&their_properties[0],&their_properties[0]+their_properties.size(),&my_properties[0]); } } else - properties = PropertyPool::invalid_handle; + properties = PropertyPool::invalid_handle; } return *this; } - template - Particle & - Particle::operator=(Particle &&particle) + template + Particle & + Particle::operator=(Particle &&particle) { if (this != &particle) { @@ -160,25 +153,25 @@ namespace Particles id = particle.id; property_pool = particle.property_pool; properties = particle.properties; - particle.properties = PropertyPool::invalid_handle; + particle.properties = PropertyPool::invalid_handle; } return *this; } - template - Particle::~Particle () + template + Particle::~Particle () { - if (properties != PropertyPool::invalid_handle) + if (properties != PropertyPool::invalid_handle) property_pool->deallocate_properties_array(properties); } - template + template void - Particle::write_data (void *&data) const + Particle::write_data (void *&data) const { types::particle_index *id_data = static_cast (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 (pdata); - // Write property data - if (has_properties()) - { - PropertyType *property_data = reinterpret_cast (data); - - const ArrayView 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 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 (pdata); - } + data = static_cast (pdata); } - template + template std::size_t - Particle::size () const + Particle::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 particle_properties = property_pool->get_properties(properties); - size += sizeof(PropertyType) * particle_properties.size(); + const ArrayView particle_properties = property_pool->get_properties(properties); + size += sizeof(double) * particle_properties.size(); } return size; } - template + template void - Particle::set_location (const Point &new_loc) + Particle::set_location (const Point &new_loc) { location = new_loc; } - template + template const Point & - Particle::get_location () const + Particle::get_location () const { return location; } - template + template void - Particle::set_reference_location (const Point &new_loc) + Particle::set_reference_location (const Point &new_loc) { reference_location = new_loc; } - template + template const Point & - Particle::get_reference_location () const + Particle::get_reference_location () const { return reference_location; } - template + template types::particle_index - Particle::get_id () const + Particle::get_id () const { return id; } - template + template void - Particle::set_property_pool (PropertyPool &new_property_pool) + Particle::set_property_pool (PropertyPool &new_property_pool) { property_pool = &new_property_pool; } - template - bool - Particle::has_properties () const + template + void + Particle::set_properties (const ArrayView &new_properties) { - return (property_pool != NULL) - && (properties != PropertyPool::invalid_handle); + if (properties == PropertyPool::invalid_handle) + properties = property_pool->allocate_properties_array(); + + const ArrayView 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 - void - Particle::set_properties (const ArrayView &new_properties) + template + const ArrayView + Particle::get_properties () const { Assert(property_pool != NULL, - ExcMessage("A particle was asked to set its properties without an " - "associated PropertyPool.")) - - if (properties == PropertyPool::invalid_handle) - properties = property_pool->allocate_properties_array(); + ExcInternalError()); - const ArrayView 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 - const ArrayView - Particle::get_properties () const + template + const ArrayView + Particle::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 - const ArrayView - Particle::get_properties () + template + bool + Particle::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); } } diff --git a/source/particles/particle.inst.in b/source/particles/particle.inst.in index 1f1327202a..bf68675593 100644 --- a/source/particles/particle.inst.in +++ b/source/particles/particle.inst.in @@ -14,13 +14,13 @@ // --------------------------------------------------------------------- -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 ; + class Particle ; \} #endif } diff --git a/source/particles/particle_accessor.cc b/source/particles/particle_accessor.cc index 16bbd14c65..ea82fedfd1 100644 --- a/source/particles/particle_accessor.cc +++ b/source/particles/particle_accessor.cc @@ -19,6 +19,15 @@ DEAL_II_NAMESPACE_OPEN namespace Particles { + template + ParticleAccessor::ParticleAccessor () + : + map (NULL), + particle () + {} + + + template ParticleAccessor::ParticleAccessor (const std::multimap > &map, const typename std::multimap >::iterator &particle) @@ -103,7 +112,7 @@ namespace Particles template void - ParticleAccessor::set_property_pool (PropertyPool &new_property_pool) + ParticleAccessor::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(&(new_properties[0]),new_properties.size())); + particle->second.set_properties(new_properties); return; } @@ -167,12 +176,12 @@ namespace Particles template std::size_t - ParticleAccessor::size () const + ParticleAccessor::serialized_size_in_bytes () const { Assert(particle != map->end(), ExcInternalError()); - return particle->second.size(); + return particle->second.serialized_size_in_bytes(); } diff --git a/source/particles/particle_iterator.cc b/source/particles/particle_iterator.cc index 4fa7873382..bdcba3020a 100644 --- a/source/particles/particle_iterator.cc +++ b/source/particles/particle_iterator.cc @@ -19,6 +19,14 @@ DEAL_II_NAMESPACE_OPEN namespace Particles { + template + ParticleIterator::ParticleIterator () + : + accessor () + {} + + + template ParticleIterator::ParticleIterator (const std::multimap > &map, const typename std::multimap >::iterator &particle) @@ -63,6 +71,15 @@ namespace Particles } + template + ParticleIterator & + ParticleIterator::operator =(const ParticleIterator &other) + { + accessor = other.accessor; + return *this; + } + + template bool diff --git a/source/particles/property_pool.cc b/source/particles/property_pool.cc index a11d773c86..68b13ed192 100644 --- a/source/particles/property_pool.cc +++ b/source/particles/property_pool.cc @@ -14,10 +14,58 @@ // --------------------------------------------------------------------- -#include +#include 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 + PropertyPool::get_properties (const Handle handle) + { + return ArrayView(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 index 974d14254e..0000000000 --- a/source/particles/property_pool.inst.in +++ /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 ; - \} -} diff --git a/tests/particles/particle_03.cc b/tests/particles/particle_03.cc index 9a9e04d2ce..aaa6a882bf 100644 --- a/tests/particles/particle_03.cc +++ b/tests/particles/particle_03.cc @@ -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; diff --git a/tests/particles/property_pool_01.cc b/tests/particles/property_pool_01.cc index e178ca8705..e078ed98ec 100644 --- a/tests/particles/property_pool_01.cc +++ b/tests/particles/property_pool_01.cc @@ -23,13 +23,12 @@ #include -template void test () { { - Particles::PropertyPool pool; + Particles::PropertyPool pool; - typename Particles::PropertyPool::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(); - test(); + test(); } diff --git a/tests/particles/property_pool_01.output b/tests/particles/property_pool_01.output index fdb9accf31..0fb52adf90 100644 --- a/tests/particles/property_pool_01.output +++ b/tests/particles/property_pool_01.output @@ -1,5 +1,3 @@ DEAL::Pool properties: 2.50000 DEAL::OK -DEAL::Pool properties: 2.50000 -DEAL::OK diff --git a/tests/particles/property_pool_02.cc b/tests/particles/property_pool_02.cc index f60f69b8e6..256721e9f3 100644 --- a/tests/particles/property_pool_02.cc +++ b/tests/particles/property_pool_02.cc @@ -23,14 +23,13 @@ #include -template void test () { { const unsigned int n_properties = 3; - Particles::PropertyPool pool(n_properties); + Particles::PropertyPool pool(n_properties); - typename Particles::PropertyPool::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(); - test(); + test(); } diff --git a/tests/particles/property_pool_02.output b/tests/particles/property_pool_02.output index 80f767455c..f514eabca2 100644 --- a/tests/particles/property_pool_02.output +++ b/tests/particles/property_pool_02.output @@ -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 index 48570962f3..0000000000 --- a/tests/particles/property_pool_03.cc +++ /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 -#include -#include - - - -struct DataType -{ - double a[2]; - char c; - double *pointer; -}; - -void test () -{ - { - double b[2] = {0.7,1.3}; - - Particles::PropertyPool pool; - - typename Particles::PropertyPool::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 index bf8cb587f1..0000000000 --- a/tests/particles/property_pool_03.output +++ /dev/null @@ -1,3 +0,0 @@ - -DEAL::Pool properties: 2.50000 2.00000 f 1.30000 -DEAL::OK