Anasazi Version of the Day
Loading...
Searching...
No Matches
AnasaziEpetraAdapter.cpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Anasazi: Block Eigensolvers Package
4//
5// Copyright 2004 NTESS and the Anasazi contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
11
16namespace Anasazi {
17
19 //
20 //--------Anasazi::EpetraMultiVec Implementation-------------------------------
21 //
23
24 // Construction/Destruction
25
26 EpetraMultiVec::EpetraMultiVec(const Epetra_BlockMap& Map_in, double * array,
27 const int numvecs, const int stride)
28 : Epetra_MultiVector(Epetra_DataAccess::Copy, Map_in, array, stride, numvecs)
29 {
30 }
31
32
33 EpetraMultiVec::EpetraMultiVec(const Epetra_BlockMap& Map_in, const int numvecs)
34 : Epetra_MultiVector(Map_in, numvecs)
35 {
36 }
37
38
39 EpetraMultiVec::EpetraMultiVec(Epetra_DataAccess CV,
40 const Epetra_MultiVector& P_vec,
41 const std::vector<int>& index )
42 : Epetra_MultiVector(CV, P_vec, &(const_cast<std::vector<int> &>(index))[0], index.size())
43 {
44 }
45
46
47 EpetraMultiVec::EpetraMultiVec(const Epetra_MultiVector& P_vec)
48 : Epetra_MultiVector(P_vec)
49 {
50 }
51
52
53 //
54 // member functions inherited from Anasazi::MultiVec
55 //
56 //
57 // Simulating a virtual copy constructor. If we could rely on the co-variance
58 // of virtual functions, we could return a pointer to EpetraMultiVec
59 // (the derived type) instead of a pointer to the pure virtual base class.
60 //
61
62 MultiVec<double>* EpetraMultiVec::Clone ( const int numvecs ) const
63 {
64 EpetraMultiVec * ptr_apv = new EpetraMultiVec(Map(), numvecs);
65 return ptr_apv; // safe upcast.
66 }
67 //
68 // the following is a virtual copy constructor returning
69 // a pointer to the pure virtual class. vector values are
70 // copied.
71 //
72
74 {
75 EpetraMultiVec *ptr_apv = new EpetraMultiVec(*this);
76 return ptr_apv; // safe upcast
77 }
78
79
80 MultiVec<double>* EpetraMultiVec::CloneCopy ( const std::vector<int>& index ) const
81 {
82 EpetraMultiVec * ptr_apv = new EpetraMultiVec(Epetra_DataAccess::Copy, *this, index);
83 return ptr_apv; // safe upcast.
84 }
85
86
87 MultiVec<double>* EpetraMultiVec::CloneViewNonConst ( const std::vector<int>& index )
88 {
89 EpetraMultiVec * ptr_apv = new EpetraMultiVec(Epetra_DataAccess::View, *this, index);
90 return ptr_apv; // safe upcast.
91 }
92
93 const MultiVec<double>* EpetraMultiVec::CloneView ( const std::vector<int>& index ) const
94 {
95 EpetraMultiVec * ptr_apv = new EpetraMultiVec(Epetra_DataAccess::View, *this, index);
96 return ptr_apv; // safe upcast.
97 }
98
99
100 void EpetraMultiVec::SetBlock( const MultiVec<double>& A, const std::vector<int>& index )
101 {
102 // this should be revisited to e
103 EpetraMultiVec temp_vec(Epetra_DataAccess::View, *this, index);
104
105 int numvecs = index.size();
106 if ( A.GetNumberVecs() != numvecs ) {
107 std::vector<int> index2( numvecs );
108 for(int i=0; i<numvecs; i++)
109 index2[i] = i;
110 EpetraMultiVec *tmp_vec = dynamic_cast<EpetraMultiVec *>(&const_cast<MultiVec<double> &>(A));
111 TEUCHOS_TEST_FOR_EXCEPTION( tmp_vec==NULL, std::invalid_argument, "Anasazi::EpetraMultiVec::SetBlocks() cast of MultiVec<double> to EpetraMultiVec failed.");
112 EpetraMultiVec A_vec(Epetra_DataAccess::View, *tmp_vec, index2);
113 temp_vec.MvAddMv( 1.0, A_vec, 0.0, A_vec );
114 }
115 else {
116 temp_vec.MvAddMv( 1.0, A, 0.0, A );
117 }
118 }
119
120 //-------------------------------------------------------------
121 //
122 // *this <- alpha * A * B + beta * (*this)
123 //
124 //-------------------------------------------------------------
125
126 void EpetraMultiVec::MvTimesMatAddMv ( double alpha, const MultiVec<double>& A,
127 const Teuchos::SerialDenseMatrix<int,double>& B, double beta )
128 {
129 Epetra_LocalMap LocalMap(B.numRows(), 0, Map().Comm());
130 Epetra_MultiVector B_Pvec(Epetra_DataAccess::View, LocalMap, B.values(), B.stride(), B.numCols());
131
132 EpetraMultiVec *A_vec = dynamic_cast<EpetraMultiVec *>(&const_cast<MultiVec<double> &>(A));
133 TEUCHOS_TEST_FOR_EXCEPTION( A_vec==NULL, std::invalid_argument, "Anasazi::EpetraMultiVec::SetBlocks() cast of MultiVec<double> to EpetraMultiVec failed.");
134
135 TEUCHOS_TEST_FOR_EXCEPTION(
136 Multiply( 'N', 'N', alpha, *A_vec, B_Pvec, beta ) != 0,
137 EpetraMultiVecFailure, "Anasazi::EpetraMultiVec::MvTimesMatAddMv() call to Epetra_MultiVec::Multiply() returned a nonzero value.");
138 }
139
140 //-------------------------------------------------------------
141 //
142 // *this <- alpha * A + beta * B
143 //
144 //-------------------------------------------------------------
145
146 void EpetraMultiVec::MvAddMv ( double alpha , const MultiVec<double>& A,
147 double beta, const MultiVec<double>& B)
148 {
149 EpetraMultiVec *A_vec = dynamic_cast<EpetraMultiVec *>(&const_cast<MultiVec<double> &>(A));
150 TEUCHOS_TEST_FOR_EXCEPTION( A_vec==NULL, std::invalid_argument, "Anasazi::EpetraMultiVec::MvAddMv() cast of MultiVec<double> to EpetraMultiVec failed.");
151 EpetraMultiVec *B_vec = dynamic_cast<EpetraMultiVec *>(&const_cast<MultiVec<double> &>(B));
152 TEUCHOS_TEST_FOR_EXCEPTION( B_vec==NULL, std::invalid_argument, "Anasazi::EpetraMultiVec::MvAddMv() cast of MultiVec<double> to EpetraMultiVec failed.");
153
154 TEUCHOS_TEST_FOR_EXCEPTION(
155 Update( alpha, *A_vec, beta, *B_vec, 0.0 ) != 0,
156 EpetraMultiVecFailure, "Anasazi::EpetraMultiVec::MvAddMv() call to Epetra_MultiVec::Update() returned a nonzero value.");
157 }
158
159 //-------------------------------------------------------------
160 //
161 // dense B <- alpha * A^T * (*this)
162 //
163 //-------------------------------------------------------------
164
165 void EpetraMultiVec::MvTransMv ( double alpha, const MultiVec<double>& A,
166 Teuchos::SerialDenseMatrix<int,double>& B
167#ifdef HAVE_ANASAZI_EXPERIMENTAL
168 , ConjType conj
169#endif
170 ) const
171 {
172 EpetraMultiVec *A_vec = dynamic_cast<EpetraMultiVec *>(&const_cast<MultiVec<double> &>(A));
173
174 if (A_vec) {
175 Epetra_LocalMap LocalMap(B.numRows(), 0, Map().Comm());
176 Epetra_MultiVector B_Pvec(Epetra_DataAccess::View, LocalMap, B.values(), B.stride(), B.numCols());
177
178 TEUCHOS_TEST_FOR_EXCEPTION(
179 B_Pvec.Multiply( 'T', 'N', alpha, *A_vec, *this, 0.0 ) != 0,
180 EpetraMultiVecFailure, "Anasazi::EpetraMultiVec::MvTransMv() call to Epetra_MultiVec::Multiply() returned a nonzero value.");
181 }
182 }
183
184 //-------------------------------------------------------------
185 //
186 // b[i] = A[i]^T * this[i]
187 //
188 //-------------------------------------------------------------
189
190 void EpetraMultiVec::MvDot ( const MultiVec<double>& A, std::vector<double> & b
191#ifdef HAVE_ANASAZI_EXPERIMENTAL
192 , ConjType conj
193#endif
194 ) const
195 {
196 EpetraMultiVec *A_vec = dynamic_cast<EpetraMultiVec *>(&const_cast<MultiVec<double> &>(A));
197 TEUCHOS_TEST_FOR_EXCEPTION( A_vec==NULL, std::invalid_argument, "Anasazi::EpetraMultiVec::MvDot() cast of MultiVec<double> to EpetraMultiVec failed.");
198
199 if (( (int)b.size() >= A_vec->NumVectors() ) ) {
200 TEUCHOS_TEST_FOR_EXCEPTION(
201 this->Dot( *A_vec, &b[0] ) != 0,
202 EpetraMultiVecFailure, "Anasazi::EpetraMultiVec::MvDot() call to Epetra_MultiVec::Dot() returned a nonzero value.");
203 }
204 }
205
206 //-------------------------------------------------------------
207 //
208 // this[i] = alpha[i] * this[i]
209 //
210 //-------------------------------------------------------------
211 void EpetraMultiVec::MvScale ( const std::vector<double>& alpha )
212 {
213 // Check to make sure the vector is as long as the multivector has columns.
214 int numvecs = this->NumVectors();
215 TEUCHOS_TEST_FOR_EXCEPTION( (int)alpha.size() != numvecs, std::invalid_argument,
216 "Anasazi::EpetraMultiVec::MvScale() alpha argument size was inconsistent with number of vectors in mv.");
217
218 std::vector<int> tmp_index( 1, 0 );
219 for (int i=0; i<numvecs; i++) {
220 Epetra_MultiVector temp_vec(Epetra_DataAccess::View, *this, &tmp_index[0], 1);
221 TEUCHOS_TEST_FOR_EXCEPTION(
222 temp_vec.Scale( alpha[i] ) != 0,
223 EpetraMultiVecFailure, "Anasazi::EpetraMultiVec::MvScale() call to Epetra_MultiVec::Scale() returned a nonzero value.");
224 tmp_index[0]++;
225 }
226 }
227
229 //
230 //--------Anasazi::EpetraOp Implementation-------------------------------------
231 //
233
234 //
235 // AnasaziOperator constructors
236 //
237 EpetraOp::EpetraOp(const Teuchos::RCP<Epetra_Operator> &Op)
238 : Epetra_Op(Op)
239 {
240 }
241
243 {
244 }
245 //
246 // AnasaziOperator applications
247 //
249 MultiVec<double>& Y ) const
250 {
251 //
252 // This standard operator computes Y = A*X
253 //
254 MultiVec<double> & temp_X = const_cast<MultiVec<double> &>(X);
255 Epetra_MultiVector* vec_X = dynamic_cast<EpetraMultiVecAccessor*>(&temp_X)->GetEpetraMultiVec();
256 Epetra_MultiVector* vec_Y = dynamic_cast<EpetraMultiVecAccessor*>(&Y)->GetEpetraMultiVec();
257
258 TEUCHOS_TEST_FOR_EXCEPTION( vec_X==NULL, std::invalid_argument, "Anasazi::EpetraOp::Apply() cast of MultiVec<double> to Epetra_MultiVector failed.");
259 TEUCHOS_TEST_FOR_EXCEPTION( vec_Y==NULL, std::invalid_argument, "Anasazi::EpetraOp::Apply() cast of MultiVec<double> to Epetra_MultiVector failed.");
260
261 int info = Epetra_Op->Apply( *vec_X, *vec_Y );
262 TEUCHOS_TEST_FOR_EXCEPTION( info != 0, OperatorError,
263 "Anasazi::EpetraOp::Apply(): Error returned from Epetra_Operator::Apply()" );
264 }
265
267 //
268 //--------Anasazi::EpetraGenOp Implementation----------------------------------
269 //
271
272 //
273 // AnasaziOperator constructors
274 //
275
276 EpetraGenOp::EpetraGenOp(const Teuchos::RCP<Epetra_Operator> &AOp,
277 const Teuchos::RCP<Epetra_Operator> &MOp,
278 bool isAInverse_)
279 : isAInverse( isAInverse_ ), Epetra_AOp(AOp), Epetra_MOp(MOp)
280 {
281 }
282
286 //
287 // AnasaziOperator applications
288 //
290 {
291 //
292 // This generalized operator computes Y = A^{-1}*M*X
293 //
294 int info=0;
295 MultiVec<double> & temp_X = const_cast<MultiVec<double> &>(X);
296 Epetra_MultiVector* vec_X = dynamic_cast<EpetraMultiVecAccessor*>(&temp_X)->GetEpetraMultiVec();
297 Epetra_MultiVector* vec_Y = dynamic_cast<EpetraMultiVecAccessor*>(&Y)->GetEpetraMultiVec();
298 Epetra_MultiVector temp_Y(*vec_Y);
299
300 TEUCHOS_TEST_FOR_EXCEPTION( vec_X==NULL, std::invalid_argument, "Anasazi::EpetraGenOp::Apply() cast of MultiVec<double> to Epetra_MultiVector failed.");
301 TEUCHOS_TEST_FOR_EXCEPTION( vec_Y==NULL, std::invalid_argument, "Anasazi::EpetraGenOp::Apply() cast of MultiVec<double> to Epetra_MultiVector failed.");
302 //
303 // Need to cast away constness because the member function Apply is not declared const.
304 // Change the transpose setting for the operator if necessary and change it back when done.
305 //
306 // Apply M
307 info = Epetra_MOp->Apply( *vec_X, temp_Y );
308 TEUCHOS_TEST_FOR_EXCEPTION( info != 0, OperatorError,
309 "Anasazi::EpetraGenOp::Apply(): Error returned from Epetra_Operator::Apply()" );
310 // Apply A or A^{-1}
311 if (isAInverse) {
312 info = Epetra_AOp->ApplyInverse( temp_Y, *vec_Y );
313 }
314 else {
315 info = Epetra_AOp->Apply( temp_Y, *vec_Y );
316 }
317 TEUCHOS_TEST_FOR_EXCEPTION( info != 0, OperatorError,
318 "Anasazi::EpetraGenOp::Apply(): Error returned from Epetra_Operator::Apply()" );
319 }
320
321 int EpetraGenOp::Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
322 {
323 //
324 // This generalized operator computes Y = A^{-1}*M*X
325 //
326 int info=0;
327 Epetra_MultiVector temp_Y(OperatorDomainMap(), Y.NumVectors());
328
329 // Apply M
330 info = Epetra_MOp->Apply( X, temp_Y );
331 if (info!=0) return info;
332
333 // Apply A or A^{-1}
334 if (isAInverse)
335 info = Epetra_AOp->ApplyInverse( temp_Y, Y );
336 else
337 info = Epetra_AOp->Apply( temp_Y, Y );
338
339 return info;
340 }
341
342 int EpetraGenOp::ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
343 {
344 //
345 // This generalized operator computes Y = M^{-1}*A*X
346 //
347 int info=0;
348 Epetra_MultiVector temp_Y(OperatorDomainMap(), Y.NumVectors());
349
350 // Apply A or A^{-1}
351 if (isAInverse)
352 info = Epetra_AOp->Apply( X, temp_Y );
353 else
354 info = Epetra_AOp->ApplyInverse( X, temp_Y );
355 if (info!=0) return info;
356
357 // Apply M^{-1}
358 info = Epetra_MOp->ApplyInverse( temp_Y, Y );
359
360 return info;
361 }
362
364 //
365 //--------Anasazi::EpetraSymOp Implementation----------------------------------
366 //
368
369 //
370 // AnasaziOperator constructors
371 //
372 EpetraSymOp::EpetraSymOp(const Teuchos::RCP<Epetra_Operator> &Op,
373 bool isTrans)
374 : Epetra_Op(Op), isTrans_(isTrans)
375 {
376 }
377
381 //
382 // AnasaziOperator applications
383 //
385 MultiVec<double>& Y ) const
386 {
387 int info=0;
388 MultiVec<double> & temp_X = const_cast<MultiVec<double> &>(X);
389 Epetra_MultiVector* vec_X = dynamic_cast<EpetraMultiVecAccessor*>(&temp_X)->GetEpetraMultiVec();
390 Epetra_MultiVector* vec_Y = dynamic_cast<EpetraMultiVecAccessor*>(&Y)->GetEpetraMultiVec();
391 Epetra_MultiVector* temp_vec = new Epetra_MultiVector(
392 (isTrans_) ? Epetra_Op->OperatorDomainMap()
393 : Epetra_Op->OperatorRangeMap(),
394 vec_X->NumVectors() );
395
396 TEUCHOS_TEST_FOR_EXCEPTION( vec_X==NULL , std::invalid_argument, "Anasazi::EpetraSymOp::Apply() cast of MultiVec<double> to Epetra_MultiVector failed.");
397 TEUCHOS_TEST_FOR_EXCEPTION( vec_Y==NULL , std::invalid_argument, "Anasazi::EpetraSymOp::Apply() cast of MultiVec<double> to Epetra_MultiVector failed.");
398 TEUCHOS_TEST_FOR_EXCEPTION( temp_vec==NULL, std::invalid_argument, "Anasazi::EpetraSymOp::Apply() allocation Epetra_MultiVector failed.");
399 //
400 // Need to cast away constness because the member function Apply
401 // is not declared const.
402 //
403 // Transpose the operator (if isTrans_ = true)
404 if (isTrans_) {
405 info = Epetra_Op->SetUseTranspose( isTrans_ );
406 if (info != 0) {
407 delete temp_vec;
408 TEUCHOS_TEST_FOR_EXCEPTION( true, OperatorError,
409 "Anasazi::EpetraSymOp::Apply(): Error returned from Epetra_Operator::Apply()" );
410 }
411 }
412 //
413 // Compute A*X or A'*X
414 //
415 info=Epetra_Op->Apply( *vec_X, *temp_vec );
416 if (info!=0) {
417 delete temp_vec;
418 TEUCHOS_TEST_FOR_EXCEPTION( true, OperatorError,
419 "Anasazi::EpetraSymOp::Apply(): Error returned from Epetra_Operator::Apply()" );
420 }
421 //
422 // Transpose/Un-transpose the operator based on value of isTrans_
423 info=Epetra_Op->SetUseTranspose( !isTrans_ );
424 if (info!=0) {
425 delete temp_vec;
426 TEUCHOS_TEST_FOR_EXCEPTION( true, OperatorError,
427 "Anasazi::EpetraSymOp::Apply(): Error returned from Epetra_Operator::Apply()" );
428 }
429
430 // Compute A^T*(A*X) or A*A^T
431 info=Epetra_Op->Apply( *temp_vec, *vec_Y );
432 if (info!=0) {
433 delete temp_vec;
434 TEUCHOS_TEST_FOR_EXCEPTION( true, OperatorError,
435 "Anasazi::EpetraSymOp::Apply(): Error returned from Epetra_Operator::Apply()" );
436 }
437
438 // Un-transpose the operator
439 info=Epetra_Op->SetUseTranspose( false );
440 delete temp_vec;
441 TEUCHOS_TEST_FOR_EXCEPTION( info != 0, OperatorError,
442 "Anasazi::EpetraSymOp::Apply(): Error returned from Epetra_Operator::Apply()" );
443 }
444
445 int EpetraSymOp::Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
446 {
447 int info=0;
448 Epetra_MultiVector temp_vec(OperatorDomainMap(), Y.NumVectors());
449 //
450 // This generalized operator computes Y = A^T*A*X or Y = A*A^T*X
451 //
452 // Transpose the operator (if isTrans_ = true)
453 if (isTrans_) {
454 info=Epetra_Op->SetUseTranspose( isTrans_ );
455 if (info!=0) { return info; }
456 }
457 //
458 // Compute A*X or A^T*X
459 //
460 info=Epetra_Op->Apply( X, temp_vec );
461 if (info!=0) { return info; }
462 //
463 // Transpose/Un-transpose the operator based on value of isTrans_
464 info=Epetra_Op->SetUseTranspose( !isTrans_ );
465 if (info!=0) { return info; }
466
467 // Compute A^T*(A*X) or A*A^T
468 info=Epetra_Op->Apply( temp_vec, Y );
469 if (info!=0) { return info; }
470
471 // Un-transpose the operator
472 info=Epetra_Op->SetUseTranspose( false );
473 return info;
474 }
475
476 int EpetraSymOp::ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
477 {
478 int info=0;
479 Epetra_MultiVector temp_vec(OperatorDomainMap(), Y.NumVectors());
480 //
481 // This generalized operator computes Y = (A^T*A)^{-1}*X or Y = (A*A^T)^{-1}*X
482 //
483 // Transpose the operator (if isTrans_ = true)
484 if (!isTrans_) {
485 info=Epetra_Op->SetUseTranspose( !isTrans_ );
486 if (info!=0) { return info; }
487 }
488 //
489 // Compute A^{-1}*X or A^{-T}*X
490 //
491 info=Epetra_Op->ApplyInverse( X, temp_vec );
492 if (info!=0) { return info; }
493 //
494 // Transpose/Un-transpose the operator based on value of isTrans_
495 info=Epetra_Op->SetUseTranspose( isTrans_ );
496 if (info!=0) { return info; }
497
498 // Compute A^{-T}*(A^{-1}*X) or A^{-1}*A^{-T}
499 info=Epetra_Op->Apply( temp_vec, Y );
500 if (info!=0) { return info; }
501
502 // Un-transpose the operator
503 info=Epetra_Op->SetUseTranspose( false );
504 return info;
505 }
506
508 //
509 //--------Anasazi::EpetraSymMVOp Implementation--------------------------------
510 //
512
513 //
514 // Anasazi::Operator constructors
515 //
516 EpetraSymMVOp::EpetraSymMVOp(const Teuchos::RCP<const Epetra_MultiVector> &MV,
517 bool isTrans)
518 : Epetra_MV(MV), isTrans_(isTrans)
519 {
520 if (isTrans)
521 MV_localmap = Teuchos::rcp( new Epetra_LocalMap( Epetra_MV->NumVectors(), 0, Epetra_MV->Map().Comm() ) );
522 else
523 MV_blockmap = Teuchos::rcp( &Epetra_MV->Map(), false );
524 }
525
526 //
527 // AnasaziOperator applications
528 //
530 {
531 int info=0;
532 MultiVec<double> & temp_X = const_cast<MultiVec<double> &>(X);
533 Epetra_MultiVector* vec_X = dynamic_cast<EpetraMultiVecAccessor*>(&temp_X)->GetEpetraMultiVec();
534 Epetra_MultiVector* vec_Y = dynamic_cast<EpetraMultiVecAccessor*>(&Y)->GetEpetraMultiVec();
535
536 if (isTrans_) {
537
538 Epetra_MultiVector temp_vec( *MV_localmap, temp_X.GetNumberVecs() );
539
540 /* A'*X */
541 info = temp_vec.Multiply( 'T', 'N', 1.0, *Epetra_MV, *vec_X, 0.0 );
542 TEUCHOS_TEST_FOR_EXCEPTION( info != 0, OperatorError,
543 "Anasazi::EpetraSymMVOp::Apply(): Error returned from Epetra_MultiVector::Multiply()" );
544
545 /* A*(A'*X) */
546 info = vec_Y->Multiply( 'N', 'N', 1.0, *Epetra_MV, temp_vec, 0.0 );
547 TEUCHOS_TEST_FOR_EXCEPTION( info != 0, OperatorError,
548 "Anasazi::EpetraSymMVOp::Apply(): Error returned from Epetra_MultiVector::Multiply()" );
549 }
550 else {
551
552 Epetra_MultiVector temp_vec( *MV_blockmap, temp_X.GetNumberVecs() );
553
554 /* A*X */
555 info = temp_vec.Multiply( 'N', 'N', 1.0, *Epetra_MV, *vec_X, 0.0 );
556 TEUCHOS_TEST_FOR_EXCEPTION( info != 0, OperatorError,
557 "Anasazi::EpetraSymMVOp::Apply(): Error returned from Epetra_MultiVector::Multiply()" );
558
559 /* A'*(A*X) */
560 info = vec_Y->Multiply( 'T', 'N', 1.0, *Epetra_MV, temp_vec, 0.0 );
561 TEUCHOS_TEST_FOR_EXCEPTION( info != 0, OperatorError,
562 "Anasazi::EpetraSymMVOp::Apply(): Error returned from Epetra_MultiVector::Multiply()" );
563 }
564 }
565
567 //
568 //--------Anasazi::EpetraWSymMVOp Implementation--------------------------------
569 //
571
572 //
573 // Anasazi::Operator constructors
574 //
575 EpetraWSymMVOp::EpetraWSymMVOp(const Teuchos::RCP<const Epetra_MultiVector> &MV,
576 const Teuchos::RCP<Epetra_Operator> &OP )
577 : Epetra_MV(MV), Epetra_OP(OP)
578 {
579 MV_blockmap = Teuchos::rcp( &Epetra_MV->Map(), false );
580 Epetra_WMV = Teuchos::rcp( new Epetra_MultiVector( *MV_blockmap, Epetra_MV->NumVectors() ) );
581 Epetra_OP->Apply( *Epetra_MV, *Epetra_WMV );
582 }
583
584 //
585 // AnasaziOperator applications
586 //
588 {
589 int info=0;
590 MultiVec<double> & temp_X = const_cast<MultiVec<double> &>(X);
591 Epetra_MultiVector* vec_X = dynamic_cast<EpetraMultiVecAccessor*>(&temp_X)->GetEpetraMultiVec();
592 Epetra_MultiVector* vec_Y = dynamic_cast<EpetraMultiVecAccessor*>(&Y)->GetEpetraMultiVec();
593
594 Epetra_MultiVector temp_vec( *MV_blockmap, temp_X.GetNumberVecs() );
595
596 /* WA*X */
597 info = temp_vec.Multiply( 'N', 'N', 1.0, *Epetra_WMV, *vec_X, 0.0 );
598 TEUCHOS_TEST_FOR_EXCEPTION( info != 0, OperatorError,
599 "Anasazi::EpetraWSymMVOp::Apply(): Error returned from Epetra_MultiVector::Multiply()" );
600
601 /* A'*(WA*X) */
602 info = vec_Y->Multiply( 'T', 'N', 1.0, *Epetra_MV, temp_vec, 0.0 );
603 TEUCHOS_TEST_FOR_EXCEPTION( info != 0, OperatorError,
604 "Anasazi::EpetraWSymMVOp::Apply(): Error returned from Epetra_MultiVector::Multiply()" );
605 }
606
608 //
609 //--------Anasazi::EpetraW2SymMVOp Implementation--------------------------------
610 //
612
613 //
614 // Anasazi::Operator constructors
615 //
616 EpetraW2SymMVOp::EpetraW2SymMVOp(const Teuchos::RCP<const Epetra_MultiVector> &MV,
617 const Teuchos::RCP<Epetra_Operator> &OP )
618 : Epetra_MV(MV), Epetra_OP(OP)
619 {
620 MV_blockmap = Teuchos::rcp( &Epetra_MV->Map(), false );
621 Epetra_WMV = Teuchos::rcp( new Epetra_MultiVector( *MV_blockmap, Epetra_MV->NumVectors() ) );
622 Epetra_OP->Apply( *Epetra_MV, *Epetra_WMV );
623 }
624
625 //
626 // AnasaziOperator applications
627 //
629 {
630 int info=0;
631 MultiVec<double> & temp_X = const_cast<MultiVec<double> &>(X);
632 Epetra_MultiVector* vec_X = dynamic_cast<EpetraMultiVecAccessor*>(&temp_X)->GetEpetraMultiVec();
633 Epetra_MultiVector* vec_Y = dynamic_cast<EpetraMultiVecAccessor*>(&Y)->GetEpetraMultiVec();
634
635 Epetra_MultiVector temp_vec( *MV_blockmap, temp_X.GetNumberVecs() );
636
637 /* WA*X */
638 info = temp_vec.Multiply( 'N', 'N', 1.0, *Epetra_WMV, *vec_X, 0.0 );
639 TEUCHOS_TEST_FOR_EXCEPTION( info != 0, OperatorError,
640 "Anasazi::EpetraW2SymMVOp::Apply(): Error returned from Epetra_MultiVector::Multiply()" );
641
642 /* (WA)'*(WA*X) */
643 info = vec_Y->Multiply( 'T', 'N', 1.0, *Epetra_WMV, temp_vec, 0.0 );
644 TEUCHOS_TEST_FOR_EXCEPTION( info != 0, OperatorError,
645 "Anasazi::EpetraW2SymMVOp::Apply(): Error returned from Epetra_MultiVector::Multiply()" );
646
647 }
648} // end namespace Anasazi
Declarations of Anasazi multi-vector and operator classes using Epetra_MultiVector and Epetra_Operato...
void Apply(const MultiVec< double > &X, MultiVec< double > &Y) const
Apply method [inherited from Anasazi::Operator class].
int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Apply inverse method [inherited from Epetra_Operator class].
EpetraGenOp(const Teuchos::RCP< Epetra_Operator > &AOp, const Teuchos::RCP< Epetra_Operator > &MOp, bool isAInverse=true)
Basic constructor for applying operator [default] or .
const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
EpetraMultiVecAccessor is an interfaceto allow any Anasazi::MultiVec implementation that is based on ...
EpetraMultiVecFailure is thrown when a return value from an Epetra call on an Epetra_MultiVector is n...
Basic adapter class for Anasazi::MultiVec that uses Epetra_MultiVector.
MultiVec< double > * Clone(const int numvecs) const
Creates a new empty EpetraMultiVec containing numvecs columns.
void MvScale(double alpha)
Scale each element of the vectors in *this with alpha.
void MvAddMv(double alpha, const MultiVec< double > &A, double beta, const MultiVec< double > &B)
Replace *this with .
const MultiVec< double > * CloneView(const std::vector< int > &index) const
Creates a new EpetraMultiVec that shares the selected contents of *this.
void SetBlock(const MultiVec< double > &A, const std::vector< int > &index)
Copy the vectors in A to a set of vectors in *this.
EpetraMultiVec(const Epetra_BlockMap &Map_in, const int numvecs)
Basic EpetraMultiVec constructor.
void MvTransMv(double alpha, const MultiVec< double > &A, Teuchos::SerialDenseMatrix< int, double > &B) const
Compute a dense matrix B through the matrix-matrix multiply .
MultiVec< double > * CloneViewNonConst(const std::vector< int > &index)
Creates a new EpetraMultiVec that shares the selected contents of *this.
MultiVec< double > * CloneCopy() const
Creates a new EpetraMultiVec and copies contents of *this into the new vector (deep copy).
void MvTimesMatAddMv(double alpha, const MultiVec< double > &A, const Teuchos::SerialDenseMatrix< int, double > &B, double beta)
Update *this with .
void MvDot(const MultiVec< double > &A, std::vector< double > &b) const
Compute a vector b where the components are the individual dot-products, i.e. where A[i] is the i-th...
void Apply(const MultiVec< double > &X, MultiVec< double > &Y) const
This method takes the Anasazi::MultiVec X and applies the operator to it resulting in the Anasazi::Mu...
EpetraOp(const Teuchos::RCP< Epetra_Operator > &Op)
Basic constructor. Accepts reference-counted pointer to an Epetra_Operator.
void Apply(const MultiVec< double > &X, MultiVec< double > &Y) const
Apply method.
EpetraSymMVOp(const Teuchos::RCP< const Epetra_MultiVector > &MV, bool isTrans=false)
Basic constructor for applying operator [default] or .
EpetraSymOp(const Teuchos::RCP< Epetra_Operator > &Op, bool isTrans=false)
Basic constructor for applying operator [default] or .
const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Apply inverse method [inherited from Epetra_Operator class].
void Apply(const MultiVec< double > &X, MultiVec< double > &Y) const
Apply method [inherited from Anasazi::Operator class].
void Apply(const MultiVec< double > &X, MultiVec< double > &Y) const
Apply method.
EpetraW2SymMVOp(const Teuchos::RCP< const Epetra_MultiVector > &MV, const Teuchos::RCP< Epetra_Operator > &OP)
Basic constructor for applying operator .
EpetraWSymMVOp(const Teuchos::RCP< const Epetra_MultiVector > &MV, const Teuchos::RCP< Epetra_Operator > &OP)
Basic constructor for applying operator .
void Apply(const MultiVec< double > &X, MultiVec< double > &Y) const
Apply method.
Interface for multivectors used by Anasazi's linear solvers.
virtual int GetNumberVecs() const =0
The number of vectors (i.e., columns) in the multivector.
Exceptions thrown to signal error in operator application.
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package.
ConjType
Enumerated types used to specify conjugation arguments.