TSFHeatOperator1D.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 "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   /* fill in with the heat operator given the current value of c_j */
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 }

Site Contact