From 56276b308f5682f3d292cc7046341bcd9810b326 Mon Sep 17 00:00:00 2001 From: Sebastian Eibl <sebastian.eibl@fau.de> Date: Thu, 6 Jun 2019 17:46:38 +0200 Subject: [PATCH] [API] added reset function to ReduceProperty --- apps/tutorials/mesa_pd/01_LennardJones.cpp | 6 ++-- .../templates/mpi/ReduceProperty.templ.h | 2 ++ .../ContactHistoryNotification.templ.h | 7 ++++ .../ForceTorqueNotification.templ.h | 8 +++++ src/mesa_pd/mpi/ReduceProperty.h | 2 ++ .../ContactHistoryNotification.h | 7 ++++ .../notifications/ForceTorqueNotification.h | 8 +++++ src/mesa_pd/mpi/notifications/reset.h | 35 +++++++++++++++++++ tests/mesa_pd/mpi/ReduceProperty.cpp | 2 +- 9 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 src/mesa_pd/mpi/notifications/reset.h diff --git a/apps/tutorials/mesa_pd/01_LennardJones.cpp b/apps/tutorials/mesa_pd/01_LennardJones.cpp index eec37960f..6ed34ccab 100644 --- a/apps/tutorials/mesa_pd/01_LennardJones.cpp +++ b/apps/tutorials/mesa_pd/01_LennardJones.cpp @@ -89,15 +89,15 @@ int main( int argc, char ** argv ) WALBERLA_LOG_DEVEL(timestep); linkedCells.clear(); storage->forEachParticle(true, kernel::SelectAll(), ac, ipilc, ac, linkedCells); - storage->forEachParticle(true, kernel::SelectAll(), ac, vvPreForce, ac); + storage->forEachParticle(true, kernel::SelectLocal(), ac, vvPreForce, ac); linkedCells.forEachParticlePairHalf(true, kernel::SelectAll(), ac, lj, ac); const real_t coeff = real_t(0.2); storage->forEachParticle(true, - kernel::SelectAll(), + kernel::SelectLocal(), ac, [coeff](const size_t idx, auto& access){ access.setForce(idx, -coeff*access.getPosition(idx) + access.getForce(idx)); }, ac); - storage->forEachParticle(true, kernel::SelectAll(), ac, vvPostForce, ac); + storage->forEachParticle(true, kernel::SelectLocal(), ac, vvPostForce, ac); vtkWriter->write(); } diff --git a/python/mesa_pd/templates/mpi/ReduceProperty.templ.h b/python/mesa_pd/templates/mpi/ReduceProperty.templ.h index 99eab36d7..38f734085 100644 --- a/python/mesa_pd/templates/mpi/ReduceProperty.templ.h +++ b/python/mesa_pd/templates/mpi/ReduceProperty.templ.h @@ -29,6 +29,7 @@ #include <mesa_pd/data/DataTypes.h> #include <mesa_pd/data/Flags.h> #include <mesa_pd/data/ParticleStorage.h> +#include <mesa_pd/mpi/notifications/reset.h> #include <core/mpi/BufferSystem.h> #include <core/logging/Logging.h> @@ -100,6 +101,7 @@ void ReduceProperty::operator()(data::ParticleStorage& ps) const } sb << Notification( p ); + reset<Notification>( p ); } else { //local particles should receive the property and sum it up diff --git a/python/mesa_pd/templates/mpi/notifications/ContactHistoryNotification.templ.h b/python/mesa_pd/templates/mpi/notifications/ContactHistoryNotification.templ.h index 15ab081fd..2ffca67a2 100644 --- a/python/mesa_pd/templates/mpi/notifications/ContactHistoryNotification.templ.h +++ b/python/mesa_pd/templates/mpi/notifications/ContactHistoryNotification.templ.h @@ -28,6 +28,7 @@ #include <mesa_pd/data/ContactHistory.h> #include <mesa_pd/data/DataTypes.h> +#include <mesa_pd/mpi/notifications/reset.h> #include <core/mpi/BufferDataTypeExtensions.h> #include <core/mpi/Datatype.h> @@ -56,6 +57,12 @@ public: const data::Particle& p_; }; +template <> +void reset<ContactHistoryNotification>(data::Particle& p) +{ + p.setNewContactHistory(std::map<walberla::id_t, walberla::mesa_pd::data::ContactHistory>()); +} + void reduce(data::Particle&& p, const ContactHistoryNotification::Parameters& objparam) { auto& ch = p.getNewContactHistoryRef(); diff --git a/python/mesa_pd/templates/mpi/notifications/ForceTorqueNotification.templ.h b/python/mesa_pd/templates/mpi/notifications/ForceTorqueNotification.templ.h index f00db9e42..6bfa6412b 100644 --- a/python/mesa_pd/templates/mpi/notifications/ForceTorqueNotification.templ.h +++ b/python/mesa_pd/templates/mpi/notifications/ForceTorqueNotification.templ.h @@ -29,6 +29,7 @@ #include <mesa_pd/data/DataTypes.h> #include <mesa_pd/data/ParticleStorage.h> #include <mesa_pd/mpi/notifications/NotificationType.h> +#include <mesa_pd/mpi/notifications/reset.h> #include <core/mpi/Datatype.h> #include <core/mpi/RecvBuffer.h> @@ -55,6 +56,13 @@ public: const data::Particle& p_; }; +template <> +void reset<ForceTorqueNotification>(data::Particle& p) +{ + p.setForce( Vec3(real_t(0)) ); + p.setTorque( Vec3(real_t(0)) ); +} + void reduce(data::Particle&& p, const ForceTorqueNotification::Parameters& objparam) { p.getForceRef() += objparam.force_; diff --git a/src/mesa_pd/mpi/ReduceProperty.h b/src/mesa_pd/mpi/ReduceProperty.h index 22ca078f1..7f55c3349 100644 --- a/src/mesa_pd/mpi/ReduceProperty.h +++ b/src/mesa_pd/mpi/ReduceProperty.h @@ -29,6 +29,7 @@ #include <mesa_pd/data/DataTypes.h> #include <mesa_pd/data/Flags.h> #include <mesa_pd/data/ParticleStorage.h> +#include <mesa_pd/mpi/notifications/reset.h> #include <core/mpi/BufferSystem.h> #include <core/logging/Logging.h> @@ -100,6 +101,7 @@ void ReduceProperty::operator()(data::ParticleStorage& ps) const } sb << Notification( p ); + reset<Notification>( p ); } else { //local particles should receive the property and sum it up diff --git a/src/mesa_pd/mpi/notifications/ContactHistoryNotification.h b/src/mesa_pd/mpi/notifications/ContactHistoryNotification.h index c306f6c89..b177f313c 100644 --- a/src/mesa_pd/mpi/notifications/ContactHistoryNotification.h +++ b/src/mesa_pd/mpi/notifications/ContactHistoryNotification.h @@ -28,6 +28,7 @@ #include <mesa_pd/data/ContactHistory.h> #include <mesa_pd/data/DataTypes.h> +#include <mesa_pd/mpi/notifications/reset.h> #include <core/mpi/BufferDataTypeExtensions.h> #include <core/mpi/Datatype.h> @@ -56,6 +57,12 @@ public: const data::Particle& p_; }; +template <> +void reset<ContactHistoryNotification>(data::Particle& p) +{ + p.setNewContactHistory(std::map<walberla::id_t, walberla::mesa_pd::data::ContactHistory>()); +} + void reduce(data::Particle&& p, const ContactHistoryNotification::Parameters& objparam) { auto& ch = p.getNewContactHistoryRef(); diff --git a/src/mesa_pd/mpi/notifications/ForceTorqueNotification.h b/src/mesa_pd/mpi/notifications/ForceTorqueNotification.h index c46f58724..d19d0d084 100644 --- a/src/mesa_pd/mpi/notifications/ForceTorqueNotification.h +++ b/src/mesa_pd/mpi/notifications/ForceTorqueNotification.h @@ -29,6 +29,7 @@ #include <mesa_pd/data/DataTypes.h> #include <mesa_pd/data/ParticleStorage.h> #include <mesa_pd/mpi/notifications/NotificationType.h> +#include <mesa_pd/mpi/notifications/reset.h> #include <core/mpi/Datatype.h> #include <core/mpi/RecvBuffer.h> @@ -55,6 +56,13 @@ public: const data::Particle& p_; }; +template <> +void reset<ForceTorqueNotification>(data::Particle& p) +{ + p.setForce( Vec3(real_t(0)) ); + p.setTorque( Vec3(real_t(0)) ); +} + void reduce(data::Particle&& p, const ForceTorqueNotification::Parameters& objparam) { p.getForceRef() += objparam.force_; diff --git a/src/mesa_pd/mpi/notifications/reset.h b/src/mesa_pd/mpi/notifications/reset.h new file mode 100644 index 000000000..24bab4533 --- /dev/null +++ b/src/mesa_pd/mpi/notifications/reset.h @@ -0,0 +1,35 @@ +//====================================================================================================================== +// +// This file is part of waLBerla. waLBerla is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// waLBerla is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file reset.h +//! \author Sebastian Eibl <sebastian.eibl@fau.de> +// +//====================================================================================================================== + +#pragma once + +#include <mesa_pd/data/ParticleStorage.h> + +namespace walberla { +namespace mesa_pd { + +template <class Notification> +void reset(data::Particle& /*p*/) +{ + WALBERLA_ABORT("not implemented!"); +} + +} // mpi +} // walberla diff --git a/tests/mesa_pd/mpi/ReduceProperty.cpp b/tests/mesa_pd/mpi/ReduceProperty.cpp index 300fc5dc1..50c5b7783 100644 --- a/tests/mesa_pd/mpi/ReduceProperty.cpp +++ b/tests/mesa_pd/mpi/ReduceProperty.cpp @@ -95,7 +95,7 @@ void main( int argc, char ** argv ) WALBERLA_CHECK_FLOAT_EQUAL( pIt->getForce(), Vec3(real_t(28)) ); } else { - WALBERLA_CHECK_FLOAT_EQUAL( pIt->getForce(), Vec3(real_t(walberla::mpi::MPIManager::instance()->rank())) ); + WALBERLA_CHECK_FLOAT_EQUAL( pIt->getForce(), Vec3(0) ); } } -- GitLab