forked from cmkaul/SCAMPy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Simulation1d.pyx
72 lines (63 loc) · 2.51 KB
/
Simulation1d.pyx
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import time
from pathlib import Path
import numpy as np
cimport numpy as np
from Variables cimport GridMeanVariables
from Turbulence import ParameterizationFactory
from Cases import CasesFactory
cimport Grid
cimport ReferenceState
cimport Cases
from Surface cimport SurfaceBase
from Cases cimport CasesBase
from NetCDFIO cimport NetCDFIO_Stats
cimport TimeStepping
class Simulation1d:
def __init__(self, namelist, paramlist, inpath=Path.cwd()):
self.Gr = Grid.Grid(namelist)
self.Ref = ReferenceState.ReferenceState(self.Gr)
self.GMV = GridMeanVariables(namelist, self.Gr, self.Ref)
self.Case = CasesFactory(namelist, paramlist)
self.Turb = ParameterizationFactory(namelist,paramlist, self.Gr, self.Ref)
self.TS = TimeStepping.TimeStepping(self.Gr, namelist)
self.Stats = NetCDFIO_Stats(namelist, paramlist, self.Gr, inpath)
return
def initialize(self, namelist):
self.Case.initialize_reference(self.Gr, self.Ref, self.Stats, namelist)
self.Case.initialize_profiles(self.Gr, self.GMV, self.Ref)
self.Case.initialize_surface(self.Gr, self.Ref, self.TS, namelist)
self.Case.initialize_forcing(self.Gr, self.Ref, self.GMV, self.TS)
self.Case.initialize_radiation(self.Gr, self.Ref, self.GMV, self.TS)
self.Turb.initialize(self.Case, self.GMV, self.Ref)
self.initialize_io()
self.io()
return
def run(self):
while self.TS.t <= self.TS.t_max:
self.GMV.zero_tendencies()
self.Case.update_surface(self.GMV, self.TS)
self.Case.update_forcing(self.GMV, self.TS)
self.Case.update_radiation(self.Ref, self.Gr, self.GMV, self.TS)
self.Turb.update(self.GMV, self.Case, self.TS)
self.TS.update()
# Apply the tendencies, also update the BCs and diagnostic thermodynamics
self.GMV.update(self.TS)
self.Turb.update_GMV_diagnostics(self.GMV)
if np.mod(self.TS.t, self.Stats.frequency) == 0:
self.io()
return
def initialize_io(self):
self.GMV.initialize_io(self.Stats)
self.Case.initialize_io(self.Stats)
self.Turb.initialize_io(self.Stats)
return
def io(self):
self.Stats.open_files()
self.Stats.write_simulation_time(self.TS.t)
self.GMV.io(self.Stats)
self.Case.io(self.Stats)
self.Turb.io(self.Stats, self.TS)
self.Stats.close_files()
return
def force_io(self):
return