def test_curl_explicit_2d_vector(basis, N, dealias, dtype): c, d, b, r = basis(N, dealias, dtype) x, y = r kx, ky = 2 * np.pi / Lx, 2 * np.pi / Ly f = d.VectorField(c, bases=b) f.preset_scales(dealias) f['g'][0] = (np.sin(2 * kx * x) + np.sin(kx * x)) * np.cos(ky * y) f['g'][1] = np.sin(kx * x) * np.cos(ky * y) g_op = -d3.div(d3.skew(f)) # z @ curl(f) g = d.Field(bases=b) g.preset_scales(dealias) g['g'] = kx * np.cos(kx * x) * np.cos( ky * y) + ky * (np.sin(2 * kx * x) + np.sin(kx * x)) * np.sin(ky * y) assert np.allclose(g_op.evaluate()['g'], g['g'])
# Solver solver = problem.build_solver(timestepper) solver.stop_sim_time = stop_sim_time # Initial conditions b.fill_random('g', seed=42, distribution='normal', scale=1e-3) # Random noise b['g'] *= z * (Lz - z) # Damp noise at walls b['g'] += Lz - z # Add linear background # Analysis snapshots = solver.evaluator.add_file_handler('snapshots', sim_dt=0.25, max_writes=50) snapshots.add_task(b, name='buoyancy') snapshots.add_task(-d3.div(d3.skew(u)), name='vorticity') # CFL CFL = d3.CFL(solver, initial_dt=max_timestep, cadence=10, safety=0.5, threshold=0.05, max_change=1.5, min_change=0.5, max_dt=max_timestep) CFL.add_velocity(u) # Flow properties flow = d3.GlobalFlowProperty(solver, cadence=10) flow.add_property(np.sqrt(u @ u) / nu, name='Re')
# Bases coords = d3.S2Coordinates('phi', 'theta') dist = d3.Distributor(coords, dtype=dtype) basis = d3.SphereBasis(coords, (Nphi, Ntheta), radius=1, dealias=dealias, dtype=dtype) phi, theta = basis.local_grids((1, 1)) # Fields u = dist.VectorField(coords, name='u', bases=basis) f = dist.VectorField(coords, name='f', bases=basis) p = dist.Field(name='p', bases=basis) g = dist.Field(name='g') # Substitutions zcross = lambda A: d3.MulCosine(d3.skew(A)) curl_vec = lambda A: - d3.div(d3.skew(A)) # Problem problem = d3.IVP([u, p, g], namespace=locals()) problem.add_equation("dt(u) + grad(p) + kappa*u - nu*lap(u) + (2*Omega)*zcross(u) = - dot(u,grad(u)) + f") problem.add_equation("div(u) + g = 0") problem.add_equation("ave(p) = 0") # Solver solver = problem.build_solver(d3.RK222) solver.stop_iteration = stop_iteration # Analysis snapshots = solver.evaluator.add_file_handler('snapshots', iter=10, max_writes=10) snapshots.add_task(curl_vec(u), name='vorticity')