Reference documentation for deal.II version 8.5.1
petsc_vector.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2004 - 2016 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #include <deal.II/lac/petsc_vector.h>
17 
18 #ifdef DEAL_II_WITH_PETSC
19 
20 #include <deal.II/lac/exceptions.h>
21 
22 # include <cmath>
23 
24 DEAL_II_NAMESPACE_OPEN
25 
26 namespace PETScWrappers
27 {
28 
29 
31  {
33  }
34 
35 
36 
38  {
40  }
41 
42 
43 
45  :
46  VectorBase ()
47  {
48  // first create a dummy vector, then copy
49  // over the other one
52  }
53 
54 
55 
57  {
58  // first create a dummy vector, then copy
59  // over the other one
62  }
63 
64 
65 
66  void
68  {
71  }
72 
73 
74 
75  void
77  const bool omit_zeroing_entries)
78  {
79  // only do something if the sizes
80  // mismatch
81  if (size() != n)
82  {
83  // FIXME: I'd like to use this here,
84  // but somehow it leads to odd errors
85  // somewhere down the line in some of
86  // the tests:
87 // const PetscErrorCode ierr = VecSetSizes (vector, n, n);
88 // AssertThrow (ierr == 0, ExcPETScError(ierr));
89 
90  // so let's go the slow way:
92  {
93 #if DEAL_II_PETSC_VERSION_LT(3,2,0)
94  PetscErrorCode ierr = VecDestroy (vector);
95 #else
96  PetscErrorCode ierr = VecDestroy (&vector);
97 #endif
98  AssertThrow (ierr == 0, ExcPETScError(ierr));
99  }
100 
101  create_vector (n);
102  }
103 
104  // finally clear the new vector if so
105  // desired
106  if (omit_zeroing_entries == false)
107  *this = 0;
108  }
109 
110 
111 
112  void
114  const bool omit_zeroing_entries)
115  {
116  reinit (v.size(), omit_zeroing_entries);
117  }
118 
119 
120 
121  void
123  {
124  const PetscErrorCode ierr
125  = VecCreateSeq (PETSC_COMM_SELF, n, &vector);
126  AssertThrow (ierr == 0, ExcPETScError(ierr));
127  attained_ownership = true;
128  }
129 }
130 
131 DEAL_II_NAMESPACE_CLOSE
132 
133 #endif // DEAL_II_WITH_PETSC
types::global_dof_index size_type
Definition: petsc_vector.h:60
#define AssertThrow(cond, exc)
Definition: exceptions.h:369
Vector & operator=(const Vector &v)
void create_vector(const size_type n)
void reinit(const size_type N, const bool omit_zeroing_entries=false)
Definition: petsc_vector.cc:76