Skip to content

Conversation

@ZoeLeibowitz
Copy link
Owner

@ZoeLeibowitz ZoeLeibowitz commented Mar 20, 2025

  • Change the _C_ctype of PetscArray objects to PetscScalar
  • Refactored _restrict_keyword to be a property of Basic objects, instead of a string defined in the CGen class. By overriding this property for PetscArray objects, we can prevent specific warnings generated by PETSc.

TODO:

  • Add test that checks for single/double precision and ensures the multi-dim casting is correct

ZoeLeibowitz and others added 30 commits February 18, 2025 10:10
if isinstance(obj, (AbstractFunction, IndexedData)) and mode >= 1:
if not obj._mem_stack:
strtype = '%s%s' % (strtype, self._restrict_keyword)
strtype = '%s%s' % (strtype, obj._restrict_keyword)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f-string, we try to update all string to f".. {}" whenever we touch one

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think _restrict_keyword should be an object property that seems at the wrong place.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any other suggestions on where it could go if I need to drop it for certain objects like PETScArrays?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be attached to the class?


f = Function(name='f', grid=grid, space_order=2)
g = Function(name='g', grid=grid, space_order=2)
f = Function(name='f', grid=grid, space_order=2, dtype=np.float64)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to repeat the dtype of it's already the one from the grid.

grid = Grid(shape=(11, 11))
f = Function(name='f', grid=grid, space_order=2)
grid = Grid(shape=(11, 11), dtype=np.float64)
f = Function(name='f', grid=grid, space_order=2, dtype=np.float64)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dtype not needed

f1 = Function(name='f1', grid=grid1, space_order=2)
f2 = Function(name='f2', grid=grid2, space_order=4)
f3 = Function(name='f3', grid=grid3, space_order=6)
f1 = Function(name='f1', grid=grid1, space_order=2, dtype=np.float64)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same


f = Function(name='f', grid=grid, space_order=2)
g = Function(name='g', grid=grid, space_order=2)
f = Function(name='f', grid=grid, space_order=2, dtype=np.float64)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same


f1 = Function(name='f1', grid=grid, space_order=2)
g1 = Function(name='g1', grid=grid, space_order=2)
f1 = Function(name='f1', grid=grid, space_order=2, dtype=np.float64)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

arrays=None, **kwargs):
self._target = kwargs.get('target', target)

petsc_precision = mapper[get_petsc_precision()]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: This dict should probably have a more descriptive name

"""
return False

@property
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this an attribute of the class rather than the object. I.e. have _restrict_keyword = 'restrict' immediately under the docstring.

op = Operator(petsc)

# Check the solve function returns the correct output
op.apply()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I think it's probably better if the op.apply() is also within the switchconfig

"""
petsc_dir = get_petsc_dir()
petsc_arch = get_petsc_arch()
variables_path = os.path.join(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion, use pathlib instead of chaining os.path commands

@ZoeLeibowitz ZoeLeibowitz force-pushed the master branch 2 times, most recently from 794ac3e to cccb988 Compare March 24, 2025 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert to PetscScalar instead of float/double Drop restrict keyword when using PETSc

6 participants