Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change dt based on nit #1

Open
wants to merge 1 commit into
base: implicit_new
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions smoderp2d/runoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def run(self):
self.hydrographs,
self.flow_control,
self.delta_t,
self.delta_tmax,
self.list_fd
)

Expand Down Expand Up @@ -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)


Expand Down
16 changes: 12 additions & 4 deletions smoderp2d/time_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.")
Expand Down