wolfhece 2.1.100__py3-none-any.whl → 2.1.101__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -288,7 +288,8 @@ def Euler_RK_hedge(h_t1:np.ndarray, h_t2:np.ndarray,
288
288
  dt:float, dx:float,
289
289
  CL_h:float, CL_q:float,
290
290
  n:float, u_border:np.ndarray,
291
- h_center:np.ndarray, u_center:np.ndarray) -> None:
291
+ h_center:np.ndarray, u_center:np.ndarray,
292
+ theta:np.ndarray, theta_border:np.ndarray) -> None:
292
293
  """ Solve the mass and momentum equations using a explicit Euler/Runge-Kutta scheme (only 1 step)
293
294
 
294
295
  :param h_t1: Water depth at time t
@@ -311,9 +312,6 @@ def Euler_RK_hedge(h_t1:np.ndarray, h_t2:np.ndarray,
311
312
  :param u_center: Velocity at the mesh center
312
313
  """
313
314
 
314
- theta = 0.2
315
- slice_hedge = slice(len(h_t1) // 2-1, len(h_t1) // 2+2)
316
-
317
315
  g = 9.81
318
316
 
319
317
  slice_mesh = slice(1,-1)
@@ -333,6 +331,9 @@ def Euler_RK_hedge(h_t1:np.ndarray, h_t2:np.ndarray,
333
331
  z_border[slice_right_border, up] = z[1:-1]
334
332
  z_border[1,up] = z[1]
335
333
 
334
+ theta_border[slice_right_border, up] = theta[1:-1]
335
+ theta_border[1,up] = theta[1]
336
+
336
337
  # valeur à droite du bord
337
338
  q_border[slice_left_border, do] = q[1:-1]
338
339
  q_border[-1,do] = q[-2]
@@ -343,12 +344,14 @@ def Euler_RK_hedge(h_t1:np.ndarray, h_t2:np.ndarray,
343
344
  z_border[slice_left_border, do] = z[1:-1]
344
345
  z_border[-1,do] = z[-2]
345
346
 
346
- u_border[1:] = q_border[1:,up]/h_border[1:,up]
347
+ theta_border[slice_left_border, do] = theta[1:-1]
348
+ theta_border[-1,do] = theta[-2]
347
349
 
348
- u_border[slice_hedge] /= theta
349
350
 
350
- h_center = (h_border[slice_right_border,do] + h_border[slice_left_border,do])/2.
351
- u_center = q[slice_mesh]/h[slice_mesh]
351
+ u_border[1:] = q_border[1:,up]/(h_border[1:,up] * theta_border[1:,up])
352
+
353
+ h_center = (theta_border[slice_right_border,do] * h_border[slice_right_border,do] + theta_border[slice_left_border,do] * h_border[slice_left_border,do])/2.
354
+ u_center = q[slice_mesh]/(h[slice_mesh]*theta[slice_mesh])
352
355
 
353
356
  #Continuity
354
357
  h_t2[slice_mesh] = h_t1[slice_mesh] - dt/dx * (q_border[slice_right_border,up] - q_border[slice_left_border,up])
@@ -357,13 +360,13 @@ def Euler_RK_hedge(h_t1:np.ndarray, h_t2:np.ndarray,
357
360
 
358
361
  J = get_friction_slope_2D_Manning_semi_implicit(u_center, h[slice_mesh], n)
359
362
  qm_right = u_border[slice_right_border]*q_border[slice_right_border,up]
360
- qm_left = u_border[slice_left_border]*q_border[slice_left_border,up]
363
+ qm_left = u_border[slice_left_border ]*q_border[slice_left_border,up]
361
364
 
362
- press_right = 0.5 * g * h_border[slice_right_border,do]**2
363
- press_left = 0.5 * g * h_border[slice_left_border,do]**2
365
+ press_right = 0.5 * g * (theta_border[slice_right_border,do] * h_border[slice_right_border,do])**2
366
+ press_left = 0.5 * g * (theta_border[slice_left_border ,do] * h_border[slice_left_border ,do])**2
364
367
 
365
- bed_right = g * h_center * z_border[slice_right_border,do]
366
- bed_left = g * h_center * z_border[slice_left_border,do]
368
+ bed_right = g * h_center * (z_border[slice_right_border,do] + (1-theta_border[slice_right_border,do]) * h_border[slice_right_border,do])
369
+ bed_left = g * h_center * (z_border[slice_left_border,do] + (1-theta_border[slice_left_border,do]) * h_border[slice_left_border,do])
367
370
 
368
371
  q_t2[slice_mesh] = 1./(1. + dt * g *h[slice_mesh] * J) * (q_t1[slice_mesh] - dt/dx * (qm_right - qm_left + press_right - press_left + bed_right - bed_left))
369
372
 
@@ -716,6 +719,13 @@ def problem_hedge(dom:np.ndarray, z:np.ndarray, h0:float, q0:float, dx:float, CN
716
719
 
717
720
  h, q, h_pred, q_pred, h_corr, q_corr, q_border, h_border, z_border, u_border, h_center, u_center = all_unk_border(dom, h0, q0)
718
721
 
722
+ theta = np.ones_like(h)
723
+ theta_border = np.ones_like(h_border)
724
+
725
+ slice_hedge = slice(len(h) // 2-1, len(h) // 2+2)
726
+ theta_val = 0.5
727
+ theta[slice_hedge] = theta_val
728
+
719
729
  totaltime = 4*3600
720
730
  eps=1.
721
731
 
@@ -724,9 +734,9 @@ def problem_hedge(dom:np.ndarray, z:np.ndarray, h0:float, q0:float, dx:float, CN
724
734
  while eps > 1e-12:
725
735
  dt = compute_dt(dx, h, q, CN)
726
736
  # Predictor step
727
- Euler_RK_hedge(h, h_pred, q, q_pred, h, q, h_border, q_border, z, z_border, dt, dx, h0, q0, n, u_border, h_center, u_center)
737
+ Euler_RK_hedge(h, h_pred, q, q_pred, h, q, h_border, q_border, z, z_border, dt, dx, h0, q0, n, u_border, h_center, u_center, theta, theta_border)
728
738
  # Corrector step
729
- Euler_RK_hedge(h, h_corr, q, q_corr, h_pred, q_pred, h_border, q_border, z, z_border, dt, dx, h0, q0, n, u_border, h_center, u_center)
739
+ Euler_RK_hedge(h, h_corr, q, q_corr, h_pred, q_pred, h_border, q_border, z, z_border, dt, dx, h0, q0, n, u_border, h_center, u_center, theta, theta_border)
730
740
 
731
741
  # Update -- Mean for second order in time
732
742
  h = (h_pred + h_corr)/2.
@@ -740,7 +750,7 @@ def problem_hedge(dom:np.ndarray, z:np.ndarray, h0:float, q0:float, dx:float, CN
740
750
  print("Total time : ", t)
741
751
  print("Residual : ", eps)
742
752
 
743
- return h, q
753
+ return h, q, theta
744
754
 
745
755
  def problem_bridge(dom:np.ndarray, z:np.ndarray, z_bridge:np.ndarray,
746
756
  h0:float, q0:float,
@@ -1062,7 +1072,7 @@ def problem_bridge_unsteady_topo(dom:np.ndarray, z:np.ndarray,
1062
1072
 
1063
1073
  infil_exfil = None
1064
1074
 
1065
- filling_bridge = False
1075
+ bridge_in_motion = False
1066
1076
  filled_bridge = False
1067
1077
  emptying_bridge = False
1068
1078
  motion_completed = True
@@ -1105,6 +1115,8 @@ def problem_bridge_unsteady_topo(dom:np.ndarray, z:np.ndarray,
1105
1115
  t = 0.
1106
1116
 
1107
1117
  res_time = 0.
1118
+ update_time = 0.
1119
+
1108
1120
  delta_res_time = delta_res_time_def
1109
1121
 
1110
1122
  z_roof_start = None
@@ -1220,172 +1232,181 @@ def problem_bridge_unsteady_topo(dom:np.ndarray, z:np.ndarray,
1220
1232
  res.append((t, h.copy(), q.copy(), z.copy(), z_roof.copy(), infil_exfil if infil_exfil is not None else (idx_up, idx_do, 0., 0., 0., 0.)))
1221
1233
  res_time += delta_res_time
1222
1234
 
1223
- if z[survey_up] + h[survey_up] > z_overflow:
1224
- # Overflow
1235
+ if updating_time_interval == 0. or t> update_time:
1236
+ update_time += updating_time_interval
1237
+
1238
+ if z[survey_up] + h[survey_up] > z_overflow:
1239
+ # Overflow
1240
+
1241
+ # Convert Bridge into topography
1242
+ # add infiltration/exfiltration
1243
+ if not bridge_in_motion and motion_completed and not filled_bridge:
1244
+
1245
+ # Movement must be initiated...
1246
+
1247
+ # Decreasing the interval of time for the
1248
+ # saving to be more precise when plotting
1249
+ delta_res_time = delta_res_time_def / 5.
1225
1250
 
1226
- # Convert Bridge into topography
1227
- # add infiltration/exfiltration
1228
- if not filling_bridge and motion_completed and not filled_bridge:
1251
+ bridge_in_motion = True
1252
+ emptying_bridge = False
1253
+ motion_completed = False
1229
1254
 
1230
- # Movement must be initiated...
1255
+ local_motion_time = 0.
1256
+ starting_time = t
1231
1257
 
1232
- # Decreasing the interval of time for the
1233
- # saving to be more precise when plotting
1234
- delta_res_time = delta_res_time_def / 5.
1258
+ # Keeping the old values -- Can be useful when restoring
1259
+ old_z_roof = z_roof.copy()
1260
+ old_z = z.copy()
1235
1261
 
1236
- filling_bridge = True
1237
- emptying_bridge = False
1238
- motion_completed = False
1239
- local_motion_time = 0.
1262
+ # Reference section of the bridge...
1263
+ # Keeping the minimum distance between the bridge and the floor
1264
+ A_bridge = np.min(z_roof[bridge] - z[bridge])
1240
1265
 
1241
- # Keeping the old values -- Can be useful when restoring
1242
- old_z_roof = z_roof.copy()
1243
- old_z = z.copy()
1244
1266
 
1245
- # Reference section of the bridge...
1246
- # Keeping the minimum distance between the bridge and the floor
1247
- A_bridge = np.min(z_roof[bridge] - z[bridge])
1267
+ # Computing global head loss coefficient associated to the bridge and the reference section
1268
+ k_bridge = compute_k_mean(z[survey_up], h[survey_up], q[survey_up],
1269
+ z[survey_do], h[survey_do], q[survey_do],
1270
+ A_bridge)
1248
1271
 
1272
+ # Starting the motion...
1273
+ # - the bridge's roof is going up
1274
+ # - the bridge's floor is going up
1249
1275
 
1250
- # Computing global head loss coefficient associated to the bridge and the reference section
1251
- k_bridge = compute_k_mean(z[survey_up], h[survey_up], q[survey_up],
1252
- z[survey_do], h[survey_do], q[survey_do],
1253
- A_bridge)
1276
+ z_roof_start = old_z_roof[bridge]
1277
+ z_roof_end = z_roof_null
1278
+ z_bath_start = old_z[bridge]
1279
+ z_bath_end = z_deck[bridge]
1254
1280
 
1255
- # Starting the motion...
1256
- # - the bridge's roof is going up
1257
- # - the bridge's floor is going up
1281
+ # Mean Flow rate under the bridge
1282
+ q_infil_t_current = np.mean(q[bridge])
1258
1283
 
1259
- z_roof_start = old_z_roof[bridge]
1260
- z_roof_end = z_roof_null
1261
- z_bath_start = old_z[bridge]
1262
- z_bath_end = z_deck[bridge]
1284
+ infil_exfil, z_roof, z, q_infil_t_current = update_top_q(z, h, q, z_roof,
1285
+ idx_up, idx_do,
1286
+ survey_up, survey_do,
1287
+ A_bridge, k_bridge, q_infil_t_current,
1288
+ dt,
1289
+ local_motion_time, total_motion_time,
1290
+ emptying_bridge,
1291
+ z_roof_start, z_roof_end, z_bath_start, z_bath_end)
1263
1292
 
1264
- # Mean Flow rate under the bridge
1265
- q_infil_t_current = np.mean(q[bridge])
1293
+ else:
1294
+ if not motion_completed:
1295
+ # Movement is initiated but not finished...
1296
+
1297
+ # Updating the local time
1298
+ # local_motion_time += dt
1299
+ local_motion_time = t - starting_time
1300
+
1301
+ if local_motion_time > total_motion_time:
1302
+ # Total time is reached...
1303
+ # ... so terminate the movement
1304
+
1305
+ delta_res_time = delta_res_time_def
1306
+
1307
+ bridge_in_motion = False
1308
+ motion_completed = True
1309
+ filled_bridge = not filled_bridge
1310
+
1311
+ infil_exfil, z_roof, z, q_infil_t_current = update_top_q(z, h, q, z_roof,
1312
+ idx_up, idx_do,
1313
+ survey_up, survey_do,
1314
+ A_bridge, k_bridge, q_infil_t_current, dt,
1315
+ local_motion_time, total_motion_time, emptying_bridge,
1316
+ z_roof_start, z_roof_end, z_bath_start, z_bath_end,
1317
+ stop_motion= True)
1318
+
1319
+ local_motion_time = 0.
1320
+ else:
1321
+ # Total time is not reached...
1322
+ # ... so continue the movement
1323
+
1324
+ infil_exfil, z_roof, z, q_infil_t_current = update_top_q(z, h, q, z_roof,
1325
+ idx_up, idx_do,
1326
+ survey_up, survey_do,
1327
+ A_bridge, k_bridge, q_infil_t_current, dt,
1328
+ local_motion_time, total_motion_time, emptying_bridge,
1329
+ z_roof_start, z_roof_end, z_bath_start, z_bath_end)
1330
+ else:
1331
+ # Movement is done...
1332
+
1333
+ if infil_exfil is not None:
1334
+
1335
+ # Updating the infiltration discharge according to head difference
1336
+ infil_exfil, z_roof, z, q_infil_t_current = update_top_q(z, h, q, z_roof,
1337
+ idx_up, idx_do,
1338
+ survey_up, survey_do,
1339
+ A_bridge, k_bridge, q_infil_t_current, dt,
1340
+ local_motion_time, total_motion_time, emptying_bridge,
1341
+ z_roof_start, z_roof_end, z_bath_start, z_bath_end,
1342
+ update_top=False)
1266
1343
 
1267
- infil_exfil, z_roof, z, q_infil_t_current = update_top_q(z, h, q, z_roof,
1268
- idx_up, idx_do,
1269
- survey_up, survey_do,
1270
- A_bridge, k_bridge, q_infil_t_current,
1271
- dt,
1272
- local_motion_time, total_motion_time,
1273
- emptying_bridge,
1274
- z_roof_start, z_roof_end, z_bath_start, z_bath_end)
1275
1344
 
1276
1345
  else:
1277
- if not motion_completed:
1278
- # Movement is initiated but not finished...
1346
+ # No overflow
1279
1347
 
1280
- # Updating the local time
1281
- local_motion_time += dt
1348
+ if bridge_in_motion:
1349
+ # But movement is initiated...
1350
+ # local_motion_time += dt
1351
+ local_motion_time = t - starting_time
1282
1352
 
1283
1353
  if local_motion_time > total_motion_time:
1284
- # Total time is reached...
1285
- # ... so terminate the movement
1286
1354
 
1287
1355
  delta_res_time = delta_res_time_def
1288
1356
 
1289
- filling_bridge = False
1357
+ # Total time is reached...
1358
+ # ... so terminate the movement
1359
+
1360
+ bridge_in_motion = False
1290
1361
  motion_completed = True
1291
1362
  filled_bridge = not filled_bridge
1292
1363
 
1293
1364
  infil_exfil, z_roof, z, q_infil_t_current = update_top_q(z, h, q, z_roof,
1294
- idx_up, idx_do,
1295
- survey_up, survey_do,
1296
- A_bridge, k_bridge, q_infil_t_current, dt,
1297
- local_motion_time, total_motion_time, emptying_bridge,
1298
- z_roof_start, z_roof_end, z_bath_start, z_bath_end,
1299
- stop_motion= True)
1365
+ idx_up, idx_do,
1366
+ survey_up, survey_do,
1367
+ A_bridge, k_bridge, q_infil_t_current, dt,
1368
+ local_motion_time, total_motion_time, emptying_bridge,
1369
+ z_roof_start, z_roof_end, z_bath_start, z_bath_end,
1370
+ stop_motion= True)
1300
1371
 
1301
1372
  local_motion_time = 0.
1373
+
1302
1374
  else:
1303
1375
  # Total time is not reached...
1304
1376
  # ... so continue the movement
1305
1377
 
1306
1378
  infil_exfil, z_roof, z, q_infil_t_current = update_top_q(z, h, q, z_roof,
1307
- idx_up, idx_do,
1308
- survey_up, survey_do,
1309
- A_bridge, k_bridge, q_infil_t_current, dt,
1310
- local_motion_time, total_motion_time, emptying_bridge,
1311
- z_roof_start, z_roof_end, z_bath_start, z_bath_end)
1312
- else:
1313
- # Movement is done...
1314
-
1315
- if infil_exfil is not None:
1316
-
1317
- # Updating the infiltration discharge according to head difference
1318
- infil_exfil, z_roof, z, q_infil_t_current = update_top_q(z, h, q, z_roof,
1319
- idx_up, idx_do,
1320
- survey_up, survey_do,
1321
- A_bridge, k_bridge, q_infil_t_current, dt,
1322
- local_motion_time, total_motion_time, emptying_bridge,
1323
- z_roof_start, z_roof_end, z_bath_start, z_bath_end,
1324
- update_top=False)
1325
-
1326
-
1327
- else:
1328
- # No overflow
1329
-
1330
- if filling_bridge:
1331
- # But movement is initiated...
1332
- local_motion_time += dt
1333
-
1334
- if local_motion_time > total_motion_time:
1335
-
1336
- delta_res_time = delta_res_time_def
1337
-
1338
- # Total time is reached...
1339
- # ... so terminate the movement
1340
-
1341
- filling_bridge = False
1342
- motion_completed = True
1343
- filled_bridge = not filled_bridge
1344
-
1345
- infil_exfil, z_roof, z, q_infil_t_current = update_top_q(z, h, q, z_roof,
1346
- idx_up, idx_do,
1347
- survey_up, survey_do,
1348
- A_bridge, k_bridge, q_infil_t_current, dt,
1349
- local_motion_time, total_motion_time, emptying_bridge,
1350
- z_roof_start, z_roof_end, z_bath_start, z_bath_end,
1351
- stop_motion= True)
1352
-
1353
- local_motion_time = 0.
1379
+ idx_up, idx_do,
1380
+ survey_up, survey_do,
1381
+ A_bridge, k_bridge, q_infil_t_current, dt,
1382
+ local_motion_time, total_motion_time, emptying_bridge,
1383
+ z_roof_start, z_roof_end, z_bath_start, z_bath_end)
1354
1384
 
1355
1385
  else:
1356
- # Total time is not reached...
1357
- # ... so continue the movement
1358
-
1359
- infil_exfil, z_roof, z, q_infil_t_current = update_top_q(z, h, q, z_roof,
1360
- idx_up, idx_do,
1361
- survey_up, survey_do,
1362
- A_bridge, k_bridge, q_infil_t_current, dt,
1363
- local_motion_time, total_motion_time, emptying_bridge,
1364
- z_roof_start, z_roof_end, z_bath_start, z_bath_end)
1365
1386
 
1366
- else:
1387
+ if infil_exfil is not None:
1367
1388
 
1368
- if infil_exfil is not None:
1389
+ if motion_completed:
1390
+ # The bridge is not moving and the infiltration/exfiltration exists
1369
1391
 
1370
- if motion_completed:
1371
- # The bridge is not moving and the infiltration/exfiltration exists
1392
+ # We can start to restore the bridge as it was before the overflow...
1372
1393
 
1373
- # We can start to restore the bridge as it was before the overflow...
1394
+ delta_res_time = delta_res_time_def / 5.
1374
1395
 
1375
- delta_res_time = delta_res_time_def / 5.
1396
+ bridge_in_motion = True
1397
+ local_motion_time = 0.
1398
+ motion_completed = False
1376
1399
 
1377
- filling_bridge = True
1378
- local_motion_time = 0.
1379
- motion_completed = False
1380
- emptying_bridge = True
1400
+ emptying_bridge = True
1401
+ starting_time = t
1381
1402
 
1382
- infil_exfil, z_roof, z, q_infil_t_current = update_top_q(z, h, q, z_roof,
1383
- idx_up, idx_do,
1384
- survey_up, survey_do,
1385
- A_bridge, k_bridge, q_infil_t_current, dt,
1386
- local_motion_time, total_motion_time, emptying_bridge,
1387
- z_roof_start, z_roof_end, z_bath_start, z_bath_end,
1388
- )
1403
+ infil_exfil, z_roof, z, q_infil_t_current = update_top_q(z, h, q, z_roof,
1404
+ idx_up, idx_do,
1405
+ survey_up, survey_do,
1406
+ A_bridge, k_bridge, q_infil_t_current, dt,
1407
+ local_motion_time, total_motion_time, emptying_bridge,
1408
+ z_roof_start, z_roof_end, z_bath_start, z_bath_end,
1409
+ )
1389
1410
 
1390
1411
  t+=dt
1391
1412
  pbar.update(dt)
@@ -1439,17 +1460,14 @@ def plot_bridge(ax:plt.Axes, x:np.ndarray,
1439
1460
  def plot_hedge(ax:plt.Axes, x:np.ndarray,
1440
1461
  h1:np.ndarray, h2:np.ndarray,
1441
1462
  q1:np.ndarray, q2:np.ndarray,
1442
- z:np.ndarray, hu:float):
1463
+ z:np.ndarray, hu:float,
1464
+ theta:np.ndarray):
1443
1465
 
1444
1466
  u1=np.zeros_like(q1)
1445
1467
  u2=np.zeros_like(q1)
1446
1468
 
1447
- slice_hedge = slice(len(h1) // 2-1, len(h1) // 2+2)
1448
- theta = 0.2
1449
-
1450
1469
  u1[1:-1] = q1[1:-1]/h1[1:-1]
1451
- u2[1:-1] = q2[1:-1]/h2[1:-1]
1452
- u2[slice_hedge] /= theta
1470
+ u2[1:-1] = q2[1:-1]/(h2[1:-1]*theta[1:-1])
1453
1471
 
1454
1472
  ax.plot(x[1:-1], z[1:-1], label = 'z')
1455
1473
 
@@ -1934,7 +1952,7 @@ def unsteady_without_bedmotion():
1934
1952
  return fig, axes
1935
1953
 
1936
1954
 
1937
- def unteaady_with_bedmotion(problems:list[int], save_video:bool = False) -> list[animation.FuncAnimation]:
1955
+ def unsteady_with_bedmotion(problems:list[int], save_video:bool = False) -> list[animation.FuncAnimation]:
1938
1956
  """
1939
1957
  Unsteady problem with bed motion if overflowing occurs.
1940
1958
 
@@ -2330,6 +2348,403 @@ def unteaady_with_bedmotion(problems:list[int], save_video:bool = False) -> list
2330
2348
 
2331
2349
  return anims
2332
2350
 
2351
+ def unsteady_with_bedmotion_interval(problems:list[int], save_video:bool = False, update_interval:float = 0., motion_duration:float = 300.) -> list[animation.FuncAnimation]:
2352
+ """
2353
+ Unsteady problem with bed motion if overflowing occurs.
2354
+
2355
+ :param problems: list of problems to solve
2356
+
2357
+ Problems :
2358
+ 2 - Rectangular bridge - Length = 20 m (will compute 21, 22 and 23)
2359
+ 6 - Rectangular bridge - Length = 60 m (will compute 61, 62 and 63)
2360
+ 7 - V-shape bridge - Length = 20 m (will compute 71, 72 and 73)
2361
+ 8 - U-shape bridge - Length = 20 m (will compute 81, 82 and 83)
2362
+ 9 - Culvert - Length = 100 m (will compute 91, 92 and 93)
2363
+
2364
+ 21 - Rectangular bridge - Length = 20 m - Unsteady downstream bc
2365
+ 22 - Rectangular bridge - Length = 20 m - Hydrograph
2366
+ 23 - Rectangular bridge - Length = 20 m - Hydrograph 2 steps
2367
+
2368
+ 61 - Rectangular bridge - Length = 60 m - Unsteady downstream bc
2369
+ 62 - Rectangular bridge - Length = 60 m - Hydrograph
2370
+ 63 - Rectangular bridge - Length = 60 m - Hydrograph 2 steps
2371
+
2372
+ 71 - V-shape bridge - Length = 20 m - Unsteady downstream bc
2373
+ 72 - V-shape bridge - Length = 20 m - Hydrograph
2374
+ 73 - V-shape bridge - Length = 20 m - Hydrograph 2 steps
2375
+
2376
+ 81 - U-shape bridge - Length = 20 m - Unsteady downstream bc
2377
+ 82 - U-shape bridge - Length = 20 m - Hydrograph
2378
+ 83 - U-shape bridge - Length = 20 m - Hydrograph 2 steps
2379
+
2380
+ 91 - Culvert - Length = 100 m - Unsteady downstream bc
2381
+ 92 - Culvert - Length = 100 m - Hydrograph
2382
+ 93 - Culvert - Length = 100 m - Hydrograph 2 steps
2383
+
2384
+ """
2385
+ length = 500.
2386
+ dx = 1.
2387
+ CN = 0.4
2388
+ h0 = 4.
2389
+ q0 = 7.
2390
+ n = 0.025
2391
+ slope = 0 #1e-4
2392
+ press_mode = 4
2393
+
2394
+ dom, x, z = domain(length, dx, slope)
2395
+ x = np.array(x)
2396
+
2397
+ hu = uniform_waterdepth(slope, q0, n)
2398
+
2399
+ anims=[]
2400
+
2401
+ if 2 in problems or 21 in problems or 22 in problems or 23 in problems or 24 in problems:
2402
+ # Rectangular bridge - Lenght = 20 m
2403
+
2404
+ CN = 0.4
2405
+
2406
+ if 2 in problems:
2407
+ scenarios = ['unsteady_downstream_bc',
2408
+ 'hydrograph',
2409
+ 'hydrograph_2steps',
2410
+ # 'Gauss',
2411
+ ]
2412
+ elif 21 in problems:
2413
+ scenarios = ['unsteady_downstream_bc']
2414
+ elif 22 in problems:
2415
+ scenarios = ['hydrograph']
2416
+ elif 23 in problems:
2417
+ scenarios = ['hydrograph_2steps']
2418
+ elif 24 in problems:
2419
+ scenarios = ['Gauss']
2420
+
2421
+ for scenario in scenarios:
2422
+
2423
+ # UNSTEADY WITH TOPOGRAPHY ADAPTATION
2424
+ len_bridge = 20
2425
+ z_roof_null = 10.
2426
+ min_overflow = 0.25
2427
+
2428
+ h0 = 1.5
2429
+
2430
+ h_under_bridge = 3.5
2431
+ h_deck_bridge = 0.75
2432
+
2433
+ slice_bridge = slice(int(len(dom)//2-len_bridge//2),int(len(dom)//2+len_bridge//2))
2434
+ slice_bridge_up = slice(int(len(dom)//2+(len_bridge//2-1)),int(len(dom)//2-(len_bridge//2+1)),-1)
2435
+
2436
+ z_bridge = np.ones_like(z) * z_roof_null
2437
+ z_deck = np.ones_like(z) * z_roof_null
2438
+
2439
+ for idx in range(len(dom)//2-len_bridge//2,len(dom)//2+len_bridge//2):
2440
+ z_bridge[idx] = z[idx] + h_under_bridge
2441
+ z_deck[idx] = z_bridge[idx] + h_deck_bridge
2442
+
2443
+ poly_bridge_x = np.concatenate((x[slice_bridge], x[slice_bridge_up]))
2444
+ poly_bridge_y = np.concatenate((z_bridge[slice_bridge], z_deck[slice_bridge_up]))
2445
+
2446
+ z_ini = z.copy()
2447
+
2448
+ res = problem_bridge_unsteady_topo(dom, z,
2449
+ z_bridge, z_deck, z_roof_null,
2450
+ h0, q0, dx, CN, n,
2451
+ press_mode= press_mode,
2452
+ motion_duration= motion_duration,
2453
+ scenario_bc= scenario,
2454
+ min_overflow= min_overflow,
2455
+ updating_time_interval=update_interval)
2456
+
2457
+ ani = animate_bridge_unsteady_topo(dom, poly_bridge_x, poly_bridge_y, res, x, z_ini, hu, z_roof_null, len_bridge, motion_duration=motion_duration)
2458
+
2459
+ if save_video:
2460
+ update_func = lambda _i, _n: progress_bar.update(1)
2461
+ with tqdm(total=len(res), desc='Saving video') as progress_bar:
2462
+ ani.save(f'bridge_L20_{scenario}.mp4',
2463
+ writer='ffmpeg', fps=5,
2464
+ progress_callback=update_func)
2465
+
2466
+ anims.append(ani)
2467
+
2468
+ if 6 in problems or 61 in problems or 62 in problems or 63 in problems or 64 in problems:
2469
+ # Rectangular bridge - Lenght = 60 m
2470
+
2471
+ CN = 0.2
2472
+
2473
+ if 6 in problems:
2474
+ scenarios = ['unsteady_downstream_bc',
2475
+ 'hydrograph',
2476
+ 'hydrograph_2steps',
2477
+ # 'Gauss',
2478
+ ]
2479
+
2480
+ elif 61 in problems:
2481
+ scenarios = ['unsteady_downstream_bc']
2482
+ elif 62 in problems:
2483
+ scenarios = ['hydrograph']
2484
+ elif 63 in problems:
2485
+ scenarios = ['hydrograph_2steps']
2486
+ elif 64 in problems:
2487
+ scenarios = ['Gauss']
2488
+
2489
+ for scenario in scenarios:
2490
+
2491
+ # UNSTEADY WITH TOPOGRAPHY ADAPTATION
2492
+ z_roof_null = 10.
2493
+ min_overflow = 0.25
2494
+
2495
+ h_under_bridge = 3.5
2496
+ h_deck_bridge = 0.75
2497
+ len_bridge = 60
2498
+ q0 = 6.
2499
+ h0 = 1.5
2500
+
2501
+ slice_bridge = slice(int(len(dom)//2-len_bridge//2),int(len(dom)//2+len_bridge//2))
2502
+ slice_bridge_up = slice(int(len(dom)//2+(len_bridge//2-1)),int(len(dom)//2-(len_bridge//2+1)),-1)
2503
+
2504
+ z_bridge = np.ones_like(z) * z_roof_null
2505
+ z_deck = np.ones_like(z) * z_roof_null
2506
+
2507
+ for idx in range(len(dom)//2-len_bridge//2,len(dom)//2+len_bridge//2):
2508
+ z_bridge[idx] = z[idx] + h_under_bridge
2509
+ z_deck[idx] = z_bridge[idx] + h_deck_bridge
2510
+
2511
+ poly_bridge_x = np.concatenate((x[slice_bridge], x[slice_bridge_up]))
2512
+ poly_bridge_y = np.concatenate((z_bridge[slice_bridge], z_deck[slice_bridge_up]))
2513
+
2514
+ z_ini = z.copy()
2515
+
2516
+ res = problem_bridge_unsteady_topo(dom, z, z_bridge,
2517
+ z_deck, z_roof_null,
2518
+ h0, q0, dx, CN, n,
2519
+ press_mode=press_mode,
2520
+ motion_duration=motion_duration,
2521
+ scenario_bc=scenario,
2522
+ min_overflow=min_overflow,
2523
+ updating_time_interval=update_interval)
2524
+
2525
+ ani = animate_bridge_unsteady_topo(dom, res, x, z_ini, hu, z_roof_null, len_bridge, motion_duration=motion_duration)
2526
+
2527
+ if save_video:
2528
+ update_func = lambda _i, _n: progress_bar.update(1)
2529
+ with tqdm(total=len(res), desc='Saving video') as progress_bar:
2530
+ ani.save(f'bridge_L60{scenario}.mp4',
2531
+ writer='ffmpeg', fps=5,
2532
+ progress_callback=update_func)
2533
+
2534
+ anims.append(ani)
2535
+
2536
+ if 9 in problems or 91 in problems or 92 in problems or 93 in problems or 94 in problems:
2537
+ # Culvert
2538
+
2539
+ CN = 0.4
2540
+
2541
+ if 9 in problems:
2542
+ scenarios = ['unsteady_downstream_bc_culvert',
2543
+ 'hydrograph_culvert',
2544
+ 'hydrograph_2steps_culvert',
2545
+ # 'Gauss',
2546
+ ]
2547
+
2548
+ elif 91 in problems:
2549
+ scenarios = ['unsteady_downstream_bc_culvert']
2550
+ elif 92 in problems:
2551
+ scenarios = ['hydrograph_culvert']
2552
+ elif 93 in problems:
2553
+ scenarios = ['hydrograph_2steps_culvert']
2554
+
2555
+ for scenario in scenarios:
2556
+
2557
+ # UNSTEADY WITH TOPOGRAPHY ADAPTATION
2558
+ z_roof_null = 10.
2559
+ min_overflow = 0.25
2560
+
2561
+ h_under_bridge = 1.5
2562
+ h_deck_bridge = 4.0
2563
+ len_bridge = 100
2564
+ h0 = 0.8
2565
+ q0 = 1.
2566
+
2567
+ slice_bridge = slice(int(len(dom)//2-len_bridge//2),int(len(dom)//2+len_bridge//2))
2568
+ slice_bridge_up = slice(int(len(dom)//2+(len_bridge//2-1)),int(len(dom)//2-(len_bridge//2+1)),-1)
2569
+
2570
+ z_bridge = np.ones_like(z) * z_roof_null
2571
+ z_deck = np.ones_like(z) * z_roof_null
2572
+
2573
+ for idx in range(len(dom)//2-len_bridge//2,len(dom)//2+len_bridge//2):
2574
+ z_bridge[idx] = z[idx] + h_under_bridge
2575
+ z_deck[idx] = z_bridge[idx] + h_deck_bridge
2576
+
2577
+ poly_bridge_x = np.concatenate((x[slice_bridge], x[slice_bridge_up]))
2578
+ poly_bridge_y = np.concatenate((z_bridge[slice_bridge], z_deck[slice_bridge_up]))
2579
+
2580
+ z_ini = z.copy()
2581
+
2582
+ res = problem_bridge_unsteady_topo(dom, z, z_bridge,
2583
+ z_deck, z_roof_null,
2584
+ h0, q0, dx, CN, n,
2585
+ press_mode=press_mode,
2586
+ motion_duration=motion_duration,
2587
+ scenario_bc=scenario,
2588
+ min_overflow=min_overflow,
2589
+ updating_time_interval=update_interval)
2590
+
2591
+ ani = animate_bridge_unsteady_topo(dom, poly_bridge_x, poly_bridge_y, res, x, z_ini, hu, z_roof_null, len_bridge, title='Culvert', motion_duration=motion_duration)
2592
+
2593
+ if save_video:
2594
+ update_func = lambda _i, _n: progress_bar.update(1)
2595
+ with tqdm(total=len(res), desc='Saving video') as progress_bar:
2596
+ ani.save(f'culvert_{scenario}.mp4',
2597
+ writer='ffmpeg', fps=5,
2598
+ progress_callback=update_func)
2599
+
2600
+ anims.append(ani)
2601
+
2602
+ if 7 in problems or 71 in problems or 72 in problems or 73 in problems or 74 in problems:
2603
+ # V-shape Bridge
2604
+
2605
+ CN = 0.4
2606
+
2607
+ if 7 in problems:
2608
+ scenarios = ['unsteady_downstream_bc',
2609
+ 'hydrograph',
2610
+ 'hydrograph_2steps',
2611
+ # 'Gauss',
2612
+ ]
2613
+ elif 71 in problems:
2614
+ scenarios = ['unsteady_downstream_bc']
2615
+ elif 72 in problems:
2616
+ scenarios = ['hydrograph']
2617
+ elif 73 in problems:
2618
+ scenarios = ['hydrograph_2steps']
2619
+ elif 74 in problems:
2620
+ scenarios = ['Gauss']
2621
+
2622
+ for scenario in scenarios:
2623
+
2624
+ # UNSTEADY WITH TOPOGRAPHY ADAPTATION
2625
+ z_roof_null = 10.
2626
+ min_overflow = 0.25
2627
+
2628
+ h_under_bridge = 3.5
2629
+ h_deck_bridge = 0.75
2630
+ len_bridge = 20
2631
+
2632
+ h0 = 1.5
2633
+
2634
+ z_bridge = np.ones_like(z) * z_roof_null
2635
+ z_deck = np.ones_like(z) * z_roof_null
2636
+
2637
+ slice_bridge = slice(len(dom)//2-len_bridge//2,len(dom)//2+len_bridge//2)
2638
+ slice_bridge_up = slice(len(dom)//2+(len_bridge//2-1),len(dom)//2-(len_bridge//2+1),-1)
2639
+
2640
+ for idx in range(len(dom)//2-len_bridge//2,len(dom)//2+len_bridge//2):
2641
+ decal = abs(idx - (len(dom)//2))
2642
+ z_bridge[idx] = z[idx] + h_under_bridge + 0.05 * decal
2643
+ z_deck[idx] = h_under_bridge + h_deck_bridge
2644
+
2645
+ poly_bridge_x = np.concatenate((x[slice_bridge], x[slice_bridge_up]))
2646
+ poly_bridge_y = np.concatenate((z_bridge[slice_bridge], z_deck[slice_bridge_up]))
2647
+
2648
+ z_ini = z.copy()
2649
+
2650
+ res = problem_bridge_unsteady_topo(dom, z,
2651
+ z_bridge, z_deck, z_roof_null,
2652
+ h0, q0, dx, CN, n,
2653
+ press_mode=press_mode,
2654
+ motion_duration=motion_duration,
2655
+ scenario_bc=scenario,
2656
+ min_overflow= min_overflow,
2657
+ updating_time_interval=update_interval)
2658
+
2659
+ ani = animate_bridge_unsteady_topo(dom, poly_bridge_x, poly_bridge_y, res, x, z_ini, hu, z_roof_null, len_bridge, motion_duration=motion_duration)
2660
+
2661
+ if save_video:
2662
+ update_func = lambda _i, _n: progress_bar.update(1)
2663
+ with tqdm(total=len(res), desc='Saving video') as progress_bar:
2664
+ ani.save(f'bridge_Vshape{scenario}.mp4',
2665
+ writer='ffmpeg', fps=5,
2666
+ progress_callback=update_func)
2667
+
2668
+ anims.append(ani)
2669
+
2670
+ if 8 in problems or 81 in problems or 82 in problems or 83 in problems or 84 in problems:
2671
+ # U-shape Bridge
2672
+
2673
+ CN = 0.4
2674
+
2675
+ if 8 in problems:
2676
+ scenarios = ['unsteady_downstream_bc',
2677
+ 'hydrograph',
2678
+ 'hydrograph_2steps',
2679
+ # 'Gauss',
2680
+ ]
2681
+ elif 81 in problems:
2682
+ scenarios = ['unsteady_downstream_bc']
2683
+ elif 82 in problems:
2684
+ scenarios = ['hydrograph']
2685
+ elif 83 in problems:
2686
+ scenarios = ['hydrograph_2steps']
2687
+ elif 84 in problems:
2688
+ scenarios = ['Gauss']
2689
+
2690
+ for scenario in scenarios:
2691
+
2692
+ # UNSTEADY WITH TOPOGRAPHY ADAPTATION
2693
+ z_roof_null = 10.
2694
+ min_overflow = 0.25
2695
+
2696
+ h_under_bridge = 3.5
2697
+ h_deck_bridge = 0.4
2698
+ len_bridge = 20
2699
+
2700
+ h0 = 1.5
2701
+
2702
+ z_bridge = np.ones_like(z) * z_roof_null
2703
+ z_deck = np.ones_like(z) * z_roof_null
2704
+
2705
+ slice_bridge = slice(len(dom)//2-len_bridge//2,len(dom)//2+len_bridge//2)
2706
+ slice_bridge_up = slice(len(dom)//2+(len_bridge//2-1),len(dom)//2-(len_bridge//2+1),-1)
2707
+
2708
+ z_bridge[slice_bridge] = z[slice_bridge] + h_under_bridge
2709
+ z_deck[slice_bridge] = z_bridge[slice_bridge] + h_deck_bridge
2710
+
2711
+ idx_up = len(dom)//2-len_bridge//2
2712
+ idx_down = len(dom)//2+len_bridge//2-1
2713
+
2714
+ z_bridge[idx_up] -= .4
2715
+ z_bridge[idx_up+1] -= .4
2716
+
2717
+ z_bridge[idx_down] -= .4
2718
+ z_bridge[idx_down-1] -= .4
2719
+
2720
+ poly_bridge_x = np.concatenate((x[slice_bridge], x[slice_bridge_up]))
2721
+ poly_bridge_y = np.concatenate((z_bridge[slice_bridge], z_deck[slice_bridge_up]))
2722
+
2723
+ z_ini = z.copy()
2724
+
2725
+ res = problem_bridge_unsteady_topo(dom, z,
2726
+ z_bridge, z_deck, z_roof_null,
2727
+ h0, q0, dx, CN, n,
2728
+ press_mode=press_mode,
2729
+ motion_duration=motion_duration,
2730
+ scenario_bc=scenario,
2731
+ min_overflow= min_overflow,
2732
+ updating_time_interval=update_interval)
2733
+
2734
+ ani = animate_bridge_unsteady_topo(dom, poly_bridge_x, poly_bridge_y, res, x, z_ini, hu, z_roof_null, len_bridge, motion_duration=motion_duration)
2735
+
2736
+ if save_video:
2737
+ update_func = lambda _i, _n: progress_bar.update(1)
2738
+ with tqdm(total=len(res), desc='Saving video') as progress_bar:
2739
+ ani.save(f'bridge_Ushape{scenario}.mp4',
2740
+ writer='ffmpeg', fps=5,
2741
+ progress_callback=update_func)
2742
+
2743
+ anims.append(ani)
2744
+
2745
+ return anims
2746
+
2747
+
2333
2748
 
2334
2749
  def hedge():
2335
2750
  """ Compute Water line problems with hedge
@@ -2365,19 +2780,19 @@ def hedge():
2365
2780
  fig, axes = plt.subplots(3,1)
2366
2781
 
2367
2782
  h1, q1 = problem(dom, z, h0, q0, dx, CN, n)
2368
- h2, q2 = problem_hedge(dom, z, h0, q0, dx, CN, n)
2783
+ h2, q2, theta = problem_hedge(dom, z, h0, q0, dx, CN, n)
2369
2784
 
2370
- plot_hedge(axes[0], x, h1, h2, q1, q2, z, hu)
2785
+ plot_hedge(axes[0], x, h1, h2, q1, q2, z, hu, theta)
2371
2786
 
2372
2787
  h1, q1 = problem(dom, z, h0+1., q0, dx, CN, n)
2373
- h2, q2 = problem_hedge(dom, z, h0+1., q0, dx, CN, n)
2788
+ h2, q2, theta = problem_hedge(dom, z, h0+1., q0, dx, CN, n)
2374
2789
 
2375
- plot_hedge(axes[1], x, h1, h2, q1, q2, z, hu)
2790
+ plot_hedge(axes[1], x, h1, h2, q1, q2, z, hu, theta)
2376
2791
 
2377
2792
  h1, q1 = problem(dom, z, h0+2., q0, dx, CN, n)
2378
- h2, q2 = problem_hedge(dom, z, h0+2., q0, dx, CN, n)
2793
+ h2, q2, theta = problem_hedge(dom, z, h0+2., q0, dx, CN, n)
2379
2794
 
2380
- plot_hedge(axes[2], x, h1, h2, q1, q2, z, hu)
2795
+ plot_hedge(axes[2], x, h1, h2, q1, q2, z, hu, theta)
2381
2796
 
2382
2797
  fig.set_size_inches(20, 10)
2383
2798
  fig.tight_layout()
@@ -2386,13 +2801,16 @@ def hedge():
2386
2801
 
2387
2802
  if __name__ == '__main__':
2388
2803
 
2389
- # fig, axes = steady()
2390
- fig, axes = water_line()
2391
- # fig, axes = water_lines()
2392
- # fig, axes = unsteady_without_bedmotion()
2393
- # fig, axes = unteaady_with_bedmotion([2, 6, 7, 8, 9])
2394
- # fig, axes = hedge()
2395
- fig, axes = water_line_noloss_noslope()
2804
+ # anim = steady()
2805
+ # anim = water_line()
2806
+ # anim = water_lines()
2807
+ # anim = unsteady_without_bedmotion()
2808
+ # anim = unteaady_with_bedmotion([2, 6, 7, 8, 9])
2809
+ anim = hedge()
2810
+ # anim = water_line_noloss_noslope()
2811
+
2812
+ # anim1 = unsteady_with_bedmotion([2])
2813
+ # anim2 = unsteady_with_bedmotion_interval([21], update_interval=2., motion_duration=300.)
2396
2814
 
2397
2815
  plt.show()
2398
2816