h = sph.TensorField(0, S, domain) c = sph.TensorField(0, S, domain) Du = sph.TensorField(2, S, domain) uh = sph.TensorField(1, S, domain) Dc = sph.TensorField(1, S, domain) divuh = sph.TensorField(0, S, domain) u_rhs = sph.TensorField(1, S, domain) h_rhs = sph.TensorField(0, S, domain) c_rhs = sph.TensorField(0, S, domain) state_vector = eq.StateVector(u, h, c) RHS = eq.StateVector(u, h, c) timestepper = timesteppers.SBDF2(eq.StateVector, u, h, c) # Add random perturbations to the spectral coefficients # rand = np.random.RandomState(seed=42) # u.layout='c' # for m in range(0,L_max+1): # md = m - m_start # (start_index,end_index,spin) = S.tensor_index(m,1) # shape = (end_index[-1]) # noise = rand.standard_normal(shape) # phase = rand.uniform(0,2*np.pi,shape) # if m>=m_start and m<=m_end: # u['c'][md] = 0.0001 * noise*np.exp(1j*phase) # def hump(i,j,rlat0,rlon0,a): # phiamp = 1
T = ball.TensorField_3D(0, B, domain) DT = ball.TensorField_3D(1, B, domain) u_rhs = ball.TensorField_3D(1, B, domain) p_rhs = ball.TensorField_3D(0, B, domain) T_rhs = ball.TensorField_3D(0, B, domain) # initial condition T['g'] = 0.5 * (1 - r**2) + 0.1 / 8. * np.sqrt(35 / np.pi) * r**3 * ( 1 - r**2) * (np.cos(3 * phi) + np.sin(3 * phi)) * np.sin(theta)**3 # build state vector state_vector = StateVector(u, p, T) NL = StateVector(u, p, T) #timestepper = timesteppers.SBDF4(StateVector, u,p,T) timestepper = timesteppers.SBDF2(StateVector, u, p, T) # build matrices M, L, P, LU = [], [], [], [] for ell in range(ell_start, ell_end + 1): N = B.N_max - B.N_min(ell - B.R_max) M_ell, L_ell = matrices(N, ell, Ekman, Prandtl, Rayleigh) M.append(M_ell.astype(np.complex128)) L.append(L_ell.astype(np.complex128)) P.append(M_ell.astype(np.complex128)) LU.append([None]) # calculate RHS terms from state vector def nonlinear(state_vector, RHS, t):