From 88e758e8315f6f44f4cbec85c5042c13d1d8488a Mon Sep 17 00:00:00 2001
From: Sebastian Eibl <sebastian.eibl@fau.de>
Date: Tue, 10 Mar 2020 12:15:20 +0100
Subject: [PATCH] updated generation scripts for new interface

---
 apps/benchmarks/GranularGas/GenerateModule.py | 144 ++++++++----------
 python/mesa_pd.py                             |   2 -
 2 files changed, 61 insertions(+), 85 deletions(-)

diff --git a/apps/benchmarks/GranularGas/GenerateModule.py b/apps/benchmarks/GranularGas/GenerateModule.py
index 1e98dd07e..7931cebb7 100755
--- a/apps/benchmarks/GranularGas/GenerateModule.py
+++ b/apps/benchmarks/GranularGas/GenerateModule.py
@@ -1,93 +1,71 @@
 #! /usr/bin/env python3
 # -*- coding: utf-8 -*-
 
-from mesa_pd.accessor import Accessor
+from mesa_pd import Module
 import mesa_pd.data as data
 import mesa_pd.kernel as kernel
 import mesa_pd.mpi as mpi
 
 import argparse
-import numpy as np
-import os
 
 if __name__ == '__main__':
-   parser = argparse.ArgumentParser(description='Generate all necessary files for the waLBerla mesa_pd module.')
-   parser.add_argument('path', help='Where should the files be created?')
-   parser.add_argument("-f", "--force", help="Generate the files even if not inside a waLBerla directory.",
-                       action="store_true")
-   args = parser.parse_args()
-
-   if ((not os.path.isfile(args.path + "/src/walberla.h")) and (not args.force)):
-      raise RuntimeError(args.path + " is not the path to a waLBerla root directory! Specify -f to generate the files anyway.")
-
-   os.makedirs(args.path + "/src/mesa_pd/common", exist_ok = True)
-   os.makedirs(args.path + "/src/mesa_pd/data", exist_ok = True)
-   os.makedirs(args.path + "/src/mesa_pd/domain", exist_ok = True)
-   os.makedirs(args.path + "/src/mesa_pd/kernel", exist_ok = True)
-   os.makedirs(args.path + "/src/mesa_pd/mpi/notifications", exist_ok = True)
-   os.makedirs(args.path + "/src/mesa_pd/vtk", exist_ok = True)
-
-   shapes = ["Sphere", "HalfSpace"]
-
-   ps    = data.ParticleStorage()
-   ch    = data.ContactHistory()
-   lc    = data.LinkedCells()
-   ss    = data.ShapeStorage(ps, shapes)
-
-   ps.addProperty("position",         "walberla::mesa_pd::Vec3", defValue="real_t(0)", syncMode="ALWAYS")
-   ps.addProperty("linearVelocity",   "walberla::mesa_pd::Vec3", defValue="real_t(0)", syncMode="ALWAYS")
-   ps.addProperty("invMass",          "walberla::real_t",        defValue="real_t(1)", syncMode="ON_GHOST_CREATION")
-   ps.addProperty("force",            "walberla::mesa_pd::Vec3", defValue="real_t(0)", syncMode="NEVER")
-
-   ps.addProperty("shapeID",          "size_t",                  defValue="",          syncMode="ON_GHOST_CREATION")
-   ps.addProperty("rotation",         "walberla::mesa_pd::Rot3", defValue="",          syncMode="ALWAYS")
-   ps.addProperty("angularVelocity",  "walberla::mesa_pd::Vec3", defValue="real_t(0)", syncMode="ALWAYS")
-   ps.addProperty("torque",           "walberla::mesa_pd::Vec3", defValue="real_t(0)", syncMode="NEVER")
-
-   ps.addProperty("type",             "uint_t",                  defValue="0",         syncMode="ON_GHOST_CREATION")
-
-   ps.addProperty("flags",            "walberla::mesa_pd::data::particle_flags::FlagT", defValue="", syncMode="ON_GHOST_CREATION")
-   ps.addProperty("nextParticle",     "int",                     defValue="-1",        syncMode="NEVER")
-
-   ps.addInclude("blockforest/BlockForest.h")
-   ps.addProperty("currentBlock",     "blockforest::BlockID",    defValue="",          syncMode="NEVER")
-
-   kernels = []
-   kernels.append( kernel.DoubleCast(shapes) )
-   kernels.append( kernel.ExplicitEuler() )
-   kernels.append( kernel.ExplicitEulerWithShape() )
-   kernels.append( kernel.ForceLJ() )
-   kernels.append( kernel.HeatConduction() )
-   kernels.append( kernel.InsertParticleIntoLinkedCells() )
-   kernels.append( kernel.LinearSpringDashpot() )
-   kernels.append( kernel.NonLinearSpringDashpot() )
-   kernels.append( kernel.SingleCast(shapes) )
-   kernels.append( kernel.SpringDashpot() )
-   kernels.append( kernel.TemperatureIntegration() )
-   kernels.append( kernel.VelocityVerlet() )
-   kernels.append( kernel.VelocityVerletWithShape() )
-
-   ac = Accessor()
-   for k in kernels:
-      ac.mergeRequirements(k.getRequirements())
-   ac.printSummary()
-
-   comm = []
-   comm.append(mpi.BroadcastProperty())
-   comm.append(mpi.ClearNextNeighborSync())
-   comm.append(mpi.ReduceContactHistory())
-   comm.append(mpi.ReduceProperty())
-   comm.append(mpi.SyncGhostOwners(ps))
-   comm.append(mpi.SyncNextNeighbors(ps))
-
-
-   ps.generate(args.path + "/src/mesa_pd/")
-   ch.generate(args.path + "/src/mesa_pd/")
-   lc.generate(args.path + "/src/mesa_pd/")
-   ss.generate(args.path + "/src/mesa_pd/")
-
-   for k in kernels:
-      k.generate(args.path + "/src/mesa_pd/")
-
-   for c in comm:
-      c.generate(args.path + "/src/mesa_pd/")
+    parser = argparse.ArgumentParser(description='Generate all necessary files for the waLBerla mesa_pd module.')
+    parser.add_argument('path', help='Where should the files be created?')
+    args = parser.parse_args()
+
+    mpd = Module(args.path)
+    ps = mpd.add(data.ParticleStorage())
+
+    ps.set_shapes("Sphere", "HalfSpace")
+
+    ps.add_property("position",         "walberla::mesa_pd::Vec3", defValue="real_t(0)", syncMode="ALWAYS")
+    ps.add_property("linearVelocity",   "walberla::mesa_pd::Vec3", defValue="real_t(0)", syncMode="ALWAYS")
+    ps.add_property("invMass",          "walberla::real_t",        defValue="real_t(1)", syncMode="ON_GHOST_CREATION")
+    ps.add_property("force",            "walberla::mesa_pd::Vec3", defValue="real_t(0)", syncMode="NEVER")
+
+    ps.add_property("shapeID",          "size_t",                  defValue="",          syncMode="ON_GHOST_CREATION")
+    ps.add_property("rotation",         "walberla::mesa_pd::Rot3", defValue="",          syncMode="ALWAYS")
+    ps.add_property("angularVelocity",  "walberla::mesa_pd::Vec3", defValue="real_t(0)", syncMode="ALWAYS")
+    ps.add_property("torque",           "walberla::mesa_pd::Vec3", defValue="real_t(0)", syncMode="NEVER")
+
+    ps.add_property("type",             "uint_t",                  defValue="0",         syncMode="ON_GHOST_CREATION")
+
+    ps.add_property("flags",            "walberla::mesa_pd::data::particle_flags::FlagT", defValue="", syncMode="ON_GHOST_CREATION")
+    ps.add_property("nextParticle",     "int",                     defValue="-1",        syncMode="NEVER")
+
+    ps.add_include("blockforest/BlockForest.h")
+    ps.add_property("currentBlock",     "blockforest::BlockID",    defValue="",          syncMode="NEVER")
+
+    mpd.add(data.LinkedCells())
+    mpd.add(data.SparseLinkedCells())
+    mpd.add(data.ShapeStorage(ps))
+
+    mpd.add(kernel.DoubleCast(ps))
+    mpd.add(kernel.ExplicitEuler())
+    mpd.add(kernel.ExplicitEulerWithShape())
+    mpd.add(kernel.ForceLJ())
+    mpd.add(kernel.HeatConduction())
+    mpd.add(kernel.InsertParticleIntoLinkedCells())
+    mpd.add(kernel.LinearSpringDashpot())
+    mpd.add(kernel.NonLinearSpringDashpot())
+    mpd.add(kernel.SingleCast(ps))
+    mpd.add(kernel.SpringDashpot())
+    mpd.add(kernel.TemperatureIntegration())
+    mpd.add(kernel.VelocityVerlet())
+    mpd.add(kernel.VelocityVerletWithShape())
+
+    mpd.add(mpi.BroadcastProperty())
+    mpd.add(mpi.ClearGhostOwnerSync())
+    mpd.add(mpi.ClearNextNeighborSync())
+    mpd.add(mpi.Notifications(ps))
+    ftn = mpd.add(mpi.PropertyNotification('ForceTorqueNotification'))
+    ftn.add_property('force', 'mesa_pd::Vec3', 'Vec3(real_t(0))')
+    ftn.add_property('torque', 'mesa_pd::Vec3', 'Vec3(real_t(0))')
+    mpd.add(mpi.ReduceContactHistory())
+    mpd.add(mpi.ReduceProperty())
+    mpd.add(mpi.ShapePackUnpack(ps))
+    mpd.add(mpi.SyncGhostOwners(ps))
+    mpd.add(mpi.SyncNextNeighbors(ps))
+    mpd.add(mpi.SyncNextNeighborsNoGhosts(ps))
+
+    mpd.generate()
diff --git a/python/mesa_pd.py b/python/mesa_pd.py
index 67da03b51..80b5bff0e 100755
--- a/python/mesa_pd.py
+++ b/python/mesa_pd.py
@@ -7,8 +7,6 @@ import mesa_pd.kernel as kernel
 import mesa_pd.mpi as mpi
 
 import argparse
-import numpy as np
-import os
 
 if __name__ == '__main__':
     parser = argparse.ArgumentParser(description='Generate all necessary files for the waLBerla mesa_pd module.')
-- 
GitLab