Skip to content

BUG: domain of Constant not preserved in adjoint replay #3009

@stephankramer

Description

@stephankramer

Describe the bug
When assigning to a Constant T the value of a Constant S on a different domain, it appears that in the replay the checkpointed value of T after the assignment has taken the domain of S. I think this is because the checkpointed value of T just points to the checkpointed value of S (through a DeferredCheckpoint). This means T ends up on the wrong domain.

Steps to Reproduce
Consider the following example where S is on a normal FEM mesh, and T is on a vertexonly mesh mesh0. The functional integrates T over mesh0. This works correctly in the initial run of the model, but in the replay it errors in the assembly of that integral complaining NotImplementedError: Assembly with multiple meshes is not supported and digging into the 0-form it's trying to assemble at that point it does appear that the checkpointed value of T it is using there is on mesh instead of mesh0

from firedrake import *
from firedrake_adjoint import *
mesh = UnitSquareMesh(10,10)
mesh0 = VertexOnlyMesh(mesh, [[.5,.5]])
S = Constant(1.0, domain=mesh)
T = Constant(2.0, domain=mesh0)
T.assign(S)
J = assemble(T*dx(domain=mesh0))
rf = ReducedFunctional(J, Control(S))
rf(Constant(3.0, domain=mesh))

When constructing T immediately from the value of S:

T = Constant(S, domain=mesh0)

the same error is produced.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions