TSFPartitionedToMonolithicConverter.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 TSFPARTITIONED_TO_MONOLITHIC_CONVERTER_HPP
00030 #define TSFPARTITIONED_TO_MONOLITHIC_CONVERTER_HPP
00031 
00032 #include "TSFVectorSpaceImpl.hpp"
00033 #include "TSFVectorImpl.hpp"
00034 #include "TSFVectorType.hpp"
00035 #include <set>
00036 
00037 namespace TSFExtended
00038 {
00039   using namespace Teuchos;
00040   using namespace Thyra;
00041 
00042   /** */
00043   class PartitionedToMonolithicConverter
00044   {
00045   public:
00046 
00047     /**  */
00048     PartitionedToMonolithicConverter(
00049       const VectorSpace<double>& partitionedSpace,
00050       const RCP<Array<int> >& isBCCol,
00051       const VectorSpace<double>& monolithicSpace
00052       ) : partitionedSpace_(partitionedSpace),
00053           monolithicSpace_(monolithicSpace),
00054           indices_(2)
00055       {
00056         int n = monolithicSpace.numLocalElements();
00057         int low = monolithicSpace.lowestLocallyOwnedIndex();
00058 
00059         indices_[0].reserve(n);
00060         indices_[1].reserve(n);
00061 
00062         const Array<int>& bc = *isBCCol;
00063 
00064         for (int i=0; i<n; i++)
00065         {
00066           indices_[bc[i]].append(low+i);
00067         }
00068       }
00069 
00070     /** */
00071     void convert(
00072       const Vector<double>& in,
00073       Vector<double>& out) const 
00074       {
00075         TEST_FOR_EXCEPTION(in.space().numBlocks() != 2, std::runtime_error,
00076           "PartitionedToMonolithicConverter::convert() expects 2 blocks "
00077           "in input vector. Input vector has numBlocks()="
00078           << in.space().numBlocks());
00079         Array<Vector<double> > x(2);
00080         x[0] = in.getBlock(0);
00081         x[1] = in.getBlock(1);
00082 
00083         cout << "index array=" << indices_ << std::endl;
00084 
00085         for (int b=0; b<2; b++)
00086         {
00087           VectorSpace<double> space = x[b].space();
00088           int j=0;
00089           for (SequentialIterator<double> i=space.begin(); i!=space.end(); i++,j++)
00090           {
00091             double val = x[b][i];
00092             int globalIndex = indices_[b][j];
00093             out.setElement(globalIndex, val);
00094           }
00095         }
00096       }
00097 
00098   protected:
00099 
00100   private:
00101     VectorSpace<double> partitionedSpace_;
00102     VectorSpace<double> monolithicSpace_;
00103     Array<Array<int> > indices_;
00104   };
00105 }
00106 
00107 
00108 #endif

Site Contact