diff --git a/dune/elasticity/assemblers/localadolcstiffness.hh b/dune/elasticity/assemblers/localadolcstiffness.hh index 5c02eb4f3635f712dd6d7fd94c18765506514324..5ac66171a2336ea9bb0d458194cb27db93f72830 100644 --- a/dune/elasticity/assemblers/localadolcstiffness.hh +++ b/dune/elasticity/assemblers/localadolcstiffness.hh @@ -27,8 +27,12 @@ class LocalADOLCStiffness public: // accepts ADOL_C's "adouble" only - LocalADOLCStiffness(std::shared_ptr> energy) + // useHessian2: there are different basic drivers for computing the hessian by ADOL-C, namely "hessian" and "hessian2". + // They yield the same results, but "hessian2" seems to be faster. The user can switch to "hessian" with + // useHessian2=false. See ADOL-C spec for more info about the drivers + LocalADOLCStiffness(std::shared_ptr> energy, bool useHessian2 = true) : localEnergy_(energy) + , useHessian2_(useHessian2) {} /** \brief Compute the energy at the current configuration */ @@ -45,6 +49,7 @@ public: Dune::Matrix& localHessian); std::shared_ptr> localEnergy_; + const bool useHessian2_; }; @@ -110,29 +115,41 @@ assembleGradientAndHessian(const LocalView& localView, localHessian.setSize(nDoubles,nDoubles); - std::vector v(nDoubles); - std::vector w(nDoubles); - - std::fill(v.begin(), v.end(), 0.0); - - for (size_t i=0; i(localConfiguration.data()), v.data(), w.data())); // ADOL-C won't accept pointers with const values - if (rc < 0) - DUNE_THROW(Dune::Exception, "ADOL-C has returned with error code " << rc << "!"); + // ADOL-C won't accept pointers with const values, therefore the const_cast + if ( useHessian2_ ) + rc = hessian2(rank,nDoubles,const_cast(localConfiguration.data()),rawHessian); + else + rc = hessian(rank,nDoubles,const_cast(localConfiguration.data()),rawHessian); - for (size_t j=0; j