From 5c3e978d7867ea098ff9f9bfab4b06075dc51a68 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Thu, 4 Mar 2021 14:54:19 +0100
Subject: [PATCH] [T] Made Snakemake vtkdiff wrapper more generic.

Files to compare have to specified explicitly.

Added check_mesh option.
---
 Applications/Utils/ExtractBoundary.smk | 6 ++++--
 scripts/snakemake/vtkdiff/wrapper.py   | 9 ++++-----
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/Applications/Utils/ExtractBoundary.smk b/Applications/Utils/ExtractBoundary.smk
index 3809ec7a224..ed091c3ef5d 100644
--- a/Applications/Utils/ExtractBoundary.smk
+++ b/Applications/Utils/ExtractBoundary.smk
@@ -29,7 +29,7 @@ rule generate_meshes:
 
 rule extract_boundary:
     input:
-        "input_square_1x1_{type}.vtu"
+        rules.generate_meshes.output
     output:
         "square_1x1_{type}_boundary.vtu"
     shell:
@@ -37,10 +37,12 @@ rule extract_boundary:
 
 rule vtkdiff:
     input:
-        "square_1x1_{type}_boundary.vtu"
+        a = rules.extract_boundary.output, # "square_1x1_{type}_boundary.vtu"
+        b = f"{config['Data_SOURCE_DIR']}/{output_path}/{rules.extract_boundary.output}"
     output:
         "square_1x1_{type}_boundary_diff.out"
     params:
+        check_mesh = True,
         fields = [
             # second field name can be omitted if identical
             ["bulk_node_ids", 0, 0],
diff --git a/scripts/snakemake/vtkdiff/wrapper.py b/scripts/snakemake/vtkdiff/wrapper.py
index 564f9aeae03..74ed33ac140 100644
--- a/scripts/snakemake/vtkdiff/wrapper.py
+++ b/scripts/snakemake/vtkdiff/wrapper.py
@@ -7,12 +7,12 @@ __license__ = "BSD"
 import os
 from snakemake.shell import shell
 
-output_path = (
-    os.getcwd().replace("\\", "/").replace(snakemake.config["Data_BINARY_DIR"], "")
-)
 if os.path.exists(snakemake.output[0]):
     os.remove(snakemake.output[0])
 
+if snakemake.params.check_mesh:
+    shell("vtkdiff {snakemake.input.a} {snakemake.input.b} -m > {snakemake.output[0]}")
+
 for field in snakemake.params.fields:
     field_a = field[0]
     offset = 0
@@ -24,8 +24,7 @@ for field in snakemake.params.fields:
 
     shell(
         """
-        vtkdiff {snakemake.input[0]} \
-          {snakemake.config[Data_SOURCE_DIR]}/{output_path}/{snakemake.input[0]} \
+        vtkdiff {snakemake.input.a} {snakemake.input.b} \
           -a {field_a} -b {field_b} \
           --abs {abs_tol} --rel {rel_tol} >> {snakemake.output[0]}
         """
-- 
GitLab