<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import os <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> import compare <EOL> import multigrid . MG as MG <EOL> import mesh . patch as patch <EOL> from util import msg <EOL> def true ( x , y ) : <EOL> return ( x ** <NUM_LIT:2> - x ** <NUM_LIT:4> ) * ( y ** <NUM_LIT:4> - y ** <NUM_LIT:2> ) <EOL> def f ( x , y ) : <EOL> return - <NUM_LIT> * ( ( <NUM_LIT:1.0> - <NUM_LIT> * x ** <NUM_LIT:2> ) * y ** <NUM_LIT:2> * ( <NUM_LIT:1.0> - y ** <NUM_LIT:2> ) + ( <NUM_LIT:1.0> - <NUM_LIT> * y ** <NUM_LIT:2> ) * x ** <NUM_LIT:2> * ( <NUM_LIT:1.0> - x ** <NUM_LIT:2> ) ) <EOL> def test_poisson_dirichlet ( N , store_bench = False , comp_bench = False , <EOL> make_plot = False , verbose = <NUM_LIT:1> ) : <EOL> nx = N <EOL> ny = nx <EOL> a = MG . CellCenterMG2d ( nx , ny , <EOL> xl_BC_type = "<STR_LIT>" , yl_BC_type = "<STR_LIT>" , <EOL> xr_BC_type = "<STR_LIT>" , yr_BC_type = "<STR_LIT>" , <EOL> verbose = verbose ) <EOL> a . init_zeros ( ) <EOL> rhs = f ( a . x2d , a . y2d ) <EOL> a . init_RHS ( rhs ) <EOL> a . solve ( rtol = <NUM_LIT> ) <EOL> v = a . get_solution ( ) <EOL> b = true ( a . x2d , a . y2d ) <EOL> e = v - b <EOL> print ( "<STR_LIT>" % ( e . norm ( ) , a . relative_error , a . num_cycles ) ) <EOL> if make_plot : <EOL> plt . figure ( num = <NUM_LIT:1> , figsize = ( <NUM_LIT> , <NUM_LIT> ) , dpi = <NUM_LIT:100> , facecolor = '<STR_LIT:w>' ) <EOL> plt . imshow ( np . transpose ( v [ a . ilo : a . ihi + <NUM_LIT:1> , a . jlo : a . jhi + <NUM_LIT:1> ] ) , <EOL> interpolation = "<STR_LIT>" , origin = "<STR_LIT>" , <EOL> extent = [ a . xmin , a . xmax , a . ymin , a . ymax ] ) <EOL> plt . xlabel ( "<STR_LIT:x>" ) <EOL> plt . ylabel ( "<STR_LIT:y>" ) <EOL> plt . savefig ( "<STR_LIT>" ) <EOL> bench = "<STR_LIT>" <EOL> bench_dir = os . environ [ "<STR_LIT>" ] + "<STR_LIT>" <EOL> my_data = a . get_solution_object ( ) <EOL> if store_bench : <EOL> my_data . write ( "<STR_LIT>" . format ( bench_dir , bench ) ) <EOL> if comp_bench : <EOL> compare_file = "<STR_LIT>" . format ( bench_dir , bench ) <EOL> msg . warning ( "<STR_LIT>" % ( compare_file ) ) <EOL> bench_grid , bench_data = patch . read ( compare_file ) <EOL> result = compare . compare ( my_data . grid , my_data , bench_grid , bench_data ) <EOL> if result == <NUM_LIT:0> : <EOL> msg . success ( "<STR_LIT>" ) <EOL> else : <EOL> msg . warning ( "<STR_LIT>" + compare . errors [ result ] + "<STR_LIT:\n>" ) <EOL> return result <EOL> return None <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_poisson_dirichlet ( <NUM_LIT> , comp_bench = True ) </s>
