1 | from dynamico.meshes import Cartesian_mesh as Mesh |
---|
2 | from dynamico import unstructured as unst |
---|
3 | from dynamico import dyn |
---|
4 | from dynamico import time_step |
---|
5 | from dynamico import DCMIP |
---|
6 | import math as math |
---|
7 | import matplotlib.pyplot as plt |
---|
8 | import numpy as np |
---|
9 | import time |
---|
10 | |
---|
11 | nx,ny,llm,nqdyn=128,128,1,1 |
---|
12 | Lx,Ly,g,f = 8.,8.,1.,1. |
---|
13 | dx,dy=Lx/nx,Ly/ny |
---|
14 | |
---|
15 | unst.setvar('g',g) |
---|
16 | mesh = Mesh(nx,ny,llm,nqdyn,Lx,Ly,f) |
---|
17 | caldyn = unst.Caldyn_RSW(mesh) |
---|
18 | |
---|
19 | x1,x2,yy = mesh.xx[:,:,0]-1., mesh.xx[:,:,0]+1., mesh.yy[:,:,0] |
---|
20 | h0 = 1+0.1*(np.exp(-2.*(x1*x1+yy*yy))+ |
---|
21 | np.exp(-2.*(x2*x2+yy*yy))) |
---|
22 | u0 = mesh.field_u() # flow initally at rest |
---|
23 | flow0=(h0,u0) |
---|
24 | |
---|
25 | cfl = .8 |
---|
26 | dt = cfl/math.sqrt((nx/Lx)**2+(ny/Ly)**2) |
---|
27 | |
---|
28 | T=10. |
---|
29 | N=int(T/dt)+1 |
---|
30 | dt=T/N |
---|
31 | print N,dt,Lx/nx |
---|
32 | scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt) |
---|
33 | |
---|
34 | flow=flow0 |
---|
35 | for i in range(10): |
---|
36 | h,u=flow |
---|
37 | caldyn.bwd_fast_slow(flow, 0.) |
---|
38 | plt.figure(); plt.pcolor(mesh.x,mesh.y,caldyn.qv) |
---|
39 | plt.colorbar(); plt.title('potential vorticity') |
---|
40 | plt.savefig('fig_RSW_2D/%02d.png'%i) |
---|
41 | # plt.figure(); plt.pcolor(mesh.x,mesh.y,h) |
---|
42 | # plt.colorbar(); plt.title('h') |
---|
43 | # plt.show() |
---|
44 | # plt.pcolor(x,y,vcomp(u)/dx) |
---|
45 | # plt.colorbar(); plt.title('v') |
---|
46 | # plt.show() |
---|
47 | for j in range(5): |
---|
48 | unst.elapsed=0. |
---|
49 | flow = scheme.advance(flow,N) |
---|
50 | # flops |
---|
51 | # mass flux : 1add+1mul per edge => 4 |
---|
52 | # div U : 4 add per cell => 4 |
---|
53 | # KE : 4*(2add+1mul) per cell => 12 |
---|
54 | # grad KE : 1 add per edge => 2 |
---|
55 | # grad h : 1 add per edge => 2 |
---|
56 | # qv : 4+4+1 add +4mul + 1div per cell => 10 |
---|
57 | # qu : 1add+1mul per edge => 4 |
---|
58 | # TrisK : 4add+4mul+4add+1add per edge => 26 |
---|
59 | # Total : 64 FLOPS/cell |
---|
60 | print i,j, unst.elapsed, 100.*(1.-unst.getvar('elapsed')/unst.elapsed) |
---|
61 | print 'GFlops', 64*(N*nx*ny)/unst.elapsed/1e9 |
---|
62 | unst.setvar('elapsed',0.) |
---|