def test8(self): instance = QGmodel(redirection="none") Lx2 = instance.parameters.Lx / 2 instance.parameters.Ly = Lx2 Nx, Ny, Nm = instance.grid.shape s = instance.boundaries(1).shape self.assertEqual(s, (2, Ny + 2, 1)) s = instance.boundaries(2).shape self.assertEqual(s, (2, Ny + 2, 1)) s = instance.boundaries(3).shape self.assertEqual(s, (Nx + 2, 2, 1)) s = instance.boundaries(4).shape self.assertEqual(s, (Nx + 2, 2, 1)) instance.stop()
def test10(self): instance = QGmodel() org = instance.boundaries(1) self.assertEquals(org.psi.number, 0.) self.assertEquals(org.dpsi_dt.number, 0.) shape = org.shape copy = org.copy() instance.stop()
def test11(self): instance = QGmodel(redirection="none") instance.parameters.Ly = instance.parameters.Ly / 8 instance.parameters.Lx = instance.parameters.Lx / 8 for i in [1, 2, 3, 4]: org = instance.boundaries(i) shape = org.shape copy = org.copy() channel = copy.new_channel_to(org) copy.psi = numpy.random.random(shape) | units.m**2 / units.s copy.dpsi_dt = numpy.random.random(shape) | units.m**2 / units.s**2 channel.copy_attributes(["psi", "dpsi_dt"]) self.assertEquals(copy.psi, instance.boundaries(i).psi) self.assertEquals(copy.dpsi_dt, instance.boundaries(i).dpsi_dt) instance.stop()
def interface_bc(tend=1. | units.hour, dt=3600. | units.s, correct=True): q = QGmodel(redirection="none") q.parameters.dt = dt q.parameters.xbound1 = "interface" while q.model_time < tend: q.evolve_model(q.model_time + dt) if correct: xb1 = q.boundaries(1).copy() xb1.psi[0, 1:-1, 0] = -q.grid.psi[1, :, 0] channel = xb1.new_channel_to(q.boundaries(1)) channel.copy() psi = q.grid[:, :, 0].psi.number return psi
def semi_domain_test(tend=1. | units.hour, dt=3600. | units.s): q1 = QGmodel(redirection="none") q1.parameters.dt = dt / 2 Lx = q1.parameters.Lx.value_in(1000 * units.km) q2 = QGmodel(redirection="none") q2.parameters.dt = dt / 2 q2.parameters.Lx /= 2 q2.parameters.boundary_east = "interface" Nx, Ny, Nm = q1.grid.shape pyplot.ion() f = pyplot.figure(figsize=(12, 5)) pyplot.show() i = 0 while q1.model_time < tend: i = i + 1 tnow = q1.model_time q1.evolve_model(tnow + dt / 2) psi = q1.grid[(Nx - 1) / 2:(Nx - 1) / 2 + 2, :, 0].psi dpsi_dt = q1.grid[(Nx - 1) / 2:(Nx - 1) / 2 + 2, :, 0].dpsi_dt west = q2.boundaries("west").copy() west[:, 1:-1, 0].psi = psi west[:, 1:-1, 0].dpsi_dt = dpsi_dt channel = west.new_channel_to(q2.boundaries("west")) channel.copy() q1.evolve_model(tnow + dt) q2.evolve_model(tnow + dt) # print(q1.grid[(Nx+1)/2,1,0].dpsi_dt) # print(q2.boundaries("west")[0:2,0,0].x) if i % 5 == 0: psi1_complete = q1.grid.psi.number[:, :, 0] psi1 = q1.grid[:(Nx + 1) / 2, :, 0].psi.number psi2 = q2.grid[:, :, 0].psi.number d = abs(psi2 - psi1) print(d.max(), d.mean(), abs(psi1).max()) f.clf() f1 = pyplot.subplot(131) f1.imshow(psi1_complete.transpose() / psi1.max(), vmin=0, vmax=1, extent=[0, Lx, 0, Lx], origin="lower") f1.set_xlabel("x (x1000 km)") f2 = pyplot.subplot(132) f2.imshow(psi2.transpose() / psi1.max(), vmin=0, vmax=1, extent=[0, Lx / 2, 0, Lx], origin="lower") f2.set_xlabel("x (x1000 km)") f3 = pyplot.subplot(133) f3.imshow(d.transpose() / psi1.max(), vmin=0, vmax=0.001, extent=[0, Lx / 2, 0, Lx], origin="lower") f3.set_xlabel("x (x1000 km)") pyplot.draw() pyplot.savefig("snapshots/half_domain_test-%6.6i.png" % i) raw_input()