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