Skip to content
Snippets Groups Projects
Commit 279f65f6 authored by Oliver Sander's avatar Oliver Sander Committed by sander@PCPOOL.MI.FU-BERLIN.DE
Browse files

A tool to compute solver convergence rates from a convergence history...

A tool to compute solver convergence rates from a convergence history available as disk files.  Not really usable yet.

[[Imported from SVN: r1852]]
parent a4eff011
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python
import sys
import getopt
from math import sqrt
from numpy import array, matrix
from scipy import sparse
from scipy.sparse import coo_matrix
####################################################
# Print program usage
####################################################
def usage():
print 'Hallo Welt!'
####################################################
# Read a matrix
####################################################
def read_matrix(filename):
inputmatrix = open(filename)
allentries = inputmatrix.read()
entries = allentries.split()
rows = array(entries[::3],int)
cols = array(entries[1::3],int)
values = array(entries[2::3])
for i in range(0,len(rows)):
rows[i] -= 1
cols[i] = cols[i] - 1
print 'Reading a', max(rows)+1, 'x', max(cols)+1, 'matrix'
return coo_matrix((values,(rows,cols)), dims=(max(rows)+1,max(cols)+1))
####################################################
# Read a vector
####################################################
def read_vector(filename):
inputvector = open(filename)
allentries = inputvector.read()
entries = allentries.split()
#print 'Reading a vector of length', len(entries)
return matrix(entries[:],float)
####################################################
# Main programm
####################################################
try:
opts, args = getopt.getopt(sys.argv[1:], "hm:s:i:f:t:",
["help", "matrix=", "solution:", "iterates=", "from=", "to="])
except getopt.GetoptError:
usage()
sys.exit(2)
fro = 0
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
elif opt in ("-m", "--matrix"):
matrix_filename = arg
elif opt in ("-s", "--solution"):
solution_filename = arg
elif opt in ("-i", "--iterates"):
iterates_filename = arg
elif opt in ("-f", "--from"):
fro = int(arg)
elif opt in ("-t", "--to"):
to = int(arg) + 1
print 'Matrix filename: ' + matrix_filename
print 'Solution filename: ' + solution_filename
# The matrix for the energy norm
A = read_matrix(matrix_filename)
# The vector taken as the 'exact' solution
solution = read_vector(solution_filename)
# Main loop
for i in range(fro,to):
current_iterate = read_vector(iterates_filename + str(i))
current_iterate -= solution
#print current_iterate
energy_norm = current_iterate*A*current_iterate.transpose()
print 'Iteration:', i, 'error', sqrt(energy_norm)
#print energy_norm(A,b)
#A.todense()
#print A.todense()
#print energy_norm(A,b)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment