@@ -83,7 +83,12 @@ def initialize(s, p):
8383 if isinstance (p ['grain_dist' ], str ):
8484 logger .log_and_raise ('Grain size file not recognized as array, check file path and whether all values have been filled in.' , exc = ValueError )
8585
86- if p ['bedcomp_file' ] is None and p ['grain_dist' ].ndim == 1 and p ['grain_dist' ].dtype == 'float64' or p ['grain_dist' ].dtype == 'int' :
86+ if p ['bedcomp_file' ] is not None and p ['supply_file' ] is not None :
87+ logger .log_and_raise ('Conflict in input definition, cannot define supply_file and bedcomp_file simultaneously' , exc = ValueError )
88+
89+ if p ['supply_file' ] is not None :
90+ s ['mass' ][:,:,:,:] = 0 #p['supply_file'].reshape(s['mass'].shape)
91+ elif p ['bedcomp_file' ] is None and p ['grain_dist' ].ndim == 1 and p ['grain_dist' ].dtype == 'float64' or p ['grain_dist' ].dtype == 'int' :
8792 # Both float and int are included as options for the grain dist to make sure there is no error when grain_dist is filled in as 1 instead of 1.0.
8893 for i in range (nl ):
8994 gs = makeiterable (p ['grain_dist' ])
@@ -100,8 +105,14 @@ def initialize(s, p):
100105 for j in range (nf ):
101106 s ['mass' ][:,:,i ,j ] = p ['rhog' ] * (1. - p ['porosity' ]) \
102107 * s ['thlyr' ][:,:,i ] * gs [j ]
103- else :
104- s ['mass' ][:,:,:,:] = p ['bedcomp_file' ].reshape (s ['mass' ].shape )
108+ else :
109+ # if a quasi 2D domain is used, the bedcomp_file is reshaped to fit the domain
110+ if s ['mass' ].shape [0 ] == 3 :
111+ s ['mass' ][0 ,:,:,:] = p ['bedcomp_file' ].reshape (s ['mass' ].shape [1 :])
112+ s ['mass' ][1 ,:,:,:] = p ['bedcomp_file' ].reshape (s ['mass' ].shape [1 :])
113+ s ['mass' ][2 ,:,:,:] = p ['bedcomp_file' ].reshape (s ['mass' ].shape [1 :])
114+ else :
115+ s ['mass' ][:,:,:,:] = p ['bedcomp_file' ].reshape (s ['mass' ].shape )
105116
106117 # initialize masks
107118 for k , v in p .items ():
@@ -200,7 +211,7 @@ def mixtoplayer(s, p):
200211
201212
202213def wet_bed_reset (s , p ):
203- ''' Text
214+ ''' Reset wet bed to initial bed level if the total water level is above the bed level.
204215
205216
206217
@@ -222,7 +233,7 @@ def wet_bed_reset(s, p):
222233
223234 Tbedreset = p ['dt_opt' ] / p ['Tbedreset' ]
224235
225- ix = s ['zs ' ] > (s ['zb' ] + 0.01 )
236+ ix = s ['TWL ' ] > (s ['zb' ])
226237 s ['zb' ][ix ] += (s ['zb0' ][ix ] - s ['zb' ][ix ]) * Tbedreset
227238
228239 return s
@@ -257,6 +268,16 @@ def update(s, p):
257268 Spatial grids
258269
259270 '''
271+ # this is where a supply file is used, this in only for simple cases.
272+ if type (p ['supply_file' ]) == np .ndarray :
273+ # in descrete supply limited conditions the bed bed layer operations are not valid.
274+ s ['mass' ][:,:,0 ,0 ] -= s ['pickup' ][:,:,0 ]
275+ s ['mass' ][:,:,0 ,0 ] += p ['supply_file' ]* p ['dt_opt' ]
276+ # reset supply under water if process tide is active
277+ if p ['process_tide' ]:
278+ s ['mass' ][(s ['zb' ]< s ['zs' ]),0 ,0 ]= 0
279+ return s
280+
260281
261282 nx = p ['nx' ]
262283 ny = p ['ny' ]
@@ -274,7 +295,8 @@ def update(s, p):
274295 ix_dep = dm [:,0 ] > 0.
275296
276297 # reshape mass matrix
277- m = s ['mass' ].reshape ((- 1 ,nl ,nf ))
298+ m = s ['mass' ].reshape ((- 1 ,nl ,nf )).copy ()
299+
278300
279301 # negative mass may occur in case of deposition due to numerics,
280302 # which should be prevented
@@ -298,8 +320,11 @@ def update(s, p):
298320 if p ['grain_dist' ].ndim == 2 :
299321 m [ix_ero ,- 1 ,:] -= dm [ix_ero ,:] * normalize (p ['grain_dist' ][- 1 ,:])[np .newaxis ,:].repeat (np .sum (ix_ero ), axis = 0 )
300322 elif type (p ['bedcomp_file' ]) == np .ndarray :
301- gs = p ['bedcomp_file' ].reshape ((- 1 ,nl ,nf ))
302- m [ix_ero ,- 1 ,:] -= dm [ix_ero ,:] * normalize (gs [ix_ero ,- 1 , :], axis = 1 )
323+ gs = np .zeros (s ['mass' ].shape )
324+ gs [0 ,:,:,:] = p ['bedcomp_file' ].reshape ((- 1 ,nl ,nf ))
325+ gs [1 ,:,:,:] = p ['bedcomp_file' ].reshape ((- 1 ,nl ,nf ))
326+ gs [2 ,:,:,:] = p ['bedcomp_file' ].reshape ((- 1 ,nl ,nf ))
327+ m [ix_ero ,- 1 ,:] -= dm [ix_ero ,:] * normalize (gs .reshape ((- 1 ,nl ,nf ))[ix_ero ,- 1 , :], axis = 1 )
303328 else :
304329 m [ix_ero ,- 1 ,:] -= dm [ix_ero ,:] * normalize (p ['grain_dist' ])[np .newaxis ,:].repeat (np .sum (ix_ero ), axis = 0 )
305330 # remove tiny negatives
@@ -316,6 +341,9 @@ def update(s, p):
316341 # reshape mass matrix
317342 s ['mass' ] = m .reshape ((ny + 1 ,nx + 1 ,nl ,nf ))
318343
344+ # Store toplayer of 'mass' variable (ilayer = 0)
345+ s ['masstop' ][:,:,:] = s ['mass' ][:,:,0 ,:].copy ()
346+
319347 # update bathy
320348 if p ['process_bedupdate' ]:
321349
@@ -475,8 +503,11 @@ def average_change(l, s, p):
475503 s ['dzbavg' ] = n * s ['dzbyear' ]+ (1 - n )* l ['dzbavg' ]
476504
477505 # Calculate average bed level change as input for vegetation growth [m/year]
478- # s['dzbveg'] = s['dzbavg'].copy()
479- s ['dzbveg' ] = s ['dzbyear' ].copy ()
506+ s ['dzbveg' ] = s ['dzbavg' ].copy ()
507+ # s['dzbveg'] = s['dzbyear'].copy()
508+
509+ if p ['_time' ] < p ['avg_time' ]:
510+ s ['dzbveg' ] *= 0.
480511
481512
482513 return s
0 commit comments