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;
100 const DiscreteFunctionSpaceType& space )
103 dofVector_( allocateDofStorage(
space ) )
113 const DiscreteFunctionSpaceType& space,
114 DofVectorType& dofVector )
117 dofVector_( dofVector )
121 PetscDiscreteFunction(
const ThisType& other )
122 : BaseType(
"copy of " + other.
name(), other.
space() ),
124 dofVector_( allocateDofStorage( other.
space() ) )
130 PetscDiscreteFunction( ThisType&& other )
131 : BaseType( static_cast< BaseType && >( other ) ),
132 memObject_(
std::
move( other.memObject_ ) ),
133 dofVector_( other.dofVector_ )
136 PetscDiscreteFunction () =
delete;
137 ThisType&
operator= (
const ThisType& ) =
delete;
138 ThisType&
operator= ( ThisType&& ) =
delete;
141 void enableDofCompression ()
144 memObject_->enableDofCompression();
149 void assign(
const AdaptiveDiscreteFunction< DiscreteFunctionSpaceType > &g )
152 dofVector().assignVector( g.dofVector() );
157 template <
class Block >
158 void assign(
const ISTLBlockVectorDiscreteFunction< DiscreteFunctionSpaceType, Block > &g )
161 dofVector().assignVector( g.dofVector() );
166 template <
class Vector >
167 void assign(
const VectorDiscreteFunction< DiscreteFunctionSpaceType, Vector > &g )
170 dofVector().assignVector( g.dofVector() );
174 template<
class AssembleOperation >
175 void beginAssemble ()
177 BaseType :: template beginAssemble< AssembleOperation > ();
178 dofVector().beginAssemble();
182 template<
class AssembleOperation >
183 void endAssemble (
const bool communicate =
true )
185 BaseType :: template endAssemble< AssembleOperation > ();
186 dofVector().endAssemble( communicate );
190 DofVectorType& dofVector() {
return dofVector_; }
192 const DofVectorType& dofVector()
const {
return dofVector_; }
195 const Vec* petscVec ()
const {
return dofVector().getVector(); }
198 Vec* petscVec () {
return dofVector().getVector(); }
201 typedef typename DiscreteFunctionSpaceType :: BlockMapperType BlockMapperType;
202 typedef PetscManagedDofStorage< DiscreteFunctionSpaceType, BlockMapperType > PetscManagedDofStorageType;
205 DofVectorType& allocateDofStorage (
const DiscreteFunctionSpaceType &space )
207 memObject_.reset(
new PetscManagedDofStorageType( space,
space.blockMapper() ) );
209 return memObject_->getArray();
216 DofVectorType& dofVector_;
220 template <
class DiscreteFunctionSpace>
222 :
public RestrictProlongInterfaceDefault< RestrictProlongTraits< RestrictProlongDefault< PetscDiscreteFunction< DiscreteFunctionSpace > >,
223 typename DiscreteFunctionSpace::DomainFieldType > >
225 typedef PetscDiscreteFunction< DiscreteFunctionSpace > DiscreteFunction;
226 typedef RestrictProlongDefault< DiscreteFunction > ThisType;
227 typedef RestrictProlongInterfaceDefault< RestrictProlongTraits< ThisType, typename DiscreteFunction::DomainFieldType > > BaseType;
229 typedef AdaptiveDiscreteFunction< DiscreteFunctionSpace > AdaptiveDiscreteFunctionType;
230 typedef RestrictProlongDefault < AdaptiveDiscreteFunctionType > AdaptiveRestrictProlongType;
238 typedef typename DiscreteFunctionType::LocalFunctionType LocalFunctionType;
239 typedef typename DiscreteFunctionType::GridPartType
GridPartType;
246 rpOp_( adaptiveFunction_ ),
247 initialized_( false )
254 rpOp_( adaptiveFunction_ ),
255 initialized_( false )
261 rpOp_.setFatherChildWeight( weight );
265 template<
class Entity >
268 assert( initialized_ );
269 rpOp_.restrictLocal( father, son,
initialize );
273 template<
class Entity >
276 assert( initialized_ );
277 rpOp_.prolongLocal( father, son,
initialize );
281 template<
class Communicator,
class Operation >
282 void addToList ( Communicator &comm,
const Operation& op)
284 rpOp_.addToList( comm, op );
288 template<
class Communicator >
291 rpOp_.addToList( comm );
295 template<
class Communicator >
298 rpOp_.removeFromList( comm );
302 template<
class LoadBalancer >
305 rpOp_.addToLoadBalancer( lb );
312 initialized_ = true ;
318 assert( initialized_ );
321 initialized_ = false ;
330 AdaptiveDiscreteFunctionType adaptiveFunction_;
331 AdaptiveRestrictProlongType rpOp_;
SLList< T, A > & operator=(const SLList< T, A > &other)
std::ptrdiff_t index() const
virtual void operator()()=0
void assign(T &dst, const T &src, bool mask)
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