PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
Vec.hh
Go to the documentation of this file.
1 /* Copyright (C) 2015, 2016 PISM Authors
2  *
3  * This file is part of PISM.
4  *
5  * PISM is free software; you can redistribute it and/or modify it under the
6  * terms of the GNU General Public License as published by the Free Software
7  * Foundation; either version 3 of the License, or (at your option) any later
8  * version.
9  *
10  * PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with PISM; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #ifndef _VEC_H_
21 #define _VEC_H_
22 
23 #include <petscvec.h>
24 
25 #include "pism/util/Wrapper.hh"
26 #include "pism/util/petscwrappers/DM.hh"
27 
28 namespace pism {
29 namespace petsc {
30 /** Wrapper around PETSc's Vec. Simplifies memory management.
31  *
32  * The constructor takes ownership of the Vec argument passed to it.
33  *
34  * The destructor call VecDestroy().
35  */
36 class Vec : public Wrapper< ::Vec > {
37 public:
38  Vec();
39  Vec(::Vec v);
40  ~Vec();
41 };
42 
43 //! Wrapper around VecGetArray and VecRestoreArray.
44 class VecArray {
45 public:
46  VecArray(::Vec v);
47  ~VecArray();
48  double* get();
49 private:
51  double *m_array;
52 };
53 
54 //! Wrapper around VecGetArray2d and VecRestoreArray2d.
55 class VecArray2D {
56 public:
57  VecArray2D(::Vec vec, int my_Mx, int my_My);
58  VecArray2D(::Vec vec, int my_Mx, int my_My, int i0, int j0);
59  ~VecArray2D();
60 
61  inline double& operator()(int i, int j) {
62  return m_array[j + m_j_offset][i + m_i_offset];
63  }
64 private:
67  double **m_array;
68 };
69 
70 class DMDAVecArray {
71 public:
72  DMDAVecArray(DM::Ptr dm, ::Vec v);
73  ~DMDAVecArray();
74  void* get();
75 private:
78  void *m_array;
79 };
80 
82 public:
83  DMDAVecArrayDOF(DM::Ptr dm, ::Vec v);
85  void* get();
86 private:
89  void *m_array;
90 };
91 
92 class TemporaryGlobalVec : public Vec {
93 public:
96 private:
98 };
99 
100 } // end of namespace petsc
101 } // end of namespace pism
102 
103 
104 #endif /* _VEC_H_ */
std::shared_ptr< Wrapper > Ptr
Definition: Wrapper.hh:30
DMDAVecArrayDOF(DM::Ptr dm, ::Vec v)
Definition: Vec.cc:94
DMDAVecArray(DM::Ptr dm, ::Vec v)
Definition: Vec.cc:78
TemporaryGlobalVec(DM::Ptr dm)
Definition: Vec.cc:110
double ** m_array
Definition: Vec.hh:67
VecArray2D(::Vec vec, int my_Mx, int my_My)
Definition: Vec.cc:60
double & operator()(int i, int j)
Definition: Vec.hh:61
Wrapper around VecGetArray2d and VecRestoreArray2d.
Definition: Vec.hh:55
VecArray(::Vec v)
Definition: Vec.cc:44
double * m_array
Definition: Vec.hh:51
double * get()
Definition: Vec.cc:54
Wrapper around VecGetArray and VecRestoreArray.
Definition: Vec.hh:44