EpetraExt Package Browser (Single Doxygen Collection) Development
Loading...
Searching...
No Matches
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
42#include "Epetra_ConfigDefs.h"
44#include "Trilinos_Util.h"
45
46#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
48 const std::string &fileName
49 ,const Epetra_Comm &comm
50 ,Teuchos::RCP<Epetra_CrsMatrix> *A
51 ,Teuchos::RCP<Epetra_Map> *map
52 ,Teuchos::RCP<Epetra_Vector> *x
53 ,Teuchos::RCP<Epetra_Vector> *b
54 ,Teuchos::RCP<Epetra_Vector> *xExact
55 )
56{
57
58 Epetra_Map *readMap;
59 Epetra_CrsMatrix *readA;
60 Epetra_Vector *readx;
61 Epetra_Vector *readb;
62 Epetra_Vector *readxexact;
63
64 const std::string::size_type ext_dot = fileName.rfind(".");
65 TEUCHOS_TEST_FOR_EXCEPT( ext_dot == std::string::npos );
66 std::string ext = fileName.substr(ext_dot+1);
67 //std::cout << "\nfileName = " << fileName << "\next = " << ext << std::endl;
68
69 char *hacked_file_str = const_cast<char*>(fileName.c_str());
70
71 if ( ext == "triU" ) {
72 const bool NonContiguousMap = true;
73 TEUCHOS_TEST_FOR_EXCEPT(
74 0!=Trilinos_Util_ReadTriples2Epetra(
75 hacked_file_str, false, comm, readMap, readA, readx,
76 readb, readxexact, NonContiguousMap
77 )
78 );
79 }
80 else if ( ext == "triS" ) {
81 const bool NonContiguousMap = true;
82 TEUCHOS_TEST_FOR_EXCEPT(
83 0!=Trilinos_Util_ReadTriples2Epetra(
84 hacked_file_str, true, comm, readMap, readA, readx,
85 readb, readxexact, NonContiguousMap
86 )
87 );
88 }
89 else if( ext == "mtx" ) {
90 TEUCHOS_TEST_FOR_EXCEPT(
91 0!=Trilinos_Util_ReadMatrixMarket2Epetra(
92 hacked_file_str, comm, readMap,
93 readA, readx, readb, readxexact
94 )
95 );
96 }
97 else if ( ext == "hb" ) {
98 Trilinos_Util_ReadHb2Epetra(
99 hacked_file_str, comm, readMap, readA, readx,
100 readb, readxexact
101 ); // No error return???
102 }
103 else {
104 TEUCHOS_TEST_FOR_EXCEPTION(
105 true, std::logic_error
106 ,"Error, the file = \'"<<hacked_file_str<<"\' has the extension "
107 "\'*."<<ext<<"\' is not \'*.triU\', \'*.triS\', \'*.mtx\', or \'*.hb\'!"
108 );
109 }
110
111 Teuchos::RCP<Epetra_CrsMatrix> loc_A = Teuchos::rcp(readA);
112 Teuchos::RCP<Epetra_Map> loc_map = Teuchos::rcp(readMap);
113 Teuchos::RCP<Epetra_Vector> loc_x = Teuchos::rcp(readx);
114 Teuchos::RCP<Epetra_Vector> loc_b = Teuchos::rcp(readb);
115 Teuchos::RCP<Epetra_Vector> loc_xExact = Teuchos::rcp(readxexact);
116
117 if(A) *A = loc_A;
118 if(map) *map = loc_map;
119 if(x) *x = loc_x;
120 if(b) *b = loc_b;
121 if(xExact) *xExact = loc_xExact;
122
123}
124#endif
125
126#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
128 const std::string &fileName
129 ,const Epetra_Comm &comm
130 ,Teuchos::RCP<Epetra_CrsMatrix> *A
131 ,Teuchos::RCP<Epetra_Map> *map
132 ,Teuchos::RCP<Epetra_Vector> *x
133 ,Teuchos::RCP<Epetra_Vector> *b
134 ,Teuchos::RCP<Epetra_Vector> *xExact
135 )
136{
137
138 Epetra_Map *readMap;
139 Epetra_CrsMatrix *readA;
140 Epetra_Vector *readx;
141 Epetra_Vector *readb;
142 Epetra_Vector *readxexact;
143
144 const std::string::size_type ext_dot = fileName.rfind(".");
145 TEUCHOS_TEST_FOR_EXCEPT( ext_dot == std::string::npos );
146 std::string ext = fileName.substr(ext_dot+1);
147 //std::cout << "\nfileName = " << fileName << "\next = " << ext << std::endl;
148
149 char *hacked_file_str = const_cast<char*>(fileName.c_str());
150
151 if ( ext == "triU" ) {
152 const bool NonContiguousMap = true;
153 TEUCHOS_TEST_FOR_EXCEPT(
154 0!=Trilinos_Util_ReadTriples2Epetra64(
155 hacked_file_str, false, comm, readMap, readA, readx,
156 readb, readxexact, NonContiguousMap
157 )
158 );
159 }
160 else if ( ext == "triS" ) {
161 const bool NonContiguousMap = true;
162 TEUCHOS_TEST_FOR_EXCEPT(
163 0!=Trilinos_Util_ReadTriples2Epetra64(
164 hacked_file_str, true, comm, readMap, readA, readx,
165 readb, readxexact, NonContiguousMap
166 )
167 );
168 }
169 else if( ext == "mtx" ) {
170 TEUCHOS_TEST_FOR_EXCEPT(
171 0!=Trilinos_Util_ReadMatrixMarket2Epetra64(
172 hacked_file_str, comm, readMap,
173 readA, readx, readb, readxexact
174 )
175 );
176 }
177 else if ( ext == "hb" ) {
178 Trilinos_Util_ReadHb2Epetra64(
179 hacked_file_str, comm, readMap, readA, readx,
180 readb, readxexact
181 ); // No error return???
182 }
183 else {
184 TEUCHOS_TEST_FOR_EXCEPTION(
185 true, std::logic_error
186 ,"Error, the file = \'"<<hacked_file_str<<"\' has the extension "
187 "\'*."<<ext<<"\' is not \'*.triU\', \'*.triS\', \'*.mtx\', or \'*.hb\'!"
188 );
189 }
190
191 Teuchos::RCP<Epetra_CrsMatrix> loc_A = Teuchos::rcp(readA);
192 Teuchos::RCP<Epetra_Map> loc_map = Teuchos::rcp(readMap);
193 Teuchos::RCP<Epetra_Vector> loc_x = Teuchos::rcp(readx);
194 Teuchos::RCP<Epetra_Vector> loc_b = Teuchos::rcp(readb);
195 Teuchos::RCP<Epetra_Vector> loc_xExact = Teuchos::rcp(readxexact);
196
197 if(A) *A = loc_A;
198 if(map) *map = loc_map;
199 if(x) *x = loc_x;
200 if(b) *b = loc_b;
201 if(xExact) *xExact = loc_xExact;
202
203}
204#endif
void readEpetraLinearSystem64(const std::string &fileName, const Epetra_Comm &comm, Teuchos::RCP< Epetra_CrsMatrix > *A=NULL, Teuchos::RCP< Epetra_Map > *map=NULL, Teuchos::RCP< Epetra_Vector > *x=NULL, Teuchos::RCP< Epetra_Vector > *b=NULL, Teuchos::RCP< Epetra_Vector > *xExact=NULL)
void readEpetraLinearSystem(const std::string &fileName, const Epetra_Comm &comm, Teuchos::RCP< Epetra_CrsMatrix > *A=NULL, Teuchos::RCP< Epetra_Map > *map=NULL, Teuchos::RCP< Epetra_Vector > *x=NULL, Teuchos::RCP< Epetra_Vector > *b=NULL, Teuchos::RCP< Epetra_Vector > *xExact=NULL)
Read in an Epetra linear system from a file.