@reimar, @akostic I have made some simplifications for your energy. All derivatives can be computed automatically by Linearizations.