EpetraExt  Development
EpetraExt_PointToBlockDiagPermute.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_POINTTOBLOCKDIAGPERMUTE_H
43 #define EPETRAEXT_POINTTOBLOCKDIAGPERMUTE_H
44 
45 #include "Epetra_DistObject.h"
46 #include "Epetra_BlockMap.h"
47 #include "Epetra_BlockMap.h"
48 #include "Epetra_Map.h"
49 #include "Epetra_Operator.h"
50 #include "Epetra_CrsMatrix.h"
51 #include "Epetra_FECrsMatrix.h"
52 #include "Teuchos_ParameterList.hpp"
53 
54 class Epetra_Comm;
55 class Epetra_Import;
56 class Epetra_Export;
58 
60 
68 // NTS: Map() == RowMap is the convention
69 
70 //=========================================================================
71 class EpetraExt_PointToBlockDiagPermute : public virtual Epetra_Operator, public Epetra_DistObject {
72 public:
73 
75 
76  EpetraExt_PointToBlockDiagPermute(const Epetra_CrsMatrix& MAT);
79 
81 
85 
86 
88 
89 
91  virtual int SetParameters(Teuchos::ParameterList & List);
92 
94  virtual int SetUseTranspose(bool UseTranspose){return -1;}
95 
97  virtual int Compute();
98 
100 
102 
103 
105 
113  virtual int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
114 
116 
127  virtual int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
128 
130  virtual double NormInf() const {return -1;}
132 
134 
135 
137  virtual const char * Label() const{return "Fix Me";}
138 
140  virtual bool UseTranspose() const {return false;}
141 
143  virtual bool HasNormInf() const {return false;}
144 
146  virtual const Epetra_Comm & Comm() const {return Map().Comm();}
147 
149  //operator.
150  virtual const Epetra_Map & OperatorDomainMap() const {return Matrix_->OperatorDomainMap();}
151 
153  //operator.
154  virtual const Epetra_Map & OperatorRangeMap() const {return Matrix_->OperatorRangeMap();}
155 
156 
158  virtual const EpetraExt_BlockDiagMatrix & BlockMatrix(){return *BDMat_;}
159 
160 
162  virtual Epetra_FECrsMatrix * CreateFECrsMatrix();
163 
165 
166  virtual void Print(ostream& os) const;
168 
170 
171 
173 
174 
176 
188  int Import(const Epetra_SrcDistObject& A, const Epetra_Import& Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex * Indexor = 0);
189 
191 
203  int Import(const Epetra_SrcDistObject& A, const Epetra_Export& Exporter, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex * Indexor = 0);
204 
206 
218  int Export(const Epetra_SrcDistObject& A, const Epetra_Import & Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex * Indexor = 0);
219 
221 
233  int Export(const Epetra_SrcDistObject& A, const Epetra_Export& Exporter, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex * Indexor = 0);
235 
236  protected:
237 
238 
240 
241  virtual int CheckSizes(const Epetra_SrcDistObject& Source);
244  virtual int CopyAndPermute(const Epetra_SrcDistObject& Source,
245  int NumSameIDs,
246  int NumPermuteIDs,
247  int * PermuteToLIDs,
248  int * PermuteFromLIDs,
249  const Epetra_OffsetIndex * Indexor);
250 
252  virtual int PackAndPrepare(const Epetra_SrcDistObject& Source,
253  int NumExportIDs,
254  int* ExportLIDs,
255  int& LenExports,
256  char*& Exports,
257  int& SizeOfPacket,
258  int* Sizes,
259  bool & VarSizes,
260  Epetra_Distributor& Distor);
261 
263  virtual int UnpackAndCombine(const Epetra_SrcDistObject& Source,
264  int NumImportIDs,
265  int* ImportLIDs,
266  int LenImports,
267  char* Imports,
268  int& SizeOfPacket,
269  Epetra_Distributor& Distor,
270  Epetra_CombineMode CombineMode,
271  const Epetra_OffsetIndex * Indexor);
272 
274 
275 private:
277  int ExtractBlockDiagonal();
278 
280  int SetupContiguousMode();
281  int CleanupContiguousMode();
282 
283  // Copied from Epetra_CrsMatrix
284  void UpdateImportVector(int NumVectors) const;
285  void UpdateExportVector(int NumVectors) const;
286 
287  Teuchos::ParameterList List_;
288  const Epetra_CrsMatrix* Matrix_;
289  bool PurelyLocalMode_;
290 
291  // For contiguous blocking only
292  bool ContiguousBlockMode_;
293  int ContiguousBlockSize_;
294 
295  int NumBlocks_;
296  int *Blockstart_;
297  int *Blockids_;
298  Epetra_BlockMap *BDMap_;
299  Epetra_Map *CompatibleMap_; //A map compatible with BD's block map - used for imports
301  Epetra_Import *Importer_;
302  Epetra_Export *Exporter_;
303  mutable Epetra_MultiVector *ImportVector_;
304  mutable Epetra_MultiVector *ExportVector_;
305 
306 
307 }; /* EPETRAEXT_POINTTOBLOCKDIAGPERMUTE_H */
308 
309 #endif
virtual const EpetraExt_BlockDiagMatrix & BlockMatrix()
Returns the block matrix. Only call this after calling Compute.
EpetraExt_PointToBlockDiagPermute: A class for managing point-to-block-diagonal permutations.
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this.
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
virtual int SetParameters(Teuchos::ParameterList &List)
Sets the parameter list.
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...
virtual int SetUseTranspose(bool UseTranspose)
If set true, transpose of this operator will be applied. NOT IMPLEMENTED.
virtual const Epetra_Comm & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
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().
virtual int CheckSizes(const Epetra_SrcDistObject &Source)
Allows the source and target (this) objects to be compared for compatibility, return nonzero if not...
virtual int CopyAndPermute(const Epetra_SrcDistObject &Source, int NumSameIDs, int NumPermuteIDs, int *PermuteToLIDs, int *PermuteFromLIDs, const Epetra_OffsetIndex *Indexor)
Perform ID copies and permutations that are on processor.
EpetraExt_PointToBlockDiagPermute(const Epetra_CrsMatrix &MAT)
@ Name Constructors
virtual const char * Label() const
Returns a character string describing the operator.
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()
Creates an Epetra_FECrsMatrix from the BlockDiagMatrix. This is generally only useful if you want to ...
virtual void Print(ostream &os) const
Print method.
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this.
virtual double NormInf() const
Returns the infinity norm of the global matrix - NOT IMPLEMENTED.
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 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.
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.