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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# File 'lib/numru/gphys/derivative.rb', line 123
def __deriv(gp,dim,bc, altcoord, dtype="cderiv", deriv_order=1)
if bc == CYCLIC_OR_LINEAR
bc = ( gp.axis(dim).cyclic_extendible? ? CYCLIC_EXT : LINEAR_EXT )
end
if (dim.is_a?(Numeric) && dim < 0)
dim += gp.rank
elsif dim.is_a?(String)
dim = gp.axnames.index(dim)
end
v_data = gp.data if altcoord
v_x = altcoord
else
v_x = gp.coord(dim)
end
n_data = v_data.val n_x = v_x.val
case dtype
when "cderiv"
n_dgpdx = NumRu::Derivative::cderiv(n_data,n_x,dim,bc)
when "threepoint_O2nd_deriv"
n_dgpdx = NumRu::Derivative::threepoint_O2nd_deriv(n_data,n_x,dim,bc)
when "deriv2nd"
n_dgpdx = NumRu::Derivative::deriv2nd(n_data,n_x,dim,bc)
else
raise ArgumentError, "Unsupported derivative type :'#{dtype}'"
end
case deriv_order
when 1
name = "d#{gp.name}_d#{v_x.name}" when 2
name = "d2#{gp.name}_d#{v_x.name}2" end
v_dgpdx = VArray.new(n_dgpdx, gp.data, name) g_dgpdx = GPhys.new( gp.grid_copy, v_dgpdx )
u_data = v_data.units
u_x = v_x.units
case deriv_order
when 1
g_dgpdx.units = u_data/u_x if v_data.get_att('long_name') && v_x.get_att('long_name')
long_name = "d_#{v_data.get_att('long_name')}_d_#{v_x.get_att('long_name')}"
else
long_name = name
end
when 2
g_dgpdx.units = u_data/u_x**2 if v_data.get_att('long_name') && v_x.get_att('long_name')
long_name = "d2(#{v_data.get_att('long_name')})_d(#{v_x.get_att('long_name')})2"
else
long_name = name
end
end
g_dgpdx.data.set_att("long_name",long_name) return g_dgpdx
end
|