[Param] Loop over parameters class and fix factory interface

parent 3875eefe
......@@ -39,7 +39,7 @@ struct ParameterizationFactory
*/
virtual std::shared_ptr<Param> selector(
const YAML::Node& type_node,
const std::string name) const = 0;
const std::string& name) const = 0;
/**
......@@ -58,7 +58,7 @@ struct ParameterizationFactory
*/
std::unordered_map<int, std::shared_ptr<Param>>
reader( const YAML::Node& param_file,
const std::string param_name,
const std::string& param_name,
const std::shared_ptr<spdlog::logger> log) const
{
// mapping: index on grid to parameterization object (will be returned)
......@@ -70,60 +70,41 @@ struct ParameterizationFactory
// iterate over all volume nodes
for (auto&& node : param_file["volumes"])
{
const auto name = node.first.as<std::string>();
const auto volume = node.first.as<std::string>();
const YAML::Node param_info = node.second;
// read relevant data
const auto index = param_info["index"].as<int>();
if (param_index_set.count(index) != 0) {
log->error("Index '{}' in material '{}' of parameterization '{}'"
log->error("Index '{}' in volume '{}' of parameterization '{}'"
"already exists.",
index, name, param_name);
index, volume, param_name);
DUNE_THROW(IOError, "Parameter file indices must be unique");
}
param_index_set.emplace(index);
// get parameterization object
const YAML::Node& type_node = param_info[param_name];
auto parameterization = this->selector(type_node, name);
auto parameterization = this->selector(type_node, volume);
auto parameter_values = parameterization->parameters();
// fill parameterization with parameter entries
log->trace(" Reading parameters. Volume: {}, Index: {}",
name, index);
log->trace(" Required parameters: {}", parameter_values.size());
for (auto p : parameter_values)
log->trace(" {}", p.first);
volume, index);
auto yaml_parameters = yaml_sequence_to_map(type_node["parameters"]);
log->trace(" Available parameters: {}",
yaml_parameters.size());
unsigned param_used = 0;
for (auto&& yaml_param : yaml_parameters)
for (auto&& [name, value] : parameter_values)
{
const auto p_name = yaml_param.first.as<std::string>();
const auto p_value = yaml_param.second.as<double>();
// try to insert the value into the parameter map
auto [begin,end] = parameter_values.equal_range(p_name);
if (begin==end) { // mark unused parameter
log->trace(" - {}: {}", p_name, p_value);
} else { // mark and set parameter
for (auto p = begin; p != end; ++p) {
p->second = p_value;
log->trace(" + {}: {}", p->first, p->second);
param_used++;
}
try {
value = yaml_parameters[name].template as<double>();
}
catch (...) {
log->error(" Parameter '{}' is missing in '{}' parameterization,"
" volume {}, index {}.",
name, param_name, volume, index);
DUNE_THROW(IOError, "Missing parameters!");
}
}
if (param_used!=parameter_values.size()) {
log->error(" Parameters used: {} of {}. "
"Volume: {}, Index: {}.",
param_used,parameter_values.size(),name, index);
DUNE_THROW(IOError, "Missing parameters!");
}
ret.emplace(index, parameterization);
......
......@@ -28,7 +28,7 @@ struct RichardsFactory
std::shared_ptr<Richards<Traits>>
selector(
const YAML::Node& type_node,
const std::string name) const override
const std::string& name) const override
{
auto log = Dorie::get_logger(log_richards);
const auto type = type_node["type"].as<std::string>();
......
......@@ -42,7 +42,7 @@ struct TransportFactory
std::shared_ptr<Transport<Traits>>
selector(
const YAML::Node& type_node,
const std::string name) const override
const std::string& name) const override
{
auto log = Dorie::get_logger(log_transport);
......
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