[docs]classEdgeCoeffs:""" a simple container class to hold edge-centered coefficients and restrict them to coarse levels """def__init__(self,g,eta,empty=False):self.grid=gifnotempty:eta_x=g.scratch_array()eta_y=g.scratch_array()# the eta's are defined on the interfaces, so# eta_x[i,j] will be eta_{i-1/2,j} and# eta_y[i,j] will be eta_{i,j-1/2}b=(0,1)eta_x.v(buf=b)[:,:]=0.5*(eta.ip(-1,buf=b)+eta.v(buf=b))eta_y.v(buf=b)[:,:]=0.5*(eta.jp(-1,buf=b)+eta.v(buf=b))eta_x/=g.dx**2eta_y/=g.dy**2self.x=eta_xself.y=eta_y
[docs]defrestrict(self):""" restrict the edge values to a coarser grid. Return a new EdgeCoeffs object """cg=self.grid.coarse_like(2)c_edge_coeffs=EdgeCoeffs(cg,None,empty=True)c_eta_x=cg.scratch_array()c_eta_y=cg.scratch_array()fg=self.gridb=(0,1,0,0)c_eta_x.v(buf=b)[:,:]=0.5*(self.x.v(buf=b,s=2)+self.x.jp(1,buf=b,s=2))b=(0,0,0,1)c_eta_y.v(buf=b)[:,:]=0.5*(self.y.v(buf=b,s=2)+self.y.ip(1,buf=b,s=2))# redo the normalizationc_edge_coeffs.x=c_eta_x*fg.dx**2/cg.dx**2c_edge_coeffs.y=c_eta_y*fg.dy**2/cg.dy**2returnc_edge_coeffs