Skip to content
Snippets Groups Projects
Commit d58b3398 authored by Adrian Burri's avatar Adrian Burri
Browse files

new functionality

[[Imported from SVN: r2670]]
parent d694fcba
No related branches found
No related tags found
No related merge requests found
......@@ -2,41 +2,130 @@
// vi: set et ts=4 sw=2 sts=2:
namespace Dune {
template <class DiscreteFunctionSpaceImp, int N>
CombinedSpace<DiscreteFunctionSpaceImp, int N>::
CombinedSpace(DiscreteFunctionSpaceType& spc) :
spc_(spc)
template <class DiscreteFunctionSpaceImp, int N, DofStoragePolicy policy>
CombinedSpace<DiscreteFunctionSpaceImp, N, policy>::
CombinedSpace(ContainedDiscreteFunctionSpaceType& spc) :
BaseType(0),
spc_(spc),
mapper_(spc),
baseSetVec_(GeometryIdentifier::numTypes, 0)
{
// * more to come
// * initialise your basefunction set
// initialise your basefunction set with all Geometry types found in mesh
IteratorType endit = spc.end();
for (IteratorType it = spc.begin(); it != endit; ++it) {
GeometryType geo = it->geometry().type();
const int dimension =
static_cast<int>(IteratorType::Entity::mydimension);
GeometryIdentifier::IdentifierType id =
GeometryIdentifier::fromGeo(dimension, geo);
if (baseSetVec_[id] == 0) {
baseSetVec_[id] = new BaseFunctionSetType(spc.getBaseFunctionSet(*it));
}
} // end for
// * initialise your mapper
}
template <class DiscreteFunctionSpaceImp, int N, DofStoragePolicy policy>
CombinedSpace<DiscreteFunctionSpaceImp, N, policy>::
~CombinedSpace()
{
for (int i = 0; i < baseSetVec_.size(); ++i) {
delete baseSetVec_[i];
baseSetVec_[i] = 0;
}
}
template <class BaseFunctionSetImp, int N>
template <class BaseFunctionSetImp, int N, DofStoragePolicy policy>
template <int diffOrd>
void CombinedBaseFunctionSet<BaseFunctionSetImp, int N>::
void CombinedBaseFunctionSet<BaseFunctionSetImp, N, policy>::
evaluate (int baseFunct,
const FieldVector<deriType, diffOrd> &diffVariable,
const DomainType & x, RangeType & phi ) const {
expand(containedResult_, phi);
const DomainType & x, RangeType & phi ) const
{
baseFunctionSet_.evaluate(containedDof(baseFunct),
diffVariable, x, containedResult_);
expand(baseFunct, containedResult_, phi);
}
template <class BaseFunctionSetImp, int N>
template <class BaseFunctionSetImp, int N, DofStoragePolicy policy>
template <int diffOrd, class QuadratureType>
void CombinedBaseFunctionSet<BaseFunctionSetImp, int N>::
void CombinedBaseFunctionSet<BaseFunctionSetImp, N, policy>::
evaluate (int baseFunct,
const FieldVector<deriType, diffOrd> &diffVariable,
QuadratureType & quad,
int quadPoint, RangeType & phi ) const {
int quadPoint, RangeType & phi ) const
{
baseFunctionSet_.evaluate(containedDof(baseFunct), diffVariable,
quad, quadPoint, containedResult_);
expand(baseFunct, containedResult_, phi);
}
expand(containedResult_, phi);
template <class BaseFunctionSetImp, int N, DofStoragePolicy policy>
int CombinedBaseFunctionSet<BaseFunctionSetImp, N, policy>::
containedDof(int combinedBaseNumber) const {
//return global%N;
return combinedBaseNumber/N;
}
template <class BaseFunctionSetImp, int N>
void CombinedBaseFunctionSet<BaseFunctionSetImp, int N>::
expand(const ContainedRangeType& arg, RangeType& dest) const {}
template <class BaseFunctionSetImp, int N, DofStoragePolicy policy>
int CombinedBaseFunctionSet<BaseFunctionSetImp, N, policy>::
component(int combinedBaseNumber) const {
//return global%N;
return combinedBaseNumber%N;
}
template <class BaseFunctionSetImp, int N, DofStoragePolicy policy>
void CombinedBaseFunctionSet<BaseFunctionSetImp, N, policy>::
expand(int baseFunct, const ContainedRangeType& arg, RangeType& dest) const
{
dest = 0.0;
assert(arg.dim() == 1); // only DimRange == 1 allowed
dest[component(baseFunct)] = arg[0];
}
template <class DiscreteFunctionSpaceImp, int N, DofStoragePolicy policy>
int CombinedMapper<DiscreteFunctionSpaceImp, N, policy>::size() const {
return spc_.size()*N;
}
template <class DiscreteFunctionSpaceImp, int N, DofStoragePolicy policy>
template <class EntityType>
int CombinedMapper<DiscreteFunctionSpaceImp, N, policy>::
mapToGlobal(EntityType& en, int localNum) const {
return mapToGlobal(en, localNum, Int2Type<policy>());
}
template <class DiscreteFunctionSpaceImp, int N, DofStoragePolicy policy>
template <class EntityType>
int CombinedMapper<DiscreteFunctionSpaceImp, N, policy>::
mapToGlobal(EntityType& en, int localNum, Int2Type<PointBased>) const {
const int offset = spc_.mapToGlobal(en, containedDof(localNum))*N;
const int local = component(localNum);
return offset + local;
}
template <class DiscreteFunctionSpaceImp, int N, DofStoragePolicy policy>
template <class EntityType>
int CombinedMapper<DiscreteFunctionSpaceImp, N, policy>::
mapToGlobal(EntityType& en, int localNum, Int2Type<VariableBased>) const {
const int offset = component(localNum)*spc_.size();
const int local = spc_.mapToGlobal(en, containedDof(localNum));
return offset + local;
}
template <class DiscreteFunctionSpaceImp, int N, DofStoragePolicy policy>
int CombinedMapper<DiscreteFunctionSpaceImp, N, policy>::
containedDof(int localNum) const {
return localNum/N;
//return localNum%numBaseLoc_;
}
template <class DiscreteFunctionSpaceImp, int N, DofStoragePolicy policy>
int CombinedMapper<DiscreteFunctionSpaceImp, N, policy>::
component(int localNum) const {
return localNum%N;
//return localNum/numBaseLoc_;
}
} // end namespace Dune
......@@ -10,64 +10,108 @@
#include <dune/fem/common/discretefunctionspace.hh>
#include <dune/fem/common/basefunctions.hh>
#include <dune/fem/common/dofmapperinterface.hh>
#include <dune/common/misc.hh>
namespace Dune {
// Note: the methods component and contained dof do actually the same
// in the Mapper and in the BaseFunctionSet. It would be a good idea to
// factor them out in a common class (private inheritance? BaseFunctionSet
// provides them for the mapper?
//! Indicates how the dofs shall be stored in the discrete functions
//! Point based means that all dofs belonging to one local degree in a
//! contained spaced are stored consecutively, whereas in the variable based
//! approach all dofs belonging to one subspace are stored consecutively
enum DofStoragePolicy { PointBased, VariableBased };
// Forward declarations
template <class DiscreteFunctionSpaceImp, int N>
class CombinedSpaceange;
template <class DiscreteFunctionSpaceImp, int N>
template <class DiscreteFunctionSpaceImp, int N, DofStoragePolicy policy>
class CombinedSpace;
template <class DiscreteFunctionSpaceImp, int N, DofStoragePolicy policy>
class CombinedMapper;
//template <class BaseFunctionImp, int N>
//class CombinedBaseFunction;
template <class BaseFunctionSetImp, int N>
template <class BaseFunctionSetImp, int N, DofStoragePolicy policy>
class CombinedBaseFunctionSet;
template <class DiscreteFunctionSpaceImp, int N>
template <class DiscreteFunctionSpaceImp, int N, DofStoragePolicy policy>
struct CombinedSpaceTraits {
private:
typedef DiscreteFunctionSpaceImp ContainedDiscreteFunctionSpaceType;
typedef ContainedDiscreteFunctionSpaceType::MapperType ContainedMapperType;
typedef typename ContainedDiscreteFunctionSpaceType::Traits ContainedTraits;
typedef typename ContainedTraits::FunctionSpaceType ContainedFunctionSpaceType;
typedef typename ContainedTraits::BaseFunctionSetType ContainedBaseFunctionSetType;
enum { ContainedDimRange = ContainedFunctionSpace::DimRange,
ContainedDimDomain = ContainedFunctionSpace::DimDomain };
// typedef ContainedDiscreteFunctionSpaceType::MapperType ContainedMapperType;
typedef typename ContainedDiscreteFunctionSpaceType::Traits
ContainedTraits;
typedef typename ContainedTraits::FunctionSpaceType
ContainedFunctionSpaceType;
typedef typename ContainedTraits::BaseFunctionSetType
ContainedBaseFunctionSetType;
enum { ContainedDimRange = ContainedFunctionSpaceType::DimRange,
ContainedDimDomain = ContainedFunctionSpaceType::DimDomain };
public:
typedef typename ContainedFunctionSpace::DomainFieldType DomainFieldType;
typedef typename ContainedFunctionSpace::RangeFieldType RangeFieldType;
typedef typename ContainedFunctionSpaceType::DomainFieldType
DomainFieldType;
typedef typename ContainedFunctionSpaceType::RangeFieldType
RangeFieldType;
// * Require contained space to have dimRange == 1? (ie to be scalar)
typedef FunctionSpace<
DomainFieldType, RangeFieldType,
ContainedDimDomain, ContainedDimRange*N
> FunctionSpaceType;
typedef typename FunctionSpaceType::RangeType RangeType;
typedef typename FunctionSpaceType::DomainType DomainType;
typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
typedef typename FunctionSpaceType::DomainFieldType DomainFieldType;
typedef CombinedSpace<
DiscreteFunctionSpaceImp, N
DiscreteFunctionSpaceImp, N, policy
> DiscreteFunctionSpaceType;
typedef typename ContainedTraits::GridType GridType;
typedef typename ContainedTraits::IteratorType IteratorType;
typedef CombinedBaseFunctionSet<ContainedBaseFunctionSetType, N> BaseFunctionSetType;
typedef CombinedBaseFunctionSet<
ContainedBaseFunctionSetType, N, policy
> BaseFunctionSetType;
friend class DiscreteFunctionSpaceType;
};
template <class DiscreteFunctionSpaceImp, int N>
template <class DiscreteFunctionSpaceImp, int N, DofStoragePolicy policy>
class CombinedSpace :
public DiscreteFunctionSpaceDefault<
CombinedSpaceTraits<DiscreteFunctionSpaceImp, N>
CombinedSpaceTraits<DiscreteFunctionSpaceImp, N, policy>
>
{
private:
//- Private typedefs
typedef CombinedMapper<DiscreteFunctionSpaceImp, N, policy> MapperType;
typedef DiscreteFunctionSpaceDefault<
CombinedSpaceTraits<DiscreteFunctionSpaceImp, N, policy>
> BaseType;
public:
//- Public typedefs and enums
typedef CombinedSpaceTraits<DiscreteFunctionSpaceImp, N> Traits;
typedef CombinedSpace<DiscreteFunctionSpaceImp, N, policy> ThisType;
typedef CombinedSpaceTraits<DiscreteFunctionSpaceImp, N, policy> Traits;
typedef DiscreteFunctionSpaceImp ContainedDiscreteFunctionSpaceType;
typedef typename Traits::IteratorType IteratorType;
typedef typename Traits::RangeType RangeType;
typedef typename Traits::DomainType DomainType;
typedef typename Traits::RangeFieldType RangeFieldType;
typedef typename Traits::DomainFieldType DomainFieldType;
public:
//- Public methods
//! constructor
CombinedSpace(ContainedDiscreteFunctionSpaceType& spc);
//! destructor
~CombinedSpace();
//! continuous?
bool continuous() const { return spc_.continous(); }
//! begin iterator
IteratorType begin() const { return spc_.begin(); }
......@@ -80,113 +124,89 @@ namespace Dune {
//! map a local dof number to a global one
template <class EntityType>
int mapToGlobal(EntityType& en, int local) const {
mapper_.mapToGlobal(en, localNum);
mapper_.mapToGlobal(en, local);
}
template <class EntityType>
const BaseFunctionSetType& getBaseFunctionSet(EntityType& en) const {
// * More to come
return ? ?;
const BaseFunctionSetType& getBaseFunctionSet(EntityType& en) const
{
GeometryType geo = en.geometry().type();
int dimension = static_cast<int>(EntityType::mydimension);
return *baseSetVec_[GeometryIdentifier::fromGeo(dimension, geo)];
}
GridType& grid() { return spc_.grid(); }
const GridType& grid() const { return spc_.grid(); }
template <class DiscFuncType>
typename DiscFuncType::MemObjectType &
signIn(DiscFuncType & df) const { return spc_.signIn(df); }
//! sign out to dofmanager, dofmanager frees the memory
template <class DiscFuncType>
bool signOut ( DiscFuncType & df) const { return spc_.signOut(df); }
private:
//- Private typedefs
private:
//- Private methods
CombinedSpace(const ThisType& other);
private:
//- Member data
DiscreteFunctionSpaceType& spc_;
ContainedDiscreteFunctionSpaceType& spc_;
MapperType mapper_;
std::vector<BaseFunctionSetType*> baseSetVec_;
}; // end class CombinedSpace
/* Probably not needed
template <class BaseFunctionImp, int N>
class CombinedBaseFunction :
public BaseFunctionInterface<
CombinedSpace<typename BaseFunctionImp::FunctionSpaceType, N>
>
{
public:
//- Typedefs and enums
typedef CombinedSpace<typename BaseFunctionImp::FunctionSpaceType, N> DisreteFunctionSpaceType;
typedef BaseFunctionImp ContainedBaseFunctionType;
typedef ... DomainType;
typedef ... RangeType;
public:
//- Public methods
CombinedBaseFunction(const ContainedBaseFunctionType& bf) :
containedBaseFunction_(bf) {}
//! evaluate the function at DomainType x, and store the value in Range Phi
//! diffVariable stores information about which gradient is to be
//! evaluated. In the derived classes the evaluate method are template
//! methods with template parameter "length of Vec".
//! Though the evaluate Methods can be spezialized for each
//! differentiation order
//! \param x The local coordinate in the reference element
virtual void evaluate ( const FieldVector<deriType, 0> &diffVariable,
const DomainType& x, RangeType& result);
//! diffVariable contain the component of the gradient which is delivered.
//! for example gradient of the basefunction x component ==>
//! diffVariable(0) == 0, y component ==> diffVariable(0) == 1 ...
virtual void evaluate ( const FieldVector<deriType, 1> &diffVariable,
const DomainType& x, RangeType& result) const;
virtual void evaluate ( const FieldVector<deriType, 2> &diffVariable,
const DomainType& x, RangeType& result) const;
private:
//- Private typedefs
typedef ... ContainedRangeType;
private:
//- Private methods
void expand(const ContainedRangeType& arg, RangeType& result) const;
private:
//- Data members
const ContainedBaseFunctionType& containedBaseFunction_;
};
*/
template <class BaseFunctionSetImp, int N>
template <class BaseFunctionSetImp, int N, DofStoragePolicy policy>
struct CombinedBaseFunctionSetTraits {
private:
typedef typename BaseFunctionSetImp::DiscreteFunctionSpaceType ContainedFunctionSpaceType;
typedef typename BaseFunctionSetImp::DiscreteFunctionSpaceType
ContainedFunctionSpaceType;
public:
typedef CombinedBaseFunctionSet<BaseFunctionSetImp, N> BaseFunctionSetType;
typedef CombinedSpace<ContainedFunctionSpaceType, N> DiscreteFunctionSpaceType;
typedef CombinedBaseFunctionSet<BaseFunctionSetImp, N, policy>
BaseFunctionSetType;
typedef CombinedSpace<ContainedFunctionSpaceType, N, policy>
DiscreteFunctionSpaceType;
typedef DiscreteFunctionSpaceType::RangeType RangeType;
typedef DiscreteFunctionSpaceType::DomainType DomainType;
typedef typename DiscreteFunctionSpaceType::JacobianRangeType JacobianRangeType;
typedef typename DiscreteFunctionSpaceType::HessianRangeType HessianRangeType;
typedef typename DiscreteFunctionSpaceType::JacobianRangeType
JacobianRangeType;
typedef typename DiscreteFunctionSpaceType::HessianRangeType
HessianRangeType;
enum { DimDomain = DiscreteFunctionSpaceType::DimDomain };
enum { DimRange = DiscreteFunctionSpaceType::DimRange };
};
template <class BaseFunctionSetImp, int N>
template <class BaseFunctionSetImp, int N, DofStoragePolicy policy>
class CombinedBaseFunctionSet :
public BaseFunctionSetDefault<
CombinedBaseFunctionSetTraits<BaseFunctionSetImp, int N>
CombinedBaseFunctionSetTraits<BaseFunctionSetImp, N, policy>
>
{
private:
//- Private typedefs
typedef BaseFunctionSetImp ContainedBaseFunctionSetType;
typedef ContainedBaseFunctionSetType::RangeType ContainedRangeType;
public:
//- Typedefs and enums
typedef CombinedBaseFunctionSetTraits<BaseFunctionSetImp, N> Traits;
enum { numComponents = N };
typedef CombinedBaseFunctionSet<BaseFunctionSetImp, N, policy> ThisType;
typedef CombinedBaseFunctionSetTraits<BaseFunctionSetImp, N, policy> Traits;
typedef typename Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
typedef typename Traits::RangeType RangeType;
typedef typename Traits::DomainType DomainType;
public:
//- Public methods
......@@ -209,37 +229,72 @@ namespace Dune {
const FieldVector<deriType, diffOrd> &diffVariable,
QuadratureType & quad,
int quadPoint, RangeType & phi ) const;
private:
//- Private methods
void expand(const ContainedRangeType& arg, RangeType& dest) const ;
CombinedBaseFunctionSet(const ThisType& other);
int containedDof(int combinedDofNum) const;
int component(int combinedDofNum) const;
void expand(int baseFunct,
const ContainedRangeType& arg,
RangeType& dest) const;
private:
//- Data members
mutable ContainedRangeType containtedResult_;
mutable ContainedRangeType containedResult_;
const ContainedBaseFunctionSetType& baseFunctionSet_;
};
}; // end class CombinedBaseFunctionSet
template <class DiscreteFunctionSpaceImp, int N>
class CombinedMapper :
public DofMapperDefault<CombinedMapper<DiscreteFunctionSpaceImp, int N> >
template <class DiscreteFunctionSpaceImp, int N, DofStoragePolicy policy>
class CombinedMapper : public DofMapperDefault<
CombinedMapper<DiscreteFunctionSpaceImp, N, policy>
>
{
public:
//- Typedefs and enums
enum { numComponents = N };
typedef CombinedMapper<DiscreteFunctionSpaceImp, N, policy> ThisType;
typedef typename CombinedSpaceTraits<DiscreteFunctionSpaceImp, N, policy> SpaceTraits;
typedef DiscreteFunctionSpaceImp ContainedDiscreteFunctionSpaceType;
public:
//- Public methods
CombinedMapper(const ContainedDiscreteFunctionSpaceType& spc) :
spc_(spc)
{}
int size() const;
template <class EntityType>
int mapToGlobal(EntityType& en, int localNum) const;
private:
//- Private methods
CombinedMapper(const ThisType& other);
template <class EntityType>
int mapToGlobal(EntityType& en, int localNum, Int2Type<PointBased>) const;
template <class EntityType>
int mapToGlobal(EntityType& en, int localNum, Int2Type<VariableBased>) const;
int containedDof(int combinedDofNum) const;
int component(int combinedDofNum) const;
private:
//- Data members
const ContainedDiscreteFunctionSpaceType& spc_;
};
// include implementation
#include "combinedspace.cc"
//int numBaseLoc_;
}; // end class CombinedMapper
} // end namespace Dune
// include implementation
#include "combinedspace.cc"
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment