2 #ifndef DUNE_FEM_PETSCDISCRETEFUNCTION_HH 3 #define DUNE_FEM_PETSCDISCRETEFUNCTION_HH 21 #include <dune/common/fvector.hh> 22 #include <dune/common/dynvector.hh> 29 #include <dune/common/shared_ptr.hh> 41 template<
class DiscreteFunctionSpace >
class PetscDiscreteFunction;
46 template<
class DofProxy,
class Allocator >
47 struct AssignVectorReference<
Dune::DynamicVector< DofProxy, Allocator > >
50 typedef Dune::DynamicVector< DofProxy, Allocator > Vector;
56 void operator() (
const std::size_t index, DofProxy value )
58 vector_[ index ].assign( value );
68 template <
class DiscreteFunctionSpace>
69 class PetscDiscreteFunction;
77 template<
typename DiscreteFunctionSpace >
79 :
public DefaultDiscreteFunctionTraits< DiscreteFunctionSpace, PetscVector< DiscreteFunctionSpace > >
81 typedef PetscVector< DiscreteFunctionSpace > DofVectorType;
82 typedef PetscDiscreteFunction< DiscreteFunctionSpace > DiscreteFunctionType;
84 typedef typename DofVectorType::DofBlockType DofBlockType;
85 typedef typename DofBlockType::DofProxy DofProxyType;
88 typedef StackAllocator< DofProxyType, LocalDofVectorStackType* > LocalDofVectorAllocatorType;
89 typedef Dune::DynamicVector< DofProxyType, LocalDofVectorAllocatorType > LocalDofVectorType;
91 typedef MutableLocalFunction< DiscreteFunctionType > LocalFunctionType;
107 template <
class DiscreteFunctionSpace>
108 class PetscDiscreteFunction
109 :
public DiscreteFunctionDefault< PetscDiscreteFunction< DiscreteFunctionSpace > >
111 typedef PetscDiscreteFunction< DiscreteFunctionSpace > ThisType;
112 typedef DiscreteFunctionDefault< ThisType > BaseType;
115 typedef typename BaseType :: DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
116 typedef typename BaseType :: DofVectorType DofVectorType;
118 using BaseType::assign;
120 PetscDiscreteFunction(
const std::string &name,
121 const DiscreteFunctionSpaceType &space )
122 : BaseType( name, space ),
124 dofVector_( allocateDofStorage( space ) )
128 PetscDiscreteFunction(
const std::string &name,
129 const DiscreteFunctionSpaceType &space,
130 DofVectorType& dofVector )
131 : BaseType( name, space ),
133 dofVector_( dofVector )
137 PetscDiscreteFunction(
const PetscDiscreteFunction& other )
138 : BaseType(
"copy of " + other.name(), other.space() ),
140 dofVector_( allocateDofStorage( other.space() ) )
147 void enableDofCompression ()
150 memObject_->enableDofCompression();
156 dofVector().communicateNow();
160 DofVectorType& dofVector() {
return dofVector_; }
162 const DofVectorType& dofVector()
const {
return dofVector_; }
165 const Vec* petscVec ()
const {
return dofVector().getVector(); }
168 Vec* petscVec () {
return dofVector().getVector(); }
171 typedef typename DiscreteFunctionSpaceType :: BlockMapperType BlockMapperType;
172 typedef PetscManagedDofStorage< DiscreteFunctionSpaceType, BlockMapperType > PetscManagedDofStorageType;
175 DofVectorType& allocateDofStorage (
const DiscreteFunctionSpaceType &space )
177 std::string name(
"deprecated");
179 memObject_.reset(
new PetscManagedDofStorageType( space, space.blockMapper(), name ) );
181 return memObject_->getArray();
185 std::unique_ptr< PetscManagedDofStorageType > memObject_;
188 DofVectorType& dofVector_;
195 #endif // #if HAVE_PETSC 197 #endif // #ifndef DUNE_FEM_PETSCDISCRETEFUNCTION_HH
Vector & vector_
Definition: function/common/functor.hh:94
Definition: coordinate.hh:4
AssignVectorReference(Vector &vector)
Definition: function/common/functor.hh:83
void operator()(const std::size_t index, Value &&value) const
Definition: function/common/functor.hh:88