1#ifndef DUNE_FEM_DATACOLLECTOR_HH
2#define DUNE_FEM_DATACOLLECTOR_HH
13#include <dune/common/dynvector.hh>
14#include <dune/common/version.hh>
43 struct DiscreteFunctionTraits;
45 template <
class Gr
idImp>
class DofManager;
47 template <
class LocalOp,
class ParamType>
class LocalInlinePlus;
56 template <
class A,
class B >
58 :
public LocalInlinePlus< CombinedLocalDataCollect< A, B >, typename A::Traits::ParamType >
73 template <
class Arg1,
class Arg2>
74 void apply(Arg1 & arg1, Arg2 & arg2)
const
76 a_.apply( arg1, arg2 );
77 b_.apply( arg1, arg2 );
81 template <
class ParamT>
97 template <
class T1 ,
class T2 >
108 typedef typename std::pair < MyType * , FuncType * >
PairType;
109 typedef typename std::vector < PairType >
ListType;
111 template <
class OpType>
117 static_cast<OpType &
> (m).
apply(p);
136 vec.resize( vec.size() + ve.size() );
139 for(
unsigned int i=0; i<tmp.size(); i++)
141 for(
unsigned int i=tmp.size(); i<vec.size(); i++)
142 vec[i] = ve[i-tmp.size()];
149 template <
class OpType>
165 const size_t size = vec_.size();
166 for(
size_t i=0; i<size; ++i)
168 assert( vec_[i].second );
169 assert( vec_[i].first );
172 (*vec_[i].second)( *(vec_[i].first) , p );
176 template <
class OpType>
189 template <
class OpType>
202 template <
class OpType>
205 typedef typename ListType :: iterator iterator;
206 iterator end = vec_.end();
207 for(iterator it = vec_.begin(); it != end; ++it)
209 if( &op == (*it).first )
217 template <
class OpType>
224 bool empty ()
const {
return (vec_.size() == 0); }
230 template <
class LocalOp,
class ParamT>
245 std::cout <<
"operator + of LocalInlinePlus \n";
247 CombinedType * combo =
new CombinedType (
asImp() , b );
251 LocalOp &
asImp() {
return static_cast<LocalOp &
> (*this); }
260 template <
class Gr
idType,
class ObjectStreamImp = DummyObjectStream >
267 typedef typename GridType::template Codim<0>::Entity
EntityType;
292 if(dc_) (*dc_).apply(str, entity );
295 std::cerr <<
"WARNING: apply: did nothing! \n";
305 std::cerr <<
"No LocalInterfaceOperator \n";
317 std::cerr <<
"No LocalInterfaceOperator \n";
324 template <
class OpType>
331 MyType * tmp =
const_cast<OpType &
> (dc).convert();
332 dc_ = &(*dc_).operator += (*tmp);
336 dc_ =
const_cast<OpType *
> (&dc);
337 dcConv_ =
const_cast<OpType &
> (dc).convert();
349 dc_ = &(*dc_).operator += (dc);
353 dc_ =
const_cast<MyType *
> (&dc);
354 dcConv_ =
const_cast<MyType *
> (&dc);
360 template <
class OpType>
364 dc_ =
const_cast<OpType *
> (&dc);
365 dcConv_ =
const_cast<OpType &
> (dc).convert();
373 dc_ =
const_cast<MyType *
> (dc.dc_);
374 dcConv_ =
const_cast<MyType *
> (dc.dcConv_);
391 template <
class Gr
idType>
404 std::cerr <<
"WARNING: apply: did nothing! \n";
408 template <
class OpType>
415 template <
class OpType>
431 template <
class GridType,
432 class LocalDataCollectImp >
439 typedef typename GridType::template Codim<0>::Entity
EntityType;
448 typedef typename std::pair < ObjectStreamType * , const EntityType * >
ParamType;
458 LocalDataCollectImp & ldc,
461 : grid_(grid) , dm_ ( dm ), ldc_ (ldc)
463 , numChildren_(numChildren)
470 template <
class LocalDataCollectType>
472 CombinedLocalDataCollect <LocalDataCollectImp,LocalDataCollectType> > &
476 typedef CombinedLocalDataCollect <LocalDataCollectImp,LocalDataCollectType> COType;
478 COType *newLDCOp =
new COType ( ldc_ ,
const_cast<CopyType &
> (op).
getLocalOp() );
479 typedef DataCollector <GridType, COType> OPType;
481 OPType *dcOp =
new OPType ( grid_ , dm_ , *newLDCOp, rwType_ );
491 template <
class LocalDataCollectType>
497 COType *newLDCOp =
new COType ( ldc_ + op.
getLocalOp() );
498 typedef DataCollector <GridType, COType> OPType;
500 OPType *dcOp =
new OPType ( grid_ , dm_ , *newLDCOp, rwType_ );
519 OPType *dcOp =
new OPType ( grid_ , dm_ , *newLDCOp, rwType_ );
553 bool writeData()
const {
return rwType_ == DataCollectorTraits :: writeData ; }
567 const int mxlvl = grid_.maxLevel();
570 inlineLocal(str, entity );
573 typedef typename EntityType::HierarchicIterator HierarchicIteratorType;
574 const HierarchicIteratorType endit = entity.hend( mxlvl );
575 for(HierarchicIteratorType it = entity.hbegin( mxlvl );
578 inlineLocal(str, *it);
586 const int mxlvl = grid_.maxLevel();
589 xtractLocal(str, entity );
592 typedef typename EntityType::HierarchicIterator HierarchicIteratorType;
593 const HierarchicIteratorType endit = entity.hend( mxlvl );
594 for(HierarchicIteratorType it = entity.hbegin( mxlvl );
597 xtractLocal(str, *it);
607 COType *newLDCOp =
new COType ( ldc_ );
608 typedef DataCollector <GridType, COType> OPType;
610 OPType *dcOp =
new OPType ( grid_ , dm_ , *newLDCOp, rwType_ );
646 LocalDataCollectImp &ldc_;
652 const int numChildren_;
657 template<
class DiscreteFunctionType >
660 typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType
662 typedef typename DiscreteFunctionSpaceType::GridType
GridType;
663 typedef typename DiscreteFunctionSpaceType::EntityType
EntityType;
669 typedef std::pair< ObjectStreamType *, const GridEntityType * >
ParamType;
675 template<
class DiscreteFunctionType,
676 class ContainsCheck >
678 :
public LocalInlinePlus< LocalDataInliner< DiscreteFunctionType, ContainsCheck >,
679 typename LocalDataInlinerTraits< DiscreteFunctionType >::ParamType >
700 const ContainsCheck& containsCheck )
718 assert( p.first && p.second );
719 const EntityType& entity =
df_.space().gridPart().convert( *p.second );
723 typename DataCollectorTraits :: ReadWriteType
733 assert(
df_.space().indexSet().contains( entity ) );
735 ldv_.resize(
df_.space().basisFunctionSet( entity ).size() );
736 df_.getLocalDofs( entity,
ldv_ );
742 const DiscreteFunctionType &
df_;
749 template<
class DiscreteFunctionType >
752 typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType
754 typedef typename DiscreteFunctionSpaceType::GridType
GridType;
755 typedef typename DiscreteFunctionSpaceType::EntityType
EntityType;
761 typedef std::pair< ObjectStreamType *, const GridEntityType * >
ParamType;
767 template<
class DiscreteFunctionType,
768 class ContainsCheck >
770 :
public LocalInlinePlus< LocalDataXtractor< DiscreteFunctionType, ContainsCheck >,
771 typename LocalDataXtractorTraits< DiscreteFunctionType >::ParamType >
792 const ContainsCheck& containsCheck )
810 assert( p.first && p.second );
811 const EntityType& entity =
df_.space().gridPart().convert( *p.second );
815 typename DataCollectorTraits :: ReadWriteType
826 assert(
df_.space().indexSet().contains( entity ) );
828 ldv_.resize(
df_.space().basisFunctionSet( entity ).size() );
831 df_.setLocalDofs( entity,
ldv_ );
835 DiscreteFunctionType &
df_;
Definition: bindguard.hh:11
const GridEntityAccess< Entity >::GridEntityType & gridEntity(const Entity &entity)
Definition: gridpart.hh:412
Traits class for a DiscreteFunction.
Definition: common/discretefunction.hh:61
Definition: objpointer.hh:42
void saveObjPointer(DiscrOpType *discrOp)
Store new generated DiscreteOperator Pointer.
Definition: objpointer.hh:58
Definition: dofmanager.hh:761
Definition: datacollector.hh:232
LocalOp & asImp()
Definition: datacollector.hh:251
CombinedLocalDataCollect< LocalOp, B > & operator+(const B &b)
Definition: datacollector.hh:243
Definition: datacollector.hh:52
ReadWriteType
Definition: datacollector.hh:53
@ readData
Definition: datacollector.hh:53
@ writeData
Definition: datacollector.hh:53
Definition: datacollector.hh:59
void apply(Arg &arg) const
Definition: datacollector.hh:67
void apply(Arg1 &arg1, Arg2 &arg2) const
Definition: datacollector.hh:74
CombinedLocalDataCollect(const A &a, const B &b)
Definition: datacollector.hh:64
const B & b_
Definition: datacollector.hh:62
const A & a_
Definition: datacollector.hh:61
Definition: datacollector.hh:83
static void copyList(ListType &vec, const MyType &op)
Definition: datacollector.hh:130
LocalInterface(const MyType &op)
Definition: datacollector.hh:155
void apply(ParamType &p) const
for all pointer to local operators call the func pointer
Definition: datacollector.hh:163
virtual ~LocalInterface()
Definition: datacollector.hh:160
LocalInterface(const OpType &op)
Definition: datacollector.hh:150
bool empty() const
Definition: datacollector.hh:224
ObjectStreamExtractor< ParamT >::ObjectStreamType ObjectStreamType
Definition: datacollector.hh:103
std::pair< MyType *, FuncType * > PairType
Definition: datacollector.hh:108
LocalInterface< ParamT > MyType
Definition: datacollector.hh:85
std::vector< PairType > ListType
Definition: datacollector.hh:109
MyType & operator=(const OpType &op)
Definition: datacollector.hh:218
LocalInterface()
Definition: datacollector.hh:147
MyType & operator+=(const OpType &op)
Definition: datacollector.hh:190
void remove(const OpType &op)
Definition: datacollector.hh:203
MyType & operator+(const OpType &op)
Definition: datacollector.hh:177
ParamT ParamType
Definition: datacollector.hh:106
void FuncType(MyType &, ParamType &p)
Definition: datacollector.hh:107
Definition: datacollector.hh:87
ParamT ParamType
Definition: datacollector.hh:88
Definition: datacollector.hh:93
PT ObjectStreamType
Definition: datacollector.hh:94
T1 ObjectStreamType
Definition: datacollector.hh:100
Definition: datacollector.hh:113
static void applyWrapper(MyType &m, ParamType &p)
applyWrapper knows the real type of Op
Definition: datacollector.hh:115
static void addToList(ListType &vec, const OpType &op)
Definition: datacollector.hh:122
Definition: datacollector.hh:237
LocalInterface< ParamType > LocalInterfaceType
Definition: datacollector.hh:239
ParamT ParamType
Definition: datacollector.hh:238
Definition: datacollector.hh:262
DataCollectorInterface< GridType, ObjectStreamImp > MyType
Definition: datacollector.hh:269
std::pair< ObjectStreamType *, const EntityType * > DataCollectorParamType
Definition: datacollector.hh:270
MyType & operator=(const OpType &dc)
Assignement operator.
Definition: datacollector.hh:361
virtual void clear()
clear object list
Definition: datacollector.hh:379
GridType::template Codim< 0 >::Entity EntityType
Definition: datacollector.hh:267
MyType & operator+=(const OpType &dc)
Assignement operator.
Definition: datacollector.hh:325
virtual LocalInterfaceType & getLocalInterfaceOp()
Definition: datacollector.hh:311
LocalInterface< DataCollectorParamType > LocalInterfaceType
Definition: datacollector.hh:273
virtual const LocalInterfaceType & getLocalInterfaceOp() const
Definition: datacollector.hh:299
virtual ~DataCollectorInterface()
Virtual desctructor.
Definition: datacollector.hh:284
ObjectStreamImp ObjectStreamType
Definition: datacollector.hh:264
virtual void apply(ObjectStreamType &str, const EntityType &entity) const
Definition: datacollector.hh:289
DataCollectorInterface()
empty constructor
Definition: datacollector.hh:281
Definition: datacollector.hh:276
LocalInterface< DataCollectorParamType > LocalInterfaceType
Definition: datacollector.hh:277
empty data collector
Definition: datacollector.hh:393
MyType & operator+=(const OpType &dc)
Assignement operator.
Definition: datacollector.hh:409
MyType & operator=(const OpType &dc)
Assignement operator.
Definition: datacollector.hh:416
void apply(int, int) const
Definition: datacollector.hh:402
std::pair< int *, int * > DataCollectorParamType
Definition: datacollector.hh:397
LocalInterface< DataCollectorParamType > LocalInterfaceType
Definition: datacollector.hh:398
The DataCollector is an example for a grid walk done while load balancing moves entities from one pro...
Definition: datacollector.hh:436
const LocalDataCollectImp & getLocalOp() const
return reference to loacl Operator
Definition: datacollector.hh:529
void apply(ObjectStreamType &str, const EntityType &entity) const
Definition: datacollector.hh:557
DofManager< GridType > DofManagerType
Definition: datacollector.hh:446
DataCollector(GridType &grid, DofManagerType &dm, LocalDataCollectImp &ldc, const ReadWriteType rwType, int numChildren=8)
create DiscreteOperator with a LocalOperator
Definition: datacollector.hh:456
const LocalInterfaceType & getLocalInterfaceOp() const
Definition: datacollector.hh:540
std::pair< ObjectStreamType *, const EntityType * > ParamType
Definition: datacollector.hh:448
LocalInterface< ParamType > LocalInterfaceType
Definition: datacollector.hh:449
DataCollectorTraits::ReadWriteType ReadWriteType
Definition: datacollector.hh:443
DataCollectorInterface< GridType, ObjectStreamType > BaseType
Definition: datacollector.hh:442
void inlineData(ObjectStreamType &str, const EntityType &entity) const
write all data of all entities blowe this Entity to the stream
Definition: datacollector.hh:565
void xtractData(ObjectStreamType &str, const EntityType &entity) const
read all data of all entities blowe this Entity from the stream
Definition: datacollector.hh:584
LocalInterfaceType & getLocalInterfaceOp()
Definition: datacollector.hh:546
bool writeData() const
return true if data collector is writing data instead of reading
Definition: datacollector.hh:553
virtual ~DataCollector()
Desctructor.
Definition: datacollector.hh:467
DataCollectorInterface< GridType, ObjectStreamType > DataCollectorInterfaceType
Definition: datacollector.hh:452
GridType::template Codim< 0 >::Entity EntityType
Definition: datacollector.hh:439
LocalDataCollectImp::ObjectStreamType ObjectStreamType
Definition: datacollector.hh:438
DataCollector< GridType, CombinedLocalDataCollect< LocalDataCollectImp, LocalDataCollectType > > & operator+(const DataCollector< GridType, LocalDataCollectType > &op)
operator + (combine this operator) and return new Object
Definition: datacollector.hh:473
DataCollector< GridType, LocalInterface< ParamType > > & operator+=(const DataCollector< GridType, LocalDataCollectType > &op)
oeprator += combine and return this Object
Definition: datacollector.hh:493
LocalDataCollectImp & getLocalOp()
return reference to loacl Operator
Definition: datacollector.hh:535
DataCollector< EntityType, LocalDataCollectImp > MyType
Definition: datacollector.hh:445
Definition: datacollector.hh:659
LocalInterface< ParamType > LocalInterfaceType
Definition: datacollector.hh:670
DiscreteFunctionSpaceType::GridType GridType
Definition: datacollector.hh:662
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: datacollector.hh:661
DofManager< GridType > DofManagerType
Definition: datacollector.hh:666
std::pair< ObjectStreamType *, const GridEntityType * > ParamType
Definition: datacollector.hh:669
DofManagerType::InlineStreamType ObjectStreamType
Definition: datacollector.hh:667
DiscreteFunctionSpaceType::EntityType EntityType
Definition: datacollector.hh:663
GridType::template Codim< 0 >::Entity GridEntityType
Definition: datacollector.hh:664
Inline DiscreteFunction data during load balancing.
Definition: datacollector.hh:680
LocalDataInliner(const DiscreteFunctionType &df, const ContainsCheck &containsCheck)
constructor
Definition: datacollector.hh:699
Traits::GridEntityType GridEntityType
Definition: datacollector.hh:688
LocalDofVectorType ldv_
Definition: datacollector.hh:745
Dune::DynamicVector< DofType > LocalDofVectorType
Definition: datacollector.hh:696
Traits::EntityType EntityType
Definition: datacollector.hh:687
LocalInterface< ParamType > LocalInterfaceType
Definition: datacollector.hh:691
const DiscreteFunctionType & df_
Definition: datacollector.hh:742
LocalDataInliner(const LocalDataInliner &other)
copy constructor
Definition: datacollector.hh:708
const ContainsCheck containsCheck_
Definition: datacollector.hh:744
void apply(ParamType &p) const
store data to stream
Definition: datacollector.hh:716
DataCollectorTraits::ReadWriteType readWriteInfo() const
Definition: datacollector.hh:724
Traits::ParamType ParamType
Definition: datacollector.hh:689
LocalDataInlinerTraits< DiscreteFunctionType > Traits
Definition: datacollector.hh:682
Traits::ObjectStreamType ObjectStreamType
Definition: datacollector.hh:683
void inlineData(ObjectStreamType &str, const EntityType &entity, const GridEntityType &gridEntity) const
store data to stream
Definition: datacollector.hh:727
Traits::DofManagerType DofManagerType
Definition: datacollector.hh:685
DofManagerType & dm_
Definition: datacollector.hh:743
DiscreteFunctionTraits< DiscreteFunctionType >::DofType DofType
Definition: datacollector.hh:693
Definition: datacollector.hh:751
DiscreteFunctionSpaceType::GridType GridType
Definition: datacollector.hh:754
GridType::template Codim< 0 >::Entity GridEntityType
Definition: datacollector.hh:756
DofManagerType::XtractStreamType ObjectStreamType
Definition: datacollector.hh:759
std::pair< ObjectStreamType *, const GridEntityType * > ParamType
Definition: datacollector.hh:761
DofManager< GridType > DofManagerType
Definition: datacollector.hh:758
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: datacollector.hh:753
DiscreteFunctionSpaceType::EntityType EntityType
Definition: datacollector.hh:755
LocalInterface< ParamType > LocalInterfaceType
Definition: datacollector.hh:762
Inline DiscreteFunction data during load balancing.
Definition: datacollector.hh:772
DiscreteFunctionType & df_
Definition: datacollector.hh:835
const ContainsCheck containsCheck_
Definition: datacollector.hh:837
Traits::ObjectStreamType ObjectStreamType
Definition: datacollector.hh:775
LocalDataXtractorTraits< DiscreteFunctionType > Traits
Definition: datacollector.hh:774
Traits::EntityType EntityType
Definition: datacollector.hh:779
LocalDataXtractor(const LocalDataXtractor &other)
copy constructor
Definition: datacollector.hh:800
Dune::DynamicVector< DofType > LocalDofVectorType
Definition: datacollector.hh:788
LocalDofVectorType ldv_
Definition: datacollector.hh:838
LocalDataXtractor(DiscreteFunctionType &df, const ContainsCheck &containsCheck)
constructor
Definition: datacollector.hh:791
Traits::DofManagerType DofManagerType
Definition: datacollector.hh:777
DiscreteFunctionTraits< DiscreteFunctionType >::DofType DofType
Definition: datacollector.hh:785
DataCollectorTraits::ReadWriteType readWriteInfo() const
Definition: datacollector.hh:816
DofManagerType & dm_
Definition: datacollector.hh:836
Traits::GridEntityType GridEntityType
Definition: datacollector.hh:780
void apply(ParamType &p) const
store data to stream
Definition: datacollector.hh:808
Traits::LocalInterfaceType LocalInterfaceType
Definition: datacollector.hh:783
Traits::ParamType ParamType
Definition: datacollector.hh:781
void xtractData(ObjectStreamType &str, const EntityType &entity, const GridEntityType &gridEntity) const
store data to stream
Definition: datacollector.hh:819