EpetraExt Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EpetraExt_BlockUtility.h
Go to the documentation of this file.
1 //@HEADER
2 // ***********************************************************************
3 //
4 // EpetraExt: Epetra Extended - Linear Algebra Services Package
5 // Copyright (2011) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 
42 #ifndef EPETRAEXT_BLOCKUTILITY_H
43 #define EPETRAEXT_BLOCKUTILITY_H
44 
45 #include <vector>
46 
47 #include <Epetra_ConfigDefs.h>
48 #include <Epetra_CrsGraph.h>
49 #include <Epetra_RowMatrix.h>
50 
52 
53 namespace EpetraExt {
54 
55 class BlockUtility {
56  public:
57 
65 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
66  static Epetra_Map * GenerateBlockMap( const Epetra_BlockMap & BaseMap, const int* RowIndices, int num_indices, const Epetra_Comm & GlobalComm, int Offset = 0 );
67 #endif
68 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
69  static Epetra_Map * GenerateBlockMap( const Epetra_BlockMap & BaseMap, const long long* RowIndices, int num_indices, const Epetra_Comm & GlobalComm, long long Offset = 0 );
70 #endif
71 
79 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
80  static Epetra_Map * GenerateBlockMap( const Epetra_BlockMap & BaseMap, const std::vector<int> & RowIndices, const Epetra_Comm & GlobalComm, int Offset = 0 );
81 #endif
82 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
83  static Epetra_Map * GenerateBlockMap( const Epetra_BlockMap & BaseMap, const std::vector<long long> & RowIndices, const Epetra_Comm & GlobalComm, long long Offset = 0 );
84 #endif
85 
93  static Epetra_Map * GenerateBlockMap( const Epetra_BlockMap & BaseMap, const Epetra_BlockMap& BlockMap, const Epetra_Comm & GlobalComm, int Offset = 0 );
94 
96 
105 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
106  static Epetra_CrsGraph * GenerateBlockGraph( const Epetra_CrsGraph & BaseGraph, const std::vector< std::vector<int> > & RowStencil, const std::vector<int> & RowIndices, const Epetra_Comm & GlobalComm );
107 #endif
108 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
109  static Epetra_CrsGraph * GenerateBlockGraph( const Epetra_CrsGraph & BaseGraph, const std::vector< std::vector<long long> > & RowStencil, const std::vector<long long> & RowIndices, const Epetra_Comm & GlobalComm );
110 #endif
111 
112  // Nearly identical version yet using RowMatrix interface instead of CrsGraph
113 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
114  static Epetra_CrsGraph * GenerateBlockGraph( const Epetra_RowMatrix & BaseMatrix, const std::vector< std::vector<int> > & RowStencil, const std::vector<int> & RowIndices, const Epetra_Comm & GlobalComm );
115 #endif
116 
117 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
118  static Epetra_CrsGraph * GenerateBlockGraph( const Epetra_RowMatrix & BaseMatrix, const std::vector< std::vector<long long> > & RowStencil, const std::vector<long long> & RowIndices, const Epetra_Comm & GlobalComm );
119 #endif
120 
122  static Epetra_CrsGraph * GenerateBlockGraph( const Epetra_CrsGraph & BaseGraph, const Epetra_CrsGraph& LocalBlockGraph, const Epetra_Comm & GlobalComm );
123 
125 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
126  static void GenerateRowStencil(const Epetra_CrsGraph& LocalBlockGraph, std::vector<int> RowIndices, std::vector< std::vector<int> >& RowStencil);
127 #endif
128 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
129  static void GenerateRowStencil(const Epetra_CrsGraph& LocalBlockGraph, std::vector<long long> RowIndices, std::vector< std::vector<long long> >& RowStencil);
130 #endif
131 
133 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
134  static int CalculateOffset(const Epetra_BlockMap & BaseMap);
135 #endif
136 
137  static long long CalculateOffset64(const Epetra_BlockMap & BaseMap);
138 
139 private:
140 
141  template<typename int_type>
142  static int_type TCalculateOffset(const Epetra_BlockMap & BaseMap);
143 
144  template<typename int_type>
145  static Epetra_Map * TGenerateBlockMap( const Epetra_BlockMap & BaseMap, const int_type* RowIndices, int num_indices, const Epetra_Comm & GlobalComm, int_type Offset = 0);
146 
147  template<typename int_type>
148  static Epetra_CrsGraph * TGenerateBlockGraph( const Epetra_CrsGraph & BaseGraph, const std::vector< std::vector<int_type> > & RowStencil, const std::vector<int_type> & RowIndices, const Epetra_Comm & GlobalComm );
149 
150  template<typename int_type>
151  static Epetra_CrsGraph * TGenerateBlockGraph( const Epetra_RowMatrix & BaseMatrix, const std::vector< std::vector<int_type> > & RowStencil, const std::vector<int_type> & RowIndices, const Epetra_Comm & GlobalComm );
152 
153  template<typename int_type>
154  static Epetra_CrsGraph * TGenerateBlockGraph( const Epetra_CrsGraph & BaseGraph, const Epetra_CrsGraph& LocalBlockGraph, const Epetra_Comm & GlobalComm );
155 
156  template<typename int_type>
157  static void TGenerateRowStencil(const Epetra_CrsGraph& LocalBlockGraph, std::vector<int_type> RowIndices, std::vector< std::vector<int_type> >& RowStencil);
158 };
159 
160 } //namespace EpetraExt
161 
162 #endif /* EPETRA_CRSMATRIX_H */
static Epetra_CrsGraph * TGenerateBlockGraph(const Epetra_CrsGraph &BaseGraph, const std::vector< std::vector< int_type > > &RowStencil, const std::vector< int_type > &RowIndices, const Epetra_Comm &GlobalComm)
static void GenerateRowStencil(const Epetra_CrsGraph &LocalBlockGraph, std::vector< int > RowIndices, std::vector< std::vector< int > > &RowStencil)
Generate stencil arrays from a local block graph.
static long long CalculateOffset64(const Epetra_BlockMap &BaseMap)
static Epetra_Map * TGenerateBlockMap(const Epetra_BlockMap &BaseMap, const int_type *RowIndices, int num_indices, const Epetra_Comm &GlobalComm, int_type Offset=0)
static int CalculateOffset(const Epetra_BlockMap &BaseMap)
Routine for calculating Offset for creating unique global IDs for Block representation.
static int_type TCalculateOffset(const Epetra_BlockMap &BaseMap)
static Epetra_Map * GenerateBlockMap(const Epetra_BlockMap &BaseMap, const int *RowIndices, int num_indices, const Epetra_Comm &GlobalComm, int Offset=0)
static void TGenerateRowStencil(const Epetra_CrsGraph &LocalBlockGraph, std::vector< int_type > RowIndices, std::vector< std::vector< int_type > > &RowStencil)
static Epetra_CrsGraph * GenerateBlockGraph(const Epetra_CrsGraph &BaseGraph, const std::vector< std::vector< int > > &RowStencil, const std::vector< int > &RowIndices, const Epetra_Comm &GlobalComm)
BlockCrsMatrix constuctor.