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 "TSFMatrixLaplacian1D.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 MatrixLaplacian1D::MatrixLaplacian1D(int nLocalRows,
00042 const VectorType<double>& type)
00043 : OperatorBuilder<double>(nLocalRows, type), op_()
00044 {
00045 init(nLocalRows, type);
00046 }
00047
00048
00049
00050
00051 void MatrixLaplacian1D::init(int nLocalRows,
00052 const VectorType<double>& type)
00053 {
00054 int rank = MPIComm::world().getRank();
00055 int nProc = MPIComm::world().getNProc();
00056 RCP<MatrixFactory<double> > mFact;
00057 mFact = vecType().createMatrixFactory(domain(), range());
00058
00059 if (domain().dim() == domain().numLocalElements())
00060 {
00061 rank = 0;
00062 nProc = 1;
00063 }
00064
00065 int lowestLocalRow = nLocalRows * rank;
00066
00067 IncrementallyConfigurableMatrixFactory* icmf
00068 = dynamic_cast<IncrementallyConfigurableMatrixFactory*>(mFact.get());
00069 if (icmf)
00070 {
00071 for (int i=0; i<nLocalRows; i++)
00072 {
00073 int row = lowestLocalRow + i;
00074 Array<int> colIndices;
00075 if (rank==0 && i==0)
00076 {
00077 colIndices = tuple(row, row+1);
00078 }
00079 else if (rank==nProc-1 && i==nLocalRows-1)
00080 {
00081 colIndices = tuple(row-1, row);
00082 }
00083 else
00084 {
00085 colIndices = tuple(row-1, row, row+1);
00086 }
00087 icmf->initializeNonzerosInRow(row, colIndices.size(),
00088 &(colIndices[0]));
00089 }
00090 icmf->finalize();
00091 }
00092
00093 op_ = mFact->createMatrix();
00094
00095 double h = 1.0/((double) domain().dim() + 1);
00096
00097 RCP<LoadableMatrix<double> > mat = op_.matrix();
00098
00099
00100 for (int i=0; i<nLocalRows; i++)
00101 {
00102 int row = lowestLocalRow + i;
00103 Array<int> colIndices;
00104 Array<double> colVals;
00105 if (rank==0 && i==0)
00106 {
00107 colIndices = tuple(row, row+1);
00108 colVals = tuple(2.0/h/h, -1.0/h/h);
00109 }
00110 else if (rank==nProc-1 && i==nLocalRows-1)
00111 {
00112 colIndices = tuple(row-1, row);
00113 colVals = tuple(-1.0/h/h, 2.0/h/h);
00114 }
00115 else
00116 {
00117 colIndices = tuple(row-1, row, row+1);
00118 colVals = tuple(-1.0/h/h, 2.0/h/h, -1.0/h/h);
00119 }
00120 mat->addToRow(row, colIndices.size(),
00121 &(colIndices[0]), &(colVals[0]));
00122 }
00123 }