EpetraExt  Development
EpetraExt_CrsSingletonFilter_LinearProblem.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_LINEARPROBLEM_CRSSINGLETONFILTER_H_
43 #define _EpetraExt_LINEARPROBLEM_CRSSINGLETONFILTER_H_
44 
45 #include "Epetra_Object.h"
46 #include "Epetra_CrsMatrix.h"
47 #include "Epetra_MapColoring.h"
48 #include "Epetra_SerialDenseVector.h"
49 
50 #include "EpetraExt_Transform.h"
51 #include "Teuchos_RCP.hpp"
52 
53 class Epetra_LinearProblem;
54 class Epetra_Map;
55 class Epetra_MultiVector;
56 class Epetra_Import;
57 class Epetra_Export;
58 class Epetra_IntVector;
59 
60 namespace EpetraExt {
61 
63 
119 class LinearProblem_CrsSingletonFilter : public SameTypeTransform<Epetra_LinearProblem> {
120 
121  public:
122 
124  LinearProblem_CrsSingletonFilter( bool verbose = false );
126 
130 
133 
135  bool analyze( OriginalTypeRef orig );
136 
139 
141  bool fwd();
142 
144  bool rvs();
145 
147 
157  int Analyze(Epetra_RowMatrix * FullMatrix);
158 
160  bool SingletonsDetected() const {if (!AnalysisDone_) return(false); else return(NumSingletons()>0);};
162 
164 
170  int ConstructReducedProblem(Epetra_LinearProblem * Problem);
171 
173 
178  int UpdateReducedProblem(Epetra_LinearProblem * Problem);
179 
181 
182 
188  int ComputeFullSolution();
190 
191  int NumRowSingletons() const {return(NumGlobalRowSingletons_);};
193 
196 
198 
203  int NumSingletons() const {return(NumColSingletons()+NumRowSingletons());};
204 
206  double RatioOfDimensions() const {return(RatioOfDimensions_);};
207 
209  double RatioOfNonzeros() const {return(RatioOfNonzeros_);};
210 
212 
213 
215  Epetra_LinearProblem * FullProblem() const {return(FullProblem_);};
216 
218  Epetra_LinearProblem * ReducedProblem() const {return(ReducedProblem_.get());};
219 
221  Epetra_RowMatrix * FullMatrix() const {return(FullMatrix_);};
222 
224  Epetra_CrsMatrix * ReducedMatrix() const {return(ReducedMatrix_.get());};
225 
227  Epetra_MapColoring * RowMapColors() const {return(RowMapColors_);};
228 
230  Epetra_MapColoring * ColMapColors() const {return(ColMapColors_);};
231 
233  Epetra_Map * ReducedMatrixRowMap() const {return(ReducedMatrixRowMap_);};
234 
236  Epetra_Map * ReducedMatrixColMap() const {return(ReducedMatrixColMap_);};
237 
239  Epetra_Map * ReducedMatrixDomainMap() const {return(ReducedMatrixDomainMap_);};
240 
242  Epetra_Map * ReducedMatrixRangeMap() const {return(ReducedMatrixRangeMap_);};
244 
245  protected:
246 
247 
248 
249  // This pointer will be zero if full matrix is not a CrsMatrix.
250  Epetra_CrsMatrix * FullCrsMatrix() const {return(FullCrsMatrix_);};
251 
252  const Epetra_Map & FullMatrixRowMap() const {return(FullMatrix()->RowMatrixRowMap());};
253  const Epetra_Map & FullMatrixColMap() const {return(FullMatrix()->RowMatrixColMap());};
254  const Epetra_Map & FullMatrixDomainMap() const {return((FullMatrix()->OperatorDomainMap()));};
255  const Epetra_Map & FullMatrixRangeMap() const {return((FullMatrix()->OperatorRangeMap()));};
256  void InitializeDefaults();
257  int ComputeEliminateMaps();
258  int Setup(Epetra_LinearProblem * Problem);
259  int InitFullMatrixAccess();
260  int GetRow(int Row, int & NumIndices, int * & Indices);
261  int GetRowGCIDs(int Row, int & NumIndices, double * & Values, int * & GlobalIndices);
262  int GetRow(int Row, int & NumIndices, double * & Values, int * & Indices);
263  int CreatePostSolveArrays(const Epetra_IntVector & RowIDs,
264  const Epetra_MapColoring & RowMapColors,
265  const Epetra_IntVector & ColProfiles,
266  const Epetra_IntVector & NewColProfiles,
267  const Epetra_IntVector & ColHasRowWithSingleton);
268 
269  int ConstructRedistributeExporter(Epetra_Map * SourceMap, Epetra_Map * TargetMap,
270  Epetra_Export * & RedistributeExporter,
271  Epetra_Map * & RedistributeMap);
272 
273  Epetra_LinearProblem * FullProblem_;
274  Teuchos::RCP<Epetra_LinearProblem> ReducedProblem_;
275  Epetra_RowMatrix * FullMatrix_;
276  Epetra_CrsMatrix * FullCrsMatrix_;
277  Teuchos::RCP<Epetra_CrsMatrix> ReducedMatrix_;
278  Epetra_MultiVector * ReducedRHS_;
279  Epetra_MultiVector * ReducedLHS_;
280 
281  Epetra_Map * ReducedMatrixRowMap_;
282  Epetra_Map * ReducedMatrixColMap_;
286  Epetra_Import * Full2ReducedRHSImporter_;
287  Epetra_Import * Full2ReducedLHSImporter_;
289 
294 
295 
298 
305 
310 
311  Epetra_MultiVector * tempExportX_;
312  Epetra_MultiVector * tempX_;
313  Epetra_MultiVector * tempB_;
314  Epetra_MultiVector * RedistributeReducedLHS_;
315  int * Indices_;
316  Epetra_SerialDenseVector Values_;
317 
318  Epetra_MapColoring * RowMapColors_;
319  Epetra_MapColoring * ColMapColors_;
322 
323  bool verbose_;
324 
325 
326  private:
329 };
330 
331 } //namespace EpetraExt
332 
333 #endif /* _EpetraExt_LINEARPROBLEM_CRSSINGLETONFILTER_H_ */
int GetRowGCIDs(int Row, int &NumIndices, double *&Values, int *&GlobalIndices)
Epetra_Map * ReducedMatrixDomainMap() const
Returns pointer to Epetra_Map describing the domain map for the reduced system.
Epetra_Map * ReducedMatrixRangeMap() const
Returns pointer to Epetra_Map describing the range map for the reduced system.
double RatioOfDimensions() const
Returns ratio of reduced system to full system dimensions, returns -1.0 if reduced problem not constr...
NewTypeRef operator()(OriginalTypeRef orig)
Analysis of transform operation on original object and construction of new object.
bool fwd()
Forward transfer of data from orig object input in the operator() method call to the new object creat...
NewTypeRef construct()
Construction of new object as a result of the transform.
virtual ~LinearProblem_CrsSingletonFilter()
Epetra_CrsSingletonFilter Destructor.
bool rvs()
Reverse transfer of data from new object created in the operator() method call to the orig object inp...
EpetraExt::BlockCrsMatrix: A class for constructing a distributed block matrix.
bool SingletonsDetected() const
Returns true if singletons were detected in this matrix (must be called after Analyze() to be effecti...
int Analyze(Epetra_RowMatrix *FullMatrix)
Analyze the input matrix, removing row/column pairs that have singletons.
int Setup(Epetra_LinearProblem *Problem)
Epetra_CrsSingletonFilter: A class for explicitly eliminating matrix rows and columns.
Epetra_Map * ReducedMatrixRowMap() const
Returns pointer to Epetra_Map describing the reduced system row distribution.
Epetra_CrsMatrix * ReducedMatrix() const
Returns pointer to Epetra_CrsMatrix from full problem.
Epetra_MapColoring * RowMapColors() const
Returns pointer to Epetra_MapColoring object: color 0 rows are part of reduced system.
int ComputeFullSolution()
Compute a solution for the full problem using the solution of the reduced problem, put in LHS of FullProblem().
LinearProblem_CrsSingletonFilter(bool verbose=false)
Epetra_CrsSingletonFilter default constructor.
Epetra_LinearProblem * ReducedProblem() const
Returns pointer to the derived reduced Epetra_LinearProblem.
bool analyze(OriginalTypeRef orig)
Initial analysis phase of transform.
int NumRowSingletons() const
Return number of rows that contain a single entry, returns -1 if Analysis not performed yet...
double RatioOfNonzeros() const
Returns ratio of reduced system to full system nonzero count, returns -1.0 if reduced problem not con...
int ConstructRedistributeExporter(Epetra_Map *SourceMap, Epetra_Map *TargetMap, Epetra_Export *&RedistributeExporter, Epetra_Map *&RedistributeMap)
int CreatePostSolveArrays(const Epetra_IntVector &RowIDs, const Epetra_MapColoring &RowMapColors, const Epetra_IntVector &ColProfiles, const Epetra_IntVector &NewColProfiles, const Epetra_IntVector &ColHasRowWithSingleton)
Epetra_RowMatrix * FullMatrix() const
Returns pointer to Epetra_CrsMatrix from full problem.
int NumColSingletons() const
Return number of columns that contain a single entry that are not associated with singleton row...
int UpdateReducedProblem(Epetra_LinearProblem *Problem)
Update a reduced linear problem using new values.
Epetra_Map * ReducedMatrixColMap() const
Returns pointer to Epetra_Map describing the reduced system column distribution.
int ConstructReducedProblem(Epetra_LinearProblem *Problem)
Return a reduced linear problem based on results of Analyze().
Epetra_LinearProblem * FullProblem() const
Returns pointer to the original unreduced Epetra_LinearProblem.
int NumSingletons() const
Return total number of singletons detected, returns -1 if Analysis not performed yet.
Epetra_MapColoring * ColMapColors() const
Returns pointer to Epetra_MapColoring object: color 0 columns are part of reduced system...