FEI Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
test_utils
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
13
#include <
test_utils/fei_test_utils.hpp
>
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
//==============================================================================
44
int
SolnCheck::compareSoln
(
fei::FillableMat
& solution1,
fei::FillableMat
& solution2,
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
//==============================================================================
57
int
SolnCheck::compareMatrices
(
fei::FillableMat
& mat1,
fei::FillableMat
& mat2)
58
{
59
return
(
fei_test_utils::compareMatrices
(mat1, mat2) );
60
}
61
62
//----------------------------------------------------------------------------
63
int
SolnCheck::checkSolution
(
int
localProc,
int
numProcs,
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
SolnCheck.hpp
fei::FillableMat
Definition
fei_FillableMat.hpp:20
fei::FillableMat::putCoef
void putCoef(int row, int col, double coef)
Definition
fei_FillableMat.cpp:132
fei_fstream.hpp
FEI_IFSTREAM
#define FEI_IFSTREAM
Definition
fei_fstream.hpp:13
fei_iostream.hpp
FEI_ENDL
#define FEI_ENDL
Definition
fei_iostream.hpp:34
FEI_COUT
#define FEI_COUT
Definition
fei_iostream.hpp:33
fei_sstream.hpp
FEI_OSTRINGSTREAM
#define FEI_OSTRINGSTREAM
Definition
fei_sstream.hpp:32
fei_test_utils.hpp
SolnCheck::readSoln
int readSoln(const char *baseName, int np, fei::FillableMat &solution)
Definition
SolnCheck.cpp:18
SolnCheck::compareMatrices
int compareMatrices(fei::FillableMat &mat1, fei::FillableMat &mat2)
Definition
SolnCheck.cpp:57
SolnCheck::compareSoln
int compareSoln(fei::FillableMat &solution1, fei::FillableMat &solution2, double tol=1.e-3)
Definition
SolnCheck.cpp:44
SolnCheck::checkSolution
int checkSolution(int localProc, int numProcs, const char *solnFileName, const char *checkFileName, const char *extension, int solveCounter)
Definition
SolnCheck.cpp:63
SolnCheck::readMatrix
int readMatrix(const char *baseName, int np, fei::FillableMat &matrix)
Definition
SolnCheck.cpp:51
fei_test_utils::compareMatrices
int compareMatrices(fei::FillableMat &mat1, fei::FillableMat &mat2, double tol)
Definition
fei_test_utils.cpp:396
fei_test_utils::readMatrix
int readMatrix(const char *baseName, int np, fei::FillableMat &matrix)
Definition
fei_test_utils.cpp:403
fei::print
void print(std::ostream &os, const FillableMat &mat)
Definition
fei_FillableMat.cpp:252
Generated by
1.17.0