Open cgraeser opened 2 days ago
Unfortunately I cannot attach a source file. So I'll link to the current version:
https://gitlab.dune-project.org/fufem/dune-fufem/-/blob/feature/forward-ad/dune/fufem/functions/advalue.hh?ref_type=heads.
Notice that this is almost independent of the rest of Dune
. The remaining uses of Dune::range()
can easily be replaced.
I just noticed that nesting ADValue
works. So you could even use ADValue<ADValue<T, 1, dim>, 1, dim>
to compute second order derivatives or, with one level more, third order ones.
Since this is just a lucky coincidence, it there may be cases where this fails. I will also be less efficient, since one computes several derivatives multiple times. But it's probably worth to be investigated.
Hi Carsten,
that is indeed very interesting. Thanks a lot for the opportunity to discuss the integration into ADOL-C! There is actually a variant of the traceless mode that allows the calculation of higher order derivatives. So maybe these two approaches could be merged to some extend. Should we coordinate via email how to proceed?
Best
Andrea
I also noticed adtl_hov.h
today, but did not understand how to use it. Since my approach is templated, it can probably not be integrated into one of the other solutions. Dropping the template would also destroy the performance benefit. But I understand that it should be avoided to have functionally similar solutions in parallel.
Should we coordinate via email how to proceed? That's probably a good idea. I'll contact you.
We have bindings for AdolC in dune. Unfortunately the lack of thread-safety of the tape-based mode prohibits its use in thread-parallel assembly. On the other hand traceless forward mode with
adtl::adouble
has several drawbacks that cannot easily be fixed by patching it. As a remedy I implemented my own forward mode class. If there is interest, I'd happily propose it for inclusion in AdolC.Here's a rough sketch on the approach:
ADValue<T, maxOrder, dim>
for storing a AD-aware value.T
is the raw type (fixed to double inadtl::adouble
),maxOrder
is the order of computed derivatives,dim
is the domain dimension.maxOrder<=2
is supported (adtl::adouble
supports a single derivative only), but the interface is allows for later extension.dynamicDim
as template parameter (i.e.ADValue<T, maxOrder, dynamicDim>
), one can switch to a dynamic mode as used inadtl::adouble
. As far the latter this supports simple allocation (viastd::vector
) andboost::pool
to manage the storage.ADValue
is threadsafe, but it allows to do evaluations (with local variables) in concurrent threads without race conditions due to global variables.In
adtl::adouble
is roughly equivalent toADValue<double,1,dynamicDim>
.In my tests (with complicated nested function but small dimension), using a compile time dimension is about twice as fast as
adtl::adouble
withboost::pool
. In another test I used this to compute the 1st and 2nd order derivatives for a Newton step of a quasilinear PDE (minimal surface). Here the performance is exactly the same as if the derivatives are handwritten.Notice that the above obviously cannot be achieved by patching
adtl::adouble
. Hence adding this would mean to add a new templated class.