EpetraExt  Development
EpetraExt_readEpetraLinearSystem.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 #include "Trilinos_Util.h"
44 
46  const std::string &fileName
47  ,const Epetra_Comm &comm
48  ,Teuchos::RefCountPtr<Epetra_CrsMatrix> *A
49  ,Teuchos::RefCountPtr<Epetra_Map> *map
50  ,Teuchos::RefCountPtr<Epetra_Vector> *x
51  ,Teuchos::RefCountPtr<Epetra_Vector> *b
52  ,Teuchos::RefCountPtr<Epetra_Vector> *xExact
53  )
54 {
55 
56  Epetra_Map *readMap;
57  Epetra_CrsMatrix *readA;
58  Epetra_Vector *readx;
59  Epetra_Vector *readb;
60  Epetra_Vector *readxexact;
61 
62  const std::string::size_type ext_dot = fileName.rfind(".");
63  TEUCHOS_TEST_FOR_EXCEPT( ext_dot == std::string::npos );
64  std::string ext = fileName.substr(ext_dot+1);
65  //std::cout << "\nfileName = " << fileName << "\next = " << ext << std::endl;
66 
67  char *hacked_file_str = const_cast<char*>(fileName.c_str());
68 
69  if ( ext == "triU" ) {
70  const bool NonContiguousMap = true;
71  TEUCHOS_TEST_FOR_EXCEPT(
72  0!=Trilinos_Util_ReadTriples2Epetra(
73  hacked_file_str, false, comm, readMap, readA, readx,
74  readb, readxexact, NonContiguousMap
75  )
76  );
77  }
78  else if ( ext == "triS" ) {
79  const bool NonContiguousMap = true;
80  TEUCHOS_TEST_FOR_EXCEPT(
81  0!=Trilinos_Util_ReadTriples2Epetra(
82  hacked_file_str, true, comm, readMap, readA, readx,
83  readb, readxexact, NonContiguousMap
84  )
85  );
86  }
87  else if( ext == "mtx" ) {
88  TEUCHOS_TEST_FOR_EXCEPT(
89  0!=Trilinos_Util_ReadMatrixMarket2Epetra(
90  hacked_file_str, comm, readMap,
91  readA, readx, readb, readxexact
92  )
93  );
94  }
95  else if ( ext == "hb" ) {
96  Trilinos_Util_ReadHb2Epetra(
97  hacked_file_str, comm, readMap, readA, readx,
98  readb, readxexact
99  ); // No error return???
100  }
101  else {
102  TEUCHOS_TEST_FOR_EXCEPTION(
103  true, std::logic_error
104  ,"Error, the file = \'"<<hacked_file_str<<"\' has the extension "
105  "\'*."<<ext<<"\' is not \'*.triU\', \'*.triS\', \'*.mtx\', or \'*.hb\'!"
106  );
107  }
108 
109  Teuchos::RefCountPtr<Epetra_CrsMatrix> loc_A = Teuchos::rcp(readA);
110  Teuchos::RefCountPtr<Epetra_Map> loc_map = Teuchos::rcp(readMap);
111  Teuchos::RefCountPtr<Epetra_Vector> loc_x = Teuchos::rcp(readx);
112  Teuchos::RefCountPtr<Epetra_Vector> loc_b = Teuchos::rcp(readb);
113  Teuchos::RefCountPtr<Epetra_Vector> loc_xExact = Teuchos::rcp(readxexact);
114 
115  if(A) *A = loc_A;
116  if(map) *map = loc_map;
117  if(x) *x = loc_x;
118  if(b) *b = loc_b;
119  if(xExact) *xExact = loc_xExact;
120 
121 }
void readEpetraLinearSystem(const std::string &fileName, const Epetra_Comm &comm, Teuchos::RefCountPtr< Epetra_CrsMatrix > *A=NULL, Teuchos::RefCountPtr< Epetra_Map > *map=NULL, Teuchos::RefCountPtr< Epetra_Vector > *x=NULL, Teuchos::RefCountPtr< Epetra_Vector > *b=NULL, Teuchos::RefCountPtr< Epetra_Vector > *xExact=NULL)
Read in an Epetra linear system from a file.