From: Rene Gassmoeller Date: Mon, 25 Sep 2017 17:35:32 +0000 (-0600) Subject: Address comments, add test for ParticleIterator and ParticleAccessor X-Git-Tag: v9.0.0-rc1~1013^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d51b1ef00ead211619eb1e0c67b6529b5cd609d;p=dealii.git Address comments, add test for ParticleIterator and ParticleAccessor --- diff --git a/include/deal.II/particles/particle_accessor.h b/include/deal.II/particles/particle_accessor.h index 0336063e5e..bdb7aff9d1 100644 --- a/include/deal.II/particles/particle_accessor.h +++ b/include/deal.II/particles/particle_accessor.h @@ -18,7 +18,7 @@ #include #include -#include +#include DEAL_II_NAMESPACE_OPEN @@ -141,8 +141,8 @@ namespace Particles * but the triangulation itself is not stored in the particle this * operation requires a reference to the triangulation. */ - typename parallel::distributed::Triangulation::cell_iterator - get_surrounding_cell (const parallel::distributed::Triangulation &triangulation) const; + typename Triangulation::cell_iterator + get_surrounding_cell (const Triangulation &triangulation) const; /** * Serialize the contents of this class. @@ -189,19 +189,18 @@ namespace Particles * A pointer to the container that stores the particles. Obviously, * this accessor is invalidated if the container changes. */ - std::multimap > *map; + std::multimap > *map; /** * An iterator into the container of particles. Obviously, - * this accessor is invalidated if the container changes. + * this accessor is invalidated if the container changes. */ - typename std::multimap >::iterator particle; + typename std::multimap >::iterator particle; /** * Make ParticleIterator a friend to allow it constructing ParticleAccessors. */ template friend class ParticleIterator; - template friend class ParticleHandler; }; } diff --git a/source/particles/particle_accessor.cc b/source/particles/particle_accessor.cc index ea82fedfd1..42fabc1469 100644 --- a/source/particles/particle_accessor.cc +++ b/source/particles/particle_accessor.cc @@ -148,13 +148,13 @@ namespace Particles template - typename parallel::distributed::Triangulation::cell_iterator - ParticleAccessor::get_surrounding_cell (const parallel::distributed::Triangulation &triangulation) const + typename Triangulation::cell_iterator + ParticleAccessor::get_surrounding_cell (const Triangulation &triangulation) const { Assert(particle != map->end(), ExcInternalError()); - const typename parallel::distributed::Triangulation::cell_iterator cell (&triangulation, + const typename Triangulation::cell_iterator cell (&triangulation, particle->first.first, particle->first.second); return cell; diff --git a/tests/particles/particle_iterator_01.cc b/tests/particles/particle_iterator_01.cc new file mode 100644 index 0000000000..67ccd4597f --- /dev/null +++ b/tests/particles/particle_iterator_01.cc @@ -0,0 +1,86 @@ +// --------------------------------------------------------------------- +// +// 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. +// +// --------------------------------------------------------------------- + + + +// Like particle_03, but tests the creation and use of a +// particle iterator from the created particle. + +#include "../tests.h" +#include +#include + +#include + + +template +void test () +{ + { + const unsigned int n_properties_per_particle = 3; + Particles::PropertyPool pool(n_properties_per_particle); + + Point position; + position(0) = 0.3; + + if (dim>1) + position(1) = 0.5; + + Point reference_position; + reference_position(0) = 0.2; + + if (dim>1) + reference_position(1) = 0.4; + + const Particles::types::particle_index index(7); + + std::vector properties = {0.15,0.45,0.75}; + + Particles::Particle particle(position,reference_position,index); + particle.set_property_pool(pool); + particle.set_properties(ArrayView(&properties[0],properties.size())); + + std::multimap > map; + + Particles::types::LevelInd level_index = std::make_pair(0,0); + map.insert(std::make_pair(level_index,particle)); + + particle.get_properties()[0] = 0.05; + map.insert(std::make_pair(level_index,particle)); + + Particles::ParticleIterator particle_it (map,map.begin()); + Particles::ParticleIterator particle_end (map,map.end()); + + for (; particle_it != particle_end; ++particle_it) + { + deallog << "Particle position: " + << (*particle_it).get_location() + << std::endl + << "Particle properties: " + << std::vector(particle_it->get_properties().begin(),particle_it->get_properties().end()) + << std::endl; + } + } + + deallog << "OK" << std::endl; +} + + + +int main () +{ + initlog(); + test<2>(); +} diff --git a/tests/particles/particle_iterator_01.output b/tests/particles/particle_iterator_01.output new file mode 100644 index 0000000000..777a4e2eaa --- /dev/null +++ b/tests/particles/particle_iterator_01.output @@ -0,0 +1,6 @@ + +DEAL::Particle position: 0.300000 0.500000 +DEAL::Particle properties: 0.150000 0.450000 0.750000 +DEAL::Particle position: 0.300000 0.500000 +DEAL::Particle properties: 0.0500000 0.450000 0.750000 +DEAL::OK