41 #ifndef EpetraExt_PERMUTATION_IMPL_H
42 #define EpetraExt_PERMUTATION_IMPL_H
44 #if defined(EpetraExt_SHOW_DEPRECATED_WARNINGS)
46 #warning "The EpetraExt package is deprecated"
86 {
static const char name[] =
"unknown";
return( name ); }
105 { std::cerr <<
"not implemented for unknown type"<<std::endl; }
108 template<
typename int_type>
112 { std::cerr <<
"not implemented for unknown type"<<std::endl; }
126 {
static const char name[] =
"Epetra_CrsMatrix";
return( name ); }
143 if (pointmap == NULL) {
144 std::cerr <<
"dynamic_cast<const Epetra_Map*> failed."<<std::endl;
157 template<
typename int_type>
171 colperm->PutValue(0);
174 colperm->Export(*perm, p_exporter,
Add);
178 int_type* myGlobalRows = 0;
185 for(
int i=0; i<numMyRows; ++i) {
186 int_type globalRow = myGlobalRows[i];
190 double* src_values =
new double[len];
191 int_type* src_indices =
new int_type[len];
193 src_values, src_indices);
194 if (err < 0 || numIndices != len) {
195 std::cerr<<
"Perm_traits<CrsMatrix>::produceColumnPermutation err("<<err<<
") row "
196 <<globalRow<<
", len "<<len<<
", numIndices "<<numIndices<<std::endl;
199 int_type* pindices =
new int_type[len];
202 int_type* p = colperm->Values();
204 for(
int j=0; j<len; ++j) {
205 int_type old_col = src_indices[j];
207 int lid = pmap.
LID(old_col);
209 std::cerr <<
"Perm_traits<CrsMatrix>::permuteColumnIndices GID("<<old_col
210 <<
") not found"<<std::endl;
214 pindices[j] = p[lid];
219 std::cerr <<
"Perm_traits<CrsMatrix>::permuteColumnIndices err("<<err
220 <<
") row "<<globalRow<<std::endl;
224 delete [] src_indices;
225 delete [] src_values;
235 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
241 return TproduceColumnPermutation<int>(perm, srcObj);
245 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
251 return TproduceColumnPermutation<long long>(perm, srcObj);
266 {
static const char name[] =
"Epetra_CrsGraph";
return( name ); }
287 template<
typename int_type>
301 colperm->PutValue(0);
304 colperm->Export(*perm, p_exporter,
Add);
308 int_type* myGlobalRows = 0;
315 for(
int i=0; i<numMyRows; ++i) {
316 int_type globalRow = myGlobalRows[i];
320 int_type* src_indices =
new int_type[len];
322 if (err < 0 || numIndices != len) {
323 std::cerr<<
"Perm_traits<CrsGraph>::produceColumnPermutation err("<<err<<
") row "
324 <<globalRow<<
", len "<<len<<
", numIndices "<<numIndices<<std::endl;
327 int_type* pindices =
new int_type[len];
330 int_type* p = colperm->Values();
332 for(
int j=0; j<len; ++j) {
333 int_type old_col = src_indices[j];
335 int lid = pmap.
LID(old_col);
337 std::cerr <<
"Perm_traits<CrsGraph>::permuteColumnIndices GID("<<old_col
338 <<
") not found"<<std::endl;
342 pindices[j] = p[lid];
347 std::cerr <<
"Perm_traits<CrsGraph>::produceColumnPermutation err("<<err
348 <<
") row "<<globalRow<<std::endl;
352 delete [] src_indices;
362 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
368 return TproduceColumnPermutation<int>(perm, srcObj);
372 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
378 return TproduceColumnPermutation<long long>(perm, srcObj);
392 {
static const char name[] =
"Epetra_MultiVector";
return( name ); }
407 { mvec->ReplaceMap(map); }
409 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
415 std::cerr <<
"col-permutation not implemented for Epetra_MultiVector"<<std::endl;
419 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
425 std::cerr <<
"col-permutation not implemented for Epetra_MultiVector"<<std::endl;
436 template<
typename T,
typename int_type>
439 int_type* permutation)
445 std::cerr <<
"unsupported type for permutation, aborting" << std::endl;
450 template<
typename T,
typename int_type>
457 std::cerr <<
"unsupported type for permutation, aborting" << std::endl;
462 template<
typename T,
typename int_type>
469 std::cerr <<
"unsupported type for permutation, aborting" << std::endl;
474 template<
typename T,
typename int_type>
480 template<
typename T,
typename int_type>
484 if (!strcmp(type_name,
"unknown")) {
491 template<
typename T,
typename int_type>
535 newp->Export(*p, p_exporter, Add);
539 pmap =
new Epetra_Map((int_type) p->Map().NumGlobalPoints64(),
540 p->Map().NumMyPoints(),
542 (int_type) p->Map().IndexBase64(),
558 newObj_->Export(orig, exporter, Add);
576 template<
typename T,
typename int_type>
577 typename TPermutation<T, int_type>::OutputRef
579 bool column_permutation )
584 if (!column_permutation) {
585 return(
operator()(orig) );
588 if (strcmp(
"Epetra_CrsMatrix", Perm_traits<T>::typeName()) &&
589 strcmp(
"Epetra_CrsGraph", Perm_traits<T>::typeName())) {
590 std::cerr <<
"Permutation: column-permutation only implemented for"
591 <<
"CrsMatrix and CrsGraph." << std::endl;
602 #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
int ExtractGlobalRowCopy(int_type Row, int Length, int &NumEntries, double *values, int_type *Indices) 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 ...
virtual int InsertGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
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 InsertGlobalIndices(int_type GlobalRow, int NumIndices, int_type *Indices)
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
virtual const Epetra_BlockMap & Map() const =0
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 MyGlobalElementsPtr(int *&MyGlobalElementList) const
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.
EpetraExt::SameTypeTransform< T >::TransformTypeRef InputRef
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...
int ExtractGlobalRowCopy(int_type Row, int LenOfIndices, int &NumIndices, int_type *Indices) const
EpetraExt::SameTypeTransform< T >::TransformTypeRef OutputRef
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