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>
478 COType *newLDCOp =
new COType ( ldc_ ,
const_cast<CopyType &
> (op).
getLocalOp() );
481 OPType *dcOp =
new OPType ( grid_ , dm_ , *newLDCOp, rwType_ );
491 template <
class LocalDataCollectType>
497 COType *newLDCOp =
new COType ( ldc_ + op.
getLocalOp() );
500 OPType *dcOp =
new OPType ( grid_ , dm_ , *newLDCOp, rwType_ );
519 OPType *dcOp =
new OPType ( grid_ , dm_ , *newLDCOp, rwType_ );
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_ );
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 >
694 typedef Dune::DynamicVector< DofType, typename DiscreteFunctionTraits< DiscreteFunctionType >::LocalDofVectorAllocatorType::template rebind< DofType >::other >
LocalDofVectorType;
698 const ContainsCheck& containsCheck )
714 assert( p.first && p.second );
715 const EntityType& entity =
df_.space().gridPart().convert( *p.second );
729 assert(
df_.space().indexSet().contains( entity ) );
732 df_.getLocalDofs( entity, ldv );
733 for(
const DofType &dof : ldv )
738 const DiscreteFunctionType &
df_;
744 template<
class DiscreteFunctionType >
747 typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType
749 typedef typename DiscreteFunctionSpaceType::GridType
GridType;
750 typedef typename DiscreteFunctionSpaceType::EntityType
EntityType;
756 typedef std::pair< ObjectStreamType *, const GridEntityType * >
ParamType;
762 template<
class DiscreteFunctionType,
763 class ContainsCheck >
765 :
public LocalInlinePlus< LocalDataXtractor< DiscreteFunctionType, ContainsCheck >,
766 typename LocalDataXtractorTraits< DiscreteFunctionType >::ParamType >
781 typedef Dune::DynamicVector< DofType, typename DiscreteFunctionTraits< DiscreteFunctionType >::LocalDofVectorAllocatorType::template rebind< DofType >::other >
LocalDofVectorType;
785 const ContainsCheck& containsCheck )
801 assert( p.first && p.second );
802 const EntityType& entity =
df_.space().gridPart().convert( *p.second );
817 assert(
df_.space().indexSet().contains( entity ) );
822 df_.setLocalDofs( entity, ldv );
826 DiscreteFunctionType &
df_;
MessageBufferIF< InlineStreamImplType > InlineStreamType
Definition: dofmanager.hh:840
MessageBufferIF< XtractStreamImplType > XtractStreamType
Definition: dofmanager.hh:839
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:60
Definition: objpointer.hh:42
void saveObjPointer(DiscrOpType *discrOp)
Store new generated DiscreteOperator Pointer.
Definition: objpointer.hh:58
Definition: dofmanager.hh:825
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
std::pair< MyType *, FuncType * > PairType
Definition: datacollector.hh:108
LocalInterface< ParamT > MyType
Definition: datacollector.hh:85
MyType & operator=(const OpType &op)
Definition: datacollector.hh:218
std::vector< PairType > ListType
Definition: datacollector.hh:109
ObjectStreamExtractor< LocalDataInlinerTraits< DiscreteFunctionType >::ParamType >::ObjectStreamType ObjectStreamType
Definition: datacollector.hh:103
LocalInterface()
Definition: datacollector.hh:147
void remove(const OpType &op)
Definition: datacollector.hh:203
MyType & operator+=(const OpType &op)
Definition: datacollector.hh:190
ParamT ParamType
Definition: datacollector.hh:106
MyType & operator+(const OpType &op)
Definition: datacollector.hh:177
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
MyType & operator=(const OpType &dc)
Assignement operator.
Definition: datacollector.hh:361
std::pair< ObjectStreamType *, const EntityType * > DataCollectorParamType
Definition: datacollector.hh:270
virtual void clear()
clear object list
Definition: datacollector.hh:379
GridType::template Codim< 0 >::Entity EntityType
Definition: datacollector.hh:267
LocalInterface< DataCollectorParamType > LocalInterfaceType
Definition: datacollector.hh:273
virtual ~DataCollectorInterface()
Virtual desctructor.
Definition: datacollector.hh:284
virtual const LocalInterfaceType & getLocalInterfaceOp() const
Definition: datacollector.hh:299
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
MyType & operator+=(const OpType &dc)
Assignement operator.
Definition: datacollector.hh:325
virtual LocalInterfaceType & getLocalInterfaceOp()
Definition: datacollector.hh:311
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: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
MyType & operator+=(const OpType &dc)
Assignement operator.
Definition: datacollector.hh:409
The DataCollector is an example for a grid walk done while load balancing moves entities from one pro...
Definition: datacollector.hh:436
void apply(ObjectStreamType &str, const EntityType &entity) const
Definition: datacollector.hh:557
DofManager< GridType > DofManagerType
Definition: datacollector.hh:446
LocalDataCollectImp & getLocalOp()
return reference to loacl Operator
Definition: datacollector.hh:535
DataCollector(GridType &grid, DofManagerType &dm, LocalDataCollectImp &ldc, const ReadWriteType rwType, int numChildren=8)
create DiscreteOperator with a LocalOperator
Definition: datacollector.hh:456
LocalDataCollectImp ::ObjectStreamType ObjectStreamType
Definition: datacollector.hh:438
std::pair< ObjectStreamType *, const EntityType * > ParamType
Definition: datacollector.hh:448
LocalInterface< ParamType > LocalInterfaceType
Definition: datacollector.hh:449
DataCollectorTraits ::ReadWriteType ReadWriteType
Definition: datacollector.hh:443
LocalInterfaceType & getLocalInterfaceOp()
Definition: datacollector.hh:546
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
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
const LocalDataCollectImp & getLocalOp() const
return reference to loacl Operator
Definition: datacollector.hh:529
GridType::template Codim< 0 >::Entity EntityType
Definition: datacollector.hh:439
DataCollector< GridType, CombinedLocalDataCollect< LocalDataCollectImp, LocalDataCollectType > > & operator+(const DataCollector< GridType, LocalDataCollectType > &op)
operator + (combine this operator) and return new Object
Definition: datacollector.hh:473
const LocalInterfaceType & getLocalInterfaceOp() const
Definition: datacollector.hh:540
DataCollector< GridType, LocalInterface< ParamType > > & operator+=(const DataCollector< GridType, LocalDataCollectType > &op)
oeprator += combine and return this Object
Definition: datacollector.hh:493
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
GridType ::template Codim< 0 >::Entity GridEntityType
Definition: datacollector.hh:664
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: datacollector.hh:661
DofManager< GridType > DofManagerType
Definition: datacollector.hh:666
std::pair< ObjectStreamType *, const GridEntityType * > ParamType
Definition: datacollector.hh:669
DiscreteFunctionSpaceType::EntityType EntityType
Definition: datacollector.hh:663
DofManagerType ::InlineStreamType ObjectStreamType
Definition: datacollector.hh:667
Inline DiscreteFunction data during load balancing.
Definition: datacollector.hh:680
LocalDataInliner(const DiscreteFunctionType &df, const ContainsCheck &containsCheck)
constructor
Definition: datacollector.hh:697
Traits::GridEntityType GridEntityType
Definition: datacollector.hh:688
Traits::EntityType EntityType
Definition: datacollector.hh:687
LocalInterface< ParamType > LocalInterfaceType
Definition: datacollector.hh:691
const DiscreteFunctionType & df_
Definition: datacollector.hh:738
LocalDataInliner(const LocalDataInliner &other)
copy constructor
Definition: datacollector.hh:705
DataCollectorTraits ::ReadWriteType readWriteInfo() const
Definition: datacollector.hh:720
const ContainsCheck containsCheck_
Definition: datacollector.hh:740
void apply(ParamType &p) const
store data to stream
Definition: datacollector.hh:712
DiscreteFunctionTraits< DiscreteFunctionType >::DofType DofType
Definition: datacollector.hh:693
Dune::DynamicVector< DofType, typename DiscreteFunctionTraits< DiscreteFunctionType >::LocalDofVectorAllocatorType::template rebind< DofType >::other > LocalDofVectorType
Definition: datacollector.hh:694
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:723
Traits::DofManagerType DofManagerType
Definition: datacollector.hh:685
DofManagerType & dm_
Definition: datacollector.hh:739
Definition: datacollector.hh:746
DiscreteFunctionSpaceType::GridType GridType
Definition: datacollector.hh:749
std::pair< ObjectStreamType *, const GridEntityType * > ParamType
Definition: datacollector.hh:756
DofManager< GridType > DofManagerType
Definition: datacollector.hh:753
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: datacollector.hh:748
DiscreteFunctionSpaceType::EntityType EntityType
Definition: datacollector.hh:750
DofManagerType ::XtractStreamType ObjectStreamType
Definition: datacollector.hh:754
LocalInterface< ParamType > LocalInterfaceType
Definition: datacollector.hh:757
GridType ::template Codim< 0 >::Entity GridEntityType
Definition: datacollector.hh:751
Inline DiscreteFunction data during load balancing.
Definition: datacollector.hh:767
DataCollectorTraits ::ReadWriteType readWriteInfo() const
Definition: datacollector.hh:807
DiscreteFunctionType & df_
Definition: datacollector.hh:826
const ContainsCheck containsCheck_
Definition: datacollector.hh:828
Traits::ObjectStreamType ObjectStreamType
Definition: datacollector.hh:770
LocalDataXtractorTraits< DiscreteFunctionType > Traits
Definition: datacollector.hh:769
Traits::EntityType EntityType
Definition: datacollector.hh:774
LocalDataXtractor(const LocalDataXtractor &other)
copy constructor
Definition: datacollector.hh:792
LocalDataXtractor(DiscreteFunctionType &df, const ContainsCheck &containsCheck)
constructor
Definition: datacollector.hh:784
Traits::DofManagerType DofManagerType
Definition: datacollector.hh:772
DofManagerType & dm_
Definition: datacollector.hh:827
Dune::DynamicVector< DofType, typename DiscreteFunctionTraits< DiscreteFunctionType >::LocalDofVectorAllocatorType::template rebind< DofType >::other > LocalDofVectorType
Definition: datacollector.hh:781
Traits::GridEntityType GridEntityType
Definition: datacollector.hh:775
void apply(ParamType &p) const
store data to stream
Definition: datacollector.hh:799
Traits::LocalInterfaceType LocalInterfaceType
Definition: datacollector.hh:778
Traits::ParamType ParamType
Definition: datacollector.hh:776
void xtractData(ObjectStreamType &str, const EntityType &entity, const GridEntityType &gridEntity) const
store data to stream
Definition: datacollector.hh:810
DiscreteFunctionTraits< DiscreteFunctionType >::DofType DofType
Definition: datacollector.hh:780