00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SELDON_FILE_VECTOR_PETSCVECTOR_HXX
00022
00023 #include "../share/Common.hxx"
00024 #include "../share/Properties.hxx"
00025 #include "../share/Storage.hxx"
00026 #include "../share/Errors.hxx"
00027 #include "../share/Allocator.hxx"
00028
00029 #include "petscvec.h"
00030
00031
00032 namespace Seldon
00033 {
00034
00035
00037
00040 template <class T, class Allocator>
00041 class PETScVector: public Vector_Base<T, Allocator>
00042 {
00043 public:
00044 typedef typename Allocator::value_type value_type;
00045 typedef typename Allocator::pointer pointer;
00046 typedef typename Allocator::const_pointer const_pointer;
00047 typedef typename Allocator::reference reference;
00048 typedef typename Allocator::const_reference const_reference;
00049
00051 Vec petsc_vector_;
00053 MPI_Comm mpi_communicator_;
00055 bool petsc_vector_deallocated_;
00056
00057
00058 public:
00059
00060 explicit PETScVector();
00061 explicit PETScVector(int i, MPI_Comm mpi_communicator = MPI_COMM_WORLD);
00062 PETScVector(Vec& petsc_vector);
00063 PETScVector(const PETScVector<T, Allocator>& A);
00064
00065
00066 ~PETScVector();
00067
00068 Vec& GetPetscVector();
00069 const Vec& GetPetscVector() const;
00070 void SetCommunicator(MPI_Comm mpi_communicator);
00071
00072 void Clear();
00073
00074 void Resize(int i);
00075 void SetData(int i, pointer data);
00076 void Nullify();
00077
00078
00079 value_type operator() (int i) const;
00080 void SetBuffer(int i, T value, InsertMode insert_mode = INSERT_VALUES);
00081 void Flush();
00082 void GetProcessorRange(int& i, int& j) const;
00083 void Copy(const PETScVector<T, Allocator>& X);
00084 void Copy(const Vec& petsc_vector);
00085 void Append(const T& x);
00086
00087
00088 int GetDataSize() const;
00089 int GetLocalM() const;
00090
00091
00092 void Zero();
00093 void Fill();
00094 template <class T0>
00095 void Fill(const T0& x);
00096 void FillRand();
00097
00098
00099 value_type GetNormInf() const;
00100 int GetNormInfIndex() const;
00101 };
00102
00103
00104 template <class T, class Allocator>
00105 class Vector<T, PETScSeq, Allocator>: public PETScVector<T, Allocator>
00106 {
00107 public:
00108 typedef typename Allocator::value_type value_type;
00109 typedef typename Allocator::pointer pointer;
00110 typedef typename Allocator::const_pointer const_pointer;
00111 typedef typename Allocator::reference reference;
00112 typedef typename Allocator::const_reference const_reference;
00113
00114 typedef PETScSeq storage;
00115
00116
00117 public:
00118
00119 explicit Vector();
00120 explicit Vector(int i, MPI_Comm mpi_communicator = MPI_COMM_WORLD);
00121 Vector(Vec& petsc_vector);
00122 Vector(const Vector<T, PETScSeq, Allocator>& A);
00123
00124 ~Vector();
00125
00126 void Copy(const Vector<T, PETScSeq, Allocator>& X);
00127 void Copy(const Vec& petsc_vector);
00128
00129 void Reallocate(int i);
00130
00131 #ifndef SWIG
00132 Vector<T, PETScSeq, Allocator>& operator= (const Vector<T,
00133 PETScSeq, Allocator>& X);
00134 template <class T0>
00135 Vector<T, PETScSeq, Allocator>& operator= (const T0& X);
00136 #endif
00137 template <class T0>
00138 Vector<T, PETScSeq, Allocator>& operator*= (const T0& X);
00139
00140 void Print() const;
00141
00142
00143 void Write(string FileName, bool with_size = true) const;
00144 void Write(ostream& FileStream, bool with_size = true) const;
00145 void WriteText(string FileName) const;
00146 void WriteText(ostream& FileStream) const;
00147 void Read(string FileName, bool with_size = true);
00148 void Read(istream& FileStream, bool with_size = true);
00149 void ReadText(string FileName);
00150 void ReadText(istream& FileStream);
00151 };
00152
00153
00154 #ifndef SWIG
00155 template <class T, class Allocator>
00156 ostream& operator << (ostream& out,
00157 const Vector<T, PETScSeq, Allocator>& V);
00158 #endif
00159
00160
00161 template <class T, class Allocator>
00162 class Vector<T, PETScPar, Allocator>: public PETScVector<T, Allocator>
00163 {
00164 public:
00165 typedef typename Allocator::value_type value_type;
00166 typedef typename Allocator::pointer pointer;
00167 typedef typename Allocator::const_pointer const_pointer;
00168 typedef typename Allocator::reference reference;
00169 typedef typename Allocator::const_reference const_reference;
00170
00171 typedef PETScPar storage;
00172
00173
00174 public:
00175
00176 explicit Vector();
00177 explicit Vector(int i, MPI_Comm mpi_communicator = MPI_COMM_WORLD);
00178 explicit Vector(int i, int Nlocal, MPI_Comm mpi_communicator);
00179 Vector(Vec& petsc_vector);
00180 Vector(const Vector<T, PETScPar, Allocator>& A);
00181
00182 ~Vector();
00183
00184 void Copy(const Vector<T, PETScPar, Allocator>& X);
00185 void Copy(const Vec& petsc_vector);
00186
00187 void Reallocate(int i, int local_size = PETSC_DECIDE);
00188
00189 #ifndef SWIG
00190 Vector<T, PETScPar, Allocator>& operator= (const Vector<T,
00191 PETScPar, Allocator>& X);
00192 template <class T0>
00193 Vector<T, PETScPar, Allocator>& operator= (const T0& X);
00194 #endif
00195 template <class T0>
00196 Vector<T, PETScPar, Allocator>& operator*= (const T0& X);
00197
00198 void Print() const;
00199
00200
00201 void Write(string FileName, bool with_size = true) const;
00202 void Write(ostream& FileStream, bool with_size = true) const;
00203 void WriteText(string FileName) const;
00204 void WriteText(ostream& FileStream) const;
00205 void Read(string FileName, bool with_size = true);
00206 void Read(istream& FileStream, bool with_size = true);
00207 void ReadText(string FileName);
00208 void ReadText(istream& FileStream);
00209 };
00210
00211
00212 #ifndef SWIG
00213 template <class T, class Allocator>
00214 ostream& operator << (ostream& out,
00215 const Vector<T, PETScPar, Allocator>& V);
00216 #endif
00217
00218
00219
00220 }
00221
00222 #define SELDON_FILE_VECTOR_PETSCVECTOR_HXX
00223 #endif