From bde7e19864eb13d252a177447cf718c6c1d9db42 Mon Sep 17 00:00:00 2001 From: Oliver Sander <oliver.sander@tu-dresden.de> Date: Wed, 10 Feb 2016 13:18:51 +0100 Subject: [PATCH] Implement squared distance between a 'double' RealTuple and an 'adouble' one Needed for gradient-flow applications. --- dune/gfe/realtuple.hh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dune/gfe/realtuple.hh b/dune/gfe/realtuple.hh index e8b5420b..5921c9ea 100644 --- a/dune/gfe/realtuple.hh +++ b/dune/gfe/realtuple.hh @@ -94,6 +94,19 @@ public: return (a.data_ - b.data_).two_norm(); } +#if ADOLC_ADOUBLE_H + /** \brief Geodesic distance squared between two points + + Simply the Euclidean distance squared */ + static adouble distanceSquared(const RealTuple<double,N>& a, const RealTuple<adouble,N>& b) { + adouble result(0.0); + for (int i=0; i<N; i++) + result += (a.globalCoordinates()[i] - b.globalCoordinates()[i]) * (a.globalCoordinates()[i] - b.globalCoordinates()[i]); + return result; + } +#endif + + /** \brief Compute the gradient of the squared distance function keeping the first argument fixed Unlike the distance itself the squared distance is differentiable at zero -- GitLab