[Test] Use correct yml file for parameterization factory

parent c9a8c84f
......@@ -10,6 +10,59 @@
#include <dune/dorie/common/parameterization_factory.hh>
#include "test-parameterization.hh"
/// Return parameter values based on the material index
/** \param index index assigned to the material
* \return Map of parameters and associated values
* \throw runtime_error index is not known
*/
std::multimap<std::string, double> get_parameter_map (const int index)
{
if (index == 0) { // scalar
return std::multimap<std::string, double> {
{"val", 1.}
};
}
else if (index == 1) { // 2Dvector
return std::multimap<std::string, double> {
{"val_x", 1.},
{"val_y", 2.}
};
}
else if (index == 2) { // 2Dtensor
return std::multimap<std::string, double> {
{"val_xx", 1.},
{"val_xy", 2.},
{"val_yx", 3.},
{"val_yy", 4.}
};
}
else if (index == 3) { // 3Dvector
return std::multimap<std::string, double> {
{"val_x", 1.},
{"val_y", 2.},
{"val_z", 3.}
};
}
else if (index == 4) { // 3Dtensor
return std::multimap<std::string, double> {
{"val_xx", 1.},
{"val_xy", 2.},
{"val_xz", 3.},
{"val_yx", 4.},
{"val_yy", 5.},
{"val_yz", 6.},
{"val_zx", 7.},
{"val_zy", 8.},
{"val_zz", 9.}
};
}
else {
throw std::runtime_error("Unknown index " + index);
}
}
struct Param {
virtual ~Param() = default;
virtual std::multimap<std::string, double&> parameters() = 0;
......@@ -86,6 +139,18 @@ struct ParamFactory : public Dune::Dorie::ParameterizationFactory<Param>
}
};
template<typename ParamMap, typename ParamGetter>
bool compare_parameter_maps(const ParamMap& param_map, const ParamGetter& param_getter)
{
bool pass = true;
for (const auto& [index,param] : param_map)
{
pass &= compare_maps(param->parameters(),param_getter(index));
}
return pass;
}
int main (int argc, char** argv)
{
try{
......@@ -96,11 +161,17 @@ int main (int argc, char** argv)
const auto log = Dune::Dorie::create_base_logger(helper,
spdlog::level::trace);
const YAML::Node param_file = YAML::LoadFile("test-param-reader.yml");
const YAML::Node param_file = YAML::LoadFile("test-param-factory.yml");
// Create factory and read parameters
ParamFactory factory;
auto result = factory.reader(param_file,"param",log);
DUNE_THROW(Dune::NotImplemented,"Test is unfinished!");
auto param_map = factory.reader(param_file,"param",log);
// Wrap map getter in a lambda
auto parameter_getter = [](int index){return get_parameter_map(index);};
// Compare parameters from yaml with hardcoded values
return !compare_parameter_maps(param_map,parameter_getter);
}
catch (Dune::Exception &e) {
......
......@@ -3,6 +3,7 @@
#include <dune/common/fvector.hh>
#include <dune/common/fmatrix.hh>
#include <dune/common/float_cmp.hh>
#include <dune/grid/yaspgrid.hh>
......@@ -20,11 +21,14 @@ bool compare_maps (const MapA& map_a, const MapB& map_b)
{
auto&& [key_a,value_a] = *it_a;
auto&& [key_b,value_b] = *it_b;
if (key_a<key_b) ++it_a;
else if (key_b<key_a) ++it_b;
else {
if (not Dune::FloatCmp::eq(value_a, value_b)) {
std::cout << key_a << " " << key_b << " " << value_a << " " << value_b << std::endl;
std::cout << "Error comparing maps: " << std::endl;
std::cout << " MapA[" << key_a << "]:" << value_a << std::endl;
std::cout << " MapB[" << key_b << "]:" << value_b << std::endl;
return false;
}
else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment