Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing dof_indices method of DirichletBC in python #3167

Closed
twmr opened this issue Apr 23, 2024 · 1 comment · Fixed by #3389
Closed

Missing dof_indices method of DirichletBC in python #3167

twmr opened this issue Apr 23, 2024 · 1 comment · Fixed by #3389
Labels
enhancement New feature or request

Comments

@twmr
Copy link

twmr commented Apr 23, 2024

Summarize the issue

I noticed that while upgrading dolfinx from 0.6.2 to 0.7.0 that there is no longer a dof_indices method for the dolfinx.fem.bcs.DirichletBC class. I couldn't find anything related in the release notes of 0.7.0.
In 0.7.0 there seems to be a single unit-test that calls the dof_indices method, but this test was removed later (in #2820).

debugging my code with dolfinx 0.6.2:

(Pdb) p bcs[0]
<dolfinx.fem.bcs.DirichletBC object at 0x72af6bee1ad0>
(Pdb) p dir(bcs[0])
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'dof_indices', 'dtype', 'function_space', 'g', 'value']
(Pdb) p bcs[0].dof_indices
<bound method PyCapsule.dof_indices of <dolfinx.fem.bcs.DirichletBC object at 0x72af6bee1ad0>>

debugging my code with dolfinx 0.7.0:

(Pdb) p bcs[0]
<dolfinx.fem.bcs.DirichletBC object at 0x7acbd3d24dd0>
(Pdb) p bcs[0].function_space
<dolfinx.cpp.fem.FunctionSpace_float64 object at 0x7acbe0ddc530>
(Pdb) p dir(bcs[0])
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_cpp_object', 'function_space', 'g']

You can see that 0.7.0 no longer has the dof_indices, dtype and value methods/attributes. Is this on purpose?
Am I missing anything?

How to reproduce the bug

see script below

Minimal Example (Python)

import numpy as np
import ufl
from dolfinx import fem, mesh
from mpi4py import MPI
from petsc4py import PETSc

msh = mesh.create_unit_interval(MPI.COMM_WORLD, nx=1000)

V = fem.FunctionSpace(msh, ("Lagrange", 3))

ds_obc = ufl.ds
bcs_dofs = fem.locate_dofs_geometrical(
    V,
    lambda x: np.isclose(x[0], 0.0),
)

bc = fem.dirichletbc(PETSc.ScalarType(0), bcs_dofs, V)
print(bc)
print(bc.dof_indices())

Output (Python)

$ pixi run python repr.py                                                                                                                  <dolfinx.fem.bcs.DirichletBC object at 0x7fd328936110>
Traceback (most recent call last):
  File "/home/thomas/repr.py", line 19, in <module>
    print(bc.dof_indices())
          ^^^^^^^^^^^^^^
AttributeError: 'DirichletBC' object has no attribute 'dof_indices'

Version

0.7.0

DOLFINx git commit

No response

Installation

conda linux-64 env

Additional information

No response

@twmr twmr added the bug Something isn't working label Apr 23, 2024
@twmr
Copy link
Author

twmr commented Apr 23, 2024

As a workaround, it is possible to call the dof_indices method on the private _cpp_object attribute:

(tested in dolfinx 0.7.3)

In [2]: bc._cpp_object
Out[2]: <dolfinx.cpp.fem.DirichletBC_complex128 at 0x70fe740d7730>

In [3]: bc._cpp_object.dof_indices()
Out[3]: (array([0], dtype=int32), 1)

@francesco-ballarin francesco-ballarin added enhancement New feature or request and removed bug Something isn't working labels Apr 23, 2024
@francesco-ballarin francesco-ballarin changed the title [BUG]: Missing dof_indices method of DirichletBC in python Missing dof_indices method of DirichletBC in python Apr 23, 2024
jorgensd added a commit that referenced this issue Sep 12, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants