FEI Version of the Day
feiDriver_main.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 // This is a simple program to exercise the FEI.
00011 //
00012 #include <fei_macros.hpp>
00013 
00014 
00015 //Including the header fei_base.hpp gets us the declaration for
00016 //most FEI classes.
00017 
00018 #include <fei_base.hpp>
00019 #include <FEI_Implementation.hpp>
00020 
00021 #include <fei_LibraryWrapper.hpp>
00022 #include <test_utils/LibraryFactory.hpp>
00023 
00024 #include <test_utils/Poisson_Elem.hpp>
00025 #include <test_utils/PoissonData.hpp>
00026 
00027 #include <test_utils/ElemBlock.hpp>
00028 #include <test_utils/CRSet.hpp>
00029 #include <test_utils/BCNodeSet.hpp>
00030 #include <test_utils/CommNodeSet.hpp>
00031 #include <test_utils/DataReader.hpp>
00032 #include <test_utils/driverData.hpp>
00033 #include <test_utils/fei_test_utils.hpp>
00034 #include <test_utils/SolnCheck.hpp>
00035 
00036 #undef fei_file
00037 #define fei_file "feiDriver.cpp"
00038 #include <fei_ErrMacros.hpp>
00039 
00040 //==============================================================================
00041 //Here's the main...
00042 //==============================================================================
00043 int feiDriver_main(int argc, char** argv,
00044        MPI_Comm comm, int numProcs, int localProc){
00045 
00046   std::vector<std::string> stdstrings;
00047   CHK_ERR( fei_test_utils::get_filename_and_read_input(argc, argv,
00048             comm, localProc,
00049             stdstrings) );
00050   const char** params = NULL;
00051   int numParams = 0;
00052   fei::utils::strings_to_char_ptrs(stdstrings, numParams, params);
00053   
00054   fei::ParameterSet paramset;
00055   fei::utils::parse_strings(stdstrings, " ", paramset);
00056 
00057   std::string solverName;
00058   std::string inputFileName;
00059   int errcode = paramset.getStringParamValue("SOLVER_LIBRARY", solverName);
00060   errcode += paramset.getStringParamValue("INPUT_FILE", inputFileName);
00061   if (errcode != 0) {
00062     FEI_CERR << "Expected to find both 'SOLVER_NAME' and 'INPUT_FILE' "
00063        <<"in input-file."<<FEI_ENDL;
00064     return(-1);
00065   }
00066 
00067   //let's add the appropriate file-name extension to the file-name obtained from
00068   //the input...
00069   FEI_OSTRINGSTREAM fullFileName;
00070   fullFileName<< inputFileName<<"."<<numProcs<<"."<< localProc;
00071 
00072   driverData drv;
00073   CHK_ERR( drv.readData(fullFileName.str().c_str()) );
00074 
00075   //ok, all the data is in the 'data' object, so we're ready to start
00076   //handing it all over to an instantiation of the FEI.
00077 
00078   //first, we have to instantiate a LibraryWrapper and an FEI...
00079 
00080   fei::SharedPtr<LibraryWrapper> wrapper;
00081   try {
00082     wrapper = fei::create_LibraryWrapper(comm, solverName.c_str());
00083   }
00084   catch (std::runtime_error& exc) {
00085     FEI_CERR << exc.what() << FEI_ENDL;
00086     ERReturn(-1);
00087   }
00088 
00089   fei::SharedPtr<FEI> fei(new FEI_Implementation(wrapper, comm));
00090 
00091   const char* feiVersionString;
00092   CHK_ERR( fei->version(feiVersionString) );
00093 
00094   FEI_COUT << FEI_ENDL << "FEI version: " << feiVersionString << FEI_ENDL << FEI_ENDL;
00095 
00096   CHK_ERR( fei->parameters(numParams, params) );
00097 
00098   std::vector<const char*>& methodNames = drv.get_methodNames();
00099 
00100   for(size_t i=0; i<methodNames.size(); i++) {
00101     if (!strcmp("destructor", methodNames[i])) {
00102       //In some cases the input file indicates that the FEI should be
00103       //destroyed and then re-allocated before continuing. Note that we
00104       //assume here that the solver-layer (linsyscore, wrapper or feData)
00105       //should also be destroyed and re-allocated at the same time.
00106       FEI_COUT << "feiDriver: proc " << localProc << " destroying/reallocing FEI"
00107      << FEI_ENDL;
00108 
00109       fei.reset();
00110       wrapper.reset();
00111       try {
00112   wrapper = fei::create_LibraryWrapper(comm, solverName.c_str());
00113       }
00114       catch (std::runtime_error& exc) {
00115   FEI_CERR << exc.what()<<FEI_ENDL;
00116   ERReturn(-1);
00117       }
00118 
00119       fei.reset(new FEI_Implementation(wrapper, comm));
00120 
00121       CHK_ERR( fei->parameters(numParams, params) );
00122 
00123       continue;
00124     }
00125 
00126     FEI_COUT << "feiDriver: proc " << localProc << " calling FEI method: "
00127    << methodNames[i] << FEI_ENDL;
00128     int feierror = drv.call_fei_method(methodNames[i], fei.get());
00129     if (feierror > 0) continue;
00130     if (feierror < 0) {
00131       //for testing purposes, temporarily, don't bail out if an fei method
00132       //returns an error.
00133       continue;
00134       //return(-1);
00135     }
00136   }
00137 
00138   MPI_Barrier(comm);
00139 
00140   if (localProc == 0) {
00141     FEI_COUT << "feiDriver: TEST PASSED" << FEI_ENDL;
00142 
00143     //This is something the SIERRA runtest tool looks for in test output...
00144     FEI_COUT << "SIERRA execution successful" << FEI_ENDL;
00145 #ifdef SIERRA_BUILD_DATE
00146     FEI_COUT.setf(IOS_FIXED, IOS_FLOATFIELD);
00147     FEI_COUT << "Maximum CPU  time: 0.0 seconds." << FEI_ENDL;
00148 #endif
00149   }
00150 
00151   delete [] params;
00152 
00153   return(0);
00154 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends