From 50619280c30d0c2a493739fedaf76b90a8bad2b3 Mon Sep 17 00:00:00 2001
From: "Dennis.Glaeser" <dennis.glaeser@iws.uni-stuttgart.de>
Date: Wed, 4 Nov 2020 20:34:56 +0100
Subject: [PATCH] [examples][ldc] add test for plot script

---
 examples/liddrivencavity/CMakeLists.txt  | 10 ++++++++++
 examples/liddrivencavity/run_and_plot.py | 12 ++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 examples/liddrivencavity/run_and_plot.py

diff --git a/examples/liddrivencavity/CMakeLists.txt b/examples/liddrivencavity/CMakeLists.txt
index 751e373ac7..1e6d9b6316 100644
--- a/examples/liddrivencavity/CMakeLists.txt
+++ b/examples/liddrivencavity/CMakeLists.txt
@@ -24,4 +24,14 @@ dumux_add_test(NAME example_ff_liddrivencavity_re1000
                              -Problem.Name example_ff_liddrivencavity_re1000
                              -Grid.Cells \"64 64\" -TimeLoop.TEnd 50")
 
+# test plot script
+set(DUNE_REENABLE_ADD_TEST True)
+string(CONCAT LDCLOGFILES
+              "example_ff_liddrivencavity_re1_vx.log;example_ff_liddrivencavity_re1_vy.log;"
+              "example_ff_liddrivencavity_re1000_vx.log;example_ff_liddrivencavity_re1000_vy.log")
+add_test(NAME example_ff_liddrivencavity_plot COMMAND ${CMAKE_CURRENT_BINARY_DIR}/run_and_plot.py -s -n)
+set_tests_properties(example_ff_liddrivencavity_plot
+                     PROPERTIES LABEL example REQUIRED_FILES "${LDCLOGFILES}")
+set(DUNE_REENABLE_ADD_TEST False)
+
 dune_symlink_to_source_files(FILES "params_re1.input" "params_re1000.input" "run_and_plot.py")
diff --git a/examples/liddrivencavity/run_and_plot.py b/examples/liddrivencavity/run_and_plot.py
old mode 100644
new mode 100755
index cebce55d7d..e7b43699f5
--- a/examples/liddrivencavity/run_and_plot.py
+++ b/examples/liddrivencavity/run_and_plot.py
@@ -1,4 +1,4 @@
-##!/usr/bin/env python3
+#!/usr/bin/env python3
 import sys
 if sys.version_info[0] < 3:
     sys.exit("Python 3 required to run this script. Exit.")
@@ -13,6 +13,8 @@ import argparse
 parser = argparse.ArgumentParser(description='plot script for the lid-driven cavity example')
 parser.add_argument('-s', '--skipsim', required=False, action='store_true',
                     help='use this flag to skip the simulation run and directly plot already existing data')
+parser.add_argument('-n', '--noplotwindow', required=False, action='store_true',
+                    help='use this flag to suppress the plot window popping up')
 args = vars(parser.parse_args())
 
 reynolds = [1, 1000]
@@ -53,6 +55,7 @@ ax1.plot(jurjevicnumvx, jurjevicnumy, '--', markerfacecolor='white', color='blac
 ax1.plot(jurjevicexpvx, jurjevicexpy, 'o', markerfacecolor='white', color='black', label=u"R.Jurjevic et al., exp")
 ax1.set_xlabel(r"$v_x$[m/s]")
 ax1.set_ylabel(u"y [m]")
+
 ax2.plot(x['1'], vy['1'],  color='black', label=u"DuMu$^\mathrm{x}$",linewidth=2)
 ax2.plot(jurjevicnumx, jurjevicnumvy, '--', markerfacecolor='white', color='black', label=u"R.Jurjevic, num")
 ax2.plot(jurjevicexpx, jurjevicexpvy, 'o', markerfacecolor='white', color='black', label=u"R.Jurjevic, exp")
@@ -60,18 +63,23 @@ ax2.set_xlabel(u"x [m]")
 ax2.set_ylabel(r"$v_y$[m/s]",labelpad=1)
 ax2.set_xlabel(u"x [m]")
 ax2.set_ylabel(r"$v_y$[m/s]",labelpad=1)
+
 handles, labels = ax2.get_legend_handles_labels()
 fig.legend(handles, labels, bbox_to_anchor=(0.51, 1.0), ncol=3, labelspacing=0.)
+
 ax3.plot(vx['1000'], y['1000'], color='black', label=u"DuMu$^\mathrm{x}$",linewidth=2)
 ax3.plot(ghiavx, ghiay, 'o',  markerfacecolor='white', color='black', label=u"Ghia et al.")
 ax3.set_xlabel(r"$v_x$[m/s]")
 ax3.set_ylabel(u"y [m]")
+
 ax4.plot(x['1000'], vy['1000'], color='black', label=u"DuMu$^\mathrm{x}$",linewidth=2)
 ax4.plot(ghiax, ghiavy, 'o',  markerfacecolor='white', color='black', label=u"Ghia et al.")
 ax4.set_xlabel(u"x [m]")
 ax4.set_ylabel(r"$v_y$[m/s]",labelpad=1)
+
 handles, labels = ax4.get_legend_handles_labels()
 fig.legend(handles, labels, bbox_to_anchor=(0.92, 1.0), ncol =2, labelspacing=0.)
 fig.tight_layout(rect=[0.03, 0.07, 1, 0.9], pad=0.4, w_pad=2.0, h_pad=1.0)
+
 plt.savefig("lidverification.png", dpi= 300)
-plt.show()
+if not args['noplotwindow']: plt.show()
-- 
GitLab