test_FEI.cpp

00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 
00010 #include <fei_sstream.hpp>
00011 #include <snl_fei_Utils.hpp>
00012 #include <test_utils/test_FEI.hpp>
00013 
00014 #include <test_utils/fei_test_utils.hpp>
00015 #include <test_utils/LibraryFactory.hpp>
00016 
00017 #include <fei_ParameterSet.hpp>
00018 #include <fei_utils.hpp>
00019 #include <test_utils/DataReader.hpp>
00020 #include <test_utils/FEI_tester.hpp>     //FEI_tester tests the "old" FEI.
00021 #include <test_utils/snl_fei_tester.hpp> //snl_fei_tester tests the "new" fei
00022 
00023 #undef fei_file
00024 #define fei_file "test_FEI.cpp"
00025 #include <fei_ErrMacros.hpp>
00026 
00027 test_FEI::test_FEI(MPI_Comm comm)
00028   : tester(comm),
00029     fileName_()
00030 {
00031 }
00032 
00033 test_FEI::~test_FEI()
00034 {
00035 }
00036 
00037 int test_FEI::runtests()
00038 {
00039   if (fileName_.empty()) return(-1);
00040 
00041   CHK_ERR( test1() );
00042   return(0);
00043 }
00044 
00045 int test_FEI::test1()
00046 {
00047   fei::SharedPtr<fei::ParameterSet> test_params = get_test_parameters();
00048 
00049   int errcode = 0;
00050 
00051   int numSolves = 0;
00052   errcode = test_params->getIntParamValue("NUM_SOLVES", numSolves);
00053 
00054   std::string solverName;
00055   errcode = test_params->getStringParamValue("SOLVER_LIBRARY", solverName);
00056   if (errcode != 0) {
00057     throw std::runtime_error(".input file doesn't contain 'SOLVER_LIBRARY'");
00058   }
00059 
00060   std::string whichFEI;
00061   errcode = test_params->getStringParamValue("WHICH_FEI", whichFEI);
00062   if (errcode != 0) {
00063     throw std::runtime_error(".input file doesn't contain 'WHICH_FEI'");
00064   }
00065 
00066   std::string inputFileName;
00067   errcode = test_params->getStringParamValue("INPUT_FILE",inputFileName);
00068   if (errcode != 0) {
00069     throw std::runtime_error(".input file doesn't contain 'INPUT_FILE'");
00070   }
00071 
00072   std::string paramFile;
00073   errcode = test_params->getStringParamValue("PARAM_FILE", paramFile);
00074   if (errcode != 0) {
00075     throw std::runtime_error(".input file doesn't contain 'PARAM_FILE'");
00076   }
00077 
00078   std::string solnFile;
00079   errcode = test_params->getStringParamValue("SOLN_FILE", solnFile);
00080   if (errcode != 0) {
00081     throw std::runtime_error(".input file doesn't contain 'SOLN_FILE'");
00082   }
00083 
00084   std::string checkFile;
00085   errcode = test_params->getStringParamValue("CHECK_FILE", checkFile);
00086   if (errcode != 0) {
00087     throw std::runtime_error(".input file doesn't contain 'CHECK_FILE'");
00088   }
00089 
00090   std::string readerType;
00091   errcode = test_params->getStringParamValue("READER_TYPE", readerType);
00092 
00093   fei::SharedPtr<feitester> fei_tester;
00094 
00095   FEI_OSTRINGSTREAM fullName;
00096   std::string fullInputFileName = fully_qualified_name(inputFileName);
00097   fullName<< fullInputFileName<<"."<< numProcs_<<"."<< localProc_;
00098 
00099   std::string fullName_str = fullName.str();
00100   const char* fullName_c_str = fullName_str.c_str();
00101 
00102   fei::SharedPtr<DataReader> data_reader(new DataReader);
00103 
00104   //let's read all the data out of the input file.
00105   CHK_ERR( data_reader->readData(fullName_c_str));
00106 
00107   //now we'll get the parameters out of another file.
00108   std::string fullParamFileName = fully_qualified_name(paramFile);
00109   const char* paramFile_c_str = fullParamFileName.c_str();
00110 
00111   std::vector<std::string> param_file_contents;
00112   fei_test_utils::read_input_file(paramFile_c_str, comm_,
00113                                   param_file_contents);
00114 
00115   data_reader->numParams_ = param_file_contents.size();
00116   data_reader->paramStrings_ = new char*[data_reader->numParams_];
00117 
00118   for(unsigned i=0; i<param_file_contents.size(); ++i) {
00119     std::string& str = param_file_contents[i];
00120     data_reader->paramStrings_[i] = new char[str.size()+1];
00121     for(unsigned j=0; j<str.size(); ++j) {
00122       data_reader->paramStrings_[i][j] = str[j];
00123     }
00124     data_reader->paramStrings_[i][str.size()] = '\0';
00125   }
00126 
00127   data_reader->solverLibraryName_ = solverName;
00128 
00129   std::string fullSolnFile = fully_qualified_name(solnFile);
00130   data_reader->solnFileName_ = fullSolnFile;
00131 
00132   std::string fullCheckFile = fully_qualified_name(checkFile);
00133   data_reader->checkFileName_ = fullCheckFile;
00134 
00135   //ok, all the data is in the 'data' object, so we're ready to start
00136   //handing it all over to an instantiation of the FEI.
00137 
00138   if (whichFEI == "OLDFEI") {
00139     fei_tester.reset(new FEI_tester(data_reader, comm_, localProc_, numProcs_));
00140   }
00141   if (whichFEI == "fei::FEI_Impl") {
00142     bool useNewFEI = true;
00143     fei_tester.reset(new FEI_tester(data_reader, comm_, localProc_, numProcs_,
00144                   useNewFEI));
00145   }
00146   else if (whichFEI == "new_fei") {
00147     fei_tester.reset( new snl_fei_tester(data_reader, comm_, localProc_, numProcs_));
00148   }
00149 
00150   if (fei_tester.get() == NULL) {
00151     ERReturn(-1);
00152   }
00153 
00154   fei_tester->setPath(path_);
00155 
00156   int errCode = fei_tester->testInitialization();
00157   if (errCode < 0) {
00158     ERReturn(errCode);
00159   }
00160   if (errCode > 0) {
00161     FEI_COUT << "library " << solverName << " not available."<<FEI_ENDL;
00162     return(-1);
00163   }
00164 
00165   for(int solveCounter=1; solveCounter<=numSolves; solveCounter++) {
00166 
00167     CHK_ERR( fei_tester->testLoading() );
00168 
00169 //    if (solverName == "Trilinos") {
00170 //      fei_tester->dumpMatrixFiles();
00171 //      fei_tester->setParameter("USE_FEI_MATRIX_LOCAL true");
00172 //      fei_tester->testLoading();
00173 //      fei_tester->dumpMatrixFiles();
00174 //    }
00175 
00176     CHK_ERR( fei_tester->testSolve() );
00177 
00178     CHK_ERR( fei_tester->testCheckResult() );
00179 
00180   } //end of 'for solveCounter<=numSolves loop'
00181 
00182   return(0);
00183 }
00184 
00185 fei::SharedPtr<fei::ParameterSet>
00186 test_FEI::get_test_parameters()
00187 {
00188   std::vector<std::string> inputFileStrings;
00189 
00190   FEI_OSTRINGSTREAM filename;
00191   filename << path_;
00192 
00193   std::size_t length = path_.size();
00194   if (length > 0) {
00195     if (path_[length-1] != '/') filename<< "/";
00196   }
00197 
00198   filename << fileName_;
00199 
00200   std::string filename_str = filename.str();
00201   const char* filename_c_str = filename_str.c_str();
00202   fei_test_utils::read_input_file(filename_c_str, comm_, inputFileStrings);
00203 
00204   fei::SharedPtr<fei::ParameterSet> paramset(new fei::ParameterSet);
00205   fei::utils::parse_strings(inputFileStrings, " ", *paramset);
00206 
00207   return(paramset);
00208 }
00209 
00210 std::string test_FEI::fully_qualified_name(const std::string& fileName)
00211 {
00212   FEI_OSTRINGSTREAM osstr;
00213   osstr << path_;
00214 
00215   std::size_t length = path_.size();
00216   if (length > 0) {
00217     if (path_[length-1] != '/') osstr<< "/";
00218   }
00219 
00220   osstr << fileName;
00221 
00222   return(osstr.str());
00223 }

Generated on Tue Jul 13 09:27:46 2010 for FEI by  doxygen 1.4.7