EpetraExt  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EpetraExt_BlockDiagMatrix.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_BLOCKDIAGMATRIX_H
43 #define EPETRAEXT_BLOCKDIAGMATRIX_H
44 
45 #include "Epetra_BLAS.h"
46 #include "Epetra_LAPACK.h"
47 #include "Epetra_DistObject.h"
48 #include "Epetra_BlockMap.h"
49 #include "Epetra_Map.h"
50 #include "Epetra_Operator.h"
51 #include "Teuchos_ParameterList.hpp"
52 
53 class Epetra_Comm;
54 
56 
65 //=========================================================================
66 class EpetraExt_BlockDiagMatrix : public virtual Epetra_Operator, public Epetra_DistObject,public Epetra_BLAS {
67 
68  public:
70  EpetraExt_BlockDiagMatrix(const Epetra_BlockMap& Map,bool zero_out=true);
71 
72 
75 
78 
80 
87 
89 
92  double* operator [] (int index) {return &Values_[DataMap_->FirstPointInElement(index)];}
94 
97  const double* operator [] (int index) const {return &Values_[DataMap_->FirstPointInElement(index)];}
99 
100 
102 
103 
105  virtual int SetUseTranspose(bool UseTranspose){return -1;}
106 
108  virtual int SetParameters(Teuchos::ParameterList & List);
109 
111  virtual int Compute();
112 
114 
115 
117 
118 
120  virtual const char * Label() const{return "EpetraExt::BlockDiagMatrix";}//HAQ
121 
123  virtual bool UseTranspose() const {return false;}
124 
126  virtual bool HasNormInf() const {return false;}
127 
129  virtual const Epetra_Comm & Comm() const {return Map().Comm();}
130 
132  virtual const Epetra_Map & OperatorDomainMap() const {return *dynamic_cast<const Epetra_Map*>(&Map());}
133 
135  virtual const Epetra_Map & OperatorRangeMap() const {return *dynamic_cast<const Epetra_Map*>(&Map());}
136 
138  virtual const Epetra_BlockMap & BlockMap() const {return Map();}
139 
141  double* Values() const {return(Values_);}
142 
144  int BlockSize(int LID) const {return Map().ElementSize(LID);}
145 
147  int DataSize(int LID) const {return DataMap_->ElementSize(LID);}
148 
150  bool ConstantBlockSize() const {return Map().ConstantElementSize();}
151 
153  int NumMyBlocks() const {return(Map().NumMyElements());}
154 
156  int NumGlobalBlocks() const {return(Map().NumGlobalElements());}
157 
159  int NumMyUnknowns() const {return(Map().NumMyPoints());}
160 
162  int NumGlobalUnknowns() const {return(Map().NumGlobalPoints());}
163 
165  int NumData() const {return DataMap_->NumMyPoints();}
166 
168  int GetApplyMode() {return ApplyMode_;}
169 
171  virtual void Print(ostream & os) const;
172 
174 
175 
177 
178 
180 
187  virtual int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const {return -1;}
188 
190 
201  virtual int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
202 
204  virtual double NormInf() const{return -1;}
205 
207  void PutScalar(double value);
208 
210  virtual const Epetra_BlockMap & DataMap() const {return *DataMap_;}
211 
213 
214 
215 private:
216  void Allocate();
217 
218  int DoCopy(const EpetraExt_BlockDiagMatrix& Source);
219 
220  // Routines to implement Epetra_DistObject virtual methods
221  // Allows the source and target (\e this) objects to be compared for compatibility, return nonzero if not.
222  int CheckSizes(const Epetra_SrcDistObject& Source);
223  // Perform ID copies and permutations that are on processor.
224  int CopyAndPermute(const Epetra_SrcDistObject& Source,
225  int NumSameIDs,
226  int NumPermuteIDs,
227  int * PermuteToLIDs,
228  int * PermuteFromLIDs,
229  const Epetra_OffsetIndex * Indexor);
230 
231  // Perform any packing or preparation required for call to DoTransfer().
232  int PackAndPrepare(const Epetra_SrcDistObject& Source,
233  int NumExportIDs,
234  int* ExportLIDs,
235  int& LenExports,
236  char*& Exports,
237  int& SizeOfPacket,
238  int* Sizes,
239  bool & VarSizes,
240  Epetra_Distributor& Distor);
241 
242  // Perform any unpacking and combining after call to DoTransfer().
243  int UnpackAndCombine(const Epetra_SrcDistObject& Source,
244  int NumImportIDs,
245  int* ImportLIDs,
246  int LenImports,
247  char* Imports,
248  int& SizeOfPacket,
249  Epetra_Distributor& Distor,
250  Epetra_CombineMode CombineMode,
251  const Epetra_OffsetIndex * Indexor);
252 
253  Epetra_LAPACK LAPACK;
254  Teuchos::ParameterList List_;
255 
257  bool HasComputed_;
258 
260  int ApplyMode_;
261 
263  Epetra_BlockMap* DataMap_;
264 
266  double *Values_;
267 
269  int *Pivots_;
270 
271 }; /* EPETRAEXT_BLOCKDIAGMATRIX_H */
272 
273 #endif
virtual const Epetra_BlockMap & DataMap() const
Returns the Epetra_BlockMap object with the distribution of underlying values.
bool ConstantBlockSize() const
Returns true if the element size is constant.
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 NumGlobalUnknowns() const
Returns the number of global unknowns.
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 NumMyBlocks() const
Returns the number of local blocks.
double * Values() const
Returns a pointer to the array containing the blocks.
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
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.
int NumMyUnknowns() const
Returns the number of local unknowns.
EpetraExt_BlockDiagMatrix & operator=(const EpetraExt_BlockDiagMatrix &Source)
= Operator.
int NumGlobalBlocks() const
Returns the number of global blocks.
virtual double NormInf() const
NormInf - Not Implemented.
virtual ~EpetraExt_BlockDiagMatrix()
Destructor.
double * operator[](int index)
Block access function.
EpetraExt_BlockDiagMatrix: A class for storing distributed block matrices.
virtual void Print(ostream &os) const
Print method.
int BlockSize(int LID) const
Returns the size of the given block.
virtual int SetUseTranspose(bool UseTranspose)
SetUseTranspose - not implemented.
int NumData() const
Returns the size of the total Data block.
EpetraExt_BlockDiagMatrix(const Epetra_BlockMap &Map, bool zero_out=true)
Constructor - This map is the map of the vector this can be applied to.
virtual int Compute()
Computes the inverse / factorization if such is set on the list.
virtual int SetParameters(Teuchos::ParameterList &List)
SetParameters.
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
virtual const char * Label() const
Returns a character string describing the operator.
int DataSize(int LID) const
Returns the size of the data in the given block.
int GetApplyMode()
Gets apply mode info.
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
virtual const Epetra_BlockMap & BlockMap() const
Returns the Epetra_BlockMap object associated with the range of this operator.
void PutScalar(double value)
PutScalar function.