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
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "PlayaMatrixLaplacian1D.hpp"
00043 #include "PlayaEpetraMatrix.hpp"
00044 #include "PlayaIncrementallyConfigurableMatrixFactory.hpp"
00045
00046 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00047 #include "PlayaVectorImpl.hpp"
00048 #include "PlayaLinearOperatorImpl.hpp"
00049 #endif
00050
00051 namespace Playa
00052 {
00053
00054 using namespace Teuchos;
00055
00056
00057 MatrixLaplacian1D::MatrixLaplacian1D(int nLocalRows,
00058 const VectorType<double>& type)
00059 : OperatorBuilder<double>(nLocalRows, type), op_()
00060 {
00061 init(nLocalRows, type);
00062 }
00063
00064
00065
00066 MassMatrix1D::MassMatrix1D(int nLocalRows,
00067 const VectorType<double>& type)
00068 : OperatorBuilder<double>(nLocalRows, type), op_()
00069 {
00070 init(nLocalRows, type);
00071 }
00072
00073
00074
00075
00076 void MatrixLaplacian1D::init(int nLocalRows,
00077 const VectorType<double>& type)
00078 {
00079 int rank = MPIComm::world().getRank();
00080 int nProc = MPIComm::world().getNProc();
00081 RCP<MatrixFactory<double> > mFact;
00082 mFact = vecType().createMatrixFactory(domain(), range());
00083
00084 if (domain().dim() == domain().numLocalElements())
00085 {
00086 rank = 0;
00087 nProc = 1;
00088 }
00089
00090 int lowestLocalRow = nLocalRows * rank;
00091
00092 IncrementallyConfigurableMatrixFactory* icmf
00093 = dynamic_cast<IncrementallyConfigurableMatrixFactory*>(mFact.get());
00094 if (icmf)
00095 {
00096 for (int i=0; i<nLocalRows; i++)
00097 {
00098 int row = lowestLocalRow + i;
00099 Array<int> colIndices;
00100 if (rank==0 && i==0)
00101 {
00102 colIndices = tuple(row, row+1);
00103 }
00104 else if (rank==nProc-1 && i==nLocalRows-1)
00105 {
00106 colIndices = tuple(row-1, row);
00107 }
00108 else
00109 {
00110 colIndices = tuple(row-1, row, row+1);
00111 }
00112 icmf->initializeNonzerosInRow(row, colIndices.size(),
00113 &(colIndices[0]));
00114 }
00115 icmf->finalize();
00116 }
00117
00118 op_ = mFact->createMatrix();
00119
00120 double h = 1.0/((double) domain().dim() + 1);
00121
00122 RCP<LoadableMatrix<double> > mat = op_.matrix();
00123
00124
00125 for (int i=0; i<nLocalRows; i++)
00126 {
00127 int row = lowestLocalRow + i;
00128 Array<int> colIndices;
00129 Array<double> colVals;
00130 if (rank==0 && i==0)
00131 {
00132 colIndices = tuple(row, row+1);
00133 colVals = tuple(2.0/h/h, -1.0/h/h);
00134 }
00135 else if (rank==nProc-1 && i==nLocalRows-1)
00136 {
00137 colIndices = tuple(row-1, row);
00138 colVals = tuple(-1.0/h/h, 2.0/h/h);
00139 }
00140 else
00141 {
00142 colIndices = tuple(row-1, row, row+1);
00143 colVals = tuple(-1.0/h/h, 2.0/h/h, -1.0/h/h);
00144 }
00145 mat->addToRow(row, colIndices.size(),
00146 &(colIndices[0]), &(colVals[0]));
00147 }
00148 }
00149
00150
00151 void MassMatrix1D::init(int nLocalRows,
00152 const VectorType<double>& type)
00153 {
00154 int rank = MPIComm::world().getRank();
00155 int nProc = MPIComm::world().getNProc();
00156 RCP<MatrixFactory<double> > mFact;
00157 mFact = vecType().createMatrixFactory(domain(), range());
00158
00159 if (domain().dim() == domain().numLocalElements())
00160 {
00161 rank = 0;
00162 nProc = 1;
00163 }
00164
00165 int lowestLocalRow = nLocalRows * rank;
00166
00167 IncrementallyConfigurableMatrixFactory* icmf
00168 = dynamic_cast<IncrementallyConfigurableMatrixFactory*>(mFact.get());
00169 if (icmf)
00170 {
00171 for (int i=0; i<nLocalRows; i++)
00172 {
00173 int row = lowestLocalRow + i;
00174 Array<int> colIndices;
00175 if (rank==0 && i==0)
00176 {
00177 colIndices = tuple(row, row+1);
00178 }
00179 else if (rank==nProc-1 && i==nLocalRows-1)
00180 {
00181 colIndices = tuple(row-1, row);
00182 }
00183 else
00184 {
00185 colIndices = tuple(row-1, row, row+1);
00186 }
00187 icmf->initializeNonzerosInRow(row, colIndices.size(),
00188 &(colIndices[0]));
00189 }
00190 icmf->finalize();
00191 }
00192
00193 op_ = mFact->createMatrix();
00194
00195 double h = 1.0/((double) domain().dim() + 1);
00196
00197 RCP<LoadableMatrix<double> > mat = op_.matrix();
00198
00199
00200 for (int i=0; i<nLocalRows; i++)
00201 {
00202 int row = lowestLocalRow + i;
00203 Array<int> colIndices;
00204 Array<double> colVals;
00205 if (rank==0 && i==0)
00206 {
00207 colIndices = tuple(row, row+1);
00208 colVals = tuple(2.0/3.0, 1.0/3.0);
00209 }
00210 else if (rank==nProc-1 && i==nLocalRows-1)
00211 {
00212 colIndices = tuple(row-1, row);
00213 colVals = tuple(1.0/3.0, 2.0/3.0);
00214 }
00215 else
00216 {
00217 colIndices = tuple(row-1, row, row+1);
00218 colVals = tuple(1.0/3.0, 2.0/3.0, 1.0/3.0);
00219 }
00220 mat->addToRow(row, colIndices.size(),
00221 &(colIndices[0]), &(colVals[0]));
00222 }
00223 }
00224
00225
00226 }