PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
Vec.hh
Go to the documentation of this file.
1/* Copyright (C) 2015, 2016, 2025 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#include <memory>
25
26#include "pism/util/Wrapper.hh"
27
28namespace pism {
29namespace petsc {
30
31class DM;
32
33/** Wrapper around PETSc's Vec. Simplifies memory management.
34 *
35 * The constructor takes ownership of the Vec argument passed to it.
36 *
37 * The destructor call VecDestroy().
38 */
39class Vec : public Wrapper< ::Vec > {
40public:
41 Vec();
42 Vec(::Vec v);
43 ~Vec();
44};
45
46//! Wrapper around VecGetArray and VecRestoreArray.
47class VecArray {
48public:
49 VecArray(::Vec v);
50 ~VecArray();
51 double* get();
52private:
53 ::Vec m_v;
54 double *m_array;
55};
56
57//! Wrapper around VecGetArray2d and VecRestoreArray2d.
59public:
60 VecArray2D(::Vec vec, int my_Mx, int my_My);
61 VecArray2D(::Vec vec, int my_Mx, int my_My, int i0, int j0);
63
64 inline double& operator()(int i, int j) {
65 return m_array[j + m_j_offset][i + m_i_offset];
66 }
67private:
69 ::Vec m_v;
70 double **m_array;
71};
72
74public:
75 DMDAVecArray(std::shared_ptr<DM> dm, ::Vec v);
77 void* get();
78private:
79 std::shared_ptr<DM> m_dm;
80 ::Vec m_v;
81 void *m_array;
82};
83
85public:
86 DMDAVecArrayDOF(std::shared_ptr<DM> dm, ::Vec v);
88 void* get();
89private:
90 std::shared_ptr<DM> m_dm;
91 ::Vec m_v;
92 void *m_array;
93};
94
95class TemporaryGlobalVec : public Vec {
96public:
97 TemporaryGlobalVec(std::shared_ptr<DM> dm);
99private:
100 std::shared_ptr<DM> m_dm;
101};
102
103} // end of namespace petsc
104} // end of namespace pism
105
106
107#endif /* _VEC_H_ */
std::shared_ptr< DM > m_dm
Definition Vec.hh:90
std::shared_ptr< DM > m_dm
Definition Vec.hh:79
std::shared_ptr< DM > m_dm
Definition Vec.hh:100
double ** m_array
Definition Vec.hh:70
double & operator()(int i, int j)
Definition Vec.hh:64
Wrapper around VecGetArray2d and VecRestoreArray2d.
Definition Vec.hh:58
double * m_array
Definition Vec.hh:54
double * get()
Definition Vec.cc:55
Wrapper around VecGetArray and VecRestoreArray.
Definition Vec.hh:47