[Dune-devel] Efficiency of VtkFunction
Christian Engwer
christian.engwer at uni-muenster.de
Wed Dec 2 09:13:17 CET 2015
On Tue, Dec 01, 2015 at 05:34:45PM +0100, Aleksejs Fomins wrote:
> Dear Dune,
>
> Currently, the Dune::VTKFunction<typename Grid::LeafGridView> has the query interface
>
> virtual double evaluate(int comp, const EntityElement & element, const LocalCoordinate &xi) const
>
> I this interface inefficient in my code for two reasons:
> 1) My field is vectorial. The code naturally computes a vectorial field for a given coordinate. It is much cheaper than recomputing it for every coordinate component "comp"
> 2) My field is based on basis functions, which need a small initialization step. Thus for me the ideal interface would be
>
> template<mydim>
> VTKFunction
>
> and
>
> VTKFunction::VTKFunction(const EntityElement & element)
>
> and
>
> virtual Dune::FieldVector<ctype, mydim> evaluate(const LocalCoordinate &xi) const
>
> initializing the VtkFunction separately for each element.
No, this is not your interface of choice, because you will create
loads of new objects and the repetitive memory allcoation is just as
expensive, or even more expensive than the current double dispatch. We
tried this long ago in dune-localfunctions and pdelab and you die.
> Is there a neat way to achieve the desired functionality at the moment?
Switch to the new dune-functions interface. If you pass an object,
which fulfills the dune-functions localfunction interface, this will
also work.
You have create and object with basically two member functions (and
perhaps some typedefs)
void bind(const Entity &)
will switch the function to the local context. In this call you can
load your coefficients vector, precompute your basis functions etc.
Range operator()(const Domain &)
just as with std::function you provide a ()-operator to evaluate.
As with std::function your callable will be wrapped using type
erasure and you will still have one virtual function call. It is not
possible to do this without.
Christian
More information about the Dune-devel
mailing list