How can we specify a local lambda?
Imagine the following situation:
I want to do some local computations like the squared error, given the analytic solution f
and the discrete gridview function dgfv
. How can write this as a lambda?
I basically have to specify the three stages: bind()
, (x)
, unbind()
. But at the same time I now need some state, which is non trivial and depends on my particular implementation...
I could imagine something like:
makeDiscreteLocalFunction(
std::make_tuple(localView(f), localView(dgfv)),
[](auto & state, auto & entity) {
std::get<0>(state).bind(entity);
std::get<1>(state).bind(entity);
},
[](auto & state, auto & x) {
auto v1 = std::get<0>(state)(x);
auto v2 = std::get<1>(state)(x);
return (v1-v2)*(v1-v2);
},
[](auto & state) {
std::get<0>(state).unbind();
std::get<1>(state).unbind();
}
);
This basically mimics C-style classes as a collection of data and functions.
On the other hand, we could avoid most of these situations, if we write many overloads of standard operators, like +-*/ pow abs
...