def wathen_test09(): #*****************************************************************************80 # ## WATHEN_TEST09 uses SPY to display the sparsity of the Wathen matrix. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 31 August 2014 # # Author: # # John Burkardt # from matplotlib.pyplot import figure from matplotlib.pyplot import show from matplotlib.pyplot import savefig from wathen_ge import wathen_ge from wathen_order import wathen_order print '' print 'WATHEN_TEST09' print ' Display the sparsity of the Wathen matrix.' fig = figure() nx = 1 ny = 1 n = wathen_order(nx, ny) seed = 123456789 a, seed = wathen_ge(nx, ny, n, seed) ax1 = fig.add_subplot(231) ax1.spy(a, markersize=4) nx = 2 ny = 2 n = wathen_order(nx, ny) seed = 123456789 a, seed = wathen_ge(nx, ny, n, seed) ax2 = fig.add_subplot(232) ax2.spy(a, markersize=4) nx = 3 ny = 3 n = wathen_order(nx, ny) seed = 123456789 a, seed = wathen_ge(nx, ny, n, seed) ax3 = fig.add_subplot(233) ax3.spy(a, markersize=4) nx = 4 ny = 4 n = wathen_order(nx, ny) seed = 123456789 a, seed = wathen_ge(nx, ny, n, seed) ax4 = fig.add_subplot(234) ax4.spy(a, markersize=4) nx = 5 ny = 5 n = wathen_order(nx, ny) seed = 123456789 a, seed = wathen_ge(nx, ny, n, seed) ax5 = fig.add_subplot(235) ax5.spy(a, markersize=4) nx = 6 ny = 6 n = wathen_order(nx, ny) seed = 123456789 a, seed = wathen_ge(nx, ny, n, seed) ax6 = fig.add_subplot(236) ax6.spy(a, markersize=4) fig.suptitle('WATHEN Matrix Sparsity Pattern') show() filename = 'wathen_spy.png' fig.savefig(filename) print '' print ' Graphics file saved as "%s"' % (filename) return
def wathen_test06(): #*****************************************************************************80 # ## WATHEN_TEST06 assembles, factor and solves using WATHEN_GE + CG_GE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 31 August 2014 # # Author: # # John Burkardt # import numpy as np from cg_ge import cg_ge from numpy.linalg import norm from r8vec_uniform_01 import r8vec_uniform_01 from wathen_ge import wathen_ge from wathen_order import wathen_order print '' print 'WATHEN_TEST06' print ' Assemble, factor and solve a Wathen system' print ' defined by WATHEN_GE and CG_GE.' print '' nx = 2 ny = 2 print ' Elements in X direction NX = %d' % (nx) print ' Elements in Y direction NY = %d' % (ny) print ' Number of elements = %d' % (nx * ny) # # Compute the number of unknowns. # n = wathen_order(nx, ny) print ' Number of nodes N = %d' % (n) # # Set up a random solution X1. # seed = 123456789 x1, seed = r8vec_uniform_01(n, seed) # # Compute the matrix. # seed = 123456789 a, seed = wathen_ge(nx, ny, n, seed) # # Compute the corresponding right hand side B. # b = np.dot(a, x1) # # Solve the linear system. # x2 = np.ones(n) x2 = cg_ge(n, a, b, x2) # # Compute the maximum solution error. # e = norm(x1 - x2) print ' Maximum solution error is %g' % (e) return
def wathen_test03 ( ): #*****************************************************************************80 # ## WATHEN_TEST03 times WATHEN_GE assembly and solution. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 04 September 2014 # # Author: # # John Burkardt # import numpy as np import scipy.linalg as la import time from numpy.linalg import norm from r8vec_uniform_01 import r8vec_uniform_01 from wathen_ge import wathen_ge from wathen_order import wathen_order print '' print 'WATHEN_TEST03' print ' For various problem sizes,' print ' time the assembly and factorization of a Wathen system' print ' using the WATHEN_GE function.' print '' print ' NX Elements Nodes Storage Assembly ', print 'Factor Error' print '' nx = 1 ny = 1 for test in range ( 0, 6 ): # # Compute the number of unknowns. # n = wathen_order ( nx, ny ) storage_ge = n * n # # Set up a random solution X1. # seed = 123456789 x1, seed = r8vec_uniform_01 ( n, seed ) # # Compute the matrix. # seed = 123456789 t0 = time.clock ( ) a, seed = wathen_ge ( nx, ny, n, seed ) t1 = ( time.clock ( ) - t0 ) # # Compute the corresponding right hand side B. # b = np.dot ( a, x1 ) # # Solve the system. # t0 = time.clock ( ) x2 = la.solve ( a, b ) t2 = ( time.clock ( ) - t0 ) # # Compute the norm of the solution error. # e = norm ( x1 - x2 ) # # Report. # print ' %4d %4d %6d %8d %10.2e %10.2e %10.2e' % \ ( nx, nx * ny, n, storage_ge, t1, t2, e ) # # Ready for next iteration. # nx = nx * 2 ny = ny * 2 return
def wathen_test09 ( ): #*****************************************************************************80 # ## WATHEN_TEST09 uses SPY to display the sparsity of the Wathen matrix. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 31 August 2014 # # Author: # # John Burkardt # from matplotlib.pyplot import figure from matplotlib.pyplot import show from matplotlib.pyplot import savefig from wathen_ge import wathen_ge from wathen_order import wathen_order print '' print 'WATHEN_TEST09' print ' Display the sparsity of the Wathen matrix.' fig = figure ( ) nx = 1 ny = 1 n = wathen_order ( nx, ny ) seed = 123456789 a, seed = wathen_ge ( nx, ny, n, seed ) ax1 = fig.add_subplot ( 231 ) ax1.spy ( a, markersize = 4 ) nx = 2 ny = 2 n = wathen_order ( nx, ny ) seed = 123456789 a, seed = wathen_ge ( nx, ny, n, seed ) ax2 = fig.add_subplot ( 232 ) ax2.spy ( a, markersize = 4 ) nx = 3 ny = 3 n = wathen_order ( nx, ny ) seed = 123456789 a, seed = wathen_ge ( nx, ny, n, seed ) ax3 = fig.add_subplot ( 233 ) ax3.spy ( a, markersize = 4 ) nx = 4 ny = 4 n = wathen_order ( nx, ny ) seed = 123456789 a, seed = wathen_ge ( nx, ny, n, seed ) ax4 = fig.add_subplot ( 234 ) ax4.spy ( a, markersize = 4 ) nx = 5 ny = 5 n = wathen_order ( nx, ny ) seed = 123456789 a, seed = wathen_ge ( nx, ny, n, seed ) ax5 = fig.add_subplot ( 235 ) ax5.spy ( a, markersize = 4 ) nx = 6 ny = 6 n = wathen_order ( nx, ny ) seed = 123456789 a, seed = wathen_ge ( nx, ny, n, seed ) ax6 = fig.add_subplot ( 236 ) ax6.spy ( a, markersize = 4 ) fig.suptitle ( 'WATHEN Matrix Sparsity Pattern' ) show ( ) filename = 'wathen_spy.png' fig.savefig ( filename ) print '' print ' Graphics file saved as "%s"' % ( filename ) return
def wathen_test06 ( ): #*****************************************************************************80 # ## WATHEN_TEST06 assembles, factor and solves using WATHEN_GE + CG_GE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 31 August 2014 # # Author: # # John Burkardt # import numpy as np from cg_ge import cg_ge from numpy.linalg import norm from r8vec_uniform_01 import r8vec_uniform_01 from wathen_ge import wathen_ge from wathen_order import wathen_order print '' print 'WATHEN_TEST06' print ' Assemble, factor and solve a Wathen system' print ' defined by WATHEN_GE and CG_GE.' print '' nx = 2 ny = 2 print ' Elements in X direction NX = %d' % ( nx ) print ' Elements in Y direction NY = %d' % ( ny ) print ' Number of elements = %d' % ( nx * ny ) # # Compute the number of unknowns. # n = wathen_order ( nx, ny ) print ' Number of nodes N = %d' % ( n ) # # Set up a random solution X1. # seed = 123456789 x1, seed = r8vec_uniform_01 ( n, seed ) # # Compute the matrix. # seed = 123456789 a, seed = wathen_ge ( nx, ny, n, seed ) # # Compute the corresponding right hand side B. # b = np.dot ( a, x1 ) # # Solve the linear system. # x2 = np.ones ( n ) x2 = cg_ge ( n, a, b, x2 ) # # Compute the maximum solution error. # e = norm ( x1 - x2 ) print ' Maximum solution error is %g' % ( e ) return
def wathen_test03(): #*****************************************************************************80 # ## WATHEN_TEST03 times WATHEN_GE assembly and solution. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 04 September 2014 # # Author: # # John Burkardt # import numpy as np import scipy.linalg as la import time from numpy.linalg import norm from r8vec_uniform_01 import r8vec_uniform_01 from wathen_ge import wathen_ge from wathen_order import wathen_order print '' print 'WATHEN_TEST03' print ' For various problem sizes,' print ' time the assembly and factorization of a Wathen system' print ' using the WATHEN_GE function.' print '' print ' NX Elements Nodes Storage Assembly ', print 'Factor Error' print '' nx = 1 ny = 1 for test in range(0, 6): # # Compute the number of unknowns. # n = wathen_order(nx, ny) storage_ge = n * n # # Set up a random solution X1. # seed = 123456789 x1, seed = r8vec_uniform_01(n, seed) # # Compute the matrix. # seed = 123456789 t0 = time.clock() a, seed = wathen_ge(nx, ny, n, seed) t1 = (time.clock() - t0) # # Compute the corresponding right hand side B. # b = np.dot(a, x1) # # Solve the system. # t0 = time.clock() x2 = la.solve(a, b) t2 = (time.clock() - t0) # # Compute the norm of the solution error. # e = norm(x1 - x2) # # Report. # print ' %4d %4d %6d %8d %10.2e %10.2e %10.2e' % \ ( nx, nx * ny, n, storage_ge, t1, t2, e ) # # Ready for next iteration. # nx = nx * 2 ny = ny * 2 return