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> 79 {
static const char name[] =
"unknown";
return( name ); }
90 const Epetra_BlockMap& map,
97 static void replaceMap(T* obj,
const Epetra_BlockMap& map)
98 { cerr <<
"not implemented for unknown type"<<endl; }
104 { cerr <<
"not implemented for unknown type"<<endl; }
118 {
static const char name[] =
"Epetra_CrsMatrix";
return( name ); }
122 static Epetra_CrsMatrix*
clone(Epetra_CrsMatrix* example,
123 Epetra_DataAccess CV,
124 const Epetra_BlockMap& map,
133 const Epetra_Map* pointmap =
134 dynamic_cast<const Epetra_Map*
>(&map);
135 if (pointmap == NULL) {
136 cerr <<
"dynamic_cast<const Epetra_Map*> failed."<<endl;
140 return(
new Epetra_CrsMatrix(CV, *pointmap, rowLength) );
145 static void replaceMap(Epetra_CrsMatrix* mat,
const Epetra_BlockMap& map)
146 { mat->ReplaceRowMap(map); }
149 static Epetra_CrsMatrix*
151 Epetra_CrsMatrix* srcObj)
158 const Epetra_Map& origColMap = srcObj->ColMap();
162 colperm->PutValue(0);
164 Epetra_Export p_exporter(perm->Map(), origColMap);
165 colperm->Export(*perm, p_exporter, Add);
167 const Epetra_Map& origRowMap = srcObj->RowMap();
168 int numMyRows = origRowMap.NumMyElements();
169 const int* myGlobalRows = origRowMap.MyGlobalElements();
173 Epetra_CrsMatrix* result =
new Epetra_CrsMatrix(Copy, origRowMap, 1);
175 for(
int i=0; i<numMyRows; ++i) {
176 int globalRow = myGlobalRows[i];
177 int len = srcObj->NumGlobalEntries(globalRow);
180 double* src_values =
new double[len];
181 int* src_indices =
new int[len];
182 int err = srcObj->ExtractGlobalRowCopy(globalRow, len, numIndices,
183 src_values, src_indices);
184 if (err < 0 || numIndices != len) {
185 cerr<<
"Perm_traits<CrsMatrix>::produceColumnPermutation err("<<err<<
") row " 186 <<globalRow<<
", len "<<len<<
", numIndices "<<numIndices<<endl;
189 int* pindices =
new int[len];
191 const Epetra_BlockMap& pmap = colperm->Map();
192 int* p = colperm->Values();
194 for(
int j=0; j<len; ++j) {
195 int old_col = src_indices[j];
197 int lid = pmap.LID(old_col);
199 cerr <<
"Perm_traits<CrsMatrix>::permuteColumnIndices GID("<<old_col
200 <<
") not found"<<endl;
204 pindices[j] = p[lid];
207 err = result->InsertGlobalValues(globalRow, len, src_values, pindices);
209 cerr <<
"Perm_traits<CrsMatrix>::permuteColumnIndices err("<<err
210 <<
") row "<<globalRow<<endl;
214 delete [] src_indices;
215 delete [] src_values;
218 result->FillComplete();
237 {
static const char name[] =
"Epetra_CrsGraph";
return( name ); }
241 static Epetra_CrsGraph*
clone(Epetra_CrsGraph* example,
242 Epetra_DataAccess CV,
243 const Epetra_BlockMap& map,
249 return(
new Epetra_CrsGraph(CV, map, rowLength) );
254 static void replaceMap(Epetra_CrsGraph* graph,
const Epetra_BlockMap& map)
255 { graph->ReplaceRowMap(map); }
258 static Epetra_CrsGraph*
260 Epetra_CrsGraph* srcObj)
267 const Epetra_BlockMap& origColMap = srcObj->ColMap();
271 colperm->PutValue(0);
273 Epetra_Export p_exporter(perm->Map(), origColMap);
274 colperm->Export(*perm, p_exporter, Add);
276 const Epetra_BlockMap& origRowMap = srcObj->RowMap();
277 int numMyRows = origRowMap.NumMyElements();
278 const int* myGlobalRows = origRowMap.MyGlobalElements();
282 Epetra_CrsGraph* result =
new Epetra_CrsGraph(Copy, origRowMap, 1);
284 for(
int i=0; i<numMyRows; ++i) {
285 int globalRow = myGlobalRows[i];
286 int len = srcObj->NumGlobalIndices(globalRow);
289 int* src_indices =
new int[len];
290 int err = srcObj->ExtractGlobalRowCopy(globalRow, len, numIndices, src_indices);
291 if (err < 0 || numIndices != len) {
292 cerr<<
"Perm_traits<CrsGraph>::produceColumnPermutation err("<<err<<
") row " 293 <<globalRow<<
", len "<<len<<
", numIndices "<<numIndices<<endl;
296 int* pindices =
new int[len];
298 const Epetra_BlockMap& pmap = colperm->Map();
299 int* p = colperm->Values();
301 for(
int j=0; j<len; ++j) {
302 int old_col = src_indices[j];
304 int lid = pmap.LID(old_col);
306 cerr <<
"Perm_traits<CrsGraph>::permuteColumnIndices GID("<<old_col
307 <<
") not found"<<endl;
311 pindices[j] = p[lid];
314 err = result->InsertGlobalIndices(globalRow, len, pindices);
316 cerr <<
"Perm_traits<CrsGraph>::produceColumnPermutation err("<<err
317 <<
") row "<<globalRow<<endl;
321 delete [] src_indices;
324 result->FillComplete();
342 {
static const char name[] =
"Epetra_MultiVector";
return( name ); }
346 static Epetra_MultiVector*
clone(Epetra_MultiVector* example,
347 Epetra_DataAccess CV,
348 const Epetra_BlockMap& map,
351 return(
new Epetra_MultiVector(map, example->NumVectors()) );
356 static void replaceMap(Epetra_MultiVector* mvec,
const Epetra_BlockMap& map)
357 { mvec->ReplaceMap(map); }
360 static Epetra_MultiVector*
362 Epetra_MultiVector* srcObj)
364 cerr <<
"col-permutation not implemented for Epetra_MultiVector"<<endl;
377 const Epetra_BlockMap& map,
379 : Epetra_IntVector(CV, map, permutation),
383 if (!isTypeSupported()) {
384 cerr <<
"unsupported type for permutation, aborting" << endl;
391 : Epetra_IntVector(map),
395 if (!isTypeSupported()) {
396 cerr <<
"unsupported type for permutation, aborting" << endl;
403 : Epetra_IntVector((const Epetra_IntVector&)src),
407 if (!isTypeSupported()) {
408 cerr <<
"unsupported type for permutation, aborting" << endl;
416 if (newObj_ != NULL)
delete newObj_;
423 if (!strcmp(type_name,
"unknown")) {
456 const Epetra_BlockMap& origMap = orig.Map();
460 Epetra_Map* pmap =
new Epetra_Map(Map().NumGlobalPoints(),
471 if (!pmap->PointSameAs(origMap)) {
472 Epetra_Export p_exporter(Map(), origMap);
474 newp->Export(*p, p_exporter, Add);
478 pmap =
new Epetra_Map(p->Map().NumGlobalPoints(),
479 p->Map().NumMyPoints(),
481 p->Map().IndexBase(),
493 Epetra_Export exporter(origMap, *pmap);
497 newObj_->Export(orig, exporter, Add);
518 bool column_permutation )
523 if (!column_permutation) {
524 return(
operator()(orig) );
529 cerr <<
"Permutation: column-permutation only implemented for" 530 <<
"CrsMatrix and CrsGraph." << endl;
541 #endif //EpetraExt_PERMUTATION_IMPL_H virtual ~Permutation()
Destructor.
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
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
static T * produceColumnPermutation(Permutation< T > *perm, T *srcObj)
return new object, which is a column-permutation of srcObj
static const char * typeName()
typeName implementation
EpetraExt::BlockCrsMatrix: A class for constructing a distributed block matrix.
static Epetra_MultiVector * clone(Epetra_MultiVector *example, Epetra_DataAccess CV, const Epetra_BlockMap &map, int numVectors)
clone implementation
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
Permutation stores and describes a permutation matrix P.
static Epetra_MultiVector * produceColumnPermutation(Permutation< Epetra_MultiVector > *perm, Epetra_MultiVector *srcObj)
permute column-indices within a specified row, if applicable
static const char * typeName()
typeName implementation
Permutation(Epetra_DataAccess CV, const Epetra_BlockMap &map, int *permutation)
Constructor.
EpetraExt::SameTypeTransform< T >::TransformTypeRef OutputRef
OutputRef operator()(InputRef orig)
This method creates a new object which is a permuted copy of the input argument.
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)
EpetraExt::SameTypeTransform< T >::TransformTypeRef InputRef
static const char * typeName()
return a 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 Epetra_CrsMatrix * produceColumnPermutation(Permutation< Epetra_CrsMatrix > *perm, Epetra_CrsMatrix *srcObj)
return new object, which is a column-permutation of srcObj
static void replaceMap(Epetra_CrsGraph *graph, const Epetra_BlockMap &map)
replaceMap implementation
static Epetra_CrsGraph * produceColumnPermutation(Permutation< Epetra_CrsGraph > *perm, Epetra_CrsGraph *srcObj)
return new object which is a column-permutation of srcObj