1
1
import numpy as np
2
2
import argparse
3
3
from time import perf_counter
4
+ from IPython .display import clear_output
5
+ from matplotlib import pyplot as plt
6
+
7
+ def read_arrays (u_file , v_file , p_file ):
8
+ u_v = np .loadtxt (u_file ,)
9
+ v_v = np .loadtxt (v_file )
10
+ p_v = np .loadtxt (p_file )
11
+ return u_v , v_v , p_v
12
+
13
+ def live_plot_val (fu , fv , fp , title = '' ):
14
+ mxu = fu .max ()
15
+ mxv = fv .max ()
16
+ mxp = fp .max ()
17
+ clear_output (wait = True )
18
+ fig , (ax1 , ax2 , ax3 ) = plt .subplots (figsize = (13 , 3 ), ncols = 3 )
19
+
20
+ pos1 = ax1 .imshow (fp , cmap = 'Blues' , vmin = - mxp , vmax = mxp ,interpolation = 'none' )
21
+ ax1 .set_title ('p' )
22
+ plt .colorbar (pos1 ,ax = ax1 )
23
+ pos2 = ax2 .imshow (fu , cmap = 'Reds' , vmin = - mxu , vmax = mxu ,interpolation = 'none' )
24
+ ax2 .set_title ('u' )
25
+ plt .colorbar (pos2 ,ax = ax2 )
26
+ pos3 = ax3 .imshow (fv , cmap = 'Greens' ,vmin = - mxv , vmax = mxv ,interpolation = 'none' )
27
+ ax3 .set_title ('v' )
28
+ plt .colorbar (pos3 , ax = ax3 )
29
+
30
+ fig .suptitle (title )
31
+ plt .show ()
32
+
4
33
5
34
def main ():
6
35
parser = argparse .ArgumentParser (description = "Shallow Water Model" )
7
- parser .add_argument ('--M' , type = int , default = 256 , help = 'Number of points in the x direction' )
8
- parser .add_argument ('--N' , type = int , default = 256 , help = 'Number of points in the y direction' )
36
+ parser .add_argument ('--M' , type = int , default = 64 , help = 'Number of points in the x direction' )
37
+ parser .add_argument ('--N' , type = int , default = 64 , help = 'Number of points in the y direction' )
9
38
parser .add_argument ('--L_OUT' , type = bool , default = True , help = 'a boolean for L_OUT' )
10
39
11
40
@@ -20,6 +49,7 @@ def main():
20
49
M_LEN = M + 1
21
50
N_LEN = N + 1
22
51
L_OUT = args .L_OUT
52
+ VAL = True
23
53
ITMAX = 4000
24
54
dt = 90.
25
55
tdt = dt
@@ -269,5 +299,34 @@ def main():
269
299
print ("t200: " ,dt2 )
270
300
print ("t300: " ,dt3 )
271
301
302
+
303
+ if VAL :
304
+
305
+ u_val_f = 'ref/u.64.64.IT4000.txt'
306
+ v_val_f = 'ref/v.64.64.IT4000.txt'
307
+ p_val_f = 'ref/p.64.64.IT4000.txt'
308
+ uval = np .zeros ((M_LEN , N_LEN ))
309
+ vval = np .zeros ((M_LEN , N_LEN ))
310
+ pval = np .zeros ((M_LEN , N_LEN ))
311
+
312
+ uref , vref , pref = read_arrays (v_val_f , u_val_f , p_val_f )
313
+ uval = uref - unew
314
+ vval = vref - vnew
315
+ pval = pref - pnew
316
+
317
+ uLinfN = np .linalg .norm (uval , np .inf )
318
+ vLinfN = np .linalg .norm (vval , np .inf )
319
+ pLinfN = np .linalg .norm (pval , np .inf )
320
+
321
+
322
+
323
+ live_plot_val (uval , vval , pval , "Val" )
324
+ print ("uLinfN: " , uLinfN )
325
+ print ("vLinfN: " , vLinfN )
326
+ print ("pLinfN: " , pLinfN )
327
+ print ("udiff max: " ,uval .max ())
328
+ print ("vdiff max: " ,vval .max ())
329
+ print ("pdiff max: " ,pval .max ())
330
+
272
331
if __name__ == "__main__" :
273
332
main ()
0 commit comments