Loading [MathJax]/extensions/tex2jax.js
PISM, A Parallel Ice Sheet Model 2.2.2-d6b3a29ca committed by Constantine Khrulev on 2025-03-28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
28namespace pism {
29namespace 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 */
36class Vec : public Wrapper< ::Vec > {
37public:
38 Vec();
39 Vec(::Vec v);
40 ~Vec();
41};
42
43//! Wrapper around VecGetArray and VecRestoreArray.
44class VecArray {
45public:
46 VecArray(::Vec v);
47 ~VecArray();
48 double* get();
49private:
50 ::Vec m_v;
51 double *m_array;
52};
53
54//! Wrapper around VecGetArray2d and VecRestoreArray2d.
56public:
57 VecArray2D(::Vec vec, int my_Mx, int my_My);
58 VecArray2D(::Vec vec, int my_Mx, int my_My, int i0, int j0);
60
61 inline double& operator()(int i, int j) {
62 return m_array[j + m_j_offset][i + m_i_offset];
63 }
64private:
66 ::Vec m_v;
67 double **m_array;
68};
69
71public:
72 DMDAVecArray(DM::Ptr dm, ::Vec v);
74 void* get();
75private:
77 ::Vec m_v;
78 void *m_array;
79};
80
82public:
83 DMDAVecArrayDOF(DM::Ptr dm, ::Vec v);
85 void* get();
86private:
88 ::Vec m_v;
89 void *m_array;
90};
91
92class TemporaryGlobalVec : public Vec {
93public:
96private:
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
double ** m_array
Definition Vec.hh:67
double & operator()(int i, int j)
Definition Vec.hh:61
Wrapper around VecGetArray2d and VecRestoreArray2d.
Definition Vec.hh:55
double * m_array
Definition Vec.hh:51
double * get()
Definition Vec.cc:54
Wrapper around VecGetArray and VecRestoreArray.
Definition Vec.hh:44