diff --git a/dune/elasticity/materials/sumenergy.hh b/dune/elasticity/materials/sumenergy.hh index 209924678da7438f649f412c95ab7befa7fc2469..698a601cd89aa1bdffe406c483df0abfbfbbfcd8 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