From: Rene Gassmoeller Date: Thu, 31 Jan 2019 18:24:06 +0000 (-0800) Subject: Ensure particle property initialization X-Git-Tag: v9.1.0-rc1~380^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F7666%2Fhead;p=dealii.git Ensure particle property initialization --- diff --git a/source/particles/particle.cc b/source/particles/particle.cc index 03f90811b3..b426aac4cc 100644 --- a/source/particles/particle.cc +++ b/source/particles/particle.cc @@ -328,8 +328,16 @@ namespace Particles { Assert(property_pool != nullptr, ExcInternalError()); + // If this particle has no properties yet, allocate and initialize them. if (properties == PropertyPool::invalid_handle) - properties = property_pool->allocate_properties_array(); + { + properties = property_pool->allocate_properties_array(); + + ArrayView my_properties = + property_pool->get_properties(properties); + + std::fill(my_properties.begin(), my_properties.end(), 0.0); + } return property_pool->get_properties(properties); } diff --git a/tests/particles/particle_07.cc b/tests/particles/particle_07.cc new file mode 100644 index 0000000000..0df754f23f --- /dev/null +++ b/tests/particles/particle_07.cc @@ -0,0 +1,64 @@ +// --------------------------------------------------------------------- +// +// 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + + +// Like particle_03, but test property initialization. + +#include + +#include + +#include "../tests.h" + + +template +void +test() +{ + { + const unsigned int n_properties_per_particle = 3; + Particles::PropertyPool pool(n_properties_per_particle); + + Point<2> position; + position(0) = 0.3; + position(1) = 0.5; + + Point<2> reference_position; + reference_position(0) = 0.2; + reference_position(1) = 0.4; + + const types::particle_index index(7); + + std::vector properties = {0.15, 0.45, 0.75}; + + Particles::Particle<2> particle(position, reference_position, index); + particle.set_property_pool(pool); + + for (unsigned int i = 0; i < n_properties_per_particle; ++i) + AssertThrow(particle.get_properties()[i] == 0.0, ExcInternalError()); + } + + deallog << "OK" << std::endl; +} + + + +int +main() +{ + initlog(); + test<2>(); +} diff --git a/tests/particles/particle_07.output b/tests/particles/particle_07.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/particles/particle_07.output @@ -0,0 +1,2 @@ + +DEAL::OK