SolnCheck.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 #include <fei_iostream.hpp>
00010 #include <fei_sstream.hpp>
00011 #include <fei_fstream.hpp>
00012 
00013 #include <test_utils/fei_test_utils.hpp>
00014 
00015 #include <test_utils/SolnCheck.hpp>
00016 
00017 //==============================================================================
00018 int SolnCheck::readSoln(const char* baseName, int np, fei::FillableMat& solution)
00019 {
00020   for(int i=0; i<np; i++) {
00021     FEI_OSTRINGSTREAM osstr;
00022     osstr << baseName << "." << np << "." << i;
00023     FEI_IFSTREAM infile(osstr.str().c_str());
00024     if (!infile || infile.bad()) return(-1);
00025 
00026     int node, numDOF;
00027     double tmpValue;
00028     infile >> node;
00029     while(!infile.eof()) {
00030       infile >> numDOF;
00031 
00032       for(int j=0; j<numDOF; j++) {
00033   infile >> tmpValue;
00034   solution.putCoef(node,j,tmpValue);
00035       }
00036       infile >> node;
00037     }
00038   }
00039 
00040   return(0);
00041 }
00042 
00043 //==============================================================================
00044 int SolnCheck::compareSoln(fei::FillableMat& solution1, fei::FillableMat& solution2,
00045          double tol)
00046 {
00047   return(fei_test_utils::compareMatrices(solution1, solution2, tol) );
00048 }
00049 
00050 //==============================================================================
00051 int SolnCheck::readMatrix(const char* baseName, int np, fei::FillableMat& matrix)
00052 {
00053   return( fei_test_utils::readMatrix(baseName, np, matrix) );
00054 }
00055 
00056 //==============================================================================
00057 int SolnCheck::compareMatrices(fei::FillableMat& mat1, fei::FillableMat& mat2)
00058 {
00059   return( fei_test_utils::compareMatrices(mat1, mat2) );
00060 }
00061 
00062 //----------------------------------------------------------------------------
00063 int SolnCheck::checkSolution(int localProc, int numProcs,
00064            const char* solnFileName,
00065            const char* checkFileName,
00066            const char* extension,
00067            int solveCounter)
00068 {
00069   if (localProc == 0) {
00070     fei::FillableMat soln, correctSoln;
00071     FEI_OSTRINGSTREAM fullSolnFileName;
00072     FEI_OSTRINGSTREAM fullCheckFileName;
00073 
00074     fullSolnFileName << solnFileName<<"."<<extension<<"."<<solveCounter;
00075     fullCheckFileName<< checkFileName<<"."<<extension<<".correct."<<solveCounter;
00076 
00077     std::string fullCheck_str = fullCheckFileName.str();
00078     const char* check_c_str = fullCheck_str.c_str();
00079     int err = SolnCheck::readSoln(check_c_str, 1, correctSoln);
00080     if (err != 0) {
00081       //If we failed to read the data for the "correct" solution, assume that
00082       //this is simply a portion of the solution (e.g., lagrange multipliers)
00083       //that this test isn't supposed to compare.
00084       //FEI_COUT << "FEI_tester: checkSolution: no check-file for '"<<extension
00085       //    << "' portion of solution, skipping..." << FEI_ENDL;
00086       return(0);
00087     }
00088 
00089     std::string fullSoln_str = fullSolnFileName.str();
00090     const char* soln_c_str = fullSoln_str.c_str();
00091     err = SolnCheck::readSoln(soln_c_str, numProcs, soln);
00092     if (err != 0) return(err);
00093 
00094     FEI_COUT << "FEI_tester:checkSolution: checking '"<<extension<<"' solution...";
00095     int solnCheckCode = SolnCheck::compareSoln(soln, correctSoln);
00096 
00097     if (solnCheckCode != 0) return(-1);
00098     FEI_COUT << " ok"<<FEI_ENDL;
00099   }
00100   return(0);
00101 }
00102 

Generated on Wed May 12 21:30:42 2010 for FEI by  doxygen 1.4.7