TSFPoissonBoltzmannJacobian.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 /* ***********************************************************************
00003 // 
00004 //           TSFExtended: Trilinos Solver Framework Extended
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // **********************************************************************/
00027  /* @HEADER@ */
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   /* fill in with the Laplacian operator plus exp(-x) */
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 }

Site Contact