1 #ifndef DUNE_FEM_FUNCTION_COMBINEDFUNCTION_COMBINEDFUNCTION_HH 2 #define DUNE_FEM_FUNCTION_COMBINEDFUNCTION_COMBINEDFUNCTION_HH 22 template<
class ContainedDiscreteFunction,
int N >
25 template<
class ContainedDiscreteFunction,
int N >
32 template<
class ContainedDiscreteFunction,
int N >
39 typedef typename ContainedDiscreteFunctionType :: DiscreteFunctionSpaceType
46 typedef typename DiscreteFunctionSpaceType :: DomainType
DomainType;
47 typedef typename DiscreteFunctionSpaceType :: RangeType
RangeType;
52 typedef typename DiscreteFunctionSpaceType :: MapperType
MapperType;
53 typedef typename DiscreteFunctionSpaceType :: GridType
GridType;
54 typedef typename DiscreteFunctionSpaceType :: GridPartType
GridPartType;
60 typedef typename ContainedDiscreteFunctionType :: DofBlockType
DofBlockType;
61 typedef typename ContainedDiscreteFunctionType :: ConstDofBlockType
63 typedef typename ContainedDiscreteFunctionType :: DofBlockPtrType
65 typedef typename ContainedDiscreteFunctionType :: ConstDofBlockPtrType
79 template <
class ContainedDiscreteFunctionImp,
int N >
109 typedef typename Traits::ContainedDiscreteFunctionSpaceType
137 using BaseType :: assign;
139 using BaseType :: space;
146 : BaseType(
"combined_"+func.name(), createSpace( func.space().gridPart() ), LocalDofVectorAllocatorType( &ldvStack_ ) ),
149 for (
int i=0; i<N; ++i)
151 func_[i] =
new ContainedDiscreteFunctionType(func);
157 : BaseType(
"combined_"+name, createSpace( spc.gridPart() ), LocalDofVectorAllocatorType( &ldvStack_ ) ),
160 for (
int i=0; i<N; ++i)
162 func_[i] =
new ContainedDiscreteFunctionType(name,spc);
168 : BaseType(
"combined_"+name, createSpace( spc.gridPart() ), LocalDofVectorAllocatorType( &ldvStack_) ),
171 for (
int i=0; i<N; ++i)
173 func_[i] =
new ContainedDiscreteFunctionType(name,space().containedSpace());
180 : BaseType( other.name()+
"_copy", createSpace( other.space().gridPart() ), LocalDofVectorAllocatorType( &ldvStack_ ) ),
181 ldvStack_( other.ldvStack_ )
183 for (
int i=0; i<N; ++i)
186 ContainedDiscreteFunctionType(other.
subFunction(i));
193 for (
int i=0; i<N; ++i)
200 ThisType &operator= (
const ThisType &other );
205 for (
int i=0; i<N; ++i)
212 for(
int i=0; i<N; ++i)
219 return func_[0]->size()*N;
223 ThisType &operator+= (
const ThisType &g )
225 for (
int i=0; i<N; ++i)
232 using BaseType::operator-=;
233 ThisType &operator-= (
const ThisType &g )
237 for(
int i = 0; i < N; ++i )
245 for (
int i=0; i<N; ++i)
253 for (
int i=0; i<N; ++i)
260 void addScaled(
const ThisType &g,
const RangeFieldType &s )
267 void axpy(
const RangeFieldType &s,
const ThisType &g )
269 for (
int i=0; i<N; ++i)
276 RangeFieldType ret( 0 );
277 for(
int i = 0; i < N; ++i )
278 ret += func_[ i ]->scalarProductDofs( other.
subFunction( i ) );
283 template<
class StreamTraits >
286 for (
int i=0; i<N; ++i)
290 template<
class StreamTraits >
293 for (
int i=0; i<N; ++i)
294 func_[i]->write(out);
298 inline void print( std :: ostream &out )
const {
299 for (
int i=0; i<N; ++i)
300 func_[i]->print(out);
305 bool ret = func_[0]->dofsValid();
306 for (
int i=1;i<N;i++)
307 ret |= func_[i]->dofsValid();
311 inline ConstDofBlockPtrType
block (
unsigned int index )
const 314 const int containedSize = func_[ 0 ]->space().blockMapper().size();
315 const int component = index / containedSize;
316 const int containedIndex = index % containedSize;
317 const ContainedDiscreteFunctionType& func = *(func_[ component ]);
318 return func.block( containedIndex );
321 inline DofBlockPtrType
block (
unsigned int index )
324 const int containedSize = func_[ 0 ]->space().blockMapper().size();
325 const int component = index / containedSize;
326 const int containedIndex = index % containedSize;
327 return func_[ component ]->block( containedIndex );
330 inline const RangeFieldType &
dof(
unsigned int index)
const 336 int variable = index / func_[0]->size();
337 int point = index % func_[0]->size();
338 return func_[variable]->dof(point);
341 inline RangeFieldType &
dof (
unsigned int index )
347 int variable = index / func_[0]->size();
348 int point = index % func_[0]->size();
349 return func_[variable]->dof(point);
365 return DofIteratorType(*
this);
370 return DofIteratorType(
false,*
this);
378 inline const ContainedDiscreteFunctionType&
subFunction(
const int i )
const 385 return space().containedSpace();
391 const MyType& interface()
const {
return *
this; }
399 typename Traits :: LocalDofVectorStackType ldvStack_;
400 ContainedDiscreteFunctionType* func_[N];
407 template <
class ContainedDiscreteFunctionImp,
int N>
410 typename ContainedDiscreteFunctionImp::DofType ,
411 CombinedDiscreteFunctionDofIterator<ContainedDiscreteFunctionImp,N> >
424 (
bool end,
const DiscreteFunctionType& df) :
425 df_(const_cast<DiscreteFunctionType&>(df)),
427 iter_(df.func_[N-1]->dend()),
428 endIter_(df.func_[N-1]->dend())
432 (
const DiscreteFunctionType& df) :
433 df_(const_cast<DiscreteFunctionType&>(df)),
435 iter_(df.func_[0]->dbegin()),
436 endIter_(df.func_[0]->dend())
440 (
bool end,DiscreteFunctionType& df) :
443 iter_(df.func_[N-1]->dend()),
444 endIter_(df.func_[N-1]->dend())
448 (DiscreteFunctionType& df) :
451 iter_(df.func_[0]->dbegin()),
452 endIter_(df.func_[0]->dend())
459 endIter_(other.endIter_)
467 endIter_ = other.endIter_;
478 ThisType& operator++ () {
480 if (iter_==endIter_ && comp_<N-1) {
482 iter_ = df_.func_[comp_]->dbegin();
483 endIter_ = df_.func_[comp_]->dend();
489 bool operator == (
const ThisType & I )
const {
return (comp_ == I.comp_) && (iter_ == I.iter_); }
492 bool operator != (
const ThisType & I )
const {
return !((*this) == I); }
497 iter_ = df_.func_[ 0 ]->dbegin();
498 endIter_ = df_.func_[ 0 ]->dend();
502 DiscreteFunctionType& df_;
505 mutable ContainedDofIteratorType iter_,endIter_;
513 #endif // #ifndef DUNE_FEM_FUNCTION_COMBINEDFUNCTION_COMBINEDFUNCTION_HH
ConstDofIteratorDefault< DofIteratorType > ConstDofIteratorType
Definition: combinedfunction/combinedfunction.hh:58
CombinedDiscreteFunctionDofIterator(const ThisType &other)
Copy Constructor.
Definition: combinedfunction/combinedfunction.hh:455
DiscreteFunctionSpaceType::DomainType DomainType
Definition: combinedfunction/combinedfunction.hh:46
ContainedDiscreteFunctionType::ConstDofIteratorType ContainedConstDofIteratorType
Definition: combinedfunction/combinedfunction.hh:419
ContainedDiscreteFunctionType::DofBlockType DofBlockType
Definition: combinedfunction/combinedfunction.hh:60
BaseType::DofBlockPtrType DofBlockPtrType
Definition: discretefunction.hh:608
Definition: dofiterator.hh:208
BaseType::RangeType RangeType
Vector type used for the range field.
Definition: combinedfunction/combinedfunction.hh:120
void clear()
set all degrees of freedom to zero
Definition: combinedfunction/combinedfunction.hh:204
DiscreteFunctionSpaceType::GridPartType GridPartType
Definition: combinedfunction/combinedfunction.hh:54
ContainedDiscreteFunction ContainedDiscreteFunctionType
Definition: combinedfunction/combinedfunction.hh:35
ContainedDiscreteFunctionType::ConstDofBlockType ConstDofBlockType
Definition: combinedfunction/combinedfunction.hh:62
ThisType & operator=(const ThisType &other)
Assignment operator.
Definition: combinedfunction/combinedfunction.hh:463
RangeFieldType DofType
Definition: combinedfunction/combinedfunction.hh:51
BaseType::LocalDofVectorAllocatorType LocalDofVectorAllocatorType
Definition: combinedfunction/combinedfunction.hh:135
Traits class for a DiscreteFunction.
Definition: discretefunction.hh:60
ConstDofBlockPtrType block(unsigned int index) const
Definition: combinedfunction/combinedfunction.hh:311
DiscreteFunctionSpaceType::MapperType MapperType
Definition: combinedfunction/combinedfunction.hh:52
BaseType::RangeFieldType RangeFieldType
Intrinsic type used for range field (like DofType)
Definition: combinedfunction/combinedfunction.hh:116
Traits::DofIteratorType DofIteratorType
type of the dof iterator
Definition: discretefunction.hh:591
Traits::DofType DofType
Definition: combinedfunction/combinedfunction.hh:420
Construct a vector with a dynamic size.
Definition: referencevector.hh:23
static double max(const Double &v, const double p)
Definition: double.hh:387
Definition: discretefunction.hh:63
Traits::DiscreteFunctionType DiscreteFunctionType
Definition: combinedfunction/combinedfunction.hh:416
ContainedDiscreteFunctionType::DiscreteFunctionSpaceType ContainedDiscreteFunctionSpaceType
Definition: combinedfunction/combinedfunction.hh:40
ContainedDiscreteFunctionType::DofIteratorType ContainedDofIteratorType
Definition: combinedfunction/combinedfunction.hh:418
BaseType::DiscreteFunctionType DiscreteFunctionType
Definition: combinedfunction/combinedfunction.hh:104
BaseType::DomainType DomainType
Vector type used for the domain field.
Definition: combinedfunction/combinedfunction.hh:122
DiscreteFunctionSpaceType::RangeType RangeType
type of range vector
Definition: discretefunction.hh:579
BaseType::DofIteratorType DofIteratorType
Iterator over dof container.
Definition: combinedfunction/combinedfunction.hh:127
void axpy(const T &a, const T &x, T &y)
Definition: space/basisfunctionset/functor.hh:37
RangeFieldType & dof(unsigned int index)
Definition: combinedfunction/combinedfunction.hh:341
DiscreteFunctionSpaceType::RangeFieldType RangeFieldType
Definition: combinedfunction/combinedfunction.hh:45
This file implements a dense vector with a dynamic size.
void write(OutStreamInterface< StreamTraits > &out) const
write the discrete function into a stream
Definition: combinedfunction/combinedfunction.hh:291
DiscreteFunctionSpaceType::RangeFieldType RangeFieldType
type of range field (usually a float type)
Definition: discretefunction.hh:588
bool operator!=(const Double &a, const Double &b)
Definition: double.hh:629
DiscreteFunctionSpaceType::DomainFieldType DomainFieldType
type of domain field (usually a float type)
Definition: discretefunction.hh:586
BaseType::GridPartType GridPartType
type of the underlying grid part
Definition: discretefunction.hh:574
DynamicReferenceVector< DofType, LocalDofVectorAllocatorType > LocalDofVectorType
Definition: combinedfunction/combinedfunction.hh:70
BaseType::DomainFieldType DomainFieldType
Intrinsic type used for the domain field.
Definition: combinedfunction/combinedfunction.hh:118
ContainedDiscreteFunctionImp ContainedDiscreteFunctionType
Discrete function this discrete function belongs to.
Definition: combinedfunction/combinedfunction.hh:89
CombinedDiscreteFunction(const ContainedDiscreteFunctionType &func)
Definition: combinedfunction/combinedfunction.hh:145
void addScaled(const ThisType &g, const RangeFieldType &s)
Definition: combinedfunction/combinedfunction.hh:260
bool operator==(const Double &a, const Double &b)
Definition: double.hh:589
ThreadSafeValue< UninitializedObjectStack > LocalDofVectorStackType
Definition: combinedfunction/combinedfunction.hh:68
MutableLocalFunction< DiscreteFunctionType > LocalFunctionType
Definition: combinedfunction/combinedfunction.hh:72
Definition: coordinate.hh:4
CombinedDiscreteFunction(const std::string &name, const ContainedDiscreteFunctionSpaceType &spc)
Definition: combinedfunction/combinedfunction.hh:155
ConstDofIteratorType dend() const
obtain an iterator pointing behind the last DoF (read-only)
Definition: combinedfunction/combinedfunction.hh:358
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
the combined discrete function type
Definition: combinedfunction/combinedfunction.hh:107
abstract interface for an input stream
Definition: streams.hh:177
Traits::ConstDofIteratorType ConstDofIteratorType
type of the const dof iterator
Definition: discretefunction.hh:593
Definition: combinedspace/combinedspace.hh:32
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: discretefunction.hh:571
ContainedDiscreteFunctionType::ConstDofBlockPtrType ConstDofBlockPtrType
Definition: combinedfunction/combinedfunction.hh:66
~CombinedDiscreteFunction()
Destructor.
Definition: combinedfunction/combinedfunction.hh:191
ConstDofIteratorType dbegin() const
obtain an iterator pointing to the first DoF (read-only)
Definition: combinedfunction/combinedfunction.hh:353
bool dofsValid() const
check for NaNs
Definition: combinedfunction/combinedfunction.hh:304
Double operator*(const Double &a, const Double &b)
Definition: double.hh:495
BaseType::ConstDofBlockPtrType ConstDofBlockPtrType
Definition: combinedfunction/combinedfunction.hh:133
CombinedDiscreteFunctionDofIterator< ContainedDiscreteFunctionImp, N > ThisType
Definition: combinedfunction/combinedfunction.hh:414
DiscreteFunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: combinedfunction/combinedfunction.hh:49
DiscreteFunctionSpaceType::RangeType RangeType
Definition: combinedfunction/combinedfunction.hh:47
DofIteratorType dbegin()
obtain an iterator pointing to the first DoF (read-write)
Definition: combinedfunction/combinedfunction.hh:363
DofBlockPtrType block(unsigned int index)
Definition: combinedfunction/combinedfunction.hh:321
Traits::MapperType MapperType
Mapper type (from the space)
Definition: combinedfunction/combinedfunction.hh:124
BaseType::GridPartType GridPartType
GridPart implementation.
Definition: combinedfunction/combinedfunction.hh:99
Definition: stackallocator.hh:61
CombinedSpace< ContainedDiscreteFunctionSpaceType, N, VariableBased > DiscreteFunctionSpaceType
Definition: combinedfunction/combinedfunction.hh:42
ContainedDiscreteFunctionSpaceType & subSpace()
Definition: combinedfunction/combinedfunction.hh:383
BaseType::ConstDofBlockPtrType ConstDofBlockPtrType
Definition: discretefunction.hh:609
StackAllocator< DofType, LocalDofVectorStackType * > LocalDofVectorAllocatorType
Definition: combinedfunction/combinedfunction.hh:69
void read(InStreamInterface< StreamTraits > &in)
read the discrete function from a stream
Definition: combinedfunction/combinedfunction.hh:284
Iterator over an array of dofs.
Definition: combinedfunction/combinedfunction.hh:26
BaseType::ConstDofIteratorType ConstDofIteratorType
Read-only iterator over dof container.
Definition: combinedfunction/combinedfunction.hh:130
DiscreteFunctionSpaceType::DomainType DomainType
type of domain vector
Definition: discretefunction.hh:577
BaseType::DofType DofType
Intrinsic type used for dofs (typically a float type)
Definition: combinedfunction/combinedfunction.hh:114
void reset()
Definition: combinedfunction/combinedfunction.hh:494
DofIteratorType dend()
obtain an iterator pointing behind the last DoF (read-write)
Definition: combinedfunction/combinedfunction.hh:368
BaseType::DofBlockPtrType DofBlockPtrType
Definition: combinedfunction/combinedfunction.hh:132
CombinedDiscreteFunction< ContainedDiscreteFunctionType, N > DiscreteFunctionType
Definition: combinedfunction/combinedfunction.hh:37
ContainedDiscreteFunctionType::DofBlockPtrType DofBlockPtrType
Definition: combinedfunction/combinedfunction.hh:64
BaseType::DofType DofType
Definition: discretefunction.hh:613
ContainedDiscreteFunctionType SubDiscreteFunctionType
Definition: combinedfunction/combinedfunction.hh:90
CombinedDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &spc)
Definition: combinedfunction/combinedfunction.hh:166
ContainedDiscreteFunctionType & subFunction(const int i)
Definition: combinedfunction/combinedfunction.hh:373
void print(std::ostream &out) const
print all DoFs to a stream (for debugging purposes)
Definition: combinedfunction/combinedfunction.hh:298
default implementation of DofManagerInterface
Definition: dofiterator.hh:141
void assign(const ThisType &g)
Definition: combinedfunction/combinedfunction.hh:210
CombinedDiscreteFunctionDofIterator< ContainedDiscreteFunctionType, N > DofIteratorType
Definition: combinedfunction/combinedfunction.hh:57
const ContainedDiscreteFunctionType & subFunction(const int i) const
Definition: combinedfunction/combinedfunction.hh:378
ContainedDiscreteFunctionSpaceType SubDiscreteFunctionSpaceType
Definition: combinedfunction/combinedfunction.hh:112
CombinedDiscreteFunction(const ThisType &other)
Definition: combinedfunction/combinedfunction.hh:179
Traits::LocalDofVectorAllocatorType LocalDofVectorAllocatorType
type of LocalDofVector
Definition: discretefunction.hh:601
RangeFieldType scalarProductDofs(const ThisType &other) const
Definition: combinedfunction/combinedfunction.hh:274
DiscreteFunctionTraits< CombinedDiscreteFunction< ContainedDiscreteFunctionImp, N > > Traits
Definition: combinedfunction/combinedfunction.hh:415
DiscreteFunctionTraits< ThisType > Traits
Traits class with all necessary type definitions.
Definition: combinedfunction/combinedfunction.hh:93
Traits::ContainedDiscreteFunctionSpaceType ContainedDiscreteFunctionSpaceType
Contained discrete function space.
Definition: combinedfunction/combinedfunction.hh:110
int size() const
obtain total number of DoFs
Definition: combinedfunction/combinedfunction.hh:217
Definition: combinedfunction/combinedfunction.hh:23
void axpy(const RangeFieldType &s, const ThisType &g)
axpy operation
Definition: combinedfunction/combinedfunction.hh:267
Traits::ContainedDiscreteFunctionType ContainedDiscreteFunctionType
Definition: combinedfunction/combinedfunction.hh:417
DiscreteFunctionSpaceType::DomainFieldType DomainFieldType
Definition: combinedfunction/combinedfunction.hh:44
const RangeFieldType & dof(unsigned int index) const
Definition: combinedfunction/combinedfunction.hh:330
abstract interface for an output stream
Definition: streams.hh:44
BaseType::GridType GridType
Grid implementation.
Definition: combinedfunction/combinedfunction.hh:96
DiscreteFunctionSpaceType::GridType GridType
Type of the underlying grid.
Definition: discretefunction.hh:117
DiscreteFunctionSpaceType::GridType GridType
Definition: combinedfunction/combinedfunction.hh:53