From 08644e1e2f459c6674467d2f6ba8647d89b6753d Mon Sep 17 00:00:00 2001
From: Martin Bauer <martin.bauer@fau.de>
Date: Thu, 25 Apr 2019 11:02:39 +0200
Subject: [PATCH] Python tools: function for block decomposition

---
 python/waLBerla/tools/config/__init__.py        |  4 ++++
 .../tools/{config.py => config/prm_files.py}    |  0
 python/waLBerla/tools/config/setup.py           | 17 +++++++++++++++++
 3 files changed, 21 insertions(+)
 create mode 100644 python/waLBerla/tools/config/__init__.py
 rename python/waLBerla/tools/{config.py => config/prm_files.py} (100%)
 create mode 100644 python/waLBerla/tools/config/setup.py

diff --git a/python/waLBerla/tools/config/__init__.py b/python/waLBerla/tools/config/__init__.py
new file mode 100644
index 000000000..3fa8afd43
--- /dev/null
+++ b/python/waLBerla/tools/config/__init__.py
@@ -0,0 +1,4 @@
+from .prm_files import toPrm, fromPrm
+from .setup import block_decomposition
+
+__all__ = ['toPrm', 'fromPrm', 'block_decomposition']
diff --git a/python/waLBerla/tools/config.py b/python/waLBerla/tools/config/prm_files.py
similarity index 100%
rename from python/waLBerla/tools/config.py
rename to python/waLBerla/tools/config/prm_files.py
diff --git a/python/waLBerla/tools/config/setup.py b/python/waLBerla/tools/config/setup.py
new file mode 100644
index 000000000..a4a934daf
--- /dev/null
+++ b/python/waLBerla/tools/config/setup.py
@@ -0,0 +1,17 @@
+def _factors(n):
+    while n > 1:
+        for i in range(2, n + 1):
+            if n % i == 0:
+                n //= i
+                yield i
+                break
+
+
+def block_decomposition(processes):
+    """Compute a 3D factorization of 'processes' in a 3 factors returned as tuple"""
+    result = [1, 1, 1]
+    for factor in _factors(processes):
+        min_idx = result.index(min(result))
+        result[min_idx] *= factor
+    assert result[0] * result[1] * result[2] == processes
+    return tuple(result)
-- 
GitLab