-
Notifications
You must be signed in to change notification settings - Fork 3
/
control.py
47 lines (34 loc) · 1.16 KB
/
control.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import netCDF4 as nc
import torch
from qbo1d import adsolver
from qbo1d.stochastic_forcing import WaveSpectrum
if __name__ == "__main__":
# global parameters for all scenarios
t_max = 360 * 108 * 86400
nsteps = 360 * 108
nspinup = 360 * 12
ntot = int(nsteps - nspinup)
torch.set_default_dtype(torch.float64)
# scenario 0 (control)
# --------------------
solver = adsolver.ADSolver(t_max=t_max, w=3e-4)
model = WaveSpectrum(solver)
time = solver.time
z = solver.z
u = solver.solve(source_func=model)
# evaluate source
s = model.s
# save to a netcdf file
file_name = './data/direct/control.nc'
ds = nc.Dataset(file_name, 'w', format='NETCDF4')
heights = ds.createDimension('z', z.shape[0])
times = ds.createDimension('time', ntot)
heights = ds.createVariable('z', 'f8', ('z'))
times = ds.createVariable('time', 'f8', ('time'))
wind = ds.createVariable('u', 'f8', ('time', 'z'))
source = ds.createVariable('S', 'f8', ('time', 'z'))
heights[:] = z
times[:] = time[nspinup:nsteps]
wind[:, :] = u[nspinup:nsteps, :]
source[:, :] = s[nspinup:nsteps, :]
ds.close()