EpetraExt  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EpetraExt_LPTrans_From_GraphTrans.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( MatExporter_ ) delete MatExporter_;
61  if( VecExporter_ ) delete VecExporter_;
62  if( Importer_ ) delete Importer_;
63 
64  if( NewProblem_ ) delete NewProblem_;
65  if( NewRHS_ ) delete NewRHS_;
66  if( NewLHS_ ) delete NewLHS_;
67  if( NewMatrix_ ) delete NewMatrix_;
68 }
69 
73 {
74  OldProblem_ = &orig;
75  OldMatrix_ = dynamic_cast<Epetra_CrsMatrix*>( orig.GetMatrix() );
76  OldGraph_ = const_cast<Epetra_CrsGraph*>(&OldMatrix_->Graph());
77  OldRHS_ = orig.GetRHS();
78  OldLHS_ = orig.GetLHS();
79  OldRowMap_ = const_cast<Epetra_Map*>(&OldMatrix_->RowMap());
80 
81  int ierr = 0;
82 
83 
84  if( !OldMatrix_ ) ierr = -2;
85  if( !OldRHS_ ) ierr = -3;
86  if( !OldLHS_ ) ierr = -4;
87 
88  Epetra_CrsGraph & NewGraph = graphTrans_( *OldGraph_ );
89  NewMatrix_ = new Epetra_CrsMatrix( Copy, NewGraph );
90 
91  Epetra_BlockMap & NewRowMap = const_cast<Epetra_BlockMap&>(NewGraph.RowMap());
92 
93  NewRHS_ = new Epetra_MultiVector( NewRowMap, 1 );
94  NewLHS_ = new Epetra_MultiVector( NewRowMap, 1 );
95 
96  MatExporter_ = new Epetra_Export( *OldRowMap_, NewRowMap );
97  VecExporter_ = new Epetra_Export( *OldRowMap_, NewRowMap );
98  Importer_ = new Epetra_Import( *OldRowMap_, NewRowMap );
99 
100  NewProblem_ = new Epetra_LinearProblem( NewMatrix_, NewLHS_, NewRHS_ );
101 
102  return *NewProblem_;
103 }
104 
105 bool
108 {
109  NewLHS_->Export( *OldLHS_, *VecExporter_, Insert );
110  NewRHS_->Export( *OldRHS_, *VecExporter_, Insert );
111  NewMatrix_->Export( *OldMatrix_, *MatExporter_, Insert );
112 
113  return true;
114 }
115 
116 bool
119 {
120  OldLHS_->Import( *NewLHS_, *Importer_, Insert );
121 // OldRHS_->Import( *NewRHS_, *Importer_, Insert );
122 // OldMatrix_->Import( *NewMatrix_, *Importer_, Insert );
123 
124  return true;
125 }
126 
127 } //namespace EpetraExt
128 
NewTypeRef operator()(OriginalTypeRef orig)
Constructs an Epetra_LinearProblem from the original using the same row transformation given by the E...
bool fwd()
Forward migration of data from original to transformed object.
bool rvs()
Reverse migration of data from transformed to original object.
~LinearProblem_GraphTrans()
EpetraExt::LinearProblem_GraphTrans Destructor.