FEI Version of the Day
SolnCheck.cpp
00001 /*
00002 // @HEADER
00003 // ************************************************************************
00004 //             FEI: Finite Element Interface to Linear Solvers
00005 //                  Copyright (2005) Sandia Corporation.
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the
00008 // U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Alan Williams (william@sandia.gov) 
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 */
00042 
00043 #include <fei_iostream.hpp>
00044 #include <fei_sstream.hpp>
00045 #include <fei_fstream.hpp>
00046 
00047 #include <test_utils/fei_test_utils.hpp>
00048 
00049 #include <test_utils/SolnCheck.hpp>
00050 
00051 //==============================================================================
00052 int SolnCheck::readSoln(const char* baseName, int np, fei::FillableMat& solution)
00053 {
00054   for(int i=0; i<np; i++) {
00055     FEI_OSTRINGSTREAM osstr;
00056     osstr << baseName << "." << np << "." << i;
00057     FEI_IFSTREAM infile(osstr.str().c_str());
00058     if (!infile || infile.bad()) return(-1);
00059 
00060     int node, numDOF;
00061     double tmpValue;
00062     infile >> node;
00063     while(!infile.eof()) {
00064       infile >> numDOF;
00065 
00066       for(int j=0; j<numDOF; j++) {
00067         infile >> tmpValue;
00068         solution.putCoef(node,j,tmpValue);
00069       }
00070       infile >> node;
00071     }
00072   }
00073 
00074   return(0);
00075 }
00076 
00077 //==============================================================================
00078 int SolnCheck::compareSoln(fei::FillableMat& solution1, fei::FillableMat& solution2,
00079          double tol)
00080 {
00081   return(fei_test_utils::compareMatrices(solution1, solution2, tol) );
00082 }
00083 
00084 //==============================================================================
00085 int SolnCheck::readMatrix(const char* baseName, int np, fei::FillableMat& matrix)
00086 {
00087   return( fei_test_utils::readMatrix(baseName, np, matrix) );
00088 }
00089 
00090 //==============================================================================
00091 int SolnCheck::compareMatrices(fei::FillableMat& mat1, fei::FillableMat& mat2)
00092 {
00093   return( fei_test_utils::compareMatrices(mat1, mat2) );
00094 }
00095 
00096 //----------------------------------------------------------------------------
00097 int SolnCheck::checkSolution(int localProc, int numProcs,
00098            const char* solnFileName,
00099            const char* checkFileName,
00100            const char* extension,
00101            int solveCounter)
00102 {
00103   if (localProc == 0) {
00104     fei::FillableMat soln, correctSoln;
00105     FEI_OSTRINGSTREAM fullSolnFileName;
00106     FEI_OSTRINGSTREAM fullCheckFileName;
00107 
00108     fullSolnFileName << solnFileName<<"."<<extension<<"."<<solveCounter;
00109     fullCheckFileName<< checkFileName<<"."<<extension<<".correct."<<solveCounter;
00110 
00111     std::string fullCheck_str = fullCheckFileName.str();
00112     const char* check_c_str = fullCheck_str.c_str();
00113     int err = SolnCheck::readSoln(check_c_str, 1, correctSoln);
00114     if (err != 0) {
00115       //If we failed to read the data for the "correct" solution, assume that
00116       //this is simply a portion of the solution (e.g., lagrange multipliers)
00117       //that this test isn't supposed to compare.
00118       //FEI_COUT << "FEI_tester: checkSolution: no check-file for '"<<extension
00119       //    << "' portion of solution, skipping..." << FEI_ENDL;
00120       return(0);
00121     }
00122 
00123     std::string fullSoln_str = fullSolnFileName.str();
00124     const char* soln_c_str = fullSoln_str.c_str();
00125     err = SolnCheck::readSoln(soln_c_str, numProcs, soln);
00126     if (err != 0) return(err);
00127 
00128     FEI_COUT << "FEI_tester:checkSolution: checking '"<<extension<<"' solution...";
00129     int solnCheckCode = SolnCheck::compareSoln(soln, correctSoln);
00130 
00131     if (solnCheckCode != 0) {
00132       FEI_COUT << "soln file-name: " << soln_c_str << FEI_ENDL;
00133       FEI_COUT << "soln-check failed, checkFileName="<<checkFileName<<FEI_ENDL;
00134       FEI_COUT << "soln: " << FEI_ENDL;
00135       fei::print(FEI_COUT, soln);
00136       FEI_COUT << "correctSoln file-name: " << check_c_str << FEI_ENDL;
00137       FEI_COUT << "correctSoln: " << FEI_ENDL;
00138       fei::print(FEI_COUT, correctSoln);
00139       return(-1);
00140     }
00141     FEI_COUT << " ok"<<FEI_ENDL;
00142   }
00143   return(0);
00144 }
00145 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends