EpetraExt Development
EpetraExt_BlockUtility.cpp
Go to the documentation of this file.
00001 //@HEADER
00002 // ***********************************************************************
00003 //
00004 //     EpetraExt: Epetra Extended - Linear Algebra Services Package
00005 //                 Copyright (2011) Sandia Corporation
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 //@HEADER
00041 
00042 #include "EpetraExt_BlockUtility.h"
00043 #include "Epetra_Map.h"
00044 #include "Epetra_Comm.h"
00045 
00046 namespace EpetraExt {
00047 
00048 using std::vector;
00049 
00050 template<typename int_type>
00051 Epetra_Map * BlockUtility::TGenerateBlockMap(
00052         const Epetra_BlockMap & BaseMap,
00053         const int_type * RowIndices,
00054         int NumBlockRows,
00055         const Epetra_Comm & GlobalComm,
00056         int_type Offset)
00057 {
00058   int_type BaseIndex = (int_type) BaseMap.IndexBase64();
00059   if (Offset == 0)
00060     Offset = BlockUtility::TCalculateOffset<int_type>(BaseMap);
00061 
00062   //Get Base Global IDs
00063   int Size = BaseMap.NumMyElements();
00064   int TotalSize = NumBlockRows * Size;
00065   vector<int_type> GIDs(Size);
00066   BaseMap.MyGlobalElements( &GIDs[0] );
00067 
00068   vector<int_type> GlobalGIDs( TotalSize );
00069   for( int i = 0; i < NumBlockRows; ++i )
00070   {
00071     for( int j = 0; j < Size; ++j )
00072       GlobalGIDs[i*Size+j] = GIDs[j] + RowIndices[i] * Offset;
00073   }
00074 
00075   int_type GlobalSize;
00076   int_type TotalSize_int_type = TotalSize;
00077   GlobalComm.SumAll( &TotalSize_int_type, &GlobalSize, 1 );
00078 
00079   Epetra_Map *GlobalMap =
00080     new Epetra_Map( GlobalSize, TotalSize, &GlobalGIDs[0], BaseIndex,
00081                     GlobalComm );
00082 
00083   return GlobalMap;
00084 }
00085 
00086 //==============================================================================
00087 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00088 Epetra_Map * BlockUtility::GenerateBlockMap(
00089         const Epetra_BlockMap & BaseMap,
00090         const int * RowIndices,
00091         int NumBlockRows,
00092         const Epetra_Comm & GlobalComm,
00093         int Offset)
00094 {
00095   if(BaseMap.GlobalIndicesInt())
00096     return TGenerateBlockMap<int>(BaseMap, RowIndices, NumBlockRows, GlobalComm, Offset);
00097   else
00098     throw "EpetraExt::BlockUtility::GenerateBlockMap: Global Indices not int.";
00099 }
00100 #endif
00101 //==============================================================================
00102 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00103 Epetra_Map * BlockUtility::GenerateBlockMap(
00104         const Epetra_BlockMap & BaseMap,
00105         const long long * RowIndices,
00106         int NumBlockRows,
00107         const Epetra_Comm & GlobalComm,
00108         long long Offset)
00109 {
00110   if(BaseMap.GlobalIndicesLongLong())
00111     return TGenerateBlockMap<long long>(BaseMap, RowIndices, NumBlockRows, GlobalComm, Offset);
00112   else
00113     throw "EpetraExt::BlockUtility::GenerateBlockMap: Global Indices not long long.";
00114 }
00115 #endif
00116 //==============================================================================
00117 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00118 Epetra_Map * BlockUtility::GenerateBlockMap(
00119         const Epetra_BlockMap & BaseMap,
00120         const std::vector<int>& RowIndices,
00121         const Epetra_Comm & GlobalComm,
00122         int Offset )
00123 {
00124   return GenerateBlockMap(BaseMap, &RowIndices[0], RowIndices.size(),
00125                           GlobalComm, Offset);
00126 }
00127 #endif
00128 
00129 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00130 Epetra_Map * BlockUtility::GenerateBlockMap(
00131         const Epetra_BlockMap & BaseMap,
00132         const std::vector<long long>& RowIndices,
00133         const Epetra_Comm & GlobalComm,
00134         long long Offset )
00135 {
00136   return GenerateBlockMap(BaseMap, &RowIndices[0], RowIndices.size(),
00137                           GlobalComm, Offset);
00138 }
00139 #endif
00140 
00141 //==============================================================================
00142 Epetra_Map * BlockUtility::GenerateBlockMap(
00143         const Epetra_BlockMap & BaseMap,
00144         const Epetra_BlockMap& BlockMap,
00145         const Epetra_Comm & GlobalComm,
00146         int Offset)
00147 {
00148 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00149   if(BaseMap.GlobalIndicesInt() && BlockMap.GlobalIndicesInt())
00150     return GenerateBlockMap(BaseMap,
00151                           BlockMap.MyGlobalElements(),
00152                           BlockMap.NumMyElements(),
00153                           GlobalComm,
00154                           Offset);
00155   else
00156 #endif
00157 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00158     if(BaseMap.GlobalIndicesLongLong() && BlockMap.GlobalIndicesLongLong())
00159         return GenerateBlockMap(BaseMap,
00160                           BlockMap.MyGlobalElements64(),
00161                           BlockMap.NumMyElements(),
00162                           GlobalComm,
00163                           Offset);
00164   else
00165 #endif
00166     throw "EpetraExt::BlockUtility::GenerateBlockMap: Error Global Indices unknown.";
00167 }
00168 
00169 //==============================================================================
00170 template<typename int_type>
00171 Epetra_CrsGraph * BlockUtility::TGenerateBlockGraph(
00172         const Epetra_CrsGraph & BaseGraph,
00173         const vector< vector<int_type> > & RowStencil,
00174         const vector<int_type> & RowIndices,
00175         const Epetra_Comm & GlobalComm )
00176 {
00177 
00178   const Epetra_BlockMap & BaseMap = BaseGraph.RowMap();
00179   int_type BaseIndex = (int_type) BaseMap.IndexBase64();
00180   int_type Offset = BlockUtility::TCalculateOffset<int_type>(BaseMap);
00181 
00182   //Get Base Global IDs
00183   int NumBlockRows = RowIndices.size();
00184   int Size = BaseMap.NumMyElements();
00185   int TotalSize = NumBlockRows * Size;
00186   vector<int_type> GIDs(Size);
00187   BaseMap.MyGlobalElements( &GIDs[0] );
00188 
00189   vector<int_type> GlobalGIDs( TotalSize );
00190   for( int i = 0; i < NumBlockRows; ++i )
00191   {
00192     for( int j = 0; j < Size; ++j )
00193       GlobalGIDs[i*Size+j] = GIDs[j] + RowIndices[i] * Offset;
00194   }
00195 
00196   int_type GlobalSize;
00197   int_type TotalSize_int_type = TotalSize;
00198   GlobalComm.SumAll( &TotalSize_int_type, &GlobalSize, 1 );
00199 
00200   Epetra_Map GlobalMap( GlobalSize, TotalSize, &GlobalGIDs[0], BaseIndex, GlobalComm );
00201 
00202   int MaxIndices = BaseGraph.MaxNumIndices();
00203   vector<int_type> Indices(MaxIndices);
00204   int NumIndices;
00205 
00206   Epetra_CrsGraph * GlobalGraph = new Epetra_CrsGraph( Copy,
00207                                dynamic_cast<Epetra_BlockMap&>(GlobalMap),
00208                                0 );
00209 
00210   for( int i = 0; i < NumBlockRows; ++i )
00211   {
00212     int StencilSize = RowStencil[i].size();
00213     for( int j = 0; j < Size; ++j )
00214     {
00215       int_type BaseRow = (int_type) BaseMap.GID64(j);
00216       int_type GlobalRow = (int_type) GlobalMap.GID64(j+i*Size);
00217 
00218       BaseGraph.ExtractGlobalRowCopy( BaseRow, MaxIndices, NumIndices, &Indices[0] );
00219       for( int k = 0; k < StencilSize; ++k )
00220       {
00221         int_type ColOffset = (RowIndices[i]+RowStencil[i][k]) * Offset;
00222         if( k > 0 ) ColOffset -= (RowIndices[i]+RowStencil[i][k-1]) * Offset;
00223 
00224         for( int l = 0; l < NumIndices; ++l )
00225           Indices[l] += ColOffset;
00226 
00227         GlobalGraph->InsertGlobalIndices( GlobalRow, NumIndices, &Indices[0] );
00228       }
00229     }
00230   }
00231 
00232   GlobalGraph->FillComplete();
00233 
00234   return GlobalGraph;
00235 }
00236 
00237 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00238 Epetra_CrsGraph * BlockUtility::GenerateBlockGraph(
00239         const Epetra_CrsGraph & BaseGraph,
00240         const vector< vector<int> > & RowStencil,
00241         const vector<int> & RowIndices,
00242         const Epetra_Comm & GlobalComm )
00243 {
00244   if(BaseGraph.RowMap().GlobalIndicesInt())
00245     return TGenerateBlockGraph<int>(BaseGraph, RowStencil, RowIndices, GlobalComm);
00246   else
00247     throw "EpetraExt::BlockUtility::GenerateBlockGraph: Error Global Indices not int.";
00248 }
00249 #endif
00250 
00251 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00252 Epetra_CrsGraph * BlockUtility::GenerateBlockGraph(
00253         const Epetra_CrsGraph & BaseGraph,
00254         const vector< vector<long long> > & RowStencil,
00255         const vector<long long> & RowIndices,
00256         const Epetra_Comm & GlobalComm )
00257 {
00258   if(BaseGraph.RowMap().GlobalIndicesLongLong())
00259     return TGenerateBlockGraph<long long>(BaseGraph, RowStencil, RowIndices, GlobalComm);
00260   else
00261     throw "EpetraExt::BlockUtility::GenerateBlockGraph: Error Global Indices not long long.";
00262 }
00263 #endif
00264 
00265 //==============================================================================
00266 template<typename int_type>
00267 Epetra_CrsGraph * BlockUtility::TGenerateBlockGraph(
00268         const Epetra_RowMatrix & BaseMatrix,
00269         const vector< vector<int_type> > & RowStencil,
00270         const vector<int_type> & RowIndices,
00271         const Epetra_Comm & GlobalComm )
00272 {
00273 
00274   const Epetra_BlockMap & BaseMap = BaseMatrix.RowMatrixRowMap();
00275   const Epetra_BlockMap & BaseColMap = BaseMatrix.RowMatrixColMap();
00276   int_type BaseIndex = (int_type) BaseMap.IndexBase64();
00277   int_type Offset = BlockUtility::TCalculateOffset<int_type>(BaseMap);
00278 
00279   //Get Base Global IDs
00280   int NumBlockRows = RowIndices.size();
00281   int Size = BaseMap.NumMyElements();
00282   int TotalSize = NumBlockRows * Size;
00283   vector<int_type> GIDs(Size);
00284   BaseMap.MyGlobalElements( &GIDs[0] );
00285 
00286   vector<int_type> GlobalGIDs( TotalSize );
00287   for( int i = 0; i < NumBlockRows; ++i )
00288   {
00289     for( int j = 0; j < Size; ++j )
00290       GlobalGIDs[i*Size+j] = GIDs[j] + RowIndices[i] * Offset;
00291   }
00292 
00293   int_type GlobalSize;
00294   int_type TotalSize_int_type = TotalSize;
00295   GlobalComm.SumAll( &TotalSize_int_type, &GlobalSize, 1 );
00296 
00297   Epetra_Map GlobalMap( GlobalSize, TotalSize, &GlobalGIDs[0], BaseIndex, GlobalComm );
00298 
00299   int MaxIndices = BaseMatrix.MaxNumEntries();
00300   vector<int> Indices_local(MaxIndices);
00301   vector<int_type> Indices_global(MaxIndices);
00302   vector<double> Values(MaxIndices);
00303   int NumIndices;
00304 
00305   Epetra_CrsGraph * GlobalGraph = new Epetra_CrsGraph( Copy,
00306                                dynamic_cast<Epetra_BlockMap&>(GlobalMap),
00307                                0 );
00308 
00309   for( int i = 0; i < NumBlockRows; ++i )
00310   {
00311     int StencilSize = RowStencil[i].size();
00312     for( int j = 0; j < Size; ++j )
00313     {
00314       int_type GlobalRow = (int_type) GlobalMap.GID64(j+i*Size);
00315 
00316       BaseMatrix.ExtractMyRowCopy( j, MaxIndices, NumIndices, &Values[0], &Indices_local[0] );
00317       for( int l = 0; l < NumIndices; ++l ) Indices_global[l] = (int_type) BaseColMap.GID64(Indices_local[l]);
00318 
00319       for( int k = 0; k < StencilSize; ++k )
00320       {
00321         int_type ColOffset = (RowIndices[i]+RowStencil[i][k]) * Offset;
00322         if( k > 0 ) ColOffset -= (RowIndices[i]+RowStencil[i][k-1]) * Offset;
00323 
00324         for( int l = 0; l < NumIndices; ++l )
00325           Indices_global[l] += ColOffset;
00326 
00327         GlobalGraph->InsertGlobalIndices( GlobalRow, NumIndices, &Indices_global[0] );
00328       }
00329     }
00330   }
00331 
00332   GlobalGraph->FillComplete();
00333 
00334   return GlobalGraph;
00335 }
00336 
00337 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00338 Epetra_CrsGraph * BlockUtility::GenerateBlockGraph(
00339         const Epetra_RowMatrix & BaseMatrix,
00340         const vector< vector<int> > & RowStencil,
00341         const vector<int> & RowIndices,
00342         const Epetra_Comm & GlobalComm )
00343 {
00344   if(BaseMatrix.RowMatrixRowMap().GlobalIndicesInt())
00345     return TGenerateBlockGraph<int>(BaseMatrix, RowStencil, RowIndices, GlobalComm);
00346   else
00347     throw "EpetraExt::BlockUtility::GenerateBlockGraph: Error Global Indices not int.";
00348 }
00349 #endif
00350 
00351 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00352 Epetra_CrsGraph * BlockUtility::GenerateBlockGraph(
00353         const Epetra_RowMatrix & BaseMatrix,
00354         const vector< vector<long long> > & RowStencil,
00355         const vector<long long> & RowIndices,
00356         const Epetra_Comm & GlobalComm )
00357 {
00358   if(BaseMatrix.RowMatrixRowMap().GlobalIndicesLongLong())
00359     return TGenerateBlockGraph<long long>(BaseMatrix, RowStencil, RowIndices, GlobalComm);
00360   else
00361     throw "EpetraExt::BlockUtility::GenerateBlockGraph: Error Global Indices not long long.";
00362 }
00363 #endif
00364 
00365 //==============================================================================
00366 template<typename int_type>
00367 Epetra_CrsGraph * BlockUtility::TGenerateBlockGraph(
00368         const Epetra_CrsGraph & BaseGraph,
00369         const Epetra_CrsGraph & LocalBlockGraph,
00370         const Epetra_Comm & GlobalComm )
00371 {
00372   const Epetra_BlockMap & BaseRowMap = BaseGraph.RowMap();
00373   const Epetra_BlockMap & BaseColMap = BaseGraph.ColMap();
00374   int_type ROffset = BlockUtility::TCalculateOffset<int_type>(BaseRowMap);
00375   (void) ROffset; // Silence "unused variable" compiler warning.
00376   int_type COffset = BlockUtility::TCalculateOffset<int_type>(BaseColMap);
00377 
00378   //Get Base Global IDs
00379   const Epetra_BlockMap & BlockRowMap = LocalBlockGraph.RowMap();
00380   const Epetra_BlockMap & BlockColMap = LocalBlockGraph.ColMap();
00381 
00382   int NumBlockRows = BlockRowMap.NumMyElements();
00383   vector<int_type> RowIndices(NumBlockRows);
00384   BlockRowMap.MyGlobalElements(&RowIndices[0]);
00385 
00386   int Size = BaseRowMap.NumMyElements();
00387 
00388   Epetra_Map *GlobalRowMap =
00389     GenerateBlockMap(BaseRowMap, BlockRowMap, GlobalComm);
00390 
00391 
00392   int MaxIndices = BaseGraph.MaxNumIndices();
00393   vector<int_type> Indices(MaxIndices);
00394 
00395   Epetra_CrsGraph * GlobalGraph = new Epetra_CrsGraph( Copy,
00396                                dynamic_cast<Epetra_BlockMap&>(*GlobalRowMap),
00397                                0 );
00398 
00399   int NumBlockIndices, NumBaseIndices;
00400   int *BlockIndices, *BaseIndices;
00401   for( int i = 0; i < NumBlockRows; ++i )
00402   {
00403     LocalBlockGraph.ExtractMyRowView(i, NumBlockIndices, BlockIndices);
00404 
00405     for( int j = 0; j < Size; ++j )
00406     {
00407       int_type GlobalRow = (int_type) GlobalRowMap->GID64(j+i*Size);
00408 
00409       BaseGraph.ExtractMyRowView( j, NumBaseIndices, BaseIndices );
00410       for( int k = 0; k < NumBlockIndices; ++k )
00411       {
00412         int_type ColOffset = (int_type) BlockColMap.GID64(BlockIndices[k]) * COffset;
00413 
00414         for( int l = 0; l < NumBaseIndices; ++l )
00415           Indices[l] = (int_type) BaseGraph.GCID64(BaseIndices[l]) + ColOffset;
00416 
00417         GlobalGraph->InsertGlobalIndices( GlobalRow, NumBaseIndices, &Indices[0] );
00418       }
00419     }
00420   }
00421 
00422   const Epetra_BlockMap & BaseDomainMap = BaseGraph.DomainMap();
00423   const Epetra_BlockMap & BaseRangeMap = BaseGraph.RangeMap();
00424   const Epetra_BlockMap & BlockDomainMap = LocalBlockGraph.DomainMap();
00425   const Epetra_BlockMap & BlockRangeMap = LocalBlockGraph.RangeMap();
00426 
00427   Epetra_Map *GlobalDomainMap =
00428     GenerateBlockMap(BaseDomainMap, BlockDomainMap, GlobalComm);
00429   Epetra_Map *GlobalRangeMap =
00430     GenerateBlockMap(BaseRangeMap, BlockRangeMap, GlobalComm);
00431 
00432   GlobalGraph->FillComplete(*GlobalDomainMap, *GlobalRangeMap);
00433 
00434   delete GlobalDomainMap;
00435   delete GlobalRangeMap;
00436   delete GlobalRowMap;
00437 
00438   return GlobalGraph;
00439 }
00440 
00441 Epetra_CrsGraph * BlockUtility::GenerateBlockGraph(
00442         const Epetra_CrsGraph & BaseGraph,
00443         const Epetra_CrsGraph & LocalBlockGraph,
00444         const Epetra_Comm & GlobalComm )
00445 {
00446 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00447   if(BaseGraph.RowMap().GlobalIndicesInt() && LocalBlockGraph.RowMap().GlobalIndicesInt())
00448     return TGenerateBlockGraph<int>(BaseGraph, LocalBlockGraph, GlobalComm);
00449   else
00450 #endif
00451 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00452     if(BaseGraph.RowMap().GlobalIndicesLongLong() && LocalBlockGraph.RowMap().GlobalIndicesLongLong())
00453       return TGenerateBlockGraph<long long>(BaseGraph, LocalBlockGraph, GlobalComm);
00454   else
00455 #endif
00456     throw "EpetraExt::BlockUtility::GenerateBlockGraph: Error Global Indices unknown.";
00457 }
00458 
00459 //==============================================================================
00460 template<typename int_type>
00461 void BlockUtility::TGenerateRowStencil(const Epetra_CrsGraph& LocalBlockGraph,
00462                                       std::vector<int_type> RowIndices,
00463                                       std::vector< std::vector<int_type> >& RowStencil)
00464 {
00465   // Get row indices
00466   int NumMyRows = LocalBlockGraph.NumMyRows();
00467   RowIndices.resize(NumMyRows);
00468   const Epetra_BlockMap& RowMap = LocalBlockGraph.RowMap();
00469   RowMap.MyGlobalElements(&RowIndices[0]);
00470 
00471   // Get stencil
00472   RowStencil.resize(NumMyRows);
00473   if (LocalBlockGraph.IndicesAreGlobal()) {
00474     for (int i=0; i<NumMyRows; i++) {
00475       int_type Row = RowIndices[i];
00476       int NumCols = LocalBlockGraph.NumGlobalIndices(Row);
00477       RowStencil[i].resize(NumCols);
00478       LocalBlockGraph.ExtractGlobalRowCopy(Row, NumCols, NumCols,
00479                                            &RowStencil[i][0]);
00480       for (int k=0; k<NumCols; k++)
00481         RowStencil[i][k] -= Row;
00482     }
00483   }
00484   else {
00485     for (int i=0; i<NumMyRows; i++) {
00486       int NumCols = LocalBlockGraph.NumMyIndices(i);
00487     std::vector<int> RowStencil_local(NumCols);
00488       RowStencil[i].resize(NumCols);
00489       LocalBlockGraph.ExtractMyRowCopy(i, NumCols, NumCols,
00490                                        &RowStencil_local[0]);
00491       for (int k=0; k<NumCols; k++)
00492         RowStencil[i][k] = (int_type) ((int) (LocalBlockGraph.GCID64(RowStencil_local[k]) - RowIndices[i]));
00493     }
00494   }
00495 }
00496 
00497 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00498 void BlockUtility::GenerateRowStencil(const Epetra_CrsGraph& LocalBlockGraph,
00499                                       std::vector<int> RowIndices,
00500                                       std::vector< std::vector<int> >& RowStencil)
00501 {
00502   if(LocalBlockGraph.RowMap().GlobalIndicesInt())
00503     BlockUtility::TGenerateRowStencil<int>(LocalBlockGraph, RowIndices, RowStencil);
00504   else
00505     throw "EpetraExt::BlockUtility::GenerateRowStencil: Global Indices not int.";
00506 }
00507 #endif
00508 
00509 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00510 void BlockUtility::GenerateRowStencil(const Epetra_CrsGraph& LocalBlockGraph,
00511                                       std::vector<long long> RowIndices,
00512                                       std::vector< std::vector<long long> >& RowStencil)
00513 {
00514   if(LocalBlockGraph.RowMap().GlobalIndicesLongLong())
00515     BlockUtility::TGenerateRowStencil<long long>(LocalBlockGraph, RowIndices, RowStencil);
00516   else
00517     throw "EpetraExt::BlockUtility::GenerateRowStencil: Global Indices not long long.";
00518 }
00519 #endif
00520 
00521 
00522 //==============================================================================
00523 template<typename int_type>
00524 int_type BlockUtility::TCalculateOffset(const Epetra_BlockMap & BaseMap)
00525 {
00526   int_type MaxGID = (int_type) BaseMap.MaxAllGID64();
00527 
00528 //   int Offset = 1;
00529 //   while( Offset <= MaxGID ) Offset *= 10;
00530 
00531 //   return Offset;
00532 
00533   return MaxGID+1;
00534 }
00535 
00536 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00537 int BlockUtility::CalculateOffset(const Epetra_BlockMap & BaseMap)
00538 {
00539   if(BaseMap.GlobalIndicesInt())
00540     return TCalculateOffset<int>(BaseMap);
00541   else
00542     throw "EpetraExt::BlockUtility::GenerateBlockMap: Global Indices not int.";
00543 }
00544 #endif
00545 
00546 long long BlockUtility::CalculateOffset64(const Epetra_BlockMap & BaseMap)
00547 {
00548   return TCalculateOffset<long long>(BaseMap);
00549 }
00550 
00551 } //namespace EpetraExt
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines