| 263 | } |
| 264 | |
| 265 | ParameterManager::Ptr ParameterManager::create_from_dof_file( |
| 266 | WireNetwork::Ptr wire_network, Float default_thickness, |
| 267 | const std::string& dof_file) { |
| 268 | PTree dof_config; |
| 269 | read_json(dof_file, dof_config); |
| 270 | std::string dof_type = dof_config.get<std::string>("dof_type"); |
| 271 | std::string thickness_type_str = |
| 272 | dof_config.get<std::string>("thickness_type"); |
| 273 | |
| 274 | PTree& dof_values = dof_config.get_child("dof"); |
| 275 | VectorF dof = VectorF::Zero(dof_values.size()); |
| 276 | size_t count = 0; |
| 277 | for (const auto& value : dof_values) { |
| 278 | dof[count] = value.second.get_value<Float>(); |
| 279 | count++; |
| 280 | } |
| 281 | assert(count == dof.size()); |
| 282 | |
| 283 | TargetType thickness_type = ParameterCommon::VERTEX; |
| 284 | if (thickness_type_str == "vertex") { |
| 285 | thickness_type = ParameterCommon::VERTEX; |
| 286 | } else if (thickness_type_str == "edge") { |
| 287 | thickness_type = ParameterCommon::EDGE; |
| 288 | } |
| 289 | |
| 290 | Ptr manager; |
| 291 | if (dof_type == "isotropic") { |
| 292 | manager = ParameterManager::create_isotropic(wire_network, |
| 293 | default_thickness, thickness_type); |
| 294 | } else if (dof_type == "orthotropic") { |
| 295 | manager = ParameterManager::create(wire_network, |
| 296 | default_thickness, thickness_type); |
| 297 | } else { |
| 298 | std::stringstream err_msg; |
| 299 | err_msg << "Unknown dof type: " << dof_type; |
| 300 | throw NotImplementedError(err_msg.str()); |
| 301 | } |
| 302 | |
| 303 | size_t num_dofs = manager->get_num_dofs(); |
| 304 | if (num_dofs > dof.size()) { |
| 305 | std::stringstream err_msg; |
| 306 | err_msg << "Dof mismatch: expect " << num_dofs |
| 307 | << " dofs, but only received " << dof.size() << " values"; |
| 308 | throw RuntimeError(err_msg.str()); |
| 309 | } |
| 310 | manager->set_dofs(dof.segment(0, num_dofs)); |
| 311 | return manager; |
| 312 | } |
| 313 | |
| 314 | ParameterManager::ParameterManager( |
| 315 | WireNetwork::Ptr wire_network, Float default_thickness) : |
no test coverage detected