From 83d6d57aeb158aba0d3b4a54e82b9bd8aa6dd809 Mon Sep 17 00:00:00 2001
From: David Seus <david.seus@ians.uni-stuttgart.de>
Date: Sat, 10 Aug 2019 16:35:18 +0200
Subject: [PATCH] run several new examples

---
 LDDsimulation/LDDsimulation.py                |   4 +-
 LDDsimulation/helpers.py                      |  19 +-
 TP-R-two-patch-test-case/TP-R-2-patch-test.py |  29 +-
 .../TP-TP-2-patch-pure-dd.py                  |  47 +-
 .../TP-TP-layered_soil_with_inner_patch.py    | 427 +++++++++---------
 TP-TP-layered-soil-case/TP-TP-layered_soil.py | 174 +++----
 ...h-with-gravity-same-wetting-phase-as-RR.py |  38 +-
 .../TP-one-patch-linear-koefficients.py       |  44 +-
 TP-one-patch/TP-one-patch.py                  |  18 +-
 9 files changed, 404 insertions(+), 396 deletions(-)

diff --git a/LDDsimulation/LDDsimulation.py b/LDDsimulation/LDDsimulation.py
index e75dccb..310f1b8 100644
--- a/LDDsimulation/LDDsimulation.py
+++ b/LDDsimulation/LDDsimulation.py
@@ -106,7 +106,7 @@ class LDDsimulation(object):
 
         ## Private variables
         # maximal number of L-iterations that the LDD solver uses.
-        self._max_iter_num = 500
+        self._max_iter_num = 1000
         # TODO rewrite this with regard to the mesh sizes
         # self.calc_tol = self.tol
         # list of timesteps that get analyed. Gets initiated by self._init_analyse_timesteps
@@ -470,7 +470,7 @@ class LDDsimulation(object):
                     subsequent_error_filename = self.output_dir\
                         +self.output_filename_parameter_part[sd_index]\
                         +"subsequent_iteration_errors" +"_at_time"+\
-                        "{number:.{digits}f}".format(number=time, digits=4) +".csv"
+                        "{number}".format(number=self.timestep_num) +".csv"  #"{number:.{digits}f}".format(number=time, digits=4)
                     self.write_subsequent_errors_to_csv(
                         filename = subsequent_error_filename, #
                         subdomain_index = sd_index,
diff --git a/LDDsimulation/helpers.py b/LDDsimulation/helpers.py
index 0665caa..803031f 100644
--- a/LDDsimulation/helpers.py
+++ b/LDDsimulation/helpers.py
@@ -31,8 +31,10 @@ def generate_exact_solution_expressions(
                                         porosity: tp.Dict[int, tp.Dict[str, float]],#
                                         relative_permeability: tp.Dict[int, tp.Dict[str, tp.Callable[...,None]] ],#
                                         relative_permeability_prime: tp.Dict[int, tp.Dict[str, tp.Callable[...,None]] ],
-                                        saturation_pressure_relationship: tp.Dict[int, tp.Callable[...,None]],#
-                                        saturation_pressure_relationship_prime: tp.Dict[int, tp.Callable[...,None]],#
+                                        saturation_pressure_relationship: tp.Dict[int, tp.Callable[...,None]] = None,#
+                                        saturation_pressure_relationship_prime: tp.Dict[int, tp.Callable[...,None]] = None,#
+                                        symbolic_S_pc_relationship: tp.Dict[int, tp.Callable[...,None]] = None,#
+                                        symbolic_S_pc_relationship_prime: tp.Dict[int, tp.Callable[...,None]] = None,#
                                         densities: tp.Dict[int, tp.Dict[str, float]] = None,#
                                         gravity_acceleration: float = 9.81,
                                         include_gravity: bool = False,
@@ -51,8 +53,9 @@ def generate_exact_solution_expressions(
     # construct the rhs that matches the above exact solution.
     dtS = dict()
     div_flux = dict()
-    S_pc_sym = saturation_pressure_relationship
-    S_pc_sym_prime = saturation_pressure_relationship_prime
+    if saturation_pressure_relationship is not None:
+        S_pc_sym = saturation_pressure_relationship
+        S_pc_sym_prime = saturation_pressure_relationship_prime
     for subdomain, isR in isRichards.items():
         dtS.update({subdomain: dict()})
         div_flux.update({subdomain: dict()})
@@ -69,8 +72,12 @@ def generate_exact_solution_expressions(
         dtpc = sym.diff(pc, t, 1)
         dxpc = sym.diff(pc, x, 1)
         dypc = sym.diff(pc, y, 1)
-        S = sym.Piecewise((S_pc_sym[subdomain](pc), pc > 0), (1, True))
-        dS = sym.Piecewise((S_pc_sym_prime[subdomain](pc), pc > 0), (0, True))
+        if saturation_pressure_relationship is not None:
+            S = sym.Piecewise((S_pc_sym[subdomain](pc), pc > 0), (1, True))
+            dS = sym.Piecewise((S_pc_sym_prime[subdomain](pc), pc > 0), (0, True))
+        else:
+            S = symbolic_S_pc_relationship[subdomain]
+            dS = symbolic_S_pc_relationship_prime[subdomain]
         for phase in subdomain_has_phases:
             # Turn above symbolic expression for exact solution into c code
             output['exact_solution'][subdomain].update(
diff --git a/TP-R-two-patch-test-case/TP-R-2-patch-test.py b/TP-R-two-patch-test-case/TP-R-2-patch-test.py
index 9924115..ad5199e 100755
--- a/TP-R-two-patch-test-case/TP-R-2-patch-test.py
+++ b/TP-R-two-patch-test-case/TP-R-2-patch-test.py
@@ -13,23 +13,28 @@ import helpers as hlp
 # init sympy session
 sym.init_printing()
 
-solver_tol = 5e-7
-######################## GRID #######################
-mesh_resolution = 30
+solver_tol = 1E-7
+
+############ GRID #######################ü
+mesh_resolution = 40
 timestep_size = 0.0001
-number_of_timesteps = 50
+number_of_timesteps = 10
 # decide how many timesteps you want analysed. Analysed means, that we write out
 # subsequent errors of the L-iteration within the timestep.
 number_of_timesteps_to_analyse = 10
 starttime = 0
 
-Lw = 1/timestep_size
+Lw = 4  #/timestep_size
 Lnw=Lw
 
-l_param_w = 40
-l_param_nw = l_param_w
+l_param_w = 60
+l_param_nw = 60
 
 include_gravity = True
+debugflag = True
+analyse_condition = False
+
+output_string = "./output/nondirichlet_number_of_timesteps{}_".format(number_of_timesteps)
 
 ##### Domain and Interface ####
 # global simulation domain domain
@@ -317,9 +322,9 @@ x, y = sym.symbols('x[0], x[1]')  # needed by UFL
 t = sym.symbols('t', positive=True)
 
 p_e_sym = {
-    1: {'wetting': (1.0 - (1.0 + t*t)*(1.0 + x*x + y*y))*(1-x)**2*(1+x)**2*(1-y)**2},
-    2: {'wetting': (1.0 - (1.0 + t*t)*(1.0 + x*x))*(1-x)**2*(1+x)**2*(1+y)**2,
-        'nonwetting': (-t**2*(1+y + x**2)**2 - sym.sqrt(2+t**4))*y**2*(1-x)**2*(1+x)**2*(1+y)**2},
+    1: {'wetting': (-3.0 - (1.0 + t*t)*(1.0 + x*x + y*y))}, #*(1-x)**2*(1+x)**2*(1-y)**2},
+    2: {'wetting': (-3.0 - (1.0 + t*t)*(1.0 + x*x)), #*(1-x)**2*(1+x)**2*(1+y)**2,
+        'nonwetting': (-t**2*(1+y + x**2)**2 - sym.sqrt(2+t**4))*y**2}, #*(1-x)**2*(1+x)**2*(1+y)**2},
 } #-y*y*(sym.sin(-2*t+2*x)*sym.sin(1/2*y-1.2*t)) - t*t*x*(0.5-y)*y*(1-x)
 
 
@@ -399,7 +404,7 @@ write_to_file = {
 
 # initialise LDD simulation class
 simulation = ldd.LDDsimulation(tol = 1E-14, LDDsolver_tol=solver_tol, debug=True)
-simulation.set_parameters(output_dir = "./output/",#
+simulation.set_parameters(output_dir = output_string,#
     subdomain_def_points = subdomain_def_points,#
     isRichards = isRichards,#
     interface_def_points = interface_def_points,#
@@ -427,4 +432,4 @@ simulation.set_parameters(output_dir = "./output/",#
 
 simulation.initialise()
 # simulation.write_exact_solution_to_xdmf()
-simulation.run()
+simulation.run(analyse_condition=analyse_condition)
diff --git a/TP-TP-2-patch-pure-dd/TP-TP-2-patch-pure-dd.py b/TP-TP-2-patch-pure-dd/TP-TP-2-patch-pure-dd.py
index a2f841a..c9b8d4a 100755
--- a/TP-TP-2-patch-pure-dd/TP-TP-2-patch-pure-dd.py
+++ b/TP-TP-2-patch-pure-dd/TP-TP-2-patch-pure-dd.py
@@ -13,23 +13,28 @@ import helpers as hlp
 # init sympy session
 sym.init_printing()
 
-solver_tol = 1E-6
+solver_tol = 5E-7
 
 ############ GRID #######################ü
-mesh_resolution = 31
-timestep_size = 0.001
-number_of_timesteps = 15
+mesh_resolution = 50
+timestep_size = 0.0001
+number_of_timesteps = 1000
 # decide how many timesteps you want analysed. Analysed means, that we write out
 # subsequent errors of the L-iteration within the timestep.
-number_of_timesteps_to_analyse = 11
+number_of_timesteps_to_analyse = 10
 starttime = 0
 
+Lw = 1  #/timestep_size
+Lnw=Lw
+
+l_param_w = 40
+l_param_nw = 40
+
 include_gravity = True
-Lw = 10/timestep_size
-Lnw = Lw
+debugflag = False
+analyse_condition = True
 
-l_param_w = 50
-l_param_nw = l_param_w
+output_string = "./output/nondirichlet_number_of_timesteps{}_".format(number_of_timesteps)
 
 ##### Domain and Interface ####
 # global simulation domain domain
@@ -412,20 +417,22 @@ Spc = {
     2: sym.Piecewise((pc_saturation_sym[2](sat_sym[2]), sat_sym[2] > 0), (pc_saturation_sym[2](sat_sym[2]), 2>=sat_sym[2]), (0, True))
     }
 
-p1w = (-1 - (1+t*t)*(1 + x*x + y*y))*cutoff
+p1w = (-1 - (1+t*t)*(1 + x*x + y*y))#*cutoff
 p2w = p1w
 p_e_sym = {
     1: {'wetting': p1w,
-        'nonwetting': (p1w + Spc[1])*cutoff},
+        'nonwetting': (p1w + Spc[1])}, #*cutoff},
     2: {'wetting': p2w,
-        'nonwetting': (p2w + Spc[2])*cutoff},
-}
-
-pc_e_sym = {
-    1: p_e_sym[1]['nonwetting'] - p_e_sym[1]['wetting'],
-    2: p_e_sym[2]['nonwetting'] - p_e_sym[2]['wetting'],
+        'nonwetting': (p2w + Spc[2])}, #*cutoff},
 }
 
+pc_e_sym = dict()
+for subdomain, isR in isRichards.items():
+    if isR:
+        pc_e_sym.update({subdomain: -p_e_sym[subdomain]['wetting']})
+    else:
+        pc_e_sym.update({subdomain: p_e_sym[subdomain]['nonwetting']
+                                        - p_e_sym[subdomain]['wetting']})
 
 # pc_e_sym = {
 #     1: -1*p_e_sym[1]['wetting'],
@@ -493,8 +500,8 @@ write_to_file = {
 
 
 # initialise LDD simulation class
-simulation = ldd.LDDsimulation(tol = 1E-14, LDDsolver_tol=solver_tol, debug = True)
-simulation.set_parameters(output_dir = "./output/with_dirichlet_zero",#
+simulation = ldd.LDDsimulation(tol=1E-14, LDDsolver_tol=solver_tol, debug=debugflag)
+simulation.set_parameters(output_dir = output_string,#
     subdomain_def_points = subdomain_def_points,#
     isRichards = isRichards,#
     interface_def_points = interface_def_points,#
@@ -522,4 +529,4 @@ simulation.set_parameters(output_dir = "./output/with_dirichlet_zero",#
 
 simulation.initialise()
 # simulation.write_exact_solution_to_xdmf()
-simulation.run()
+simulation.run(analyse_condition=analyse_condition)
diff --git a/TP-TP-layered-soil-case-with-inner-patch/TP-TP-layered_soil_with_inner_patch.py b/TP-TP-layered-soil-case-with-inner-patch/TP-TP-layered_soil_with_inner_patch.py
index 868fd4f..b1a38f8 100755
--- a/TP-TP-layered-soil-case-with-inner-patch/TP-TP-layered_soil_with_inner_patch.py
+++ b/TP-TP-layered-soil-case-with-inner-patch/TP-TP-layered_soil_with_inner_patch.py
@@ -16,57 +16,59 @@ import typing as tp
 import functools as ft
 import domainPatch as dp
 import LDDsimulation as ldd
+import helpers as hlp
 
 # init sympy session
 sym.init_printing()
 
-# ----------------------------------------------------------------------------#
-# ------------------- MESH ---------------------------------------------------#
-# ----------------------------------------------------------------------------#
-mesh_resolution = 50
-# ----------------------------------------:-----------------------------------#
-# ------------------- TIME ---------------------------------------------------#
-# ----------------------------------------------------------------------------#
-timestep_size = 0.0001
-number_of_timesteps = 50
-# decide how many timesteps you want analysed. Analysed means, that we write
-# out subsequent errors of the L-iteration within the timestep.
-number_of_timesteps_to_analyse = 4
+solver_tol = 5E-7
+
+############ GRID #######################ü
+mesh_resolution = 40
+timestep_size = 0.0005
+number_of_timesteps = 1000
+# decide how many timesteps you want analysed. Analysed means, that we write out
+# subsequent errors of the L-iteration within the timestep.
+number_of_timesteps_to_analyse = 5
 starttime = 0
 
-Lw = 10000
-Lnw = 10000
+Lw = 0.25  #/timestep_size
+Lnw=Lw
 
-l_param_w = 30
+l_param_w = 40
 l_param_nw = 40
+
+include_gravity = True
+debugflag = False
+analyse_condition = True
+
+output_string = "./output/nondirichlet_number_of_timesteps{}_".format(number_of_timesteps)
+
 # global domain
-subdomain0_vertices = [df.Point(0.0,0.0), #
-                        df.Point(13.0,0.0),#
-                        df.Point(13.0,8.0),#
-                        df.Point(0.0,8.0)]
+subdomain0_vertices = [df.Point(-1.0,-1.0), #
+                        df.Point(1.0,-1.0),#
+                        df.Point(1.0,1.0),#
+                        df.Point(-1.0,1.0)]
 
-interface12_vertices = [df.Point(0.0, 7.0),
-                        df.Point(9.0, 7.0),
-                        df.Point(10.5, 7.5),
-                        df.Point(12.0, 7.0),
-                        df.Point(13.0, 6.5)]
+interface12_vertices = [df.Point(-1.0, 0.8),
+                        df.Point(0.3, 0.8),
+                        df.Point(0.5, 0.9),
+                        df.Point(0.8, 0.7),
+                        df.Point(1.0, 0.65)]
 
 
-# interface23
-interface23_vertices = [df.Point(0.0, 5.0),
-                        df.Point(3.0, 5.0),
+                        # interface23
+interface23_vertices = [df.Point(-1.0, 0.0),
+                        df.Point(-0.35, 0.0),
                         # df.Point(6.5, 4.5),
-                        df.Point(6.5, 5.0)]
+                        df.Point(0.0, 0.0)]
 
-interface24_vertices = [df.Point(6.5, 5.0),
-                        df.Point(9.5, 5.0),
-                        # df.Point(11.5, 3.5),
-                        # df.Point(13.0, 3)
-                        df.Point(11.5, 5.0)
+interface24_vertices = [interface23_vertices[2],
+                        df.Point(0.6, 0.0),
                         ]
 
-interface25_vertices = [df.Point(11.5, 5.0),
-                        df.Point(13.0, 5.0)
+interface25_vertices = [interface24_vertices[1],
+                        df.Point(1.0, 0.0)
                         ]
 
 
@@ -74,26 +76,72 @@ interface32_vertices = [interface23_vertices[2],
                         interface23_vertices[1],
                         interface23_vertices[0]]
 
-interface34_vertices = [df.Point(4.0, 2.0),
-                        df.Point(4.7, 3.0),
-                        interface23_vertices[2]]
-# interface36
-interface36_vertices = [df.Point(0.0, 2.0),
-                        df.Point(4.0, 2.0)]
+
+interface36_vertices = [df.Point(-1.0, -0.6),
+                        df.Point(-0.6, -0.45)]
 
 
-interface46_vertices = [df.Point(4.0, 2.0),
-                        df.Point(9.0, 2.5)]
+interface46_vertices = [interface36_vertices[1],
+                        df.Point(0.3, -0.25)]
+
+interface56_vertices = [interface46_vertices[1],
+                        df.Point(0.65, -0.6),
+                        df.Point(1.0, -0.7)]
+
+
+
+
+interface34_vertices = [interface36_vertices[1],
+                        interface23_vertices[2]]
+# interface36
 
-interface45_vertices = [df.Point(9.0, 2.5),
-                        df.Point(10.0, 3.0),
+interface45_vertices = [interface56_vertices[0],
+                        df.Point(0.7, -0.2),
                         interface25_vertices[0]
                         ]
 
-interface56_vertices = [df.Point(9.0, 2.5),
-                        df.Point(10.5, 2.0),
-                        df.Point(13.0, 1.5)]
+# # subdomain1.
+# subdomain1_vertices = [interface12_vertices[0],
+#                         interface12_vertices[1],
+#                         interface12_vertices[2],
+#                         interface12_vertices[3],
+#                         interface12_vertices[4], # southern boundary, 12 interface
+#                         subdomain0_vertices[2], # eastern boundary, outer boundary
+#                         subdomain0_vertices[3]] # northern boundary, outer on_boundary
+#
+# # vertex coordinates of the outer boundaries. If it can not be specified as a
+# # polygon, use an entry per boundary polygon. This information is used for defining
+# # the Dirichlet boundary conditions. If a domain is completely internal, the
+# # dictionary entry should be 0: None
+# subdomain1_outer_boundary_verts = {
+#     0: [interface12_vertices[4], #
+#         subdomain0_vertices[2], # eastern boundary, outer boundary
+#         subdomain0_vertices[3],
+#         interface12_vertices[0]]
+# }
+#
+
 
+# #subdomain1
+# subdomain2_vertices = [interface23_vertices[0],
+#                         interface23_vertices[1],
+#                         interface23_vertices[2],
+#                         interface23_vertices[3],
+#                         interface23_vertices[4],
+#                         interface23_vertices[5], # southern boundary, 23 interface
+#                         subdomain1_vertices[4], # eastern boundary, outer boundary
+#                         subdomain1_vertices[3],
+#                         subdomain1_vertices[2],
+#                         subdomain1_vertices[1],
+#                         subdomain1_vertices[0] ] # northern boundary, 12 interface
+#
+# subdomain2_outer_boundary_verts = {
+#     0: [interface23_vertices[5],
+#         subdomain1_vertices[4]],
+#     1: [subdomain1_vertices[0],
+#         interface23_vertices[0]]
+# }
+#
 
 # interface_vertices introduces a global numbering of interfaces.
 interface_def_points = [interface12_vertices,
@@ -131,10 +179,10 @@ subdomain1_vertices = [interface12_vertices[0],
 # the Dirichlet boundary conditions. If a domain is completely internal, the
 # dictionary entry should be 0: None
 subdomain1_outer_boundary_verts = {
-    0: [interface12_vertices[4], #
-        subdomain0_vertices[2], # eastern boundary, outer boundary
-        subdomain0_vertices[3],
-        interface12_vertices[0]]
+    0: [subdomain1_vertices[4], #
+        subdomain1_vertices[5], # eastern boundary, outer boundary
+        subdomain1_vertices[6],
+        subdomain1_vertices[0]]
 }
 
 #subdomain1
@@ -142,7 +190,6 @@ subdomain2_vertices = [interface23_vertices[0],
                         interface23_vertices[1],
                         interface23_vertices[2],
                         interface24_vertices[1],
-                        interface24_vertices[2],
                         interface25_vertices[1], # southern boundary, 23 interface
                         subdomain1_vertices[4], # eastern boundary, outer boundary
                         subdomain1_vertices[3],
@@ -151,10 +198,10 @@ subdomain2_vertices = [interface23_vertices[0],
                         subdomain1_vertices[0] ] # northern boundary, 12 interface
 
 subdomain2_outer_boundary_verts = {
-    0: [interface25_vertices[1],
-        subdomain1_vertices[4]],
-    1: [subdomain1_vertices[0],
-        interface23_vertices[0]]
+    0: [subdomain2_vertices[9],
+        subdomain2_vertices[0]],
+    1: [subdomain2_vertices[4],
+        subdomain2_vertices[5]]
 }
 
 
@@ -162,14 +209,13 @@ subdomain3_vertices = [interface36_vertices[0],
                        interface36_vertices[1],
                        # interface34_vertices[0],
                        interface34_vertices[1],
-                       interface34_vertices[2],
                        # interface32_vertices[0],
                        interface32_vertices[1],
                        interface32_vertices[2]
                        ]
 
 subdomain3_outer_boundary_verts = {
-    0: [subdomain2_vertices[0],
+    0: [subdomain3_vertices[4],
         subdomain3_vertices[0]]
 }
 
@@ -177,8 +223,7 @@ subdomain3_outer_boundary_verts = {
 # subdomain3
 subdomain4_vertices = [interface46_vertices[0],
                        interface46_vertices[1],
-                       df.Point(10.0, 3.0),
-                       interface24_vertices[2],
+                       interface45_vertices[1],
                        interface24_vertices[1],
                        interface24_vertices[0],
                        interface34_vertices[1]
@@ -212,10 +257,10 @@ subdomain6_vertices = [subdomain0_vertices[0],
                        ]
 
 subdomain6_outer_boundary_verts = {
-    0: [subdomain4_vertices[6],
-        subdomain4_vertices[0],
-        subdomain4_vertices[1],
-        subdomain4_vertices[2]]
+    0: [subdomain6_vertices[6],
+        subdomain6_vertices[0],
+        subdomain6_vertices[1],
+        subdomain6_vertices[2]]
 }
 
 
@@ -242,24 +287,25 @@ outer_boundary_def_points = {
     6: subdomain6_outer_boundary_verts
 }
 
-# isRichards = {
-#     1: False,
-#     2: False,
-#     3: False,
-#     4: False,
-#     5: False,
-#     6: False
-#     }
 
 isRichards = {
-    1: True,
-    2: True,
-    3: True,
-    4: True,
-    5: True,
-    6: True
+    1: False,
+    2: False,
+    3: False,
+    4: False,
+    5: False,
+    6: False
     }
 
+# isRichards = {
+#     1: True,
+#     2: True,
+#     3: True,
+#     4: True,
+#     5: True,
+#     6: True
+#     }
+
 # Dict of the form: { subdom_num : viscosity }
 viscosity = {
     1: {'wetting' :1,
@@ -349,31 +395,31 @@ def rel_perm1nw(s):
     return (1-s)**2
 
 
-# ## relative permeabilty functions on subdomain 2
-# def rel_perm2w(s):
-#     # relative permeabilty wetting on subdomain2
-#     return s**3
-#
-#
-# def rel_perm2nw(s):
-#     # relative permeabilty nonwetting on subdosym.cos(0.8*t - (0.8*x + 1/7*y))main2
-#     return (1-s)**2
+## relative permeabilty functions on subdomain 2
+def rel_perm2w(s):
+    # relative permeabilty wetting on subdomain2
+    return s**3
+
+
+def rel_perm2nw(s):
+    # relative permeabilty nonwetting on subdosym.cos(0.8*t - (0.8*x + 1/7*y))main2
+    return (1-s)**3
 
 
 _rel_perm1w = ft.partial(rel_perm1w)
 _rel_perm1nw = ft.partial(rel_perm1nw)
-# _rel_perm2w = ft.partial(rel_perm2w)
-# _rel_perm2nw = ft.partial(rel_perm2nw)
+_rel_perm2w = ft.partial(rel_perm2w)
+_rel_perm2nw = ft.partial(rel_perm2nw)
 
 subdomain1_rel_perm = {
     'wetting': _rel_perm1w,#
     'nonwetting': _rel_perm1nw
 }
 
-# subdomain2_rel_perm = {
-#     'wetting': _rel_perm2w,#
-#     'nonwetting': _rel_perm2nw
-# }
+subdomain2_rel_perm = {
+    'wetting': _rel_perm2w,#
+    'nonwetting': _rel_perm2nw
+}
 
 # _rel_perm3 = ft.partial(rel_perm2)
 # subdomain3_rel_perm = subdomain2_rel_perm.copy()
@@ -385,10 +431,10 @@ subdomain1_rel_perm = {
 relative_permeability = {
     1: subdomain1_rel_perm,
     2: subdomain1_rel_perm,
-    3: subdomain1_rel_perm,
-    4: subdomain1_rel_perm,
-    5: subdomain1_rel_perm,
-    6: subdomain1_rel_perm,
+    3: subdomain2_rel_perm,
+    4: subdomain2_rel_perm,
+    5: subdomain2_rel_perm,
+    6: subdomain2_rel_perm,
 }
 
 # definition of the derivatives of the relative permeabilities
@@ -399,22 +445,22 @@ def rel_perm1w_prime(s):
 
 def rel_perm1nw_prime(s):
     # relative permeabilty on subdomain1
-    return 2*(1-s)
+    return -2*(1-s)
 
-# # definition of the derivatives of the relative permeabilities
-# # relative permeabilty functions on subdomain 1
-# def rel_perm2w_prime(s):
-#     # relative permeabilty on subdomain1
-#     return 3*s**2
-#
-# def rel_perm2nw_prime(s):
-#     # relative permeabilty on subdomain1
-#     return 2*(l_param_w1-s)
+# definition of the derivatives of the relative permeabilities
+# relative permeabilty functions on subdomain 1
+def rel_perm2w_prime(s):
+    # relative permeabilty on subdomain1
+    return 3*s**2
+
+def rel_perm2nw_prime(s):
+    # relative permeabilty on subdomain1
+    return -3*(1-s)**2
 
 _rel_perm1w_prime = ft.partial(rel_perm1w_prime)
 _rel_perm1nw_prime = ft.partial(rel_perm1nw_prime)
-# _rel_perm2w_prime = ft.partial(rel_perm2w_prime)
-# _rel_perm2nw_prime = ft.partial(rel_perm2nw_prime)
+_rel_perm2w_prime = ft.partial(rel_perm2w_prime)
+_rel_perm2nw_prime = ft.partial(rel_perm2nw_prime)
 
 subdomain1_rel_perm_prime = {
     'wetting': _rel_perm1w_prime,
@@ -422,19 +468,19 @@ subdomain1_rel_perm_prime = {
 }
 
 
-# subdomain2_rel_perm_prime = {
-#     'wetting': _rel_perm2w_prime,
-#     'nonwetting': _rel_perm2nw_prime
-# }
+subdomain2_rel_perm_prime = {
+    'wetting': _rel_perm2w_prime,
+    'nonwetting': _rel_perm2nw_prime
+}
 
 # dictionary of relative permeabilties on all domains.
 ka_prime = {
     1: subdomain1_rel_perm_prime,
     2: subdomain1_rel_perm_prime,
-    3: subdomain1_rel_perm_prime,
-    4: subdomain1_rel_perm_prime,
-    5: subdomain1_rel_perm_prime,
-    6: subdomain1_rel_perm_prime,
+    3: subdomain2_rel_perm_prime,
+    4: subdomain2_rel_perm_prime,
+    5: subdomain2_rel_perm_prime,
+    6: subdomain2_rel_perm_prime,
 }
 
 
@@ -546,19 +592,20 @@ sat_pressure_relationship = {
 x, y = sym.symbols('x[0], x[1]')  # needed by UFL
 t = sym.symbols('t', positive=True)
 
+
 p_e_sym = {
-    1: {'wetting': 1.0 - (1.0 + t*t)*(1.0 + (x-6.5)*(x-6.5) + (y-5.0)*(y-5.0)),
-        'nonwetting': - 2 - t*(1 + (y-5.0) + x**2)**2 -sym.sqrt(2+t**2)*(1 + (y-5.0)) },
-    2: {'wetting': 1.0 - (1.0 + t*t)*(1.0 + (x-6.5)*(x-6.5) + (y-5.0)*(y-5.0)),
-        'nonwetting': - 2 - t*(1 + (y-5.0) + x**2)**2 -sym.sqrt(2+t**2)*(1 + (y-5.0)) },
-    3: {'wetting': 1.0 - (1.0 + t*t)*(1.0 + (x-6.5)*(x-6.5)),
-        'nonwetting': - 2 - t*(1 + (y-5.0) + x**2)**2 -sym.sqrt(2+t**2)*(1 + (y-5.0)) },
-    4: {'wetting': 1.0 - (1.0 + t*t)*(1.0 + (x-6.5)*(x-6.5)),
-        'nonwetting': - 2 - t*(1 + (y-5.0) + x**2)**2 -sym.sqrt(2+t**2)*(1 + (y-5.0)) },
-    5: {'wetting': 1.0 - (1.0 + t*t)*(1.0 + (x-6.5)*(x-6.5)),
-        'nonwetting': - 2 - t*(1 + (y-5.0) + x**2)**2 -sym.sqrt(2+t**2)*(1 + (y-5.0)) },
-    6: {'wetting': 1.0 - (1.0 + t*t)*(1.0 + (x-6.5)*(x-6.5)),
-        'nonwetting': - 2 - t*(1 + (y-5.0) + x**2)**2 -sym.sqrt(2+t**2)*(1 + (y-5.0)) },
+    1: {'wetting': -3.0 - (1.0 + t*t)*(1.0 + x*x + y*y),
+        'nonwetting': (-1 -t*(1-y - x**2)**2) },
+    2: {'wetting': -3.0 - (1.0 + t*t)*(1.0 + x*x + y*y),
+        'nonwetting': (-1 -t*(1-y - x**2)**2) },
+    3: {'wetting': (-3.0 - (1.0 + t*t)*(1.0 + x*x)),
+        'nonwetting': (-1 -t*(1- x**2)**2 - sym.sqrt(2+t**2)*(1+y)*y**2) },
+    4: {'wetting': (-3.0 - (1.0 + t*t)*(1.0 + x*x)),
+        'nonwetting': (-1 -t*(1- x**2)**2 - sym.sqrt(2+t**2)*(1+y)*y**2) },
+    5: {'wetting': (-3.0 - (1.0 + t*t)*(1.0 + x*x)),
+        'nonwetting': (-1 -t*(1- x**2)**2 - sym.sqrt(2+t**2)*(1+y)*y**2) },
+    6: {'wetting': (-3.0 - (1.0 + t*t)*(1.0 + x*x)),
+        'nonwetting': (-1 -t*(1- x**2)**2 - sym.sqrt(2+t**2)*(1+y)*y**2) },
     # 2: {'wetting': 1.0 - (1.0 + t*t)*(10.0 + x*x + (y-5.0)*(y-5.0)),
     #     'nonwetting': - 2 - t*(1 + (y-5.0) + x**2)**2 -sym.sqrt(2+t**2)*(1 + (y-5.0))},
     # 3: {'wetting': 1.0 - (1.0 + t*t)*(10.0 + x*x + (y-5.0)*(y-5.0)*3*sym.sin(-2*t+2*x)*sym.sin(1/2*y-1.2*t)),
@@ -576,86 +623,48 @@ p_e_sym = {
 #     6: p_e_sym[5]['nonwetting'] - p_e_sym[6]['wetting']
 # }
 
-pc_e_sym = {
-    1: -p_e_sym[1]['wetting'],
-    2: -p_e_sym[2]['wetting'],
-    3: -p_e_sym[3]['wetting'],
-    4: -p_e_sym[4]['wetting'],
-    5: -p_e_sym[5]['wetting'],
-    6: -p_e_sym[6]['wetting']
-}
+# pc_e_sym = {
+#     1: -p_e_sym[1]['wetting'],
+#     2: -p_e_sym[2]['wetting'],
+#     3: -p_e_sym[3]['wetting'],
+#     4: -p_e_sym[4]['wetting'],
+#     5: -p_e_sym[5]['wetting'],
+#     6: -p_e_sym[6]['wetting']
+# }
 
 
-# turn above symbolic code into exact solution for dolphin and
-# construct the rhs that matches the above exact solution.
-dtS = dict()
-div_flux = dict()
-source_expression = dict()
-exact_solution = dict()
-initial_condition = dict()
+pc_e_sym = dict()
 for subdomain, isR in isRichards.items():
-    dtS.update({subdomain: dict()})
-    div_flux.update({subdomain: dict()})
-    source_expression.update({subdomain: dict()})
-    exact_solution.update({subdomain: dict()})
-    initial_condition.update({subdomain: dict()})
     if isR:
-        subdomain_has_phases = ["wetting"]
+        pc_e_sym.update({subdomain: -p_e_sym[subdomain]['wetting']})
     else:
-        subdomain_has_phases = ["wetting", "nonwetting"]
-
-    # conditional for S_pc_prime
-    pc = pc_e_sym[subdomain]
-    dtpc = sym.diff(pc, t, 1)
-    dxpc = sym.diff(pc, x, 1)
-    dypc = sym.diff(pc, y, 1)
-    S = sym.Piecewise((S_pc_sym[subdomain](pc), pc > 0), (1, True))
-    dS = sym.Piecewise((S_pc_sym_prime[subdomain](pc), pc > 0), (0, True))
-    for phase in subdomain_has_phases:
-        # Turn above symbolic expression for exact solution into c code
-        exact_solution[subdomain].update(
-            {phase: sym.printing.ccode(p_e_sym[subdomain][phase])}
-            )
-        # save the c code for initial conditions
-        initial_condition[subdomain].update(
-            {phase: sym.printing.ccode(p_e_sym[subdomain][phase].subs(t, 0))}
-            )
-        if phase == "nonwetting":
-            dtS[subdomain].update(
-                {phase: -porosity[subdomain]*dS*dtpc}
-                )
-        else:
-            dtS[subdomain].update(
-                {phase: porosity[subdomain]*dS*dtpc}
-                )
-        pa = p_e_sym[subdomain][phase]
-        dxpa = sym.diff(pa, x, 1)
-        dxdxpa = sym.diff(pa, x, 2)
-        dypa = sym.diff(pa, y, 1)
-        dydypa = sym.diff(pa, y, 2)
-        mu = viscosity[subdomain][phase]
-        ka = relative_permeability[subdomain][phase]
-        dka = ka_prime[subdomain][phase]
-        rho = densities[subdomain][phase]
-        g = gravity_acceleration
-
-        if phase == "nonwetting":
-            # x part of div(flux) for nonwetting
-            dxdxflux = -1/mu*dka(1-S)*dS*dxpc*dxpa + 1/mu*dxdxpa*ka(1-S)
-            # y part of div(flux) for nonwetting
-            dydyflux = -1/mu*dka(1-S)*dS*dypc*(dypa - rho*g) \
-                + 1/mu*dydypa*ka(1-S)
-        else:
-            # x part of div(flux) for wetting
-            dxdxflux = 1/mu*dka(S)*dS*dxpc*dxpa + 1/mu*dxdxpa*ka(S)
-            # y part of div(flux) for wetting
-            dydyflux = 1/mu*dka(S)*dS*dypc*(dypa - rho*g) + 1/mu*dydypa*ka(S)
-        div_flux[subdomain].update({phase: dxdxflux + dydyflux})
-        contructed_rhs = dtS[subdomain][phase] - div_flux[subdomain][phase]
-        source_expression[subdomain].update(
-            {phase: sym.printing.ccode(contructed_rhs)}
-            )
-        # print(f"source_expression[{subdomain}][{phase}] =", source_expression[subdomain][phase])
+        pc_e_sym.update({subdomain: p_e_sym[subdomain]['nonwetting']
+                                        - p_e_sym[subdomain]['wetting']})
+
+
+symbols = {"x": x,
+           "y": y,
+           "t": t}
+# turn above symbolic code into exact solution for dolphin and
+# construct the rhs that matches the above exact solution.
+exact_solution_example = hlp.generate_exact_solution_expressions(
+                        symbols=symbols,
+                        isRichards=isRichards,
+                        symbolic_pressure=p_e_sym,
+                        symbolic_capillary_pressure=pc_e_sym,
+                        saturation_pressure_relationship=S_pc_sym,
+                        saturation_pressure_relationship_prime=S_pc_sym_prime,
+                        viscosity=viscosity,
+                        porosity=porosity,
+                        relative_permeability=relative_permeability,
+                        relative_permeability_prime=ka_prime,
+                        densities=densities,
+                        gravity_acceleration=gravity_acceleration,
+                        include_gravity=include_gravity,
+                        )
+source_expression = exact_solution_example['source']
+exact_solution = exact_solution_example['exact_solution']
+initial_condition = exact_solution_example['initial_condition']
 
 # Dictionary of dirichlet boundary conditions.
 dirichletBC = dict()
@@ -691,8 +700,8 @@ write_to_file = {
 }
 
 # initialise LDD simulation class
-simulation = ldd.LDDsimulation(tol=1E-14, debug=True, LDDsolver_tol=1E-6)
-simulation.set_parameters(output_dir="./output/",
+simulation = ldd.LDDsimulation(tol=1E-14, debug=debugflag, LDDsolver_tol=solver_tol)
+simulation.set_parameters(output_dir=output_string,
                           subdomain_def_points=subdomain_def_points,
                           isRichards=isRichards,
                           interface_def_points=interface_def_points,
@@ -714,12 +723,12 @@ simulation.set_parameters(output_dir="./output/",
                           dirichletBC_expression_strings=dirichletBC,
                           exact_solution=exact_solution,
                           densities=densities,
-                          include_gravity=True,
+                          include_gravity=include_gravity,
                           write2file=write_to_file,
                           )
 
 simulation.initialise()
 # print(simulation.__dict__)
-simulation.run()
+simulation.run(analyse_condition=analyse_condition)
 # simulation.LDDsolver(time=0, debug=True, analyse_timestep=True)
 # df.info(parameters, True)
diff --git a/TP-TP-layered-soil-case/TP-TP-layered_soil.py b/TP-TP-layered-soil-case/TP-TP-layered_soil.py
index 68d799f..65b24d7 100755
--- a/TP-TP-layered-soil-case/TP-TP-layered_soil.py
+++ b/TP-TP-layered-soil-case/TP-TP-layered_soil.py
@@ -16,26 +16,33 @@ import typing as tp
 import functools as ft
 import domainPatch as dp
 import LDDsimulation as ldd
+import helpers as hlp
 
 # init sympy session
 sym.init_printing()
 
-# ----------------------------------------------------------------------------#
-# ------------------- MESH ---------------------------------------------------#
-# ----------------------------------------------------------------------------#
-mesh_resolution = 19
-# ----------------------------------------:-------------------------------------#
-# ------------------- TIME ---------------------------------------------------#
-# ----------------------------------------------------------------------------#
-timestep_size = 0.001
-number_of_timesteps = 1000
-# decide how many timesteps you want analysed. Analysed means, that we write
-# out subsequent errors of the L-iteration within the timestep.
-number_of_timesteps_to_analyse = 10
+solver_tol = 5E-7
+
+############ GRID #######################ü
+mesh_resolution = 40
+timestep_size = 0.0005
+number_of_timesteps = 2000
+# decide how many timesteps you want analysed. Analysed means, that we write out
+# subsequent errors of the L-iteration within the timestep.
+number_of_timesteps_to_analyse = 5
 starttime = 0
 
-l_param_w = 40
-l_param_nw = 40
+Lw = 0.25  #/timestep_size
+Lnw=Lw
+
+l_param_w = 60
+l_param_nw = 60
+
+include_gravity = True
+debugflag = False
+analyse_condition = True
+
+output_string = "./output/nondirichlet_number_of_timesteps{}_".format(number_of_timesteps)
 
 # global domain
 subdomain0_vertices = [df.Point(-1.0,-1.0), #
@@ -220,14 +227,14 @@ porosity = {
 
 # subdom_num : subdomain L for L-scheme
 L = {
-    1: {'wetting' :0.25,
-         'nonwetting': 0.25},
-    2: {'wetting' :0.25,
-         'nonwetting': 0.25},
-    3: {'wetting' :0.25,
-         'nonwetting': 0.25},
-    4: {'wetting' :0.25,
-         'nonwetting': 0.25}
+    1: {'wetting' :Lw,
+         'nonwetting': Lnw},
+    2: {'wetting' :Lw,
+         'nonwetting': Lnw},
+    3: {'wetting' :Lw,
+         'nonwetting': Lnw},
+    4: {'wetting' :Lw,
+         'nonwetting': Lnw}
 }
 
 # subdom_num : lambda parameter for the L-scheme
@@ -302,7 +309,7 @@ def rel_perm1w_prime(s):
 
 def rel_perm1nw_prime(s):
     # relative permeabilty on subdomain1
-    return 2*(1-s)
+    return -2*(1-s)
 
 # definition of the derivatives of the relative permeabilities
 # relative permeabilty functions on subdomain 1
@@ -312,7 +319,7 @@ def rel_perm2w_prime(s):
 
 def rel_perm2nw_prime(s):
     # relative permeabilty on subdomain1
-    return 2*(1-s)
+    return -2*(1-s)
 
 _rel_perm1w_prime = ft.partial(rel_perm1w_prime)
 _rel_perm1nw_prime = ft.partial(rel_perm1nw_prime)
@@ -398,10 +405,10 @@ x, y = sym.symbols('x[0], x[1]')  # needed by UFL
 t = sym.symbols('t', positive=True)
 
 p_e_sym_2patch = {
-    1: {'wetting': -1 - (1+t*t)*(1 + x*x + y*y),
-        'nonwetting': -t*(1-y - x**2)**2 - sym.sqrt(2+t**2)*(1-y)},
-    2: {'wetting': -1.0 - (1.0 + t*t)*(1.0 + x*x),
-        'nonwetting': -t*(1- x**2)**2 - sym.sqrt(2+t**2)*(1-y)},
+    1: {'wetting': -3 - (1+t*t)*(1 + x*x + y*y),
+        'nonwetting': -1-t*(1-y - x**2)**2 - sym.sqrt(2+t**2)*(1-y)**2},
+    2: {'wetting': -3.0 - (1.0 + t*t)*(1.0 + x*x),
+        'nonwetting': -1-t*(1- x**2)**2 - sym.sqrt(2+t**2)*(1-y)**2},
 }
 
 p_e_sym = {
@@ -427,83 +434,38 @@ p_e_sym = {
 #         'nonwetting': - 2 - t*(1 + x**2)**2 -sym.sqrt(2+t**2)}
 # }
 
-pc_e_sym = {
-    1: p_e_sym[1]['nonwetting'] - p_e_sym[1]['wetting'],
-    2: p_e_sym[2]['nonwetting'] - p_e_sym[2]['wetting'],
-    3: p_e_sym[3]['nonwetting'] - p_e_sym[3]['wetting'],
-    4: p_e_sym[4]['nonwetting'] - p_e_sym[4]['wetting']
-}
-
-# turn above symbolic code into exact solution for dolphin and
-# construct the rhs that matches the above exact solution.
-dtS = dict()
-div_flux = dict()
-source_expression = dict()
-exact_solution = dict()
-initial_condition = dict()
+pc_e_sym = dict()
 for subdomain, isR in isRichards.items():
-    dtS.update({subdomain: dict()})
-    div_flux.update({subdomain: dict()})
-    source_expression.update({subdomain: dict()})
-    exact_solution.update({subdomain: dict()})
-    initial_condition.update({subdomain: dict()})
     if isR:
-        subdomain_has_phases = ["wetting"]
+        pc_e_sym.update({subdomain: -p_e_sym[subdomain]['wetting']})
     else:
-        subdomain_has_phases = ["wetting", "nonwetting"]
-
-    # conditional for S_pc_prime
-    pc = pc_e_sym[subdomain]
-    dtpc = sym.diff(pc, t, 1)
-    dxpc = sym.diff(pc, x, 1)
-    dypc = sym.diff(pc, y, 1)
-    S = sym.Piecewise((S_pc_sym[subdomain](pc), pc > 0), (1, True))
-    dS = sym.Piecewise((S_pc_sym_prime[subdomain](pc), pc > 0), (0, True))
-    for phase in subdomain_has_phases:
-        # Turn above symbolic expression for exact solution into c code
-        exact_solution[subdomain].update(
-            {phase: sym.printing.ccode(p_e_sym[subdomain][phase])}
-            )
-        # save the c code for initial conditions
-        initial_condition[subdomain].update(
-            {phase: sym.printing.ccode(p_e_sym[subdomain][phase].subs(t, 0))}
-            )
-        if phase == "nonwetting":
-            dtS[subdomain].update(
-                {phase: -porosity[subdomain]*dS*dtpc}
-                )
-        else:
-            dtS[subdomain].update(
-                {phase: porosity[subdomain]*dS*dtpc}
-                )
-        pa = p_e_sym[subdomain][phase]
-        dxpa = sym.diff(pa, x, 1)
-        dxdxpa = sym.diff(pa, x, 2)
-        dypa = sym.diff(pa, y, 1)
-        dydypa = sym.diff(pa, y, 2)
-        mu = viscosity[subdomain][phase]
-        ka = relative_permeability[subdomain][phase]
-        dka = ka_prime[subdomain][phase]
-        rho = densities[subdomain][phase]
-        g = gravity_acceleration
-
-        if phase == "nonwetting":
-            # x part of div(flux) for nonwetting
-            dxdxflux = -1/mu*dka(1-S)*dS*dxpc*dxpa + 1/mu*dxdxpa*ka(1-S)
-            # y part of div(flux) for nonwetting
-            dydyflux = -1/mu*dka(1-S)*dS*dypc*(dypa - rho*g) \
-                + 1/mu*dydypa*ka(1-S)
-        else:
-            # x part of div(flux) for wetting
-            dxdxflux = 1/mu*dka(S)*dS*dxpc*dxpa + 1/mu*dxdxpa*ka(S)
-            # y part of div(flux) for wetting
-            dydyflux = 1/mu*dka(S)*dS*dypc*(dypa - rho*g) + 1/mu*dydypa*ka(S)
-        div_flux[subdomain].update({phase: dxdxflux + dydyflux})
-        contructed_rhs = dtS[subdomain][phase] - div_flux[subdomain][phase]
-        source_expression[subdomain].update(
-            {phase: sym.printing.ccode(contructed_rhs)}
-            )
-        # print(f"source_expression[{subdomain}][{phase}] =", source_expression[subdomain][phase])
+        pc_e_sym.update({subdomain: p_e_sym[subdomain]['nonwetting']
+                                        - p_e_sym[subdomain]['wetting']})
+
+
+symbols = {"x": x,
+           "y": y,
+           "t": t}
+# turn above symbolic code into exact solution for dolphin and
+# construct the rhs that matches the above exact solution.
+exact_solution_example = hlp.generate_exact_solution_expressions(
+                        symbols=symbols,
+                        isRichards=isRichards,
+                        symbolic_pressure=p_e_sym,
+                        symbolic_capillary_pressure=pc_e_sym,
+                        saturation_pressure_relationship=S_pc_sym,
+                        saturation_pressure_relationship_prime=S_pc_sym_prime,
+                        viscosity=viscosity,
+                        porosity=porosity,
+                        relative_permeability=relative_permeability,
+                        relative_permeability_prime=ka_prime,
+                        densities=densities,
+                        gravity_acceleration=gravity_acceleration,
+                        include_gravity=include_gravity,
+                        )
+source_expression = exact_solution_example['source']
+exact_solution = exact_solution_example['exact_solution']
+initial_condition = exact_solution_example['initial_condition']
 
 # Dictionary of dirichlet boundary conditions.
 dirichletBC = dict()
@@ -539,8 +501,8 @@ write_to_file = {
 }
 
 # initialise LDD simulation class
-simulation = ldd.LDDsimulation(tol=1E-14, debug=True, LDDsolver_tol=1E-7)
-simulation.set_parameters(output_dir="./output/",
+simulation = ldd.LDDsimulation(tol=1E-14, debug=debugflag, LDDsolver_tol=solver_tol)
+simulation.set_parameters(output_dir=output_string,
                           subdomain_def_points=subdomain_def_points,
                           isRichards=isRichards,
                           interface_def_points=interface_def_points,
@@ -562,12 +524,12 @@ simulation.set_parameters(output_dir="./output/",
                           dirichletBC_expression_strings=dirichletBC,
                           exact_solution=exact_solution,
                           densities=densities,
-                          include_gravity=True,
+                          include_gravity=include_gravity,
                           write2file=write_to_file,
                           )
 
 simulation.initialise()
 # print(simulation.__dict__)
-simulation.run()
+simulation.run(analyse_condition=analyse_condition)
 # simulation.LDDsolver(time=0, debug=True, analyse_timestep=True)
 # df.info(parameters, True)
diff --git a/TP-multi-patch-plus-gravity-with-same-wetting-phase-as-RR/TP-multi-patch-with-gravity-same-wetting-phase-as-RR.py b/TP-multi-patch-plus-gravity-with-same-wetting-phase-as-RR/TP-multi-patch-with-gravity-same-wetting-phase-as-RR.py
index 3510d8a..9c526f8 100755
--- a/TP-multi-patch-plus-gravity-with-same-wetting-phase-as-RR/TP-multi-patch-with-gravity-same-wetting-phase-as-RR.py
+++ b/TP-multi-patch-plus-gravity-with-same-wetting-phase-as-RR/TP-multi-patch-with-gravity-same-wetting-phase-as-RR.py
@@ -13,28 +13,28 @@ import helpers as hlp
 # init sympy session
 sym.init_printing()
 
-# ----------------------------------------------------------------------------#
-# ------------------- MESH ---------------------------------------------------#
-# ----------------------------------------------------------------------------#
-mesh_resolution = 50
-# ----------------------------------------:-------------------------------------#
-# ------------------- TIME ---------------------------------------------------#
-# ----------------------------------------------------------------------------#
+solver_tol = 5E-7
+
+############ GRID #######################ü
+mesh_resolution = 30
 timestep_size = 0.001
-number_of_timesteps = 1500
-# decide how many timesteps you want analysed. Analysed means, that we write
-# out subsequent errors of the L-iteration within the timestep.
+number_of_timesteps = 1000
+# decide how many timesteps you want analysed. Analysed means, that we write out
+# subsequent errors of the L-iteration within the timestep.
 number_of_timesteps_to_analyse = 10
 starttime = 0
 
-Lw = 1/timestep_size
-Lnw = Lw
+Lw = 1  #/timestep_size
+Lnw=Lw
 
 l_param_w = 40
 l_param_nw = 40
 
-solver_tol = 5e-8
 include_gravity = True
+debugflag = False
+analyse_condition = True
+
+output_string = "./output/like_RR_number_of_timesteps{}_".format(number_of_timesteps)
 
 # ----------------------------------------------------------------------------#
 # ------------------- Domain and Interface -----------------------------------#
@@ -378,10 +378,10 @@ p_e_sym = {
 pc_e_sym = dict()
 for subdomain, isR in isRichards.items():
     if isR:
-        pc_e_sym.update({subdomain: -p_e_sym[subdomain]['wetting'].copy()})
+        pc_e_sym.update({subdomain: -p_e_sym[subdomain]['wetting']})
     else:
-        pc_e_sym.update({subdomain: p_e_sym[subdomain]['nonwetting'].copy()
-                                        - p_e_sym[subdomain]['wetting'].copy()})
+        pc_e_sym.update({subdomain: p_e_sym[subdomain]['nonwetting']
+                                        - p_e_sym[subdomain]['wetting']})
 
 symbols = {"x": x,
            "y": y,
@@ -443,10 +443,8 @@ write_to_file = {
     'L_iterations': True
 }
 
-output_string = "./output/like_RR_number_of_timesteps{}_".format(number_of_timesteps)
-
 # initialise LDD simulation class
-simulation = ldd.LDDsimulation(tol=1E-14, LDDsolver_tol=solver_tol, debug=False)
+simulation = ldd.LDDsimulation(tol=1E-14, LDDsolver_tol=solver_tol, debug=debugflag)
 simulation.set_parameters(output_dir=output_string,
                           subdomain_def_points=subdomain_def_points,
                           isRichards=isRichards,
@@ -475,6 +473,6 @@ simulation.set_parameters(output_dir=output_string,
 
 simulation.initialise()
 # print(simulation.__dict__)
-simulation.run()
+simulation.run(analyse_condition=analyse_condition)
 # simulation.LDDsolver(time=0, debug=True, analyse_timestep=True)
 # df.info(parameters, True)
diff --git a/TP-one-patch/TP-one-patch-linear-koefficients.py b/TP-one-patch/TP-one-patch-linear-koefficients.py
index 64cf3df..d181f8d 100755
--- a/TP-one-patch/TP-one-patch-linear-koefficients.py
+++ b/TP-one-patch/TP-one-patch-linear-koefficients.py
@@ -14,12 +14,12 @@ import helpers as hlp
 sym.init_printing()
 
 
-solver_tol = 1E-7
+solver_tol = 1E-12
 
 ############ GRID #######################ü
-mesh_resolution = 30
-timestep_size = 0.0001
-number_of_timesteps = 100
+mesh_resolution = 60
+timestep_size = 0.01
+number_of_timesteps = 140
 # decide how many timesteps you want analysed. Analysed means, that we write out
 # subsequent errors of the L-iteration within the timestep.
 number_of_timesteps_to_analyse = 10
@@ -31,8 +31,8 @@ Lnw=Lw
 l_param_w = 40
 l_param_nw = 40
 
-include_gravity = False
-debugflag = True
+include_gravity = True
+debugflag = False
 analyse_condition = True
 
 output_string = "./output/linear_coefficients_number_of_timesteps{}_".format(number_of_timesteps)
@@ -191,11 +191,11 @@ def saturation_sym_prime(pc, index):
 
 # note that the conditional definition of S-pc in the nonsymbolic part will be
 # incorporated in the construction of the exact solution below.
-S_pc_sym = {
+S_pc_sym_handle = {
     0: ft.partial(saturation_sym, index=1),
 }
 
-S_pc_sym_prime = {
+S_pc_sym_prime_handle = {
     0: ft.partial(saturation_sym_prime, index=1),
 }
 
@@ -226,6 +226,7 @@ pw_sym_x = sym.Piecewise(
     (mollifier_handle(x), x**2 < epsilon_x_outer**2),
     (0, True)
 )
+
 pw_sym_y = sym.Piecewise(
     (mollifier_handle(y), y**2 < epsilon_y_outer**2),
     (0, True)
@@ -293,8 +294,8 @@ cutoff = gaussian/(gaussian + zero_on_shrinking)
 # }
 
 p_e_sym = {
-    0: {'wetting': -(sym.cos(2*t-x - 2*y)*sym.sin(3*(1+y)/2*sym.pi)*sym.sin(5*(1+x)/2*sym.pi))**2,
-        'nonwetting': -6*(sym.cos(t-x -y)*sym.sin(3*(1+y)/2*sym.pi)*sym.sin(5*(1+x)/2*sym.pi))**2},
+    0: {'wetting': -3 -(sym.cos(2*t-x - 2*y)*sym.sin(3*(1+y)/2*sym.pi)*sym.sin(5*(1+x)/2*sym.pi))**2,
+        'nonwetting': -1 -(sym.cos(t-x -y)*sym.sin(3*(1+y)/2*sym.pi)*sym.sin(5*(1+x)/2*sym.pi))**2},
 }
 
 
@@ -319,9 +320,28 @@ for subdomain, isR in isRichards.items():
         pc_e_sym.update({subdomain: p_e_sym[subdomain]['nonwetting'].copy()
                                         - p_e_sym[subdomain]['wetting'].copy()})
 
+
+
+S_pc_sym = {
+    0: sym.Piecewise(
+        (1, pc_e_sym[0]<= 0),
+        (S_pc_sym_handle[0](pc_e_sym[0]), ((0<pc_e_sym[0])& (pc_e_sym[0] < 1))),
+        (0, True)
+        )
+}
+
+S_pc_sym_prime = {
+    0: sym.Piecewise(
+        (S_pc_sym_prime_handle[0](pc_e_sym[0]), ((pc_e_sym[0] > 0)& (pc_e_sym[0] < 1))),
+        (0, True)
+        )
+}
+
 symbols = {"x": x,
            "y": y,
            "t": t}
+
+
 # turn above symbolic code into exact solution for dolphin and
 # construct the rhs that matches the above exact solution.
 exact_solution_example = hlp.generate_exact_solution_expressions(
@@ -329,8 +349,8 @@ exact_solution_example = hlp.generate_exact_solution_expressions(
                         isRichards=isRichards,
                         symbolic_pressure=p_e_sym,
                         symbolic_capillary_pressure=pc_e_sym,
-                        saturation_pressure_relationship=S_pc_sym,
-                        saturation_pressure_relationship_prime=S_pc_sym_prime,
+                        symbolic_S_pc_relationship=S_pc_sym,
+                        symbolic_S_pc_relationship_prime=S_pc_sym_prime,
                         viscosity=viscosity,
                         porosity=porosity,
                         relative_permeability=relative_permeability,
diff --git a/TP-one-patch/TP-one-patch.py b/TP-one-patch/TP-one-patch.py
index 4df57fc..dbf4cf3 100755
--- a/TP-one-patch/TP-one-patch.py
+++ b/TP-one-patch/TP-one-patch.py
@@ -14,26 +14,26 @@ import helpers as hlp
 sym.init_printing()
 
 
-solver_tol = 1E-7
+solver_tol = 5E-6
 
 ############ GRID #######################ü
-mesh_resolution = 20
-timestep_size = 0.0001
-number_of_timesteps = 20
+mesh_resolution = 30
+timestep_size = 0.0005
+number_of_timesteps = 2500
 # decide how many timesteps you want analysed. Analysed means, that we write out
 # subsequent errors of the L-iteration within the timestep.
-number_of_timesteps_to_analyse = 10
+number_of_timesteps_to_analyse = 5
 starttime = 0
 
-Lw = 1  #/timestep_size
+Lw = 0.25  #/timestep_size
 Lnw=Lw
 
 l_param_w = 40
 l_param_nw = 40
 
-include_gravity = False
-debugflag = True
-analyse_condition = False
+include_gravity = True
+debugflag = False
+analyse_condition = True
 
 output_string = "./output/nondirichlet_number_of_timesteps{}_".format(number_of_timesteps)
 
-- 
GitLab