URI:
       tVec.hh - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
  HTML git clone git://src.adamsgaard.dk/pism
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
       tVec.hh (2288B)
       ---
            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 "Wrapper.hh"
           26 #include "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 petsc::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:
           50   ::Vec m_v;
           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:
           65   int m_Mx, m_My, m_i_offset, m_j_offset;
           66   ::Vec m_v;
           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:
           76   DM::Ptr m_dm;
           77   ::Vec m_v;
           78   void *m_array;
           79 };
           80 
           81 class DMDAVecArrayDOF {
           82 public:
           83   DMDAVecArrayDOF(DM::Ptr dm, ::Vec v);
           84   ~DMDAVecArrayDOF();
           85   void* get();
           86 private:
           87   DM::Ptr m_dm;
           88   ::Vec m_v;
           89   void *m_array;
           90 };
           91 
           92 class TemporaryGlobalVec : public Vec {
           93 public:
           94   TemporaryGlobalVec(DM::Ptr dm);
           95   ~TemporaryGlobalVec();
           96 private:
           97   DM::Ptr m_dm;
           98 };
           99 
          100 } // end of namespace petsc
          101 } // end of namespace pism
          102 
          103 
          104 #endif /* _VEC_H_ */