WaveBlocksND
hawp_paramset_decoder.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdexcept>
4 
5 #include <yaml-cpp/yaml.h>
6 #include <Eigen/Core>
7 
8 #include "../wavepackets/hawp_paramset.hpp"
9 #include "complex.hpp"
10 
11 
12 namespace waveblocks {
13  namespace yaml {
14 
15  template<dim_t D>
17  {
18  public:
19  HaWpParamSet<D> operator()(YAML::Node const& config)
20  {
21  HaWpParamSet<D> params;
22 
23  params.q(decode_rvector(config["q"]));
24  params.p(decode_rvector(config["p"]));
25  params.Q(decode_cmatrix(config["Q"]));
26  params.P(decode_cmatrix(config["P"]));
27 
28  // if (config["sqrt_detQ"]) {
29  // params.sqrt_detQ = config["sqrt_detQ"].as<std::complex<double> >();
30  // }
31  //
32  return params;
33  }
34 
35  private:
36  Eigen::Matrix<real_t,D,1> decode_rvector(YAML::Node const& config)
37  {
38  Eigen::Matrix<real_t,D,1> result(D,1);
39 
40  if (config.size() != D)
41  throw std::runtime_error("encountered vector dimension != parameter set dimensionality");
42 
43  for (dim_t i = 0; i < D; i++) {
44  result(i,0) = config[i].as<double>();
45  }
46 
47  return result;
48  }
49 
50  Eigen::Matrix<complex_t,D,D> decode_cmatrix(YAML::Node const& config)
51  {
52  Eigen::Matrix<complex_t,D,D> result(D,D);
53 
54  if (config.size() != D)
55  throw std::runtime_error("encountered matrix column dimension != parameter set dimensionality");
56 
57  for (dim_t i = 0; i < D; i++) {
58  YAML::Node const& in_row = config[i];
59 
60  if (in_row.size() != D)
61  throw std::runtime_error("encountered matrix row dimension != parameter set dimensionality");
62 
63  for (dim_t j = 0; j < D; j++) {
64  result(i,j) = in_row[j].as< std::complex<double> >();
65  }
66  }
67 
68  return result;
69  }
70  };
71  }
72 }
Definition: coefficients_file_parser.cpp:10
Definition: hawp_paramset_decoder.hpp:16
HaWpParamSet< D > operator()(YAML::Node const &config)
Definition: hawp_paramset_decoder.hpp:19
Eigen::Matrix< complex_t, D, D > decode_cmatrix(YAML::Node const &config)
Definition: hawp_paramset_decoder.hpp:50
Eigen::Matrix< real_t, D, 1 > decode_rvector(YAML::Node const &config)
Definition: hawp_paramset_decoder.hpp:36
int dim_t
Definition: types.hpp:16