def calc_velocity(self, nonlinear=True): """ Return the velocity components u = d \psi /dz w = -d \psi /dx """ psi = self.calc_streamfunction(nonlinear=nonlinear) #us, ws = np.gradient(psi) #return -us/self.dZ[np.newaxis,...], -ws/self.dx_s u = grad_z(psi, self.Z, axis=0) w = -1 * grad_z(psi, self.X, axis=1) return u.T, w.T
def get_Lw(rho, z, z0=None, Nz=400, mode=1, omega=2 * np.pi / (12.42 * 3600)): """ A function to calculate the wavelength of a specific vertical mode for a specific frequency given stratification conditions. z0 is the final depth. Will interpolate there if necessary. """ if z0 is None: z0 = max(z) Z = -np.linspace(0, 1, Nz) * z0 dZ = np.abs(Z[1] - Z[0]) # Interpolate the density profile onto all points Fi = interp1d(z, rho, axis=0, fill_value='extrapolate') rhoZ = Fi(Z) drho_dz = grad_z(rhoZ, Z, axis=0) N2 = -GRAV * drho_dz / RHO0 phi, c = isw.iwave_modes(N2, dZ) phi_n = phi[:, mode] c_n = c[mode] k = omega / c_n Lw = 2 * np.pi / k return Lw
def calc_N2(self): """ Calculate the buoyancy frequency """ #drho_dz = np.gradient(self.rhoz, -np.abs(self.dz)) drho_dz = grad_z(self.rhoz, self.z, axis=0) N2 = -GRAV * drho_dz if not self.nondim: N2 /= RHO0 return N2
def calc_buoyancy_h99(self, nonlinear=True): """ Use the Holloway et al 99 version of the eqn's """ dN2_dz = grad_z(self.N2, self.Z, axis=0) # Linear term b = self.B[np.newaxis, :] * self.phi_1 * self.N2 #alpha = self.r10/(2*self.c1) ?? #alpha = -2*self.c1*self.r10 alpha = self.Alpha # nonlinear terms if nonlinear: b -= alpha / ( 2 * self.c1) * self.B[np.newaxis, :] * self.phi_1 * self.N2 b -= 0.5 * dN2_dz * self.B[np.newaxis, :]**2. * self.phi_1**2. # Cubic nonlinearity #b += self.c1*self.B[:,np.newaxis]**2. *self.N2 * self.T10 return b.T
def calc_N2(self): drho_dz = grad_z(self.rhoZ, self.Z, axis=0) return -GRAV * drho_dz / RHO0