From 539237b0a0a5a29a142a40c94fcbae98f4da9de5 Mon Sep 17 00:00:00 2001 From: Sebastian Eibl <sebastian.eibl@fau.de> Date: Tue, 3 Nov 2020 10:25:03 +0100 Subject: [PATCH] added unit test for infinite domain --- src/mesa_pd/domain/InfiniteDomain.h | 18 ++++++-- tests/mesa_pd/CMakeLists.txt | 3 ++ tests/mesa_pd/domain/InfiniteDomain.cpp | 60 +++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 tests/mesa_pd/domain/InfiniteDomain.cpp diff --git a/src/mesa_pd/domain/InfiniteDomain.h b/src/mesa_pd/domain/InfiniteDomain.h index b9dc4f322..591da8902 100644 --- a/src/mesa_pd/domain/InfiniteDomain.h +++ b/src/mesa_pd/domain/InfiniteDomain.h @@ -20,22 +20,34 @@ #pragma once +#include <core/mpi/MPIManager.h> #include <mesa_pd/domain/IDomain.h> namespace walberla { namespace mesa_pd { namespace domain { +/** + * Every process assumes the whole simulation space belongs to its subdomain. + */ class InfiniteDomain : public IDomain { public: - bool isContainedInProcessSubdomain(const uint_t /*rank*/, const Vec3& /*pt*/) const override {return true;} - int findContainingProcessRank(const Vec3& /*pt*/) const override {return walberla::mpi::MPIManager::instance()->rank();} + ///Everything belongs to the calling process. + bool isContainedInProcessSubdomain(const uint_t rank, const Vec3& /*pt*/) const override {return rank==rank_;} + ///Everything belongs to the calling process. + int findContainingProcessRank(const Vec3& /*pt*/) const override {return static_cast<int>(rank_);} + ///Nothing to do here since domain is infinite. void periodicallyMapToDomain(Vec3& /*pt*/) const override {} + ///If I own everything I do not have neighbors. std::vector<uint_t> getNeighborProcesses() const override {return {};} + ///Everything belongs to my subdomain. bool intersectsWithProcessSubdomain(const uint_t rank, const Vec3& /*pt*/, const real_t& /*radius*/) const override - { return int_c(rank)==walberla::mpi::MPIManager::instance()->rank() ? true : false;} + { return rank==rank_;} + ///Nothing to do here. void correctParticlePosition(Vec3& /*pt*/) const override {} +private: + const uint_t rank_ = static_cast<uint_t>(MPIManager::instance()->rank()); }; } //namespace domain diff --git a/tests/mesa_pd/CMakeLists.txt b/tests/mesa_pd/CMakeLists.txt index ad034a098..6bbc471dc 100644 --- a/tests/mesa_pd/CMakeLists.txt +++ b/tests/mesa_pd/CMakeLists.txt @@ -66,6 +66,9 @@ waLBerla_execute_test( NAME MESA_PD_Domain_DistanceCalculation ) waLBerla_compile_test( NAME MESA_PD_Domain_DynamicRefinement FILES domain/DynamicRefinement.cpp DEPENDS blockforest core pe ) waLBerla_execute_test( NAME MESA_PD_Domain_DynamicRefinement PROCESSES 8) +waLBerla_compile_test( NAME MESA_PD_Domain_InfiniteDomain FILES domain/InfiniteDomain.cpp DEPENDS core ) +waLBerla_execute_test( NAME MESA_PD_Domain_InfiniteDomain ) + waLBerla_compile_test( NAME MESA_PD_Domain_SerializeDeserialize FILES domain/SerializeDeserialize.cpp DEPENDS blockforest core pe) waLBerla_execute_test( NAME MESA_PD_Domain_SerializeDeserialize PROCESSES 8 ) diff --git a/tests/mesa_pd/domain/InfiniteDomain.cpp b/tests/mesa_pd/domain/InfiniteDomain.cpp new file mode 100644 index 000000000..74dee98a9 --- /dev/null +++ b/tests/mesa_pd/domain/InfiniteDomain.cpp @@ -0,0 +1,60 @@ +//====================================================================================================================== +// +// 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 InfiniteDomain.cpp +//! \author Sebastian Eibl <sebastian.eibl@fau.de> +// +//====================================================================================================================== + +#include <mesa_pd/domain/InfiniteDomain.h> + +#include <core/Environment.h> +#include <core/logging/Logging.h> + +#include <iostream> + +namespace walberla { + +using namespace walberla::mesa_pd; + +void main( int argc, char ** argv ) +{ + Environment env(argc, argv); + WALBERLA_UNUSED(env); + mpi::MPIManager::instance()->useWorldComm(); + auto rank = mpi::MPIManager::instance()->rank(); + + auto randomPoint = Vec3(1.23_r,2.34_r,3.45_r); + domain::InfiniteDomain domain; + WALBERLA_CHECK(domain.isContainedInProcessSubdomain(static_cast<uint_t>(rank), randomPoint)); + WALBERLA_CHECK(!domain.isContainedInProcessSubdomain(static_cast<uint_t>(rank + 1), randomPoint)); + WALBERLA_CHECK_EQUAL(domain.findContainingProcessRank(randomPoint), rank); + auto pt = randomPoint; + domain.periodicallyMapToDomain(pt); + WALBERLA_CHECK_IDENTICAL(pt, randomPoint); + WALBERLA_CHECK_EQUAL(domain.getNeighborProcesses().size(), 0); + WALBERLA_CHECK(domain.intersectsWithProcessSubdomain(static_cast<uint_t>(rank), randomPoint, 1_r)); + WALBERLA_CHECK(!domain.intersectsWithProcessSubdomain(static_cast<uint_t>(rank + 1), randomPoint, 1_r)); + domain.correctParticlePosition(pt); + WALBERLA_CHECK_IDENTICAL(pt, randomPoint); +} + +} + +int main( int argc, char ** argv ) +{ + walberla::main(argc, argv); + return EXIT_SUCCESS; +} -- GitLab