FEI Version of the Day
test_FEI.cpp
00001 /*
00002 // @HEADER
00003 // ************************************************************************
00004 //             FEI: Finite Element Interface to Linear Solvers
00005 //                  Copyright (2005) Sandia Corporation.
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the
00008 // 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 Alan Williams (william@sandia.gov) 
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 */
00042 
00043 #include <fei_sstream.hpp>
00044 #include <snl_fei_Utils.hpp>
00045 #include <test_utils/test_FEI.hpp>
00046 
00047 #include <test_utils/fei_test_utils.hpp>
00048 #include <test_utils/LibraryFactory.hpp>
00049 
00050 #include <fei_ParameterSet.hpp>
00051 #include <fei_utils.hpp>
00052 #include <test_utils/DataReader.hpp>
00053 #include <test_utils/FEI_tester.hpp>     //FEI_tester tests the "old" FEI.
00054 #include <test_utils/snl_fei_tester.hpp> //snl_fei_tester tests the "new" fei
00055 
00056 #undef fei_file
00057 #define fei_file "test_FEI.cpp"
00058 #include <fei_ErrMacros.hpp>
00059 
00060 test_FEI::test_FEI(MPI_Comm comm)
00061   : tester(comm),
00062     fileName_()
00063 {
00064 }
00065 
00066 test_FEI::~test_FEI()
00067 {
00068 }
00069 
00070 int test_FEI::runtests()
00071 {
00072   if (fileName_.empty()) return(-1);
00073 
00074   CHK_ERR( test1() );
00075   return(0);
00076 }
00077 
00078 int test_FEI::test1()
00079 {
00080   fei::SharedPtr<fei::ParameterSet> test_params = get_test_parameters();
00081 
00082   int errcode = 0;
00083 
00084   int numSolves = 0;
00085   errcode = test_params->getIntParamValue("NUM_SOLVES", numSolves);
00086 
00087   std::string solverName;
00088   errcode = test_params->getStringParamValue("SOLVER_LIBRARY", solverName);
00089   if (errcode != 0) {
00090     throw std::runtime_error(".input file doesn't contain 'SOLVER_LIBRARY'");
00091   }
00092 
00093   std::string whichFEI;
00094   errcode = test_params->getStringParamValue("WHICH_FEI", whichFEI);
00095   if (errcode != 0) {
00096     throw std::runtime_error(".input file doesn't contain 'WHICH_FEI'");
00097   }
00098 
00099   std::string inputFileName;
00100   errcode = test_params->getStringParamValue("INPUT_FILE",inputFileName);
00101   if (errcode != 0) {
00102     throw std::runtime_error(".input file doesn't contain 'INPUT_FILE'");
00103   }
00104 
00105   std::string paramFile;
00106   errcode = test_params->getStringParamValue("PARAM_FILE", paramFile);
00107   if (errcode != 0) {
00108     throw std::runtime_error(".input file doesn't contain 'PARAM_FILE'");
00109   }
00110 
00111   std::string solnFile;
00112   errcode = test_params->getStringParamValue("SOLN_FILE", solnFile);
00113   if (errcode != 0) {
00114     throw std::runtime_error(".input file doesn't contain 'SOLN_FILE'");
00115   }
00116 
00117   std::string checkFile;
00118   errcode = test_params->getStringParamValue("CHECK_FILE", checkFile);
00119   if (errcode != 0) {
00120     throw std::runtime_error(".input file doesn't contain 'CHECK_FILE'");
00121   }
00122 
00123   std::string readerType;
00124   errcode = test_params->getStringParamValue("READER_TYPE", readerType);
00125 
00126   fei::SharedPtr<feitester> fei_tester;
00127 
00128   FEI_OSTRINGSTREAM fullName;
00129   std::string fullInputFileName = fully_qualified_name(inputFileName);
00130   fullName<< fullInputFileName<<"."<< numProcs_<<"."<< localProc_;
00131 
00132   std::string fullName_str = fullName.str();
00133   const char* fullName_c_str = fullName_str.c_str();
00134 
00135   fei::SharedPtr<DataReader> data_reader(new DataReader);
00136 
00137   //let's read all the data out of the input file.
00138   CHK_ERR( data_reader->readData(fullName_c_str));
00139 
00140   //now we'll get the parameters out of another file.
00141   std::string fullParamFileName = fully_qualified_name(paramFile);
00142   const char* paramFile_c_str = fullParamFileName.c_str();
00143 
00144   std::vector<std::string> param_file_contents;
00145   fei_test_utils::read_input_file(paramFile_c_str, comm_,
00146                                   param_file_contents);
00147 
00148   data_reader->numParams_ = param_file_contents.size();
00149   data_reader->paramStrings_ = new char*[data_reader->numParams_];
00150 
00151   for(unsigned i=0; i<param_file_contents.size(); ++i) {
00152     std::string& str = param_file_contents[i];
00153     data_reader->paramStrings_[i] = new char[str.size()+1];
00154     for(unsigned j=0; j<str.size(); ++j) {
00155       data_reader->paramStrings_[i][j] = str[j];
00156     }
00157     data_reader->paramStrings_[i][str.size()] = '\0';
00158   }
00159 
00160   data_reader->solverLibraryName_ = solverName;
00161 
00162   std::string fullSolnFile = fully_qualified_name(solnFile);
00163   data_reader->solnFileName_ = fullSolnFile;
00164 
00165   std::string fullCheckFile = fully_qualified_name(checkFile);
00166   data_reader->checkFileName_ = fullCheckFile;
00167 
00168   //ok, all the data is in the 'data' object, so we're ready to start
00169   //handing it all over to an instantiation of the FEI.
00170 
00171   if (whichFEI == "OLDFEI") {
00172     fei_tester.reset(new FEI_tester(data_reader, comm_, localProc_, numProcs_));
00173   }
00174   if (whichFEI == "fei::FEI_Impl") {
00175     bool useNewFEI = true;
00176     fei_tester.reset(new FEI_tester(data_reader, comm_, localProc_, numProcs_,
00177                   useNewFEI));
00178   }
00179   else if (whichFEI == "new_fei") {
00180     fei_tester.reset( new snl_fei_tester(data_reader, comm_, localProc_, numProcs_));
00181   }
00182 
00183   if (fei_tester.get() == NULL) {
00184     ERReturn(-1);
00185   }
00186 
00187   fei_tester->setPath(path_);
00188 
00189   int errCode = fei_tester->testInitialization();
00190   if (errCode < 0) {
00191     ERReturn(errCode);
00192   }
00193   if (errCode > 0) {
00194     FEI_COUT << "library " << solverName << " not available."<<FEI_ENDL;
00195     return(-1);
00196   }
00197 
00198   for(int solveCounter=1; solveCounter<=numSolves; solveCounter++) {
00199 
00200     CHK_ERR( fei_tester->testLoading() );
00201 
00202 //    if (solverName == "Trilinos") {
00203 //      fei_tester->dumpMatrixFiles();
00204 //      fei_tester->setParameter("USE_FEI_MATRIX_LOCAL true");
00205 //      fei_tester->testLoading();
00206 //      fei_tester->dumpMatrixFiles();
00207 //    }
00208 
00209     CHK_ERR( fei_tester->testSolve() );
00210 
00211     CHK_ERR( fei_tester->testCheckResult() );
00212 
00213   } //end of 'for solveCounter<=numSolves loop'
00214 
00215   return(0);
00216 }
00217 
00218 fei::SharedPtr<fei::ParameterSet>
00219 test_FEI::get_test_parameters()
00220 {
00221   std::vector<std::string> inputFileStrings;
00222 
00223   FEI_OSTRINGSTREAM filename;
00224   filename << path_;
00225 
00226   std::size_t length = path_.size();
00227   if (length > 0) {
00228     if (path_[length-1] != '/') filename<< "/";
00229   }
00230 
00231   filename << fileName_;
00232 
00233   std::string filename_str = filename.str();
00234   const char* filename_c_str = filename_str.c_str();
00235   fei_test_utils::read_input_file(filename_c_str, comm_, inputFileStrings);
00236 
00237   fei::SharedPtr<fei::ParameterSet> paramset(new fei::ParameterSet);
00238   fei::utils::parse_strings(inputFileStrings, " ", *paramset);
00239 
00240   return(paramset);
00241 }
00242 
00243 std::string test_FEI::fully_qualified_name(const std::string& fileName)
00244 {
00245   FEI_OSTRINGSTREAM osstr;
00246   osstr << path_;
00247 
00248   std::size_t length = path_.size();
00249   if (length > 0) {
00250     if (path_[length-1] != '/') osstr<< "/";
00251   }
00252 
00253   osstr << fileName;
00254 
00255   return(osstr.str());
00256 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends