00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "EpetraExt_readEpetraLinearSystem.h"
00030 #include "Trilinos_Util.h"
00031
00032 void EpetraExt::readEpetraLinearSystem(
00033 const std::string &fileName
00034 ,const Epetra_Comm &comm
00035 ,Teuchos::RefCountPtr<Epetra_CrsMatrix> *A
00036 ,Teuchos::RefCountPtr<Epetra_Map> *map
00037 ,Teuchos::RefCountPtr<Epetra_Vector> *x
00038 ,Teuchos::RefCountPtr<Epetra_Vector> *b
00039 ,Teuchos::RefCountPtr<Epetra_Vector> *xExact
00040 )
00041 {
00042
00043 Epetra_Map *readMap;
00044 Epetra_CrsMatrix *readA;
00045 Epetra_Vector *readx;
00046 Epetra_Vector *readb;
00047 Epetra_Vector *readxexact;
00048
00049 const std::string::size_type ext_dot = fileName.rfind(".");
00050 TEST_FOR_EXCEPT( ext_dot == std::string::npos );
00051 std::string ext = fileName.substr(ext_dot+1);
00052
00053
00054 char *hacked_file_str = const_cast<char*>(fileName.c_str());
00055
00056 if ( ext == "triU" ) {
00057 const bool NonContiguousMap = true;
00058 TEST_FOR_EXCEPT(
00059 0!=Trilinos_Util_ReadTriples2Epetra(
00060 hacked_file_str, false, comm, readMap, readA, readx,
00061 readb, readxexact, NonContiguousMap
00062 )
00063 );
00064 }
00065 else if ( ext == "triS" ) {
00066 const bool NonContiguousMap = true;
00067 TEST_FOR_EXCEPT(
00068 0!=Trilinos_Util_ReadTriples2Epetra(
00069 hacked_file_str, true, comm, readMap, readA, readx,
00070 readb, readxexact, NonContiguousMap
00071 )
00072 );
00073 }
00074 else if( ext == "mtx" ) {
00075 TEST_FOR_EXCEPT(
00076 0!=Trilinos_Util_ReadMatrixMarket2Epetra(
00077 hacked_file_str, comm, readMap,
00078 readA, readx, readb, readxexact
00079 )
00080 );
00081 }
00082 else if ( ext == "hb" ) {
00083 Trilinos_Util_ReadHb2Epetra(
00084 hacked_file_str, comm, readMap, readA, readx,
00085 readb, readxexact
00086 );
00087 }
00088 else {
00089 TEST_FOR_EXCEPTION(
00090 true, std::logic_error
00091 ,"Error, the file = \'"<<hacked_file_str<<"\' has the extension "
00092 "\'*."<<ext<<"\' is not \'*.triU\', \'*.triS\', \'*.mtx\', or \'*.hb\'!"
00093 );
00094 }
00095
00096 Teuchos::RefCountPtr<Epetra_CrsMatrix> loc_A = Teuchos::rcp(readA);
00097 Teuchos::RefCountPtr<Epetra_Map> loc_map = Teuchos::rcp(readMap);
00098 Teuchos::RefCountPtr<Epetra_Vector> loc_x = Teuchos::rcp(readx);
00099 Teuchos::RefCountPtr<Epetra_Vector> loc_b = Teuchos::rcp(readb);
00100 Teuchos::RefCountPtr<Epetra_Vector> loc_xExact = Teuchos::rcp(readxexact);
00101
00102 if(A) *A = loc_A;
00103 if(map) *map = loc_map;
00104 if(x) *x = loc_x;
00105 if(b) *b = loc_b;
00106 if(xExact) *xExact = loc_xExact;
00107
00108 }