def __call__(self, x): self.n += 1 if self.n == 1 or self.n % 10 == 0: resnorm1 = norm(self.pde.matvec(x,0)-self.rhs) resnorm = norm(self.pde.matvec(x, 1)) # Compute Gradient grad = channel.uavgGrad(self.pde.n,self.pde.nb,self.T,self.Jbar,self.pde.zeta,profile=False) print('iter ', self.n, resnorm, resnorm1, grad) self.hist.append([self.n, resnorm, grad]) sys.stdout.flush()
def __call__(self, x): self.n += 1 if self.n == 1 or self.n % 10 == 0: mpi_rank = mpi_comm.Get_rank() mpi_size = mpi_comm.Get_size() resnorm = par_norm(self.pde.matvec(x, 1)) nb = self.pde.nb.copy() if mpi_rank < (mpi_size - 1): nb[-1] = nb[-1] - 1 # Compute Gradient grad = channel.uavgGrad(self.pde.n,nb,self.T,self.Jbar,self.pde.zeta,profile=False) grad = mpi_comm.allreduce(grad) if mpi_rank == 0: print 'iter ', self.n, resnorm, grad self.hist.append([self.n, resnorm, grad]) sys.stdout.flush()
# v and w plots vxhist = [] for i in range(0,n_steps): vx = (channel.Ivel(i,project=True).mean(2)).mean(0) vxhist.append(vx) t = channel.dt * arange(n_steps) y,w = channel.quad() figure() contourf(y, t, vxhist, 100); colorbar() axis([-1.0, 1.0, t[0], t[-1]]) # gradient plots uxavg = channel.velAvg(0,n_steps,T,profile=True) grad = channel.uavgGrad(n_chunk,chunk_bounds,T,uxavg,pde.zeta,profile=True) figure() mag = 1 #plot(uz2bar_avg,y,uz2bar_avg + mag*grad,y,uz2bar_avg - mag*grad,y) plot(grad,y) show() ''' import sensitivities as sens dirc = 0 y,w = channel.quad() # gradient plots ux2bar_avg = sens.vel2Avg(dirc,0,n_steps,T) gradu2 = sens.u2BarGrad(dirc,n_chunk,chunk_bounds,T,ux2bar_avg,pde.zeta) uxbar_avg = sens.velAvg(dirc,0,n_steps,T)