#NEWLINE# def smooth( self , level , nsmooth ) : #NEWLINE# #INDENT# '\n        Use red-black Gauss-Seidel iterations to smooth the solution\n        at a given level.  This is used at each stage of the V-cycle\n        (up and down) in the MG solution, but it can also be called\n        directly to solve the elliptic problem (although it will take\n        many more iterations).\n\n        Parameters\n        ----------\n        level : int\n            The level in the MG hierarchy to smooth the solution\n        nsmooth : int\n            The number of r-b Gauss-Seidel smoothing iterations to perform\n\n        ' #NEWLINE# v = self . grids [ level ] . get_var ( 'v' ) #NEWLINE# f = self . grids [ level ] . get_var ( 'f' ) #NEWLINE# myg = self . grids [ level ] . grid #NEWLINE# dx = myg . dx #NEWLINE# dy = myg . dy #NEWLINE# self . grids [ level ] . fill_BC ( 'v' ) #NEWLINE# alpha = self . grids [ level ] . get_var ( 'alpha' ) #NEWLINE# gamma_x = ( ( 0.5 * self . grids [ level ] . get_var ( 'gamma_x' ) ) / dx ) #NEWLINE# gamma_y = ( ( 0.5 * self . grids [ level ] . get_var ( 'gamma_y' ) ) / dy ) #NEWLINE# beta_x = self . beta_edge [ level ] . x #NEWLINE# beta_y = self . beta_edge [ level ] . y #NEWLINE# for i in range ( nsmooth ) : #NEWLINE# #INDENT# for ( n , ( ix , iy ) ) in enumerate ( [ ( 0 , 0 ) , ( 1 , 1 ) , ( 1 , 0 ) , ( 0 , 1 ) ] ) : #NEWLINE# #INDENT# denom = ( ( ( ( alpha . ip_jp ( ix , iy , s = 2 ) - beta_x . ip_jp ( ( 1 + ix ) , iy , s = 2 ) ) - beta_x . ip_jp ( ix , iy , s = 2 ) ) - beta_y . ip_jp ( ix , ( 1 + iy ) , s = 2 ) ) - beta_y . ip_jp ( ix , iy , s = 2 ) ) #NEWLINE# v . ip_jp ( ix , iy , s = 2 ) [ : , : ] = ( ( ( ( ( f . ip_jp ( ix , iy , s = 2 ) - ( ( beta_x . ip_jp ( ( 1 + ix ) , iy , s = 2 ) + gamma_x . ip_jp ( ix , iy , s = 2 ) ) * v . ip_jp ( ( 1 + ix ) , iy , s = 2 ) ) ) - ( ( beta_x . ip_jp ( ix , iy , s = 2 ) - gamma_x . ip_jp ( ix , iy , s = 2 ) ) * v . ip_jp ( ( ( - 1 ) + ix ) , iy , s = 2 ) ) ) - ( ( beta_y . ip_jp ( ix , ( 1 + iy ) , s = 2 ) + gamma_y . ip_jp ( ix , iy , s = 2 ) ) * v . ip_jp ( ix , ( 1 + iy ) , s = 2 ) ) ) - ( ( beta_y . ip_jp ( ix , iy , s = 2 ) - gamma_y . ip_jp ( ix , iy , s = 2 ) ) * v . ip_jp ( ix , ( ( - 1 ) + iy ) , s = 2 ) ) ) / denom ) #NEWLINE# if ( ( n == 1 ) or ( n == 3 ) ) : #NEWLINE# #INDENT# self . grids [ level ] . fill_BC ( 'v' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( self . vis == 1 ) : #NEWLINE# #INDENT# plt . clf ( ) #NEWLINE# plt . subplot ( 221 ) #NEWLINE# self . _draw_solution ( ) #NEWLINE# plt . subplot ( 222 ) #NEWLINE# self . _draw_V ( ) #NEWLINE# plt . subplot ( 223 ) #NEWLINE# self . _draw_main_solution ( ) #NEWLINE# plt . subplot ( 224 ) #NEWLINE# self . _draw_main_error ( ) #NEWLINE# plt . suptitle ( self . vis_title , fontsize = 18 ) #NEWLINE# plt . draw ( ) #NEWLINE# plt . savefig ( ( 'mg_%4.4d.png' % self . frame ) ) #NEWLINE# self . frame += 1