def dump_step(self,status): """ Overwrite standard dump per step Args: status: status object per step """ super(particles_output,self).dump_step(status) # some abbreviations L = self.level u = L.uend R = np.linalg.norm(u.pos.values) H = 1/2*np.dot(u.vel.values,u.vel.values)+0.02/R stats.add_to_stats(step=status.step, time=status.time, type='energy', value=H) oldcol = self.sframe # self.sframe = self.ax.scatter(L.uend.pos.values[0],L.uend.pos.values[1],L.uend.pos.values[2]) self.sframe = self.ax.scatter(L.uend.pos.values[0],L.uend.pos.values[1]) # Remove old line collection before drawing if oldcol is not None: self.ax.collections.remove(oldcol) plt.pause(0.00001) return None
def dump_step(self, status): """ Overwrite standard dump per step Args: status: status object per step """ super(particles_output, self).dump_step(status) # some abbreviations L = self.level u = L.uend R = np.linalg.norm(u.pos.values) H = 1 / 2 * np.dot(u.vel.values, u.vel.values) + 0.02 / R stats.add_to_stats(step=status.step, time=status.time, type='energy', value=H) oldcol = self.sframe # self.sframe = self.ax.scatter(L.uend.pos.values[0],L.uend.pos.values[1],L.uend.pos.values[2]) self.sframe = self.ax.scatter(L.uend.pos.values[0], L.uend.pos.values[1]) # Remove old line collection before drawing if oldcol is not None: self.ax.collections.remove(oldcol) plt.pause(0.00001) return None
def dump_iteration(self,status): """ Default routine called after each iteration """ L = self.level stats.add_to_stats(step=status.step, time=status.time, iter=status.iter, type='residual', value=L.status.residual) pass
def dump_iteration(self, status): """ Default routine called after each iteration """ L = self.level stats.add_to_stats(step=status.step, time=status.time, iter=status.iter, type='residual', value=L.status.residual) pass
def dump_sweep(self,status): """ Default routine called after each sweep """ L = self.level logger = logging.getLogger('root') logger.info('Process %2i on time %8.6f at stage %15s: Level: %s -- Iteration: %2i -- Residual: %12.8e', status.slot,status.time,status.stage,L.id,status.iter,L.status.residual) stats.add_to_stats(step=status.step, time=status.time, level=L.id, iter=status.iter, type='residual', value=L.status.residual) pass
def dump_step(self,status): """ Overwrite standard dump per step Args: status: status object per step """ super(particles_output,self).dump_step(status) # some abbreviations L = self.level part = L.uend N = L.prob.nparts w = np.array([1,1,-2]) # compute (slowly..) the potential at uend fpot = np.zeros(N) for i in range(N): # inner loop, omit ith particle for j in range(0,i): dist2 = np.linalg.norm(part.pos.values[3*i:3*i+3]-part.pos.values[3*j:3*j+3],2)**2+L.prob.sig**2 fpot[i] += part.q[j]/np.sqrt(dist2) for j in range(i+1,N): dist2 = np.linalg.norm(part.pos.values[3*i:3*i+3]-part.pos.values[3*j:3*j+3],2)**2+L.prob.sig**2 fpot[i] += part.q[j]/np.sqrt(dist2) fpot[i] -= L.prob.omega_E**2 * part.m[i]/part.q[i]/2.0 \ * np.dot(w,part.pos.values[3*i:3*i+3]*part.pos.values[3*i:3*i+3]) # add up kinetic and potntial contributions to total energy epot = 0 ekin = 0 for n in range(N): epot += part.q[n]*fpot[n] ekin += part.m[n]/2.0*np.dot(part.vel.values[3*n:3*n+3],part.vel.values[3*n:3*n+3]) print('Energy (pot/kin/tot) at step %i: %12.4f / %12.4f / %12.4f' %(status.step,epot,ekin,epot+ekin)) stats.add_to_stats(step=status.step, time=status.time, type='etot', value=epot+ekin) # print('plotting particles...') # oldcol = self.sframe # # self.sframe = self.ax.scatter(L.uend.pos.values[0],L.uend.pos.values[1],L.uend.pos.values[2]) self.sframe = self.ax.scatter(L.uend.pos.values[0::3],L.uend.pos.values[1::3],L.uend.pos.values[2::3]) # # Remove old line collection before drawing # if oldcol is not None: # self.ax.collections.remove(oldcol) # plt.pause(0.001) return None
def dump_iteration(self,status): super(error_output,self).dump_iteration(status) L = self.level P = L.prob L.sweep.compute_end_point() uend = L.uend uex = P.u_exact(status.time+status.dt) err = np.linalg.norm(uex.values-uend.values,np.inf)/np.linalg.norm(uex.values,np.inf) # print('error at time %s, iteration %s: %s' %(status.time,status.iter,err)) stats.add_to_stats(step=status.step, time=status.time, iter=status.iter, type='error', value=err)
def dump_sweep(self, status): """ Default routine called after each sweep """ L = self.level logger = logging.getLogger('root') logger.info( 'Process %2i at stage %15s: Level: %s -- Iteration: %2i -- Residual: %12.8e', status.slot, status.stage, L.id, status.iter, L.status.residual) stats.add_to_stats(step=status.step, time=status.time, level=L.id, iter=status.iter, type='residual', value=L.status.residual) pass
def dump_pre(self, status): """ Overwrite standard dump at the beginning Args: status: status object per step """ super(particles_output, self).dump_pre(status) # some abbreviations L = self.level part = L.u[0] N = L.prob.nparts w = np.array([1, 1, -2]) # compute (slowly..) the potential at u0 fpot = np.zeros(N) for i in range(N): # inner loop, omit ith particle for j in range(0, i): dist2 = np.linalg.norm( part.pos.values[3 * i:3 * i + 3] - part.pos.values[3 * j:3 * j + 3], 2)**2 + L.prob.sig**2 fpot[i] += part.q[j] / np.sqrt(dist2) for j in range(i + 1, N): dist2 = np.linalg.norm( part.pos.values[3 * i:3 * i + 3] - part.pos.values[3 * j:3 * j + 3], 2)**2 + L.prob.sig**2 fpot[i] += part.q[j] / np.sqrt(dist2) fpot[i] -= L.prob.omega_E**2 * part.m[i]/part.q[i]/2.0 \ * np.dot(w,part.pos.values[3*i:3*i+3]*part.pos.values[3*i:3*i+3]) # add up kinetic and potntial contributions to total energy epot = 0 ekin = 0 for n in range(N): epot += part.q[n] * fpot[n] ekin += part.m[n] / 2.0 * np.dot(part.vel.values[3 * n:3 * n + 3], part.vel.values[3 * n:3 * n + 3]) print('Energy (pot/kin/tot): %12.4f / %12.4f / %12.4f' % (epot, ekin, epot + ekin)) stats.add_to_stats(type='etot', value=epot + ekin)
def dump_pre(self,status): """ Overwrite standard dump at the beginning Args: status: status object per step """ super(particles_output,self).dump_pre(status) # some abbreviations L = self.level part = L.u[0] N = L.prob.nparts w = np.array([1,1,-2]) # compute (slowly..) the potential at u0 fpot = np.zeros(N) for i in range(N): # inner loop, omit ith particle for j in range(0,i): dist2 = np.linalg.norm(part.pos.values[3*i:3*i+3]-part.pos.values[3*j:3*j+3],2)**2+L.prob.sig**2 fpot[i] += part.q[j]/np.sqrt(dist2) for j in range(i+1,N): dist2 = np.linalg.norm(part.pos.values[3*i:3*i+3]-part.pos.values[3*j:3*j+3],2)**2+L.prob.sig**2 fpot[i] += part.q[j]/np.sqrt(dist2) fpot[i] -= L.prob.omega_E**2 * part.m[i]/part.q[i]/2.0 \ * np.dot(w,part.pos.values[3*i:3*i+3]*part.pos.values[3*i:3*i+3]) # add up kinetic and potntial contributions to total energy epot = 0 ekin = 0 for n in range(N): epot += part.q[n]*fpot[n] ekin += part.m[n]/2.0*np.dot(part.vel.values[3*n:3*n+3],part.vel.values[3*n:3*n+3]) print('Energy (pot/kin/tot): %12.4f / %12.4f / %12.4f' %(epot,ekin,epot+ekin)) stats.add_to_stats(type='etot', value=epot+ekin)
def dump_step(self,status): """ Default routine called after each step """ L = self.level stats.add_to_stats(step=status.step, time=status.time, type='timing_step', value=time.time()-self.t0) stats.add_to_stats(step=status.step, time=status.time, type='niter', value=status.iter) stats.add_to_stats(step=status.step, time=status.time, type='residual', value=L.status.residual) pass
def dump_step(self, status): """ Default routine called after each step """ L = self.level stats.add_to_stats(step=status.step, time=status.time, type='timing_step', value=time.time() - self.t0) stats.add_to_stats(step=status.step, time=status.time, type='niter', value=status.iter) stats.add_to_stats(step=status.step, time=status.time, type='residual', value=L.status.residual) pass
def dump_step(self, status): """ Overwrite standard dump per step Args: status: status object per step """ super(particles_output, self).dump_step(status) # some abbreviations L = self.level part = L.uend N = L.prob.nparts w = np.array([1, 1, -2]) # compute (slowly..) the potential at uend fpot = np.zeros(N) for i in range(N): # inner loop, omit ith particle for j in range(0, i): dist2 = np.linalg.norm( part.pos.values[3 * i:3 * i + 3] - part.pos.values[3 * j:3 * j + 3], 2)**2 + L.prob.sig**2 fpot[i] += part.q[j] / np.sqrt(dist2) for j in range(i + 1, N): dist2 = np.linalg.norm( part.pos.values[3 * i:3 * i + 3] - part.pos.values[3 * j:3 * j + 3], 2)**2 + L.prob.sig**2 fpot[i] += part.q[j] / np.sqrt(dist2) fpot[i] -= L.prob.omega_E**2 * part.m[i]/part.q[i]/2.0 \ * np.dot(w,part.pos.values[3*i:3*i+3]*part.pos.values[3*i:3*i+3]) # add up kinetic and potntial contributions to total energy epot = 0 ekin = 0 for n in range(N): epot += part.q[n] * fpot[n] ekin += part.m[n] / 2.0 * np.dot(part.vel.values[3 * n:3 * n + 3], part.vel.values[3 * n:3 * n + 3]) print('Energy (pot/kin/tot) at step %i: %12.4f / %12.4f / %12.4f' % (status.step, epot, ekin, epot + ekin)) stats.add_to_stats(step=status.step, time=status.time, type='etot', value=epot + ekin) # print('plotting particles...') # oldcol = self.sframe # # self.sframe = self.ax.scatter(L.uend.pos.values[0],L.uend.pos.values[1],L.uend.pos.values[2]) self.sframe = self.ax.scatter(L.uend.pos.values[0::3], L.uend.pos.values[1::3], L.uend.pos.values[2::3]) # # Remove old line collection before drawing # if oldcol is not None: # self.ax.collections.remove(oldcol) # plt.pause(0.001) return None