Changeset 11734 for issm/trunk-jpl/src/c/objects/Numerics/Vector.cpp
- Timestamp:
- 03/19/12 20:11:39 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/objects/Numerics/Vector.cpp
r11713 r11734 25 25 Vector::Vector(){ 26 26 27 this->M=0;28 27 #ifdef _HAVE_PETSC_ 29 28 this->vector=NULL; … … 42 41 this->vector=NewVec(pM,fromlocalsize); 43 42 #else 44 this->M=pM; 45 this->vector=(double*)xcalloc(pM,sizeof(double)); 43 this->vector=new SeqVec(pM,fromlocalsize); 46 44 #endif 47 45 #ifdef _HAVE_ADOLC_ … … 51 49 /*}}}*/ 52 50 /*FUNCTION Vector::Vector(double* serial_vec,int M){{{1*/ 53 Vector::Vector(double* serial_vec,int pM){51 Vector::Vector(double* serial_vec,int M){ 54 52 55 53 int i,j; … … 58 56 int* idxm=NULL; 59 57 60 this->vector=NewVec( pM);58 this->vector=NewVec(M); 61 59 62 60 idxm=(int*)xmalloc(M*sizeof(int)); … … 70 68 71 69 #else 72 this->M=pM; 73 this->vector=(double*)xcalloc(pM,sizeof(double)); 74 #endif 75 #ifdef _HAVE_ADOLC_ 76 this->avector=(adouble*)xmalloc(pM*sizeof(adouble)); 70 this->vector=new SeqVec(serial_vec,M); 71 #endif 72 #ifdef _HAVE_ADOLC_ 73 this->avector=(adouble*)xmalloc(M*sizeof(adouble)); 77 74 #endif 78 75 } … … 82 79 Vector::Vector(Vec petsc_vec){ 83 80 84 /*Get Vector size*/85 VecGetSize(petsc_vec,&this->M);86 87 81 /*copy vector*/ 88 82 VecDuplicate(petsc_vec,&this->vector); … … 98 92 VecFree(&this->vector); 99 93 #else 100 xfree((void**)&this->vector);94 delete this->vector; 101 95 #endif 102 96 #ifdef _HAVE_ADOLC_ … … 115 109 VecView(this->vector,PETSC_VIEWER_STDOUT_WORLD); 116 110 #else 117 printf("Vector size: %i\n",M); 118 for(i=0;i<M;i++){ 119 printf("%g\n ",*(vector+i)); 120 } 121 #endif 122 123 #ifdef _HAVE_ADOLC_ 124 /*Not sure about that one. Should we use the overloaded operator >>?*/ 125 printf("ADOLC Vector equivalent:" ); 126 for(i=0;i<M;i++){ 127 printf("%g\n ",*(avector+i)); 128 } 111 this->vector->Echo(); 112 #endif 113 114 #ifdef _HAVE_ADOLC_ 115 /*do nothing for now: */ 129 116 #endif 130 117 } … … 139 126 PetscVectorToMatlabVector(&dataref,this->vector); 140 127 #else 141 _error_("not implemented yet!");128 dataref=this->vector->ToMatlabVector(); 142 129 #endif 143 130 return dataref; 144 131 132 } 133 /*}}}*/ 134 /*FUNCTION MatlabVectorToVector{{{1*/ 135 Vector* MatlabVectorToVector(const mxArray* mxvector){ 136 137 int dummy; 138 Vector* vector=NULL; 139 140 /*allocate vector object: */ 141 vector=new Vector(); 142 143 #ifdef _HAVE_PETSC_ 144 MatlabVectorToPetscVector(&vector->vector,&dummy,mxvector); 145 #else 146 vector->vector=MatlabVectorToSeqVec(mxvector); 147 #endif 148 149 return vector; 145 150 } 146 151 /*}}}*/ … … 154 159 VecAssemblyEnd(this->vector); 155 160 #else 156 /*do nothing*/161 this->vector->Assemble(); 157 162 #endif 158 163 … … 167 172 VecSetValues(this->vector,ssize,list,values,ISSMToPetscInsertMode(mode)); 168 173 #else 169 _error_("not implemented yet!");174 this->vector->SetValues(ssize,list,values,mode); 170 175 #endif 171 176 … … 179 184 VecSetValues(this->vector,1,&dof,&value,ISSMToPetscInsertMode(mode)); 180 185 #else 181 _error_("not implemented yet!");186 this->vector->SetValue(dof,value,mode); 182 187 #endif 183 188 … … 191 196 VecGetValues(this->vector,1,&dof,pvalue); 192 197 #else 193 _error_("not implemented yet!");198 this->vector->GetValue(pvalue,dof); 194 199 #endif 195 200 } … … 202 207 VecGetSize(this->vector,pM); 203 208 #else 204 _error_("not implemented yet!");209 this->vector->GetSize(pM); 205 210 #endif 206 211 … … 214 219 VecGetLocalSize(this->vector,pM); 215 220 #else 216 _error_("not implemented yet!");221 this->vector->GetLocalSize(pM); 217 222 #endif 218 223 … … 229 234 VecDuplicate(this->vector,&vec_output); 230 235 output->vector=vec_output; 231 VecGetSize(output->vector,&output->M); 232 #else 233 _error_("not implemented yet!"); 236 #else 237 output->vector=this->vector->Duplicate(); 234 238 #endif 235 239 return output; … … 244 248 VecSet(this->vector,value); 245 249 #else 246 _error_("not implemented yet!");250 this->vector->Set(value); 247 251 #endif 248 252 … … 256 260 VecAXPY(this->vector,a,X->vector); 257 261 #else 258 _error_("not implemented yet!");262 this->vector->AXPY(X->vector,a); 259 263 #endif 260 264 } … … 267 271 VecAYPX(this->vector,a,X->vector); 268 272 #else 269 _error_("not implemented yet!");273 this->vector->AYPX(X->vector,a); 270 274 #endif 271 275 … … 280 284 VecToMPISerial(&vec_serial, this->vector); 281 285 #else 282 _error_("not implemented yet!");286 vec_serial=this->vector->ToMPISerial(); 283 287 #endif 284 288 … … 293 297 VecCopy(this->vector,to->vector); 294 298 #else 295 _error_("not implemented yet!");299 this->vector->Copy(to->vector); 296 300 #endif 297 301 … … 306 310 VecNorm(this->vector,ISSMToPetscNormMode(norm_type),&norm); 307 311 #else 308 _error_("not implemented yet!");312 norm=this->vector->Norm(norm_type); 309 313 #endif 310 314 return norm; … … 318 322 VecScale(this->vector,scale_factor); 319 323 #else 320 _error_("not implemented yet!");324 this->vector->Scale(scale_factor); 321 325 #endif 322 326 } … … 330 334 VecDot(this->vector,vector->vector,&dot); 331 335 #else 332 _error_("not implemented yet!");336 dot=this->vector->Dot(vector->vector); 333 337 #endif 334 338 return dot; … … 342 346 VecPointwiseDivide(this->vector,x->vector,y->vector); 343 347 #else 344 _error_("not implemented yet!");345 #endif 346 } 347 /*}}}*/ 348 this->vector->PointwiseDivide(x->vector,y->vector); 349 #endif 350 } 351 /*}}}*/
Note:
See TracChangeset
for help on using the changeset viewer.