@@ -27,7 +27,6 @@ class MatrixBase(ufl.Matrix):
2727 def __init__ (
2828 self ,
2929 a : ufl .BaseForm | TensorBase | tuple [BaseArgument , BaseArgument ],
30- mat_type : Literal ["aij" , "baij" , "dense" , "nest" , "matfree" ],
3130 bcs : Iterable [BCBase ] | None = None ,
3231 fc_params : dict [str , Any ] | None = None ,
3332 ):
@@ -38,10 +37,7 @@ def __init__(
3837 ----------
3938 a
4039 A UFL BaseForm (with two arguments) that this MatrixBase represents,
41- or a tuple of the arguments it represents.
42- mat_type
43- Matrix type used in the assembly of the PETSc matrix: 'aij', 'baij', 'dense' or 'nest',
44- or 'matfree' for matrix-free.
40+ or a tuple of the arguments it represents, or a slate TensorBase.
4541 fc_params
4642 A dictionary of form compiler parameters for this matrix.
4743 bcs
@@ -70,15 +66,12 @@ def __init__(
7066 self ._analyze_form_arguments ()
7167 self ._arguments = arguments
7268
73- if bcs is None :
74- bcs = ()
75- self .bcs = bcs
69+ self .bcs = bcs or ()
7670 self .comm = test .function_space ().comm
7771 self ._comm = internal_comm (self .comm , self )
7872 self .block_shape = (len (test .function_space ()),
7973 len (trial .function_space ()))
80- self .mat_type = mat_type
81- self .form_compiler_parameters = fc_params
74+ self .form_compiler_parameters = fc_params or {}
8275
8376 def arguments (self ):
8477 if self .a :
@@ -155,7 +148,6 @@ def __init__(
155148 self ,
156149 a : ufl .BaseForm ,
157150 mat : op2 .Mat | PETSc .Mat ,
158- mat_type : Literal ["aij" , "baij" , "dense" , "nest" ],
159151 bcs : Iterable [BCBase ] | None = None ,
160152 fc_params : dict [str , Any ] | None = None ,
161153 options_prefix : str | None = None ,
@@ -168,8 +160,6 @@ def __init__(
168160 The bilinear form this :class:`Matrix` represents.
169161 mat : op2.Mat | PETSc.Mat
170162 The underlying matrix object. Either a PyOP2 Mat or a PETSc Mat.
171- mat_type
172- The type of the PETSc matrix.
173163 bcs : Iterable[DirichletBC] | None, optional
174164 An iterable of boundary conditions to apply to this :class:`Matrix`.
175165 May be `None` if there are no boundary conditions to apply.
@@ -179,7 +169,7 @@ def __init__(
179169 options_prefix : str | None, optional
180170 PETSc options prefix to apply, by default None.
181171 """
182- super ().__init__ (a , mat_type , bcs = bcs , fc_params = fc_params )
172+ super ().__init__ (a , bcs = bcs , fc_params = fc_params )
183173 if isinstance (mat , op2 .Mat ):
184174 self .M = mat
185175 else :
@@ -188,7 +178,7 @@ def __init__(
188178 self .petscmat = self .M .handle
189179 if options_prefix :
190180 self .petscmat .setOptionsPrefix (options_prefix )
191- self .mat_type = mat_type
181+ self .mat_type = self . petscmat . getType ()
192182
193183 def assemble (self ):
194184 raise NotImplementedError ("API compatibility to apply bcs after 'assemble(a)'\
@@ -226,7 +216,7 @@ def __init__(
226216 options_prefix
227217 PETSc options prefix to apply, by default None.
228218 """
229- super ().__init__ (a , "matfree" , bcs = bcs , fc_params = fc_params )
219+ super ().__init__ (a , bcs = bcs , fc_params = fc_params )
230220
231221 self .petscmat = PETSc .Mat ().create (comm = self .comm )
232222 self .petscmat .setType ("python" )
@@ -236,6 +226,7 @@ def __init__(
236226 self .petscmat .setOptionsPrefix (options_prefix )
237227 self .petscmat .setUp ()
238228 self .petscmat .assemble ()
229+ self .mat_type = "matfree"
239230
240231 def assemble (self ):
241232 # Bump petsc matrix state by assembling it.
@@ -250,7 +241,6 @@ def __init__(
250241 self ,
251242 args : tuple [BaseArgument , BaseArgument ],
252243 petscmat : PETSc .Mat ,
253- mat_type : Literal ["aij" , "baij" , "dense" , "nest" , "matfree" ],
254244 bcs : Iterable [BCBase ] | None = None ,
255245 options_prefix : str | None = None ,
256246 ):
@@ -262,19 +252,18 @@ def __init__(
262252 A tuple of the arguments the matrix represents.
263253 petscmat
264254 The PETSc matrix this object wraps.
265- mat_type
266- The type of the PETSc matrix.
267255 bcs
268256 an iterable of boundary conditions to apply to this :class:`Matrix`.
269257 May be `None` if there are no boundary conditions to apply. By default None.
270258 options_prefix
271259 PETSc options prefix to apply, by default None.
272260 """
273- super ().__init__ (args , mat_type , bcs = bcs )
261+ super ().__init__ (args , bcs = bcs )
274262
275263 self .petscmat = petscmat
276264 if options_prefix :
277265 self .petscmat .setOptionsPrefix (options_prefix )
266+ self .mat_type = self .petscmat .getType ()
278267
279268 # this mimics op2.Mat.handle
280269 self .M = DummyOP2Mat (self .petscmat )
0 commit comments