TSFLoadableBlockVector.hpp
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 #ifndef TSFLOADABLEBLOCKVECTOR_HPP
00030 #define TSFLOADABLEBLOCKVECTOR_HPP
00031 
00032 #include "SundanceDefs.hpp"
00033 #include "Thyra_VectorBase.hpp"
00034 
00035 #ifndef DOXYGEN_DEVELOPER_ONLY
00036 
00037 namespace TSFExtended
00038 {
00039   
00040   /**
00041    * LoadableBlockVector provides a LoadableVector interface to a 
00042    * physically-partitioned block 1x2 vector, making it appear to the
00043    * fill routine as if the block vector is a single vector. This 
00044    * is intended for filling systems where the internal and BC equations
00045    * and unknowns are stored in physically separate blocks.
00046    *
00047    * @author Kevin Long (krlong@sandia.gov)
00048    */
00049   class LoadableBlockVector : public LoadableVector<double>
00050     {
00051     public:
00052       /** */
00053       LoadableBlockVector(
00054         const Vector<double>& vec,
00055         int lowestLocalRow,
00056         int highestLocalRow,
00057         const RCP<Array<int> >& isBCRow
00058         ) : lowestLocalRow_(lowestLocalRow), 
00059             highestLocalRow_(highestLocalRow),
00060             bcVec_(),
00061             internalVec_(),
00062             isBCRow_(isBCRow)
00063         {
00064           TEST_FOR_EXCEPTION(vec.space().numBlocks() != 2,
00065             std::runtime_error, "LoadableBlockVector expected numBlocks=2, "
00066             "found " << vec.space().numBlocks());
00067 
00068           internalVec_ = vec.getBlock(0);
00069           bcVec_ = vec.getBlock(1);
00070         }
00071 
00072 
00073       /** virtual dtor */
00074       virtual ~LoadableBlockVector() {;}
00075 
00076       /** set a single element at the given global index */
00077       void setElement(OrdType globalIndex, const double& value) 
00078         {
00079           if (globalIndex < lowestLocalRow_ || globalIndex >= highestLocalRow_)
00080           {
00081             int localRow = globalIndex-lowestLocalRow_;
00082             if ((*isBCRow_)[localRow])
00083             {
00084               bcVec_.setElement(globalIndex, value);
00085             }
00086             else
00087             {
00088               internalVec_.setElement(globalIndex, value);
00089             }
00090           }
00091         }
00092 
00093       /** add to the existing value of 
00094        * a single element at the given global index */
00095       void addToElement(OrdType globalIndex, const double& value) 
00096         {
00097           if (globalIndex >= lowestLocalRow_ && globalIndex < highestLocalRow_)
00098           {
00099             int localRow = globalIndex-lowestLocalRow_;
00100             if ((*isBCRow_)[localRow])
00101             {
00102               bcVec_.addToElement(globalIndex, value);
00103             }
00104             else
00105             {
00106               internalVec_.addToElement(globalIndex, value);
00107             }
00108           }
00109         }
00110 
00111       const Vector<double>& bcBlock() const {return bcVec_;}
00112       const Vector<double>& internalBlock() const {return internalVec_;}
00113       
00114     private:
00115       int lowestLocalRow_;
00116       int highestLocalRow_;
00117       Vector<double> bcVec_;
00118       Vector<double> internalVec_;
00119       RCP<Array<int> > isBCRow_;
00120   };
00121   
00122 }
00123 
00124 #endif /* DOXYGEN_DEVELOPER_ONLY */
00125 #endif

Site Contact