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