Multiple implementations of homogenize(bcs)

Issue #509 resolved
Jan Blechta created an issue

There are two independent implementations of BC homogenization:

  1. member DirichletBC::homogenize()
  2. Python free function homogenize(bcs)

They can do something different due to applicable DOFs being cached by DirichletBC on first use which are retained by approach 1 and thrown away by approach 2 (to be constructed again on its first use).

Comments (9)

  1. Patrick Farrell

    Hi Jan,

    It's crucial for dolfin-adjoint to be able to construct an independent homogenised version of a given boundary condition. (These are the BCs we impose on the adjoint equation.) For that purpose we have been using the free function homogenize. However, when I now compile DOLFIN master, I get a deprecation warning.

    DirichletBC::homogenize modifies in-place, and the deprecation warning cryptically states that *** Copy construction semantics of DirichletBC is not well defined.. Hence, to use the method as opposed to the function you want to delete, I have to understand what's wrong with the copy constructor. Can you expand on this? And can we please not delete the homogenize method until this is ironed out?

  2. Jan Blechta reporter

    Ok, let's not delete free homogenize until we have a consensus.

    Previous implementation of free homogenize was creating new bc and ad hoc copying some of the member data. This had different copy semantics from member DirichletBC::homogenize because there is caching in DirichletBC::compute_bc_*. When user changes a domain, member version will not feel it because cached dofs will be kept (if already cached after first use) while free homogenize was throwing cached dofs away before this change.

    Now the semantics of both of them is the same hence free version is redundant. Why isn't usage of a member version (possibly in combination with a copy constructor) feasible for you? What exactly do you need to do? What does independent (in your first sentence) means?

  3. Patrick Farrell

    Ah, I thought from the error message that there was something wrong with the bc_copy = DirichletBC(bc) copy constructor.

    I've tried it out in dolfin-adjoint and using the copy constructor and object method works fine. I've pushed that change to dolfin-adjoint master.

    I'm happy for the free function to be removed.

  4. Jan Blechta reporter

    Yes, deprecation message is misleading. It reports the state before the fix, rather than current state. Let me fix this.

  5. Log in to comment