Commit 9fdb9210 authored by Santiago Ospina's avatar Santiago Ospina

Added modifications of the discrete grid functions

Signed-off-by: default avatarSantiago Ospina <saospina@hugo.iwr.uni-heidelberg.de>
parent ba1e0d02
......@@ -28,6 +28,7 @@
#include "../solver/adapters/saturation.hh"
#include "../solver/adapters/water_flux.hh"
#include "../solver/adapters/conductivity.hh"
#include "../solver/adapters/discrete_grid_function.hh"
namespace Dune{
......@@ -112,7 +113,7 @@ struct RichardsSimulationTraits : public BaseTraits
// -- Grid Functions of state valriables -- //
/// Matric head
using GFMatricHead = Dune::PDELab::DiscreteGridFunction<GFS,U>;
using GFMatricHead = Dune::Dorie::DiscreteGridFunction<GFS,U>;
/// Water Flux
using GFWaterFlux = Dune::Dorie::WaterFluxAdapter<GFS,U,Parameters>;
/// Conductivity
......
#ifndef DUNE_DORIE_DISCRETE_GRID_FUNCTION_ADAPTER_HH
#define DUNE_DORIE_DISCRETE_GRID_FUNCTION_ADAPTER_HH
#include <vector>
#include <memory>
#include <dune/pdelab/common/function.hh>
#include <dune/pdelab/gridfunctionspace/localfunctionspace.hh>
#include <dune/pdelab/gridfunctionspace/lfsindexcache.hh>
namespace Dune{
namespace Dorie{
/*---------------------------------------------------------------------*//**
* @brief Convert a grid function space and a coefficient vector into a
* grid function
*
* @tparam GFS GridFunctionSpace type
* @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>
>
{
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;
public:
struct Traits : public BaseT::Traits
{
using GridFunctionSpace = GFS;
using CoefficientVector = X;
};
/*-------------------------------------------------------------------*//**
* @brief Construct a DiscreteGridFunction
*
* @param gfs shared pointer to the GridFunctionsSpace
* @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())
{}
/*-------------------------------------------------------------------*//**
* @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;
}
std::shared_ptr<const GFS> gridFunctionSpace() const
{
return pgfs;
}
std::shared_ptr<X> coefficientVector()
{
return px;
}
std::shared_ptr<const X> coefficientVector() const
{
return px;
}
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;
};
}
}
#endif
\ No newline at end of file
#ifndef DUNE_DORIE_DISCRETE_GRID_FUNCTION_GRADIENTS_ADAPTER_HH
#define DUNE_DORIE_DISCRETE_GRID_FUNCTION_GRADIENTS_ADAPTER_HH
#include <vector>
#include <memory>
#include <dune/pdelab/common/function.hh>
#include <dune/pdelab/gridfunctionspace/localfunctionspace.hh>
#include <dune/pdelab/gridfunctionspace/lfsindexcache.hh>
namespace Dune{
namespace Dorie{
/*---------------------------------------------------------------------*//**
* @brief Converts a single component function space with a grid
* function representing the gradient
*
* @tparam GFS GridFunctionSpace type
* @tparam X CoefficientVector type
*/
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> >
{
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;
public:
/*-------------------------------------------------------------------*//**
* @brief Construct a DiscreteGridFunctionGradient
*
* @param gfs The GridFunctionsSpace
* @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())
{}
/*-------------------------------------------------------------------*//**
* @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;
};
}
}
#endif
\ No newline at end of file
......@@ -75,6 +75,12 @@ namespace Dune{
y = _p->saturation(head,xGlobal);
}
/*-------------------------------------------------------------------*//**
* @brief Function that returns a grid view valid for this grid
* function
*
* @return Grid view
*/
const typename Traits::GridViewType& getGridView() const
{
return _gv;
......
......@@ -75,6 +75,12 @@ namespace Dune{
y = _p->waterContent(head,xGlobal);
}
/*-------------------------------------------------------------------*//**
* @brief Function that returns a grid view valid for this grid
* function
*
* @return Grid view
*/
const typename Traits::GridViewType& getGridView() const
{
return _gv;
......
#ifndef DUNE_DORIE_RICHARDS_WATER_FLUX_ADAPTER_HH
#define DUNE_DORIE_RICHARDS_WATER_FLUX_ADAPTER_HH
#include "discrete_grid_function.hh"
#include "discrete_grid_function_gradient.hh"
namespace Dune{
namespace Dorie{
......@@ -15,16 +18,16 @@ namespace Dune{
*/
template<typename GFS, typename X, typename P>
class WaterFluxAdapter : public Dune::PDELab::GridFunctionInterface<
typename Dune::PDELab::DiscreteGridFunctionGradient<GFS,X>::Traits,
typename Dune::Dorie::DiscreteGridFunctionGradient<GFS,X>::Traits,
WaterFluxAdapter<GFS,X,P>
>
{
using DiscreteGridFunction = Dune::PDELab::DiscreteGridFunction<GFS,X>;
using DiscreteGridFunctionGradient = Dune::PDELab::DiscreteGridFunctionGradient<GFS,X>;
using DiscreteGridFunction = Dune::Dorie::DiscreteGridFunction<GFS,X>;
using DiscreteGridFunctionGradient = Dune::Dorie::DiscreteGridFunctionGradient<GFS,X>;
using Parameters = P;
public:
using Traits = typename Dune::PDELab::DiscreteGridFunctionGradient<GFS,X>::Traits;
using Traits = typename Dune::Dorie::DiscreteGridFunctionGradient<GFS,X>::Traits;
/*-------------------------------------------------------------------*//**
* @brief Constructor for the WaterFluxAdapter
......@@ -40,7 +43,7 @@ namespace Dune{
, _p(p)
, _x(x)
, _dgf_h(_gfs,_x)
, _dgf_h_grad(*_gfs,*_x)
, _dgf_h_grad(_gfs,_x)
{}
/*-------------------------------------------------------------------*//**
......
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