From 13bb7d46a139be55a1ca8dd5169dd9cd60415fd6 Mon Sep 17 00:00:00 2001 From: jerabekjak Date: Mon, 18 Mar 2024 13:32:01 +0100 Subject: [PATCH] change dt based on nit --- smoderp2d/runoff.py | 11 ++++++----- smoderp2d/time_step.py | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/smoderp2d/runoff.py b/smoderp2d/runoff.py index 7fb11fb2..46381514 100644 --- a/smoderp2d/runoff.py +++ b/smoderp2d/runoff.py @@ -275,6 +275,7 @@ def run(self): self.hydrographs, self.flow_control, self.delta_t, + self.delta_tmax, self.list_fd ) @@ -309,11 +310,11 @@ def run(self): h_new = self.surface.arr.h_total_new h_old = self.surface.arr.h_total_pre - if ma.all(abs(h_new - h_old) < 1e-5): - if ma.all(self.delta_t*2 < self.delta_tmax): - self.delta_t = self.delta_t*2 - else: - self.delta_t = self.delta_tmax + # if ma.all(abs(h_new - h_old) < 1e-5): + # if ma.all(self.delta_t*2 < self.delta_tmax): + # self.delta_t = self.delta_t*2 + # else: + # self.delta_t = self.delta_tmax self.surface.arr.h_total_pre = ma.copy(self.surface.arr.h_total_new) diff --git a/smoderp2d/time_step.py b/smoderp2d/time_step.py index 0335975e..1ab1a0b7 100644 --- a/smoderp2d/time_step.py +++ b/smoderp2d/time_step.py @@ -116,7 +116,7 @@ def model(self, # sum_interception, mat_effect_cont, ratio, iter_ def do_next_h(self, surface, subsurface, rain_arr, cumulative, - hydrographs, flow_control, delta_t,list_fd): + hydrographs, flow_control, delta_t, delta_tmax,list_fd): # global variables for infilitration # class infilt_capa # global max_infilt_capa @@ -159,7 +159,7 @@ def do_next_h(self, surface, subsurface, rain_arr, cumulative, # Setting the initial guess for the solver h_0 = h_old - dh_max = 1e-4 # [m] + dh_max = 1e-5 # [m] # Setting the maximum number of iterations for the solver max_iter = 20 @@ -216,19 +216,27 @@ def do_next_h(self, surface, subsurface, rain_arr, cumulative, h_new = solution.x + #print ('h_hew {} nit {}'.format(h_new.mean(), solution.nit)) if solution.success == False or solution.nit > max_iter-1: delta_t = delta_t/2 print('now') continue except ZeroDivisionError: raise Error("Error: The nonlinear solver did not converge. Try to change the time step") - - if ma.any(abs(h_new - h_old) > dh_max): + if solution.nit > 4 : + #if ma.any(abs(h_new - h_old) > dh_max): delta_t = delta_t/2 else: + # print ('break dt {}'.format(dt)) + if solution.nit < 3 : + if ma.all(delta_t*2 < delta_tmax): + delta_t = delta_t*2 + else: + delta_t = delta_tmax break + #input('press...') if i == fc.max_iter-1: print(abs(h_new - h_old)) raise Error("Error: The nonlinear solver did not meet the requirements after repeated decreasing of the time step. Try to change the maximum time step.")