|
EpetraExt
Development
|
00001 //@HEADER 00002 // *********************************************************************** 00003 // 00004 // EpetraExt: Epetra Extended - Linear Algebra Services Package 00005 // Copyright (2011) Sandia Corporation 00006 // 00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00008 // the U.S. Government retains certain rights in this software. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 //@HEADER 00041 00042 #include "Epetra_ConfigDefs.h" 00043 #include "EpetraExt_readEpetraLinearSystem.h" 00044 #include "Trilinos_Util.h" 00045 00046 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 00047 void EpetraExt::readEpetraLinearSystem( 00048 const std::string &fileName 00049 ,const Epetra_Comm &comm 00050 ,Teuchos::RefCountPtr<Epetra_CrsMatrix> *A 00051 ,Teuchos::RefCountPtr<Epetra_Map> *map 00052 ,Teuchos::RefCountPtr<Epetra_Vector> *x 00053 ,Teuchos::RefCountPtr<Epetra_Vector> *b 00054 ,Teuchos::RefCountPtr<Epetra_Vector> *xExact 00055 ) 00056 { 00057 00058 Epetra_Map *readMap; 00059 Epetra_CrsMatrix *readA; 00060 Epetra_Vector *readx; 00061 Epetra_Vector *readb; 00062 Epetra_Vector *readxexact; 00063 00064 const std::string::size_type ext_dot = fileName.rfind("."); 00065 TEUCHOS_TEST_FOR_EXCEPT( ext_dot == std::string::npos ); 00066 std::string ext = fileName.substr(ext_dot+1); 00067 //std::cout << "\nfileName = " << fileName << "\next = " << ext << std::endl; 00068 00069 char *hacked_file_str = const_cast<char*>(fileName.c_str()); 00070 00071 if ( ext == "triU" ) { 00072 const bool NonContiguousMap = true; 00073 TEUCHOS_TEST_FOR_EXCEPT( 00074 0!=Trilinos_Util_ReadTriples2Epetra( 00075 hacked_file_str, false, comm, readMap, readA, readx, 00076 readb, readxexact, NonContiguousMap 00077 ) 00078 ); 00079 } 00080 else if ( ext == "triS" ) { 00081 const bool NonContiguousMap = true; 00082 TEUCHOS_TEST_FOR_EXCEPT( 00083 0!=Trilinos_Util_ReadTriples2Epetra( 00084 hacked_file_str, true, comm, readMap, readA, readx, 00085 readb, readxexact, NonContiguousMap 00086 ) 00087 ); 00088 } 00089 else if( ext == "mtx" ) { 00090 TEUCHOS_TEST_FOR_EXCEPT( 00091 0!=Trilinos_Util_ReadMatrixMarket2Epetra( 00092 hacked_file_str, comm, readMap, 00093 readA, readx, readb, readxexact 00094 ) 00095 ); 00096 } 00097 else if ( ext == "hb" ) { 00098 Trilinos_Util_ReadHb2Epetra( 00099 hacked_file_str, comm, readMap, readA, readx, 00100 readb, readxexact 00101 ); // No error return??? 00102 } 00103 else { 00104 TEUCHOS_TEST_FOR_EXCEPTION( 00105 true, std::logic_error 00106 ,"Error, the file = \'"<<hacked_file_str<<"\' has the extension " 00107 "\'*."<<ext<<"\' is not \'*.triU\', \'*.triS\', \'*.mtx\', or \'*.hb\'!" 00108 ); 00109 } 00110 00111 Teuchos::RefCountPtr<Epetra_CrsMatrix> loc_A = Teuchos::rcp(readA); 00112 Teuchos::RefCountPtr<Epetra_Map> loc_map = Teuchos::rcp(readMap); 00113 Teuchos::RefCountPtr<Epetra_Vector> loc_x = Teuchos::rcp(readx); 00114 Teuchos::RefCountPtr<Epetra_Vector> loc_b = Teuchos::rcp(readb); 00115 Teuchos::RefCountPtr<Epetra_Vector> loc_xExact = Teuchos::rcp(readxexact); 00116 00117 if(A) *A = loc_A; 00118 if(map) *map = loc_map; 00119 if(x) *x = loc_x; 00120 if(b) *b = loc_b; 00121 if(xExact) *xExact = loc_xExact; 00122 00123 } 00124 #endif 00125 00126 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 00127 void EpetraExt::readEpetraLinearSystem64( 00128 const std::string &fileName 00129 ,const Epetra_Comm &comm 00130 ,Teuchos::RefCountPtr<Epetra_CrsMatrix> *A 00131 ,Teuchos::RefCountPtr<Epetra_Map> *map 00132 ,Teuchos::RefCountPtr<Epetra_Vector> *x 00133 ,Teuchos::RefCountPtr<Epetra_Vector> *b 00134 ,Teuchos::RefCountPtr<Epetra_Vector> *xExact 00135 ) 00136 { 00137 00138 Epetra_Map *readMap; 00139 Epetra_CrsMatrix *readA; 00140 Epetra_Vector *readx; 00141 Epetra_Vector *readb; 00142 Epetra_Vector *readxexact; 00143 00144 const std::string::size_type ext_dot = fileName.rfind("."); 00145 TEUCHOS_TEST_FOR_EXCEPT( ext_dot == std::string::npos ); 00146 std::string ext = fileName.substr(ext_dot+1); 00147 //std::cout << "\nfileName = " << fileName << "\next = " << ext << std::endl; 00148 00149 char *hacked_file_str = const_cast<char*>(fileName.c_str()); 00150 00151 if ( ext == "triU" ) { 00152 const bool NonContiguousMap = true; 00153 TEUCHOS_TEST_FOR_EXCEPT( 00154 0!=Trilinos_Util_ReadTriples2Epetra64( 00155 hacked_file_str, false, comm, readMap, readA, readx, 00156 readb, readxexact, NonContiguousMap 00157 ) 00158 ); 00159 } 00160 else if ( ext == "triS" ) { 00161 const bool NonContiguousMap = true; 00162 TEUCHOS_TEST_FOR_EXCEPT( 00163 0!=Trilinos_Util_ReadTriples2Epetra64( 00164 hacked_file_str, true, comm, readMap, readA, readx, 00165 readb, readxexact, NonContiguousMap 00166 ) 00167 ); 00168 } 00169 else if( ext == "mtx" ) { 00170 TEUCHOS_TEST_FOR_EXCEPT( 00171 0!=Trilinos_Util_ReadMatrixMarket2Epetra64( 00172 hacked_file_str, comm, readMap, 00173 readA, readx, readb, readxexact 00174 ) 00175 ); 00176 } 00177 else if ( ext == "hb" ) { 00178 Trilinos_Util_ReadHb2Epetra64( 00179 hacked_file_str, comm, readMap, readA, readx, 00180 readb, readxexact 00181 ); // No error return??? 00182 } 00183 else { 00184 TEUCHOS_TEST_FOR_EXCEPTION( 00185 true, std::logic_error 00186 ,"Error, the file = \'"<<hacked_file_str<<"\' has the extension " 00187 "\'*."<<ext<<"\' is not \'*.triU\', \'*.triS\', \'*.mtx\', or \'*.hb\'!" 00188 ); 00189 } 00190 00191 Teuchos::RefCountPtr<Epetra_CrsMatrix> loc_A = Teuchos::rcp(readA); 00192 Teuchos::RefCountPtr<Epetra_Map> loc_map = Teuchos::rcp(readMap); 00193 Teuchos::RefCountPtr<Epetra_Vector> loc_x = Teuchos::rcp(readx); 00194 Teuchos::RefCountPtr<Epetra_Vector> loc_b = Teuchos::rcp(readb); 00195 Teuchos::RefCountPtr<Epetra_Vector> loc_xExact = Teuchos::rcp(readxexact); 00196 00197 if(A) *A = loc_A; 00198 if(map) *map = loc_map; 00199 if(x) *x = loc_x; 00200 if(b) *b = loc_b; 00201 if(xExact) *xExact = loc_xExact; 00202 00203 } 00204 #endif
1.7.6.1