def rhs_noslip(self, x, source): """ add the vorticity source term along the boundary to enforce zero tangential velocity (=no-slip) """ ip = self.varname_list.index('psi') # iu = self.varname_list.index('u') # iv = self.varname_list.index('v') iw = self.varname_list.index(self.whosetspsi) fo.cornertocell(x[ip], self.work) meansource = fo.computenoslipsourceterm(self.msknoslip, x[ip], self.work, self.dx, self.dy, self.nh) # K = self.dx*self.dy * 0.25 # self.work2[:, :] = self.work[:, :] # for kt in range(2): # fo.add_diffusion(self.msk, self.work, self.dx, # self.nh, K, self.work2) # self.fill_halo(self.work2) # fo.add_diffusion(self.msk, self.work2, self.dx, # self.nh, K, self.work) # self.fill_halo(self.work) # # self.work = self.work/(self.dx**2)*self.mskbc source[:, :] = self.work # this step is SUPER important to ensure GLOBAL vorticity conservation meansource = self.domain_integration(source) / self.bcarea source -= meansource * self.mskbc if self.enforce_momentum: xr = self.xr0 yr = self.yr0 # this step ensures the zero momentum px = fd.computedotprod(self.msk, source, xr, self.nh) py = fd.computedotprod(self.msk, source, yr, self.nh) cst = self.mpitools.local_to_global([(px, 'sum'), (py, 'sum')]) px, py = cst[0] / self.x2bc, cst[1] / self.y2bc source -= (px * xr + py * yr) * self.mskbc self.fill_halo(source) x[iw] -= source
def diagnostics(self, var, t): """ should provide at least 'maxspeed' (for cfl determination) """ self.timers.tic('diag') u = var.get('u') v = var.get('v') trac = var.get('vorticity') psi = var.get('psi') source = self.var.get('source') xr = self.xr yr = self.yr ke, maxu = fd.computekemaxu(self.msk, u, v, self.nh) # ke = fd.computekewithpsi(self.msk, trac, psi, self.nh) z, z2 = fd.computesumandnorm(self.msk, trac, self.nh) px = fd.computedotprod(self.msk, trac, xr, self.nh) py = fd.computedotprod(self.msk, trac, yr, self.nh) angmom = fd.computesum(self.msk, psi, self.nh) sce = fd.computedotprod(self.msk, trac, source, self.nh) cst = self.mpitools.local_to_global([(maxu, 'max'), (ke, 'sum'), (z, 'sum'), (z2, 'sum'), (px, 'sum'), (py, 'sum'), (angmom, 'sum'), (sce, 'sum')]) self.diags['maxspeed'] = cst[0] self.diags['ke'] = cst[1] / self.area self.diags['vorticity'] = cst[2] / self.area self.diags['enstrophy'] = 0.5 * cst[3] / self.area self.diags['px'] = cst[4] / self.area self.diags['py'] = cst[5] / self.area self.diags['angmom'] = cst[6] / self.area self.diags['source'] = cst[7] / self.area self.timers.toc('diag')