Ice Sheet System Model  4.18
Code documentation
Public Member Functions | Data Fields
PetscVec Class Reference

#include <PetscVec.h>

Public Member Functions

 PetscVec ()
 
 PetscVec (int M, bool fromlocalsize=false)
 
 PetscVec (int m, int M)
 
 PetscVec (IssmDouble *buffer, int M)
 
 PetscVec (Vec petsc_vec)
 
 ~PetscVec ()
 
void Echo (void)
 
void Assemble (void)
 
void SetValues (int ssize, int *list, IssmDouble *values, InsMode mode)
 
void SetValue (int dof, IssmDouble value, InsMode mode)
 
void GetValue (IssmDouble *pvalue, int dof)
 
void GetSize (int *pM)
 
void GetLocalSize (int *pM)
 
void GetLocalVector (IssmDouble **pvector, int **pindices)
 
PetscVecDuplicate (void)
 
void Set (IssmDouble value)
 
void AXPY (PetscVec *X, IssmDouble a)
 
void AYPX (PetscVec *X, IssmDouble a)
 
IssmDoubleToMPISerial (void)
 
IssmDoubleToMPISerial0 (void)
 
void Shift (IssmDouble shift)
 
void Copy (PetscVec *to)
 
IssmDouble Norm (NormMode norm_type)
 
IssmDouble Max (void)
 
void Scale (IssmDouble scale_factor)
 
void Pow (IssmDouble scale_factor)
 
void PointwiseDivide (PetscVec *x, PetscVec *y)
 
void PointwiseMult (PetscVec *x, PetscVec *y)
 
IssmDouble Dot (PetscVec *vector)
 

Data Fields

Vec vector
 

Detailed Description

Definition at line 22 of file PetscVec.h.

Constructor & Destructor Documentation

◆ PetscVec() [1/5]

PetscVec::PetscVec ( )

Definition at line 21 of file PetscVec.cpp.

21  {/*{{{*/
22  this->vector=NULL;
23  #ifdef _HAVE_AD_
24  this->avector=NULL;
25  #endif
26 }

◆ PetscVec() [2/5]

PetscVec::PetscVec ( int  M,
bool  fromlocalsize = false 
)

Definition at line 28 of file PetscVec.cpp.

28  {/*{{{*/
29 
30  this->vector=NewVec(M,IssmComm::GetComm(),fromlocalsize);
31 
32 }

◆ PetscVec() [3/5]

PetscVec::PetscVec ( int  m,
int  M 
)

Definition at line 34 of file PetscVec.cpp.

34  {/*{{{*/
35 
36  VecCreate(IssmComm::GetComm(),&this->vector);
37  VecSetSizes(this->vector,m,M);
38  VecSetFromOptions(this->vector);
39  VecSet(this->vector,0.0);
40 
41 }

◆ PetscVec() [4/5]

PetscVec::PetscVec ( IssmDouble buffer,
int  M 
)

Definition at line 56 of file PetscVec.cpp.

56  {/*{{{*/
57 
58  int* idxm=NULL;
59  if(M)idxm=xNew<int>(M);
60  for(int i=0;i<M;i++) idxm[i]=i;
61 
62  this->vector=NewVec(M,IssmComm::GetComm());
63  VecSetValues(this->vector,M,idxm,serial_vec,INSERT_VALUES);
64  VecAssemblyBegin(this->vector);
65  VecAssemblyEnd(this->vector);
66 
67  xDelete<int>(idxm);
68 }

◆ PetscVec() [5/5]

PetscVec::PetscVec ( Vec  petsc_vec)

Definition at line 43 of file PetscVec.cpp.

43  {/*{{{*/
44 
45  if(petsc_vec==NULL){
46  this->vector=NewVec(0,IssmComm::GetComm());
47  }
48  else{
49  /*copy vector*/
50  VecDuplicate(petsc_vec,&this->vector);
51  VecCopy(petsc_vec,this->vector);
52  }
53 
54 }

◆ ~PetscVec()

PetscVec::~PetscVec ( )

Definition at line 70 of file PetscVec.cpp.

70  {/*{{{*/
71  VecFree(&this->vector);
72 }

Member Function Documentation

◆ Echo()

void PetscVec::Echo ( void  )

Definition at line 76 of file PetscVec.cpp.

76  {/*{{{*/
77 
78  _assert_(this->vector);
79  VecView(this->vector,PETSC_VIEWER_STDOUT_WORLD);
80 }

◆ Assemble()

void PetscVec::Assemble ( void  )

Definition at line 82 of file PetscVec.cpp.

82  {/*{{{*/
83 
84  _assert_(this->vector);
85  VecAssemblyBegin(this->vector);
86  VecAssemblyEnd(this->vector);
87 
88 }

◆ SetValues()

void PetscVec::SetValues ( int  ssize,
int *  list,
IssmDouble values,
InsMode  mode 
)

Definition at line 90 of file PetscVec.cpp.

90  {/*{{{*/
91 
92  _assert_(this->vector);
93  VecSetValues(this->vector,ssize,list,values,ISSMToPetscInsertMode(mode));
94 
95 }

◆ SetValue()

void PetscVec::SetValue ( int  dof,
IssmDouble  value,
InsMode  mode 
)

Definition at line 97 of file PetscVec.cpp.

97  {/*{{{*/
98 
99  _assert_(this->vector);
100  VecSetValues(this->vector,1,&dof,&value,ISSMToPetscInsertMode(mode));
101 
102 }

◆ GetValue()

void PetscVec::GetValue ( IssmDouble pvalue,
int  dof 
)

Definition at line 104 of file PetscVec.cpp.

104  {/*{{{*/
105 
106  _assert_(this->vector);
107  VecGetValues(this->vector,1,&dof,pvalue);
108 
109 }

◆ GetSize()

void PetscVec::GetSize ( int *  pM)

Definition at line 111 of file PetscVec.cpp.

111  {/*{{{*/
112 
113  _assert_(this->vector);
114  VecGetSize(this->vector,pM);
115 }

◆ GetLocalSize()

void PetscVec::GetLocalSize ( int *  pM)

Definition at line 117 of file PetscVec.cpp.

117  {/*{{{*/
118 
119  _assert_(this->vector);
120  VecGetLocalSize(this->vector,pm);
121 }

◆ GetLocalVector()

void PetscVec::GetLocalVector ( IssmDouble **  pvector,
int **  pindices 
)

Definition at line 123 of file PetscVec.cpp.

123  {/*{{{*/
124 
125  _assert_(this->vector);
126 
127  /*First, check that vector size is not 0*/
128  int vector_size;
129  this->GetSize(&vector_size);
130  if(vector_size==0){
131  *pvector=NULL;
132  *pindices=NULL;
133  return;
134  }
135 
136  /*Get Ownership range*/
137  PetscInt lower_row,upper_row;
138  VecGetOwnershipRange(this->vector,&lower_row,&upper_row);
139  int range=upper_row-lower_row;
140 
141  /*return NULL if no range*/
142  if(range==0){
143  *pvector=NULL;
144  *pindices=NULL;
145  return;
146  }
147 
148  /*Build indices*/
149  int* indices=xNew<int>(range);
150  for(int i=0;i<range;i++) indices[i]=lower_row+i;
151  /*Get vector*/
152  IssmDouble* values =xNew<IssmDouble>(range);
153  VecGetValues(this->vector,range,indices,values);
154 
155  *pvector = values;
156  *pindices = indices;
157 } /*}}}*/

◆ Duplicate()

PetscVec * PetscVec::Duplicate ( void  )

Definition at line 158 of file PetscVec.cpp.

158  {/*{{{*/
159 
160  _assert_(this->vector);
161  Vec vec_output=NULL;
162  VecDuplicate(this->vector,&vec_output);
163  PetscVec* output=new PetscVec(vec_output);
164  VecFree(&vec_output);
165 
166  return output;
167 }

◆ Set()

void PetscVec::Set ( IssmDouble  value)

Definition at line 169 of file PetscVec.cpp.

169  {/*{{{*/
170 
171  _assert_(this->vector);
172  VecSet(this->vector,value);
173 
174 }

◆ AXPY()

void PetscVec::AXPY ( PetscVec X,
IssmDouble  a 
)

Definition at line 176 of file PetscVec.cpp.

176  {/*{{{*/
177 
178  _assert_(this->vector);
179  VecAXPY(this->vector,a,X->vector);
180 
181 }

◆ AYPX()

void PetscVec::AYPX ( PetscVec X,
IssmDouble  a 
)

Definition at line 183 of file PetscVec.cpp.

183  {/*{{{*/
184 
185  _assert_(this->vector);
186  VecAYPX(this->vector,a,X->vector);
187 
188 }

◆ ToMPISerial()

IssmDouble * PetscVec::ToMPISerial ( void  )

Definition at line 190 of file PetscVec.cpp.

190  {/*{{{*/
191 
192  IssmDouble* vec_serial=NULL;
193  VecToMPISerial(&vec_serial, this->vector,IssmComm::GetComm(),true);
194  return vec_serial;
195 
196 }

◆ ToMPISerial0()

IssmDouble * PetscVec::ToMPISerial0 ( void  )

Definition at line 198 of file PetscVec.cpp.

198  {/*{{{*/
199 
200  IssmDouble* vec_serial=NULL;
201  VecToMPISerial(&vec_serial, this->vector,IssmComm::GetComm(),false);
202  return vec_serial;
203 
204 }

◆ Shift()

void PetscVec::Shift ( IssmDouble  shift)

Definition at line 206 of file PetscVec.cpp.

206  {/*{{{*/
207 
208  if(this->vector) VecShift(this->vector,shift);
209 
210 }

◆ Copy()

void PetscVec::Copy ( PetscVec to)

Definition at line 212 of file PetscVec.cpp.

212  {/*{{{*/
213 
214  if(this->vector) VecCopy(this->vector,to->vector);
215 
216 }

◆ Norm()

IssmDouble PetscVec::Norm ( NormMode  norm_type)

Definition at line 228 of file PetscVec.cpp.

228  {/*{{{*/
229 
230  IssmDouble norm=0;
231  _assert_(this->vector);
232  VecNorm(this->vector,ISSMToPetscNormMode(mode),&norm);
233  return norm;
234 
235 }

◆ Max()

IssmDouble PetscVec::Max ( void  )

Definition at line 218 of file PetscVec.cpp.

218  {/*{{{*/
219 
220  _assert_(this->vector);
221 
222  IssmDouble max;
223  VecMax(this->vector,NULL,&max);
224  return max;
225 
226 }

◆ Scale()

void PetscVec::Scale ( IssmDouble  scale_factor)

Definition at line 237 of file PetscVec.cpp.

237  {/*{{{*/
238 
239  _assert_(this->vector);
240  VecScale(this->vector,scale_factor);
241 
242 }

◆ Pow()

void PetscVec::Pow ( IssmDouble  scale_factor)

Definition at line 244 of file PetscVec.cpp.

244  {/*{{{*/
245 
246  _assert_(this->vector);
247  VecPow(this->vector,scale_factor);
248 
249 }

◆ PointwiseDivide()

void PetscVec::PointwiseDivide ( PetscVec x,
PetscVec y 
)

Definition at line 260 of file PetscVec.cpp.

260  {/*{{{*/
261 
262  _assert_(this->vector);
263  VecPointwiseDivide(this->vector,x->vector,y->vector);
264 
265 }

◆ PointwiseMult()

void PetscVec::PointwiseMult ( PetscVec x,
PetscVec y 
)

Definition at line 267 of file PetscVec.cpp.

267  {/*{{{*/
268 
269  _assert_(this->vector);
270  VecPointwiseMult(this->vector,x->vector,y->vector);
271 
272 }

◆ Dot()

IssmDouble PetscVec::Dot ( PetscVec vector)

Definition at line 251 of file PetscVec.cpp.

251  {/*{{{*/
252 
253  IssmDouble dot;
254  _assert_(this->vector);
255  VecDot(this->vector,input->vector,&dot);
256  return dot;
257 
258 }

Field Documentation

◆ vector

Vec PetscVec::vector

Definition at line 25 of file PetscVec.h.


The documentation for this class was generated from the following files:
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
IssmDouble
double IssmDouble
Definition: types.h:37
PetscVec::PetscVec
PetscVec()
Definition: PetscVec.cpp:21
IssmComm::GetComm
static ISSM_MPI_Comm GetComm(void)
Definition: IssmComm.cpp:30
PetscVec::vector
Vec vector
Definition: PetscVec.h:25
VecFree
void VecFree(Vec *pvec)
Definition: VecFree.cpp:16
ISSMToPetscNormMode
NormType ISSMToPetscNormMode(NormMode mode)
Definition: ISSMToPetscNormMode.cpp:20
NewVec
Vec NewVec(int size, ISSM_MPI_Comm comm, bool fromlocalsize)
Definition: NewVec.cpp:19
VecToMPISerial
int VecToMPISerial(double **pgathered_vector, Vec vector, ISSM_MPI_Comm comm, bool broadcast=true)
Definition: VecToMPISerial.cpp:14
PetscVec::GetSize
void GetSize(int *pM)
Definition: PetscVec.cpp:111
ISSMToPetscInsertMode
InsertMode ISSMToPetscInsertMode(InsMode mode)
Definition: ISSMToPetscInsertMode.cpp:20
PetscVec
Definition: PetscVec.h:22
max
IssmDouble max(IssmDouble a, IssmDouble b)
Definition: extrema.cpp:24