From b6d9aaa0ab82b0dcaa482ea0337a514814f8cd00 Mon Sep 17 00:00:00 2001
From: Konstantin Kutscher <kutscher@irmb.tu-bs.de>
Date: Thu, 4 Oct 2018 10:55:50 +0200
Subject: [PATCH] fix using of pe::SystemId parallel

---
 source/Applications/Thermoplast/config.txt    |  4 +--
 .../Applications/Thermoplast/thermoplast.cpp  |  2 +-
 .../CreateDemObjectsCoProcessor.cpp           | 10 +++----
 .../DemCoupling/CreateDemObjectsCoProcessor.h |  2 +-
 source/DemCoupling/DemCoProcessor.cpp         | 26 +++++++++----------
 .../pe/PePhysicsEngineGeometryAdapter.h       |  8 +++---
 .../pe/PePhysicsEngineSolverAdapter.cpp       |  4 +--
 .../VirtualFluidsCore/Parallel/Communicator.h |  2 ++
 .../Parallel/MPICommunicator.cpp              | 10 +++++++
 .../Parallel/MPICommunicator.h                |  4 +++
 10 files changed, 45 insertions(+), 27 deletions(-)

diff --git a/source/Applications/Thermoplast/config.txt b/source/Applications/Thermoplast/config.txt
index 654263c4d..bce2bb29f 100644
--- a/source/Applications/Thermoplast/config.txt
+++ b/source/Applications/Thermoplast/config.txt
@@ -10,7 +10,7 @@ boundingBox = 60 1370 130 190 1530 320 #test bb
 blocknx = 10 10 10 
 #blocknx = 300 420 320
 endTime = 100000
-outTime = 1
+outTime = 100
 availMem = 25e9
 uLB = 0.1
 
@@ -31,7 +31,7 @@ pathGeo = d:/Projects/ThermoPlast/SimGeo
 michel = /michel.stl
 plexiglas = /plexiglas.stl
 
-pathOut = g:/temp/thermoplastCluster1
+pathOut = g:/temp/thermoplast
 
 #restart
 cpStart = 20000000
diff --git a/source/Applications/Thermoplast/thermoplast.cpp b/source/Applications/Thermoplast/thermoplast.cpp
index 484795506..353dc5605 100644
--- a/source/Applications/Thermoplast/thermoplast.cpp
+++ b/source/Applications/Thermoplast/thermoplast.cpp
@@ -551,7 +551,7 @@ void thermoplast(string configname)
    //         createSphereCoProcessor->addGeoObject(sphere, Vector3D(uLB, 0.0, 0.0));
    //      }
 
-   createSphereCoProcessor->process(0);
+   //createSphereCoProcessor->process(0);
 
    //write data for visualization of macroscopic quantities
    SPtr<UbScheduler> visSch(new UbScheduler(outTime));
diff --git a/source/DemCoupling/CreateDemObjectsCoProcessor.cpp b/source/DemCoupling/CreateDemObjectsCoProcessor.cpp
index 58790643f..b7401d07f 100644
--- a/source/DemCoupling/CreateDemObjectsCoProcessor.cpp
+++ b/source/DemCoupling/CreateDemObjectsCoProcessor.cpp
@@ -49,7 +49,7 @@ void CreateDemObjectsCoProcessor::process(double step)
       if (comm->isRoot()) UBLOG(logINFO, "CreateDemObjectsCoProcessor::process start step: " << istep);
       timer.resetAndStart();
 #endif
-
+      
       createGeoObjects();
 
 #ifdef TIMING
@@ -59,10 +59,10 @@ void CreateDemObjectsCoProcessor::process(double step)
 #endif
       
       demCoProcessor->distributeIDs();
-//
-//#ifdef TIMING
-//      if (comm->isRoot()) UBLOG(logINFO, "demCoProcessor->distributeIDs() time = "<<timer.stop()<<" s");
-//#endif
+
+#ifdef TIMING
+      if (comm->isRoot()) UBLOG(logINFO, "demCoProcessor->distributeIDs() time = "<<timer.stop()<<" s");
+#endif
 
       
    }
diff --git a/source/DemCoupling/CreateDemObjectsCoProcessor.h b/source/DemCoupling/CreateDemObjectsCoProcessor.h
index ffb26a35d..bfd0d0c64 100644
--- a/source/DemCoupling/CreateDemObjectsCoProcessor.h
+++ b/source/DemCoupling/CreateDemObjectsCoProcessor.h
@@ -7,7 +7,7 @@
 #include <array>
 
 
-//#define TIMING
+#define TIMING
 
 #ifdef TIMING
 #include "UbTiming.h"
diff --git a/source/DemCoupling/DemCoProcessor.cpp b/source/DemCoupling/DemCoProcessor.cpp
index 56dc9cdec..be3d72070 100644
--- a/source/DemCoupling/DemCoProcessor.cpp
+++ b/source/DemCoupling/DemCoProcessor.cpp
@@ -585,7 +585,7 @@ bool DemCoProcessor::isSpheresIntersection(double centerX1, double centerX2, dou
 
 void DemCoProcessor::distributeIDs()
 {
-   std::vector<int> peIDsSend;
+   std::vector<unsigned long long> peIDsSend;
    std::vector<int> vfIDsSend;
 
    for (int i = 0; i < interactors.size(); i++)
@@ -597,13 +597,13 @@ void DemCoProcessor::distributeIDs()
       }
    }
 
-   std::vector<int> peIDsRecv;
+   std::vector<unsigned long long> peIDsRecv;
    std::vector<int> vfIDsRecv;
 
    comm->allGather(peIDsSend, peIDsRecv);
    comm->allGather(vfIDsSend, vfIDsRecv);
 
-   std::map<int, int> idMap;
+   std::map<int, unsigned long long> idMap;
 
    for (int i = 0; i < peIDsRecv.size(); i++)
    {
@@ -612,25 +612,25 @@ void DemCoProcessor::distributeIDs()
 
    for (int i = 0; i < interactors.size(); i++)
    {
-      std::map<int, int>::const_iterator it;
+      std::map<int, unsigned long long>::const_iterator it;
       if ((it=idMap.find(interactors[i]->getID())) == idMap.end())
       {
          throw UbException(UB_EXARGS, "Interactor ID is invalid! The DEM object may be not in PE domain!");
       }
 
 
-      std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->setId(it->second);
+      std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->setSystemId(it->second);
       //std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometries[i])->setId(idMap.find(interactors[i]->getID())->second);
    }
 
-   for (int i = 0; i < physicsEngineGeometrieAdapters.size(); i++)
-   {
-      //physicsEngineSolver->updateGeometry(physicsEngineGeometries[i]);
-      if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive())
-      {
-         interactors[i]->setPhysicsEngineGeometry(physicsEngineGeometrieAdapters[i]);
-      }
-   }
+   //for (int i = 0; i < physicsEngineGeometrieAdapters.size(); i++)
+   //{
+   //   //physicsEngineSolver->updateGeometry(physicsEngineGeometries[i]);
+   //   if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive())
+   //   {
+   //      interactors[i]->setPhysicsEngineGeometry(physicsEngineGeometrieAdapters[i]);
+   //   }
+   //}
 }
 
 void DemCoProcessor::setBlockVisitor(std::shared_ptr<BoundaryConditionsBlockVisitor> boundaryConditionsBlockVisitor)
diff --git a/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineGeometryAdapter.h b/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineGeometryAdapter.h
index 03349b61c..feea998f9 100644
--- a/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineGeometryAdapter.h
+++ b/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineGeometryAdapter.h
@@ -7,6 +7,7 @@
 
 
 #include "PhysicsEngineGeometryAdapter.h"
+#include <core\DataTypes.h>
 
 namespace walberla
 {
@@ -56,13 +57,14 @@ public:
     int shadowCounter;
     int counter;
 
-    int getSystemId() const { return systemId; }
-    void setSystemId(int val) { systemId = val; }
+    unsigned long long getSystemId() const { return systemId; }
+    void setSystemId(unsigned long long val) { systemId = val; }
 private:
     walberla::pe::RigidBody* peGeoObject;
     //unsigned long long id;
     int id;
-    int systemId;
+    //walberla::id_t systemId;
+    unsigned long long systemId;
     bool active;
 
 };
diff --git a/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.cpp b/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.cpp
index fd227a65b..7e5f5fcce 100644
--- a/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.cpp
+++ b/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.cpp
@@ -46,8 +46,8 @@ std::shared_ptr<PhysicsEngineGeometryAdapter> PePhysicsEngineSolverAdapter::crea
        peGeometryAdapter->setId(id);
        peGeometryAdapter->setSystemId(peGeometry->getSystemID());
        
-       if(peGeometry->getSystemID() != id+1)
-          UB_THROW(UbException(UB_EXARGS, "id="+UbSystem::toString(id)+" does not match pe::SystemId="+UbSystem::toString(peGeometry->getSystemID())));
+       //if(peGeometry->getSystemID() != id+1)
+       //   UB_THROW(UbException(UB_EXARGS, "id="+UbSystem::toString(id)+" does not match pe::SystemId="+UbSystem::toString(peGeometry->getSystemID())));
 
        peGeometryAdapter->setActive();
        peGeometryAdapter->setGeometry(peGeometry);
diff --git a/source/VirtualFluidsCore/Parallel/Communicator.h b/source/VirtualFluidsCore/Parallel/Communicator.h
index aa2e3d35d..3d07e06d4 100644
--- a/source/VirtualFluidsCore/Parallel/Communicator.h
+++ b/source/VirtualFluidsCore/Parallel/Communicator.h
@@ -33,10 +33,12 @@ public:
    virtual std::vector<int> gather(std::vector<int>& values) = 0;
    virtual std::vector<float> gather(std::vector<float>& values) = 0;
    virtual std::vector<double> gather(std::vector<double>& values) = 0;
+   virtual std::vector<unsigned long long> gather(std::vector<unsigned long long>& values) = 0;
 
    virtual void allGather(std::vector<int>& svalues, std::vector<int>& rvalues) = 0;
    virtual void allGather(std::vector<float>& svalues, std::vector<float>& rvalues) = 0;
    virtual void allGather(std::vector<double>& svalues, std::vector<double>& rvalues) = 0;
+   virtual void allGather(std::vector<unsigned long long>& svalues, std::vector<unsigned long long>& rvalues) = 0;
    
    virtual void broadcast(int& value) = 0;
    virtual void broadcast(float& value) = 0;
diff --git a/source/VirtualFluidsCore/Parallel/MPICommunicator.cpp b/source/VirtualFluidsCore/Parallel/MPICommunicator.cpp
index e2c32cdbc..cbd3cdf10 100644
--- a/source/VirtualFluidsCore/Parallel/MPICommunicator.cpp
+++ b/source/VirtualFluidsCore/Parallel/MPICommunicator.cpp
@@ -97,6 +97,11 @@ vector<double> MPICommunicator::gather(vector<double>& values)
    return gather<double>(values);
 }
 //////////////////////////////////////////////////////////////////////////
+std::vector<unsigned long long> MPICommunicator::gather(std::vector<unsigned long long>& values)
+{
+   return gather<unsigned long long>(values);
+}
+//////////////////////////////////////////////////////////////////////////
 int MPICommunicator::getProcessID()
 {
    return PID;
@@ -193,6 +198,11 @@ void MPICommunicator::allGather(std::vector<double>& svalues, std::vector<double
    allGather<double>(svalues, rvalues);
 }
 //////////////////////////////////////////////////////////////////////////
+void MPICommunicator::allGather(std::vector<unsigned long long>& svalues, std::vector<unsigned long long>& rvalues)
+{
+   allGather<unsigned long long>(svalues, rvalues);
+}
+//////////////////////////////////////////////////////////////////////////
 void MPICommunicator::broadcast(std::vector<int>& values)
 {
    broadcast<int>(values);
diff --git a/source/VirtualFluidsCore/Parallel/MPICommunicator.h b/source/VirtualFluidsCore/Parallel/MPICommunicator.h
index f57a7db4c..9338a2925 100644
--- a/source/VirtualFluidsCore/Parallel/MPICommunicator.h
+++ b/source/VirtualFluidsCore/Parallel/MPICommunicator.h
@@ -45,10 +45,12 @@ public:
    std::vector<int> gather(std::vector<int>& values);
    std::vector<float> gather(std::vector<float>& values);
    std::vector<double> gather(std::vector<double>& values);
+   std::vector<unsigned long long> gather(std::vector<unsigned long long>& values);
 
    void allGather(std::vector<int>& svalues, std::vector<int>& rvalues);
    void allGather(std::vector<float>& svalues, std::vector<float>& rvalues);
    void allGather(std::vector<double>& svalues, std::vector<double>& rvalues);
+   void allGather(std::vector<unsigned long long>& svalues, std::vector<unsigned long long>& rvalues);
 
    void broadcast(int& value);
    void broadcast(float& value);
@@ -85,6 +87,7 @@ std::vector<T> MPICommunicator::gather(std::vector<T>& values)
    if ((std::string)typeid(T).name()==(std::string)typeid(double).name()) mpiDataType = MPI_DOUBLE;
    else if ((std::string)typeid(T).name()==(std::string)typeid(float).name()) mpiDataType = MPI_FLOAT;
    else if ((std::string)typeid(T).name()==(std::string)typeid(int).name()) mpiDataType = MPI_INT;
+   else if ((std::string)typeid(T).name()==(std::string)typeid(unsigned long long).name()) mpiDataType = MPI_UNSIGNED_LONG_LONG;
    else throw UbException(UB_EXARGS, "no MpiDataType for T"+(std::string)typeid(T).name());
 
    int count = static_cast<int> (values.size());
@@ -107,6 +110,7 @@ void MPICommunicator::allGather(std::vector<T>& svalues, std::vector<T>& rvalues
    if ((std::string)typeid(T).name()==(std::string)typeid(double).name()) mpiDataType = MPI_DOUBLE;
    else if ((std::string)typeid(T).name()==(std::string)typeid(float).name()) mpiDataType = MPI_FLOAT;
    else if ((std::string)typeid(T).name()==(std::string)typeid(int).name()) mpiDataType = MPI_INT;
+   else if ((std::string)typeid(T).name()==(std::string)typeid(unsigned long long).name()) mpiDataType = MPI_UNSIGNED_LONG_LONG;
    else throw UbException(UB_EXARGS, "no MpiDataType for T"+(std::string)typeid(T).name());
 
    int scount;
-- 
GitLab