11from __future__ import division
22import numpy as np
3- from petsc4py import PETSc
43
54from pySDC .core .Problem import ptype
65from pySDC .core .Errors import ParameterError , ProblemError
@@ -32,6 +31,8 @@ def __init__(self, problem_params, dtype_u, dtype_f):
3231
3332 # these parameters will be used later, so assert their existence
3433
34+ from petsc4py import PETSc
35+
3536 if 'comm' not in problem_params :
3637 problem_params ['comm' ] = PETSc .COMM_WORLD
3738 if 'sol_tol' not in problem_params :
@@ -61,6 +62,9 @@ def __init__(self, problem_params, dtype_u, dtype_f):
6162 self .dy = 1.0 / (self .params .nvars [1 ] - 1 )
6263 (self .xs , self .xe ), (self .ys , self .ye ) = self .init .getRanges ()
6364
65+ self .row = PETSc .Mat .Stencil ()
66+ self .col = PETSc .Mat .Stencil ()
67+
6468 # compute discretization matrix A and identity
6569 self .A = self .__get_A ()
6670 self .Id = self .__get_Id ()
@@ -91,16 +95,14 @@ def __get_A(self):
9195
9296 # fill matrix
9397 A .zeroEntries ()
94- row = PETSc .Mat .Stencil ()
95- col = PETSc .Mat .Stencil ()
9698 mx , my = self .init .getSizes ()
9799 (xs , xe ), (ys , ye ) = self .init .getRanges ()
98100 for j in range (ys , ye ):
99101 for i in range (xs , xe ):
100- row .index = (i , j )
101- row .field = 0
102+ self . row .index = (i , j )
103+ self . row .field = 0
102104 if i == 0 or j == 0 or i == mx - 1 or j == my - 1 :
103- A .setValueStencil (row , row , 1.0 )
105+ A .setValueStencil (self . row , self . row , 1.0 )
104106 else :
105107 diag = self .params .nu * (- 2.0 / self .dx ** 2 - 2.0 / self .dy ** 2 )
106108 for index , value in [
@@ -110,9 +112,9 @@ def __get_A(self):
110112 ((i + 1 , j ), self .params .nu / self .dx ** 2 ),
111113 ((i , j + 1 ), self .params .nu / self .dy ** 2 ),
112114 ]:
113- col .index = index
114- col .field = 0
115- A .setValueStencil (row , col , value )
115+ self . col .index = index
116+ self . col .field = 0
117+ A .setValueStencil (self . row , self . col , value )
116118 A .assemble ()
117119
118120 return A
@@ -134,13 +136,12 @@ def __get_Id(self):
134136
135137 # fill matrix
136138 Id .zeroEntries ()
137- row = PETSc .Mat .Stencil ()
138139 (xs , xe ), (ys , ye ) = self .init .getRanges ()
139140 for j in range (ys , ye ):
140141 for i in range (xs , xe ):
141- row .index = (i , j )
142- row .field = 0
143- Id .setValueStencil (row , row , 1.0 )
142+ self . row .index = (i , j )
143+ self . row .field = 0
144+ Id .setValueStencil (self . row , self . row , 1.0 )
144145
145146 Id .assemble ()
146147
0 commit comments