1 /*  _______________________________________________________________________
2 
3     DAKOTA: Design Analysis Kit for Optimization and Terascale Applications
4     Copyright 2014-2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
5     This software is distributed under the GNU Lesser General Public License.
6     For more information, see the README file in the top Dakota directory.
7     _______________________________________________________________________ */
8 
9 
10 #include "dakota_data_io.hpp"
11 #include "dakota_tabular_io.hpp"
12 
13 #include <string>
14 
15 #include <Teuchos_UnitTestHarness.hpp>
16 
17 using namespace Dakota;
18 
19 //----------------------------------------------------------------
20 
TEUCHOS_UNIT_TEST(covariance_reader,read_constant_covariance)21 TEUCHOS_UNIT_TEST(covariance_reader, read_constant_covariance)
22 {
23   const std::string base_name = "expt_data_test_files/voltage";
24 
25   RealMatrix cov_values;
26   read_covariance(base_name, 1 /* expt number */, cov_values); // implies CONSTANT
27 
28   // Verify equality of config data
29   TEST_EQUALITY( cov_values.numRows(), 1 );
30   TEST_EQUALITY( cov_values.numCols(), 1 );
31   TEST_FLOATING_EQUALITY( cov_values[0][0], 3.67, 1.e-14 );
32 }
33 
34 //----------------------------------------------------------------
35 
TEUCHOS_UNIT_TEST(covariance_reader,read_vector_covariance)36 TEUCHOS_UNIT_TEST(covariance_reader, read_vector_covariance)
37 {
38   const std::string base_name = "expt_data_test_files/voltage";
39 
40   RealMatrix cov_values;
41   read_covariance(base_name, 2, // expt number
42                   Dakota::CovarianceMatrix::VECTOR,
43                   9, // num values in covariance VECTOR
44                   cov_values);
45 
46   double gold_values[] = { 2.34, 8.552, -3.654, 7.332, 0.01, -0.1509, -5.98, 4.74, 9.99 };
47   // Verify equality of config data
48   TEST_EQUALITY( cov_values.numRows(), 1 );
49   TEST_EQUALITY( cov_values.numCols(), 9 );
50   for( int i=0; i<9; ++i )
51     TEST_FLOATING_EQUALITY( cov_values[i][0], gold_values[i], 1.e-14 );
52 }
53 
54 //----------------------------------------------------------------
55 
TEUCHOS_UNIT_TEST(covariance_reader,read_matrix_covariance)56 TEUCHOS_UNIT_TEST(covariance_reader, read_matrix_covariance)
57 {
58   const std::string base_name = "expt_data_test_files/voltage";
59 
60   RealMatrix cov_values;
61   read_covariance(base_name, 3, // expt number
62                   Dakota::CovarianceMatrix::MATRIX,
63                   9, // num values in covariance MATRIX row (total entries = 9*9)
64                   cov_values);
65 
66   // Verify equality of config data
67   TEST_EQUALITY( cov_values.numRows(), 9 );
68   TEST_EQUALITY( cov_values.numCols(), 9 );
69   for( int i=0; i<9; ++i )
70     for( int j=0; j<9; ++j )
71       TEST_FLOATING_EQUALITY( cov_values[i][j], (double)(i+j)/2.0, 1.e-14 );
72 }
73 
74 //----------------------------------------------------------------
75