Stress and heat flux via automatic differentiation