Skip to content
Snippets Groups Projects
Commit 5f333c65 authored by oliver.sander_at_tu-dresden.de's avatar oliver.sander_at_tu-dresden.de
Browse files

Merge branch 'feature/sum-energy' into 'master'

SumEnergy: Allow more than two local energies

See merge request !34
parents 1936cb4a 1725de32
No related branches found
No related tags found
1 merge request!34SumEnergy: Allow more than two local energies
Pipeline #28541 passed
#ifndef DUNE_ELASTICITY_MATERIALS_SUMENERGY_HH #ifndef DUNE_ELASTICITY_MATERIALS_SUMENERGY_HH
#define DUNE_ELASTICITY_MATERIALS_SUMENERGY_HH #define DUNE_ELASTICITY_MATERIALS_SUMENERGY_HH
#include <vector>
#include <dune/common/fmatrix.hh> #include <dune/common/fmatrix.hh>
#include <dune/common/fmatrixev.hh> #include <dune/common/fmatrixev.hh>
...@@ -24,26 +26,38 @@ class SumEnergy ...@@ -24,26 +26,38 @@ class SumEnergy
public: public:
/** \brief Constructor with a set of material parameters /** \brief Constructor with two local energies (compatibility for old interface)*/
* \param parameters The material parameters
*/
SumEnergy(std::shared_ptr<Elasticity::LocalEnergy<LocalView, field_type>> a, SumEnergy(std::shared_ptr<Elasticity::LocalEnergy<LocalView, field_type>> a,
std::shared_ptr<Elasticity::LocalEnergy<LocalView, field_type>> b) 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 */ /** \brief Assemble the energy for a single element */
field_type energy (const LocalView& localView, field_type energy (const LocalView& localView,
const std::vector<field_type>& localConfiguration) const const std::vector<field_type>& localConfiguration) const
{ {
return a_->energy(localView, localConfiguration) field_type sum = 0.;
+ b_->energy(localView, localConfiguration); for ( const auto& localEnergy : localEnergies_ )
sum += localEnergy->energy( localView, localConfiguration );
return sum;
} }
private: private:
std::shared_ptr<Elasticity::LocalEnergy<LocalView, field_type>> a_; // vector containing pointers to the local energies
std::shared_ptr<Elasticity::LocalEnergy<LocalView, field_type>> b_; std::vector<std::shared_ptr<Elasticity::LocalEnergy<LocalView, field_type>>> localEnergies_;
}; };
} // namespace Dune::Elasticity } // namespace Dune::Elasticity
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment