1#ifndef DUNE_FEM_PETSCDISCRETEFUNCTION_HH
2#define DUNE_FEM_PETSCDISCRETEFUNCTION_HH
14#include <dune/common/dynvector.hh>
28 template<
class DiscreteFunctionSpace >
29 class PetscDiscreteFunction;
31 template<
class DofProxy,
class Allocator >
32 struct AssignVectorReference<
Dune::DynamicVector< DofProxy, Allocator > >
35 typedef Dune::DynamicVector< DofProxy, Allocator > Vector;
41 void operator() (
const std::size_t index, DofProxy value )
const
43 vector_[ index ].assign( value );
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;
70 typedef Dune::DynamicVector< DofProxyType, LocalDofVectorAllocatorType > LocalDofVectorType;
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;
99 PetscDiscreteFunction(
const std::string& name,
100 const DiscreteFunctionSpaceType& space )
101 : BaseType( name, space ),
103 dofVector_( allocateDofStorage( space ) )
112 PetscDiscreteFunction(
const std::string& name,
113 const DiscreteFunctionSpaceType& space,
114 DofVectorType& dofVector )
115 : BaseType( name, space ),
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 >
185 BaseType :: template endAssemble< AssembleOperation > ();
186 dofVector().endAssemble();
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();
213 std::unique_ptr< PetscManagedDofStorageType > memObject_;
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 )
253 adaptiveFunction_( other.adaptiveFunction_.name()+
"-copy",
discreteFunction_.space() ),
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_;
Definition: bindguard.hh:11
AssignVectorReference(Vector &vector)
Definition: function/common/functor.hh:86
Vector & vector_
Definition: function/common/functor.hh:97
void operator()(const std::size_t index, Value &&value) const
Definition: function/common/functor.hh:91
DomainFieldType calcWeight(const Entity &father, const Entity &son) const
calculates the weight, i.e. (volume son)/(volume father)
Definition: restrictprolonginterface.hh:138
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:175
BaseType::DomainFieldType DomainFieldType
Definition: restrictprolonginterface.hh:170
void finalize()
Definition: restrictprolonginterface.hh:187
void initialize()
Definition: restrictprolonginterface.hh:186
void setFatherChildWeight(const DomainFieldType &weight) const
explicit set volume ratio of son and father
Definition: restrictprolonginterface.hh:252
DefaultLocalRestrictProlong< DiscreteFunctionSpaceType > LocalRestrictProlongType
Definition: restrictprolonginterface.hh:219
void addToList(Communicator &comm, const Operation &op)
add discrete function to communicator with given unpack operation
Definition: restrictprolonginterface.hh:343
DiscreteFunctionType & discreteFunction_
Definition: restrictprolonginterface.hh:373
void removeFromList(Communicator &comm)
remove discrete function from communicator
Definition: restrictprolonginterface.hh:359
DiscreteFunction DiscreteFunctionType
Definition: restrictprolonginterface.hh:208
RestrictProlongDefault(const RestrictProlongDefault &other)
Definition: restrictprolonginterface.hh:221
BaseType::DomainFieldType DomainFieldType
Definition: restrictprolonginterface.hh:210
void prolongLocal(const Entity &father, const Entity &son, bool initialize) const
prolong data to children
Definition: restrictprolonginterface.hh:307
DiscreteFunctionType::GridPartType GridPartType
Definition: restrictprolonginterface.hh:217
void addToLoadBalancer(LoadBalancer &lb)
add discrete function to load balancer
Definition: restrictprolonginterface.hh:367
void restrictLocal(const Entity &father, const Entity &son, bool initialize) const
restrict data to father
Definition: restrictprolonginterface.hh:259
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: restrictprolonginterface.hh:212