From cf51e9917a56caf57a4388cf6cf3414d43a3874b Mon Sep 17 00:00:00 2001
From: Martin Bauer <martin.bauer@fau.de>
Date: Tue, 12 Feb 2019 10:20:11 +0100
Subject: [PATCH] waLBerla sweep generation - directly callable
 cellinterval-version

---
 templates/Sweep.tmpl.cpp | 10 +++++-----
 templates/Sweep.tmpl.h   | 25 +++++++++++++------------
 2 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/templates/Sweep.tmpl.cpp b/templates/Sweep.tmpl.cpp
index 63d686e..66fa70f 100644
--- a/templates/Sweep.tmpl.cpp
+++ b/templates/Sweep.tmpl.cpp
@@ -51,7 +51,7 @@ namespace {{namespace}} {
 {{kernel|generate_definition}}
 
 
-void {{class_name}}::sweep( IBlock * block )
+void {{class_name}}::operator()( IBlock * block )
 {
     {{kernel|generate_block_data_to_field_extraction|indent(4)}}
     {{kernel|generate_call(stream='stream_')|indent(4)}}
@@ -59,10 +59,10 @@ void {{class_name}}::sweep( IBlock * block )
 }
 
 
-void {{class_name}}::sweepOnCellInterval( const shared_ptr<StructuredBlockStorage> & blocks,
-                                          const CellInterval & globalCellInterval,
-                                          cell_idx_t ghostLayers,
-                                          IBlock * block )
+void {{class_name}}::runOnCellInterval( const shared_ptr<StructuredBlockStorage> & blocks,
+                                        const CellInterval & globalCellInterval,
+                                        cell_idx_t ghostLayers,
+                                        IBlock * block )
 {
     CellInterval ci = globalCellInterval;
     CellInterval blockBB = blocks->getBlockCellBB( *block);
diff --git a/templates/Sweep.tmpl.h b/templates/Sweep.tmpl.h
index 325b9c5..e6d24cf 100644
--- a/templates/Sweep.tmpl.h
+++ b/templates/Sweep.tmpl.h
@@ -57,28 +57,29 @@ public:
 
     {{ kernel| generate_destructor(class_name) |indent(4) }}
 
-    void operator()(IBlock * b) { sweep(b); }
+    void operator()(IBlock * b);
+    void runOnCellInterval(const shared_ptr<StructuredBlockStorage> & blocks,
+                           const CellInterval & globalCellInterval, cell_idx_t ghostLayers, IBlock * block);
 
-    std::function<void (IBlock*)> getSweep() {
-        return [this](IBlock * b) { this->sweep(b); };
+
+
+    static std::function<void (IBlock*)> getSweep(const shared_ptr<{{class_name}}> & kernel) {
+        return [kernel](IBlock * b) { (*kernel)(b); };
     }
 
-    std::function<void (IBlock*)> getSweepOnCellInterval(const shared_ptr<StructuredBlockStorage> & blocks,
-                                                         const CellInterval & globalCellInterval,
-                                                         cell_idx_t ghostLayers=1 )
+    static std::function<void (IBlock*)> getSweepOnCellInterval(const shared_ptr<{{class_name}}> & kernel,
+                                                                const shared_ptr<StructuredBlockStorage> & blocks,
+                                                                const CellInterval & globalCellInterval,
+                                                                cell_idx_t ghostLayers=1 )
     {
-        return [this, blocks, globalCellInterval, ghostLayers] (IBlock * b) {
-            this->sweepOnCellInterval(blocks, globalCellInterval, ghostLayers, b);
+        return [kernel, blocks, globalCellInterval, ghostLayers] (IBlock * b) {
+            kernel->runOnCellInterval(blocks, globalCellInterval, ghostLayers, b);
         };
     }
 
     {{ kernel|generate_members|indent(4) }}
 
 private:
-    void sweep( IBlock * block );
-    void sweepOnCellInterval(const shared_ptr<StructuredBlockStorage> & blocks,
-                             const CellInterval & globalCellInterval, cell_idx_t ghostLayers, IBlock * block );
-
     {%if target is equalto 'gpu'%}
     cudaStream_t stream_;
     {% endif %}
-- 
GitLab