EpetraExt  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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_ConfigDefs.h"
46 #include "Epetra_DistObject.h"
47 #include "Epetra_BlockMap.h"
48 #include "Epetra_BlockMap.h"
49 #include "Epetra_Map.h"
50 #include "Epetra_Operator.h"
51 #include "Epetra_CrsMatrix.h"
52 #include "Epetra_FECrsMatrix.h"
53 #include "Teuchos_ParameterList.hpp"
54 
55 class Epetra_Comm;
56 class Epetra_Import;
57 class Epetra_Export;
59 
61 
69 // NTS: Map() == RowMap is the convention
70 
71 //=========================================================================
73 public:
74 
76 
80 
82 
86 
87 
89 
90 
92  virtual int SetParameters(Teuchos::ParameterList & List);
93 
100  virtual int SetUseTranspose (bool /* useTranspose */) {return -1;}
101 
103  virtual int Compute();
104 
106 
108 
109 
111 
119  virtual int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
120 
122 
133  virtual int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
134 
136  virtual double NormInf() const {return -1;}
138 
140 
141 
143  virtual const char * Label() const{return "Fix Me";}
144 
146  virtual bool UseTranspose() const {return false;}
147 
149  virtual bool HasNormInf() const {return false;}
150 
152  virtual const Epetra_Comm & Comm() const {return Map().Comm();}
153 
155  virtual const Epetra_Map & OperatorDomainMap() const {return Matrix_->OperatorDomainMap();}
156 
158  virtual const Epetra_Map & OperatorRangeMap() const {return Matrix_->OperatorRangeMap();}
159 
161  virtual const EpetraExt_BlockDiagMatrix & BlockMatrix(){return *BDMat_;}
162 
167 
169 
170 
172  virtual void Print(std::ostream& os) const;
173 
175 
177 
179 
191  int Import(const Epetra_SrcDistObject& A, const Epetra_Import& Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex * Indexor = 0);
192 
194 
206  int Import(const Epetra_SrcDistObject& A, const Epetra_Export& Exporter, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex * Indexor = 0);
207 
209 
221  int Export(const Epetra_SrcDistObject& A, const Epetra_Import & Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex * Indexor = 0);
222 
224 
236  int Export(const Epetra_SrcDistObject& A, const Epetra_Export& Exporter, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex * Indexor = 0);
238 
239  protected:
240 
241 
243 
244  virtual int CheckSizes(const Epetra_SrcDistObject& Source);
247  virtual int CopyAndPermute(const Epetra_SrcDistObject& Source,
248  int NumSameIDs,
249  int NumPermuteIDs,
250  int * PermuteToLIDs,
251  int * PermuteFromLIDs,
252  const Epetra_OffsetIndex * Indexor,
253  Epetra_CombineMode CombineMode = Zero);
254 
256  virtual int PackAndPrepare(const Epetra_SrcDistObject& Source,
257  int NumExportIDs,
258  int* ExportLIDs,
259  int& LenExports,
260  char*& Exports,
261  int& SizeOfPacket,
262  int* Sizes,
263  bool & VarSizes,
264  Epetra_Distributor& Distor);
265 
267  virtual int UnpackAndCombine(const Epetra_SrcDistObject& Source,
268  int NumImportIDs,
269  int* ImportLIDs,
270  int LenImports,
271  char* Imports,
272  int& SizeOfPacket,
273  Epetra_Distributor& Distor,
274  Epetra_CombineMode CombineMode,
275  const Epetra_OffsetIndex * Indexor);
276 
278 
279 private:
281  int ExtractBlockDiagonal();
282 
284  int SetupContiguousMode();
285  int CleanupContiguousMode();
286 
287  // Copied from Epetra_CrsMatrix
288  void UpdateImportVector(int NumVectors) const;
289  void UpdateExportVector(int NumVectors) const;
290 
291  Teuchos::ParameterList List_;
292  const Epetra_CrsMatrix* Matrix_;
293  bool PurelyLocalMode_;
294 
295  // For contiguous blocking only
296  bool ContiguousBlockMode_;
297  int ContiguousBlockSize_;
298 
299  int NumBlocks_;
300  int *Blockstart_;
301  int *Blockids_int_;
302 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
303  long long *Blockids_LL_;
304 #endif
305  Epetra_BlockMap *BDMap_;
306  Epetra_Map *CompatibleMap_; //A map compatible with BD's block map - used for imports
308  Epetra_Import *Importer_;
309  Epetra_Export *Exporter_;
310  mutable Epetra_MultiVector *ImportVector_;
311  mutable Epetra_MultiVector *ExportVector_;
312 
313  template<typename int_type>
314  Epetra_FECrsMatrix * TCreateFECrsMatrix();
315 
316  template<typename int_type>
317  int TSetupContiguousMode();
318 
319  template<typename int_type>
320  int TExtractBlockDiagonal();
321 
322  template<typename int_type>
323  int TSetParameters(Teuchos::ParameterList & List);
324 
325  template<typename int_type>
326  const int_type* Blockids_const_ptr() const;
327 
328  template<typename int_type>
329  int_type*& Blockids_ref();
330 
331 }; /* EPETRAEXT_POINTTOBLOCKDIAGPERMUTE_H */
332 
333 template<> inline const int* EpetraExt_PointToBlockDiagPermute::Blockids_const_ptr<int>() const { return Blockids_int_; }
334 
335 template<> inline int*& EpetraExt_PointToBlockDiagPermute::Blockids_ref<int>() { return Blockids_int_; }
336 
337 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
338 template<> inline const long long* EpetraExt_PointToBlockDiagPermute::Blockids_const_ptr<long long>() const { return Blockids_LL_; }
339 template<> inline long long*& EpetraExt_PointToBlockDiagPermute::Blockids_ref<long long>() { return Blockids_LL_; }
340 #endif
341 
342 #endif
virtual const EpetraExt_BlockDiagMatrix & BlockMatrix()
Return 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
Return the Epetra_Map object associated with the domain of this operator.
virtual bool HasNormInf() const
Return 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...
const Epetra_Map & OperatorDomainMap() const
virtual const Epetra_Comm & Comm() const
Return a pointer to the Epetra_Comm communicator associated with this operator.
virtual bool UseTranspose() const
Return 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, Epetra_CombineMode CombineMode=Zero)
Perform ID copies and permutations that are on processor.
EpetraExt_PointToBlockDiagPermute(const Epetra_CrsMatrix &MAT)
@ Name Constructors
virtual const char * Label() const
Return a 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()
Create an Epetra_FECrsMatrix from the BlockDiagMatrix.
const Epetra_Map & OperatorRangeMap() const
Epetra_CombineMode
virtual const Epetra_Map & OperatorRangeMap() const
Return the Epetra_Map object associated with the range of this operator.
virtual void Print(std::ostream &os) const
Print information about this object to the given output stream.
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.
virtual int SetUseTranspose(bool)
Set whether to use the transpose.
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.