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