Coverage for /usr/share/miniconda3/envs/dolfin/lib/python3.8/site-packages/block/algebraic/trilinos/IFPACK.py: 0%
84 statements
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-20 13:03 +0000
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-20 13:03 +0000
1from __future__ import division
3from builtins import str
4from block.block_base import block_base
6class IFPACK(block_base):
8 errcode = {1 : "Generic Error (called method or function returned an error)",
9 2 : "Input data not valid (wrong parameter, out-of-bounds, wrong dimensions, matrix is not square,...)",
10 3 : "Data has not been correctly pre-processed",
11 4 : "Problem encountered during application of the algorithm (division by zero, out-of-bounds, ...)",
12 5 : "Memory allocation error",
13 22: "Matrix is numerically singular",
14 98: "Feature is not supported",
15 99: "Feature is not implemented yet (check Known Bugs and Future Developments, or submit a bug)"}
17 params = {}
19 def __init__(self, A, overlap=0, params={}):
20 from PyTrilinos.IFPACK import Factory
21 from dolfin import info
22 from time import time
24 self.A = A # Keep reference to avoid delete
26 T = time()
27 prectype = self.prectype
28 if overlap == 0:
29 prectype += ' stand-alone' # Skip the additive Schwarz step
31 self.prec = Factory().Create(prectype, A.down_cast().mat(), overlap)
32 if not self.prec:
33 raise RuntimeError("Unknown IFPACK preconditioner '%s'"%prectype)
35 paramlist = {'schwartz: combine mode' : 'Add'} # Slower than 'Zero', but symmetric
36 paramlist.update(self.params)
37 paramlist.update(params)
39 assert (0 == self.prec.SetParameters(paramlist))
40 assert (0 == self.prec.Initialize())
41 err = self.prec.Compute()
42 if err:
43 raise RuntimeError('Compute returned error %d: %s'%(err, self.errcode.get(-err)))
44 info('Constructed %s in %.2f s'%(self.__class__.__name__,time()-T))
46 def matvec(self, b):
47 from dolfin import GenericVector
48 if not isinstance(b, GenericVector):
49 return NotImplemented
50 x = self.A.create_vec(dim=1)
51 if len(x) != len(b):
52 raise RuntimeError(
53 'incompatible dimensions for AztecOO matvec, %d != %d'%(len(x),len(b)))
55 err = self.prec.ApplyInverse(b.down_cast().vec(), x.down_cast().vec())
56 if err:
57 raise RuntimeError('ApplyInverse returned error %d: %s'%(err, self.errcode.get(-err)))
58 return x
60 def down_cast(self):
61 return self.prec
63 def __str__(self):
64 return '<%s prec of %s>'%(self.__class__.__name__, str(self.A))
66# "point relaxation" : returns an instance of Ifpack_AdditiveSchwarz<Ifpack_PointRelaxation>
67# "block relaxation" : returns an instance of Ifpack_AdditiveSchwarz<Ifpack_BlockRelaxation>
68# "Amesos" : returns an instance of Ifpack_AdditiveSchwarz<Ifpack_Amesos>.
69# "IC" : returns an instance of Ifpack_AdditiveSchwarz<Ifpack_IC>.
70# "ICT" : returns an instance of Ifpack_AdditiveSchwarz<Ifpack_ICT>.
71# "ILU" : returns an instance of Ifpack_AdditiveSchwarz<Ifpack_ILU>.
72# "ILUT" : returns an instance of Ifpack_AdditiveSchwarz<Ifpack_ILUT>.
73# otherwise, Create() returns 0.
75class DD_Jacobi(IFPACK):
76 prectype = 'point relaxation'
77 params = {'relaxation: type' : 'Jacobi'}
78Jacobi = DD_Jacobi
80class DD_GaussSeidel(IFPACK):
81 prectype = 'point relaxation'
82 params = {'relaxation: type' : 'Gauss-Seidel'}
83GaussSeidel = DD_GaussSeidel
85class DD_SymmGaussSeidel(IFPACK):
86 prectype = 'point relaxation'
87 params = {'relaxation: type' : 'symmetric Gauss-Seidel'}
88SymmGaussSeidel = DD_SymmGaussSeidel
90class DD_BJacobi(IFPACK):
91 prectype = 'block relaxation'
92 params = {'relaxation: type' : 'Jacobi'}
93BJacobi = DD_BJacobi
95class DD_BGaussSeidel(IFPACK):
96 prectype = 'block relaxation'
97 params = {'relaxation: type' : 'Gauss-Seidel'}
98BGaussSeidel = DD_BGaussSeidel
100class DD_BSymmGaussSeidel(IFPACK):
101 prectype = 'block relaxation'
102 params = {'relaxation: type' : 'symmetric Gauss-Seidel'}
103BSymmGaussSeidel = DD_BSymmGaussSeidel
105class DD_ILU(IFPACK):
106 """Incomplete LU factorization"""
107 prectype = 'ILU'
108ILU = DD_ILU
110class DD_ILUT(IFPACK):
111 """ILU with threshold"""
112 prectype = 'ILUT'
113ILUT = DD_ILUT
115class DD_IC(IFPACK):
116 """Incomplete Cholesky factorization"""
117 prectype = 'IC'
118IC = DD_IC
120class DD_ICT(IFPACK):
121 """IC with threshold"""
122 prectype = 'ICT'
123ICT = DD_ICT
125class DD_Amesos(IFPACK):
126 prectype = 'Amesos'
127 def __init__(self, A, solver='Klu', **kwargs):
128 self.params.update({'amesos: solver type': 'Amesos_'+solver})
129 super(DD_Amesos, self).__init__(A, **kwargs)
131del IFPACK