11from __future__ import division
22import numpy as np
3+ from petsc4py import PETSc
34
45from pySDC .core .Problem import ptype
56from pySDC .core .Errors import ParameterError , ProblemError
@@ -31,8 +32,6 @@ def __init__(self, problem_params, dtype_u, dtype_f):
3132
3233 # these parameters will be used later, so assert their existence
3334
34- from petsc4py import PETSc
35-
3635 if 'comm' not in problem_params :
3736 problem_params ['comm' ] = PETSc .COMM_WORLD
3837 if 'sol_tol' not in problem_params :
@@ -62,9 +61,6 @@ def __init__(self, problem_params, dtype_u, dtype_f):
6261 self .dy = 1.0 / (self .params .nvars [1 ] - 1 )
6362 (self .xs , self .xe ), (self .ys , self .ye ) = self .init .getRanges ()
6463
65- self .row = PETSc .Mat .Stencil ()
66- self .col = PETSc .Mat .Stencil ()
67-
6864 # compute discretization matrix A and identity
6965 self .A = self .__get_A ()
7066 self .Id = self .__get_Id ()
@@ -95,14 +91,16 @@ def __get_A(self):
9591
9692 # fill matrix
9793 A .zeroEntries ()
94+ row = PETSc .Mat .Stencil ()
95+ col = PETSc .Mat .Stencil ()
9896 mx , my = self .init .getSizes ()
9997 (xs , xe ), (ys , ye ) = self .init .getRanges ()
10098 for j in range (ys , ye ):
10199 for i in range (xs , xe ):
102- self . row .index = (i , j )
103- self . row .field = 0
100+ row .index = (i , j )
101+ row .field = 0
104102 if i == 0 or j == 0 or i == mx - 1 or j == my - 1 :
105- A .setValueStencil (self . row , self . row , 1.0 )
103+ A .setValueStencil (row , row , 1.0 )
106104 else :
107105 diag = self .params .nu * (- 2.0 / self .dx ** 2 - 2.0 / self .dy ** 2 )
108106 for index , value in [
@@ -112,9 +110,9 @@ def __get_A(self):
112110 ((i + 1 , j ), self .params .nu / self .dx ** 2 ),
113111 ((i , j + 1 ), self .params .nu / self .dy ** 2 ),
114112 ]:
115- self . col .index = index
116- self . col .field = 0
117- A .setValueStencil (self . row , self . col , value )
113+ col .index = index
114+ col .field = 0
115+ A .setValueStencil (row , col , value )
118116 A .assemble ()
119117
120118 return A
@@ -136,12 +134,13 @@ def __get_Id(self):
136134
137135 # fill matrix
138136 Id .zeroEntries ()
137+ row = PETSc .Mat .Stencil ()
139138 (xs , xe ), (ys , ye ) = self .init .getRanges ()
140139 for j in range (ys , ye ):
141140 for i in range (xs , xe ):
142- self . row .index = (i , j )
143- self . row .field = 0
144- Id .setValueStencil (self . row , self . row , 1.0 )
141+ row .index = (i , j )
142+ row .field = 0
143+ Id .setValueStencil (row , row , 1.0 )
145144
146145 Id .assemble ()
147146
0 commit comments