From 1725de32db0d2286a98087d2e162fc17eddb9c22 Mon Sep 17 00:00:00 2001 From: Patrick <patrick.jaap@tu-dresden.de> Date: Mon, 11 May 2020 14:52:33 +0200 Subject: [PATCH] SumEnergy: Allow more than two local energies Store a vector of local energies and sum the energy over all entries. A method to add single energies is implemented. --- dune/elasticity/materials/sumenergy.hh | 32 ++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/dune/elasticity/materials/sumenergy.hh b/dune/elasticity/materials/sumenergy.hh index 2099246..698a601 100644 --- a/dune/elasticity/materials/sumenergy.hh +++ b/dune/elasticity/materials/sumenergy.hh @@ -1,6 +1,8 @@ #ifndef DUNE_ELASTICITY_MATERIALS_SUMENERGY_HH #define DUNE_ELASTICITY_MATERIALS_SUMENERGY_HH +#include <vector> + #include <dune/common/fmatrix.hh> #include <dune/common/fmatrixev.hh> @@ -24,26 +26,38 @@ class SumEnergy public: - /** \brief Constructor with a set of material parameters - * \param parameters The material parameters - */ + /** \brief Constructor with two local energies (compatibility for old interface)*/ SumEnergy(std::shared_ptr<Elasticity::LocalEnergy<LocalView, field_type>> a, std::shared_ptr<Elasticity::LocalEnergy<LocalView, field_type>> b) - : a_(a), - b_(b) + { + addLocalEnergy(a); + addLocalEnergy(b); + } + + /** \brief Default Constructor*/ + SumEnergy() {} + /** \brief Add a local energy to be part of the sum */ + void addLocalEnergy( std::shared_ptr<Elasticity::LocalEnergy<LocalView, field_type>> localEnergy ) + { + localEnergies_.push_back(localEnergy); + } + /** \brief Assemble the energy for a single element */ field_type energy (const LocalView& localView, const std::vector<field_type>& localConfiguration) const { - return a_->energy(localView, localConfiguration) - + b_->energy(localView, localConfiguration); + field_type sum = 0.; + for ( const auto& localEnergy : localEnergies_ ) + sum += localEnergy->energy( localView, localConfiguration ); + + return sum; } private: - std::shared_ptr<Elasticity::LocalEnergy<LocalView, field_type>> a_; - std::shared_ptr<Elasticity::LocalEnergy<LocalView, field_type>> b_; + // vector containing pointers to the local energies + std::vector<std::shared_ptr<Elasticity::LocalEnergy<LocalView, field_type>>> localEnergies_; }; } // namespace Dune::Elasticity -- GitLab