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 "TSFEpetraMatrixMatrixProduct.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 using Sundance::RuntimeError;
00046
00047
00048 LinearOperator<double> epetraLeftScale(
00049 const Vector<double>& d,
00050 const LinearOperator<double>& A)
00051 {
00052
00053
00054 RCP<const Epetra_CrsMatrix> A_crs = EpetraMatrix::getConcretePtr(A);
00055
00056
00057 RCP<Epetra_CrsMatrix> mtxCopy = rcp(new Epetra_CrsMatrix(*A_crs));
00058
00059
00060
00061 const Epetra_Vector& epv = EpetraVector::getConcrete(d);
00062
00063
00064 mtxCopy->LeftScale(epv);
00065
00066
00067 RCP<const EpetraVectorSpace> domain
00068 = rcp_dynamic_cast<const EpetraVectorSpace>(A.domain().ptr());
00069
00070 RCP<const EpetraVectorSpace> range
00071 = rcp_dynamic_cast<const EpetraVectorSpace>(A.range().ptr());
00072
00073 RCP<LinearOpBase<double> > rtn
00074 = rcp(new EpetraMatrix(mtxCopy, domain, range));
00075 return rtn;
00076
00077 }
00078
00079 LinearOperator<double> epetraRightScale(
00080 const LinearOperator<double>& A,
00081 const Vector<double>& d)
00082 {
00083
00084
00085 RCP<const Epetra_CrsMatrix> A_crs = EpetraMatrix::getConcretePtr(A);
00086
00087
00088 RCP<Epetra_CrsMatrix> mtxCopy = rcp(new Epetra_CrsMatrix(*A_crs));
00089
00090
00091
00092 const Epetra_Vector& epv = EpetraVector::getConcrete(d);
00093
00094
00095 mtxCopy->RightScale(epv);
00096
00097
00098 RCP<const EpetraVectorSpace> domain
00099 = rcp_dynamic_cast<const EpetraVectorSpace>(A.domain().ptr());
00100
00101 RCP<const EpetraVectorSpace> range
00102 = rcp_dynamic_cast<const EpetraVectorSpace>(A.range().ptr());
00103
00104 RCP<LinearOpBase<double> > rtn
00105 = rcp(new EpetraMatrix(mtxCopy, domain, range));
00106 return rtn;
00107
00108 }
00109
00110
00111 LinearOperator<double> epetraMatrixMatrixProduct(
00112 const LinearOperator<double>& A,
00113 const LinearOperator<double>& B)
00114 {
00115
00116
00117 RCP<const Epetra_CrsMatrix> A_crs = EpetraMatrix::getConcretePtr(A);
00118
00119
00120
00121 RCP<const Epetra_CrsMatrix> B_crs = EpetraMatrix::getConcretePtr(B);
00122
00123 bool transA = false;
00124 bool transB = false;
00125
00126
00127
00128 const Epetra_Map* rowmap
00129 = transA ? &(A_crs->DomainMap()) : &(A_crs->RowMap());
00130
00131
00132 RCP<Epetra_CrsMatrix> C = rcp(new Epetra_CrsMatrix(Copy, *rowmap, 1));
00133
00134
00135 int ierr
00136 = EpetraExt::MatrixMatrix::Multiply(*A_crs, transA, *B_crs, transB, *C);
00137 TEST_FOR_EXCEPTION(ierr != 0, RuntimeError,
00138 "EpetraExt Matrix-matrix multiply failed with error code ierr=" << ierr);
00139
00140
00141 RCP<const EpetraVectorSpace> range
00142 = rcp_dynamic_cast<const EpetraVectorSpace>(A.range().ptr());
00143
00144 RCP<const EpetraVectorSpace> domain
00145 = rcp_dynamic_cast<const EpetraVectorSpace>(B.domain().ptr());
00146
00147 RCP<LinearOpBase<double> > rtn
00148 = rcp(new EpetraMatrix(C, domain, range));
00149 return rtn;
00150
00151 }
00152
00153 }