2 #include "libmesh/libmesh_exceptions.h" 3 #include "libmesh/rb_parameters.h" 4 #include "libmesh/rb_parametrized.h" 5 #include "libmesh/simple_range.h" 6 #include "libmesh/int_range.h" 10 #include <cppunit/TestAssert.h> 18 CPPUNIT_TEST( testScalar );
19 CPPUNIT_TEST( testOldConstructor );
20 CPPUNIT_TEST( testIterators );
21 CPPUNIT_TEST( testIteratorsWithSamples );
22 CPPUNIT_TEST( testAppend );
23 CPPUNIT_TEST( testNSamples );
24 CPPUNIT_TEST( testMultiValued );
25 CPPUNIT_TEST( testRBParametrized );
26 CPPUNIT_TEST_SUITE_END();
63 std::map<std::string, Real> in = {{
"a", 1.}, {
"b", 2.}, {
"c", 3.}};
79 CPPUNIT_ASSERT_EQUAL(params.
n_samples(), 1u);
92 std::map<std::string, Real> m;
99 CPPUNIT_ASSERT(m.count(
"a"));
100 CPPUNIT_ASSERT(m.count(
"b"));
101 CPPUNIT_ASSERT(m.count(
"c"));
102 CPPUNIT_ASSERT_EQUAL(m[
"a"],
Real(1));
103 CPPUNIT_ASSERT_EQUAL(m[
"b"],
Real(2));
104 CPPUNIT_ASSERT_EQUAL(m[
"c"],
Real(3));
120 std::map<std::string, Real> m;
129 CPPUNIT_ASSERT(m.count(
"a"));
130 CPPUNIT_ASSERT(m.count(
"b"));
131 CPPUNIT_ASSERT(m.count(
"c"));
132 CPPUNIT_ASSERT_EQUAL(m[
"a"],
Real(1));
133 CPPUNIT_ASSERT_EQUAL(m[
"b"],
Real(2));
134 CPPUNIT_ASSERT_EQUAL(m[
"c"],
Real(3));
143 for (
int i=0; i<3; ++i)
149 for (
int i=0; i<3; ++i)
164 for (
int i=0; i<3; ++i)
177 CPPUNIT_ASSERT_EQUAL(params.
n_samples(),
static_cast<unsigned int>(1));
181 CPPUNIT_ASSERT_EQUAL(params.
n_samples(),
static_cast<unsigned int>(10));
189 CPPUNIT_ASSERT_EQUAL(params.
n_samples(),
static_cast<unsigned int>(4));
197 CPPUNIT_ASSERT_EQUAL(params.
n_samples(),
static_cast<unsigned int>(4));
198 CPPUNIT_ASSERT_EQUAL(params.
n_parameters(),
static_cast<unsigned int>(2));
208 #ifdef LIBMESH_ENABLE_EXCEPTIONS 221 std::vector<Real> test_vec1 = {2.1, 2.2, 2.3};
222 params.
set_value(
"a", 0, {1.1, 1.2, 1.3});
224 params.
set_value(
"a", 2, {3.1, 3.2, 3.3});
225 params.
set_value(
"b", 2, {3.1, 3.2, 3.3});
227 #ifdef LIBMESH_ENABLE_EXCEPTIONS 239 for (
const auto index :
index_range(vector_value_1))
240 CPPUNIT_ASSERT_EQUAL(vector_value_1[index], test_vec1[index]);
242 for (
const auto index :
index_range(vector_value_2))
243 CPPUNIT_ASSERT_EQUAL(vector_value_2[index], test_vec1[index]);
245 std::vector<Real> test_vec2 = {5.1, 5.2, 5.3};
249 for (
const auto index :
index_range(vector_value_3))
250 CPPUNIT_ASSERT_EQUAL(vector_value_3[index], test_vec2[index]);
265 #ifdef LIBMESH_ENABLE_EXCEPTIONS 273 #ifdef LIBMESH_ENABLE_EXCEPTIONS 280 mu_max.set_value(
"a", 10.);
298 #ifdef LIBMESH_ENABLE_EXCEPTIONS 300 mu_max.set_value(
"b", 3, 40.);
Real get_value(const std::string ¶m_name) const
Get the value of the specified parameter, throw an error if it does not exist.
void testOldConstructor()
Real get_extra_sample_value(const std::string ¶m_name, std::size_t sample_idx) const
Get the value of the specified "extra" parameter at the specified sample index, throwing an error if ...
bool has_value(const std::string ¶m_name) const
CPPUNIT_TEST_SUITE_REGISTRATION(RBParametersTest)
const_iterator begin_serialized() const
Get const_iterator access to the parameters stored in this RBParameters object.
void testRBParametrized()
The libMesh namespace provides an interface to certain functionality in the library.
unsigned int n_parameters() const
Get the number of parameters that have been added.
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.
const RBParameter & get_sample_vector_value(const std::string ¶m_name, std::size_t sample_idx) const
This class is part of the rbOOmit framework.
bool has_extra_value(const std::string ¶m_name) const
bool set_parameters(const RBParameters ¶ms)
Set the current parameters to params The parameters are checked for validity; an error is thrown if t...
unsigned int n_samples() const
Returns the number of samples stored for all parameters.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real get_sample_value(const std::string ¶m_name, std::size_t sample_idx) const
Get the value of the specified parameter at the specified sample, throwing an error if it does not ex...
void testIteratorsWithSamples()
void push_back_extra_value(const std::string ¶m_name, Real value)
Same as push_back_value(), but for "extra" parameters.
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
void set_value(const std::string ¶m_name, Real value)
Set the value of the specified parameter.
This class is part of the rbOOmit framework.
const_iterator end_serialized() const
void push_back_value(const std::string ¶m_name, Real value)
Similar to set_value(name, index, value) but instead of specifying a particular index, just appends one more.
void initialize_parameters(const RBParameters &mu_min_in, const RBParameters &mu_max_in, const std::map< std::string, std::vector< Real >> &discrete_parameter_values)
Initialize the parameter ranges and set current_parameters.
void set_n_samples(unsigned int n_samples)
Set the number of samples this RBParameters object is intended to represent, in the case that there a...
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...