diff --git a/src/localgeodesicfestiffness.hh b/src/localgeodesicfestiffness.hh index ec31db80b5f0fa7fc744a7a5edb45de71af89d84..1c0ed0758a8162e40f02029e0d0d64fb635c56e5 100644 --- a/src/localgeodesicfestiffness.hh +++ b/src/localgeodesicfestiffness.hh @@ -87,13 +87,37 @@ public: }; -template <class GridType, class TargetSpace> -void LocalGeodesicFEStiffness<GridType, TargetSpace>:: +template <class GridView, class TargetSpace> +void LocalGeodesicFEStiffness<GridView, TargetSpace>:: assembleGradient(const Entity& element, - const std::vector<TargetSpace>& solution, - Dune::array<Dune::FieldVector<double,6>, 2>& gradient) const + const std::vector<TargetSpace>& localSolution, + Dune::array<Dune::FieldVector<double,6>, 2>& localGradient) const { - + // /////////////////////////////////////////////////////////// + // Compute gradient by finite-difference approximation + // /////////////////////////////////////////////////////////// + + double eps = 1e-6; + + std::vector<TargetSpace> forwardSolution = localSolution; + std::vector<TargetSpace> backwardSolution = localSolution; + + for (size_t i=0; i<localSolution.size(); i++) { + + for (int j=0; j<6; j++) { + + infinitesimalVariation(forwardSolution[i], eps, j); + infinitesimalVariation(backwardSolution[i], -eps, j); + + localGradient[i][j] = (energy(element,forwardSolution) - energy(element,backwardSolution)) + / (2*eps); + + forwardSolution[i] = localSolution[i]; + backwardSolution[i] = localSolution[i]; + } + + } + } diff --git a/src/rodlocalstiffness.hh b/src/rodlocalstiffness.hh index 272eaa28df637a2ec492aae5d17adf4719f13bf7..8bab6c948f0ffe19db9f77edcf8141dc32a620cb 100644 --- a/src/rodlocalstiffness.hh +++ b/src/rodlocalstiffness.hh @@ -30,19 +30,6 @@ class RodLocalStiffness enum {bendingQuadOrder = 2}; public: - /** \brief For the fd approximations - \todo This is public because RodAssembler uses it - */ - static void infinitesimalVariation(RigidBodyMotion<3>& c, double eps, int i) - { - if (i<3) - c.r[i] += eps; - else - c.q = c.q.mult(Rotation<3,double>::exp((i==3)*eps, - (i==4)*eps, - (i==5)*eps)); - } - std::vector<RigidBodyMotion<3> > localReferenceConfiguration_; public: