55 #define MAX(x,y) ((x)>(y)?(x):(y))
61 PurelyLocalMode_(true),
62 ContiguousBlockMode_(false),
63 ContiguousBlockSize_(0),
67 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
96 template<
typename int_type>
110 Blockids_ref<int>()=
List_.
get(
"block entry lids",(
int*)0);
111 if(Blockids_const_ptr<int>())
114 Blockids_ref<int_type>()=
List_.
get(
"block entry gids",(int_type*)0);
115 if(Blockids_const_ptr<int_type>()) {
117 if(
sizeof(
int) !=
sizeof(int_type)) {
131 if(!Blockids_const_ptr<int>() && !Blockids_const_ptr<int_type>())
EPETRA_CHK_ERR(-3);
138 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
140 return TSetParameters<int>(List);
144 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
146 return TSetParameters<long long>(List);
150 throw "EpetraExt_PointToBlockDiagPermute::SetParameters: ERROR, GlobalIndices type unknown.";
171 int NumVectors = X.NumVectors();
172 if (NumVectors!=Y.NumVectors()) {
229 template<
typename int_type>
232 std::vector<int_type> ExtRows;
234 int ExtSize=0,ExtCols=0,MainCols=0;
236 int *l2b,*block_offset;
239 int index,col,row_in_block,col_in_block,length,*colind;
242 bool verbose=(bool)(
List_.
get(
"output",0) > 0);
257 int_type *MyBlockGIDs=
new int_type[
NumBlocks_];
259 MyBlockGIDs[i]=MyMinGID+i;
271 ExtRows.reserve(ExtSize);
274 if(RowMap.
LID(Blockids_const_ptr<int_type>()[i])==-1)
275 ExtRows.push_back(Blockids_const_ptr<int_type>()[i]);
280 ExtSize=ExtRows.size();
283 if(verbose && !
Matrix_->
Comm().
MyPID()) printf(
"EpetraExt_PointToBlockDiagPermute: Switching to purely local mode\n");
286 Blockids_ref<int>()[i]=RowMap.
LID(Blockids_const_ptr<int_type>()[i]);
295 block_offset=
new int[Nrows];
300 block_offset[Blockids_const_ptr<int>()[j]]=j-Blockstart_[i];
301 l2b[Blockids_const_ptr<int>()[j]]=i;
306 for(i=0;i<Nrows;i++) {
307 int block_num = l2b[i];
308 if(block_num>=0 && block_num<NumBlocks_) {
309 row_in_block=block_offset[i];
312 for (j = 0; j < length; j++) {
314 if(col < Nrows && l2b[col]==block_num){
316 col_in_block = block_offset[col];
317 index = col_in_block * bsize[block_num] + row_in_block;
318 (*BDMat_)[block_num][index]=values[j];
324 index = row_in_block * bsize[block_num] + row_in_block;
325 (*BDMat_)[block_num][index]=1.0;
331 l2blockid=
new int_type[Nrows];
343 int_type* ExtRowsPtr = ExtRows.size()>0 ? &ExtRows[0] : NULL;
356 LocalColIDS=
new int[MainCols+ExtCols];
357 for(i=0;i<MainCols;i++){
359 int MainLID=RowMap.
LID(GID);
360 if(MainLID!=-1) LocalColIDS[i]=MainLID;
362 int ExtLID=TmpMatrix.
LRID(GID);
363 if(ExtLID!=-1) LocalColIDS[i]=Nrows+ExtLID;
364 else LocalColIDS[i]=-1;
369 for(i=0;i<ExtCols;i++){
370 int_type GID= (int_type) TmpMatrix.
GCID64(i);
371 int MainLID=RowMap.
LID(GID);
372 if(MainLID!=-1) LocalColIDS[MainCols+i]=MainLID;
374 int ExtLID=TmpMatrix.
LRID(GID);
375 if(ExtLID!=-1) LocalColIDS[MainCols+i]=Nrows+ExtLID;
376 else LocalColIDS[MainCols+i]=-1;
381 l2b=
new int[Nrows+ExtSize];
382 block_offset=
new int[Nrows+ExtSize];
387 for(i=0;i<Nrows+ExtSize;i++) block_offset[i]=l2b[i]=-1;
391 int LID=RowMap.
LID(Blockids_const_ptr<int_type>()[j]);
392 if(LID==-1) {LID=Nrows+ext_idx;ext_idx++;}
393 block_offset[LID]=j-Blockstart_[i];
399 for(i=0;i<Nrows;i++) {
400 int block_num = l2b[i];
401 if(block_num>=0 && block_num<NumBlocks_) {
402 row_in_block=block_offset[i];
405 for (j = 0; j < length; j++) {
406 col = LocalColIDS[colind[j]];
407 if(col!=-1 && l2b[col]==block_num){
409 col_in_block = block_offset[col];
410 index = col_in_block * bsize[block_num] + row_in_block;
411 (*BDMat_)[block_num][index]=values[j];
417 index = row_in_block * bsize[block_num] + row_in_block;
418 (*BDMat_)[block_num][index]=values[j];
424 for(i=0;i<ExtSize;i++) {
425 int block_num = l2b[Nrows+i];
426 if(block_num>=0 && block_num<NumBlocks_) {
427 row_in_block=block_offset[Nrows+i];
430 for (j = 0; j < length; j++) {
431 col = LocalColIDS[MainCols+colind[j]];
432 if(col!=-1 && l2b[col]==block_num){
434 col_in_block = block_offset[col];
435 index = col_in_block * bsize[block_num] + row_in_block;
436 (*BDMat_)[block_num][index]=values[j];
442 index = row_in_block * bsize[block_num] + row_in_block;
443 (*BDMat_)[block_num][index]=1.0;
450 for(i=0;i<Nrows;i++){
452 if(bkid>-1) l2blockid[Blockstart_[bkid]+block_offset[i]]= (int_type) RowMap.
GID64(i);
455 for(i=0;i<ExtSize;i++)
456 l2blockid[Blockstart_[l2b[Nrows+i]]+block_offset[Nrows+i]]= (int_type) TmpMatrix.
GRID64(i);
465 inList=
List_.
get(
"blockdiagmatrix: list",dummy);
466 BDMat_->SetParameters(inList);
476 delete [] LocalColIDS;
477 delete [] block_offset;
481 delete [] MyBlockGIDs;
490 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
492 return TExtractBlockDiagonal<int>();
496 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
498 return TExtractBlockDiagonal<long long>();
502 throw "EpetraExt_PointToBlockDiagPermute::ExtractBlockDiagonal: ERROR, GlobalIndices type unknown.";
506 template<
typename int_type>
512 int_type MinMyGID= (int_type) RowMap.
MinMyGID64();
513 int_type MaxMyGID= (int_type) RowMap.
MaxMyGID64();
523 if(
sizeof(
int) !=
sizeof(int_type))
531 Blockids_ref<int_type>()[ct]=MyFirstBlockGID+ct;
539 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
541 return TSetupContiguousMode<int>();
545 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
547 return TSetupContiguousMode<long long>();
551 throw "EpetraExt_PointToBlockDiagPermute::SetupContiguousMode: ERROR, GlobalIndices type unknown.";
560 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
569 template<
typename int_type>
576 const int *xlist=BlockMap.FirstPointInElementList();
577 const int *blocksize=BlockMap.ElementSizeList();
582 std::vector<int_type> GIDs;
583 GIDs.resize(BlockMap.MaxMyElementSize());
586 for(
int i=0;i<NumBlocks;i++){
591 for(
int j=0;j<Nb;j++)
596 if(ierr < 0)
throw "CreateFECrsMatrix: ERROR in InsertGlobalValues";
603 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
605 return TCreateFECrsMatrix<int>();
609 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
611 return TCreateFECrsMatrix<long long>();
615 throw "EpetraExt_PointToBlockDiagPermute::CreateFECrsMatrix: ERROR, GlobalIndices type unknown.";
long long MinMyGID64() const
virtual const Epetra_BlockMap & DataMap() const
Returns the Epetra_BlockMap object with the distribution of underlying values.
Epetra_MultiVector * ExportVector_
int LRID(int GRID_in) const
virtual int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y...
int * FirstPointInElementList() const
const Epetra_Map & RangeMap() const
int TSetParameters(Teuchos::ParameterList &List)
void UpdateExportVector(int NumVectors) const
long long IndexBase64() const
virtual int SetParameters(Teuchos::ParameterList &List)
Sets the parameter list.
bool GlobalIndicesLongLong() const
bool SameAs(const Epetra_BlockMap &Map) const
int NumMyBlocks() const
Returns the number of local blocks.
int TSetupContiguousMode()
virtual int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y...
T & get(ParameterList &l, const std::string &name)
double * Values() const
Returns a pointer to the array containing the blocks.
long long GRID64(int LRID_in) const
#define EPETRA_CHK_ERR(a)
void UpdateImportVector(int NumVectors) const
bool GlobalIndicesInt() const
Epetra_FECrsMatrix * TCreateFECrsMatrix()
virtual int MyPID() const =0
int FillComplete(bool OptimizeDataStorage=true)
bool ContiguousBlockMode_
int InsertGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
EpetraExt_BlockDiagMatrix: A class for storing distributed block matrices.
virtual int UnpackAndCombine(const Epetra_SrcDistObject &Source, int NumImportIDs, int *ImportLIDs, int LenImports, char *Imports, int &SizeOfPacket, Epetra_Distributor &Distor, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex *Indexor)
Perform any unpacking and combining after call to DoTransfer().
int ExtractMyRowView(int MyRow, int &NumEntries, double *&Values, int *&Indices) const
const Epetra_Map & RowMap() const
virtual int SumAll(double *PartialSums, double *GlobalSums, int Count) const =0
int NumMyElements() const
long long GID64(int LID) const
virtual int CheckSizes(const Epetra_SrcDistObject &Source)
Allows the source and target (this) objects to be compared for compatibility, return nonzero if not...
int CleanupContiguousMode()
int GlobalAssemble(bool callFillComplete=true, Epetra_CombineMode combineMode=Add, bool save_off_and_reuse_map_exporter=false)
virtual int CopyAndPermute(const Epetra_SrcDistObject &Source, int NumSameIDs, int NumPermuteIDs, int *PermuteToLIDs, int *PermuteFromLIDs, const Epetra_OffsetIndex *Indexor, Epetra_CombineMode CombineMode=Zero)
Perform ID copies and permutations that are on processor.
EpetraExt_BlockDiagMatrix * BDMat_
Epetra_Map * CompatibleMap_
const Epetra_Comm & Comm() const
virtual ~EpetraExt_PointToBlockDiagPermute()
Destructor.
EpetraExt_PointToBlockDiagPermute(const Epetra_CrsMatrix &MAT)
@ Name Constructors
virtual int Compute()
Extracts the block-diagonal, builds maps, etc.
virtual int PackAndPrepare(const Epetra_SrcDistObject &Source, int NumExportIDs, int *ExportLIDs, int &LenExports, char *&Exports, int &SizeOfPacket, int *Sizes, bool &VarSizes, Epetra_Distributor &Distor)
Perform any packing or preparation required for call to DoTransfer().
virtual Epetra_FECrsMatrix * CreateFECrsMatrix()
Create an Epetra_FECrsMatrix from the BlockDiagMatrix.
int TExtractBlockDiagonal()
const Epetra_Map & DomainMap() const
int SetupContiguousMode()
Setup/Cleanup for Contiguous Mode.
Epetra_Import * Importer_
const Epetra_CrsMatrix * Matrix_
Epetra_MultiVector * ImportVector_
virtual void Print(std::ostream &os) const
Print information about this object to the given output stream.
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator applied to a Epetra_MultiVector X in Y.
int ExtractBlockDiagonal()
Pulls the block diagonal of the matrix and then builds the BDMat_.
Teuchos::ParameterList List_
const Epetra_Comm & Comm() const
virtual int ScanSum(double *MyVals, double *ScanSums, int Count) const =0
long long GCID64(int LCID_in) const
long long MaxMyGID64() const
int Import(const Epetra_SrcDistObject &A, const Epetra_Import &Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex *Indexor=0)
Imports an Epetra_DistObject using the Epetra_Import object.
virtual const Epetra_BlockMap & BlockMap() const
Returns the Epetra_BlockMap object associated with the range of this operator.
int Export(const Epetra_SrcDistObject &A, const Epetra_Import &Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex *Indexor=0)
Exports an Epetra_DistObject using the Epetra_Import object.
Epetra_Export * Exporter_