FEI Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
feiDriver_main.cpp
Go to the documentation of this file.
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2005 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 //
10 // This is a simple program to exercise the FEI.
11 //
12 #include <fei_macros.hpp>
13 
14 
15 //Including the header fei_base.hpp gets us the declaration for
16 //most FEI classes.
17 
18 #include <fei_base.hpp>
19 #include <FEI_Implementation.hpp>
20 
21 #include <fei_LibraryWrapper.hpp>
23 
26 
27 #include <test_utils/ElemBlock.hpp>
28 #include <test_utils/CRSet.hpp>
29 #include <test_utils/BCNodeSet.hpp>
34 #include <test_utils/SolnCheck.hpp>
35 
36 #undef fei_file
37 #define fei_file "feiDriver.cpp"
38 #include <fei_ErrMacros.hpp>
39 
40 //==============================================================================
41 //Here's the main...
42 //==============================================================================
43 int feiDriver_main(int argc, char** argv,
44  MPI_Comm comm, int numProcs, int localProc){
45 
46  std::vector<std::string> stdstrings;
48  comm, localProc,
49  stdstrings) );
50  const char** params = NULL;
51  int numParams = 0;
52  fei::utils::strings_to_char_ptrs(stdstrings, numParams, params);
53 
54  fei::ParameterSet paramset;
55  fei::utils::parse_strings(stdstrings, " ", paramset);
56 
57  std::string solverName;
58  std::string inputFileName;
59  int errcode = paramset.getStringParamValue("SOLVER_LIBRARY", solverName);
60  errcode += paramset.getStringParamValue("INPUT_FILE", inputFileName);
61  if (errcode != 0) {
62  fei::console_out() << "Expected to find both 'SOLVER_NAME' and 'INPUT_FILE' "
63  <<"in input-file."<<FEI_ENDL;
64  return(-1);
65  }
66 
67  //let's add the appropriate file-name extension to the file-name obtained from
68  //the input...
69  FEI_OSTRINGSTREAM fullFileName;
70  fullFileName<< inputFileName<<"."<<numProcs<<"."<< localProc;
71 
72  driverData drv;
73  CHK_ERR( drv.readData(fullFileName.str().c_str()) );
74 
75  //ok, all the data is in the 'data' object, so we're ready to start
76  //handing it all over to an instantiation of the FEI.
77 
78  //first, we have to instantiate a LibraryWrapper and an FEI...
79 
81  try {
82  wrapper = fei::create_LibraryWrapper(comm, solverName.c_str());
83  }
84  catch (std::runtime_error& exc) {
85  fei::console_out() << exc.what() << FEI_ENDL;
86  ERReturn(-1);
87  }
88 
89  fei::SharedPtr<FEI> fei(new FEI_Implementation(wrapper, comm));
90 
91  const char* feiVersionString;
92  CHK_ERR( fei->version(feiVersionString) );
93 
94  FEI_COUT << FEI_ENDL << "FEI version: " << feiVersionString << FEI_ENDL << FEI_ENDL;
95 
96  CHK_ERR( fei->parameters(numParams, params) );
97 
98  std::vector<const char*>& methodNames = drv.get_methodNames();
99 
100  for(size_t i=0; i<methodNames.size(); i++) {
101  if (!strcmp("destructor", methodNames[i])) {
102  //In some cases the input file indicates that the FEI should be
103  //destroyed and then re-allocated before continuing. Note that we
104  //assume here that the solver-layer (linsyscore, wrapper or feData)
105  //should also be destroyed and re-allocated at the same time.
106  FEI_COUT << "feiDriver: proc " << localProc << " destroying/reallocing FEI"
107  << FEI_ENDL;
108 
109  fei.reset();
110  wrapper.reset();
111  try {
112  wrapper = fei::create_LibraryWrapper(comm, solverName.c_str());
113  }
114  catch (std::runtime_error& exc) {
115  fei::console_out() << exc.what()<<FEI_ENDL;
116  ERReturn(-1);
117  }
118 
119  fei.reset(new FEI_Implementation(wrapper, comm));
120 
121  CHK_ERR( fei->parameters(numParams, params) );
122 
123  continue;
124  }
125 
126  FEI_COUT << "feiDriver: proc " << localProc << " calling FEI method: "
127  << methodNames[i] << FEI_ENDL;
128  int feierror = drv.call_fei_method(methodNames[i], fei.get());
129  if (feierror > 0) continue;
130  if (feierror < 0) {
131  //for testing purposes, temporarily, don't bail out if an fei method
132  //returns an error.
133  continue;
134  //return(-1);
135  }
136  }
137 
138  MPI_Barrier(comm);
139 
140  if (localProc == 0) {
141  FEI_COUT << "feiDriver: TEST PASSED" << FEI_ENDL;
142 
143  //This is something the SIERRA runtest tool looks for in test output...
144  FEI_COUT << "SIERRA execution successful" << FEI_ENDL;
145 #ifdef SIERRA_BUILD_DATE
147  FEI_COUT << "Maximum CPU time: 0.0 seconds." << FEI_ENDL;
148 #endif
149  }
150 
151  delete [] params;
152 
153  return(0);
154 }
void strings_to_char_ptrs(std::vector< std::string > &stdstrings, int &numStrings, const char **&charPtrs)
Definition: fei_utils.cpp:178
#define FEI_COUT
virtual int parameters(int numParams, const char *const *paramStrings)=0
int call_fei_method(const char *method, FEI *fei)
Definition: driverData.cpp:134
#define FEI_Implementation
Definition: fei_version.h:66
void reset(T *p=0)
#define MPI_Comm
Definition: fei_mpi.h:56
virtual int version(const char *&versionString)=0
int getStringParamValue(const char *name, std::string &paramValue) const
#define IOS_FLOATFIELD
int get_filename_and_read_input(int argc, char **argv, MPI_Comm comm, int localProc, std::vector< std::string > &stdstrings)
#define ERReturn(a)
T * get() const
#define MPI_Barrier(a)
Definition: fei_mpi.h:61
#define FEI_ENDL
std::ostream & console_out()
void parse_strings(std::vector< std::string > &stdstrings, const char *separator_string, fei::ParameterSet &paramset)
Definition: fei_utils.cpp:191
int readData(const char *fileName)
Definition: driverData.cpp:105
int feiDriver_main(int argc, char **argv, MPI_Comm comm, int numProcs, int localProc)
int localProc(MPI_Comm comm)
std::vector< const char * > & get_methodNames()
Definition: driverData.hpp:174
#define CHK_ERR(a)
#define IOS_FIXED
#define FEI_OSTRINGSTREAM
Definition: fei_sstream.hpp:32
fei::SharedPtr< LibraryWrapper > create_LibraryWrapper(MPI_Comm comm, const char *libraryName)
int numProcs(MPI_Comm comm)