From ad8c87b37a45849298307afe746d8251cf91061b Mon Sep 17 00:00:00 2001
From: Sebastian Eibl <sebastian.eibl@fau.de>
Date: Wed, 11 Mar 2020 10:21:14 +0100
Subject: [PATCH] added springdashpotspring to KernelBenchmark

---
 apps/benchmarks/GranularGas/GranularGas.cfg   |  2 +-
 .../GranularGas/MESA_PD_KernelBenchmark.cpp   | 75 +++++++++++++------
 .../mpi/ReduceContactHistory.templ.h          |  4 +
 src/mesa_pd/mpi/ReduceContactHistory.h        |  4 +
 4 files changed, 63 insertions(+), 22 deletions(-)

diff --git a/apps/benchmarks/GranularGas/GranularGas.cfg b/apps/benchmarks/GranularGas/GranularGas.cfg
index 647eca2ef..187f13e89 100644
--- a/apps/benchmarks/GranularGas/GranularGas.cfg
+++ b/apps/benchmarks/GranularGas/GranularGas.cfg
@@ -3,7 +3,7 @@ GranularGas
    simulationCorner < 0, 0, 0 >;
    simulationDomain < 40, 40, 40 >;
    blocks < 1,1,1 >;
-   isPeriodic < 0, 0, 0 >;
+   isPeriodic < 1, 1, 1 >;
    initialRefinementLevel 1;
    sorting linear;
    shift < 0.01, 0.01, 0.01 >;
diff --git a/apps/benchmarks/GranularGas/MESA_PD_KernelBenchmark.cpp b/apps/benchmarks/GranularGas/MESA_PD_KernelBenchmark.cpp
index d2c1452c4..4523db176 100644
--- a/apps/benchmarks/GranularGas/MESA_PD_KernelBenchmark.cpp
+++ b/apps/benchmarks/GranularGas/MESA_PD_KernelBenchmark.cpp
@@ -42,7 +42,9 @@
 #include <mesa_pd/kernel/InsertParticleIntoLinkedCells.h>
 #include <mesa_pd/kernel/ParticleSelector.h>
 #include <mesa_pd/kernel/SpringDashpot.h>
+#include <mesa_pd/kernel/SpringDashpotSpring.h>
 #include <mesa_pd/mpi/ContactFilter.h>
+#include <mesa_pd/mpi/ReduceContactHistory.h>
 #include <mesa_pd/mpi/ReduceProperty.h>
 #include <mesa_pd/mpi/SyncNextNeighbors.h>
 #include <mesa_pd/mpi/SyncNextNeighborsBlockForest.h>
@@ -264,12 +266,18 @@ int main( int argc, char ** argv )
    kernel::ExplicitEulerWithShape        explicitEulerWithShape( params.dt );
    kernel::AssocToBlock                  assoc(forest);
    kernel::InsertParticleIntoLinkedCells ipilc;
-   kernel::SpringDashpot                 dem(1);
-   dem.setDampingT (0, 0, real_t(0));
-   dem.setFriction (0, 0, real_t(0));
-   dem.setParametersFromCOR(0, 0, real_t(0.9), params.dt*real_t(20), ss->shapes[smallSphere]->getMass() * real_t(0.5));
+   kernel::SpringDashpot                 sd(1);
+   sd.setDampingT (0, 0, real_t(0));
+   sd.setFriction (0, 0, real_t(0));
+   sd.setParametersFromCOR(0, 0, real_t(0.9), params.dt*real_t(20), ss->shapes[smallSphere]->getMass() * real_t(0.5));
+   kernel::SpringDashpotSpring           sds(1);
+   sds.setParametersFromCOR(0, 0, real_t(0.9), params.dt*real_t(20), ss->shapes[smallSphere]->getMass() * real_t(0.5));
+   sds.setCoefficientOfFriction(0,0,real_t(0.4));
+   sds.setStiffnessT(0,0,real_t(0.9) * sds.getStiffnessN(0,0));
+
    mpi::ReduceProperty                   RP;
    mpi::SyncNextNeighbors                SNN;
+   mpi::ReduceContactHistory             RCH;
    ContactDetection                      CD(domain);
 
    // initial sync
@@ -284,6 +292,17 @@ int main( int argc, char ** argv )
 
       WcTimingPool tp;
 
+      LIKWID_MARKER_REGISTER("SNN");
+      WALBERLA_MPI_BARRIER();
+      LIKWID_MARKER_START("SNN");
+      tp["SNN"].start();
+      for (int64_t i=0; i < params.simulationSteps; ++i)
+      {
+         SNN(*ps, *domain);
+      }
+      tp["SNN"].end();
+      LIKWID_MARKER_STOP("SNN");
+
       LIKWID_MARKER_REGISTER("AssocToBlock");
       WALBERLA_MPI_BARRIER();
       LIKWID_MARKER_START("AssocToBlock");
@@ -323,19 +342,33 @@ int main( int argc, char ** argv )
       tp["ContactDetection"].end();
       LIKWID_MARKER_STOP("ContactDetection");
 
-      LIKWID_MARKER_REGISTER("DEM");
+      LIKWID_MARKER_REGISTER("SpringDashpot");
+      WALBERLA_MPI_BARRIER();
+      LIKWID_MARKER_START("SpringDashpot");
+      tp["SpringDashpot"].start();
+      for (int64_t i=0; i < params.simulationSteps; ++i)
+      {
+         for (auto& c : CD.getContacts())
+         {
+            sd(c.idx1_, c.idx2_, accessor, c.contactPoint_, c.contactNormal_, c.penetrationDepth_);
+         }
+      }
+      tp["SpringDashpot"].end();
+      LIKWID_MARKER_STOP("SpringDashpot");
+
+      LIKWID_MARKER_REGISTER("SpringDashpotSpring");
       WALBERLA_MPI_BARRIER();
-      LIKWID_MARKER_START("DEM");
-      tp["DEM"].start();
+      LIKWID_MARKER_START("SpringDashpotSpring");
+      tp["SpringDashpotSpring"].start();
       for (int64_t i=0; i < params.simulationSteps; ++i)
       {
          for (auto& c : CD.getContacts())
          {
-            dem(c.idx1_, c.idx2_, accessor, c.contactPoint_, c.contactNormal_, c.penetrationDepth_);
+            sds(c.idx1_, c.idx2_, accessor, c.contactPoint_, c.contactNormal_, c.penetrationDepth_, params.dt);
          }
       }
-      tp["DEM"].end();
-      LIKWID_MARKER_STOP("DEM");
+      tp["SpringDashpotSpring"].end();
+      LIKWID_MARKER_STOP("SpringDashpotSpring");
 
       LIKWID_MARKER_REGISTER("ReduceForce");
       WALBERLA_MPI_BARRIER();
@@ -348,6 +381,17 @@ int main( int argc, char ** argv )
       tp["ReduceForce"].end();
       LIKWID_MARKER_STOP("ReduceForce");
 
+      LIKWID_MARKER_REGISTER("ReduceContactHistory");
+      WALBERLA_MPI_BARRIER();
+      LIKWID_MARKER_START("ReduceContactHistory");
+      tp["ReduceContactHistory"].start();
+      for (int64_t i=0; i < params.simulationSteps; ++i)
+      {
+         RCH(*ps);
+      }
+      tp["ReduceContactHistory"].end();
+      LIKWID_MARKER_STOP("ReduceContactHistory");
+
       LIKWID_MARKER_REGISTER("Euler");
       WALBERLA_MPI_BARRIER();
       LIKWID_MARKER_START("Euler");
@@ -359,17 +403,6 @@ int main( int argc, char ** argv )
       tp["Euler"].end();
       LIKWID_MARKER_STOP("Euler");
 
-      LIKWID_MARKER_REGISTER("SNN");
-      WALBERLA_MPI_BARRIER();
-      LIKWID_MARKER_START("SNN");
-      tp["SNN"].start();
-      for (int64_t i=0; i < params.simulationSteps; ++i)
-      {
-         SNN(*ps, *domain);
-      }
-      tp["SNN"].end();
-      LIKWID_MARKER_STOP("SNN");
-
       WALBERLA_LOG_INFO_ON_ROOT("*** SIMULATION - END ***");
 
       if (params.checkSimulation)
diff --git a/python/mesa_pd/templates/mpi/ReduceContactHistory.templ.h b/python/mesa_pd/templates/mpi/ReduceContactHistory.templ.h
index 1798e721f..77aabba48 100644
--- a/python/mesa_pd/templates/mpi/ReduceContactHistory.templ.h
+++ b/python/mesa_pd/templates/mpi/ReduceContactHistory.templ.h
@@ -96,12 +96,16 @@ void ReduceContactHistory::operator()(data::ParticleStorage& ps) const
    const auto size = ps.size();
    for (size_t idx = 0; idx < size; ++idx)
    {
+      //only for kernel benchmark
+//      ps.getOldContactHistoryRef(idx).clear();
       if (!data::particle_flags::isSet( ps.getFlags(idx), data::particle_flags::GHOST) )
       {
+         //master
          std::swap(ps.getOldContactHistoryRef(idx), ps.getNewContactHistoryRef(idx));
          ps.getNewContactHistoryRef(idx).clear();
       } else
       {
+         //ghost
          ps.getOldContactHistoryRef(idx).clear();
          ps.getNewContactHistoryRef(idx).clear();
       }
diff --git a/src/mesa_pd/mpi/ReduceContactHistory.h b/src/mesa_pd/mpi/ReduceContactHistory.h
index 80606f776..7d304f09d 100644
--- a/src/mesa_pd/mpi/ReduceContactHistory.h
+++ b/src/mesa_pd/mpi/ReduceContactHistory.h
@@ -96,12 +96,16 @@ void ReduceContactHistory::operator()(data::ParticleStorage& ps) const
    const auto size = ps.size();
    for (size_t idx = 0; idx < size; ++idx)
    {
+      //only for kernel benchmark
+//      ps.getOldContactHistoryRef(idx).clear();
       if (!data::particle_flags::isSet( ps.getFlags(idx), data::particle_flags::GHOST) )
       {
+         //master
          std::swap(ps.getOldContactHistoryRef(idx), ps.getNewContactHistoryRef(idx));
          ps.getNewContactHistoryRef(idx).clear();
       } else
       {
+         //ghost
          ps.getOldContactHistoryRef(idx).clear();
          ps.getNewContactHistoryRef(idx).clear();
       }
-- 
GitLab