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 "TSFHeatOperator1D.hpp"
00030 #include "TSFEpetraMatrix.hpp"
00031
00032 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00033 #include "TSFVectorImpl.hpp"
00034 #include "TSFLinearOperatorImpl.hpp"
00035 #endif
00036
00037 using namespace TSFExtended;
00038 using namespace Teuchos;
00039
00040
00041 HeatOperator1D::HeatOperator1D(int nLocalRows, const VectorType<double>& type)
00042 : OperatorBuilder<double>(nLocalRows, type),
00043 matrixFactory_(),
00044 cj_(0.0),
00045 h_(0.0),
00046 nLocalRows_(nLocalRows),
00047 lowestLocalRow_(0)
00048 {
00049 int rank = MPIComm::world().getRank();
00050 int nProc = MPIComm::world().getNProc();
00051 matrixFactory_ = vecType().createMatrixFactory(domain(), range());
00052
00053 int n = domain().dim();
00054 h_ = 1.0/(n - 1.0);
00055
00056 lowestLocalRow_ = nLocalRows * rank;
00057
00058 IncrementallyConfigurableMatrixFactory* icmf
00059 = dynamic_cast<IncrementallyConfigurableMatrixFactory*>(matrixFactory_.get());
00060 for (int i=0; i<nLocalRows; i++)
00061 {
00062 int row = lowestLocalRow_ + i;
00063 Array<int> colIndices;
00064 if ((rank==0 && i==0) || (rank==nProc-1 && i==nLocalRows-1))
00065 {
00066 colIndices = tuple(row);
00067 }
00068 else
00069 {
00070 colIndices = tuple(row-1, row, row+1);
00071 }
00072 icmf->initializeNonzerosInRow(row, colIndices.size(),
00073 &(colIndices[0]));
00074 }
00075 icmf->finalize();
00076 }
00077
00078
00079
00080 LinearOperator<double> HeatOperator1D::getOp() const
00081 {
00082
00083 int rank = MPIComm::world().getRank();
00084 int nProc = MPIComm::world().getNProc();
00085 LinearOperator<double> rtn = matrixFactory_->createMatrix();
00086
00087 RCP<LoadableMatrix<double> > mat = rtn.matrix();
00088
00089
00090 for (int i=0; i<nLocalRows_; i++)
00091 {
00092 int row = lowestLocalRow_ + i;
00093 Array<int> colIndices;
00094 Array<double> colVals;
00095 if ((rank==0 && i==0) || (rank==nProc-1 && i==nLocalRows_-1))
00096 {
00097 colIndices = tuple(row);
00098 colVals = tuple(1.0);
00099 }
00100 else
00101 {
00102 colIndices = tuple(row-1, row, row+1);
00103 colVals = tuple(-1.0/h_/h_, 2.0/h_/h_ + cj_, -1.0/h_/h_);
00104 }
00105 mat->addToRow(row, colIndices.size(),
00106 &(colIndices[0]), &(colVals[0]));
00107 }
00108
00109 return rtn;
00110 }