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;
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);
122 static void addToList (ListType & vec ,
const OpType & op )
124 PairType p( const_cast<OpType *> (&op) , applyWrapper);
130 static void copyList (ListType & vec,
const MyType & op )
132 const ListType & ve = op.vec_;
135 ListType tmp ( vec );
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>
152 AddToWrapper<OpType>::addToList(vec_,op);
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>
179 AddToWrapper<OpType>::addToList(vec_,op);
189 template <
class OpType>
190 MyType & operator += (
const OpType & op)
192 AddToWrapper<OpType>::addToList(vec_,op);
196 MyType & operator += (
const MyType & op)
202 template <
class OpType>
203 void remove(
const OpType & op)
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>
218 MyType & operator = (
const OpType & op)
220 AddToWrapper<OpType>::addToList(vec_,op);
224 bool empty ()
const {
return (vec_.size() == 0); }
227 mutable ListType vec_;
230 template <
class LocalOp,
class ParamT>
245 std::cout <<
"operator + of LocalInlinePlus \n";
247 CombinedType * combo =
new CombinedType ( asImp() , b );
248 this->saveObjPointer( combo );
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;
289 virtual void apply (ObjectStreamType &str,
const EntityType & entity )
const 292 if(dc_) (*dc_).apply(str, entity );
295 std::cerr <<
"WARNING: apply: did nothing! \n";
302 return dc_->getLocalInterfaceOp ();
305 std::cerr <<
"No LocalInterfaceOperator \n";
307 return *(
new LocalInterfaceType());
314 return dc_->getLocalInterfaceOp ();
317 std::cerr <<
"No LocalInterfaceOperator \n";
319 return *(
new LocalInterfaceType());
324 template <
class OpType>
325 MyType & operator += (
const OpType & dc)
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();
343 virtual MyType & operator += (
const MyType & dc)
349 dc_ = &(*dc_).operator += (dc);
353 dc_ =
const_cast<MyType *
> (&dc);
354 dcConv_ =
const_cast<MyType *
> (&dc);
360 template <
class OpType>
361 MyType & operator = (
const OpType & dc)
364 dc_ =
const_cast<OpType *
> (&dc);
365 dcConv_ =
const_cast<OpType &
> (dc).convert();
370 MyType & operator = (
const MyType & dc)
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>
409 MyType & operator += (
const OpType & dc)
415 template <
class OpType>
416 MyType & operator = (
const OpType & dc)
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,
459 const ReadWriteType rwType,
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_ );
485 saveObjPointer( dcOp , newLDCOp );
491 template <
class LocalDataCollectType>
497 COType *newLDCOp =
new COType ( ldc_ + op.
getLocalOp() );
500 OPType *dcOp =
new OPType ( grid_ , dm_ , *newLDCOp, rwType_ );
504 saveObjPointer( dcOp , newLDCOp );
510 DataCollectorInterfaceType &
511 operator += (
const DataCollectorInterfaceType &op)
519 OPType *dcOp =
new OPType ( grid_ , dm_ , *newLDCOp, rwType_ );
523 saveObjPointer( dcOp , newLDCOp );
557 void apply ( ObjectStreamType & str,
const EntityType & entity )
const 559 ParamType p( &str , &entity );
565 void inlineData (ObjectStreamType & str,
const EntityType & entity )
const 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);
584 void xtractData (ObjectStreamType & str,
const EntityType & entity )
const 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_ );
614 saveObjPointer( dcOp , newLDCOp );
620 void inlineLocal(ObjectStreamType & str,
const EntityType& entity )
const 624 ParamType p( &str , &entity );
630 void xtractLocal(ObjectStreamType & str,
const EntityType& entity )
const 634 ParamType p( &str , &entity );
646 LocalDataCollectImp &ldc_;
649 const ReadWriteType rwType_;
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 )
700 dm_( DofManagerType::instance( df.gridPart().grid() ) ),
701 containsCheck_( containsCheck )
708 containsCheck_( other.containsCheck_ )
714 assert( p.first && p.second );
715 const EntityType& entity = df_.space().gridPart().convert( *p.second );
716 inlineData( *p.first, entity, *p.second );
724 const EntityType& entity,
727 if( ! containsCheck_.contains ( entity ) )
return ;
729 assert( df_.space().indexSet().contains( entity ) );
731 LocalDofVectorType ldv( df_.space().basisFunctionSet( entity ).size(), df_.localDofVectorAllocator() );
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 )
787 dm_( DofManagerType :: instance( df.gridPart().grid() ) ),
788 containsCheck_( containsCheck )
795 containsCheck_( other.containsCheck_ )
801 assert( p.first && p.second );
802 const EntityType& entity = df_.space().gridPart().convert( *p.second );
803 xtractData( *p.first, entity, *p.second );
811 const EntityType& entity,
814 if( ! containsCheck_.contains ( entity ) )
return ;
817 assert( df_.space().indexSet().contains( entity ) );
819 LocalDofVectorType ldv( df_.space().basisFunctionSet( entity ).size(), df_.localDofVectorAllocator() );
820 for( DofType &dof : ldv )
822 df_.setLocalDofs( entity, ldv );
826 DiscreteFunctionType &
df_;
837 #endif // #ifndef DUNE_FEM_DATACOLLECTOR_HH DataCollectorTraits::ReadWriteType readWriteInfo() const
Definition: datacollector.hh:720
void inlineData(ObjectStreamType &str, const EntityType &entity, const GridEntityType &gridEntity) const
store data to stream
Definition: datacollector.hh:723
Definition: datacollector.hh:47
LocalInterface< DataCollectorParamType > LocalInterfaceType
Definition: datacollector.hh:398
Traits::EntityType EntityType
Definition: datacollector.hh:687
Traits::GridEntityType GridEntityType
Definition: datacollector.hh:775
void apply(ObjectStreamType &str, const EntityType &entity) const
Definition: datacollector.hh:557
const LocalDataCollectImp & getLocalOp() const
return reference to loacl Operator
Definition: datacollector.hh:529
LocalDataInliner(const DiscreteFunctionType &df, const ContainsCheck &containsCheck)
constructor
Definition: datacollector.hh:697
empty data collector
Definition: datacollector.hh:392
void inlineData(ObjectStreamType &str, const EntityType &entity) const
write all data of all entities blowe this Entity to the stream
Definition: datacollector.hh:565
ReadWriteType
Definition: datacollector.hh:53
ParamT ParamType
Definition: datacollector.hh:238
Traits::ParamType ParamType
Definition: datacollector.hh:776
LocalDataCollectImp & getLocalOp()
return reference to loacl Operator
Definition: datacollector.hh:535
Definition: datacollector.hh:86
GridType::template Codim< 0 >::Entity GridEntityType
Definition: datacollector.hh:664
const DiscreteFunctionType & df_
Definition: datacollector.hh:738
std::pair< MyType *, FuncType * > PairType
Definition: datacollector.hh:108
const ContainsCheck containsCheck_
Definition: datacollector.hh:740
std::pair< ObjectStreamType *, const EntityType * > ParamType
Definition: datacollector.hh:448
Definition: datacollector.hh:236
Definition: datacollector.hh:658
Definition: datacollector.hh:57
void xtractData(ObjectStreamType &str, const EntityType &entity) const
read all data of all entities blowe this Entity from the stream
Definition: datacollector.hh:584
static void copyList(ListType &vec, const MyType &op)
Definition: datacollector.hh:130
const B & b_
Definition: datacollector.hh:62
The DataCollector is an example for a grid walk done while load balancing moves entities from one pro...
Definition: datacollector.hh:433
PT ObjectStreamType
Definition: datacollector.hh:94
void apply(ParamType &p) const
store data to stream
Definition: datacollector.hh:799
ObjectStreamExtractor< LocalDataInlinerTraits< DiscreteFunctionType >::ParamType >::ObjectStreamType ObjectStreamType
Definition: datacollector.hh:103
bool empty() const
Definition: datacollector.hh:224
LocalDataXtractor(const LocalDataXtractor &other)
copy constructor
Definition: datacollector.hh:792
Traits class for a DiscreteFunction.
Definition: discretefunction.hh:60
DofManagerType::XtractStreamType ObjectStreamType
Definition: datacollector.hh:754
LocalDataInliner(const LocalDataInliner &other)
copy constructor
Definition: datacollector.hh:705
LocalInterface< ParamT > MyType
Definition: datacollector.hh:85
LocalOp & asImp()
Definition: datacollector.hh:251
std::pair< int *, int * > DataCollectorParamType
Definition: datacollector.hh:397
Traits::LocalInterfaceType LocalInterfaceType
Definition: datacollector.hh:778
Definition: datacollector.hh:53
DofManagerType::InlineStreamType ObjectStreamType
Definition: datacollector.hh:667
Definition: datacollector.hh:45
LocalInterface< ParamType > LocalInterfaceType
Definition: datacollector.hh:449
Dune::DynamicVector< DofType, typename DiscreteFunctionTraits< DiscreteFunctionType >::LocalDofVectorAllocatorType::template rebind< DofType >::other > LocalDofVectorType
Definition: datacollector.hh:694
static void addToList(ListType &vec, const OpType &op)
Definition: datacollector.hh:122
GridType::template Codim< 0 >::Entity GridEntityType
Definition: datacollector.hh:751
void FuncType(MyType &, ParamType &p)
Definition: datacollector.hh:107
Dune::DynamicVector< DofType, typename DiscreteFunctionTraits< DiscreteFunctionType >::LocalDofVectorAllocatorType::template rebind< DofType >::other > LocalDofVectorType
Definition: datacollector.hh:781
DataCollectorInterface()
empty constructor
Definition: datacollector.hh:281
Inline DiscreteFunction data during load balancing.
Definition: datacollector.hh:677
void apply(int, int) const
Definition: datacollector.hh:402
Definition: datacollector.hh:53
DofManager< GridType > DofManagerType
Definition: datacollector.hh:753
DataCollector< EntityType, LocalDataCollectImp > MyType
Definition: datacollector.hh:445
DiscreteFunctionSpaceType::EntityType EntityType
Definition: datacollector.hh:750
Definition: datacollector.hh:92
DiscreteFunctionType & df_
Definition: datacollector.hh:826
ObjectStreamImp ObjectStreamType
Definition: datacollector.hh:264
Definition: datacollector.hh:112
LocalInterface< DataCollectorParamType > LocalInterfaceType
Definition: datacollector.hh:277
CombinedLocalDataCollect(const A &a, const B &b)
Definition: datacollector.hh:64
DiscreteFunctionSpaceType::EntityType EntityType
Definition: datacollector.hh:663
LocalInterface< ParamType > LocalInterfaceType
Definition: datacollector.hh:670
Definition: datacollector.hh:51
Traits::ObjectStreamType ObjectStreamType
Definition: datacollector.hh:770
Traits::DofManagerType DofManagerType
Definition: datacollector.hh:772
Definition: objpointer.hh:37
std::vector< PairType > ListType
Definition: datacollector.hh:109
virtual ~DataCollector()
Desctructor.
Definition: datacollector.hh:467
LocalInterfaceType & getLocalInterfaceOp()
Definition: datacollector.hh:546
DiscreteFunctionSpaceType::GridType GridType
Definition: datacollector.hh:749
DiscreteFunctionTraits< DiscreteFunctionType >::DofType DofType
Definition: datacollector.hh:693
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: datacollector.hh:748
Definition: coordinate.hh:4
Definition: datacollector.hh:275
DofManager< GridType > DofManagerType
Definition: datacollector.hh:666
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: datacollector.hh:661
DataCollectorInterface< GridType, ObjectStreamImp > MyType
Definition: datacollector.hh:269
Definition: datacollector.hh:745
DiscreteFunctionTraits< DiscreteFunctionType >::DofType DofType
Definition: datacollector.hh:780
virtual ~DataCollectorInterface()
Virtual desctructor.
Definition: datacollector.hh:284
void apply(Arg1 &arg1, Arg2 &arg2) const
Definition: datacollector.hh:74
DofManagerType & dm_
Definition: datacollector.hh:827
const LocalInterfaceType & getLocalInterfaceOp() const
Definition: datacollector.hh:540
LocalInterface< ParamType > LocalInterfaceType
Definition: datacollector.hh:239
const A & a_
Definition: datacollector.hh:61
const ContainsCheck containsCheck_
Definition: datacollector.hh:828
virtual void apply(ObjectStreamType &str, const EntityType &entity) const
Definition: datacollector.hh:289
virtual ~LocalInterface()
Definition: datacollector.hh:160
virtual void clear()
clear object list
Definition: datacollector.hh:379
LocalInterface< DataCollectorParamType > LocalInterfaceType
Definition: datacollector.hh:273
LocalInterface()
Definition: datacollector.hh:147
DataCollectorTraits::ReadWriteType readWriteInfo() const
Definition: datacollector.hh:807
LocalInterface< ParamType > LocalInterfaceType
Definition: datacollector.hh:757
ParamT ParamType
Definition: datacollector.hh:88
DataCollector(GridType &grid, DofManagerType &dm, LocalDataCollectImp &ldc, const ReadWriteType rwType, int numChildren=8)
create DiscreteOperator with a LocalOperator
Definition: datacollector.hh:456
DataCollectorInterface< GridType, ObjectStreamType > BaseType
Definition: datacollector.hh:442
GridType::template Codim< 0 >::Entity EntityType
Definition: datacollector.hh:439
const GridEntityAccess< Entity >::GridEntityType & gridEntity(const Entity &entity)
Definition: gridpart.hh:410
LocalInterface(const MyType &op)
Definition: datacollector.hh:155
DofManagerType & dm_
Definition: datacollector.hh:739
std::pair< ObjectStreamType *, const GridEntityType * > ParamType
Definition: datacollector.hh:669
ParamT ParamType
Definition: datacollector.hh:106
Traits::DofManagerType DofManagerType
Definition: datacollector.hh:685
Traits::ObjectStreamType ObjectStreamType
Definition: datacollector.hh:683
void apply(ParamType &p) const
for all pointer to local operators call the func pointer
Definition: datacollector.hh:163
void apply(ParamType &p) const
store data to stream
Definition: datacollector.hh:712
virtual LocalInterfaceType & getLocalInterfaceOp()
Definition: datacollector.hh:311
Inline DiscreteFunction data during load balancing.
Definition: datacollector.hh:764
LocalInterface(const OpType &op)
Definition: datacollector.hh:150
DataCollectorInterface< GridType, ObjectStreamType > DataCollectorInterfaceType
Definition: datacollector.hh:452
Definition: datacollector.hh:82
Traits::ParamType ParamType
Definition: datacollector.hh:689
Definition: datacollector.hh:261
bool writeData() const
return true if data collector is writing data instead of reading
Definition: datacollector.hh:553
MessageBufferIF< InlineStreamImplType > InlineStreamType
Definition: dofmanager.hh:823
Traits::GridEntityType GridEntityType
Definition: datacollector.hh:688
void apply(Arg &arg) const
Definition: datacollector.hh:67
MessageBufferIF< XtractStreamImplType > XtractStreamType
Definition: dofmanager.hh:822
DiscreteFunctionSpaceType::GridType GridType
Definition: datacollector.hh:662
T1 ObjectStreamType
Definition: datacollector.hh:100
std::pair< ObjectStreamType *, const EntityType * > DataCollectorParamType
Definition: datacollector.hh:270
virtual const LocalInterfaceType & getLocalInterfaceOp() const
Definition: datacollector.hh:299
DataCollectorTraits::ReadWriteType ReadWriteType
Definition: datacollector.hh:443
DofManager< GridType > DofManagerType
Definition: datacollector.hh:446
LocalInterface< ParamType > LocalInterfaceType
Definition: datacollector.hh:691
GridType::template Codim< 0 >::Entity EntityType
Definition: datacollector.hh:267
Double operator+(const Double &a, const Double &b)
Definition: double.hh:401
std::pair< ObjectStreamType *, const GridEntityType * > ParamType
Definition: datacollector.hh:756
LocalDataXtractorTraits< DiscreteFunctionType > Traits
Definition: datacollector.hh:769
LocalDataCollectImp::ObjectStreamType ObjectStreamType
Definition: datacollector.hh:438
void xtractData(ObjectStreamType &str, const EntityType &entity, const GridEntityType &gridEntity) const
store data to stream
Definition: datacollector.hh:810
static void applyWrapper(MyType &m, ParamType &p)
applyWrapper knows the real type of Op
Definition: datacollector.hh:115
LocalDataXtractor(DiscreteFunctionType &df, const ContainsCheck &containsCheck)
constructor
Definition: datacollector.hh:784
Traits::EntityType EntityType
Definition: datacollector.hh:774
LocalDataInlinerTraits< DiscreteFunctionType > Traits
Definition: datacollector.hh:682