zjwegert / GridapTopOpt.jl

A computational toolbox for level set-based topology optimisation in Julia
MIT License
10 stars 1 forks source link

Autodiff broken for RepeatingAffineFEStateMap #43

Closed zjwegert closed 8 months ago

zjwegert commented 8 months ago

The function adjoint_solve!(φ_to_u::RepeatingAffineFEStateMap,du::AbstractVector) expects an array of arrays for du (or something similar for the map) but is being passed as vector/pvector by j_pullback. This appears to be happening because in ChainRules.jl line 178 we take assemble_vector!(∂j∂u_vec,assem_U,∂j∂u_vecdata). This is assembling over the multi-field space U but using assem_U for U0 and V0.

One way to fix this is create a new constructor for StateParamIntegrandWithMeasure:

function StateParamIntegrandWithMeasure(F::IntegrandWithMeasure,φ_to_u::RepeatingAffineFEStateMap)
  U,V,V_φ,U_reg = φ_to_u.spaces
  assem_deriv = get_deriv_assembler(φ_to_u)
  assem_U = SparseMatrixAssembler(U,V,...)
  StateParamIntegrandWithMeasure(F,U,V_φ,U_reg,assem_U,assem_deriv)
end

However, this would then hard code the assembler assem_U and we would also need to get parameters in place of ....

@JordiManyer I've created this to remind us that this is currently bugged.