<s> import numpy as np <EOL> import mesh . patch as patch <EOL> import sys <EOL> import matplotlib . pyplot as plt <EOL> usage = """<STR_LIT>""" <EOL> def abort ( string ) : <EOL> print string <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> if not len ( sys . argv ) == <NUM_LIT:2> : <EOL> print usage <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> try : file1 = sys . argv [ <NUM_LIT:1> ] <EOL> except : <EOL> print usage <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> myg , myd = patch . read ( file1 ) <EOL> dens = myd . get_var ( "<STR_LIT>" ) <EOL> xmom = myd . get_var ( "<STR_LIT>" ) <EOL> ymom = myd . get_var ( "<STR_LIT>" ) <EOL> ener = myd . get_var ( "<STR_LIT>" ) <EOL> rho = dens [ myg . ilo : myg . ihi + <NUM_LIT:1> , myg . jlo : myg . jhi + <NUM_LIT:1> ] <EOL> u = np . sqrt ( xmom [ myg . ilo : myg . ihi + <NUM_LIT:1> , myg . jlo : myg . jhi + <NUM_LIT:1> ] ** <NUM_LIT:2> + <EOL> ymom [ myg . ilo : myg . ihi + <NUM_LIT:1> , myg . jlo : myg . jhi + <NUM_LIT:1> ] ** <NUM_LIT:2> ) / rho <EOL> e = ( ener [ myg . ilo : myg . ihi + <NUM_LIT:1> , myg . jlo : myg . jhi + <NUM_LIT:1> ] - <NUM_LIT:0.5> * rho * u * u ) / rho <EOL> gamma = myd . get_aux ( "<STR_LIT>" ) <EOL> p = rho * e * ( gamma - <NUM_LIT:1.0> ) <EOL> exact = np . loadtxt ( "<STR_LIT>" ) <EOL> x_exact = exact [ : , <NUM_LIT:1> ] <EOL> rho_exact = exact [ : , <NUM_LIT:2> ] <EOL> u_exact = exact [ : , <NUM_LIT:5> ] <EOL> p_exact = exact [ : , <NUM_LIT:4> ] <EOL> rmin = <NUM_LIT:0> <EOL> rmax = np . sqrt ( myg . xmax ** <NUM_LIT:2> + myg . ymax ** <NUM_LIT:2> ) <EOL> nbins = np . int ( np . sqrt ( myg . nx ** <NUM_LIT:2> + myg . ny ** <NUM_LIT:2> ) ) <EOL> bins = np . linspace ( rmin , rmax , nbins + <NUM_LIT:1> ) <EOL> bin_centers = <NUM_LIT:0.5> * ( bins [ <NUM_LIT:1> : ] + bins [ : - <NUM_LIT:1> ] ) <EOL> xcenter = <NUM_LIT:0.5> * ( myg . xmin + myg . xmax ) <EOL> ycenter = <NUM_LIT:0.5> * ( myg . ymin + myg . ymax ) <EOL> r = np . sqrt ( ( myg . x2d [ myg . ilo : myg . ihi + <NUM_LIT:1> , myg . jlo : myg . jhi + <NUM_LIT:1> ] - xcenter ) ** <NUM_LIT:2> + <EOL> ( myg . y2d [ myg . ilo : myg . ihi + <NUM_LIT:1> , myg . jlo : myg . jhi + <NUM_LIT:1> ] - ycenter ) ** <NUM_LIT:2> ) <EOL> whichbin = np . digitize ( r . flat , bins ) <EOL> ncount = np . bincount ( whichbin ) <EOL> rho_bin = np . zeros ( len ( ncount ) - <NUM_LIT:1> , dtype = np . float64 ) <EOL> u_bin = np . zeros ( len ( ncount ) - <NUM_LIT:1> , dtype = np . float64 ) <EOL> p_bin = np . zeros ( len ( ncount ) - <NUM_LIT:1> , dtype = np . float64 ) <EOL> for n in range ( len ( ncount ) ) : <EOL> rho_bin [ n - <NUM_LIT:1> ] = np . sum ( rho . flat [ whichbin == n ] ) / np . sum ( ncount [ n ] ) <EOL> u_bin [ n - <NUM_LIT:1> ] = np . sum ( u . flat [ whichbin == n ] ) / np . sum ( ncount [ n ] ) <EOL> p_bin [ n - <NUM_LIT:1> ] = np . sum ( p . flat [ whichbin == n ] ) / np . sum ( ncount [ n ] ) <EOL> bin_centers = bin_centers [ <NUM_LIT:0> : len ( ncount ) - <NUM_LIT:1> ] <EOL> fig , axes = plt . subplots ( nrows = <NUM_LIT:3> , ncols = <NUM_LIT:1> , num = <NUM_LIT:1> ) <EOL> plt . rc ( "<STR_LIT>" , size = <NUM_LIT:10> ) <EOL> ax = axes . flat [ <NUM_LIT:0> ] <EOL> ax . plot ( x_exact , rho_exact ) <EOL> ax . scatter ( bin_centers , rho_bin , marker = "<STR_LIT:x>" , s = <NUM_LIT:7> , color = "<STR_LIT:r>" ) <EOL> ax . set_ylabel ( r"<STR_LIT>" ) <EOL> ax . set_xlim ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> ax = axes . flat [ <NUM_LIT:1> ] <EOL> ax . plot ( x_exact , u_exact ) <EOL> ax . scatter ( bin_centers , u_bin , marker = "<STR_LIT:x>" , s = <NUM_LIT:7> , color = "<STR_LIT:r>" ) <EOL> ax . set_ylabel ( r"<STR_LIT>" ) <EOL> ax . set_xlim ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> ax = axes . flat [ <NUM_LIT:2> ] <EOL> ax . plot ( x_exact , p_exact ) <EOL> ax . scatter ( bin_centers , p_bin , marker = "<STR_LIT:x>" , s = <NUM_LIT:7> , color = "<STR_LIT:r>" ) <EOL> ax . set_ylabel ( r"<STR_LIT>" ) <EOL> ax . set_xlim ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> ax . set_xlabel ( r"<STR_LIT:r>" ) <EOL> plt . subplots_adjust ( hspace = <NUM_LIT> ) <EOL> fig . set_size_inches ( <NUM_LIT> , <NUM_LIT> ) <EOL> plt . savefig ( "<STR_LIT>" , bbox_inches = "<STR_LIT>" ) </s>
