beam_oldfei_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 new FEI (version 3?) classes,
00011 // for the purposes of testing, code tuning and scaling studies.
00012 //
00013 
00014 #include <fei_macros.hpp> //simply includes std stuff like iostream, etc.
00015                              //users could include that stuff themselves rather
00016                              //than using this header.
00017 
00018 //Including the header fei_base.hpp gets us the declaration for
00019 //various fei classes and interfaces.
00020 
00021 #include <fei_base.hpp>
00022 #include <FEI_Implementation.hpp>
00023 
00024 //Now make provision for using any one of several solver libraries. This is
00025 //handled by the code in LibraryFactory.[hC].
00026 
00027 #include <test_utils/LibraryFactory.hpp>
00028 
00029 //And finally, we need to include some 'utils' headers which are used for
00030 //setting up the data for the example problem.
00031 
00032 #include <test_utils/HexBeam.hpp>
00033 #include <test_utils/HexBeamCR.hpp>
00034 
00035 #include <test_utils/fei_test_utils.hpp>
00036 #include <snl_fei_Utils.hpp>
00037 
00038 #undef fei_file
00039 #define fei_file "cube_main.cpp"
00040 #include <fei_ErrMacros.hpp>
00041 
00042 //==============================================================================
00043 //Here's the main...
00044 //==============================================================================
00045 int beam_oldfei_main(int argc, char** argv,
00046         MPI_Comm comm, int numProcs, int localProc){
00047 
00048   std::vector<std::string> stdstrings;
00049   CHK_ERR( fei_test_utils::get_filename_and_read_input(argc, argv,
00050             comm, localProc,
00051             stdstrings) );
00052 
00053   const char** params = NULL;
00054   int numParams = 0;
00055   fei::utils::strings_to_char_ptrs(stdstrings, numParams, params);
00056   
00057   fei::ParameterSet paramset;
00058   fei::utils::parse_strings(stdstrings, " ", paramset);
00059 
00060   std::string whichFEI;
00061   std::string solverName;
00062   std::string datasource;
00063   int W = 0;
00064   int D = 0;
00065   int DofPerNode = 0;
00066 
00067   int errcode = 0;
00068   errcode += paramset.getStringParamValue("SOLVER_LIBRARY", solverName);
00069   errcode += paramset.getStringParamValue("DATA_SOURCE", datasource);
00070   errcode += paramset.getStringParamValue("WHICH_FEI", whichFEI);
00071   errcode += paramset.getIntParamValue("W", W);
00072   errcode += paramset.getIntParamValue("D", D);
00073   errcode += paramset.getIntParamValue("DofPerNode", DofPerNode);
00074 
00075   if (errcode != 0) {
00076     FEI_CERR << "Failed to find one or more required parameters in input-file."
00077        << FEI_ENDL << "Required parameters:"<<FEI_ENDL
00078        << "SOLVER_LIBRARY" << FEI_ENDL
00079        << "DATA_SOURCE" << FEI_ENDL
00080        << "CONSTRAINT_FORM" << FEI_ENDL
00081        << "W" << FEI_ENDL << "D" << FEI_ENDL << "DofPerNode" << FEI_ENDL;
00082     return(-1);
00083   }
00084 
00085   HexBeam* hexcubeptr = NULL;
00086   if (datasource == "HexBeam") {
00087     hexcubeptr = new HexBeam(W, D, DofPerNode,
00088            HexBeam::OneD, numProcs, localProc);
00089   }
00090   else {
00091     hexcubeptr = new HexBeamCR(W, D, DofPerNode,
00092              HexBeam::OneD, numProcs, localProc);
00093   }
00094 
00095   HexBeam& hexcube = *hexcubeptr;
00096 
00097   if (localProc == 0) {
00098     int numCRs = (W+1)*(W+1)*(numProcs*2)-1;
00099     if (hexcube.getNumCRs() < 1) numCRs = 0;
00100     FEI_COUT << FEI_ENDL;
00101     FEI_COUT << "========================================================" 
00102    << FEI_ENDL;
00103     FEI_COUT << "Size W: " << W << " (num-elements-along-side-of-cube)"<<FEI_ENDL;
00104     FEI_COUT << "Size D: " << D << " (num-elements-along-depth-of-cube)"<<FEI_ENDL;
00105     FEI_COUT << "DOF per node: " << DofPerNode <<FEI_ENDL;
00106     FEI_COUT << "Num local  elements: " << hexcube.localNumElems_ << FEI_ENDL;
00107     FEI_COUT << "Num global elements: " << hexcube.totalNumElems_ << FEI_ENDL;
00108     FEI_COUT << "Num local  DOF: " << hexcube.numLocalDOF_ << FEI_ENDL;
00109     FEI_COUT << "Num global DOF: " << hexcube.numGlobalDOF_ << FEI_ENDL;
00110     FEI_COUT << "Num global CRs: " << numCRs << FEI_ENDL;
00111     FEI_COUT << "========================================================" 
00112    << FEI_ENDL;
00113   }
00114 
00115   double start_init_time = fei::utils::cpu_time();
00116 
00117   //CHK_ERR( print_cube_data(hexcube, numProcs, localProc) );
00118 
00119   fei::SharedPtr<fei::Factory> factory;
00120   fei::SharedPtr<LibraryWrapper> wrapper;
00121   fei::SharedPtr<FEI> fei;
00122 
00123   if (whichFEI == "OLDFEI") {
00124     try {
00125       wrapper = fei::create_LibraryWrapper(comm, solverName.c_str());
00126     }
00127     catch (std::runtime_error& exc) {
00128       FEI_CERR << exc.what() << FEI_ENDL;
00129       ERReturn(-1);
00130     }
00131     fei.reset(new FEI_Implementation(wrapper, comm));
00132   }
00133   else if (whichFEI == "fei::FEI_Impl") {
00134     try {
00135       factory = fei::create_fei_Factory(comm, solverName.c_str());
00136     }
00137     catch (std::runtime_error& exc) {
00138       FEI_CERR << exc.what() << FEI_ENDL;
00139       ERReturn(-1);
00140     }
00141     fei = factory->createFEI(comm);
00142   }
00143   else {
00144     FEI_CERR << "cube ERROR, value of 'WHICH_FEI' must be 'OLDFEI' or 'fei::FEI_Impl'"<< FEI_ENDL;
00145     ERReturn(-1);
00146   }
00147 
00148   //load some control parameters.
00149   CHK_ERR( fei->parameters(numParams, params) );
00150 
00151   delete [] params;
00152 
00153   CHK_ERR( fei->setSolveType(FEI_SINGLE_SYSTEM) );
00154 
00155   int fieldID = 0;
00156   int fieldSize = hexcube.numDofPerNode();
00157 
00158   CHK_ERR( fei->initFields( 1, &fieldSize, &fieldID ) );
00159 
00160   CHK_ERR( HexBeam_Functions::init_elem_connectivities( fei.get(), hexcube ) );
00161 
00162   CHK_ERR( HexBeam_Functions::init_shared_nodes( fei.get(), hexcube ) );
00163 
00164   int firstLocalCRID;
00165   CHK_ERR( HexBeam_Functions::
00166      init_constraints( fei.get(), hexcube, firstLocalCRID) );
00167 
00168   CHK_ERR( fei->initComplete() );
00169 
00170   double fei_init_time = fei::utils::cpu_time() - start_init_time;
00171 
00172   if (localProc == 0) {
00173     FEI_COUT.setf(IOS_FIXED, IOS_FLOATFIELD);
00174     FEI_COUT << "Initialization time:   " << fei_init_time << FEI_ENDL;
00175   }
00176 
00177   //Now the initialization phase is complete. Next we'll do the load phase,
00178   //which for this problem just consists of loading the element data
00179   //(element-wise stiffness arrays and load vectors) and the boundary
00180   //condition data.
00181 
00182   double start_load_time = fei::utils::cpu_time();
00183 
00184   CHK_ERR( HexBeam_Functions::load_elem_data(fei.get(), hexcube) );
00185 
00186   CHK_ERR( HexBeam_Functions::load_constraints(fei.get(), hexcube, firstLocalCRID) );
00187 
00188   //FEI_COUT << "calling load_BC_data"<<FEI_ENDL;
00189   //CHK_ERR( load_BC_data(fei, hexcube) );
00190 
00191   fei->loadComplete();
00192 
00193   double fei_load_time = fei::utils::cpu_time() - start_load_time;
00194 
00195   delete hexcubeptr;
00196 
00197   if (localProc == 0) {
00198     //IOS macros are defined in fei_macros.h
00199     FEI_COUT.setf(IOS_FIXED, IOS_FLOATFIELD);
00200     FEI_COUT << "Coef. loading  time:    " << fei_load_time << FEI_ENDL;
00201     FEI_COUT << "Total assembly time:    " << fei_init_time + fei_load_time << FEI_ENDL;
00202   }
00203 
00204   //
00205   //now the load phase is complete, so we're ready to launch the underlying
00206   //solver and solve Ax=b
00207   //
00208 
00209   int err;
00210   int status;
00211   double start_solve_time = fei::utils::cpu_time();
00212 
00213   err = fei->solve(status);
00214 
00215   if (err || status) {
00216     if (localProc==0) FEI_COUT << "solve returned status: " << status << FEI_ENDL;
00217   }
00218 
00219   double solve_time = fei::utils::cpu_time() - start_solve_time;
00220 
00221   if (localProc == 0) {
00222     FEI_COUT << "Solver time:          " << solve_time << FEI_ENDL;
00223   }
00224 
00225   int returnValue = 0;
00226   if (localProc == 0) {
00227 #if defined(FEI_PLATFORM) && defined(FEI_OPT_LEVEL)
00228     double benchmark = fei_init_time;
00229 
00230     FEI_OSTRINGSTREAM testname_init;
00231     testname_init << "cube_"<<whichFEI<<"_init_"<<W<<"_"<<D<<"_"<<DofPerNode<<"_"
00232       <<solverName<<"_np"<<numProcs<<"_"
00233       <<FEI_PLATFORM<<"_"<<FEI_OPT_LEVEL;
00234 
00235     FEI_OSTRINGSTREAM testname_load;
00236     testname_load << "cube_"<<whichFEI<<"_load_"<<W<<"_"<<D<<"_"<<DofPerNode<<"_"
00237       <<solverName<<"_np"<<numProcs<<"_"
00238       <<FEI_PLATFORM<<"_"<<FEI_OPT_LEVEL;
00239 
00240     double file_init, file_load;
00241     bool file_benchmarks_available = true;
00242     try {
00243       file_init = fei_test_utils::get_file_benchmark("./cube_timings.txt",
00244                 testname_init.str().c_str());
00245       file_load = fei_test_utils::get_file_benchmark("./cube_timings.txt",
00246                 testname_load.str().c_str());
00247     }
00248     catch (std::runtime_error& exc) {
00249       file_benchmarks_available = false;
00250     }
00251 
00252     if (file_benchmarks_available) {
00253 
00254       bool init_test_passed =
00255   fei_test_utils::check_and_cout_test_result(testname_init.str(), benchmark,
00256               file_init, 10);
00257 
00258       benchmark = fei_load_time;
00259       bool load_test_passed =
00260   fei_test_utils::check_and_cout_test_result(testname_load.str(), benchmark,
00261               file_load, 10);
00262 
00263       returnValue = init_test_passed&&load_test_passed ? 0 : 1;
00264     }
00265 #endif
00266   }
00267 
00268   bool testPassed = returnValue==0;
00269   if (testPassed && localProc == 0) {
00270     //A string for the SIERRA runtest tool to search for in test output...
00271     FEI_COUT << "cube execution successful" << FEI_ENDL;
00272   }
00273 
00274   fei.reset();
00275 
00276   return(0);
00277 }

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