Commit 57e2a35b authored by Santiago Ospina's avatar Santiago Ospina

Added inheritance of discrete grid function from pdelab

Signed-off-by: default avatarSantiago Ospina <saospina@hugo.iwr.uni-heidelberg.de>
parent 9fdb9210
......@@ -20,48 +20,14 @@ namespace Dune{
* @tparam X CoefficientVector type
*/
template<typename GFS, typename X>
class DiscreteGridFunction
: public Dune::PDELab::GridFunctionBase<
Dune::PDELab::GridFunctionTraits<
typename GFS::Traits::GridViewType,
typename BasisInterfaceSwitch<
typename FiniteElementInterfaceSwitch<
typename GFS::Traits::FiniteElementType
>::Basis
>::RangeField,
BasisInterfaceSwitch<
typename FiniteElementInterfaceSwitch<
typename GFS::Traits::FiniteElementType
>::Basis
>::dimRange,
typename BasisInterfaceSwitch<
typename FiniteElementInterfaceSwitch<
typename GFS::Traits::FiniteElementType
>::Basis
>::Range
>,
DiscreteGridFunction<GFS,X>
>
class DiscreteGridFunction : public Dune::PDELab::DiscreteGridFunction<GFS,X>
{
typedef typename Dune::BasisInterfaceSwitch<
typename FiniteElementInterfaceSwitch<
typename GFS::Traits::FiniteElementType
>::Basis
> BasisSwitch;
typedef Dune::PDELab::GridFunctionBase<
Dune::PDELab::GridFunctionTraits<
typename GFS::Traits::GridViewType,
typename BasisSwitch::RangeField,
BasisSwitch::dimRange,
typename BasisSwitch::Range
>,
DiscreteGridFunction<GFS,X>
> BaseT;
using Base = Dune::PDELab::DiscreteGridFunction<GFS,X>;
public:
struct Traits : public BaseT::Traits
struct Traits : public Base::Traits
{
using GridFunctionSpace = GFS;
using CoefficientVector = X;
......@@ -74,54 +40,11 @@ namespace Dune{
* @param x shared pointer to the coefficients vector
*/
DiscreteGridFunction(std::shared_ptr<GFS> gfs, std::shared_ptr<X> x)
: pgfs(gfs)
, px(x) // FIXME: The LocalView should handle a shared_ptr correctly!
, lfs(*gfs)
, lfs_cache(lfs)
, x_view(*x)
, xl(gfs->maxLocalSize())
, yb(gfs->maxLocalSize())
: Base(*gfs,*x)
, pgfs(gfs)
, px(x)
{}
/*-------------------------------------------------------------------*//**
* @brief Evaluation of the FEM associated with the GFS for a given
* entity e in an entity position x
*
* @param[in] e Entity of a grid
* @param[in] x Position in local coordinates with respect the entity
* @param y Evaluation at position x
*/
inline void evaluate (const typename Traits::ElementType& e,
const typename Traits::DomainType& x,
typename Traits::RangeType& y) const
{
typedef FiniteElementInterfaceSwitch<
typename Dune::PDELab::LocalFunctionSpace<GFS>::Traits::FiniteElementType
> FESwitch;
lfs.bind(e);
lfs_cache.update();
x_view.bind(lfs_cache);
x_view.read(xl);
x_view.unbind();
FESwitch::basis(lfs.finiteElement()).evaluateFunction(x,yb);
y = 0;
for (unsigned int i=0; i<yb.size(); i++)
{
y.axpy(xl[i],yb[i]);
}
}
/*-------------------------------------------------------------------*//**
* @brief Function that returns a grid view valid for this grid
* function
*
* @return Grid view
*/
inline const typename Traits::GridViewType& getGridView () const
{
return pgfs->gridView();
}
std::shared_ptr<GFS> gridFunctionSpace()
{
return pgfs;
......@@ -143,19 +66,8 @@ namespace Dune{
}
private:
typedef Dune::PDELab::LocalFunctionSpace<GFS> LFS;
typedef Dune::PDELab::LFSIndexCache<LFS> LFSCache;
typedef typename X::template ConstLocalView<LFSCache> XView;
std::shared_ptr<GFS> pgfs;
std::shared_ptr<X> px;
mutable LFS lfs;
mutable LFSCache lfs_cache;
mutable XView x_view;
mutable std::vector<typename Traits::RangeFieldType> xl;
mutable std::vector<typename Traits::RangeType> yb;
};
}
......
......@@ -21,36 +21,10 @@ namespace Dune{
*/
template<typename GFS, typename X>
class DiscreteGridFunctionGradient
: public Dune::PDELab::GridFunctionBase<
Dune::PDELab::GridFunctionTraits<
typename GFS::Traits::GridViewType,
typename GFS::Traits::FiniteElementType::Traits::LocalBasisType
::Traits::RangeFieldType,
GFS::Traits::FiniteElementType::Traits::LocalBasisType::Traits
::dimDomain,
FieldVector<
typename GFS::Traits::FiniteElementType::Traits
::LocalBasisType::Traits::RangeFieldType,
GFS::Traits::FiniteElementType::Traits::LocalBasisType::Traits
::dimDomain> >,
DiscreteGridFunctionGradient<GFS,X> >
: public Dune::PDELab::DiscreteGridFunctionGradient<GFS,X>
{
typedef typename GFS::Traits::FiniteElementType::Traits::
LocalBasisType::Traits LBTraits;
public:
typedef Dune::PDELab::GridFunctionTraits<
typename GFS::Traits::GridViewType,
typename LBTraits::RangeFieldType,
LBTraits::dimDomain,
FieldVector<
typename LBTraits::RangeFieldType,
LBTraits::dimDomain> > Traits;
private:
typedef Dune::PDELab::GridFunctionBase<
Traits,
DiscreteGridFunctionGradient<GFS,X> > BaseT;
using Base = Dune::PDELab::DiscreteGridFunctionGradient<GFS,X>;
public:
......@@ -61,77 +35,14 @@ namespace Dune{
* @param x The coefficients vector
*/
DiscreteGridFunctionGradient(std::shared_ptr<GFS> gfs, std::shared_ptr<X> x)
: pgfs(gfs)
, lfs(*gfs)
, lfs_cache(lfs)
, x_view(*x)
, xl(lfs.size())
: Base(*gfs,*x)
, pgfs(gfs)
, px(x)
{}
/*-------------------------------------------------------------------*//**
* @brief Evaluation of the gradient of the FEM associated with the
* GFS for a given entity e in an entity position x
*
* @param[in] e Entity of a grid
* @param[in] x Position in local coordinates with respect the entity
* @param y Evaluation at position x
*/
inline void evaluate (const typename Traits::ElementType& e,
const typename Traits::DomainType& x,
typename Traits::RangeType& y) const
{
// get and bind local functions space
lfs.bind(e);
lfs_cache.update();
x_view.bind(lfs_cache);
// get local coefficients
xl.resize(lfs.size());
x_view.read(xl);
x_view.unbind();
// get Jacobian of geometry
const typename Traits::ElementType::Geometry::JacobianInverseTransposed
JgeoIT = e.geometry().jacobianInverseTransposed(x);
// get local Jacobians/gradients of the shape functions
std::vector<typename LBTraits::JacobianType> J(lfs.size());
lfs.finiteElement().localBasis().evaluateJacobian(x,J);
typename Traits::RangeType gradphi;
y = 0;
for(unsigned int i = 0; i < lfs.size(); ++i) {
// compute global gradient of shape function i
gradphi = 0;
JgeoIT.umv(J[i][0], gradphi);
// sum up global gradients, weighting them with the appropriate coeff
y.axpy(xl[i], gradphi);
}
}
/*-------------------------------------------------------------------*//**
* @brief Function that returns a grid view valid for this grid
* function
*
* @return Grid view
*/
inline const typename Traits::GridViewType& getGridView () const
{
return pgfs->gridView();
}
private:
typedef Dune::PDELab::LocalFunctionSpace<GFS> LFS;
typedef Dune::PDELab::LFSIndexCache<LFS> LFSCache;
typedef typename X::template ConstLocalView<LFSCache> XView;
std::shared_ptr<GFS const> pgfs;
mutable LFS lfs;
mutable LFSCache lfs_cache;
mutable XView x_view;
mutable std::vector<typename Traits::RangeFieldType> xl;
std::shared_ptr<GFS> pgfs;
std::shared_ptr<X> px;
};
}
......
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