Reference documentation for deal.II version 8.4.2
petsc_vector.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2004 - 2015 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 <cmath>
21 
22 DEAL_II_NAMESPACE_OPEN
23 
24 namespace PETScWrappers
25 {
26 
27 
29  {
31  }
32 
33 
34 
36  {
38  }
39 
40 
41 
43  :
44  VectorBase ()
45  {
46  // first create a dummy vector, then copy
47  // over the other one
50  }
51 
52 
53 
55  {
56  // first create a dummy vector, then copy
57  // over the other one
60  }
61 
62 
63 
64  void
66  {
69  }
70 
71 
72 
73  void
75  const bool omit_zeroing_entries)
76  {
77  // only do something if the sizes
78  // mismatch
79  if (size() != n)
80  {
81  // FIXME: I'd like to use this here,
82  // but somehow it leads to odd errors
83  // somewhere down the line in some of
84  // the tests:
85 // const int ierr = VecSetSizes (vector, n, n);
86 // AssertThrow (ierr == 0, ExcPETScError(ierr));
87 
88  // so let's go the slow way:
90  {
91 #if DEAL_II_PETSC_VERSION_LT(3,2,0)
92  int ierr = VecDestroy (vector);
93 #else
94  int ierr = VecDestroy (&vector);
95 #endif
96  AssertThrow (ierr == 0, ExcPETScError(ierr));
97  }
98 
99  create_vector (n);
100  }
101 
102  // finally clear the new vector if so
103  // desired
104  if (omit_zeroing_entries == false)
105  *this = 0;
106  }
107 
108 
109 
110  void
112  const bool omit_zeroing_entries)
113  {
114  reinit (v.size(), omit_zeroing_entries);
115  }
116 
117 
118 
119  void
121  {
122  const int ierr
123  = VecCreateSeq (PETSC_COMM_SELF, n, &vector);
124  AssertThrow (ierr == 0, ExcPETScError(ierr));
125  attained_ownership = true;
126  }
127 }
128 
129 DEAL_II_NAMESPACE_CLOSE
130 
131 #endif // DEAL_II_WITH_PETSC
types::global_dof_index size_type
Definition: petsc_vector.h:59
#define AssertThrow(cond, exc)
Definition: exceptions.h:358
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:74