Skip to content
Snippets Groups Projects
Commit 4ae58aa7 authored by Robert Klöfkorn's avatar Robert Klöfkorn
Browse files

Moved the localfunctionarray.hh to discfuncarray.* because these things

belong together. Furthermore made some changes in localfunctionarray for
speedup.

[[Imported from SVN: r203]]
parent c741a489
No related branches found
No related tags found
No related merge requests found
......@@ -410,6 +410,96 @@ namespace Dune
std::cout << "Written Dof to file `" << filename << "' !\n";
}
template<class DiscreteFunctionSpaceType >
inline void DiscFuncArray< DiscreteFunctionSpaceType >::
addScaled( const DiscFuncArray<DiscreteFunctionSpaceType> &g,
const RangeField &scalar )
{
int level = functionSpace_.getGrid().maxlevel();
int length = dofVec_[level].size();
Array<RangeField> &v = dofVec_[level];
const Array<RangeField> &gvec = g.dofVec_[level];
for(int i=0; i<length; i++)
v[i] += scalar*gvec[i];
}
//**********************************************************************
// --LocalFunctionArray
//**********************************************************************
template<class DiscreteFunctionSpaceType >
inline LocalFunctionArray < DiscreteFunctionSpaceType >::
LocalFunctionArray( const DiscreteFunctionSpaceType &f ,
std::vector < Array < RangeField > > & dofVec )
: fSpace_ ( f ), dofVec_ ( dofVec ) , next_ (NULL)
, baseFuncSet_ (NULL)
, uniform_(true)
{}
template<class DiscreteFunctionSpaceType >
inline LocalFunctionArray < DiscreteFunctionSpaceType >::~LocalFunctionArray()
{
if(next_) delete next_;
}
template<class DiscreteFunctionSpaceType >
inline LocalFunctionArray < DiscreteFunctionSpaceType >::RangeField &
LocalFunctionArray < DiscreteFunctionSpaceType >::operator [] (int num)
{
return (* (values_[num]));
}
template<class DiscreteFunctionSpaceType >
inline int LocalFunctionArray < DiscreteFunctionSpaceType >::
numberOfDofs () const
{
return numOfDof_;
}
template<class DiscreteFunctionSpaceType > template <class EntityType>
inline void LocalFunctionArray < DiscreteFunctionSpaceType >::
evaluate (EntityType &en, const Domain & x, Range & ret)
{
ret = 0.0;
for(int i=0; i<numOfDof_; i++)
{
baseFuncSet_->evaluate(i,diffVar,x,tmp);
ret += this->operator [] (i) * tmp;
}
}
template<class DiscreteFunctionSpaceType >
inline LocalFunctionArray < DiscreteFunctionSpaceType > *
LocalFunctionArray < DiscreteFunctionSpaceType >::getNext () const
{
return next_;
}
template<class DiscreteFunctionSpaceType >
inline void LocalFunctionArray < DiscreteFunctionSpaceType >::
setNext (LocalFunctionArray < DiscreteFunctionSpaceType > *n)
{
next_ = n;
}
template<class DiscreteFunctionSpaceType > template <class EntityType>
inline void LocalFunctionArray < DiscreteFunctionSpaceType >::
init (EntityType &en )
{
if((!uniform_) || (!baseFuncSet_))
{
baseFuncSet_ = & ( fSpace_.getBaseFunctionSet(en) );
numOfDof_ = baseFuncSet_->getNumberOfBaseFunctions();
if(numOfDof_ > values_.size())
values_.resize( numOfDof_ );
}
for(int i=0; i<numOfDof_; i++)
values_ [i] = &((dofVec_[ en.level() ])[fSpace_.mapToGlobal ( en , i)]);
}
} // end namespace
#endif
......@@ -4,13 +4,18 @@
#define __DUNE_DISFUNCARRAY_HH__
#include "discretefunction.hh"
#include "localfunctionarray.hh"
#include "localfunction.hh"
#include "dofiterator.hh"
#include <fstream>
#include <rpc/xdr.h>
namespace Dune {
template <class DiscreteFunctionSpaceType > class LocalFunctionArray;
template < class DofType > class DofIteratorArray;
//**********************************************************************
//
// --DiscFuncArray
......@@ -78,6 +83,9 @@ namespace Dune {
void set( RangeField x );
void setLevel( RangeField x, int level );
void addScaled (const DiscFuncArray <DiscreteFunctionSpaceType> & g,
const RangeField &scalar);
//! print all dofs
void print(std::ostream& s, int level);
......@@ -151,7 +159,138 @@ namespace Dune {
//! for all level an Array < RangeField > , the data
std::vector < Array < RangeField > > dofVec_;
};
}; // end class DiscFuncArray
//**************************************************************************
//
// --LocalFunctionArray
//
//! Implementation of the local functions
//
//**************************************************************************
template < class DiscreteFunctionSpaceType >
class LocalFunctionArray
: public LocalFunctionDefault <DiscreteFunctionSpaceType ,
LocalFunctionArray < DiscreteFunctionSpaceType > >
{
typedef FastBaseFunctionSet < DiscreteFunctionSpaceType > BaseFunctionSetType;
typedef LocalFunctionArray < DiscreteFunctionSpaceType > MyType;
public:
//! Constructor
LocalFunctionArray ( const DiscreteFunctionSpaceType &f ,
std::vector < Array < RangeField > > & dofVec );
//! Destructor
~LocalFunctionArray ();
//! access to dof number num, all dofs of the dof entity
RangeField & operator [] (int num);
//! return number of degrees of freedom
int numberOfDofs () const;
//! sum over all local base functions
template <class EntityType>
void evaluate (EntityType &en, const Domain & x, Range & ret);
//! get pointer to next LocalFunction
MyType * getNext() const;
//! set pointer to next LocalFunction
void setNext (MyType * n);
//! methods that do not belong to the interface but have to be public
//! used like setElInfo and so on
template <class EntityType > void init ( EntityType &en);
protected:
//! needed once
Range tmp;
//! remember pointer to next LocalFunction
MyType * next_;
//! diffVar for evaluate, is empty
static const DiffVariable<0>::Type diffVar;
//! number of dofs
int numOfDof_;
//! the corresponding function space which provides the base function set
const DiscreteFunctionSpaceType &fSpace_;
//! Array holding pointers to the local dofs
Array < RangeField * > values_;
//! dofVec from all levels of the discrete function
std::vector < Array < RangeField > > & dofVec_;
//! do we have the same base function set for all elements
bool uniform_;
//! the corresponding base function set
BaseFunctionSetType *baseFuncSet_;
}; // end LocalFunctionArray
//***********************************************************************
//
// --DofIteratorArray
//
//***********************************************************************
template < class DofType >
class DofIteratorArray : public
DofIteratorDefault < DofType , DofIteratorArray < DofType > >
{
public:
DofIteratorArray ( Array < DofType > & dofArray , int count )
: dofArray_ ( dofArray ) , count_ ( count ) {};
DofType & operator *()
{
return dofArray_ [ count_ ];
};
DofIteratorType & operator++ ()
{
count_++;
return (*this);
};
DofIteratorType & operator++ (int i)
{
count_ += i;
return (*this);
};
DofType& operator[] (int i) {
return dofArray_[i];
}
bool operator == (const DofIteratorType & I ) const
{
return count_ == I.count_;
}
bool operator != (const DofIteratorType & I ) const
{
return count_ != I.count_;
}
int index () { return count_; }
void reset () { count_ = 0; };
private:
//! index
int count_;
//! the array holding the dofs
Array < DofType > &dofArray_;
}; // end DofIteratorArray
} // end namespace Dune
......
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