00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _PETSCVECTOOLS_HPP_
00031 #define _PETSCVECTOOLS_HPP_
00032
00033 #include "UblasVectorInclude.hpp"
00034
00035 #include <petscvec.h>
00036
00040 class PetscVecTools
00041 {
00042 public:
00047 static void Assemble(Vec vector);
00048
00053 static void Display(Vec vector);
00054
00059 static void Zero(Vec vector);
00060
00068 static void SetElement(Vec vector, PetscInt row, double value);
00069
00077 static void AddToElement(Vec vector, PetscInt row, double value);
00078
00084 static unsigned GetSize(Vec vector);
00085
00093 static void GetOwnershipRange(Vec vector, PetscInt& lo, PetscInt& hi);
00094
00102 static double GetElement(Vec vector, PetscInt row);
00103
00111 static void AddScaledVector(Vec y, Vec x, double scaleFactor);
00112
00118 static void Scale(Vec vector, double scaleFactor);
00119
00128 static void WAXPY(Vec w, double a, Vec x, Vec y);
00129
00130
00141 template<size_t VECTOR_SIZE>
00142 static void AddMultipleValues(Vec vector, unsigned* vectorIndices, c_vector<double, VECTOR_SIZE>& smallVector)
00143 {
00144 PetscInt indices_owned[VECTOR_SIZE];
00145 PetscInt num_indices_owned = 0;
00146 PetscInt global_row;
00147 PetscInt lo, hi;
00148 GetOwnershipRange(vector, lo, hi);
00149
00150 for (unsigned row = 0; row<VECTOR_SIZE; row++)
00151 {
00152 global_row = vectorIndices[row];
00153 if (global_row >=lo && global_row <hi)
00154 {
00155 indices_owned[num_indices_owned++] = global_row;
00156 }
00157 }
00158
00159 if (num_indices_owned == VECTOR_SIZE)
00160 {
00161 VecSetValues(vector,
00162 num_indices_owned,
00163 indices_owned,
00164 smallVector.data(),
00165 ADD_VALUES);
00166 }
00167 else
00168 {
00169
00170
00171 double values[VECTOR_SIZE];
00172 unsigned num_values_owned = 0;
00173
00174 for (unsigned row = 0; row<VECTOR_SIZE; row++)
00175 {
00176 global_row = vectorIndices[row];
00177 if (global_row >= lo && global_row < hi)
00178 {
00179 values[num_values_owned++] = smallVector(row);
00180 }
00181 }
00182
00183 VecSetValues(vector,
00184 num_indices_owned,
00185 indices_owned,
00186 values,
00187 ADD_VALUES);
00188 }
00189 }
00190
00199 static void SetupInterleavedVectorScatterGather(Vec interleavedVec, VecScatter& rFirstVariableScatterContext, VecScatter& rSecondVariableScatterContext);
00200
00201
00211 static void DoInterleavedVecScatter(Vec interleavedVec, VecScatter firstVariableScatterContext, Vec firstVariableVec, VecScatter secondVariableScatterContext, Vec secondVariableVec);
00212
00222 static void DoInterleavedVecGather(Vec interleavedVec, VecScatter firstVariableScatterContext, Vec firstVariableVec, VecScatter secondVariableScatterContext, Vec secondVariableVec);
00223
00224 };
00225
00226 #endif //_PETSCVECTOOLS_HPP_