Commit f9fc75ef authored by Fabian's avatar Fabian
Browse files

Documentation for ex_febasis + small changes to other documentations (also...

Documentation for ex_febasis + small changes to other documentations (also introduced a module for FEBases) + renameing of TestFEBasis to ex::FEBasis
parent 93bb041e
......@@ -22,9 +22,9 @@ Eigen::VectorXd buildExtended(const gridFactory_t& gridFactory,
const gridView_t gridView = gridFactory.getView();
// Create FEBasis
using febasis_t = betl2::fe::TestFEBasis<gridFactory_t>;
using febasis_t = betl2::fe::ex::FEBasis<gridFactory_t>;
febasis_t febasis(gridFactory);
for(auto& e : gridView.template entities<gridTraits_t::dimMesh>() )
for(const auto& e : gridView.template entities<gridTraits_t::dimMesh>() )
febasis.setMult(e, 1);
// Create DoF-Handler
......
......@@ -23,11 +23,11 @@ Eigen::VectorXd buildExtended(const gridFactory_t& gridFactory,
const gridView_t gridView = gridFactory.getView();
// Create FEBasis
using febasis_t = betl2::fe::TestFEBasis<gridFactory_t>;
using febasis_t = betl2::fe::ex::FEBasis<gridFactory_t>;
febasis_t febasis(gridFactory);
for(auto& e : gridView.template entities<gridTraits_t::dimMesh-1>() )
for(const auto& e : gridView.template entities<gridTraits_t::dimMesh-1>() )
febasis.setMult(e, 1);
for(auto& e : gridView.template entities<gridTraits_t::dimMesh>() )
for(const auto& e : gridView.template entities<gridTraits_t::dimMesh>() )
febasis.setMult(e, 1);
// Create DoF-Handler
......
......@@ -132,7 +132,7 @@ int main(int argc, char **argv) {
// --------------------------------------------------------------------------
// Create FEBasis
using febasis_t = betl2::fe::TestFEBasis<gridFactory_t>;
using febasis_t = betl2::fe::ex::FEBasis<gridFactory_t>;
febasis_t febasis(gridFactory);
// How the degrees of freedom are distribute is set via the physical tags.
......
......@@ -44,12 +44,12 @@ namespace betl2 {
*
* One can use this class as follows to obtain an object of class \ref FESpace:
* \code
* typedef betl2::fe::ex::DofHanlder< betl2::fe::ex::FEBasis<gridViewFactory_t>,
* gridViewFactory_t> DH_t;
* DH_t dh;
* dh.distributeDofs(gridViewFactory, febasis);
* typedef betl2::fe::ex::DofHanlder< betl2::fe::ex::FEBasis<gridViewFactory_t>,
* gridViewFactory_t> DH_t;
* DH_t dh;
* dh.distributeDofs(gridViewFactory, febasis);
*
* const auto& fespace = dh.fespace();
* const auto& fespace = dh.fespace();
* \endcode
*
* @sa \ref fe::DofHandler, \ref FESpace, \ref FEBasis, \ref FEBasisWrapper
......
......@@ -26,207 +26,266 @@
#include "fe/fe_enumerators.hpp"
#include "ex_data_set.hpp"
// Basic stuff to note:
// Unlike the original FEBasis, this will need access to the elements of the grids.
//
// Hopefully IndexSet comes in peace.
// TODO static_iterate() probably destroys the compile time. Maybe do something faster
// Definition of doxygen group
/*! @defgroup febases Finite Element Basis
*
* A finite element basis gives access to the number degrees of freedom for any entity.
* In addition, it needs to provide information about the type of basis (e.g.\ Lagrange).
* Finite element bases differentiate between two types:\ Fixed set of degrees of
* freedom and varying sets for entities with the same reference type.
*
* In the former case any finite element basis needs to provide the following functions:
* @code
* // Approximation order of the basis functions
* static constexpr int approxOrder( );
*
* // Type of finite element space
* static const betl2::fe::FEBasisType feBasisType( );
*
* // Number of degrees of freedom associated
* // with a reference type
* template< eth::base::RefElType RET >
* static constexpr size_type multiplicity( );
*
* // Number of degrees of freedom associated
* // with a reference type including its subentities
* template< eth::base::RefElType RET >
* static constexpr size_type numDofs( );
*
* // Runtime support for multplicity
* static size_type multiplicity( const eth::base::RefElType );
* // Runtime support for numDofs
* static size_type numDofs( const eth::base::RefElType );
* @endcode
*
* In the case of the extended implementation which allows for a varying set
* of degrees of freedom for entities with the same reference element type, any
* finite element basis needs to provide the following functions:
* @code
* // A way to set the number of degrees of freedom
* template< int CODIM >
* void setMult( const entity_t<CODIM>&, size_type );
*
* // Type of finite element space
* static const betl2::fe::FEBasisType feBasisType( );
*
* // Number of degrees of freedom associated with an entity
* template< int CODIM >
* size_type multiplicity( const entity_t<CODIM>& ) const;
*
* // Total number of degrees of freedom associated with an element
* // (optionally implemented also for any entity)
* size_type numDofs( const element_t& ) const;
* @endcode
*
* @sa \ref DofHandler, \ref FESpace, \ref FEBasisType, \ref ApproxOrder
*/
namespace betl2 {
namespace fe {
namespace fe {
namespace ex {
// Forward declaration
template< class GRID_VIEW_FACTORY_T >
class TestFEBasis;
namespace detail {
template< class GRID_VIEW_FACTORY_T >
struct TestFEBasisTraits
{
};
template< class GRID, eth::grid::GridViewTypes GV_T >
struct TestFEBasisTraits<eth::grids::utils::GridViewFactory<GRID,GV_T>>
{
//! View traits of GridViewFactory
typedef typename eth::grids::utils::GridViewFactory<GRID,GV_T>::viewTraits_t
viewTraits_t;
//! Reference to TestFEBasis
typedef TestFEBasis< eth::grids::utils::GridViewFactory<GRID,GV_T> > impl_t;
};
} // end namespace detail
class FEBasis;
namespace detail {
//! @brief Provides sone types for \ref FEBasis
template< class GRID_VIEW_FACTORY_T >
struct FEBasisTraits;
template< class GRID, eth::grid::GridViewTypes GV_T >
struct FEBasisTraits<eth::grids::utils::GridViewFactory<GRID,GV_T>>
{
//! View traits of GridViewFactory
typedef typename eth::grids::utils::GridViewFactory<GRID,GV_T>::viewTraits_t
viewTraits_t;
//! Type of FEBasis
typedef FEBasis< eth::grids::utils::GridViewFactory<GRID,GV_T> > impl_t;
}; // end struct FEBasistraits
} // end namespace detail
/*! @addtogroup febases
* @{
*/
/*! @brief A basic finite element basis for Lagrangian finite elements.
*
* This class provides a simply finite element basis for Lagrangian finite
* elements for the case of varying sets of degrees of freedom of entities
* with the same reference type.
*
* The role of a finite element basis is to give access to the number of
* degrees of freedom associated with entities.
*
* It provides a member function \ref setMult to set the number of degrees of
* freedom associated with one entity. The following code shows how to use this
* function (for linear Lagrangian):
* \code
* using febasis_t = betl2::fe::ex::FEBasis<gridViewFactory_t>;
* febasis_t febasis(gridViewFactory);
*
* for(const auto& ent : gridView.template entities<griTraits_t::dimMesh>() )
* febasis.setMult(ent, 1);
* \endcode
* One can use the class \ref GridElementsIdentifier to retrieve subsets
* of all entities using gmsh's phyiscal tags in order to set different number
* of degrees of freedom in different regions of the mesh.
*
*
* @sa \ref DofHandler, \ref FESpace, \ref GridElementsIdentifier
*/
template< class GRID_VIEW_FACTORY_T >
class TestFEBasis {
class FEBasis
{
public:
//! Type of grid view factory
typedef GRID_VIEW_FACTORY_T gridViewFactory_t;
//! Traits
typedef detail::TestFEBasisTraits<gridViewFactory_t> traits_t;
//! Standard type for indexing
typedef unsigned size_type;
//! Type of eth::grid::ViewTraits
typedef typename traits_t::viewTraits_t viewTraits_t;
//! Type of eth::grid::GridView
typedef eth::grid::GridView<viewTraits_t> gridView_t;
//! Type of eth::grid::GridTraits
typedef typename gridView_t::gridTraits_t gridTraits_t;
//! Type of eth::grid::IndexSet
typedef eth::grid::IndexSet<gridTraits_t , typename viewTraits_t::indexSet_t> indexSet_t;
typedef std::array<std::vector<unsigned>, gridTraits_t::dimMesh+1> set_t;
/*! Constructor
* @param gridView GridView associated with this FESpace
*/
TestFEBasis(gridViewFactory_t gridViewFactory) :
//! Type of grid view factory
typedef GRID_VIEW_FACTORY_T gridViewFactory_t;
//! Traits
typedef detail::FEBasisTraits<gridViewFactory_t> traits_t;
//! Standard type for indexing
typedef unsigned size_type;
//! Type of eth::grid::ViewTraits
typedef typename traits_t::viewTraits_t viewTraits_t;
//! Type of eth::grid::GridView
typedef eth::grid::GridView<viewTraits_t> gridView_t;
//! Type of eth::grid::GridTraits
typedef typename gridView_t::gridTraits_t gridTraits_t;
//! Type of eth::grid::IndexSet
typedef eth::grid::IndexSet<gridTraits_t , typename viewTraits_t::indexSet_t>
indexSet_t;
typedef std::array<std::vector<unsigned>, gridTraits_t::dimMesh+1> set_t;
/*! Constructor
*
* @param gridViewFactory A grid view factory.
*/
FEBasis(gridViewFactory_t gridViewFactory) :
gridViewFactory_( gridViewFactory ),
gridView_( gridViewFactory_.getView() ),
indexSet_( &gridView_.indexSet() ) {
// Resize (and set to zero) multiplicities for all entities in this mesh
typedef betl2::utils::static_iterate< gridTraits_t::dimMesh,
ResizeMultiplcities_,
const decltype( gridView_ )&,
set_t&> static_iterate;
static_iterate()( gridView_, multiplicities_);
}
// NEEDED for Interpolation
constexpr static betl2::fe::FEBasisType feBasisType( ) { return betl2::fe::FEBasisType::Lagrange; }
indexSet_( &gridView_.indexSet() )
{
// Resize (and set to zero) multiplicities for all entities in this mesh
typedef betl2::utils::static_iterate< gridTraits_t::dimMesh,
ResizeMultiplcities_,
const decltype( gridView_ )&,
set_t&> static_iterate;
static_iterate()( gridView_, multiplicities_);
}
//! @attention needed for interpolation (set to Lagrange)
constexpr static betl2::fe::FEBasisType feBasisType( ) {
return betl2::fe::FEBasisType::Lagrange;
}
//! NEEDED despite NumPDE16 not mentioning it!
// TODO: Check if still needed and why
constexpr int approxOrder() { return -1; }
/*! @brief Sets the number of degrees of freedom for an entity.
*
* @param e Entity whose degrees of freedom are to be set.
* @param mult Number of degrees of freedom that are solely associated with this entity and not any subentities.
*/
template< int CODIM >
void setMult(const eth::grid::Entity<gridTraits_t, CODIM>& e, size_type mult) {
multiplicities_[CODIM].at(gridView_.indexSet().index(e)) = mult;
}
/*! @param e Entity.
* @return The number of degrees of freedom solely associated with an entity and not any subentities.
*/
template< int CODIM >
size_type multiplicity(const eth::grid::Entity<gridTraits_t, CODIM>& e) {
return multiplicities_[CODIM].at(gridView_.indexSet().index(e));
}
/*! @param e Entity.
* @return The number of degrees of freedom solely associated with an entity and not any subentities.
*/
template< int CODIM >
const size_type multiplicity(const eth::grid::Entity<gridTraits_t, CODIM>& e) const {
return multiplicities_[CODIM].at(gridView_.indexSet().index(e));
}
/*! @param e Element.
* @return Number of dofs for this element.
*
* @note BETL2 makes an implementation of a numDofs() function
* for anything other than elements with codimension 0.
* The reason is ethGenericGrid since it does not support
* access to sub-entites for entities with codimension other
* than 0.
*/
size_type numDofs(const eth::grid::Entity<gridTraits_t,0>& e) {
// Get degrees of freedom for this element (without its subentities)
size_type dofs = multiplicities_[0].at( gridView_.indexSet().index(e) );
// Retrieve all degrees of freedom of the subentities of this element
typedef betl2::utils::static_iterate< gridTraits_t::dimMesh-1,
GetDofs_,
const decltype( gridView_ )&,
const set_t&,
const eth::grid::Entity<gridTraits_t,0>&,
size_type&> static_iterate;
static_iterate()( gridView_, multiplicities_, e, dofs);
return dofs;
}
//! @brief Constant version of numDofs.
const size_type numDofs(const eth::grid::Entity<gridTraits_t,0>& e) const {
// Get degrees of freedom for this element (without its subentities)
size_type dofs = multiplicities_[0].at( gridView_.indexSet().index(e) );
// Retrieve all degrees of freedom of the subentities of this element
typedef betl2::utils::static_iterate< gridTraits_t::dimMesh-1,
GetDofs_,
const decltype( gridView_ )&,
const set_t&,
const eth::grid::Entity<gridTraits_t,0>&,
size_type&> static_iterate;
static_iterate()( gridView_, multiplicities_, e, dofs);
return dofs;
}
/*! @brief Sets the number of degrees of freedom for an entity.
*
* @param ent Entity whose degrees of freedom are to be set.
* @param mult Number of degrees of freedom to be set (excluding subentites).
*/
template< int CODIM >
void setMult(const eth::grid::Entity<gridTraits_t, CODIM>& ent,
const size_type mult) {
multiplicities_[CODIM].at(gridView_.indexSet().index(ent)) = mult;
}
/*! @return number of degrees of freedom associated with an entity
* (but not its subentites).
*
* @param ent Entity.
*/
template< int CODIM >
size_type multiplicity(const eth::grid::Entity<gridTraits_t, CODIM>& ent) const {
return multiplicities_[CODIM].at(gridView_.indexSet().index(ent));
}
/*! @return total number of degrees of freedom for an element.
*
* @param elem Element.
*
* @note This function is only supported for elements.
*/
size_type numDofs(const eth::grid::Entity<gridTraits_t,0>& elem) const
{
// Get degrees of freedom for this element (without its subentities)
size_type dofs = multiplicities_[0].at( gridView_.indexSet().index(elem) );
// Retrieve all degrees of freedom of the subentities of this element
typedef betl2::utils::static_iterate< gridTraits_t::dimMesh-1,
GetDofs_,
const decltype( gridView_ )&,
const set_t&,
const eth::grid::Entity<gridTraits_t,0>&,
size_type&> static_iterate;
static_iterate()( gridView_, multiplicities_, elem, dofs);
return dofs;
}
private:
// -------------------------------------------------------------------------
// Various helper structs
// -------------------------------------------------------------------------
// Helper struct for resizing all entities in mesh
template< int CODIM >
struct ResizeMultiplcities_
{
template< typename GRID_VIEW, typename DATA_SET_T>
void operator()( const GRID_VIEW& gridView,
DATA_SET_T& data) const
{
std::get<CODIM>(data).resize(gridView.size(CODIM));
}
}; // end struct ResizeMultiplicities_
// Helper struct for retrieving the degrees of freedom of all entities given a codimension
template< int CODIM >
struct GetDofs_
{
template< typename GRID_VIEW, typename DATA_SET_T, typename ELEMENT_T>
void operator()( const GRID_VIEW& gridView,
const DATA_SET_T& data,
const ELEMENT_T& elem,
size_type& dofs) const
{
const auto& multSet = std::get<CODIM+1>(data);
// Get number of subentities of this elment with codimension=CODIM
const size_type numSubEnt = elem.template countSubEntities<CODIM+1>( );
// Loop over subentities and add their degrees of freedom
for(size_type i = 0; i < numSubEnt; ++i)
dofs += multSet[ gridView.indexSet().template subIndex<CODIM+1>(elem, i) ];
}
}; // end struct GetDofs_
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Various helper structs
// -------------------------------------------------------------------------
/*------------------------- BEGIN DOXYGEN HIDING -------------------------*/
//! @cond
// Helper struct for resizing all entities in mesh
template< int CODIM >
struct ResizeMultiplcities_
{
template< typename GRID_VIEW, typename DATA_SET_T>
void operator()( const GRID_VIEW& gridView,
DATA_SET_T& data) const
{
std::get<CODIM>(data).resize(gridView.size(CODIM));
}
}; // end struct ResizeMultiplicities_
// Helper struct for retrieving the degrees of freedom of all entities
// given a codimension
template< int CODIM >
struct GetDofs_
{
template< typename GRID_VIEW, typename DATA_SET_T, typename ELEMENT_T>
void operator()( const GRID_VIEW& gridView,
const DATA_SET_T& data,
const ELEMENT_T& elem,
size_type& dofs) const
{
const auto& multSet = std::get<CODIM+1>(data);
// Get number of subentities of this elment with codimension=CODIM
const size_type numSubEnt = elem.template countSubEntities<CODIM+1>( );
// Loop over subentities and add their degrees of freedom
for(size_type i = 0; i < numSubEnt; ++i)
dofs += multSet[ gridView.indexSet().template subIndex<CODIM+1>(elem, i) ];
}
}; // end struct GetDofs_
//! @endcond
/*-------------------------- END DOXYGEN HIDING --------------------------*/
// -------------------------------------------------------------------------
private:
//! Storage for multiplicities
set_t multiplicities_;
//! Underlying GridViewFactory
const gridViewFactory_t gridViewFactory_;
//! Underlying GridView used for indices
gridView_t gridView_;
//! Pointer to underlying IndexSet
const indexSet_t* indexSet_;
//! Storage for multiplicities
set_t multiplicities_;
//! Underlying GridViewFactory
const gridViewFactory_t gridViewFactory_;
//! Underlying GridView used for indices
gridView_t gridView_;
//! Pointer to underlying IndexSet
const indexSet_t* indexSet_;
}; // end class FEBasis
}; // end class TestFEBasis
/*! @} */
} // end namespace fe
} // end namespace ex
} // end namespace fe
} // end namespace betl2
#endif // BETL2_FE_FEBASIS_EXTENDED_HPP
......@@ -152,7 +152,7 @@ namespace betl2 {
linearCombination_t linearCombination_;
//! The finite element basis.
fe_basis_t febasis_;
const fe_basis_t febasis_;
public:
/*! @brief Constructor.
......
......@@ -56,6 +56,9 @@ namespace betl2 {
}; // end struct FEBasisWrapperTraits
} // end namespace detail
/*! @addtogroup febases
* @{
*/
/*! @brief A wrapper for fe::FEBasis
*
* This class provides an wrapper for the previous impementation of the
......@@ -198,6 +201,7 @@ namespace betl2 {
}
}; // end class FEBasisWrapper
/*! @} */
} // end namespace ex
} // end namespace fe
......
Supports Markdown
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