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

Some new stuff

[[Imported from SVN: r2669]]
parent d0412858
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:
namespace Dune {
template <class DiscreteFunctionSpaceImp>
AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp>::
AdaptiveDiscreteFunction(const DiscreteFunctionSpaceType& f) :
BaseType(f)
{
// * more to come
}
//- AdaptiveDiscreteFunction
// nothing here, everything in adaptivefunction.hh
template <class DiscreteFunctionSpaceImp>
AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp>&
AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp>::
operator+=(const MappingType& g) {
static_cast<BaseType&>(*this).operator+=(g);
return *this;
}
//- AdaptiveDiscreteFunction
// comes later
//- AdaptiveLocalFunction
template <class DiscreteFunctionSpaceImp>
AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp>&
AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp>::
operator-=(const MappingType& g) {
static_cast<BaseType&>(*this).operator-=(g);
return *this;
}
AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::
AdaptiveLocalFunction(const DiscreteFunctionSpaceType& spc,
DofStorageType& dofVec) :
spc_(spc),
dofVec_(dofVec),
values_(),
init_(false)
{}
template <class DiscreteFunctionSpaceImp>
AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp>&
AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp>::
operator*=(const MappingType& g) {
static_cast<BaseType&>(*this).operator*=(g);
return *this;
}
AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::
~AdaptiveLocalFunction() {}
template <class DiscreteFunctionSpaceImp>
AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp>&
AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp>::
operator/=(const MappingType& g) {
static_cast<BaseType&>(*this).operator+=(g);
return *this;
AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::DofType&
AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::operator[] (int num) {
return (* (values_[num]));
}
//- DofIterator methods
template <class DiscreteFunctionSpaceImp>
DofIteratorType
AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp>::dbegin() {
return dofVec_.dbegin();
}
template <class DisceteFunctionSpaceImp>
DofIteratorType
AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp>::dend() {
return dofVec_.dend();
const AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::DofType&
AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::operator[] (int num) const {
return (* (values_[num]));
}
template <class DiscreteFunctionSpaceImp>
ConstDofIteratorType
AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp>::dbegin() const {
return dofVec_.dbegin();
int AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::
numberOfDofs() const {
return values_.size();
}
template <class DiscreteFunctionSpaceImp>
ConstDofIteratorType
AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp>::dend() const {
return dofVec_.dend();
}
template <class EntityType>
void AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::
evaluateLocal(EntityType& en, const DomainType& x, RangeType& ret) {
ret *= 0.0;
const BaseFunctionSetType& bSet = spc_.getBaseFunctionSet(en);
//- Read/write methods
template<class DiscreteFunctionSpaceImp >
inline bool DFAdapt< DiscreteFunctionSpaceImp >::
write_xdr( const std::basic_string<char> 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;
for (int i = 0; i < bSet.getNumberOfBaseFunctions(); ++i) {
bSet.evaluate(i, x, tmp_);
for (int l = 0; l < dimRange; ++l) {
ret[l] += (*values_[i]) * tmp_[l];
}
}
xdrstdio_create(&xdrs, file, XDR_ENCODE);
dofVec_.processXdr(&xdrs);
xdr_destroy(&xdrs);
fclose(file);
return true;
}
template<class DiscreteFunctionSpaceImp >
inline bool AdaptiveDiscreteFunction< DiscreteFunctionSpaceImp >::
read_xdr( const std::basic_string<char> fn )
{
FILE *file;
XDR xdrs;
std::cout << "Reading <" << fn << "> \n";
file = fopen(fn.c_str() , "rb");
if(!file)
{
printf( "\aERROR in AdaptiveDiscreteFunction::read_xdr(..): could not open <%s>!\n", fn.c_str());
fflush(stderr);
return(false);
}
// read xdr
xdrstdio_create(&xdrs, file, XDR_DECODE);
dofVec_.processXdr(&xdrs);
template <class DiscreteFunctionSpaceImp>
template <class EntityType>
void AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::
jacobianLocal(EntityType& en, const DomainType& x,
JacobianRangeType& ret) {
enum { dim = EntityType::dimension };
xdr_destroy(&xdrs);
fclose(file);
return true;
}
ret *= 0.0;
const BaseFunctionSetType& bSet = spc_.getBaseFunctionSet(en);
template<class DiscreteFunctionSpaceImp >
inline bool AdaptiveDiscreteFunction< DiscreteFunctionSpaceImp >::
write_ascii( const std::basic_string<char> fn )
{
std::fstream outfile( fn.c_str() , std::ios::out );
if (!outfile)
{
printf( "\aERROR in AdaptiveDiscreteFunction::write_ascii(..): could not open <%s>!\n", fn.c_str());
fflush(stderr);
return false;
}
for (int i = 0; i < bSet.getNumberOfBaseFunctions(); ++i) {
tmpGrad_ *= 0.0;
bSet.jacobian(i, x, tmpGrad_);
{
int length = this->functionSpace_.size();
outfile << length << "\n";
DofIteratorType enddof = dend ( );
for(DofIteratorType itdof = dbegin ( ); itdof != enddof; ++itdof)
{
outfile << (*itdof) << " ";
for (int l = 0; l < dimRange; ++l) {
tmpGrad_[l] *= *values_[i];
en.geometry().jacobianInverse(x).umtv(tmpGrad_[l], ret[l]);
}
outfile << "\n";
}
outfile.close();
return true;
}
/* probably not needed
template <class DiscreteFunctionSpaceImp>
AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::DofType&
AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::dofAt(int num) {
template<class DiscreteFunctionSpaceImp >
inline bool AdaptiveDiscreteFunction< DiscreteFunctionSpaceImp >::
read_ascii( const std::basic_string<char> 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;
}
}
//- class AdaptiveLocalFunction
template <class DiscreteFunctionSpaceImp>
AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::AdaptiveLocalFunction() {
// * more to come
}
template <class DiscreteFunctionSpaceImp>
AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::~AdaptiveLocalFunction() {}
template <class DiscreteFunctionSpaceImp>
const AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::DofType&
AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::dofAt(int num) const {
template <class DiscreteFunctionSpaceImp>
typename AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::DofType&
AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::operator[] (int num) {
// * more to come
}
}
*/
template <class DiscreteFunctionSpaceImp>
typename AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::ConstDofType&
AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::operator[] (int num) const {
// * more to come
}
template <class EntityType>
void AdaptiveLocalFuntion<DiscreteFunctionSpaceImp>::init(Entity& en) {
int numOfDof =
spc_.getBaseFunctionSet(en).getNumberOfBasefunctions();
template <class DiscreteFunctionSpaceImp>
AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::
AdaptiveLocalFunction(const ThisType& other) {
// * more to come
}
if (!init_) {
if (numOfDof > this->values_.size()) {
this->values_.resize(numOfDof);
}
init_ = true;
}
template <class DiscreteFunctionSpaceImp>
template <class EntityType>
void AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::
evaluateLocal(EntityType& en, const DomainType& x, RangeType& ret) {
// * more to come
for (int i = 0; i < numOfDof; ++i) {
values_[i] = &(this->dofVec_[spc_.mapToGlobal(en, i)]);
}
}
template <class DiscreteFunctionSpaceImp>
template <class EntityType>
void AdaptiveLocalFunction<DiscreteFunctionSpaceImp>::
jacobianLocal(EntityType& en, const DomainType& x, JacobianRangeType& ret) {
// * more to come
}
//- AdaptiveLocalFunction (Specialisation for CombinedSpace)
// comes later
} // end namespace Dune
......@@ -4,150 +4,104 @@
#define DUNE_ADAPTIVEFUNCTION_HH
//- System includes
#include <rpc/xdr.h>
#include <string>
//- Dune includes
#include "dofmanager.hh"
#include "common/discretefunction.hh"
#include "common/localfunction.hh"
#include "discretefunction/dofarrayiterator.hh"
#include <dune/fem/common/discretefunction.hh>
#include <dune/fem/common/localfunction.hh>
//- Local includes
#include "adaptiveimp.hh"
namespace Dune {
// Forward declarations
//- Forward declarations
template <class DiscreteFunctionSpaceImp>
class AdaptiveDiscreteFunction;
template <class DiscreteFunctionSpaceIm>
template <class DiscreteFunctionSpaceImp>
class AdaptiveLocalFunction;
//- Class definitions
template <class DiscreteFunctionSpaceImp>
struct AdaptiveDiscreteFunctionTraits {
typedef AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp> DiscreteFunctionType;
typedef AdaptiveLocalFunction<DiscreteFunctionSpaceImp> LocalFunctionType;
};
}; // end class AdaptiveDiscreteFunctionTraits
template <class DisreteFunctionSpaceImp>
template <class DiscreteFunctionSpaceImp>
class AdaptiveDiscreteFunction :
public DiscreteFunctionDefault<DiscreteFunctionSpaceImp,
AdaptiveDiscreteFunctionTraits<DiscreteFunctionSpaceImp> > {
public:
//- Public typedefs and enums
typedef AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp> TypeType;
typedef DiscreteFunctionDefault<
DiscreteFunctionSpaceImp,
AdaptiveDiscreteFunctionTraits<DiscreteFunctionSpaceImp>
> BaseType;
typedef typename BaseType::MappingType MappingType;
public DiscreteFunctionDefault<
AdaptiveDiscreteFunctionTraits<DiscreteFunctionSpaceImp> >,
private AdaptiveFunctionImplementation<DiscreteFunctionSpaceImp>
{
private:
typedef AdaptiveDiscretFunction<DiscreteFunctionSpaceImp> MyType;
typedef AdaptiveFunctionImplementation<DiscreteFunctionSpaceImp> Imp;
typedef AdaptiveDiscreteFunctionTraits<DiscreteFunctionSpaceImp> MyTraits;
typedef DiscreteFunctionDefault<MyTraits> BaseType;
public:
//- Typedefs and enums
typedef MyTraits Traits;
typedef DiscreteFunctionSpaceImp DiscreteFunctionSpaceType;
typedef typename DiscreteFunctionSpaceType::RangeFieldType RangeFieldType;
typedef typename DofArray<RangeFieldType>::DofIteratorType DofIteratorType;
typedef typename DofArray<
RangeFieldType>::ConstDofIteratorType ConstDofIteratorType;
typedef typename Traits::LocalFunctionType LocalFunctionType;
typedef typename Traits::DiscreteFunctionType DiscreteFunctionType;
public:
//- Public interface
//- Constructor and destructors
//! Constructor
AdaptiveDiscreteFunction(const DiscreteFunctionSpaceType& f);
//! Copy constructor
AdaptiveDiscreteFunction(const DiscreteFunctionType& f);
//! Destructor
~AdaptiveDiscreteFunction();
//- Operators
//! Addition of g to discrete function
virtual ThisType& operator+=(const MappingType& g);
//! subtract g from discrete function
virtual ThisType& operator-=(const MappingType &g);
//! multiply with scalar
virtual ThisType& operator*=(const RangeFieldType &scalar);
//! Division by a scalar
virtual ThisType& operator/=(const RangeFieldType &scalar);
// * Need to add operator + and so forth
//- Other methods
//! Begin iterator for contained dofs
DofIteratorType dbegin();
//! End iterator for contained dofs
DofIteratorType dend();
//! Begin const iterator for contained dofs
ConstDofIteratorType dbegin() const;
//! End const iterator for contained dofs
ConstDofIteratorType dend() const;
//! Get new local function
//! The obtained local function is uninitialised and needs to be set to
//! a specific entity
LocalFunctionType newLocalFunction();
//! Set local function to an entity
template <class EntityType>
void localFunction(const EntityType& en, LocalFunctionType& lf);
//! write data of discrete function to file filename|timestep
//! with xdr methods
bool write_xdr(const std::string& filename);
//! write data of discrete function to file filename|timestep
//! with xdr methods
bool read_xdr(const std::string& filename);
//! write function data to file filename|timestep in ascii Format
bool write_ascii(const std::string& filename);
//! read function data from file filename|timestep in ascii Format
bool read_ascii(const std::string& filename);
private:
//- Private typedefs
typedef DofArray<RangeFieldType> DofArrayType;
private:
//- Private methods
private:
//- Data members
DofArrayType& dofVec_;
};
//- Public methods
AdaptiveDiscreteFunction(const DiscreteFunctionSpaceType& spc,
std::string name = "no name") :
BaseType(spc),
Imp(name)
{}
using Imp::name;
using Imp::dbegin;
using Imp::dend;
using Imp::newLocalFunction;
using Imp::localFunction;
using Imp::write_xdr;
using Imp::read_xdr;
using Imp::write_ascii;
using Imp::read_ascii;
}; // end class AdaptiveDiscreteFunction
// Note: could use Traits class for Barton-Nackman instead
template <class DiscreteFunctionSpaceImp>
class AdaptiveLocalFunction<DiscreteFunctionSpaceImp> : public
LocalFunctionDefault<DiscreteFunctionSpaceImp,
AdaptiveLocalFunction<DiscreteFunctionSpaceImp> > {
class AdaptiveLocalFunction<DiscreteFunctionSpaceImp> :
public LocalFunctionDefault<
DiscreteFunctionSpaceImp,
AdaptiveLocalFunction<DiscreteFunctionSpaceImp> >
{
friend class AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp>;
public:
//- Public typedefs and enums
typedef AdaptiveLocalFunction<DiscreteFunctionSpaceImp> ThisType;
typedef DiscreteFunctionSpaceImp DiscreteFunctionSpaceType;
typedef AdaptiveDiscreteFunction<DiscreteFunctionSpaceImp> DiscreteFunctionSpaceType;
//! these are the types for the derived classes
typedef typename DiscreteFunctionSpaceType::FunctionSpaceType FunctionSpaceType;
typedef typename DiscreteFunctionSpaceType::BaseFunctionSetType BaseFunctionSetType;
typedef typename DiscreteFunctionSpaceType::RangeField RangeFieldType;
typedef typename DiscreteFunctionSpaceType::Domain DomainType;
typedef typename DiscreteFunctionSpaceType::Range RangeType;
typedef typename DiscreteFunctionSpaceType::JacobianRange JacobianRangeType;
typedef RangeFieldType DofType;
typedef const DofType ConstDofType;
typedef typename DiscreteFunctionSpaceType::DofStorageType DofStorageType;
enum { dimRange = FunctionSpaceType::dimRange };
public:
//- Public interface
//- Public methods
//- Constructors and destructors
//! Constructor
// * More to come
AdaptiveLocalFunction();
//! Copy constructor
AdaptiveLocalFunction(const ThisType& other);
AdaptiveLocalFunction(const DiscreteFunctionSpaceType& spc,
DofStorageType& dofVec);
//! Destructor
~AdaptiveLocalFunction();
......@@ -172,19 +126,137 @@ namespace Dune {
const DomainType& x,
JacobianRangeType& ret);
private:
//- Private typedefs
//- Forbidden methods
//! Copy constructor
AdaptiveLocalFunction(const ThisType& other);
ThisType& operator=(const ThisType& other);
private:
//- Private methods
DofType& dofAt(int num);
const DofType& dofAt(int num);
template <class EntityType>
void init(EntityType& en);
private:
//- Data members
const DiscreteFunctionSpaceType& spc_;
DofStorageType& dofVec_;
mutable Array < RangeFieldType * > values_;
mutable bool init_;
mutable RangeType& tmp_;
mutable JacobianRangeType& tmpGrad_;
}; // end class AdaptiveLocalFunction
//- Specialisations
/* Do that later
template <class ContainedFunctionSpaceImp, int N, DofStoragePolicy p>
class AdaptiveDiscreteFunction<CombinedSpace<ContainedFunctionSpaceImp, N, p> > :
public DiscreteFunctionDefault<
AdaptiveDiscreteFunctionTraits<CombinedSpace<ContainedFunctionSpaceImp, N, p> >
>,
private AdaptiveFunctionImplementation<CombinedSpace<ContainedFunctionSpaceImp, N, p> >
{
private:
typedef CombinedSpace<ContainedFunctionSpaceImp, N, p> DiscreteFunctionSpaceImp;
typedef AdaptiveDiscretFunction<DiscreteFunctionSpaceImp> MyType;
typedef AdaptiveFunctionImplementation<DiscreteFunctionSpaceImp> Imp;
typedef AdaptiveDiscreteFunctionTraits<DiscreteFunctionSpaceImp> MyTraits;
typedef DiscreteFunctionDefault<MyTraits> BaseType;
public:
//- Typedefs and enums
typedef MyTraits Traits;
typedef DiscreteFunctionSpaceImp DiscreteFunctionSpaceType;
typedef typename Traits::LocalFunctionType LocalFunctionType;
typedef typename Traits::DiscreteFunctionType DiscreteFunctionType;
public:
//- Public methods
AdaptiveDiscreteFunction(const DiscreteFunctionSpaceType& spc,
std::string name = "no name") :
BaseType(spc),
Imp(name)
{}
using Imp::name;
using Imp::dbegin;
using Imp::dend;
using Imp::newLocalFunction;
using Imp::localFunction;
using Imp::write_xdr;
using Imp::read_xdr;
using Imp::write_ascii;
using Imp::read_ascii;
//- Additional methods
private:
}; // end class AdaptiveDiscreteFunction (specialised for CombinedSpace)
template <class ContainedFunctionSpaceImp, int N, DofStoragePolicy p>
class AdaptiveLocalFunction<CombinedSpace<ContainedFunctionSpaceImp, N, p> > :
public LocalFunctionDefault<
CombinedSpace<ContainedFunctionSpaceImp, N, p>,
AdaptiveLocalFunction<CombinedSpace<ContainedFunctionSpaceImp, N, p> >
>
{
public:
//- Public typedefs and enums
typedef AdaptiveLocalFunction<DiscreteFunctionSpaceImp> ThisType;
typedef DiscreteFunctionSpaceImp DiscreteFunctionSpaceType;
//! these are the types for the derived classes
typedef typename DiscreteFunctionSpaceType::RangeField RangeFieldType;
typedef typename DiscreteFunctionSpaceType::Domain DomainType;
typedef typename DiscreteFunctionSpaceType::Range RangeType;
typedef typename DiscreteFunctionSpaceType::JacobianRange JacobianRangeType;
typedef RangeFieldType DofType;
typedef const DofType ConstDofType;
public:
//- Public methods
//- Constructors and destructors
//! Constructor
// * More to come
AdaptiveLocalFunction();
//! Copy constructor
AdaptiveLocalFunction(const ThisType& other);
//! Destructor
~AdaptiveLocalFunction();
//- Operators
//! Random access operator
DofType& operator[] (int num);
//! Cosnt random access operator
ConstDofType& operator[] (int num) const;
//- Methods
int numberOfDofs() const;
template <class EntityType>
void evaluateLocal(EntityType& en,
const DomainType& x,
RangeType & ret);
} // end namespace Dune
template <class EntityType>
void jacobianLocal(EntityType& en,
const DomainType& x,
JacobianRangeType& ret);
//- Additional methods for specialisation
void assign(const DofVectorType& dofs);
#include "adaptivefunction.cc"
int numberOfBaseFunctions() const;
private:
}; // end class AdaptiveLocalFunction (specialised for CombinedSpace)
*/
} // end namespace Dune
#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