Commit 1725de32 authored by Patrick Jaap's avatar Patrick Jaap
Browse files

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.
parent 8b27c630
#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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment