WaveBlocksND
hawp_scalar_decoder.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdexcept>
4 #include <memory>
5 
6 #include "../wavepackets/hawp_commons.hpp"
7 #include "../wavepackets/shapes/shape_enumerator.hpp"
8 #include "../csv/hawp_coeffs_loader.hpp"
10 #include "shape_decoder.hpp"
11 
12 
13 namespace waveblocks {
14  namespace yaml {
15 
16  template<dim_t D, class MultiIndex>
18  {
19  public:
20  unsigned logging_verbosity = 0; // logging disabled by default
21 
22  ScalarHaWp<D,MultiIndex> operator()(YAML::Node const& config)
23  {
24  if (config["dimensionality"] && D != config["dimensionality"].as<int>())
25  throw std::runtime_error("incompatible wavepacket. reason: dimensionality does not match");
26 
27  if (config["n_components"] && 1 != config["n_components"].as<int>())
28  throw std::runtime_error("incompatible wavepacket. reason: number of components > 1");
29 
30  if (1 != config["parameters"].size())
31  throw std::runtime_error("incompatible wavepacket. reason: number of parameter sets > 1");
32 
33  if (1 != config["shapes"].size())
34  throw std::runtime_error("incompatible wavepacket. reason: number of shapes > 1");
35 
36  // if (1 != config["coefficients"].size())
37  // throw std::runtime_error("incompatible wavepacket. reason: number of coefficients vectors > 1");
38  //
39 
40  // (1) decode eps
41  ScalarHaWp<D,MultiIndex> wp;
42  wp.eps() = config["eps"].as<double>();
43 
44  // (2) decode parameters
45  HaWpParamSetDecoder<D> paramset_decoder;
46  wp.parameters() = paramset_decoder(config["parameters"][0]);
47 
48  // (3) decode and enumerate shape
49  ShapeDecoder<D> shape_decoder;
50  ShapeEnumerator<D,MultiIndex> shape_enumerator;
51  AbstractShape<D>* shape = shape_decoder(config["shapes"][0]);
52  wp.shape() = shape_enumerator.enumerate(shape);
53  delete shape;
54 
55  return wp;
56  }
57  };
58  }
59 }
Definition: hawp_scalar_decoder.hpp:17
Definition: coefficients_file_parser.cpp:10
unsigned logging_verbosity
Definition: hawp_scalar_decoder.hpp:20
Definition: hawp_paramset_decoder.hpp:16
ScalarHaWp< D, MultiIndex > operator()(YAML::Node const &config)
Definition: hawp_scalar_decoder.hpp:22
Definition: shape_decoder.hpp:18