@@ -134,10 +134,12 @@ def __init__(self, name, pname, petsc_option_mapper, sobjs, section_mapper,
134134
135135 mapper = {v : k for k , v in petsc_type_mappings .items ()}
136136
137- fields = [
138- (str (ptype ), mapper [str (ptype ._C_ctype )])
139- for option in petsc_option_mapper .values () for ptype in option .values ()
140- ]
137+ fields = []
138+ for obj_mapper in petsc_option_mapper .values ():
139+ for petsc_option in obj_mapper .values ():
140+ ctype = mapper [str (petsc_option ._C_ctype )]
141+ fields .append ((petsc_option .name , ctype ))
142+
141143 super ().__init__ (name , pname , fields )
142144
143145 @property
@@ -164,24 +166,22 @@ def __getattr__(self, attr):
164166 # Helper to get the value from the profiling struct
165167 get_val = lambda v : getattr (self .value ._obj , v .name )
166168
167- # Return the value(s) for the given PETSc attribute:
168- # - If there's only one output (e.g., for KSPGetIterationNumber),
169- # return it directly.
170- # - If there are multiple outputs (e.g., for KSPGetTolerances),
171- # return a dictionary mapping each output name to
172- # its value, e.g., {'rtol': val0, 'abstol': val1, ...}.
169+ # - If the function returns a single value (e.g., KSPGetIterationNumber),
170+ # return that value directly.
171+ # - If the function returns multiple values (e.g., KSPGetTolerances),
172+ # return a dictionary mapping each output name to its value,
173+ # e.g., {'rtol': val0, 'abstol': val1, ...}.
173174 if len (obj_mapper ) == 1 :
174175 return get_val (next (iter (obj_mapper .values ())))
175176 return {k : get_val (v ) for k , v in obj_mapper .items ()}
176177
177178
178- # TODO: change the lists to tuples
179179@dataclass
180180class PetscReturnVariable :
181181 name : str
182- variable_type : list
182+ variable_type : tuple
183183 input_params : str
184- output_param : list [str ]
184+ output_param : tuple [str ]
185185
186186
187187# NOTE:
@@ -190,23 +190,32 @@ class PetscReturnVariable:
190190# If any of the PETSc function signatures change (e.g., names, input/output parameters),
191191# this dictionary must be updated accordingly.
192192
193+ # TODO: To be extended
193194petsc_return_variable_dict = {
195+ # KSP specific
194196 'kspgetiterationnumber' : PetscReturnVariable (
195197 name = 'KSPGetIterationNumber' ,
196- variable_type = [PetscInt ],
198+ variable_type = (PetscInt ,),
199+ input_params = 'ksp' ,
200+ output_param = ('kspits' ,)
201+ ),
202+ 'kspgettolerances' : PetscReturnVariable (
203+ name = 'KSPGetTolerances' ,
204+ variable_type = (PetscScalar , PetscScalar , PetscScalar , PetscInt ),
197205 input_params = 'ksp' ,
198- output_param = [ 'kspits' ]
206+ output_param = ( 'rtol' , 'abstol' , 'dtol' , 'maxits' ),
199207 ),
208+ 'kspgetconvergedreason' : PetscReturnVariable (
209+ name = 'KSPGetConvergedReason' ,
210+ variable_type = (PetscInt ,),
211+ input_params = 'ksp' ,
212+ output_param = ('reason' ,),
213+ ),
214+ # SNES specific
200215 'snesgetiterationnumber' : PetscReturnVariable (
201216 name = 'SNESGetIterationNumber' ,
202- variable_type = [ PetscInt ] ,
217+ variable_type = ( PetscInt ,) ,
203218 input_params = 'snes' ,
204- output_param = [ 'snesits' ] ,
219+ output_param = ( 'snesits' ,) ,
205220 ),
206- 'kspgettolerances' : PetscReturnVariable (
207- name = 'KSPGetTolerances' ,
208- variable_type = [PetscScalar , PetscScalar , PetscScalar , PetscInt ],
209- input_params = 'ksp' ,
210- output_param = ['rtol' , 'abstol' , 'dtol' , 'maxits' ],
211- )
212221}
0 commit comments