From 1bc454a244fe6eb48c3c9a73ebccbd9a32202d5f Mon Sep 17 00:00:00 2001
From: Christoph Rettinger <christoph.rettinger@fau.de>
Date: Tue, 23 Feb 2021 09:25:04 +0100
Subject: [PATCH] Minor updates in fp coupling functionalities

---
 .../MovingParticleMapping.h                   | 19 +++++++++++--------
 .../utility/InspectionProbe.h                 |  7 ++++++-
 .../utility/ParticleSelector.h                |  4 +++-
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/lbm_mesapd_coupling/momentum_exchange_method/MovingParticleMapping.h b/src/lbm_mesapd_coupling/momentum_exchange_method/MovingParticleMapping.h
index 29c161d4f..88d311236 100644
--- a/src/lbm_mesapd_coupling/momentum_exchange_method/MovingParticleMapping.h
+++ b/src/lbm_mesapd_coupling/momentum_exchange_method/MovingParticleMapping.h
@@ -165,9 +165,9 @@ private:
                      }
 
                   }
-
-                  // cell is already an obstacle (maybe from another particle)
-                  if( isFlagSet( cellFlagPtr, obstacle ) ) {
+                  else if( isFlagSet( cellFlagPtr, obstacle ) )
+                  {
+                     // cell is already an obstacle (maybe from another particle)
                      auto formerParticleUid = (*particleField)(x, y, z);
                      auto formerParticleIdx = ac_->uidToIdx(formerParticleUid);
                      if(!isSet(ac_->getFlags(formerParticleIdx), mesa_pd::data::particle_flags::FIXED) )
@@ -179,10 +179,9 @@ private:
                         (*particleField)(x, y, z) = particleUid;
                      }
                   }
-
-                  // cell is a former obstacle cell (maybe from another particle that has moved away)
-                  if( isFlagSet( cellFlagPtr, formerObstacle ) )
+                  else if( isFlagSet( cellFlagPtr, formerObstacle ) )
                   {
+                     // cell is a former obstacle cell (maybe from another particle that has moved away)
                      boundaryHandling->setBoundary( obstacle, x, y, z );
                      removeFlag( cellFlagPtr, formerObstacle );
                      (*particleField)(x, y, z) = particleUid;
@@ -333,8 +332,12 @@ private:
             {
                if( singleCast(particleIdx, ac, containsPointFctr, ac, Vector3<real_t>(cx,cy,cz)) )
                {
-                  boundaryHandling->forceBoundary(obstacleFlag, x, y, z);
-                  (*particleField)(x,y,z) = ac.getUid(particleIdx);
+                  if(boundaryHandling->isDomain(x,y,z))
+                  {
+                     boundaryHandling->forceBoundary(obstacleFlag, x, y, z);
+                     (*particleField)(x,y,z) = ac.getUid(particleIdx);
+                  }
+                  // no else -> will not overwrite pre-existing boundary cells, e.g. of previously applied applied mapping (e.g. when first mapping global particles)
                }
                cx += dx;
             }
diff --git a/src/lbm_mesapd_coupling/utility/InspectionProbe.h b/src/lbm_mesapd_coupling/utility/InspectionProbe.h
index 4513cdfaf..b2644017f 100644
--- a/src/lbm_mesapd_coupling/utility/InspectionProbe.h
+++ b/src/lbm_mesapd_coupling/utility/InspectionProbe.h
@@ -74,6 +74,11 @@ public:
       }
    }
 
+   void setPosition(Vector3<real_t> probeLocation)
+   {
+      probeLocation_ = probeLocation;
+   }
+
 private:
 
    void printStatusOfCellSurrounding(Cell centerCell, const IBlock& block)
@@ -121,7 +126,7 @@ private:
 
    void printToScreen(bool isFluid, real_t rho, Vector3<real_t> velocity)
    {
-      if(printToScreen_) WALBERLA_LOG_INFO("Values in probe at position " << probeLocation_ << ": " << (isFluid?"F":"P") << ", rho = " << rho << ", velocity = " << velocity);
+      if(printToScreen_) WALBERLA_LOG_INFO("Values in probe at position " << probeLocation_ << " on rank " << mpi::MPIManager::instance()->rank() << ": " << (isFluid?"F":"P") << ", rho = " << rho << ", velocity = " << velocity);
    }
 
    void writeToFile(bool isFluid, real_t rho, Vector3<real_t> velocity)
diff --git a/src/lbm_mesapd_coupling/utility/ParticleSelector.h b/src/lbm_mesapd_coupling/utility/ParticleSelector.h
index 9baf0a4a1..a18a91af4 100644
--- a/src/lbm_mesapd_coupling/utility/ParticleSelector.h
+++ b/src/lbm_mesapd_coupling/utility/ParticleSelector.h
@@ -24,6 +24,7 @@
 #include "mesa_pd/data/Flags.h"
 #include "mesa_pd/data/IAccessor.h"
 #include "mesa_pd/data/shape/Sphere.h"
+#include "mesa_pd/kernel/ParticleSelector.h"
 
 namespace walberla {
 namespace lbm_mesapd_coupling {
@@ -76,8 +77,9 @@ struct StokesNumberBasedSphereSelector
       static_assert(std::is_base_of<mesa_pd::data::IAccessor, ParticleAccessor_T>::value, "Provide a valid accessor as template");
 
       lbm_mesapd_coupling::RegularParticlesSelector regularParticlesSelector;
+      mesa_pd::kernel::SelectLocal localParticlesSelector;
 
-      if(regularParticlesSelector(particleIdx, ac))
+      if(regularParticlesSelector(particleIdx, ac) && localParticlesSelector(particleIdx, ac))
       {
          // check for non-fixed spheres
          if( ac.getShape(particleIdx)->getShapeType() == mesa_pd::data::Sphere::SHAPE_TYPE )
-- 
GitLab