From d03b69f9db5b3cf2e925ccf0e25de3e60ebcc10a Mon Sep 17 00:00:00 2001
From: David Seus <david.seus@ians.uni-stuttgart.de>
Date: Tue, 7 Jul 2020 15:44:30 +0200
Subject: [PATCH] merge iteration number shift in TPR two-patch

---
 .../TP-R-2-patch-pure-dd-realistic.py         | 19 ++++++++++++++----
 .../TP-R-2-patch-pure-dd.py                   | 19 ++++++++++++++----
 ...alistic-gravity-but-same-intrinsic-perm.py | 19 ++++++++++++++----
 ...c-no-gravity-but-varying-intrinsic-perm.py | 19 ++++++++++++++----
 ...R-2-patch-realistic-same-intrinsic-perm.py | 19 ++++++++++++++----
 .../TP-R-2-patch-realistic.py                 | 19 ++++++++++++++----
 .../TP-R-2-patch-test.py                      | 20 +++++++++++++++----
 ...2-patch-mesh-study-all-params-one-but-g.py | 19 ++++++++++++++----
 .../TP-R-2-patch-mesh-study-all-params-one.py | 19 ++++++++++++++----
 .../mesh_studies/TP-R-2-patch-mesh-study.py   | 11 +++++++++-
 ...vity-but-same-intrinsic-perm-mesh-study.py | 19 ++++++++++++++----
 ...y-but-varying-intrinsic-perm-mesh-study.py | 19 ++++++++++++++----
 ...R-2-patch-realistic-same-intrinsic-perm.py | 19 ++++++++++++++----
 13 files changed, 191 insertions(+), 49 deletions(-)

diff --git a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-pure-dd-realistic.py b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-pure-dd-realistic.py
index 7b96ff4..9134d00 100755
--- a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-pure-dd-realistic.py
+++ b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-pure-dd-realistic.py
@@ -55,7 +55,7 @@ resolutions = {
 # starttimes gives a list of starttimes to run the simulation from.
 # The list is looped over and a simulation is run with t_0 as initial time
 #  for each element t_0 in starttimes.
-starttimes = [0.0]
+starttimes = {0: 0.0}
 timestep_size = 0.00001
 number_of_timesteps = 5
 
@@ -278,7 +278,6 @@ f = open(thisfile, 'r')
 print(f.read())
 f.close()
 
-
 # MAIN ########################################################################
 if __name__ == '__main__':
     # dictionary of simualation parameters to pass to the run function.
@@ -321,22 +320,34 @@ if __name__ == '__main__':
         "write_to_file": write_to_file,
         "analyse_condition": analyse_condition
     }
-    for starttime in starttimes:
+    for number_shift, starttime in starttimes.items():
+        simulation_parameter.update(
+            {"starttime_timestep_number_shift": number_shift}
+        )
         for mesh_resolution, solver_tol in resolutions.items():
             simulation_parameter.update({"solver_tol": solver_tol})
             hlp.info(simulation_parameter["use_case"])
+            processQueue = mp.Queue()
             LDDsim = mp.Process(
                         target=hlp.run_simulation,
                         args=(
                             simulation_parameter,
+                            processQueue,
                             starttime,
                             mesh_resolution
                             )
                         )
             LDDsim.start()
-            LDDsim.join()
+            # LDDsim.join()
             # hlp.run_simulation(
             #     mesh_resolution=mesh_resolution,
             #     starttime=starttime,
             #     parameter=simulation_parameter
             #     )
+
+        LDDsim.join()
+        if mesh_study:
+            simulation_output_dir = processQueue.get()
+            hlp.merge_spacetime_errornorms(isRichards=isRichards,
+                                           resolutions=resolutions,
+                                           output_dir=simulation_output_dir)
diff --git a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-pure-dd.py b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-pure-dd.py
index 2b9d2cd..689b8f0 100755
--- a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-pure-dd.py
+++ b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-pure-dd.py
@@ -55,7 +55,7 @@ resolutions = {
 # starttimes gives a list of starttimes to run the simulation from.
 # The list is looped over and a simulation is run with t_0 as initial time
 #  for each element t_0 in starttimes.
-starttimes = [0.0]
+starttimes = {0: 0.0}
 timestep_size = 0.005
 number_of_timesteps = 5
 
@@ -412,7 +412,6 @@ f = open(thisfile, 'r')
 print(f.read())
 f.close()
 
-
 # MAIN ########################################################################
 if __name__ == '__main__':
     # dictionary of simualation parameters to pass to the run function.
@@ -455,22 +454,34 @@ if __name__ == '__main__':
         "write_to_file": write_to_file,
         "analyse_condition": analyse_condition
     }
-    for starttime in starttimes:
+    for number_shift, starttime in starttimes.items():
+        simulation_parameter.update(
+            {"starttime_timestep_number_shift": number_shift}
+        )
         for mesh_resolution, solver_tol in resolutions.items():
             simulation_parameter.update({"solver_tol": solver_tol})
             hlp.info(simulation_parameter["use_case"])
+            processQueue = mp.Queue()
             LDDsim = mp.Process(
                         target=hlp.run_simulation,
                         args=(
                             simulation_parameter,
+                            processQueue,
                             starttime,
                             mesh_resolution
                             )
                         )
             LDDsim.start()
-            LDDsim.join()
+            # LDDsim.join()
             # hlp.run_simulation(
             #     mesh_resolution=mesh_resolution,
             #     starttime=starttime,
             #     parameter=simulation_parameter
             #     )
+
+        LDDsim.join()
+        if mesh_study:
+            simulation_output_dir = processQueue.get()
+            hlp.merge_spacetime_errornorms(isRichards=isRichards,
+                                           resolutions=resolutions,
+                                           output_dir=simulation_output_dir)
diff --git a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic-gravity-but-same-intrinsic-perm.py b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic-gravity-but-same-intrinsic-perm.py
index fca9fe2..352e07f 100755
--- a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic-gravity-but-same-intrinsic-perm.py
+++ b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic-gravity-but-same-intrinsic-perm.py
@@ -56,7 +56,7 @@ resolutions = {
 # starttimes gives a list of starttimes to run the simulation from.
 # The list is looped over and a simulation is run with t_0 as initial time
 #  for each element t_0 in starttimes.
-starttimes = [0.0]
+starttimes = {0: 0.0}
 timestep_size = 0.001
 number_of_timesteps = 800
 
@@ -267,7 +267,6 @@ f = open(thisfile, 'r')
 print(f.read())
 f.close()
 
-
 # MAIN ########################################################################
 if __name__ == '__main__':
     # dictionary of simualation parameters to pass to the run function.
@@ -310,22 +309,34 @@ if __name__ == '__main__':
         "write_to_file": write_to_file,
         "analyse_condition": analyse_condition
     }
-    for starttime in starttimes:
+    for number_shift, starttime in starttimes.items():
+        simulation_parameter.update(
+            {"starttime_timestep_number_shift": number_shift}
+        )
         for mesh_resolution, solver_tol in resolutions.items():
             simulation_parameter.update({"solver_tol": solver_tol})
             hlp.info(simulation_parameter["use_case"])
+            processQueue = mp.Queue()
             LDDsim = mp.Process(
                         target=hlp.run_simulation,
                         args=(
                             simulation_parameter,
+                            processQueue,
                             starttime,
                             mesh_resolution
                             )
                         )
             LDDsim.start()
-            LDDsim.join()
+            # LDDsim.join()
             # hlp.run_simulation(
             #     mesh_resolution=mesh_resolution,
             #     starttime=starttime,
             #     parameter=simulation_parameter
             #     )
+
+        LDDsim.join()
+        if mesh_study:
+            simulation_output_dir = processQueue.get()
+            hlp.merge_spacetime_errornorms(isRichards=isRichards,
+                                           resolutions=resolutions,
+                                           output_dir=simulation_output_dir)
diff --git a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic-no-gravity-but-varying-intrinsic-perm.py b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic-no-gravity-but-varying-intrinsic-perm.py
index a2929e8..9152aee 100755
--- a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic-no-gravity-but-varying-intrinsic-perm.py
+++ b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic-no-gravity-but-varying-intrinsic-perm.py
@@ -56,7 +56,7 @@ resolutions = {
 # starttimes gives a list of starttimes to run the simulation from.
 # The list is looped over and a simulation is run with t_0 as initial time
 #  for each element t_0 in starttimes.
-starttimes = [0.0]
+starttimes = {0: 0.0}
 timestep_size = 0.001
 number_of_timesteps = 800
 
@@ -267,7 +267,6 @@ f = open(thisfile, 'r')
 print(f.read())
 f.close()
 
-
 # MAIN ########################################################################
 if __name__ == '__main__':
     # dictionary of simualation parameters to pass to the run function.
@@ -310,22 +309,34 @@ if __name__ == '__main__':
         "write_to_file": write_to_file,
         "analyse_condition": analyse_condition
     }
-    for starttime in starttimes:
+    for number_shift, starttime in starttimes.items():
+        simulation_parameter.update(
+            {"starttime_timestep_number_shift": number_shift}
+        )
         for mesh_resolution, solver_tol in resolutions.items():
             simulation_parameter.update({"solver_tol": solver_tol})
             hlp.info(simulation_parameter["use_case"])
+            processQueue = mp.Queue()
             LDDsim = mp.Process(
                         target=hlp.run_simulation,
                         args=(
                             simulation_parameter,
+                            processQueue,
                             starttime,
                             mesh_resolution
                             )
                         )
             LDDsim.start()
-            LDDsim.join()
+            # LDDsim.join()
             # hlp.run_simulation(
             #     mesh_resolution=mesh_resolution,
             #     starttime=starttime,
             #     parameter=simulation_parameter
             #     )
+
+        LDDsim.join()
+        if mesh_study:
+            simulation_output_dir = processQueue.get()
+            hlp.merge_spacetime_errornorms(isRichards=isRichards,
+                                           resolutions=resolutions,
+                                           output_dir=simulation_output_dir)
diff --git a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic-same-intrinsic-perm.py b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic-same-intrinsic-perm.py
index 1b40691..dcc14cc 100755
--- a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic-same-intrinsic-perm.py
+++ b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic-same-intrinsic-perm.py
@@ -56,7 +56,7 @@ resolutions = {
 # starttimes gives a list of starttimes to run the simulation from.
 # The list is looped over and a simulation is run with t_0 as initial time
 #  for each element t_0 in starttimes.
-starttimes = [0.0]
+starttimes = {0: 0.0}
 timestep_size = 0.01
 number_of_timesteps = 8
 
@@ -267,7 +267,6 @@ f = open(thisfile, 'r')
 print(f.read())
 f.close()
 
-
 # MAIN ########################################################################
 if __name__ == '__main__':
     # dictionary of simualation parameters to pass to the run function.
@@ -310,22 +309,34 @@ if __name__ == '__main__':
         "write_to_file": write_to_file,
         "analyse_condition": analyse_condition
     }
-    for starttime in starttimes:
+    for number_shift, starttime in starttimes.items():
+        simulation_parameter.update(
+            {"starttime_timestep_number_shift": number_shift}
+        )
         for mesh_resolution, solver_tol in resolutions.items():
             simulation_parameter.update({"solver_tol": solver_tol})
             hlp.info(simulation_parameter["use_case"])
+            processQueue = mp.Queue()
             LDDsim = mp.Process(
                         target=hlp.run_simulation,
                         args=(
                             simulation_parameter,
+                            processQueue,
                             starttime,
                             mesh_resolution
                             )
                         )
             LDDsim.start()
-            LDDsim.join()
+            # LDDsim.join()
             # hlp.run_simulation(
             #     mesh_resolution=mesh_resolution,
             #     starttime=starttime,
             #     parameter=simulation_parameter
             #     )
+
+        LDDsim.join()
+        if mesh_study:
+            simulation_output_dir = processQueue.get()
+            hlp.merge_spacetime_errornorms(isRichards=isRichards,
+                                           resolutions=resolutions,
+                                           output_dir=simulation_output_dir)
diff --git a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic.py b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic.py
index 6b16a1c..7477690 100755
--- a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic.py
+++ b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-realistic.py
@@ -56,7 +56,7 @@ resolutions = {
 # starttimes gives a list of starttimes to run the simulation from.
 # The list is looped over and a simulation is run with t_0 as initial time
 #  for each element t_0 in starttimes.
-starttimes = [0.0]
+starttimes = {0: 0.0}
 timestep_size = 0.001
 number_of_timesteps = 5
 
@@ -267,7 +267,6 @@ f = open(thisfile, 'r')
 print(f.read())
 f.close()
 
-
 # MAIN ########################################################################
 if __name__ == '__main__':
     # dictionary of simualation parameters to pass to the run function.
@@ -310,22 +309,34 @@ if __name__ == '__main__':
         "write_to_file": write_to_file,
         "analyse_condition": analyse_condition
     }
-    for starttime in starttimes:
+    for number_shift, starttime in starttimes.items():
+        simulation_parameter.update(
+            {"starttime_timestep_number_shift": number_shift}
+        )
         for mesh_resolution, solver_tol in resolutions.items():
             simulation_parameter.update({"solver_tol": solver_tol})
             hlp.info(simulation_parameter["use_case"])
+            processQueue = mp.Queue()
             LDDsim = mp.Process(
                         target=hlp.run_simulation,
                         args=(
                             simulation_parameter,
+                            processQueue,
                             starttime,
                             mesh_resolution
                             )
                         )
             LDDsim.start()
-            LDDsim.join()
+            # LDDsim.join()
             # hlp.run_simulation(
             #     mesh_resolution=mesh_resolution,
             #     starttime=starttime,
             #     parameter=simulation_parameter
             #     )
+
+        LDDsim.join()
+        if mesh_study:
+            simulation_output_dir = processQueue.get()
+            hlp.merge_spacetime_errornorms(isRichards=isRichards,
+                                           resolutions=resolutions,
+                                           output_dir=simulation_output_dir)
diff --git a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-test.py b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-test.py
index 09106bd..84ff68c 100755
--- a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-test.py
+++ b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/TP-R-2-patch-test.py
@@ -57,7 +57,7 @@ resolutions = {
 # starttimes gives a list of starttimes to run the simulation from.
 # The list is looped over and a simulation is run with t_0 as initial time
 #  for each element t_0 in starttimes.
-starttimes = [0.0]
+starttimes = {0: 0.0}
 timestep_size = 0.001
 number_of_timesteps = 20
 
@@ -416,7 +416,6 @@ f = open(thisfile, 'r')
 print(f.read())
 f.close()
 
-
 # MAIN ########################################################################
 if __name__ == '__main__':
     # dictionary of simualation parameters to pass to the run function.
@@ -442,6 +441,7 @@ if __name__ == '__main__':
         "L": L,
         "lambda_param": lambda_param,
         "relative_permeability": relative_permeability,
+        "intrinsic_permeability": intrinsic_permeability,
         "sat_pressure_relationship": sat_pressure_relationship,
         # "starttime": starttime,
         "number_of_timesteps": number_of_timesteps,
@@ -458,22 +458,34 @@ if __name__ == '__main__':
         "write_to_file": write_to_file,
         "analyse_condition": analyse_condition
     }
-    for starttime in starttimes:
+    for number_shift, starttime in starttimes.items():
+        simulation_parameter.update(
+            {"starttime_timestep_number_shift": number_shift}
+        )
         for mesh_resolution, solver_tol in resolutions.items():
             simulation_parameter.update({"solver_tol": solver_tol})
             hlp.info(simulation_parameter["use_case"])
+            processQueue = mp.Queue()
             LDDsim = mp.Process(
                         target=hlp.run_simulation,
                         args=(
                             simulation_parameter,
+                            processQueue,
                             starttime,
                             mesh_resolution
                             )
                         )
             LDDsim.start()
-            LDDsim.join()
+            # LDDsim.join()
             # hlp.run_simulation(
             #     mesh_resolution=mesh_resolution,
             #     starttime=starttime,
             #     parameter=simulation_parameter
             #     )
+
+        LDDsim.join()
+        if mesh_study:
+            simulation_output_dir = processQueue.get()
+            hlp.merge_spacetime_errornorms(isRichards=isRichards,
+                                           resolutions=resolutions,
+                                           output_dir=simulation_output_dir)
diff --git a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-mesh-study-all-params-one-but-g.py b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-mesh-study-all-params-one-but-g.py
index d6bc8fe..4d05dc9 100755
--- a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-mesh-study-all-params-one-but-g.py
+++ b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-mesh-study-all-params-one-but-g.py
@@ -56,7 +56,7 @@ resolutions = {
 # starttimes gives a list of starttimes to run the simulation from.
 # The list is looped over and a simulation is run with t_0 as initial time
 #  for each element t_0 in starttimes.
-starttimes = [0.0]
+starttimes = {0: 0.0}
 timestep_size = 0.001
 number_of_timesteps = 800
 
@@ -267,7 +267,6 @@ f = open(thisfile, 'r')
 print(f.read())
 f.close()
 
-
 # MAIN ########################################################################
 if __name__ == '__main__':
     # dictionary of simualation parameters to pass to the run function.
@@ -310,22 +309,34 @@ if __name__ == '__main__':
         "write_to_file": write_to_file,
         "analyse_condition": analyse_condition
     }
-    for starttime in starttimes:
+    for number_shift, starttime in starttimes.items():
+        simulation_parameter.update(
+            {"starttime_timestep_number_shift": number_shift}
+        )
         for mesh_resolution, solver_tol in resolutions.items():
             simulation_parameter.update({"solver_tol": solver_tol})
             hlp.info(simulation_parameter["use_case"])
+            processQueue = mp.Queue()
             LDDsim = mp.Process(
                         target=hlp.run_simulation,
                         args=(
                             simulation_parameter,
+                            processQueue,
                             starttime,
                             mesh_resolution
                             )
                         )
             LDDsim.start()
-            LDDsim.join()
+            # LDDsim.join()
             # hlp.run_simulation(
             #     mesh_resolution=mesh_resolution,
             #     starttime=starttime,
             #     parameter=simulation_parameter
             #     )
+
+        LDDsim.join()
+        if mesh_study:
+            simulation_output_dir = processQueue.get()
+            hlp.merge_spacetime_errornorms(isRichards=isRichards,
+                                           resolutions=resolutions,
+                                           output_dir=simulation_output_dir)
diff --git a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-mesh-study-all-params-one.py b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-mesh-study-all-params-one.py
index c613e0b..2cff89a 100755
--- a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-mesh-study-all-params-one.py
+++ b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-mesh-study-all-params-one.py
@@ -56,7 +56,7 @@ resolutions = {
 # starttimes gives a list of starttimes to run the simulation from.
 # The list is looped over and a simulation is run with t_0 as initial time
 #  for each element t_0 in starttimes.
-starttimes = [0.0]
+starttimes = {0: 0.0}
 timestep_size = 0.001
 number_of_timesteps = 800
 
@@ -267,7 +267,6 @@ f = open(thisfile, 'r')
 print(f.read())
 f.close()
 
-
 # MAIN ########################################################################
 if __name__ == '__main__':
     # dictionary of simualation parameters to pass to the run function.
@@ -310,22 +309,34 @@ if __name__ == '__main__':
         "write_to_file": write_to_file,
         "analyse_condition": analyse_condition
     }
-    for starttime in starttimes:
+    for number_shift, starttime in starttimes.items():
+        simulation_parameter.update(
+            {"starttime_timestep_number_shift": number_shift}
+        )
         for mesh_resolution, solver_tol in resolutions.items():
             simulation_parameter.update({"solver_tol": solver_tol})
             hlp.info(simulation_parameter["use_case"])
+            processQueue = mp.Queue()
             LDDsim = mp.Process(
                         target=hlp.run_simulation,
                         args=(
                             simulation_parameter,
+                            processQueue,
                             starttime,
                             mesh_resolution
                             )
                         )
             LDDsim.start()
-            LDDsim.join()
+            # LDDsim.join()
             # hlp.run_simulation(
             #     mesh_resolution=mesh_resolution,
             #     starttime=starttime,
             #     parameter=simulation_parameter
             #     )
+
+        LDDsim.join()
+        if mesh_study:
+            simulation_output_dir = processQueue.get()
+            hlp.merge_spacetime_errornorms(isRichards=isRichards,
+                                           resolutions=resolutions,
+                                           output_dir=simulation_output_dir)
diff --git a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-mesh-study.py b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-mesh-study.py
index 73de79c..fa70348 100755
--- a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-mesh-study.py
+++ b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-mesh-study.py
@@ -315,18 +315,27 @@ if __name__ == '__main__':
         for mesh_resolution, solver_tol in resolutions.items():
             simulation_parameter.update({"solver_tol": solver_tol})
             hlp.info(simulation_parameter["use_case"])
+            processQueue = mp.Queue()
             LDDsim = mp.Process(
                         target=hlp.run_simulation,
                         args=(
                             simulation_parameter,
+                            processQueue,
                             starttime,
                             mesh_resolution
                             )
                         )
             LDDsim.start()
-            LDDsim.join()
+            # LDDsim.join()
             # hlp.run_simulation(
             #     mesh_resolution=mesh_resolution,
             #     starttime=starttime,
             #     parameter=simulation_parameter
             #     )
+
+        LDDsim.join()
+        if mesh_study:
+            simulation_output_dir = processQueue.get()
+            hlp.merge_spacetime_errornorms(isRichards=isRichards,
+                                           resolutions=resolutions,
+                                           output_dir=simulation_output_dir)
diff --git a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-realistic-gravity-but-same-intrinsic-perm-mesh-study.py b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-realistic-gravity-but-same-intrinsic-perm-mesh-study.py
index 877dae6..ca31d63 100755
--- a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-realistic-gravity-but-same-intrinsic-perm-mesh-study.py
+++ b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-realistic-gravity-but-same-intrinsic-perm-mesh-study.py
@@ -56,7 +56,7 @@ resolutions = {
 # starttimes gives a list of starttimes to run the simulation from.
 # The list is looped over and a simulation is run with t_0 as initial time
 #  for each element t_0 in starttimes.
-starttimes = [0.0]
+starttimes = {0: 0.0}
 timestep_size = 0.001
 number_of_timesteps = 800
 
@@ -267,7 +267,6 @@ f = open(thisfile, 'r')
 print(f.read())
 f.close()
 
-
 # MAIN ########################################################################
 if __name__ == '__main__':
     # dictionary of simualation parameters to pass to the run function.
@@ -310,22 +309,34 @@ if __name__ == '__main__':
         "write_to_file": write_to_file,
         "analyse_condition": analyse_condition
     }
-    for starttime in starttimes:
+    for number_shift, starttime in starttimes.items():
+        simulation_parameter.update(
+            {"starttime_timestep_number_shift": number_shift}
+        )
         for mesh_resolution, solver_tol in resolutions.items():
             simulation_parameter.update({"solver_tol": solver_tol})
             hlp.info(simulation_parameter["use_case"])
+            processQueue = mp.Queue()
             LDDsim = mp.Process(
                         target=hlp.run_simulation,
                         args=(
                             simulation_parameter,
+                            processQueue,
                             starttime,
                             mesh_resolution
                             )
                         )
             LDDsim.start()
-            LDDsim.join()
+            # LDDsim.join()
             # hlp.run_simulation(
             #     mesh_resolution=mesh_resolution,
             #     starttime=starttime,
             #     parameter=simulation_parameter
             #     )
+
+        LDDsim.join()
+        if mesh_study:
+            simulation_output_dir = processQueue.get()
+            hlp.merge_spacetime_errornorms(isRichards=isRichards,
+                                           resolutions=resolutions,
+                                           output_dir=simulation_output_dir)
diff --git a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-realistic-no-gravity-but-varying-intrinsic-perm-mesh-study.py b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-realistic-no-gravity-but-varying-intrinsic-perm-mesh-study.py
index 249ab3f..f124ebf 100755
--- a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-realistic-no-gravity-but-varying-intrinsic-perm-mesh-study.py
+++ b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-realistic-no-gravity-but-varying-intrinsic-perm-mesh-study.py
@@ -56,7 +56,7 @@ resolutions = {
 # starttimes gives a list of starttimes to run the simulation from.
 # The list is looped over and a simulation is run with t_0 as initial time
 #  for each element t_0 in starttimes.
-starttimes = [0.0]
+starttimes = {0: 0.0}
 timestep_size = 0.001
 number_of_timesteps = 800
 
@@ -267,7 +267,6 @@ f = open(thisfile, 'r')
 print(f.read())
 f.close()
 
-
 # MAIN ########################################################################
 if __name__ == '__main__':
     # dictionary of simualation parameters to pass to the run function.
@@ -310,22 +309,34 @@ if __name__ == '__main__':
         "write_to_file": write_to_file,
         "analyse_condition": analyse_condition
     }
-    for starttime in starttimes:
+    for number_shift, starttime in starttimes.items():
+        simulation_parameter.update(
+            {"starttime_timestep_number_shift": number_shift}
+        )
         for mesh_resolution, solver_tol in resolutions.items():
             simulation_parameter.update({"solver_tol": solver_tol})
             hlp.info(simulation_parameter["use_case"])
+            processQueue = mp.Queue()
             LDDsim = mp.Process(
                         target=hlp.run_simulation,
                         args=(
                             simulation_parameter,
+                            processQueue,
                             starttime,
                             mesh_resolution
                             )
                         )
             LDDsim.start()
-            LDDsim.join()
+            # LDDsim.join()
             # hlp.run_simulation(
             #     mesh_resolution=mesh_resolution,
             #     starttime=starttime,
             #     parameter=simulation_parameter
             #     )
+
+        LDDsim.join()
+        if mesh_study:
+            simulation_output_dir = processQueue.get()
+            hlp.merge_spacetime_errornorms(isRichards=isRichards,
+                                           resolutions=resolutions,
+                                           output_dir=simulation_output_dir)
diff --git a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-realistic-same-intrinsic-perm.py b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-realistic-same-intrinsic-perm.py
index 5491080..6943cfe 100755
--- a/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-realistic-same-intrinsic-perm.py
+++ b/Two-phase-Richards/two-patch/TP-R-two-patch-test-case/mesh_studies/TP-R-2-patch-realistic-same-intrinsic-perm.py
@@ -56,7 +56,7 @@ resolutions = {
 # starttimes gives a list of starttimes to run the simulation from.
 # The list is looped over and a simulation is run with t_0 as initial time
 #  for each element t_0 in starttimes.
-starttimes = [0.0]
+starttimes = {0: 0.0}
 timestep_size = 0.001
 number_of_timesteps = 800
 
@@ -267,7 +267,6 @@ f = open(thisfile, 'r')
 print(f.read())
 f.close()
 
-
 # MAIN ########################################################################
 if __name__ == '__main__':
     # dictionary of simualation parameters to pass to the run function.
@@ -310,22 +309,34 @@ if __name__ == '__main__':
         "write_to_file": write_to_file,
         "analyse_condition": analyse_condition
     }
-    for starttime in starttimes:
+    for number_shift, starttime in starttimes.items():
+        simulation_parameter.update(
+            {"starttime_timestep_number_shift": number_shift}
+        )
         for mesh_resolution, solver_tol in resolutions.items():
             simulation_parameter.update({"solver_tol": solver_tol})
             hlp.info(simulation_parameter["use_case"])
+            processQueue = mp.Queue()
             LDDsim = mp.Process(
                         target=hlp.run_simulation,
                         args=(
                             simulation_parameter,
+                            processQueue,
                             starttime,
                             mesh_resolution
                             )
                         )
             LDDsim.start()
-            LDDsim.join()
+            # LDDsim.join()
             # hlp.run_simulation(
             #     mesh_resolution=mesh_resolution,
             #     starttime=starttime,
             #     parameter=simulation_parameter
             #     )
+
+        LDDsim.join()
+        if mesh_study:
+            simulation_output_dir = processQueue.get()
+            hlp.merge_spacetime_errornorms(isRichards=isRichards,
+                                           resolutions=resolutions,
+                                           output_dir=simulation_output_dir)
-- 
GitLab