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

Further removals.

[[Imported from SVN: r4430]]
parent da9a09d0
No related branches found
No related tags found
No related merge requests found
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_DFADAPT_HH
#define DUNE_DFADAPT_HH
#include "dune/common/array.hh"
#include "common/discretefunction.hh"
#include "common/fastbase.hh"
#include "common/localfunction.hh"
#include "common/dofiterator.hh"
#include "dune/common/geometrytype.hh"
#include "dofmanager.hh"
#include <fstream>
#include <rpc/xdr.h>
namespace Dune {
template <class DiscreteFunctionSpaceImp> class LocalFunctionAdapt;
template <class DofType, class DofArrayType> class DofIteratorAdapt;
template <class DiscreteFunctionSpaceImp> class DFAdapt;
template <class DiscreteFunctionSpaceImp>
struct DFAdaptTraits {
typedef DiscreteFunctionSpaceImp DiscreteFunctionSpaceType;
typedef DFAdapt<DiscreteFunctionSpaceImp> DiscreteFunctionType;
typedef LocalFunctionAdapt<DiscreteFunctionSpaceImp> LocalFunctionImp;
typedef LocalFunctionWrapper< DiscreteFunctionType > LocalFunctionType;
typedef typename DofArray<
typename DiscreteFunctionSpaceImp::RangeFieldType
>::DofIteratorType DofIteratorType;
typedef typename DofArray<
typename DiscreteFunctionSpaceImp::RangeFieldType
>::ConstDofIteratorType ConstDofIteratorType;
};
//**********************************************************************
//
// --DFAdapt
//
//! this is one special implementation of a discrete function using an
//! array for storing the dofs.
//!
//**********************************************************************
template<class DiscreteFunctionSpaceType>
class DFAdapt
: public DiscreteFunctionDefault<
DFAdaptTraits<DiscreteFunctionSpaceType>
>
{
public:
typedef typename DiscreteFunctionSpaceType::RangeFieldType RangeFieldType;
typedef DofArray< RangeFieldType > DofArrayType;
private:
typedef DiscreteFunctionDefault<
DFAdaptTraits<DiscreteFunctionSpaceType>
> DiscreteFunctionDefaultType;
friend class DiscreteFunctionDefault< DFAdaptTraits<DiscreteFunctionSpaceType> >;
enum { myId_ = 0};
public:
typedef typename DiscreteFunctionSpaceType::GridType GridType;
typedef DofManager<GridType> DofManagerType;
typedef DofManagerFactory<DofManagerType> DofManagerFactoryType;
typedef typename DiscreteFunctionSpaceType::Traits::MapperType MapperType;
typedef typename DiscreteFunctionSpaceType::Traits::RangeFieldType DofType;
typedef typename DofArrayType::DofIteratorType DofIteratorType;
typedef typename DofArrayType::ConstDofIteratorType ConstDofIteratorType;
typedef DofArrayType DofStorageType;
typedef MemObjectInterface MemObjectInterfaceType;
//! type of this class
typedef DFAdapt <DiscreteFunctionSpaceType> DiscreteFunctionType;
//! LocalFunctionImp is the implementation
typedef LocalFunctionAdapt < DiscreteFunctionSpaceType > LocalFunctionImp;
//! LocalFunctionType is the exported lf type
typedef LocalFunctionWrapper < DiscreteFunctionType > LocalFunctionType;
typedef DiscreteFunctionSpaceType FunctionSpaceType;
typedef DFAdaptTraits<DiscreteFunctionSpaceType> Traits;
/** \brief For ISTL-compatibility */
typedef FieldVector<DofType,1> block_type;
typedef LocalFunctionStorage< DiscreteFunctionType > LocalFunctionStorageType;
public:
//! Constructor make Discrete Function
DFAdapt(const DiscreteFunctionSpaceType& f);
//! Constructor creating discrete functions with name name
//! for given functions space f
DFAdapt (std::string name, const DiscreteFunctionSpaceType & f ) ;
//! Constructor creating discrete functions with name name
//! for given functions space f and using given double * as vector
//! VectorPointerType should be of the underlying array pointer type
template <class VectorPointerType>
DFAdapt (std::string name, const DiscreteFunctionSpaceType & f , VectorPointerType * vec ) ;
//! Constructor make Discrete Function
DFAdapt (const DFAdapt <DiscreteFunctionSpaceType> & df);
//! delete stack of free local functions belonging to this discrete
//! function
~DFAdapt ();
DiscreteFunctionType & argument () { return *this; }
const DiscreteFunctionType & argument () const { return *this; }
DiscreteFunctionType & destination () { return *this; }
// *********** Interface *************************
//! return empty object of a local fucntion
//! old function, will be removed soon
inline
LocalFunctionType newLocalFunction () DUNE_DEPRECATED;
//! return local function for given entity
template <class EntityType>
inline
LocalFunctionType localFunction(const EntityType& en) const;
//! update LocalFunction to given Entity en
//! old function, will be removed soon
template <class EntityType>
inline
void localFunction ( const EntityType &en, LocalFunctionType & lf) DUNE_DEPRECATED;
//! points to the first dof of type cc
inline
DofIteratorType dbegin ( );
//! points behind the last dof of type cc
inline
DofIteratorType dend ( );
//! const version of dof iterator
inline
ConstDofIteratorType dbegin ( ) const;
//! const version of dof iterator
inline
ConstDofIteratorType dend ( ) const;
//! set all dofs to zero
inline
void clear( );
//! set all dof to value x
inline
void set( RangeFieldType x );
//! \todo Please do me!
inline
void addScaled (const DFAdapt <DiscreteFunctionSpaceType> & g,
const RangeFieldType &scalar);
//! \todo Please do me!
template <class EntityType>
inline
void addScaledLocal (EntityType &en,
const DFAdapt <DiscreteFunctionSpaceType> & g,
const RangeFieldType &scalar);
//! add g to this on local entity
template <class EntityType>
inline
void addLocal (EntityType &it,
const DFAdapt <DiscreteFunctionSpaceType> & g);
//! add g to this on local entity
template <class EntityType>
inline
void subtractLocal (EntityType &it,
const DFAdapt <DiscreteFunctionSpaceType> & g);
//! \todo Please do me!
template <class EntityType>
inline
void setLocal (EntityType &it, const RangeFieldType &scalar);
//! print all dofs
inline
void print(std::ostream& s) const;
//! write data of discrete function to file filename|timestep
//! with xdr methods
inline
bool write_xdr(std::string filename);
//! write data of discrete function to file filename|timestep
//! with xdr methods
inline
bool read_xdr(std::string filename);
//! write function data to file filename|timestep in ascii Format
inline
bool write_ascii(std::string filename);
//! read function data from file filename|timestep in ascii Format
inline
bool read_ascii(std::string filename);
//! write function data in pgm fromat file
inline
bool write_pgm(std::string filename);
//! read function data from pgm fromat file
inline
bool read_pgm(std::string filename);
//! return name of this discrete function
std::string name () const { return name_; }
//! return siz fo this discrete function
int size() const { return dofVec_.size(); }
//! return pointer to internal array for use of BLAS routines
DofType * leakPointer () { return dofVec_.leakPointer(); };
//! return pointer to internal array for use of BLAS routines
const DofType * leakPointer () const { return dofVec_.leakPointer(); };
private:
//! return object pointer of type LocalFunctionImp
LocalFunctionImp * newLocalFunctionObject () const;
// name of this func
std::string name_;
// DofManager
DofManager<GridType>& dm_;
// MemObject that manages the memory for the dofs of this function
std::pair<MemObjectInterface*, DofStorageType*> memPair_;
//! array containing the dof of this function, see dofmanager.hh
//! the array is stored within the mem object
DofArrayType & dofVec_;
// one local function
LocalFunctionType localFunc_;
}; // end class DFAdapt
//**************************************************************************
//
// --LocalFunctionAdapt
//
//! Implementation of the local functions
//
//**************************************************************************
template < class DiscreteFunctionSpaceType>
class LocalFunctionAdapt
: public LocalFunctionDefault <DiscreteFunctionSpaceType ,
LocalFunctionAdapt <DiscreteFunctionSpaceType> >
{
public:
typedef typename DiscreteFunctionSpaceType::BaseFunctionSetType BaseFunctionSetType;
typedef LocalFunctionAdapt<DiscreteFunctionSpaceType> MyType;
typedef DFAdapt<DiscreteFunctionSpaceType> DiscFuncType;
friend class LocalFunctionWrapper< DiscFuncType >;
enum { dimrange = DiscreteFunctionSpaceType::DimRange };
friend class DFAdapt <DiscreteFunctionSpaceType>;
typedef typename DiscreteFunctionSpaceType::Traits::RangeFieldType RangeFieldType;
typedef typename DiscreteFunctionSpaceType::Traits::DomainType DomainType;
typedef typename DiscreteFunctionSpaceType::Traits::RangeType RangeType;
typedef RangeFieldType DofType;
typedef typename DiscreteFunctionSpaceType::Traits::JacobianRangeType JacobianRangeType;
typedef typename DiscFuncType::DofArrayType DofArrayType;
typedef typename DiscreteFunctionSpaceType::GridType GridType;
typedef typename GridType::Traits::LocalIdSet LocalIdSetType;
typedef typename LocalIdSetType::IdType IdType;
//! Constructor
public:
inline
LocalFunctionAdapt ( const DiscreteFunctionSpaceType &f ,
DofArrayType & dofVec );
//! Destructor
inline
~LocalFunctionAdapt ();
//! access to dof number num, all dofs of the dof entity
inline
RangeFieldType & operator [] (int num);
//! access to dof number num, all dofs of the dof entity
inline
const RangeFieldType & operator [] (int num) const;
//! return number of degrees of freedom
inline
int numberOfDofs () const DUNE_DEPRECATED;
//! return number of degrees of freedom
inline
int numDofs () const;
//! sum over all local base functions
template <class EntityType>
inline
void evaluate (EntityType &en, const DomainType & x, RangeType & ret) const ;
template <class EntityType>
inline
void evaluateLocal(EntityType &en, const DomainType & x, RangeType & ret) const ;
//! sum over all local base functions evaluated on given quadrature point
template <class EntityType, class QuadratureType>
inline
void evaluate (EntityType &en, QuadratureType &quad, int quadPoint , RangeType & ret) const;
//! sum over all local base functions evaluated on given quadrature point
template <class EntityType, class QuadratureType>
inline
void jacobian (EntityType &en, QuadratureType &quad, int quadPoint , JacobianRangeType & ret) const;
template <class EntityType>
inline
void jacobianLocal(EntityType& en, const DomainType& x, JacobianRangeType& ret) const ;
template <class EntityType>
inline
void jacobian(EntityType& en, const DomainType& x, JacobianRangeType& ret) const;
inline
void assign(int numDof, const RangeType& dofs);
inline
const BaseFunctionSetType& getBaseFunctionSet() const;
protected:
//! update local function for given Entity
template <class EntityType >
inline
void init ( const EntityType &en ) const;
//! Forbidden! Would wreak havoc
LocalFunctionAdapt(const LocalFunctionAdapt&);
inline
MyType& operator= (const MyType& other);
//! needed once
mutable RangeType tmp_;
mutable DomainType xtmp_;
//! needed once
mutable JacobianRangeType tmpGrad_;
//! diffVar for evaluate, is empty
const DiffVariable<0>::Type diffVar;
//! number of all dofs
mutable int numOfDof_;
//! the corresponding function space which provides the base function set
const DiscreteFunctionSpaceType& fSpace_;
//! Array holding pointers to the local dofs
mutable Array < RangeFieldType * > values_;
//! dofVec from all levels of the discrete function
DofArrayType & dofVec_;
//! the corresponding base function set
mutable const BaseFunctionSetType* baseSet_;
//! is it initialised?
mutable bool init_;
//! actual geometry type
mutable GeometryType geoType_;
//! id of last initialized entity
//mutable IdType id_;
//! corresponding local id set
//const LocalIdSetType& idSet_;
}; // end LocalFunctionAdapt
} // end namespace Dune
#include "discfuncarray/dfadapt.cc"
#endif
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_DISCFUNCARRAY_HH
#define DUNE_DISCFUNCARRAY_HH
#include <dune/common/array.hh>
#include "common/discretefunction.hh"
#include "common/fastbase.hh"
#include "common/localfunction.hh"
#include "common/dofiterator.hh"
#include <fstream>
#include <rpc/xdr.h>
namespace Dune {
template<class DiscreteFunctionSpaceType , class CoeffStorageImp = Array<typename DiscreteFunctionSpaceType::RangeFieldType> > class DiscFuncArray;
template <class DiscreteFunctionSpaceType, class CoeffStorageImp > class LocalFunctionArray;
template <class DofType> class DofIteratorArray;
template <class DiscreteFunctionSpaceImp, class CoeffStorageImp>
struct DiscFuncArrayTraits {
typedef CoeffStorageImp CoeffStorageType;
typedef DiscreteFunctionSpaceImp DiscreteFunctionSpaceType;
typedef DiscFuncArray<DiscreteFunctionSpaceImp> DiscreteFunctionType;
typedef LocalFunctionArray<DiscreteFunctionSpaceImp,CoeffStorageType> LocalFunctionImp;
typedef LocalFunctionWrapper<DiscreteFunctionType> LocalFunctionType;
typedef DofIteratorArray<typename DiscreteFunctionSpaceImp::RangeFieldType> DofIteratorType;
typedef ConstDofIteratorDefault<DofIteratorType> ConstDofIteratorType;
};
//**********************************************************************
//
// --DiscFuncArray
//
//! this is one special implementation of a discrete function using an
//! array for storing the dofs.
//!
//**********************************************************************
template<class DiscreteFunctionSpaceType, class CoeffStorageImp >
class DiscFuncArray
: public DiscreteFunctionDefault <DiscFuncArrayTraits<DiscreteFunctionSpaceType,CoeffStorageImp> >
{
typedef DiscreteFunctionDefault<DiscFuncArrayTraits <DiscreteFunctionSpaceType,CoeffStorageImp> >
DiscreteFunctionDefaultType;
friend class DiscreteFunctionDefault< DiscFuncArrayTraits <DiscreteFunctionSpaceType,CoeffStorageImp > > ;
enum { myId_ = 0};
public:
//! type of underlying array
typedef CoeffStorageImp CoeffStorageType;
//! my type
typedef DiscFuncArray < DiscreteFunctionSpaceType, CoeffStorageType > DiscreteFunctionType;
//! Type of the range field
typedef typename DiscreteFunctionSpaceType::Traits::RangeFieldType RangeFieldType;
/** \brief For ISTL-compatibility */
typedef FieldVector<RangeFieldType,1> block_type;
//! Type of the grid
typedef typename DiscreteFunctionSpaceType::Traits::GridType GridType;
//! the local function implementation e
typedef LocalFunctionArray<DiscreteFunctionSpaceType,CoeffStorageType> LocalFunctionImp;
//! LocalFunctionType is the exported lf type
typedef LocalFunctionWrapper < DiscreteFunctionType > LocalFunctionType;
// the storage of the local functions
typedef LocalFunctionStorage< DiscreteFunctionType > LocalFunctionStorageType;
//! the dof iterator type of this function
typedef DofIteratorArray <typename DiscreteFunctionSpaceType::RangeFieldType> DofIteratorType;
typedef ConstDofIteratorDefault<DofIteratorType> ConstDofIteratorType;
//! The associated discrete function space
typedef DiscreteFunctionSpaceType FunctionSpaceType;
//! our traits, like DofIterator etc.
typedef DiscFuncArrayTraits <DiscreteFunctionSpaceType,CoeffStorageImp > Traits;
//! the type of the unknowns
typedef RangeFieldType DofType;
//! Constructor makes Discrete Function
DiscFuncArray ( const DiscreteFunctionSpaceType & f ) ;
//! Constructor makes Discrete Function with name
DiscFuncArray ( const char * name, const DiscreteFunctionSpaceType & f ) ;
//! Constructor makes Discrete Function from copy
DiscFuncArray (const DiscFuncArray <DiscreteFunctionSpaceType> & df);
//! delete stack of free local functions belonging to this discrete
//! function
~DiscFuncArray ();
// *********** Interface *************************
//! return object of type LocalFunctionType
LocalFunctionType newLocalFunction () DUNE_DEPRECATED;
//! return local function for given entity
template <class EntityType>
LocalFunctionType localFunction(const EntityType& en) const;
//! update LocalFunction to given Entity en
template <class EntityType>
void localFunction ( const EntityType &en, LocalFunctionType & lf) DUNE_DEPRECATED;
//! return reference to this
//! this methods is only to fullfill the interface as parameter classes
DiscreteFunctionType & argument () { return *this; }
//! return reference to this
//! this methods is only to fullfill the interface as parameter classes
const DiscreteFunctionType & argument () const { return *this; }
//! return reference to this
//! this methods is only to fullfill the interface as parameter classes
DiscreteFunctionType & destination () { return *this; }
//! we use the default implementation
DofIteratorType dbegin ();
//! points behind the last dof of type cc
DofIteratorType dend ();
//! the const versions
//! we use the default implementation
ConstDofIteratorType dbegin () const;
//! points behind the last dof of type cc
ConstDofIteratorType dend () const;
//! Return the name of the discrete function
const std::string& name() const {return name_;}
//! return size of this discrete function
int size() const { return dofVec_.size(); }
//! set all dofs to zero
void clear( );
//! set all dof to value x
void set( RangeFieldType x );
//! add g * scalar to discrete function
void addScaled ( const DiscFuncArray
<DiscreteFunctionSpaceType,CoeffStorageImp> & g,
const RangeFieldType &scalar);
/** \todo Please to me! */
template <class GridIteratorType>
void addScaledLocal (GridIteratorType &it,
const DiscFuncArray <DiscreteFunctionSpaceType,CoeffStorageImp> & g,
const RangeFieldType &scalar);
//! add g to this on local entity
template <class GridIteratorType>
void addLocal (GridIteratorType &it,
const DiscFuncArray <DiscreteFunctionSpaceType,CoeffStorageImp> & g);
//! add g to this on local entity
template <class GridIteratorType>
void substractLocal (GridIteratorType &it,
const DiscFuncArray <DiscreteFunctionSpaceType,CoeffStorageImp> & g);
/** \todo Please to me! */
template <class GridIteratorType>
void setLocal (GridIteratorType &it, const RangeFieldType &scalar);
//! print all dofs
void print(std::ostream& s) const;
//! write data of discrete function to file filename
//! with xdr methods
bool write_xdr( const char *filename );
//! write data of discrete function to file filename
//! with xdr methods
bool read_xdr( const char *filename );
//! write function data to file filename in ascii Format
bool write_ascii(const char *filename);
//! read function data from file filename in ascii Format
bool read_ascii(const char *filename);
//! write function data in pgm fromat file
bool write_pgm(const char *filename) ;
//! read function data from pgm fromat file
bool read_pgm(const char *filename);
//! return pointer to internal array for use of BLAS routines
DofType * leakPointer () { return &(dofVec_[0]); };
//! return pointer to internal array for use of BLAS routines
const DofType * leakPointer () const { return &(dofVec_[0]); };
private:
//! return object pointer of type LocalFunctionImp
LocalFunctionImp * newLocalFunctionObject () const;
// get memory for discrete function
void getMemory();
//! the name of the function
std::string name_;
//! true if memory was allocated
bool built_;
//! hold one object for addLocal and setLocal and so on
LocalFunctionImp localFunc_;
//! the dofs stored in an array
mutable CoeffStorageType dofVec_;
}; // end class DiscFuncArray
//**************************************************************************
//
// --LocalFunctionArray
//
//! Implementation of the local functions
//
//**************************************************************************
template < class DiscreteFunctionSpaceType , class CoeffStorageImp >
class LocalFunctionArray
: public LocalFunctionDefault <DiscreteFunctionSpaceType ,
LocalFunctionArray < DiscreteFunctionSpaceType ,CoeffStorageImp > >
{
typedef typename DiscreteFunctionSpaceType::BaseFunctionSetType BaseFunctionSetType;
typedef LocalFunctionArray < DiscreteFunctionSpaceType, CoeffStorageImp > MyType;
typedef DiscFuncArray <DiscreteFunctionSpaceType,CoeffStorageImp> DiscFuncType;
enum { dimrange = DiscreteFunctionSpaceType::DimRange };
typedef typename DiscreteFunctionSpaceType::Traits::DomainType DomainType;
typedef typename DiscreteFunctionSpaceType::Traits::RangeType RangeType;
typedef typename DiscreteFunctionSpaceType::Traits::RangeFieldType RangeFieldType;
typedef typename DiscreteFunctionSpaceType::Traits::JacobianRangeType JacobianRangeType;
typedef CoeffStorageImp CoeffStorageType;
friend class DiscFuncArray <DiscreteFunctionSpaceType,CoeffStorageType>;
friend class LocalFunctionWrapper < DiscFuncArray <DiscreteFunctionSpaceType,CoeffStorageType> >;
public:
//! Constructor
LocalFunctionArray ( const DiscreteFunctionSpaceType &f , CoeffStorageType & dofVec );
//! Destructor
~LocalFunctionArray ();
//! access to dof number num, all dofs of the dof entity
RangeFieldType & operator [] (int num);
//! access to dof number num, all dofs of the dof entity
const RangeFieldType & operator [] (int num) const;
//! return number of degrees of freedom
int numberOfDofs () const DUNE_DEPRECATED;
//! return number of degrees of freedom
int numDofs () const;
//! sum over all local base functions
template <class EntityType>
void evaluate (EntityType &en, const DomainType & x, RangeType & ret) const ;
template <class EntityType>
void evaluateLocal(EntityType &en, const DomainType & x, RangeType & ret) const ;
//! sum over all local base functions evaluated on given quadrature point
template <class EntityType, class QuadratureType>
void evaluate (EntityType &en, QuadratureType &quad, int quadPoint , RangeType & ret) const;
//! sum over all local base functions evaluated on given quadrature point
template <class EntityType, class QuadratureType>
void jacobian (EntityType &en, QuadratureType &quad, int quadPoint , JacobianRangeType & ret) const;
template <class EntityType>
void jacobianLocal(EntityType& en, const DomainType& x, JacobianRangeType& ret) const ;
template <class EntityType>
void jacobian(EntityType& en, const DomainType& x, JacobianRangeType& ret) const;
protected:
//! update local function for given Entity
template <class EntityType >
void init ( const EntityType &en ) const;
//! the corresponding function space which provides the base function set
const DiscreteFunctionSpaceType &fSpace_;
//! dofVec from all levels of the discrete function
CoeffStorageType & dofVec_;
//! Array holding pointers to the local dofs
mutable Array < RangeFieldType * > values_ ;
//! needed once
mutable RangeType tmp_;
mutable DomainType xtmp_;
//! needed once
mutable JacobianRangeType tmpGrad_;
//! diffVar for evaluate, is empty
const DiffVariable<0>::Type diffVar;
//! number of all dofs
mutable int numOfDof_;
//! for example number of corners for linear elements
mutable int numOfDifferentDofs_;
//! do we have the same base function set for all elements
bool uniform_;
//! is it initialised?
mutable bool init_;
}; // end LocalFunctionArray
//***********************************************************************
//
// --DofIteratorArray
//
//***********************************************************************
/** \brief Iterator over an array of dofs
\todo Please doc me!
*/
template < class DofImp >
class DofIteratorArray : public
DofIteratorDefault < DofImp , DofIteratorArray < DofImp > >
{
public:
typedef DofImp DofType;
//! Default constructor
DofIteratorArray() :
dofArray_ (0) ,
count_() {}
//! Constructor (const)
DofIteratorArray ( const Array < DofType > & dofArray , int count )
: dofArray_ (const_cast<DofArrayType*>(&dofArray)) ,
count_ (count) {}
//! Constructor
DofIteratorArray(Array<DofType>& dofArray, int count)
: dofArray_(&dofArray),
count_(count) {}
//! Copy Constructor
DofIteratorArray (const DofIteratorArray<DofImp>& other);
//! Assignment operator
DofIteratorArray<DofImp>& operator=(const DofIteratorArray<DofImp>& other);
//! return dof
DofType & operator *();
//! return dof read only
const DofType & operator * () const;
//! go next dof
DofIteratorArray<DofType> & operator++ ();
//! random access
DofType& operator[] (int i);
//! random access read only
const DofType& operator[] (int i) const;
//! compare
bool operator == (const DofIteratorArray<DofType> & I ) const;
//! compare
bool operator != (const DofIteratorArray<DofType> & I ) const;
//! return actual index
int index () const;
//! set dof iterator back to begin , for const and not const Iterators
void reset () ;
private:
typedef Array<DofType> DofArrayType;
//! the array holding the dofs
Array < DofType >* dofArray_;
//! index
mutable int count_;
}; // end DofIteratorArray
} // end namespace Dune
#include "discfuncarray/discfuncarray.cc"
#endif
Makefile
Makefile.in
semantic.cache
\ No newline at end of file
# $Id$
femdiscfuncdir = $(includedir)/dune/fem/discfuncarray
femdiscfunc_HEADERS = dfadapt.cc discfuncarray.cc
include $(top_srcdir)/am/global-rules
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_DFADAPT_CC
#define DUNE_DFADAPT_CC
#include <algorithm>
namespace Dune {
template<class DiscreteFunctionSpaceType>
inline DFAdapt< DiscreteFunctionSpaceType>::
DFAdapt(const DiscreteFunctionSpaceType& f) :
DiscreteFunctionDefaultType ( f ),
name_ ("no name"),
dm_(DofManagerFactoryType::getDofManager(f.grid())),
memPair_(dm_.addDofSet(&dofVec_, f.mapper(), name_)),
dofVec_ ( *memPair_.second ),
localFunc_(*this)
{}
// Constructor making discrete function
template<class DiscreteFunctionSpaceType>
inline DFAdapt< DiscreteFunctionSpaceType>::
DFAdapt(std::string name, const DiscreteFunctionSpaceType & f) :
DiscreteFunctionDefaultType ( f ),
name_ ((name.length() > 0) ? name : "no name"),
dm_(DofManagerFactoryType::getDofManager(f.grid())),
memPair_(dm_.addDofSet(&dofVec_, f.mapper(), name_)),
dofVec_ ( *memPair_.second ),
localFunc_(*this)
{}
// Constructor making discrete function
template<class DiscreteFunctionSpaceType>
template <class VectorPointerType>
inline DFAdapt< DiscreteFunctionSpaceType>::
DFAdapt(std::string name, const DiscreteFunctionSpaceType & f, VectorPointerType * vector ) :
DiscreteFunctionDefaultType ( f ),
name_ ((name.length() > 0) ? name : "no name"),
dm_(DofManagerFactoryType::getDofManager(f.grid())),
memPair_(dm_.addDummyDofSet(&dofVec_, f.mapper(), name_, vector )),
dofVec_ ( *memPair_.second ),
localFunc_(*this)
{}
template<class DiscreteFunctionSpaceType>
inline DFAdapt< DiscreteFunctionSpaceType>::
DFAdapt(const DFAdapt <DiscreteFunctionSpaceType> & df ) :
DiscreteFunctionDefaultType ( df.functionSpace_ ),
name_ (std::string("copy of ") + df.name()),
dm_(df.dm_),
memPair_(dm_.addDofSet(&dofVec_, df.functionSpace_.mapper(), name_)),
dofVec_ ( *memPair_.second ),
localFunc_(*this)
{
// copy values of array
dofVec_ = df.dofVec_;
}
// Desctructor
template<class DiscreteFunctionSpaceType>
inline DFAdapt< DiscreteFunctionSpaceType>::
~DFAdapt()
{
dm_.removeDofSet(*memPair_.first);
}
template<class DiscreteFunctionSpaceType>
inline void DFAdapt< DiscreteFunctionSpaceType>::set ( RangeFieldType x )
{
int size = dofVec_.size();
DofArrayType &vec = dofVec_;
for(int i=0; i<size; i++)
vec[i] = x;
}
template<class DiscreteFunctionSpaceType>
inline void DFAdapt< DiscreteFunctionSpaceType>::clear ()
{
set ( 0.0 );
}
template<class DiscreteFunctionSpaceType>
inline void DFAdapt< DiscreteFunctionSpaceType>::
print(std::ostream &s ) const
{
RangeFieldType sum = 0.;
ConstDofIteratorType enddof = dend ( );
for(ConstDofIteratorType itdof = dbegin ( ); itdof != enddof; ++itdof)
{
s << (*itdof) << " DofValue \n";
sum += std::abs(*itdof);
}
s << "sum = " << sum << "\n";
}
//*************************************************************************
// Interface Methods
//*************************************************************************
template<class DiscreteFunctionSpaceType>
template <class EntityType>
inline typename DFAdapt< DiscreteFunctionSpaceType>:: LocalFunctionType
DFAdapt< DiscreteFunctionSpaceType>::localFunction(const EntityType& en) const
{
return LocalFunctionType (en,*this);
}
template<class DiscreteFunctionSpaceType>
template <class EntityType>
inline void
DFAdapt< DiscreteFunctionSpaceType>::
localFunction ( const EntityType &en , LocalFunctionType &lf )
{
lf.init ( en );
}
template<class DiscreteFunctionSpaceType>
inline LocalFunctionAdapt<DiscreteFunctionSpaceType> *
DFAdapt< DiscreteFunctionSpaceType>::
newLocalFunctionObject ( ) const
{
return new LocalFunctionAdapt<DiscreteFunctionSpaceType> ( this->functionSpace_ , dofVec_ );
}
template<class DiscreteFunctionSpaceType>
inline typename DFAdapt< DiscreteFunctionSpaceType>:: LocalFunctionType
DFAdapt< DiscreteFunctionSpaceType>::
newLocalFunction ()
{
return LocalFunctionType (*this);
}
template<class DiscreteFunctionSpaceType>
inline typename DFAdapt<DiscreteFunctionSpaceType>::DofIteratorType
DFAdapt< DiscreteFunctionSpaceType>::dbegin ( )
{
return dofVec_.begin();
}
template<class DiscreteFunctionSpaceType>
inline typename DFAdapt<DiscreteFunctionSpaceType>::DofIteratorType
DFAdapt< DiscreteFunctionSpaceType>::dend ()
{
return dofVec_.end();
}
template<class DiscreteFunctionSpaceType>
inline typename DFAdapt<DiscreteFunctionSpaceType>::ConstDofIteratorType
DFAdapt< DiscreteFunctionSpaceType>::dbegin ( ) const
{
return dofVec_.begin();
}
template<class DiscreteFunctionSpaceType>
inline typename DFAdapt<DiscreteFunctionSpaceType>::ConstDofIteratorType
DFAdapt< DiscreteFunctionSpaceType>::dend () const
{
return dofVec_.end();
}
//**************************************************************************
// Read and Write Methods
//**************************************************************************
template<class DiscreteFunctionSpaceType>
inline bool DFAdapt< DiscreteFunctionSpaceType>::
write_xdr(std::string fn)
{
FILE *file;
XDR xdrs;
file = fopen(fn.c_str(), "wb");
if (!file)
{
printf( "\aERROR in DFAdapt::write_xdr(..): couldnot open <%s>!\n", fn.c_str());
fflush(stderr);
return false;
}
xdrstdio_create(&xdrs, file, XDR_ENCODE);
dofVec_.processXdr(&xdrs);
xdr_destroy(&xdrs);
fclose(file);
return true;
}
template<class DiscreteFunctionSpaceType>
inline bool DFAdapt< DiscreteFunctionSpaceType>::
read_xdr(std::string fn)
{
FILE *file;
XDR xdrs;
std::cout << "Reading <" << fn << "> \n";
file = fopen(fn.c_str() , "rb");
if(!file)
{
printf( "\aERROR in DFAdapt::read_xdr(..): couldnot open <%s>!\n", fn.c_str());
fflush(stderr);
return(false);
}
// read xdr
xdrstdio_create(&xdrs, file, XDR_DECODE);
dofVec_.processXdr(&xdrs);
xdr_destroy(&xdrs);
fclose(file);
return true;
}
template<class DiscreteFunctionSpaceType>
inline bool DFAdapt< DiscreteFunctionSpaceType>::
write_ascii(std::string fn)
{
std::fstream outfile( fn.c_str() , std::ios::out );
if (!outfile)
{
printf( "\aERROR in DFAdapt::write_ascii(..): couldnot open <%s>!\n", fn.c_str());
fflush(stderr);
return false;
}
{
int length = this->functionSpace_.size();
outfile << length << "\n";
DofIteratorType enddof = dend ( );
for(DofIteratorType itdof = dbegin ( ); itdof != enddof; ++itdof)
{
outfile << (*itdof) << " ";
}
outfile << "\n";
}
outfile.close();
return true;
}
template<class DiscreteFunctionSpaceType>
inline bool DFAdapt< DiscreteFunctionSpaceType>::
read_ascii(std::string fn)
{
FILE *infile=0;
infile = fopen( fn.c_str(), "r" );
assert(infile != 0);
{
int length;
fscanf(infile,"%d \n",&length);
assert(length == this->functionSpace_.size( ));
DofIteratorType enddof = dend ( );
for(DofIteratorType itdof = dbegin ( ); itdof != enddof; ++itdof)
{
fscanf(infile,"%le \n",& (*itdof));
}
}
fclose(infile);
return true;
}
template<class DiscreteFunctionSpaceType>
inline bool DFAdapt< DiscreteFunctionSpaceType>::
write_pgm(std::string fn)
{
std::ofstream out( fn.c_str() );
enum { dim = GridType::dimension };
if(out)
{
int danz = 129;
out << "P2\n " << danz << " " << danz <<"\n255\n";
DofIteratorType enddof = dend ();
for(DofIteratorType itdof = dbegin (); itdof != enddof; ++itdof) {
out << (int)((*itdof)*255.) << "\n";
}
out.close();
}
else
{
std::cerr << "Couldn't open file '"<<fn<<"' \n";
}
return true;
}
template<class DiscreteFunctionSpaceType>
inline bool DFAdapt< DiscreteFunctionSpaceType>::
read_pgm(std::string fn)
{
FILE *in;
int v;
in = fopen( fn.c_str(), "r" );
assert(in);
fscanf( in, "P2\n%d %d\n%d\n", &v, &v, &v );
DofIteratorType enddof = dend ();
for(DofIteratorType itdof = dbegin (); itdof != enddof; ++itdof) {
fscanf( in, "%d", &v );
(*itdof) = ((double)v)/255.;
}
fclose( in );
return true;
}
template<class DiscreteFunctionSpaceType>
inline void DFAdapt< DiscreteFunctionSpaceType>::
addScaled( const DFAdapt<DiscreteFunctionSpaceType> &g,
const RangeFieldType &scalar )
{
int length = dofVec_.size();
DofArrayType &v = dofVec_;
const DofArrayType &gvec = g.dofVec_;
for(int i=0; i<length; i++)
v[i] += scalar*gvec[i];
}
template<class DiscreteFunctionSpaceType>
template<class EntityType>
inline void DFAdapt< DiscreteFunctionSpaceType>::
addScaledLocal( EntityType &en ,
const DFAdapt<DiscreteFunctionSpaceType> &g, const RangeFieldType &scalar )
{
localFunc_ = localFunction( en );
DFAdapt<DiscreteFunctionSpaceType> &G =
const_cast<DFAdapt<DiscreteFunctionSpaceType> &> (g);
G.localFunc_ = G.localFunction(en);
int length = localFunc_.numDofs();
if(scalar == 1.)
{
for(int i=0; i<length; i++)
localFunc_[i] += G.localFunc_[i];
}
else if ( scalar == -1. )
{
for(int i=0; i<length; i++)
localFunc_[i] -= G.localFunc_[i];
}
else
{
for(int i=0; i<length; i++)
localFunc_[i] += scalar * G.localFunc_[i];
}
}
template<class DiscreteFunctionSpaceType>
template<class EntityType>
inline void DFAdapt< DiscreteFunctionSpaceType>::
addLocal( EntityType &en ,
const DFAdapt<DiscreteFunctionSpaceType> &g)
{
localFunc_ = localFunction( en );
DFAdapt<DiscreteFunctionSpaceType> &G =
const_cast<DFAdapt<DiscreteFunctionSpaceType> &> (g);
G.localFunc_ = G.localFunction(en);
int length = localFunc_.numDofs();
for(int i=0; i<length; i++)
localFunc_[i] += G.localFunc_[i];
}
template<class DiscreteFunctionSpaceType>
template<class EntityType>
inline void DFAdapt< DiscreteFunctionSpaceType>::
subtractLocal( EntityType &en ,
const DFAdapt<DiscreteFunctionSpaceType> &g)
{
localFunc_ = localFunction( en );
DFAdapt<DiscreteFunctionSpaceType> &G =
const_cast<DFAdapt<DiscreteFunctionSpaceType> &> (g);
G.localFunc_ = G.localFunction(en);
int length = localFunc_.numDofs();
for(int i=0; i<length; i++)
localFunc_[i] -= G.localFunc_[i];
}
template<class DiscreteFunctionSpaceType>
template<class EntityType>
inline void DFAdapt< DiscreteFunctionSpaceType>::
setLocal( EntityType &en , const RangeFieldType & scalar )
{
localFunc_ = localFunction( en );
int length = localFunc_.numDofs();
for(int i=0; i<length; i++)
localFunc_[i] = scalar;
}
//**********************************************************************
// --LocalFunctionAdapt
//**********************************************************************
template<class DiscreteFunctionSpaceType>
inline LocalFunctionAdapt < DiscreteFunctionSpaceType>::
LocalFunctionAdapt( const DiscreteFunctionSpaceType &f ,
DofArrayType & dofVec ) :
tmp_(0.0),
xtmp_(0.0),
tmpGrad_(0.0),
numOfDof_(-1),
fSpace_ ( f ),
values_ (),
dofVec_ ( dofVec ),
baseSet_(0),
init_(false)
//,id_(-1),
//idSet_(f.grid().localIdSet())
{}
template<class DiscreteFunctionSpaceType>
inline LocalFunctionAdapt < DiscreteFunctionSpaceType>::~LocalFunctionAdapt()
{}
template<class DiscreteFunctionSpaceType>
inline typename LocalFunctionAdapt < DiscreteFunctionSpaceType>::RangeFieldType &
LocalFunctionAdapt < DiscreteFunctionSpaceType>::operator [] (int num)
{
// check that storage (dofVec_) and mapper are in sync:
assert(dofVec_.size() >= fSpace_.size());
return (* (values_[num]));
}
template<class DiscreteFunctionSpaceType>
inline const typename LocalFunctionAdapt < DiscreteFunctionSpaceType>::RangeFieldType &
LocalFunctionAdapt < DiscreteFunctionSpaceType>::operator [] (int num) const
{
// check that storage (dofVec_) and mapper are in sync:
assert(dofVec_.size() >= fSpace_.size());
return (* (values_[num]));
}
template<class DiscreteFunctionSpaceType>
inline int LocalFunctionAdapt < DiscreteFunctionSpaceType>::
numberOfDofs () const
{
return numOfDof_;
}
template<class DiscreteFunctionSpaceType>
inline int LocalFunctionAdapt < DiscreteFunctionSpaceType>::
numDofs () const
{
return numOfDof_;
}
// hier noch evaluate mit Quadrature Regel einbauen
template<class DiscreteFunctionSpaceType> template <class EntityType>
inline void LocalFunctionAdapt < DiscreteFunctionSpaceType>::
evaluate (EntityType &en, const DomainType & x, RangeType & ret) const {
ret = 0.0;
xtmp_ = en.geometry().local(x);
evaluateLocal(en, xtmp_, ret);
}
template<class DiscreteFunctionSpaceType> template <class EntityType>
inline void LocalFunctionAdapt < DiscreteFunctionSpaceType>::
evaluateLocal (EntityType &en, const DomainType & x, RangeType & ret) const
{
enum { dimRange = DiscreteFunctionSpaceType::DimRange };
assert(init_);
assert(en.geometry().checkInside(x));
ret *= 0.0;
const BaseFunctionSetType& bSet = getBaseFunctionSet();
for (int i = 0; i < numDofs(); ++i)
{
bSet.eval(i, x, tmp_);
for (int l = 0; l < dimRange; ++l) {
ret[l] += (*values_[i]) * tmp_[l];
}
}
}
// hier noch evaluate mit Quadrature Regel einbauen
template<class DiscreteFunctionSpaceType>
template <class EntityType, class QuadratureType>
inline void LocalFunctionAdapt < DiscreteFunctionSpaceType>::
evaluate (EntityType &en, QuadratureType &quad, int quadPoint, RangeType & ret) const
{
enum { dimRange = DiscreteFunctionSpaceType::DimRange };
assert(init_);
assert(en.geometry().checkInside(quad.point(quadPoint)));
ret *= 0.0;
const BaseFunctionSetType& bSet = getBaseFunctionSet();
for (int i = 0; i < numDofs(); ++i)
{
bSet.eval(i, quad,quadPoint, tmp_);
tmp_*= (*values_[i]);
ret += tmp_;
}
}
// hier noch evaluate mit Quadrature Regel einbauen
template<class DiscreteFunctionSpaceType>
template <class EntityType, class QuadratureType>
inline void LocalFunctionAdapt < DiscreteFunctionSpaceType>::
jacobian (EntityType &en, QuadratureType &quad, int quadPoint, JacobianRangeType & ret) const
{
assert(init_);
enum { dim = EntityType::dimension };
enum { dimRange = DiscreteFunctionSpaceType::DimRange };
ret *= 0.0;
const BaseFunctionSetType& bSet = getBaseFunctionSet();
typedef FieldMatrix<DofType, dim, dim> JacobianInverseType;
const JacobianInverseType& jti =
en.geometry().jacobianInverseTransposed(quad.point(quadPoint));
JacobianRangeType tmp(0.0);
for (int i = 0; i < numDofs(); ++i) {
// tmpGrad_ *= 0.0;
bSet.jacobian(i, quad,quadPoint, tmpGrad_);
tmpGrad_ *= *values_[i];
tmp += tmpGrad_;
}
for (int l = 0; l < dimRange; ++l)
jti.umv(tmp[l],ret[l]);
}
template<class DiscreteFunctionSpaceType>
template <class EntityType>
inline void LocalFunctionAdapt<DiscreteFunctionSpaceType>::
jacobianLocal(EntityType& en, const DomainType& x,
JacobianRangeType& ret) const
{
assert(init_);
assert( en.geometry().checkInside(x) );
enum { dim = EntityType::dimension };
enum { dimRange = DiscreteFunctionSpaceType::DimRange };
ret *= 0.0;
const BaseFunctionSetType& bSet = getBaseFunctionSet();
typedef FieldMatrix<DofType, dim, dim> JacobianInverseType;
const JacobianInverseType& jti =
en.geometry().jacobianInverseTransposed(x);
for (int i = 0; i < numDofs(); ++i) {
tmpGrad_ *= 0.0;
bSet.jacobian(i, x, tmpGrad_);
for (int l = 0; l < dimRange; ++l) {
tmpGrad_[l] *= *values_[i];
// * umtv or umv?
jti.umv(tmpGrad_[l], ret[l]);
}
}
}
template<class DiscreteFunctionSpaceType>
template <class EntityType>
inline void LocalFunctionAdapt<DiscreteFunctionSpaceType>::
jacobian(EntityType& en, const DomainType& x, JacobianRangeType& ret) const {
ret *= 0.0;
xtmp_ = en.geometry().local(x);
jacobianLocal(en, xtmp_, ret);
}
template<class DiscreteFunctionSpaceType>
inline
const typename
LocalFunctionAdapt < DiscreteFunctionSpaceType>::BaseFunctionSetType&
LocalFunctionAdapt < DiscreteFunctionSpaceType>::getBaseFunctionSet() const {
assert(init_ && baseSet_);
return *baseSet_;
}
template<class DiscreteFunctionSpaceType>
template <class EntityType>
inline void LocalFunctionAdapt < DiscreteFunctionSpaceType>::
init (const EntityType &en ) const
{
// if id of element is the same, then no init has to be done
// NOTE: this might fail for adaptive grids, unless
// a method of the grid tells wether the grid is new or not
//if( id_ == idSet_.id(en) ) return;
if( (geoType_ != en.geometry().type()) ||
(!init_) )
{
baseSet_ = &fSpace_.getBaseFunctionSet(en);
numOfDof_ = baseSet_->numBaseFunctions();
if(numOfDof_ > this->values_.size())
this->values_.resize( numOfDof_ );
init_ = true;
geoType_ = en.geometry().type();
}
assert( geoType_ == en.geometry().type() );
//id_=idSet_.id(en);
for(int i=0; i<numOfDof_; ++i)
values_ [i] = &(this->dofVec_[ fSpace_.mapToGlobal ( en , i) ]);
return;
}
template<class DiscreteFunctionSpaceType>
inline void LocalFunctionAdapt < DiscreteFunctionSpaceType>::
assign(int numDof, const RangeType& dofs)
{
assert(false); // untested and most probably wrong
for (size_t i = 0; i < dimrange; ++i) {
*(values_[numDof + dimrange*i]) = dofs[i];
}
}
} // end namespace
#endif
This diff is collapsed.
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