Derivative of LocalAnalyticGridViewFunction
What is the correct derivative of a local AnalyticGridViewFunction? Is it the derivative, w.r.t. global coordinates, or w.r.t. local coordinates?
Currently, it implements a global jacobian, but I think, it should be a jacobian w.r.t. local coordinates. This could be implemented by combining the global derivative with the jacobian of the local geometry.
Example:
The Problem is, that the function concepts expect a local jacobian, whereas the LocalAnalyticGridViewFunction implements a slightly different concept:
using Grid = FoamGrid<2,3>; // grid with dimension != dimensionworld
std::unique_ptr<Grid> grid = /* ... */;
using GridView = typename Grid::LeafGridView;
using EntitySet = Functions::GridViewEntitySet<GridView,0>;
using LocalContext = typename EntitySet::Element;
using Signature = FieldVector<double,3>(FieldVector<double,3>);
using LocalSignature = FieldVector<double,3>(FieldVector<double,2>);
auto f = Functions::makeDifferentiableFunctionFromCallables(
Functions::SignatureTag<Signature>{},
[](auto const& x) { return FieldVector<double,3>(0); },
[](auto const& x) { return FieldMatrix<double,3,3>(0); }
);
auto gf = Functions::makeAnalyticGridViewFunction(f, grid->leafGridView());
using GF = decltype(gf);
static_assert(Functions::Concept::isFunction<GF,Signature>(), "");
static_assert(Functions::Concept::isDifferentiableFunction<GF,Signature>(), "");
auto lf = localFunction(gf);
using LF = decltype(lf);
static_assert(Functions::Concept::isFunction<LF,LocalSignature>(), "");
static_assert(Functions::Concept::isLocalFunction<LF,LocalSignature,LocalContext>(), "");
// Here we have to explicitly change the derivative traits:
static_assert(Functions::Concept::isDifferentiableFunction<LF,LocalSignature,
Functions::LocalDerivativeTraits<EntitySet>::template Traits>(), "");
static_assert(Functions::Concept::isDifferentiableLocalFunction<LF,LocalSignature,
LocalContext,Functions::LocalDerivativeTraits<EntitySet>::template Traits>(), "");
The LocalDerivativeTraits
in the example is necessary. It changes the range type of the derivative from FieldMatrix<3,2>
to FieldMatrix<3,3>
. But the default DifferentiableLocalFunction
defines a local jacobian with FieldMatrix<3,2>
range type.
Application:
I want to use gridfunction to parametrize curved geometries and use the derivative localfunction to evaluate the geometry jacobian. This is required to be the local jacobian, i.e. the jacobian w.r.t. local coordinates. In case I only get the global jacobian, I have to manually chain this with the geometry jacobian of the grid the gridfunction is defined on. But, the localfunction does not give me access to the geometry it is bound to.