https://mooseframework.inl.gov
TestStochasticToolsCartesianProduct.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "gtest/gtest.h"
11 #include "CartesianProduct.h"
12 
13 using namespace StochasticTools;
14 
16 {
17  const std::vector<std::vector<Real>> gold = {
18  {2, 3, 4}, {2, 3, 16}, {2, 9, 4}, {2, 9, 16}, {2, 27, 4}, {2, 27, 16},
19  {4, 3, 4}, {4, 3, 16}, {4, 9, 4}, {4, 9, 16}, {4, 27, 4}, {4, 27, 16},
20  {8, 3, 4}, {8, 3, 16}, {8, 9, 4}, {8, 9, 16}, {8, 27, 4}, {8, 27, 16},
21  {16, 3, 4}, {16, 3, 16}, {16, 9, 4}, {16, 9, 16}, {16, 27, 4}, {16, 27, 16}};
22 
23  const std::vector<std::vector<Real>> x = {{2, 4, 8, 16}, {3, 9, 27}, {4, 16}};
24 
26 
27  EXPECT_EQ(cp.numRows(), (std::size_t)24);
28  EXPECT_EQ(cp.numCols(), (std::size_t)3);
29 
30  {
31  auto out = cp.computeMatrix();
32  EXPECT_EQ(out, gold);
33  }
34 
35  {
36  EXPECT_EQ(cp.computeRow(0), gold[0]);
37  EXPECT_EQ(cp.computeRow(1), gold[1]);
38  EXPECT_EQ(cp.computeRow(2), gold[2]);
39  EXPECT_EQ(cp.computeRow(3), gold[3]);
40  EXPECT_EQ(cp.computeRow(4), gold[4]);
41  EXPECT_EQ(cp.computeRow(5), gold[5]);
42  EXPECT_EQ(cp.computeRow(6), gold[6]);
43  EXPECT_EQ(cp.computeRow(7), gold[7]);
44  EXPECT_EQ(cp.computeRow(8), gold[8]);
45  EXPECT_EQ(cp.computeRow(9), gold[9]);
46  EXPECT_EQ(cp.computeRow(10), gold[10]);
47  EXPECT_EQ(cp.computeRow(11), gold[11]);
48  EXPECT_EQ(cp.computeRow(12), gold[12]);
49  EXPECT_EQ(cp.computeRow(13), gold[13]);
50  EXPECT_EQ(cp.computeRow(14), gold[14]);
51  EXPECT_EQ(cp.computeRow(15), gold[15]);
52  EXPECT_EQ(cp.computeRow(16), gold[16]);
53  EXPECT_EQ(cp.computeRow(17), gold[17]);
54  EXPECT_EQ(cp.computeRow(18), gold[18]);
55  EXPECT_EQ(cp.computeRow(19), gold[19]);
56  EXPECT_EQ(cp.computeRow(20), gold[20]);
57  EXPECT_EQ(cp.computeRow(21), gold[21]);
58  EXPECT_EQ(cp.computeRow(22), gold[22]);
59  EXPECT_EQ(cp.computeRow(23), gold[23]);
60  }
61 
62  {
63  for (std::size_t row = 0; row < cp.numRows(); ++row)
64  for (std::size_t col = 0; col < cp.numCols(); ++col)
65  EXPECT_EQ(cp.computeValue(row, col), gold[row][col]);
66  }
67 }
68 
70 {
71  const std::vector<Real> gold = {
72  1 * 10 * 100, 1 * 10 * 110, 1 * 11 * 100, 1 * 11 * 110, 1 * 12 * 100, 1 * 12 * 110,
73  2 * 10 * 100, 2 * 10 * 110, 2 * 11 * 100, 2 * 11 * 110, 2 * 12 * 100, 2 * 12 * 110,
74  3 * 10 * 100, 3 * 10 * 110, 3 * 11 * 100, 3 * 11 * 110, 3 * 12 * 100, 3 * 12 * 110,
75  4 * 10 * 100, 4 * 10 * 110, 4 * 11 * 100, 4 * 11 * 110, 4 * 12 * 100, 4 * 12 * 110};
76 
77  const std::vector<std::vector<Real>> x = {{2, 4, 8, 16}, {3, 9, 27}, {4, 16}};
78  const std::vector<std::vector<Real>> w = {{1, 2, 3, 4}, {10, 11, 12}, {100, 110}};
79 
81 
82  EXPECT_EQ(wcp.numRows(), (std::size_t)24);
83  EXPECT_EQ(wcp.numCols(), (std::size_t)3);
84 
85  {
86  auto out = wcp.computeWeightVector();
87  EXPECT_EQ(out, gold);
88  }
89 
90  {
91  for (std::size_t row = 0; row < wcp.numRows(); ++row)
92  EXPECT_EQ(wcp.computeWeight(row), gold[row]);
93  }
94 }
W computeWeight(std::size_t row) const
Compute specific weight value, given row.
static const std::string cp
Definition: NS.h:121
Enum for batch type in stochastic tools MultiApp.
const std::vector< double > x
std::size_t numCols() const
Total number of columns in the complete matrix.
OStreamProxy out
std::size_t numRows() const
Total number of rows in the complete matrix.
std::vector< W > computeWeightVector() const
Compute complete vector of weights.
TEST(StochasticTools, CartesianProduct)