FEApp_BlockDiscretization.cpp

Go to the documentation of this file.
00001 // $Id: FEApp_BlockDiscretization.cpp,v 1.4 2008/08/01 22:57:12 etphipp Exp $ 
00002 // $Source: /space/CVS/Trilinos/packages/sacado/example/FEApp/FEApp_BlockDiscretization.cpp,v $ 
00003 // @HEADER
00004 // ***********************************************************************
00005 // 
00006 //                           Sacado Package
00007 //                 Copyright (2006) Sandia Corporation
00008 // 
00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00010 // the U.S. Government retains certain rights in this software.
00011 // 
00012 // This library is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU Lesser General Public License as
00014 // published by the Free Software Foundation; either version 2.1 of the
00015 // License, or (at your option) any later version.
00016 //  
00017 // This library is distributed in the hope that it will be useful, but
00018 // WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 // Lesser General Public License for more details.
00021 //  
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License along with this library; if not, write to the Free Software
00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 // USA
00026 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
00027 // (etphipp@sandia.gov).
00028 // 
00029 // ***********************************************************************
00030 // @HEADER
00031 #include "Epetra_Export.h"
00032 
00033 #include "FEApp_BlockDiscretization.hpp"
00034 
00035 #ifdef HAVE_MPI
00036 #include "EpetraExt_MultiMpiComm.h"
00037 #endif
00038 
00039 #if SG_ACTIVE
00040 
00041 FEApp::BlockDiscretization::BlockDiscretization(
00042     const Teuchos::RCP<const Epetra_Comm>& comm,
00043     const Teuchos::RCP<const FEApp::AbstractDiscretization>& underlyingDisc_,
00044     const Teuchos::RCP<const Stokhos::OrthogPolyBasis<double> >& sg_basis_,
00045      bool makeJacobian) :
00046   underlyingDisc(underlyingDisc_),
00047   sg_basis(sg_basis_)
00048 {
00049 
00050 #ifdef HAVE_MPI
00051   // No parallelism over blocks, so spatial partition is unchanged 
00052   // as comm->NumProc()
00053   unsigned int num_sg_blocks = sg_basis->size();
00054   Teuchos::RCP<EpetraExt::MultiMpiComm> multiComm =
00055     Teuchos::rcp(new EpetraExt::MultiMpiComm(MPI_COMM_WORLD, 
00056                comm->NumProc(), 
00057                num_sg_blocks));
00058 
00059   // Create block matrix and graph from underlyingDisc and
00060   // the block information stored in globalComm
00061 
00062   int numBlockRows =  multiComm->NumTimeSteps();
00063   int myBlockRows  =  multiComm->NumTimeStepsOnDomain();
00064   int myFirstBlockRow = multiComm->FirstTimeStepOnDomain();
00065   globalComm = multiComm;
00066 #else
00067   int numBlockRows =  1;
00068   int myBlockRows  =  1;
00069   int myFirstBlockRow = 0;
00070   globalComm = comm;
00071 #endif
00072 
00073   // DENSE STENCIL for Stochastic Galerkin
00074   // For 3 blocks on 2 procs, this should be:
00075   // Proc  nBR  mBR  mFBR     Stencil      Index
00076   //  0     3    2    0       0  1  2        0
00077   //                         -1  0  1        1
00078   //  1     3    1    2      -2 -1  0        2
00079   //
00080    std::vector< std::vector<int> > rowStencil(myBlockRows);
00081    std::vector<int> rowIndex(myBlockRows);
00082    for (int i=0; i < myBlockRows; i++) {
00083      for (int j=0; j < numBlockRows; j++) 
00084        rowStencil[i].push_back(-myFirstBlockRow - i + j);
00085      rowIndex[i] = (i + myFirstBlockRow);
00086    }
00087 
00088    if (makeJacobian) {
00089      //Construct BlockGraphs from underlying graphs and stencils
00090      jac = Teuchos::rcp(new EpetraExt::BlockCrsMatrix(
00091           *(underlyingDisc->getJacobianGraph()),
00092           rowStencil, rowIndex, *globalComm));
00093      overlap_jac = Teuchos::rcp(new EpetraExt::BlockCrsMatrix(
00094           *(underlyingDisc->getOverlapJacobianGraph()),
00095           rowStencil, rowIndex, *globalComm));
00096      graph = Teuchos::rcp(&(jac->Graph()),false);
00097      overlap_graph = Teuchos::rcp(&(overlap_jac->Graph()),false);
00098      map = Teuchos::rcp(&(jac->RowMatrixRowMap()),false);
00099      overlap_map = Teuchos::rcp(&(overlap_jac->RowMatrixRowMap()),false);
00100    }
00101    else {
00102      map = Teuchos::rcp(EpetraExt::BlockUtility::GenerateBlockMap(
00103               *(underlyingDisc->getMap()),
00104               rowIndex,
00105               *globalComm));
00106      overlap_map = Teuchos::rcp(EpetraExt::BlockUtility::GenerateBlockMap(
00107               *(underlyingDisc->getOverlapMap()),
00108               rowIndex,
00109               *globalComm));
00110    }
00111 }
00112 
00113 FEApp::BlockDiscretization::~BlockDiscretization()
00114 {
00115 }
00116 
00117 void
00118 FEApp::BlockDiscretization::createMesh()
00119 {
00120   // Done in underlying Discretization
00121 }
00122 
00123 void
00124 FEApp::BlockDiscretization::createMaps()
00125 {
00126   // Done in constructor
00127 }
00128 
00129 void
00130 FEApp::BlockDiscretization::createJacobianGraphs()
00131 {
00132   // Done in constructor
00133 }
00134       
00135 Teuchos::RCP<const FEApp::Mesh>
00136 FEApp::BlockDiscretization::getMesh() const
00137 {
00138   return underlyingDisc->getMesh();
00139 }
00140 
00141 Teuchos::RCP<const Epetra_Map>
00142 FEApp::BlockDiscretization::getMap() const
00143 {
00144   return map;
00145 }
00146 
00147 Teuchos::RCP<const Epetra_Map>
00148 FEApp::BlockDiscretization::getOverlapMap() const
00149 {
00150   return overlap_map;
00151 }
00152 
00153 Teuchos::RCP<const Epetra_CrsGraph>
00154 FEApp::BlockDiscretization::getJacobianGraph() const
00155 {
00156   return graph;
00157 }
00158 
00159 Teuchos::RCP<const Epetra_CrsGraph>
00160 FEApp::BlockDiscretization::getOverlapJacobianGraph() const
00161 {
00162   return overlap_graph;
00163 }
00164 
00165 int
00166 FEApp::BlockDiscretization::getNumNodesPerElement() const
00167 {
00168   return underlyingDisc->getNumNodesPerElement();
00169 }
00170 
00171 Teuchos::RCP<EpetraExt::BlockCrsMatrix> 
00172 FEApp::BlockDiscretization::getJacobian()
00173 {
00174   return jac;
00175 }
00176 
00177 Teuchos::RCP<EpetraExt::BlockCrsMatrix> 
00178 FEApp::BlockDiscretization::getOverlapJacobian()
00179 {
00180   return overlap_jac;
00181 }
00182 
00183 #endif // SG_ACTIVE

Generated on Wed May 12 21:59:03 2010 for Sacado Package Browser (Single Doxygen Collection) by  doxygen 1.4.7