https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Functions
TestStochasticToolsCalculators.C File Reference

Go to the source code of this file.

Functions

template<typename InType , typename OutType >
std::pair< std::vector< OutType >, std::vector< OutType > > calculate (const InType &x, const std::vector< std::string > &compute)
 
 TEST (StochasticTools, Calculators)
 

Function Documentation

◆ calculate()

template<typename InType , typename OutType >
std::pair< std::vector< OutType >, std::vector< OutType > > calculate ( const InType &  x,
const std::vector< std::string > &  compute 
)

Definition at line 20 of file TestStochasticToolsCalculators.C.

21{
22 Parallel::Communicator comm;
24 std::vector<std::unique_ptr<StochasticTools::Calculator<InType, OutType>>> calcs;
25 for (const auto & stat : compute)
26 calcs.push_back(StochasticTools::makeCalculator<InType, OutType>(stat, po));
27
28 std::vector<OutType> result1;
29 for (unsigned int i = 0; i < calcs.size(); ++i)
30 result1.push_back(calcs[i]->compute(x, false));
31
32 std::vector<OutType> result2;
33 for (unsigned int i = 0; i < calcs.size(); ++i)
34 {
35 calcs[i]->initializeCalculator();
36 for (const auto & val : x)
37 calcs[i]->updateCalculator(val);
38 calcs[i]->finalizeCalculator(false);
39 result2.push_back(calcs[i]->getValue());
40 }
41
42 return {result1, result2};
43}
const std::vector< double > x
Outputs compute(const MooseEnum &rate, const Inputs &in, bool need_jacobian)
Dispatch to the rate selected by the objective_rate enum (truesdell / jaumann / green_naghdi / rashid...
Enum for batch type in stochastic tools MultiApp.
std::unique_ptr< Calculator< InType, OutType > > makeCalculator(const MooseEnumItem &item, const libMesh::ParallelObject &other)

◆ TEST()

TEST ( StochasticTools  ,
Calculators   
)

Definition at line 45 of file TestStochasticToolsCalculators.C.

46{
47 const std::vector<std::string> compute = {
48 "mean", "min", "max", "sum", "stddev", "stderr", "ratio", "norm2", "median"};
49
50 {
51 const std::vector<Real> x = {6, 1, 7, 3, 4, 5, 2};
52 const std::vector<Real> expect = {
53 4, 1, 7, 28, 2.1602468994692869408, 0.81649658092772603446, 7, 11.832159566199232259, 4};
54
55 auto result = calculate<std::vector<Real>, Real>(x, compute);
56 for (unsigned int i = 0; i < expect.size(); ++i)
57 {
58 EXPECT_EQ(result.first[i], expect[i]);
59 EXPECT_EQ(result.second[i], expect[i]);
60 }
61 }
62
63 {
64 const std::vector<int> x = {6, 1, 7, 3, 4, 5, 2};
65 const std::vector<Real> expect = {
66 4, 1, 7, 28, 2.1602468994692869408, 0.81649658092772603446, 7, 11.832159566199232259, 4};
67
68 auto result = calculate<std::vector<int>, Real>(x, compute);
69 for (unsigned int i = 0; i < expect.size(); ++i)
70 {
71 EXPECT_EQ(result.first[i], expect[i]);
72 EXPECT_EQ(result.second[i], expect[i]);
73 }
74 }
75
76 {
77 const std::vector<std::vector<Real>> x = {{6, 1, 7, 3, 4, 5, 2},
78 {1, 7, 3, 4, 5, 2, 6},
79 {7, 3, 4, 5, 2, 6, 1},
80 {3, 4, 5, 2, 6, 1, 7},
81 {4, 5, 2, 6, 1, 7, 3},
82 {5, 2, 6, 1, 7, 3, 4},
83 {2, 6, 1, 7, 3, 4, 5}};
84 const std::vector<Real> expect = {
85 4, 1, 7, 28, 2.1602468994692869408, 0.81649658092772603446, 7, 11.832159566199232259, 4};
86
87 auto result = calculate<std::vector<std::vector<Real>>, std::vector<Real>>(x, compute);
88 for (unsigned int i = 0; i < expect.size(); ++i)
89 for (unsigned int j = 0; j < x[0].size(); ++j)
90 {
91 EXPECT_EQ(result.first[i][j], expect[i]);
92 EXPECT_EQ(result.second[i][j], expect[i]);
93 }
94 }
95}
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real