def initKP(): tic = time.time() ghosts = np.array([2,2,2,2]) # north, east, south, west dataShape = (args.ny + ghosts[0]+ghosts[2], args.nx + ghosts[1]+ghosts[3]) eta0 = np.fromfunction(lambda i, j: my_exp(i,j), dataShape, dtype=np.float32) u0 = np.zeros(dataShape, dtype=np.float32, order='C'); v0 = np.zeros(dataShape, dtype=np.float32, order='C'); Hi = np.ones((dataShape[0]+1, dataShape[1]+1), dtype=np.float32, order='C') * waterHeight; toc = time.time() print("{:02.4f} s: ".format(toc-tic) + "Generated initial conditions") # Initialize simulator tic = time.time() kwargs = {'boundary_conditions': boundaryConditions, 'use_rk2': True, 'write_netcdf': True, 'comm': MPI.COMM_WORLD} if (args.block_width != None): kwargs['block_width'] = args.block_width if (args.block_height != None): kwargs['block_height'] = args.block_height sim = KP07.KP07(gpu_ctx, \ eta0, Hi, u0, v0, \ args.nx, args.ny, \ dx, dy, dt, \ g, f, r, \ **kwargs) toc = time.time() print("{:02.4f} s: ".format(toc-tic) + "Created KP simulator") return sim
def test_wall_central_with_nonzero_flat_bottom(self): self.setBoundaryConditions() self.allocData() addCentralBump(self.h0, self.nx, self.ny, self.dx, self.dy, self.validDomain) extraBottom = 10.0 self.Hi = self.Hi + extraBottom self.h0 = self.h0 + extraBottom self.sim = KP07.KP07(self.cl_ctx, \ self.eta0, self.Hi, self.u0, self.v0, \ self.nx, self.ny, \ self.dx, self.dy, self.dt, \ self.g, self.f, self.r) #, boundary_conditions=self.boundaryConditions) t = self.sim.step(self.T) eta1, u1, v1 = self.sim.download() eta2, u2, v2 = loadResults("KP07", "wallBC", "central") self.checkResults( eta1, u1, v1, eta2, u2, v2, message= "\nKNOWN TO FAIL with value eta difference! Max diff: 1.52587890625e-05, L2 diff: 0.000251422989705..." )
def test_lake_at_rest_flat_bottom(self): self.setBoundaryConditions() self.allocData() self.Hi = self.Hi+10.0 self.sim = KP07.KP07(self.gpu_ctx, \ self.eta0, self.Hi, self.u0, self.v0, \ self.nx, self.ny, \ self.dx, self.dy, self.dt, \ self.g, self.f, self.r) #, boundary_conditions=self.boundaryConditions) t = self.sim.step(self.T) eta, u, v = self.sim.download() self.checkLakeAtRest(eta, u, v)
def test_lake_at_rest_crazy_bottom(self): self.setBoundaryConditions() self.allocData() makeBathymetryCrazyness(self.Bi, self.nx+1, self.ny+1, self.dx, self.dy, self.ghosts) self.Hi += self.Bi self.sim = KP07.KP07(self.gpu_ctx, \ self.eta0, self.Hi, self.u0, self.v0, \ self.nx, self.ny, \ self.dx, self.dy, self.dt, \ self.g, self.f, self.r) #, boundary_conditions=self.boundaryConditions) t = self.sim.step(self.T) eta, u, v = self.sim.download() self.checkLakeAtRest(eta, u, v)
def test_periodicEW_upperCorner(self): self.setBoundaryConditions(bcSettings=4) self.allocData() addUpperCornerBump(self.eta0, self.nx, self.ny, self.dx, self.dy, self.validDomain) self.sim = KP07.KP07(self.gpu_ctx, \ self.eta0, self.Hi, self.u0, self.v0, \ self.nx, self.ny, \ self.dx, self.dy, self.dt, \ self.g, self.f, self.r, boundary_conditions=self.boundaryConditions) t = self.sim.step(self.T) eta1, u1, v1 = self.sim.download() eta2, u2, v2 = loadResults("KP07", "periodicEW", "upperCorner") self.checkResults(eta1, u1, v1, eta2, u2, v2)
def test_periodicNS_central(self): self.setBoundaryConditions(bcSettings=3) self.allocData() addCentralBump(self.eta0, self.nx, self.ny, self.dx, self.dy, self.validDomain) self.sim = KP07.KP07(self.gpu_ctx, \ self.eta0, self.Hi, self.u0, self.v0, \ self.nx, self.ny, \ self.dx, self.dy, self.dt, \ self.g, self.f, self.r, boundary_conditions=self.boundaryConditions) t = self.sim.step(self.T) eta1, u1, v1 = self.sim.download() eta2, u2, v2 = loadResults("KP07", "wallBC", "central") self.checkResults(eta1, u1, v1, eta2, u2, v2)
def test_wall_corner(self): self.setBoundaryConditions() self.allocData() addCornerBump(self.eta0, self.nx, self.ny, self.dx, self.dy, self.validDomain) self.sim = KP07.KP07(self.gpu_ctx, \ self.eta0, self.Hi, self.u0, self.v0, \ self.nx, self.ny, \ self.dx, self.dy, self.dt, \ self.g, self.f, self.r) #, boundary_conditions=self.boundaryConditions) t = self.sim.step(self.T) eta1, u1, v1 = self.sim.download() eta2, u2, v2 = loadResults("KP07", "wallBC", "corner") self.checkResults(eta1, u1, v1, eta2, u2, v2)
def test_coriolis_central(self): self.setBoundaryConditions() self.allocData() self.f = 0.01 addCentralBump(self.eta0, self.nx, self.ny, self.dx, self.dy, self.validDomain) self.sim = KP07.KP07(self.gpu_ctx, \ self.eta0, self.Hi, self.u0, self.v0, \ self.nx, self.ny, \ self.dx, self.dy, self.dt, \ self.g, self.f, self.r) #, boundary_conditions=self.boundaryConditions) t = self.sim.step(self.T) eta1, u1, v1 = self.sim.download() eta2, u2, v2 = loadResults("KP07", "coriolis", "central") self.checkResults(eta1, u1, v1, eta2, u2, v2)
def initKP(): tic = time.time() ghosts = np.array([2, 2, 2, 2]) # north, east, south, west dataShape = (args.ny + ghosts[0] + ghosts[2], args.nx + ghosts[1] + ghosts[3]) eta0 = np.zeros(dataShape, dtype=np.float32, order='C') initEtaFV(eta0, ghosts) u0 = np.zeros(dataShape, dtype=np.float32, order='C') v0 = np.zeros(dataShape, dtype=np.float32, order='C') Hi = np.ones( (dataShape[0] + 1, dataShape[1] + 1), dtype=np.float32, order='C') * waterHeight dt = courant_number * dx / (4 * gravity_wave_speed) toc = time.time() print("{:02.4f} s: ".format(toc - tic) + "Generated initial conditions") # Initialize simulator tic = time.time() kwargs = {'boundary_conditions': boundaryConditions, 'use_rk2': True} if (args.block_width != None): kwargs['block_width'] = args.block_width if (args.block_height != None): kwargs['block_height'] = args.block_height sim = KP07.KP07(gpu_ctx, \ eta0, Hi, u0, v0, \ args.nx, args.ny, \ dx, dy, dt, \ g, f, r, \ **kwargs) toc = time.time() print("{:02.4f} s: ".format(toc - tic) + "Created KP simulator") print_memory_req(sim, fvd=True) return sim