<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> import openmg <EOL> from scipy import sparse <EOL> from time import time <EOL> from sys import argv <EOL> def main ( ) : <EOL> args = [ int ( i ) for i in argv [ <NUM_LIT:1> : ] ] <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> args = [ <NUM_LIT:200> ] <EOL> print "<STR_LIT>" <EOL> for N in args : <EOL> explainedDemo ( N ) <EOL> print <EOL> explainedDemo ( <NUM_LIT:64> , verbose = False , dense = True ) <EOL> def simpleDemo ( verbose = False ) : <EOL> """<STR_LIT>""" <EOL> N = <NUM_LIT:100> <EOL> u_true = np . array ( [ np . sin ( x / <NUM_LIT> ) for x in np . linspace ( <NUM_LIT:0> , <NUM_LIT:20> , N ) ] ) <EOL> A = openmg . operators . poisson ( N , sparse = True ) <EOL> b = openmg . tools . flexibleMmult ( A , u_true ) <EOL> params = { '<STR_LIT>' : ( N , ) , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : verbose , '<STR_LIT>' : True , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : True } <EOL> u_mg , infoDict = openmg . mgSolve ( A , b , params ) <EOL> if verbose : <EOL> print "<STR_LIT>" <EOL> print infoDict <EOL> return u_mg <EOL> def explainedDemo ( N , verbose = True , dense = False ) : <EOL> threshold = <NUM_LIT> <EOL> u_true = np . array ( [ np . sin ( x / <NUM_LIT> ) for x in range ( N ) ] ) <EOL> A = openmg . operators . poisson ( N , sparse = True ) <EOL> b = openmg . tools . flexibleMmult ( A , u_true ) <EOL> params = { '<STR_LIT>' : False , '<STR_LIT>' : threshold } <EOL> start = time ( ) <EOL> soln = openmg . solvers . coarseSolve ( A , b ) <EOL> elapsed = time ( ) - start <EOL> if verbose : print N , "<STR_LIT>" , np . linalg . norm ( openmg . tools . getresidual ( b , A , soln , N ) ) , elapsed <EOL> if N <= <NUM_LIT:200> : <EOL> start = time ( ) <EOL> soln = openmg . smoothToThreshold ( A , b , np . zeros ( ( N , <NUM_LIT:1> ) ) , <EOL> params [ '<STR_LIT>' ] , <EOL> verbose = params [ '<STR_LIT>' ] ) <EOL> elapsed = time ( ) - start <EOL> if verbose : print N , "<STR_LIT>" , np . linalg . norm ( openmg . tools . getresidual ( b , A , soln , N ) ) , elapsed <EOL> params = { '<STR_LIT>' : ( N , ) , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : False , '<STR_LIT>' : dense , <EOL> '<STR_LIT>' : threshold , '<STR_LIT>' : True , '<STR_LIT>' : <NUM_LIT:30> } <EOL> start = time ( ) <EOL> soln , info_dict = openmg . mgSolve ( A , b , params ) <EOL> cycles = info_dict [ '<STR_LIT>' ] <EOL> elapsed = time ( ) - start <EOL> if verbose : print N , "<STR_LIT>" % params [ '<STR_LIT>' ] , np . linalg . norm ( openmg . tools . getresidual ( b , A , soln , N ) ) , elapsed , cycles <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> simpleDemo ( ) <EOL> print <EOL> main ( ) </s>
