-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_definition.py
More file actions
167 lines (126 loc) · 5.95 KB
/
Copy pathmodel_definition.py
File metadata and controls
167 lines (126 loc) · 5.95 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
##############################################################################################
#
# This script defines the Weak Temperature Gradient (WTG) tropical model using
# the LayerCake library
#
##############################################################################################
# Importing libraries
#####################
import numpy as np
from sympy import Symbol, sin, cos
# importing all that is needed to create a cake
from layercake import *
# importing specific modules to create the model basis of functions
from layercake.basis.centered_planar_fourier import contiguous_channel_basis
from layercake.inner_products.definition import StandardSymbolicInnerProductDefinition
from layercake.arithmetic.terms.gradient import vorticity_gradients_product
from layercake.arithmetic.terms.operations import ProductOfTerms
def define_model(nx, ny, chi=0.07):
"""Construct the WTG-TN model using LayerCake.
Parameters
----------
nx: int
The truncation of the model basis in the zonal x direction.
ny: int
The truncation of the model basis in the meridional y direction.
chi: float, optional
The non-dimensional value of the WTG forcing chi_2 and chi_5 components.
"""
# Setting some parameters
##########################
# Characteristic length scale (L_y / pi)
L_symbol = Symbol('L')
L = Parameter(1273239.5447351628, symbol=L_symbol, units='[m]')
# Domain aspect ratio
n_symbol = Symbol('n')
n = Parameter(0.2, symbol=n_symbol)
# Meridional gradient of the Coriolis parameter at phi_0
beta_symbol = Symbol(u'β')
beta = Parameter(2.88e-11, symbol=beta_symbol, units='[m^-1][s^-1]')
# Atmosphere bottom friction coefficient
r_symbol = Symbol('r')
r = Parameter(1.e-06, symbol=r_symbol, units='[s^-1]')
# Mixed layer height
H_symbol = Symbol('H')
H = Parameter(200., symbol=H_symbol, units='[m]')
# Gravity acceleration
g_symbol = Symbol('g')
g = Parameter(9.81, symbol=g_symbol, units='[m][s^-2]')
# Forcing parameters (dimensionless for now)
Ap = Parameter(3*np.pi*chi/4, symbol=Symbol("A'"))
Bp = Parameter(3*np.pi*chi/4, symbol=Symbol("B'"))
# Defining the domain
######################
parameters = [n]
atmospheric_basis = contiguous_channel_basis(nx, ny, parameters)
# coordinates
x = atmospheric_basis.coordinate_system.coordinates_symbol_as_list[0]
y = atmospheric_basis.coordinate_system.coordinates_symbol_as_list[1]
# creating an inner product definition with an optimizer for trigonometric functions
inner_products_definition = StandardSymbolicInnerProductDefinition(coordinate_system=atmospheric_basis.coordinate_system,
optimizer='trig', kwargs={'conds': 'none'})
# Derived (non-dimensional) parameters
#######################################
# wave speed
c = Parameter(np.sqrt(g * H), symbol=Symbol('c'), units='[m][s^-1]')
# time units
T = Parameter(1./np.sqrt(beta * c), symbol=Symbol('T'), units='[s]')
# nondimensional bottom friction
# rp_symbol = Symbol("r'")
rp_symbol = Symbol("r")
rp = Parameter(r * T, symbol=rp_symbol, units='')
# Non-dimensional Meridional gradient of the Coriolis parameter at phi_0
# betap_symbol = Symbol(u"β'")
betap_symbol = Symbol(u"β")
beta_nondim = Parameter(beta * L * T, symbol=betap_symbol, units='')
# Defining the fields
#######################
p = u'ψ'
psi = Field("psi", p, atmospheric_basis, inner_products_definition, units="[m^2][s^-2]", latex=r'\psi')
ch = u'χ'
ch_expression = Ap.symbol * cos(y)**2 * cos(n_symbol * x) + Bp.symbol * sin(y) * cos(n_symbol * x)
chi = FunctionField("chi", ch, ch_expression, atmospheric_basis, [Ap, Bp], inner_products_definition, units="[m^2][s^-2]", latex=r'\chi')
# --------------------------------
#
# Tropical field equation
#
# --------------------------------
# defining the LHS as the time derivative of the vorticity
vorticity = OperatorTerm(psi, Laplacian, atmospheric_basis.coordinate_system)
tropical_equation = Equation(psi, lhs_terms=vorticity)
# Defining the advection term
advection_term = vorticity_advection(psi, psi, atmospheric_basis.coordinate_system, sign=-1)
tropical_equation.add_rhs_terms(advection_term)
# adding the beta term
beta_term = OperatorTerm(psi, D, x, prefactor=beta_nondim, sign=-1)
tropical_equation.add_rhs_term(beta_term)
# adding the friction with the ground
friction = OperatorTerm(psi, Laplacian, atmospheric_basis.coordinate_system, prefactor=rp, sign=-1)
tropical_equation.add_rhs_term(friction)
# forcing
vorticity_gradients = vorticity_gradients_product(chi, psi, atmospheric_basis.coordinate_system, sign=-1)
tropical_equation.add_rhs_terms(vorticity_gradients)
beta_chi = OperatorTerm(chi, D, y, prefactor=beta_nondim, sign=-1)
tropical_equation.add_rhs_term(beta_chi)
chi_laplacian_term = OperatorTerm(chi, Laplacian, atmospheric_basis.coordinate_system)
psi_laplacian_term = OperatorTerm(psi, Laplacian, atmospheric_basis.coordinate_system)
chi_psi_laplacian_product = ProductOfTerms(psi_laplacian_term, chi_laplacian_term, sign=-1)
tropical_equation.add_rhs_term(chi_psi_laplacian_product)
y_expression = Expression(betap_symbol*y, latex=r"\beta y", expression_parameters=[beta_nondim])
y_chi_laplacian_term = OperatorTerm(chi, Laplacian, atmospheric_basis.coordinate_system, prefactor=y_expression, sign=-1)
tropical_equation.add_rhs_term(y_chi_laplacian_term)
# --------------------------------
#
# Constructing the layer
#
# --------------------------------
layer = Layer()
layer.add_equation(tropical_equation)
# --------------------------------
#
# Constructing the cake
#
# --------------------------------
cake = Cake()
cake.add_layer(layer)
return cake