TSFBCPartitionedVSBuilder.hpp
Go to the documentation of this file.
00001 /* ***********************************************************************
00002 // 
00003 //           TSFExtended: Trilinos Solver Framework Extended
00004 //                 Copyright (2004) Sandia Corporation
00005 // 
00006 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00007 // license for use of this work by or on behalf of the U.S. Government.
00008 // 
00009 // This library is free software; you can redistribute it and/or modify
00010 // it under the terms of the GNU Lesser General Public License as
00011 // published by the Free Software Foundation; either version 2.1 of the
00012 // License, or (at your option) any later version.
00013 //  
00014 // This library is distributed in the hope that it will be useful, but
00015 // WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 //  
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022 // USA
00023 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00024 // 
00025 // **********************************************************************/
00026 
00027 #ifndef TSFBCPARTITIONEDVSBUILDER_HPP
00028 #define TSFBCPARTITIONEDVSBUILDER_HPP
00029 
00030 #include "TSFVectorSpaceImpl.hpp"
00031 #include "TSFVectorType.hpp"
00032 #include "Teuchos_Array.hpp"
00033 #include "TSFProductVectorSpaceImpl.hpp"
00034 
00035 namespace TSFExtended
00036 {
00037 using namespace Teuchos;
00038 
00039 /**
00040  * This helper function builds a product space in which BC and internal
00041  * rows are partitioned into physically distinct spaces
00042  */
00043 template <class Scalar>
00044   VectorSpace<Scalar> buildPartitionedSpace(
00045     int nTotalDofs,
00046     int lowestLocalDof,
00047     int nLocalDofs,
00048     const Array<int>& isBCIndex,
00049     const VectorType<Scalar>& internalType,
00050     const VectorType<Scalar>& bcType,
00051     const MPIComm& comm
00052     )
00053   {
00054     int nBCDofs = 0;
00055     for (int i=0; i<nLocalDofs; i++)
00056     {
00057       if (isBCIndex[i]) nBCDofs++;
00058     }
00059 
00060     /* sum number of BC Dofs over all processors */
00061     int nTotalBCDofs = nBCDofs;
00062     comm.allReduce(&nBCDofs, &nTotalBCDofs, 1, MPIComm::INT, MPIComm::SUM);
00063     int nTotalInteriorDofs = nTotalDofs - nTotalBCDofs;
00064 
00065 
00066     Array<int> interiorDofs(nLocalDofs - nBCDofs);
00067     Array<int> bcDofs(nBCDofs);
00068     int iBC = 0;
00069     int iIn = 0;
00070 
00071     for (int i=0; i<nLocalDofs; i++)
00072     {
00073       if (isBCIndex[i]) bcDofs[iBC++] = lowestLocalDof+i;
00074       else interiorDofs[iIn++] = lowestLocalDof+i;
00075     }
00076 
00077     int p = MPIComm::world().getRank();
00078 
00079 
00080     VectorSpace<double> bcSpace = bcType.createSpace(nTotalBCDofs, nBCDofs,
00081       &(bcDofs[0]), comm);
00082     VectorSpace<double> interiorSpace = internalType.createSpace(nTotalInteriorDofs, nLocalDofs-nBCDofs,
00083       &(interiorDofs[0]), comm);
00084 
00085     return productSpace<double>(interiorSpace, bcSpace);
00086   }
00087 
00088 }
00089 
00090 
00091 #endif

Site Contact