Go to the documentation of this file.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 #include "TSFEpetraMatrix.hpp"
00030 #include "TSFEpetraMatrixMatrixSum.hpp"
00031 #include "TSFEpetraVector.hpp"
00032 #include "SundanceExceptions.hpp"
00033 #include "EpetraExt_MatrixMatrix.h"
00034
00035 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00036 #include "TSFVectorImpl.hpp"
00037 #include "TSFLinearOperatorImpl.hpp"
00038 #endif
00039
00040
00041
00042 namespace TSFExtended
00043 {
00044 using namespace Teuchos;
00045
00046
00047 LinearOperator<double> epetraMatrixMatrixSum(
00048 const LinearOperator<double>& A,
00049 const LinearOperator<double>& B)
00050 {
00051
00052
00053 RCP<const Epetra_CrsMatrix> A_crs = EpetraMatrix::getConcretePtr(A);
00054
00055
00056
00057 RCP<const Epetra_CrsMatrix> B_crs = EpetraMatrix::getConcretePtr(B);
00058
00059 bool transA = false;
00060 bool transB = false;
00061
00062 TEST_FOR_EXCEPTION(A.range() != B.range(), RuntimeError,
00063 "incompatible operand ranges in epetraMatrixMatrixSum()"
00064 << std::endl << "A.range()=" << A.range()
00065 << std::endl << "B.range()=" << B.range()
00066 );
00067
00068
00069 TEST_FOR_EXCEPTION(A.domain() != B.domain(), RuntimeError,
00070 "incompatible operand domains in epetraMatrixMatrixSum()"
00071 << std::endl << "A.domain()=" << A.domain()
00072 << std::endl << "B.domain()=" << B.domain()
00073 );
00074
00075
00076
00077 const Epetra_Map* rowmap
00078 = transA ? &(A_crs->DomainMap()) : &(A_crs->RowMap());
00079
00080
00081 RCP<Epetra_CrsMatrix> C = rcp(new Epetra_CrsMatrix(Copy, *rowmap, 1));
00082 Epetra_CrsMatrix* CPtr = C.get();
00083
00084
00085 int ierr
00086 = EpetraExt::MatrixMatrix::Add(
00087 *A_crs, transA, 1.0,
00088 *B_crs, transB, 1.0, CPtr);
00089 TEST_FOR_EXCEPTION(ierr != 0, RuntimeError,
00090 "EpetraExt Matrix-matrix add failed with error code ierr=" << ierr);
00091
00092
00093 C->FillComplete();
00094
00095
00096 RCP<const EpetraVectorSpace> range
00097 = rcp_dynamic_cast<const EpetraVectorSpace>(A.range().ptr());
00098
00099 RCP<const EpetraVectorSpace> domain
00100 = rcp_dynamic_cast<const EpetraVectorSpace>(B.domain().ptr());
00101
00102 RCP<LinearOpBase<double> > rtn
00103 = rcp(new EpetraMatrix(C, domain, range));
00104 return rtn;
00105
00106 }
00107
00108 }