FEI Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SolnCheck.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 #include <fei_iostream.hpp>
10 #include <fei_sstream.hpp>
11 #include <fei_fstream.hpp>
12 
14 
15 #include <test_utils/SolnCheck.hpp>
16 
17 //==============================================================================
18 int SolnCheck::readSoln(const char* baseName, int np, fei::FillableMat& solution)
19 {
20  for(int i=0; i<np; i++) {
21  FEI_OSTRINGSTREAM osstr;
22  osstr << baseName << "." << np << "." << i;
23  FEI_IFSTREAM infile(osstr.str().c_str());
24  if (!infile || infile.bad()) return(-1);
25 
26  int node, numDOF;
27  double tmpValue;
28  infile >> node;
29  while(!infile.eof()) {
30  infile >> numDOF;
31 
32  for(int j=0; j<numDOF; j++) {
33  infile >> tmpValue;
34  solution.putCoef(node,j,tmpValue);
35  }
36  infile >> node;
37  }
38  }
39 
40  return(0);
41 }
42 
43 //==============================================================================
45  double tol)
46 {
47  return(fei_test_utils::compareMatrices(solution1, solution2, tol) );
48 }
49 
50 //==============================================================================
51 int SolnCheck::readMatrix(const char* baseName, int np, fei::FillableMat& matrix)
52 {
53  return( fei_test_utils::readMatrix(baseName, np, matrix) );
54 }
55 
56 //==============================================================================
58 {
59  return( fei_test_utils::compareMatrices(mat1, mat2) );
60 }
61 
62 //----------------------------------------------------------------------------
64  const char* solnFileName,
65  const char* checkFileName,
66  const char* extension,
67  int solveCounter)
68 {
69  if (localProc == 0) {
70  fei::FillableMat soln, correctSoln;
71  FEI_OSTRINGSTREAM fullSolnFileName;
72  FEI_OSTRINGSTREAM fullCheckFileName;
73 
74  fullSolnFileName << solnFileName<<"."<<extension<<"."<<solveCounter;
75  fullCheckFileName<< checkFileName<<"."<<extension<<".correct."<<solveCounter;
76 
77  std::string fullCheck_str = fullCheckFileName.str();
78  const char* check_c_str = fullCheck_str.c_str();
79  int err = SolnCheck::readSoln(check_c_str, 1, correctSoln);
80  if (err != 0) {
81  //If we failed to read the data for the "correct" solution, assume that
82  //this is simply a portion of the solution (e.g., lagrange multipliers)
83  //that this test isn't supposed to compare.
84  //FEI_COUT << "FEI_tester: checkSolution: no check-file for '"<<extension
85  // << "' portion of solution, skipping..." << FEI_ENDL;
86  return(0);
87  }
88 
89  std::string fullSoln_str = fullSolnFileName.str();
90  const char* soln_c_str = fullSoln_str.c_str();
91  err = SolnCheck::readSoln(soln_c_str, numProcs, soln);
92  if (err != 0) return(err);
93 
94  FEI_COUT << "FEI_tester:checkSolution: checking '"<<extension<<"' solution...";
95  int solnCheckCode = SolnCheck::compareSoln(soln, correctSoln);
96 
97  if (solnCheckCode != 0) {
98  FEI_COUT << "soln file-name: " << soln_c_str << FEI_ENDL;
99  FEI_COUT << "soln-check failed, checkFileName="<<checkFileName<<FEI_ENDL;
100  FEI_COUT << "soln: " << FEI_ENDL;
101  fei::print(FEI_COUT, soln);
102  FEI_COUT << "correctSoln file-name: " << check_c_str << FEI_ENDL;
103  FEI_COUT << "correctSoln: " << FEI_ENDL;
104  fei::print(FEI_COUT, correctSoln);
105  return(-1);
106  }
107  FEI_COUT << " ok"<<FEI_ENDL;
108  }
109  return(0);
110 }
111 
int readMatrix(const char *baseName, int np, fei::FillableMat &matrix)
#define FEI_COUT
#define FEI_IFSTREAM
Definition: fei_fstream.hpp:13
int readSoln(const char *baseName, int np, fei::FillableMat &solution)
Definition: SolnCheck.cpp:18
int compareMatrices(fei::FillableMat &mat1, fei::FillableMat &mat2, double tol)
int checkSolution(int localProc, int numProcs, const char *solnFileName, const char *checkFileName, const char *extension, int solveCounter)
Definition: SolnCheck.cpp:63
void putCoef(int row, int col, double coef)
#define FEI_ENDL
int readMatrix(const char *baseName, int np, fei::FillableMat &matrix)
Definition: SolnCheck.cpp:51
int localProc(MPI_Comm comm)
int compareSoln(fei::FillableMat &solution1, fei::FillableMat &solution2, double tol=1.e-3)
Definition: SolnCheck.cpp:44
int compareMatrices(fei::FillableMat &mat1, fei::FillableMat &mat2)
Definition: SolnCheck.cpp:57
#define FEI_OSTRINGSTREAM
Definition: fei_sstream.hpp:32
int numProcs(MPI_Comm comm)
void print(std::ostream &os, const FillableMat &mat)