1#ifndef DUNE_FEM_DATACOLLECTOR_HH
2#define DUNE_FEM_DATACOLLECTOR_HH
17#include <dune/fem/misc/gridobjectstreams.hh>
18#include <dune/fem/operator/common/objpointer.hh>
43 struct DiscreteFunctionTraits;
45 template <
class Gr
idImp>
class DofManager;
47 template <
class LocalOp,
class ParamType>
class LocalInlinePlus;
51 struct DataCollectorTraits
53 enum ReadWriteType { readData , writeData };
56 template <
class A,
class B >
57 class CombinedLocalDataCollect
58 :
public LocalInlinePlus< CombinedLocalDataCollect< A, B >, typename A::Traits::ParamType >
64 CombinedLocalDataCollect(
const A& a,
const B& b ) : a_( a ), b_( b ) {}
67 void apply(Arg & arg)
const
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>
82 class LocalInterface :
public ObjPointerStorage
85 typedef LocalInterface<ParamT> MyType;
88 typedef ParamT ParamType;
92 struct ObjectStreamExtractor
94 typedef PT ObjectStreamType ;
97 template <
class T1 ,
class T2 >
98 struct ObjectStreamExtractor<
std::pair< T1* , const T2* > >
100 typedef T1 ObjectStreamType ;
103 typedef typename ObjectStreamExtractor< ParamT > :: ObjectStreamType ObjectStreamType;
106 typedef ParamT ParamType;
107 typedef void FuncType(MyType &, ParamType & p);
108 typedef typename std::pair < MyType * , FuncType * > PairType;
109 typedef typename std::vector < PairType > ListType;
111 template <
class OpType>
115 static void applyWrapper(MyType & m, ParamType & p )
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()];
147 LocalInterface () : vec_ (0) {}
149 template <
class OpType>
150 LocalInterface (
const OpType & op)
152 AddToWrapper<OpType>::addToList(vec_,op);
155 LocalInterface (
const MyType & op)
160 virtual ~LocalInterface() {};
163 void apply ( ParamType & p )
const
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>
177 MyType & operator + (
const OpType & op)
179 AddToWrapper<OpType>::addToList(vec_,op);
183 MyType & operator + (
const MyType & 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>
231 class LocalInlinePlus :
public LocalInterface<ParamT>
238 typedef ParamT ParamType;
239 typedef LocalInterface<ParamType> LocalInterfaceType;
243 CombinedLocalDataCollect<LocalOp,B> & operator + (
const B & b)
246 typedef CombinedLocalDataCollect<LocalOp,B> CombinedType;
247 CombinedType * combo =
new CombinedType ( asImp() , b );
251 LocalOp & asImp() {
return static_cast<LocalOp &
> (*this); }
260 template <
class Gr
idType,
class ObjectStreamImp = DummyObjectStream >
264 typedef ObjectStreamImp ObjectStreamType;
270 typedef std::pair < ObjectStreamType * , const EntityType * > DataCollectorParamType;
273 typedef LocalInterface<DataCollectorParamType> LocalInterfaceType;
277 typedef LocalInterface<DataCollectorParamType> LocalInterfaceType;
289 virtual void apply (ObjectStreamType &str,
const EntityType & entity )
const
294 (*dc_).apply(str, entity );
298 virtual const LocalInterfaceType & getLocalInterfaceOp ()
const
301 return dc_->getLocalInterfaceOp ();
304 std::cerr <<
"No LocalInterfaceOperator \n";
306 return *(
new LocalInterfaceType());
310 virtual LocalInterfaceType & getLocalInterfaceOp ()
313 return dc_->getLocalInterfaceOp ();
316 std::cerr <<
"No LocalInterfaceOperator \n";
318 return *(
new LocalInterfaceType());
323 template <
class OpType>
330 MyType * tmp =
const_cast<OpType &
> (dc).convert();
331 dc_ = &(*dc_).operator += (*tmp);
335 dc_ =
const_cast<OpType *
> (&dc);
336 dcConv_ =
const_cast<OpType &
> (dc).convert();
348 dc_ = &(*dc_).operator += (dc);
352 dc_ =
const_cast<MyType *
> (&dc);
353 dcConv_ =
const_cast<MyType *
> (&dc);
359 template <
class OpType>
363 dc_ =
const_cast<OpType *
> (&dc);
364 dcConv_ =
const_cast<OpType &
> (dc).convert();
372 dc_ =
const_cast<MyType *
> (dc.dc_);
373 dcConv_ =
const_cast<MyType *
> (dc.dcConv_);
390 template <
class Gr
idType>
396 typedef std::pair < int * , int * > DataCollectorParamType;
397 typedef LocalInterface<DataCollectorParamType> LocalInterfaceType;
403 std::cerr <<
"WARNING: apply: did nothing! \n";
407 template <
class OpType>
414 template <
class OpType>
430 template <
class GridType,
431 class LocalDataCollectImp >
437 typedef typename LocalDataCollectImp :: ObjectStreamType ObjectStreamType;
442 typedef typename DataCollectorTraits :: ReadWriteType ReadWriteType;
447 typedef typename std::pair < ObjectStreamType * , const EntityType * > ParamType;
448 typedef LocalInterface<ParamType> LocalInterfaceType;
457 LocalDataCollectImp & ldc,
458 const ReadWriteType rwType,
460 : grid_(grid) , dm_ ( dm ), ldc_ (ldc)
462 , numChildren_(numChildren)
469 template <
class LocalDataCollectType>
471 CombinedLocalDataCollect <LocalDataCollectImp,LocalDataCollectType> > &
475 typedef CombinedLocalDataCollect <LocalDataCollectImp,LocalDataCollectType> COType;
477 COType *newLDCOp =
new COType ( ldc_ ,
const_cast<CopyType &
> (op).
getLocalOp() );
480 OPType *dcOp =
new OPType ( grid_ , dm_ , *newLDCOp, rwType_ );
490 template <
class LocalDataCollectType>
494 typedef LocalInterface<ParamType> COType;
496 COType *newLDCOp =
new COType ( ldc_ + op.
getLocalOp() );
499 OPType *dcOp =
new OPType ( grid_ , dm_ , *newLDCOp, rwType_ );
509 DataCollectorInterfaceType &
513 typedef LocalInterface<ParamType> COType;
515 COType *newLDCOp =
new COType ( ldc_ + op.getLocalInterfaceOp() );
518 OPType *dcOp =
new OPType ( grid_ , dm_ , *newLDCOp, rwType_ );
539 const LocalInterfaceType & getLocalInterfaceOp ()
const
545 LocalInterfaceType & getLocalInterfaceOp ()
552 bool writeData()
const {
return rwType_ == DataCollectorTraits :: writeData ; }
556 void apply ( ObjectStreamType & str,
const EntityType & entity )
const
558 ParamType p( &str , &entity );
564 void inlineData (ObjectStreamType & str,
const EntityType & entity )
const
567 inlineLocal(str, entity );
570 if( ! entity.isLeaf() )
572 const int mxlvl = grid_.maxLevel();
574 typedef typename EntityType::HierarchicIterator HierarchicIteratorType;
575 const HierarchicIteratorType endit = entity.hend( mxlvl );
576 for(HierarchicIteratorType it = entity.hbegin( mxlvl );
579 inlineLocal(str, *it);
585 void xtractData (ObjectStreamType & str,
const EntityType & entity )
const
588 xtractLocal(str, entity );
591 if( ! entity.isLeaf() )
593 const int mxlvl = grid_.maxLevel();
595 typedef typename EntityType::HierarchicIterator HierarchicIteratorType;
596 const HierarchicIteratorType endit = entity.hend( mxlvl );
597 for(HierarchicIteratorType it = entity.hbegin( mxlvl );
600 xtractLocal(str, *it);
608 typedef LocalInterface<ParamType> COType;
610 COType *newLDCOp =
new COType ( ldc_ );
613 OPType *dcOp =
new OPType ( grid_ , dm_ , *newLDCOp, rwType_ );
623 void inlineLocal(ObjectStreamType & str,
const EntityType& entity )
const
627 ParamType p( &str , &entity );
633 void xtractLocal(ObjectStreamType & str,
const EntityType& entity )
const
637 ParamType p( &str , &entity );
649 LocalDataCollectImp &ldc_;
652 const ReadWriteType rwType_;
655 const int numChildren_;
660 template<
class DiscreteFunctionType >
661 struct LocalDataInlinerTraits
664 DiscreteFunctionSpaceType;
666 typedef typename DiscreteFunctionSpaceType::EntityType EntityType;
667 typedef typename GridType :: template
Codim< 0 > :: Entity GridEntityType;
669 typedef DofManager < GridType > DofManagerType ;
670 typedef typename DofManagerType :: InlineStreamType ObjectStreamType;
672 typedef std::pair< ObjectStreamType *, const GridEntityType * > ParamType;
673 typedef LocalInterface< ParamType > LocalInterfaceType;
679 class ContainsCheck >
681 :
public LocalInlinePlus< LocalDataInliner< DiscreteFunctionType, ContainsCheck >,
682 typename LocalDataInlinerTraits< DiscreteFunctionType >::ParamType >
685 typedef LocalDataInlinerTraits< DiscreteFunctionType > Traits;
690 typedef typename Traits::EntityType EntityType;
691 typedef typename Traits::GridEntityType GridEntityType;
692 typedef typename Traits::ParamType ParamType;
694 typedef LocalInterface<ParamType> LocalInterfaceType;
703 const ContainsCheck& containsCheck )
706 containsCheck_( containsCheck ),
714 containsCheck_( other.containsCheck_ ),
721 assert( p.first && p.second );
722 const EntityType& entity = df_.
space().gridPart().convert( *p.second );
726 typename DataCollectorTraits :: ReadWriteType
727 readWriteInfo()
const {
return DataCollectorTraits :: writeData ; }
731 const EntityType& entity,
732 const GridEntityType& gridEntity )
const
734 if( ! containsCheck_.contains ( entity ) ) return ;
736 assert( df_.
space().indexSet().contains( entity ) );
738 ldv_.resize( df_.
space().basisFunctionSet( entity ).size() );
740 for(
const DofType &dof : ldv_ )
746 DofManagerType& dm_ ;
747 const ContainsCheck containsCheck_;
748 mutable LocalDofVectorType ldv_;
752 template<
class DiscreteFunctionType >
753 struct LocalDataXtractorTraits
756 DiscreteFunctionSpaceType;
758 typedef typename DiscreteFunctionSpaceType::EntityType EntityType;
759 typedef typename GridType :: template
Codim< 0 > :: Entity GridEntityType;
761 typedef DofManager < GridType > DofManagerType ;
762 typedef typename DofManagerType :: XtractStreamType ObjectStreamType;
764 typedef std::pair< ObjectStreamType *, const GridEntityType * > ParamType;
765 typedef LocalInterface< ParamType > LocalInterfaceType;
771 class ContainsCheck >
773 :
public LocalInlinePlus< LocalDataXtractor< DiscreteFunctionType, ContainsCheck >,
774 typename LocalDataXtractorTraits< DiscreteFunctionType >::ParamType >
777 typedef LocalDataXtractorTraits< DiscreteFunctionType > Traits;
782 typedef typename Traits::EntityType EntityType;
783 typedef typename Traits::GridEntityType GridEntityType;
784 typedef typename Traits::ParamType ParamType;
786 typedef typename Traits::LocalInterfaceType LocalInterfaceType;
795 const ContainsCheck& containsCheck )
798 containsCheck_( containsCheck ),
806 containsCheck_( other.containsCheck_ ),
813 assert( p.first && p.second );
814 const EntityType& entity = df_.
space().gridPart().convert( *p.second );
818 typename DataCollectorTraits :: ReadWriteType
819 readWriteInfo()
const {
return DataCollectorTraits :: readData ; }
823 const EntityType& entity,
824 const GridEntityType& gridEntity )
const
826 if( ! containsCheck_.contains ( entity ) ) return ;
829 assert( df_.
space().indexSet().contains( entity ) );
831 ldv_.resize( df_.
space().basisFunctionSet( entity ).size() );
832 for( DofType &dof : ldv_ )
840 const ContainsCheck containsCheck_;
841 mutable LocalDofVectorType ldv_;
Definition: datacollector.hh:262
MyType & operator=(const OpType &dc)
Assignement operator.
Definition: datacollector.hh:360
virtual void clear()
clear object list
Definition: datacollector.hh:378
MyType & operator+=(const OpType &dc)
Assignement operator.
Definition: datacollector.hh:324
virtual ~DataCollectorInterface()
Virtual desctructor.
Definition: datacollector.hh:284
virtual void apply(ObjectStreamType &str, const EntityType &entity) const
Definition: datacollector.hh:289
DataCollectorInterface()
empty constructor
Definition: datacollector.hh:281
The DataCollector is an example for a grid walk done while load balancing moves entities from one pro...
Definition: datacollector.hh:435
const LocalDataCollectImp & getLocalOp() const
return reference to loacl Operator
Definition: datacollector.hh:528
void apply(ObjectStreamType &str, const EntityType &entity) const
Definition: datacollector.hh:556
DataCollector(GridType &grid, DofManagerType &dm, LocalDataCollectImp &ldc, const ReadWriteType rwType, int numChildren=8)
create DiscreteOperator with a LocalOperator
Definition: datacollector.hh:455
void inlineData(ObjectStreamType &str, const EntityType &entity) const
write all data of all entities blowe this Entity to the stream
Definition: datacollector.hh:564
void xtractData(ObjectStreamType &str, const EntityType &entity) const
read all data of all entities blowe this Entity from the stream
Definition: datacollector.hh:585
bool writeData() const
return true if data collector is writing data instead of reading
Definition: datacollector.hh:552
virtual ~DataCollector()
Desctructor.
Definition: datacollector.hh:466
DataCollector< GridType, CombinedLocalDataCollect< LocalDataCollectImp, LocalDataCollectType > > & operator+(const DataCollector< GridType, LocalDataCollectType > &op)
operator + (combine this operator) and return new Object
Definition: datacollector.hh:472
DataCollector< GridType, LocalInterface< ParamType > > & operator+=(const DataCollector< GridType, LocalDataCollectType > &op)
oeprator += combine and return this Object
Definition: datacollector.hh:492
LocalDataCollectImp & getLocalOp()
return reference to loacl Operator
Definition: datacollector.hh:534
void getLocalDofs(const EntityType &entity, Vector &localDofs) const
fill local Dofs to dof vector associated with the entity
Definition: discretefunction.hh:946
void setLocalDofs(const EntityType &entity, const LocalDofs &localDofs)
set local Dofs to dof vector associated with the entity
Definition: discretefunction.hh:938
GridPartType::GridType GridType
type of underlying dune grid
Definition: discretefunctionspace.hh:214
Definition: dofmanager.hh:786
empty data collector
Definition: datacollector.hh:392
MyType & operator+=(const OpType &dc)
Assignement operator.
Definition: datacollector.hh:408
MyType & operator=(const OpType &dc)
Assignement operator.
Definition: datacollector.hh:415
void apply(int, int) const
Definition: datacollector.hh:401
Inline DiscreteFunction data during load balancing.
Definition: datacollector.hh:683
LocalDataInliner(const DiscreteFunctionType &df, const ContainsCheck &containsCheck)
constructor
Definition: datacollector.hh:702
LocalDataInliner(const LocalDataInliner &other)
copy constructor
Definition: datacollector.hh:711
void apply(ParamType &p) const
store data to stream
Definition: datacollector.hh:719
void inlineData(ObjectStreamType &str, const EntityType &entity, const GridEntityType &gridEntity) const
store data to stream
Definition: datacollector.hh:730
Inline DiscreteFunction data during load balancing.
Definition: datacollector.hh:775
LocalDataXtractor(const LocalDataXtractor &other)
copy constructor
Definition: datacollector.hh:803
LocalDataXtractor(DiscreteFunctionType &df, const ContainsCheck &containsCheck)
constructor
Definition: datacollector.hh:794
void apply(ParamType &p) const
store data to stream
Definition: datacollector.hh:811
void xtractData(ObjectStreamType &str, const EntityType &entity, const GridEntityType &gridEntity) const
store data to stream
Definition: datacollector.hh:822
Definition: objpointer.hh:42
void saveObjPointer(DiscrOpType *discrOp)
Store new generated DiscreteOperator Pointer.
Definition: objpointer.hh:58
forward declaration
Definition: discretefunction.hh:51
const DiscreteFunctionSpaceType & space() const
obtain a reference to the corresponding DiscreteFunctionSpace
Definition: discretefunction.hh:709
TupleDiscreteFunctionSpace< typename DiscreteFunctions::DiscreteFunctionSpaceType ... > DiscreteFunctionSpaceType
type for the discrete function space this function lives in
Definition: discretefunction.hh:69
Communication message buffer interface. This class describes the interface for reading and writing da...
Definition: datahandleif.hh:33
Various macros to work with Dune module version numbers.
This file implements a dense vector with a dynamic size.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
constexpr std::bool_constant<(sizeof...(II)==0)> empty(std::integer_sequence< T, II... >)
Checks whether the sequence is empty.
Definition: integersequence.hh:80
Static tag representing a codimension.
Definition: dimension.hh:24
Traits class for a DiscreteFunction.
Definition: discretefunction.hh:61
Definition: datacollector.hh:237