From 89ad022f0417e80ae5bd999ce326ee5e3d2ff4db Mon Sep 17 00:00:00 2001
From: Sebastian Eibl <sebastian.eibl@fau.de>
Date: Thu, 16 Aug 2018 15:43:22 +0200
Subject: [PATCH] added helper function to retrive total number of master and
 shadow particles

---
 src/pe/utility/GetInfo.cpp | 56 ++++++++++++++++++++++++++++++++++++++
 src/pe/utility/GetInfo.h   | 34 +++++++++++++++++++++++
 2 files changed, 90 insertions(+)
 create mode 100644 src/pe/utility/GetInfo.cpp
 create mode 100644 src/pe/utility/GetInfo.h

diff --git a/src/pe/utility/GetInfo.cpp b/src/pe/utility/GetInfo.cpp
new file mode 100644
index 000000000..776f4cbef
--- /dev/null
+++ b/src/pe/utility/GetInfo.cpp
@@ -0,0 +1,56 @@
+//======================================================================================================================
+//
+//  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 GetInfo.cpp
+//! \author Sebastian Eibl <sebastian.eibl@fau.de>
+//
+//======================================================================================================================
+
+#include "GetInfo.h"
+
+#include "core/debug/Debug.h"
+#include <core/mpi/Reduce.h>
+#include <pe/rigidbody/BodyStorage.h>
+#include <pe/Types.h>
+
+namespace walberla {
+namespace pe {
+
+std::pair<int64_t, int64_t> getNumBodies( const domain_decomposition::BlockStorage& bs, const BlockDataID& storageID, const int rank )
+{
+   int64_t numParticles       = 0;
+   int64_t numShadowParticles = 0;
+   for (const auto& blk : bs)
+   {
+      Storage const * storage = blk.getData< Storage >( storageID );
+      const BodyStorage& localStorage = (*storage)[0];
+      const BodyStorage& shadowStorage = (*storage)[1];
+      numParticles += localStorage.size();
+      numShadowParticles += shadowStorage.size();
+   }
+   if (rank == -1)
+   {
+      mpi::allReduceInplace(numParticles, mpi::SUM);
+      mpi::allReduceInplace(numShadowParticles, mpi::SUM);
+   } else
+   {
+      mpi::reduceInplace(numParticles, mpi::SUM, rank);
+      mpi::reduceInplace(numShadowParticles, mpi::SUM, rank);
+   }
+   return std::make_pair(numParticles, numShadowParticles);
+}
+
+}  // namespace pe
+}  // namespace walberla
diff --git a/src/pe/utility/GetInfo.h b/src/pe/utility/GetInfo.h
new file mode 100644
index 000000000..7952f19d3
--- /dev/null
+++ b/src/pe/utility/GetInfo.h
@@ -0,0 +1,34 @@
+//======================================================================================================================
+//
+//  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 GetInfo.h
+//! \author Sebastian Eibl <sebastian.eibl@fau.de>
+//
+//======================================================================================================================
+
+#pragma once
+
+#include <core/DataTypes.h>
+#include <domain_decomposition/BlockStorage.h>
+
+#include <utility>
+
+namespace walberla {
+namespace pe {
+
+std::pair<int64_t, int64_t> getNumBodies( const domain_decomposition::BlockStorage& bs, const BlockDataID& storageID, const int rank = -1);
+
+}  // namespace pe
+}  // namespace walberla
-- 
GitLab