41 #ifndef EpetraExt_PERMUTATION_IMPL_H 
   42 #define EpetraExt_PERMUTATION_IMPL_H 
   48 #include <Epetra_Export.h> 
   49 #include <Epetra_Map.h> 
   50 #include <Epetra_Comm.h> 
   51 #include <Epetra_MultiVector.h> 
   52 #include <Epetra_CrsGraph.h> 
   53 #include <Epetra_CrsMatrix.h> 
   54 #include <Epetra_GIDTypeVector.h> 
   80   { 
static const char name[] = 
"unknown"; 
return( name ); }
 
   99   { std::cerr << 
"not implemented for unknown type"<<std::endl; }
 
  102   template<
typename int_type>
 
  106   { std::cerr << 
"not implemented for unknown type"<<std::endl; }
 
  120   { 
static const char name[] = 
"Epetra_CrsMatrix"; 
return( name ); }
 
  137     if (pointmap == NULL) {
 
  138       std::cerr << 
"dynamic_cast<const Epetra_Map*> failed."<<std::endl;
 
  151   template<
typename int_type>
 
  165     colperm->PutValue(0);
 
  168     colperm->Export(*perm, p_exporter, 
Add);
 
  172     int_type* myGlobalRows = 0;
 
  173     origRowMap.MyGlobalElementsPtr(myGlobalRows);
 
  179     for(
int i=0; i<numMyRows; ++i) {
 
  180       int_type globalRow = myGlobalRows[i];
 
  184       double* src_values = 
new double[len];
 
  185       int_type* src_indices = 
new int_type[len];
 
  187                src_values, src_indices);
 
  188       if (err < 0 || numIndices != len) {
 
  189   std::cerr<<
"Perm_traits<CrsMatrix>::produceColumnPermutation err("<<err<<
") row " 
  190       <<globalRow<<
", len "<<len<<
", numIndices "<<numIndices<<std::endl;
 
  193       int_type* pindices = 
new int_type[len];
 
  196       int_type* p = colperm->Values();
 
  198       for(
int j=0; j<len; ++j) {
 
  199   int_type old_col = src_indices[j];
 
  201   int lid = pmap.
LID(old_col);
 
  203     std::cerr << 
"Perm_traits<CrsMatrix>::permuteColumnIndices GID("<<old_col
 
  204          <<
") not found"<<std::endl;
 
  208   pindices[j] = p[lid];
 
  213   std::cerr << 
"Perm_traits<CrsMatrix>::permuteColumnIndices err("<<err
 
  214        <<
") row "<<globalRow<<std::endl;
 
  218       delete [] src_indices;
 
  219       delete [] src_values;
 
  229 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 
  235     return TproduceColumnPermutation<int>(perm, srcObj);
 
  239 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 
  245     return TproduceColumnPermutation<long long>(perm, srcObj);
 
  260   { 
static const char name[] = 
"Epetra_CrsGraph"; 
return( name ); }
 
  281   template<
typename int_type>
 
  295     colperm->PutValue(0);
 
  298     colperm->Export(*perm, p_exporter, 
Add);
 
  302     int_type* myGlobalRows = 0;
 
  303     origRowMap.MyGlobalElementsPtr(myGlobalRows);
 
  309     for(
int i=0; i<numMyRows; ++i) {
 
  310       int_type globalRow = myGlobalRows[i];
 
  314       int_type* src_indices = 
new int_type[len];
 
  316       if (err < 0 || numIndices != len) {
 
  317   std::cerr<<
"Perm_traits<CrsGraph>::produceColumnPermutation err("<<err<<
") row " 
  318     <<globalRow<<
", len "<<len<<
", numIndices "<<numIndices<<std::endl;
 
  321       int_type* pindices = 
new int_type[len];
 
  324       int_type* p = colperm->Values();
 
  326       for(
int j=0; j<len; ++j) {
 
  327   int_type old_col = src_indices[j];
 
  329   int lid = pmap.
LID(old_col);
 
  331     std::cerr << 
"Perm_traits<CrsGraph>::permuteColumnIndices GID("<<old_col
 
  332          <<
") not found"<<std::endl;
 
  336   pindices[j] = p[lid];
 
  341   std::cerr << 
"Perm_traits<CrsGraph>::produceColumnPermutation err("<<err
 
  342        <<
") row "<<globalRow<<std::endl;
 
  346       delete [] src_indices;
 
  356 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 
  362     return TproduceColumnPermutation<int>(perm, srcObj);
 
  366 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 
  372     return TproduceColumnPermutation<long long>(perm, srcObj);
 
  386   { 
static const char name[] = 
"Epetra_MultiVector"; 
return( name ); }
 
  401   { mvec->ReplaceMap(map); }
 
  403 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 
  409     std::cerr << 
"col-permutation not implemented for Epetra_MultiVector"<<std::endl;
 
  413 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 
  419     std::cerr << 
"col-permutation not implemented for Epetra_MultiVector"<<std::endl;
 
  430 template<
typename T, 
typename int_type>
 
  433                          int_type* permutation)
 
  438   if (!isTypeSupported()) {
 
  439     std::cerr << 
"unsupported type for permutation, aborting" << std::endl;
 
  444 template<
typename T, 
typename int_type>
 
  450   if (!isTypeSupported()) {
 
  451     std::cerr << 
"unsupported type for permutation, aborting" << std::endl;
 
  456 template<
typename T, 
typename int_type>
 
  462   if (!isTypeSupported()) {
 
  463     std::cerr << 
"unsupported type for permutation, aborting" << std::endl;
 
  468 template<
typename T, 
typename int_type>
 
  474 template<
typename T, 
typename int_type>
 
  478   if (!strcmp(type_name, 
"unknown")) {
 
  485 template<
typename T, 
typename int_type>
 
  486 typename TPermutation<T, int_type>::OutputRef
 
  516             Epetra_DistObject::Map().NumMyPoints(),
 
  518             (int_type) Epetra_DistObject::Map().IndexBase64(),
 
  519             Epetra_DistObject::Map().Comm());
 
  521   TPermutation* p = 
this;
 
  528     TPermutation* newp = 
new TPermutation(origMap);
 
  529     newp->Export(*p, p_exporter, Add);
 
  533     pmap = 
new Epetra_Map((int_type) p->Map().NumGlobalPoints64(),
 
  534         p->Map().NumMyPoints(),
 
  536         (int_type) p->Map().IndexBase64(),
 
  552   newObj_->Export(orig, exporter, Add);
 
  570 template<
typename T, 
typename int_type>
 
  571 typename TPermutation<T, int_type>::OutputRef
 
  573           bool column_permutation )
 
  578   if (!column_permutation) {
 
  579     return( 
operator()(orig) );
 
  582   if (strcmp(
"Epetra_CrsMatrix", Perm_traits<T>::typeName()) &&
 
  583       strcmp(
"Epetra_CrsGraph", Perm_traits<T>::typeName())) {
 
  584     std::cerr << 
"Permutation: column-permutation only implemented for" 
  585    << 
"CrsMatrix and CrsGraph." << std::endl;
 
  596 #endif //EpetraExt_PERMUTATION_IMPL_H 
static Epetra_CrsGraph * produceColumnPermutation(TPermutation< Epetra_CrsGraph, long long > *perm, Epetra_CrsGraph *srcObj)
return new object which is a column-permutation of srcObj 
bool PointSameAs(const Epetra_BlockMap &Map) const 
int NumGlobalEntries(long long Row) const 
static Epetra_MultiVector * produceColumnPermutation(Permutation64< Epetra_MultiVector > *, Epetra_MultiVector *)
permute column-indices within a specified row, if applicable 
static Epetra_CrsGraph * TproduceColumnPermutation(TPermutation< Epetra_CrsGraph, int_type > *perm, Epetra_CrsGraph *srcObj)
return new object which is a column-permutation of srcObj 
static Epetra_CrsGraph * clone(Epetra_CrsGraph *example, Epetra_DataAccess CV, const Epetra_BlockMap &map, int rowLength)
clone implementation 
static void replaceMap(Epetra_MultiVector *mvec, const Epetra_BlockMap &map)
replaceMap implementation 
Transform< T, T >::NewTypeRef Transform_Composite< T >typename Transform< T, T >::OriginalTypeRef orig this origObj_
int NumGlobalIndices(long long Row) const 
static T * clone(T *example, Epetra_DataAccess CV, const Epetra_BlockMap &map, int int_argument)
clone function accepts an example of the object being cloned, and enough constructor arguments to be ...
static const char * typeName()
typeName implementation 
int ReplaceRowMap(const Epetra_BlockMap &newmap)
const Epetra_BlockMap & ColMap() const 
static const char * typeName()
typeName implementation 
const Epetra_Map & ColMap() const 
static Epetra_CrsMatrix * produceColumnPermutation(TPermutation< Epetra_CrsMatrix, long long > *perm, Epetra_CrsMatrix *srcObj)
return new object, which is a column-permutation of srcObj 
int FillComplete(bool OptimizeDataStorage=true)
static Epetra_CrsMatrix * produceColumnPermutation(TPermutation< Epetra_CrsMatrix, int > *perm, Epetra_CrsMatrix *srcObj)
return new object, which is a column-permutation of srcObj 
const Epetra_Map & RowMap() const 
int NumMyElements() const 
virtual ~TPermutation()
Destructor. 
Permutation stores and describes a permutation matrix P. 
static void replaceMap(Epetra_CrsMatrix *mat, const Epetra_BlockMap &map)
replaceMap implementation 
static Epetra_CrsMatrix * clone(Epetra_CrsMatrix *example, Epetra_DataAccess CV, const Epetra_BlockMap &map, int rowLength)
clone implementation 
int ReplaceRowMap(const Epetra_BlockMap &newmap)
static Epetra_MultiVector * produceColumnPermutation(Permutation< Epetra_MultiVector > *, Epetra_MultiVector *)
permute column-indices within a specified row, if applicable 
int ExtractGlobalRowCopy(int GlobalRow, int Length, int &NumEntries, double *Values, int *Indices) const 
static Epetra_CrsGraph * produceColumnPermutation(TPermutation< Epetra_CrsGraph, int > *perm, Epetra_CrsGraph *srcObj)
return new object which is a column-permutation of srcObj 
static Epetra_MultiVector * clone(Epetra_MultiVector *example, Epetra_DataAccess, const Epetra_BlockMap &map, int)
clone implementation 
OutputRef operator()(InputRef orig)
This method creates a new object which is a permuted copy of the input argument. 
static const char * typeName()
typeName implementation 
static T * produceColumnPermutation(TPermutation< T, int_type > *perm, T *srcObj)
return new object, which is a column-permutation of srcObj 
const Epetra_BlockMap & RowMap() const 
int ExtractGlobalRowCopy(int GlobalRow, int LenOfIndices, int &NumIndices, int *Indices) const 
int InsertGlobalIndices(int GlobalRow, int NumIndices, int *Indices)
static void replaceMap(T *obj, const Epetra_BlockMap &map)
replace the object's row-map (or if it's not a matrix, replace its only map) 
TPermutation(Epetra_DataAccess CV, const Epetra_BlockMap &map, int_type *permutation)
Constructor. 
virtual int InsertGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
static const char * typeName()
return a std::string name for the object type 
Define some traits to make it easier to deal with template-parameters which are objects to be permute...
static void replaceMap(Epetra_CrsGraph *graph, const Epetra_BlockMap &map)
replaceMap implementation 
static Epetra_CrsMatrix * TproduceColumnPermutation(TPermutation< Epetra_CrsMatrix, int_type > *perm, Epetra_CrsMatrix *srcObj)
return new object, which is a column-permutation of srcObj