DirichletBC.gather() doesn't work in Python

Issue #245 resolved
Gabriel Balaban created an issue

I tried to gather the dofs of a Dirichlet boundary condition using DirichletBC.gather() in Python. This did not work and I was informed that this is a bug. Please see the conversation from FEniCS q & a below.

Q: Dear FEniCS person, I am running an application in parallel and wondering how I can get the global set of boundary values for an object of type DirichletBC.

I test with the following script global_bc.py

from dolfin import * m = UnitCubeMesh(1,1,1) V = FunctionSpace(m, "CG", 1) bc = DirichletBC(V, 1.0, "near(x[0], 0.0)") bc.gather() bc_dofs = bc.get_boundary_values().keys() print bc_dofs

If i run the script mpirun -n 3 python global_bc.py

I get the output [] [2L, 4L, 5L, 7L] []

Which looks like only the second processor owns the dofs in the bc. The method gather() returns a dictionary and accepts no parameters so I am confused as to how it should be used if not as in the script.

Best Regards, Gabriel asked 23 hours ago by Gabriel Balaban FEniCS Novice (190 points) 1 Answer 0 votes

A: This looks like a bug in the Python wrapping of gather.

The function gather is used by DirichletBC to distribute shared boundary values between processes. However, the C++ version takes the boundary values as argument, checks if the bv dof is shared and in that case the bv is distributed to its neighbours. This does not work from the Python since you're not allowed to send the boundary values in as argument (the Python gather takes no arguments). You should report the bug on bitbucket.

Comments (8)

  1. Mikael Mortensen

    The DirichletBC.gather function is only used inside the SymmetricAssembler. I suggest it is simply ignored and hidden from Python.

  2. Gabriel Balaban reporter

    Why not just fix it? It is a useful function. It can be used to pull out the array of DOFS on a surface of a mesh for example.

  3. Mikael Mortensen

    Seems to me you're really after the regular MPI gather? In that case the boundary dofs can be extracted, e.g., like this

    from mpi4py.MPI import COMM_WORLD as comm
    bc_dofs = bc.get_boundary_values().keys()
    all_bc_dofs_gathered_on_root = comm.gather(bc_dofs, 0)
    

    DirichletBC::gather merely distributes shared dofs.

  4. Mikael Mortensen
    • changed status to open

    Even though Gabriel was really after something else, the DirichletBC.gather() is still not possible to use from python. It should be hidden or fixed in the swig interface layer. It does not work because there is an automatic typemap for

    void gather(Map& boundary_values)
    

    that turns the Map into a return type in python, like this

    Map = DirichletBC.gather()
    

    where Map is a dictionary. That does not work, because the purpose of the function is to add shared boundary values to the incoming Map.

  5. Log in to comment