EpetraExt Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EpetraExt_LPTrans_From_MatrixTrans.cpp
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 
43 
44 #include <Epetra_Export.h>
45 #include <Epetra_Import.h>
46 #include <Epetra_LinearProblem.h>
47 #include <Epetra_CrsGraph.h>
48 #include <Epetra_CrsMatrix.h>
49 #include <Epetra_MultiVector.h>
50 #include <Epetra_Vector.h>
51 #include <Epetra_IntVector.h>
52 #include <Epetra_Map.h>
53 #include <Epetra_Comm.h>
54 
55 namespace EpetraExt {
56 
59 {
60  if( Exporter_ ) delete Exporter_;
61  if( Importer_ ) delete Importer_;
62 
63  if( NewProblem_ ) delete NewProblem_;
64  if( NewRHS_ ) delete NewRHS_;
65  if( NewLHS_ ) delete NewLHS_;
66 }
67 
71 {
72  OldProblem_ = &orig;
73  OldMatrix_ = dynamic_cast<Epetra_CrsMatrix*>( orig.GetMatrix() );
74  OldRHS_ = orig.GetRHS();
75  OldLHS_ = orig.GetLHS();
76  OldRowMap_ = const_cast<Epetra_Map*>(&OldMatrix_->RowMap());
77 
78  int ierr = 0;
79  (void) ierr; // forestall "variable set but unused" warning
80 
81  if( !OldMatrix_ ) ierr = -2;
82  if( !OldRHS_ ) ierr = -3;
83  if( !OldLHS_ ) ierr = -4;
84 
86 
87  Epetra_BlockMap & NewRowMap = const_cast<Epetra_BlockMap&>(NewMatrix_->Graph().RowMap());
88 
89  NewRHS_ = new Epetra_MultiVector( NewRowMap, 1 );
90  NewLHS_ = new Epetra_MultiVector( NewRowMap, 1 );
91 
92  Exporter_ = new Epetra_Export( *OldRowMap_, NewRowMap );
93  Importer_ = new Epetra_Import( NewRowMap, *OldRowMap_ );
94 
96 
97  return *NewProblem_;
98 }
99 
100 bool
103 {
104  NewLHS_->Export( *OldLHS_, *Exporter_, Insert );
105  NewRHS_->Export( *OldRHS_, *Exporter_, Insert );
106  NewMatrix_->Export( *OldMatrix_, *Exporter_, Insert );
107 
108  return true;
109 }
110 
111 bool
114 {
115  OldLHS_->Import( *NewLHS_, *Exporter_, Insert );
116  OldRHS_->Import( *NewRHS_, *Exporter_, Insert );
117  OldMatrix_->Import( *NewMatrix_, *Exporter_, Insert );
118 
119  return true;
120 }
121 
122 } //namespace EpetraExt
123 
SameTypeTransform< Epetra_CrsMatrix > & matrixTrans_
NewTypeRef operator()(OriginalTypeRef orig)
Transform Operator.
const Epetra_Map & RowMap() const
const Epetra_BlockMap & RowMap() const
const Epetra_CrsGraph & Graph() const