Using Automatic Differentiation with FinEtoolsFlexStructures.jl

Hello everyone,

I am exploring the use of automatic differentiation (AD) with the FinEtoolsFlexStructures.jl package and would like to know if anyone has experience with this. Specifically, I aim to compute the derivative of the stiffness matrix K with respect to element thickness t.

Here is a naive approach I’ve tried so far:

  1. Defined a femm function:
femm(thickness) = formul.make(IntegDomain(fes, TriRule(1), thickness), mater)
  1. Created a function to calculate K(t):
function KT(thickness)
    femm = femm(thickness)
    associategeometry!(femm, geom0)
    K = stiffness(femm, massem, geom0, u0, Rfield0, dchi)
end
  1. Used the DifferentiationInterface to compute the derivative:
derivative(KT, backend, 0.1)

I experimented with a few different backends, but without much success so far.

Eventually, my goal is to compute the gradients of elements with respect to thickness and node location for shape and thickness optimization. However, I currently have limited knowledge of both FinEtoolsFlexStructures.jl and DifferentiationInterface.

Has anyone attempted something similar, or could you provide insights into how to approach this problem? Any guidance or suggestions would be greatly appreciated!

Thank you!

Hi @Edan_Lazerson!

Can you share the errors you got with the various backends you tried? Ideally in a completely reproducible script (including all imports, function definitions and variable bindings)?
My best guess is that FinEtoolsFlexStructures.jl has some code inside which is not autodiff-friendly. Typically, if you tried ForwardDiff.jl first as a backend (like you should), you might have run into a failed conversion from Dual to Float64. Seeing that error would allow us to figure out which action to take.

You’re correct—it was indeed due to the use of Float64, which caused the error. Petr Krysl, the author of the package, is currently checking the issue to see if it can be resolved. Thanks.

1 Like