3 #ifndef DUNE_PETSCVECTORBACKEND_HH
4 #define DUNE_PETSCVECTORBACKEND_HH
10 #include<dune/common/fvector.hh>
20 class PetscVectorBackend;
22 class PetscVectorContainer
25 typedef PetscScalar ElementType;
26 typedef ElementType E;
27 typedef Vec ContainerType;
30 typedef block_type field_type;
32 typedef std::size_t size_type;
33 typedef PetscVectorBackend Backend;
36 PetscVectorContainer (
const T& t_)
40 PETSC_CALL(VecCreate(PETSC_COMM_SELF,&_v));
41 PETSC_CALL(VecSetSizes(_v,t_.globalSize(),PETSC_DECIDE));
42 PETSC_CALL(VecSetType(_v,VECSEQ));
46 PetscVectorContainer (
const T& t_,
const E&
e)
50 PETSC_CALL(VecCreate(PETSC_COMM_SELF,&_v));
51 PETSC_CALL(VecSetSizes(_v,t_.globalSize(),PETSC_DECIDE));
52 PETSC_CALL(VecSetType(_v,VECSEQ));
56 PetscVectorContainer (
const PetscVectorContainer& rhs)
61 PETSC_CALL(VecDuplicate(rhs._v,&_v));
62 PETSC_CALL(VecCopy(rhs._v,_v));
65 PetscVectorContainer(Vec vec,
bool managed =
true)
72 PetscVectorContainer& operator= (
const PetscVectorContainer& rhs)
76 PETSC_CALL(VecCopy(rhs._v,_v));
80 ~PetscVectorContainer()
85 #if DUNE_PETSC_NEWER(3,2,0)
86 PETSC_CALL(VecDestroy(&_v));
88 PETSC_CALL(VecDestroy(_v));
96 PETSC_CALL(VecGetLocalSize(_v,&size));
101 PetscVectorContainer& operator= (
const E& e)
104 PETSC_CALL(VecSet(_v,e));
108 PetscVectorContainer& operator*= (
const E& e)
111 PETSC_CALL(VecScale(_v,e));
116 PetscVectorContainer& operator+= (
const E& e)
119 PETSC_CALL(VecShift(_v,e));
123 PetscVectorContainer& operator+= (
const PetscVectorContainer& rhs)
125 return axpy(1.0,rhs);
128 PetscVectorContainer& operator-= (
const PetscVectorContainer& rhs)
130 return axpy(-1.0,rhs);
133 field_type& operator[](std::size_t i)
139 const field_type& operator[](std::size_t i)
const
149 PETSC_CALL(VecNorm(_v,NORM_2,&norm));
157 PETSC_CALL(VecNorm(_v,NORM_1,&norm));
161 E infinity_norm()
const
165 PETSC_CALL(VecNorm(_v,NORM_INFINITY,&norm));
169 E dot(
const PetscVectorContainer& y)
const
172 PetscScalar dotproduct = 0;
173 PETSC_CALL(VecDot(_v,y._v,&dotproduct));
177 E operator*(
const PetscVectorContainer& y)
const
180 PetscScalar dotproduct = 0;
181 PETSC_CALL(VecTDot(_v,y._v,&dotproduct));
186 PetscVectorContainer& axpy(
const E& a,
const PetscVectorContainer& y)
190 PETSC_CALL(VecAXPY(_v,a,y._v));
195 ContainerType& base ()
201 const ContainerType& base ()
const
207 operator ContainerType&()
213 operator const ContainerType&()
const
243 size_t flatsize()
const
249 void std_copy_to (std::vector<X>& x)
const
251 size_t n = flatsize();
254 for (
size_t i=0; i<n; i++)
259 void std_copy_from (
const std::vector<X>& x)
262 assert (x.size() == flatsize());
264 for (
size_t i=0; i<flatsize(); i++)
277 PETSC_CALL(VecRestoreArray(_v,&_data));
282 void checkout()
const
286 PETSC_CALL(VecGetArray(_v,&_data));
295 class PetscVectorBackend
302 typedef typename C::ElementType Type;
306 typedef typename std::size_t size_type;
311 static const typename C::field_type& access (
const C& c, size_type i)
319 static typename C::field_type& access (C& c, size_type i)
325 template<
typename T,
typename E>
326 struct BackendVectorSelectorHelper<PetscVectorBackend,T,E>
328 typedef PetscVectorContainer Type;
338 #endif // DUNE_PETSCVECTORBACKEND_HH
const E & e
Definition: interpolate.hh:172