EpetraExt_readEpetraLinearSystem.cpp

Go to the documentation of this file.
00001 //@HEADER
00002 // ***********************************************************************
00003 // 
00004 //     EpetraExt: Epetra Extended - Linear Algebra Services Package
00005 //                 Copyright (2001) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 //@HEADER
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   //std::cout << "\nfileName = " << fileName << "\next = " << ext << std::endl;
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       ); // No error return???
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 }

Generated on Tue Oct 20 12:45:30 2009 for EpetraExt by doxygen 1.4.7