1#ifndef DUNE_FEM_PETSCDISCRETEFUNCTION_HH
2#define DUNE_FEM_PETSCDISCRETEFUNCTION_HH
28 template<
class DiscreteFunctionSpace >
29 class PetscDiscreteFunction;
31 template<
class DofProxy,
class Allocator >
32 struct AssignVectorReference<
Dune::DynamicVector< DofProxy, Allocator > >
58 template<
typename DiscreteFunctionSpace >
60 :
public DefaultDiscreteFunctionTraits< DiscreteFunctionSpace, PetscVector< DiscreteFunctionSpace > >
62 typedef PetscVector< DiscreteFunctionSpace > DofVectorType;
63 typedef PetscDiscreteFunction< DiscreteFunctionSpace > DiscreteFunctionType;
65 typedef typename DofVectorType::DofBlockType DofBlockType;
66 typedef typename DofBlockType::DofProxy DofProxyType;
69 typedef StackAllocator< DofProxyType, LocalDofVectorStackType* > LocalDofVectorAllocatorType;
80 template <
class DiscreteFunctionSpace>
81 class PetscDiscreteFunction
82 :
public DiscreteFunctionDefault< PetscDiscreteFunction< DiscreteFunctionSpace > >
84 typedef PetscDiscreteFunction< DiscreteFunctionSpace > ThisType;
85 typedef DiscreteFunctionDefault< ThisType > BaseType;
88 typedef typename BaseType :: DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
89 typedef typename BaseType :: DofVectorType DofVectorType;
92 using BaseType::assign;
101 const DiscreteFunctionSpaceType& space,
102 const int backend = ::Dune::Petsc::Backend::defaultBackend )
105 dofVector_( allocateDofStorage(
space, backend ) )
115 const DiscreteFunctionSpaceType& space,
116 DofVectorType& dofVector )
119 dofVector_( dofVector )
123 PetscDiscreteFunction(
const ThisType& other )
124 : BaseType(
"copy of " + other.
name(), other.
space() ),
126 dofVector_( allocateDofStorage( other.
space(), other.dofVector().backend() ) )
132 PetscDiscreteFunction( ThisType&& other )
133 : BaseType( static_cast< BaseType && >( other ) ),
134 memObject_(
std::
move( other.memObject_ ) ),
135 dofVector_( other.dofVector_ )
138 PetscDiscreteFunction () =
delete;
139 ThisType&
operator= (
const ThisType& ) =
delete;
140 ThisType&
operator= ( ThisType&& ) =
delete;
143 void enableDofCompression ()
146 memObject_->enableDofCompression();
151 void assign(
const AdaptiveDiscreteFunction< DiscreteFunctionSpaceType > &g )
154 dofVector().assignVector( g.dofVector() );
159 template <
class Block >
160 void assign(
const ISTLBlockVectorDiscreteFunction< DiscreteFunctionSpaceType, Block > &g )
163 dofVector().assignVector( g.dofVector() );
168 template <
class Vector >
169 void assign(
const VectorDiscreteFunction< DiscreteFunctionSpaceType, Vector > &g )
172 dofVector().assignVector( g.dofVector() );
176 template<
class AssembleOperation >
177 void beginAssemble ()
179 BaseType :: template beginAssemble< AssembleOperation > ();
180 dofVector().beginAssemble();
184 template<
class AssembleOperation >
185 void endAssemble (
const bool communicate =
true )
187 BaseType :: template endAssemble< AssembleOperation > ();
188 dofVector().endAssemble( communicate );
192 DofVectorType& dofVector() {
return dofVector_; }
194 const DofVectorType& dofVector()
const {
return dofVector_; }
197 const Vec* petscVec ()
const {
return dofVector().getVector(); }
200 Vec* petscVec () {
return dofVector().getVector(); }
203 typedef typename DiscreteFunctionSpaceType :: BlockMapperType BlockMapperType;
204 typedef PetscManagedDofStorage< DiscreteFunctionSpaceType, BlockMapperType > PetscManagedDofStorageType;
207 DofVectorType& allocateDofStorage (
const DiscreteFunctionSpaceType &space,
const int backend )
209 memObject_.reset(
new PetscManagedDofStorageType( space,
space.blockMapper(), backend ) );
211 return memObject_->getArray();
218 DofVectorType& dofVector_;
222 template <
class DiscreteFunctionSpace>
224 :
public RestrictProlongInterfaceDefault< RestrictProlongTraits< RestrictProlongDefault< PetscDiscreteFunction< DiscreteFunctionSpace > >,
225 typename DiscreteFunctionSpace::DomainFieldType > >
227 typedef PetscDiscreteFunction< DiscreteFunctionSpace > DiscreteFunction;
228 typedef RestrictProlongDefault< DiscreteFunction > ThisType;
229 typedef RestrictProlongInterfaceDefault< RestrictProlongTraits< ThisType, typename DiscreteFunction::DomainFieldType > > BaseType;
231 typedef AdaptiveDiscreteFunction< DiscreteFunctionSpace > AdaptiveDiscreteFunctionType;
232 typedef RestrictProlongDefault < AdaptiveDiscreteFunctionType > AdaptiveRestrictProlongType;
240 typedef typename DiscreteFunctionType::LocalFunctionType LocalFunctionType;
241 typedef typename DiscreteFunctionType::GridPartType
GridPartType;
248 rpOp_( adaptiveFunction_ ),
249 initialized_( false )
256 rpOp_( adaptiveFunction_ ),
257 initialized_( false )
263 rpOp_.setFatherChildWeight( weight );
267 template<
class Entity >
270 assert( initialized_ );
271 rpOp_.restrictLocal( father, son,
initialize );
275 template<
class Entity >
278 assert( initialized_ );
279 rpOp_.prolongLocal( father, son,
initialize );
283 template<
class Communicator,
class Operation >
284 void addToList ( Communicator &comm,
const Operation& op)
286 rpOp_.addToList( comm, op );
290 template<
class Communicator >
293 rpOp_.addToList( comm );
297 template<
class Communicator >
300 rpOp_.removeFromList( comm );
304 template<
class LoadBalancer >
307 rpOp_.addToLoadBalancer( lb );
314 initialized_ = true ;
320 assert( initialized_ );
323 initialized_ = false ;
332 AdaptiveDiscreteFunctionType adaptiveFunction_;
333 AdaptiveRestrictProlongType rpOp_;
SLList< T, A > & operator=(const SLList< T, A > &other)
std::ptrdiff_t index() const
virtual void operator()()=0
GridImp::template Codim< cd >::Entity Entity
AssignVectorReference(Vector &vector)
Definition function/common/functor.hh:86
Vector & vector_
Definition function/common/functor.hh:97
DomainFieldType calcWeight(const Entity &father, const Entity &son) const
calculates the weight, i.e. (volume son)/(volume father)
Definition restrictprolonginterface.hh:139
bool entitiesAreCopies(const IndexSet &indexSet, const Entity &father, const Entity &son) const
return true if father and son have the same index
Definition restrictprolonginterface.hh:176
BaseType::DomainFieldType DomainFieldType
Definition restrictprolonginterface.hh:171
void finalize()
Definition restrictprolonginterface.hh:191
void initialize()
Definition restrictprolonginterface.hh:190
void setFatherChildWeight(const DomainFieldType &weight) const
explicit set volume ratio of son and father
Definition restrictprolonginterface.hh:256
DefaultLocalRestrictProlong< DiscreteFunctionSpaceType > LocalRestrictProlongType
Definition restrictprolonginterface.hh:223
void addToList(Communicator &comm, const Operation &op)
add discrete function to communicator with given unpack operation
Definition restrictprolonginterface.hh:347
DiscreteFunctionType & discreteFunction_
Definition restrictprolonginterface.hh:377
void removeFromList(Communicator &comm)
remove discrete function from communicator
Definition restrictprolonginterface.hh:363
DiscreteFunction DiscreteFunctionType
Definition restrictprolonginterface.hh:212
RestrictProlongDefault(const RestrictProlongDefault &other)
Definition restrictprolonginterface.hh:225
BaseType::DomainFieldType DomainFieldType
Definition restrictprolonginterface.hh:214
void prolongLocal(const Entity &father, const Entity &son, bool initialize) const
prolong data to children
Definition restrictprolonginterface.hh:311
DiscreteFunctionType::GridPartType GridPartType
Definition restrictprolonginterface.hh:221
void addToLoadBalancer(LoadBalancer &lb)
add discrete function to load balancer
Definition restrictprolonginterface.hh:371
void restrictLocal(const Entity &father, const Entity &son, bool initialize) const
restrict data to father
Definition restrictprolonginterface.hh:263
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition restrictprolonginterface.hh:216