Generate derivatives, compute gradient and dot, factor out setSpacetime()