spheregridfunction.hh 1.58 KB
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 ``````// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // vi: set et ts=4 sw=2 sts=2: #ifndef DUNE_CURVED_SURFACE_GRID_SPHERE_GRIDFUNCTION_HH #define DUNE_CURVED_SURFACE_GRID_SPHERE_GRIDFUNCTION_HH #include #include #include namespace Dune { // Sphere functor template< class T > struct SphereProjection { T radius_; SphereProjection (T radius) : radius_(radius) {} //! project the coordinate to the sphere at origin with `radius` template< class Domain > Domain operator() (const Domain& x) const { return x * (radius_ / x.two_norm()); } //! derivative of the projection friend auto derivative (const SphereProjection& sphere) { return [r=sphere.radius_](auto const& x) { using Domain = std::decay_t; using DerivativeTraits = Functions::DefaultDerivativeTraits; typename DerivativeTraits::Range out; auto nrm = x.two_norm(); for (int i = 0; i < out.N(); ++i) for (int j = 0; j < out.M(); ++j) out[i][j] = r * ((i == j ? 1 : 0) - (x[i]/nrm) * (x[j]/nrm)) / nrm; return out; }; } }; //! construct a grid function representing a sphere parametrization template< class Grid, class T > auto sphereGridFunction (T radius) { return analyticGridFunction(SphereProjection{radius}); } } // end namespace Dune #endif // DUNE_CURVED_SURFACE_GRID_SPHERE_GRIDFUNCTION_HH``````