FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
test_FEI.cpp
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 #include <fei_sstream.hpp>
11 #include <snl_fei_Utils.hpp>
12 #include <test_utils/test_FEI.hpp>
13 
14 #include <test_utils/fei_test_utils.hpp>
15 #include <test_utils/LibraryFactory.hpp>
16 
17 #include <fei_ParameterSet.hpp>
18 #include <fei_utils.hpp>
19 #include <test_utils/DataReader.hpp>
20 #include <test_utils/FEI_tester.hpp> //FEI_tester tests the "old" FEI.
21 #include <test_utils/snl_fei_tester.hpp> //snl_fei_tester tests the "new" fei
22 
23 #undef fei_file
24 #define fei_file "test_FEI.cpp"
25 #include <fei_ErrMacros.hpp>
26 
27 test_FEI::test_FEI(MPI_Comm comm)
28  : tester(comm),
29  fileName_()
30 {
31 }
32 
33 test_FEI::~test_FEI()
34 {
35 }
36 
37 int test_FEI::runtests()
38 {
39  if (fileName_.empty()) return(-1);
40 
41  CHK_ERR( test1() );
42  return(0);
43 }
44 
45 int test_FEI::test1()
46 {
47  fei::SharedPtr<fei::ParameterSet> test_params = get_test_parameters();
48 
49  int errcode = 0;
50 
51  int numSolves = 0;
52  errcode = test_params->getIntParamValue("NUM_SOLVES", numSolves);
53 
54  std::string solverName;
55  errcode = test_params->getStringParamValue("SOLVER_LIBRARY", solverName);
56  if (errcode != 0) {
57  throw std::runtime_error(".input file doesn't contain 'SOLVER_LIBRARY'");
58  }
59 
60  std::string whichFEI;
61  errcode = test_params->getStringParamValue("WHICH_FEI", whichFEI);
62  if (errcode != 0) {
63  throw std::runtime_error(".input file doesn't contain 'WHICH_FEI'");
64  }
65 
66  std::string inputFileName;
67  errcode = test_params->getStringParamValue("INPUT_FILE",inputFileName);
68  if (errcode != 0) {
69  throw std::runtime_error(".input file doesn't contain 'INPUT_FILE'");
70  }
71 
72  std::string paramFile;
73  errcode = test_params->getStringParamValue("PARAM_FILE", paramFile);
74  if (errcode != 0) {
75  throw std::runtime_error(".input file doesn't contain 'PARAM_FILE'");
76  }
77 
78  std::string solnFile;
79  errcode = test_params->getStringParamValue("SOLN_FILE", solnFile);
80  if (errcode != 0) {
81  throw std::runtime_error(".input file doesn't contain 'SOLN_FILE'");
82  }
83 
84  std::string checkFile;
85  errcode = test_params->getStringParamValue("CHECK_FILE", checkFile);
86  if (errcode != 0) {
87  throw std::runtime_error(".input file doesn't contain 'CHECK_FILE'");
88  }
89 
90  std::string readerType;
91  errcode = test_params->getStringParamValue("READER_TYPE", readerType);
92 
93  fei::SharedPtr<feitester> fei_tester;
94 
95  FEI_OSTRINGSTREAM fullName;
96  std::string fullInputFileName = fully_qualified_name(inputFileName);
97  fullName<< fullInputFileName<<"."<< numProcs_<<"."<< localProc_;
98 
99  std::string fullName_str = fullName.str();
100  const char* fullName_c_str = fullName_str.c_str();
101 
102  fei::SharedPtr<DataReader> data_reader(new DataReader);
103 
104  //let's read all the data out of the input file.
105  CHK_ERR( data_reader->readData(fullName_c_str));
106 
107  //now we'll get the parameters out of another file.
108  std::string fullParamFileName = fully_qualified_name(paramFile);
109  const char* paramFile_c_str = fullParamFileName.c_str();
110 
111  std::vector<std::string> param_file_contents;
112  fei_test_utils::read_input_file(paramFile_c_str, comm_,
113  param_file_contents);
114 
115  data_reader->numParams_ = param_file_contents.size();
116  data_reader->paramStrings_ = new char*[data_reader->numParams_];
117 
118  for(unsigned i=0; i<param_file_contents.size(); ++i) {
119  std::string& str = param_file_contents[i];
120  data_reader->paramStrings_[i] = new char[str.size()+1];
121  for(unsigned j=0; j<str.size(); ++j) {
122  data_reader->paramStrings_[i][j] = str[j];
123  }
124  data_reader->paramStrings_[i][str.size()] = '\0';
125  }
126 
127  data_reader->solverLibraryName_ = solverName;
128 
129  std::string fullSolnFile = fully_qualified_name(solnFile);
130  data_reader->solnFileName_ = fullSolnFile;
131 
132  std::string fullCheckFile = fully_qualified_name(checkFile);
133  data_reader->checkFileName_ = fullCheckFile;
134 
135  //ok, all the data is in the 'data' object, so we're ready to start
136  //handing it all over to an instantiation of the FEI.
137 
138  if (whichFEI == "OLDFEI") {
139  fei_tester.reset(new FEI_tester(data_reader, comm_, localProc_, numProcs_));
140  }
141  if (whichFEI == "fei::FEI_Impl") {
142  bool useNewFEI = true;
143  fei_tester.reset(new FEI_tester(data_reader, comm_, localProc_, numProcs_,
144  useNewFEI));
145  }
146  else if (whichFEI == "new_fei") {
147  fei_tester.reset( new snl_fei_tester(data_reader, comm_, localProc_, numProcs_));
148  }
149 
150  if (fei_tester.get() == NULL) {
151  ERReturn(-1);
152  }
153 
154  fei_tester->setPath(path_);
155 
156  int errCode = fei_tester->testInitialization();
157  if (errCode < 0) {
158  ERReturn(errCode);
159  }
160  if (errCode > 0) {
161  FEI_COUT << "library " << solverName << " not available."<<FEI_ENDL;
162  return(-1);
163  }
164 
165  for(int solveCounter=1; solveCounter<=numSolves; solveCounter++) {
166 
167  CHK_ERR( fei_tester->testLoading() );
168 
169 // if (solverName == "Trilinos") {
170 // fei_tester->dumpMatrixFiles();
171 // fei_tester->setParameter("USE_FEI_MATRIX_LOCAL true");
172 // fei_tester->testLoading();
173 // fei_tester->dumpMatrixFiles();
174 // }
175 
176  CHK_ERR( fei_tester->testSolve() );
177 
178  CHK_ERR( fei_tester->testCheckResult() );
179 
180  } //end of 'for solveCounter<=numSolves loop'
181 
182  return(0);
183 }
184 
186 test_FEI::get_test_parameters()
187 {
188  std::vector<std::string> inputFileStrings;
189 
190  FEI_OSTRINGSTREAM filename;
191  filename << path_;
192 
193  std::size_t length = path_.size();
194  if (length > 0) {
195  if (path_[length-1] != '/') filename<< "/";
196  }
197 
198  filename << fileName_;
199 
200  std::string filename_str = filename.str();
201  const char* filename_c_str = filename_str.c_str();
202  fei_test_utils::read_input_file(filename_c_str, comm_, inputFileStrings);
203 
205  fei::utils::parse_strings(inputFileStrings, " ", *paramset);
206 
207  return(paramset);
208 }
209 
210 std::string test_FEI::fully_qualified_name(const std::string& fileName)
211 {
212  FEI_OSTRINGSTREAM osstr;
213  osstr << path_;
214 
215  std::size_t length = path_.size();
216  if (length > 0) {
217  if (path_[length-1] != '/') osstr<< "/";
218  }
219 
220  osstr << fileName;
221 
222  return(osstr.str());
223 }
void reset(T *p=0)
int getStringParamValue(const char *name, std::string &paramValue) const
T * get() const
void read_input_file(const char *filename, MPI_Comm comm, std::vector< std::string > &file_contents)
void parse_strings(std::vector< std::string > &stdstrings, const char *separator_string, fei::ParameterSet &paramset)
Definition: fei_utils.cpp:191
int getIntParamValue(const char *name, int &paramValue) const