Skip to content
Snippets Groups Projects

NeumannEnergy: use std::function instead of Dune::VirtualFunction

2 files
+ 25
43
Compare changes
  • Side-by-side
  • Inline

Files

#ifndef DUNE_ELASTICITY_MATERIALS_NEUMANNENERGY_HH
#ifndef DUNE_ELASTICITY_MATERIALS_NEUMANNENERGY_HH
#define DUNE_ELASTICITY_MATERIALS_NEUMANNENERGY_HH
#define DUNE_ELASTICITY_MATERIALS_NEUMANNENERGY_HH
 
#include <functional>
 
#include <dune/geometry/quadraturerules.hh>
#include <dune/geometry/quadraturerules.hh>
#include <dune/fufem/functions/virtualgridfunction.hh>
#include <dune/fufem/boundarypatch.hh>
#include <dune/fufem/boundarypatch.hh>
#include <dune/elasticity/assemblers/localenergy.hh>
#include <dune/elasticity/assemblers/localenergy.hh>
@@ -26,7 +27,7 @@ public:
@@ -26,7 +27,7 @@ public:
* \param parameters The material parameters
* \param parameters The material parameters
*/
*/
NeumannEnergy(const std::shared_ptr<BoundaryPatch<GridView>>& neumannBoundary,
NeumannEnergy(const std::shared_ptr<BoundaryPatch<GridView>>& neumannBoundary,
const Dune::VirtualFunction<Dune::FieldVector<ctype,dim>, Dune::FieldVector<double,dim> >* neumannFunction)
std::function<Dune::FieldVector<double,dim>(Dune::FieldVector<ctype,dim>)> neumannFunction)
: neumannBoundary_(neumannBoundary),
: neumannBoundary_(neumannBoundary),
neumannFunction_(neumannFunction)
neumannFunction_(neumannFunction)
{}
{}
@@ -66,12 +67,7 @@ public:
@@ -66,12 +67,7 @@ public:
value[j] += shapeFunctionValues[i] * localConfiguration[ localView.tree().child(j).localIndex(i) ];
value[j] += shapeFunctionValues[i] * localConfiguration[ localView.tree().child(j).localIndex(i) ];
// Value of the Neumann data at the current position
// Value of the Neumann data at the current position
Dune::FieldVector<double,dim> neumannValue;
auto neumannValue = neumannFunction_( it.geometry().global(quad[pt].position()) );
if (dynamic_cast<const VirtualGridViewFunction<GridView,Dune::FieldVector<double,dim> >*>(neumannFunction_))
dynamic_cast<const VirtualGridViewFunction<GridView,Dune::FieldVector<double,dim> >*>(neumannFunction_)->evaluateLocal(element, quadPos, neumannValue);
else
neumannFunction_->evaluate(it.geometry().global(quad[pt].position()), neumannValue);
// Only translational dofs are affected by the Neumann force
// Only translational dofs are affected by the Neumann force
for (size_t i=0; i<neumannValue.size(); i++)
for (size_t i=0; i<neumannValue.size(); i++)
@@ -89,7 +85,7 @@ private:
@@ -89,7 +85,7 @@ private:
const std::shared_ptr<BoundaryPatch<GridView>> neumannBoundary_;
const std::shared_ptr<BoundaryPatch<GridView>> neumannBoundary_;
/** \brief The function implementing the Neumann data */
/** \brief The function implementing the Neumann data */
const Dune::VirtualFunction<Dune::FieldVector<double,dim>, Dune::FieldVector<double,dim> >* neumannFunction_;
std::function<Dune::FieldVector<double,dim>(Dune::FieldVector<ctype,dim>)> neumannFunction_;
};
};
} // namespace Dune::Elasticity
} // namespace Dune::Elasticity
@@ -113,8 +109,8 @@ public:
@@ -113,8 +109,8 @@ public:
/** \brief Constructor with a set of material parameters
/** \brief Constructor with a set of material parameters
* \param parameters The material parameters
* \param parameters The material parameters
*/
*/
NeumannEnergy(const BoundaryPatch<GridView>* neumannBoundary,
NeumannEnergy(const std::shared_ptr<BoundaryPatch<GridView>>& neumannBoundary,
const Dune::VirtualFunction<Dune::FieldVector<ctype,dim>, Dune::FieldVector<double,dim> >* neumannFunction)
const std::shared_ptr<std::function<Dune::FieldVector<double,dim>(Dune::FieldVector<ctype,dim>)>>& neumannFunction)
: neumannBoundary_(neumannBoundary),
: neumannBoundary_(neumannBoundary),
neumannFunction_(neumannFunction)
neumannFunction_(neumannFunction)
{}
{}
@@ -154,12 +150,8 @@ public:
@@ -154,12 +150,8 @@ public:
value[j] += shapeFunctionValues[i] * localConfiguration[i][j];
value[j] += shapeFunctionValues[i] * localConfiguration[i][j];
// Value of the Neumann data at the current position
// Value of the Neumann data at the current position
Dune::FieldVector<double,dim> neumannValue;
auto neumannValue = (*neumannFunction_)( it.geometry().global(quad[pt].position()) );
if (dynamic_cast<const VirtualGridViewFunction<GridView,Dune::FieldVector<double,dim> >*>(neumannFunction_))
dynamic_cast<const VirtualGridViewFunction<GridView,Dune::FieldVector<double,dim> >*>(neumannFunction_)->evaluateLocal(element, quadPos, neumannValue);
else
neumannFunction_->evaluate(it.geometry().global(quad[pt].position()), neumannValue);
// Only translational dofs are affected by the Neumann force
// Only translational dofs are affected by the Neumann force
for (size_t i=0; i<neumannValue.size(); i++)
for (size_t i=0; i<neumannValue.size(); i++)
@@ -174,11 +166,11 @@ public:
@@ -174,11 +166,11 @@ public:
private:
private:
/** \brief The Neumann boundary */
/** \brief The Neumann boundary */
const BoundaryPatch<GridView>*
const std::shared_ptr<BoundaryPatch<GridView>>
DUNE_DEPRECATED_MSG("Use dune-functions powerBases with LocalView concept. See Elasticity::NeumannEnergy") neumannBoundary_;
DUNE_DEPRECATED_MSG("Use dune-functions powerBases with LocalView concept. See Elasticity::NeumannEnergy") neumannBoundary_;
/** \brief The function implementing the Neumann data */
/** \brief The function implementing the Neumann data */
const Dune::VirtualFunction<Dune::FieldVector<double,dim>, Dune::FieldVector<double,dim> >* neumannFunction_;
const std::shared_ptr<std::function<Dune::FieldVector<double,dim>(Dune::FieldVector<ctype,dim>)>> neumannFunction_;
};
};
} // namespace Dune
} // namespace Dune
Loading