Commit 4392d34a authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Add public methods to read protected parameters and IOGVEC

parent f8be5af3
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -361,6 +361,44 @@ public:
   */
  static ScattererConfiguration* from_dedfb(std::string file_name);

  /*! \brief Get the ID of a sphere by its index.
   *
   * The proper way to access read-only parameters from outside a class is to define
   * public methods that return their values. For arrays, particularly those that
   * are accessed multiple times, it is convenient to have specialized methods that
   * return the required values based on their index in the array.
   *
   * \param index: `int` Index of the ID to be retrieved.
   * \return id: `int` The desired identifier.
   */
  int get_iog(int index) { return iog_vec[index]; }
  
  /*! \brief Get the value of a parameter by name.
   *
   * The proper way to access read-only parameters from outside a class is to define
   * public methods that return their values. For configuration operations, whose
   * optimization is not critical, it is possible to define a single function that
   * returns simple scalar values called by name. Access to more complicated data
   * structures, on the other hand, require specialized methods which avoid the
   * burden of searching the necessary value across the whole arrya every time.
   *
   * \param param_name: `string` Name of the parameter to be retrieved.
   * \return value: `double` Value of the requested parameter.
   */
  double get_param(std::string param_name);
  
  /*! \brief Get the value of a scale by its index.
   *
   * The proper way to access read-only parameters from outside a class is to define
   * public methods that return their values. For arrays, particularly those that
   * are accessed multiple times, it is convenient to have specialized methods that
   * return the required values based on their index in the array.
   *
   * \param index: `int` Index of the scale to be retrieved.
   * \return scale: `double` The desired scale.
   */
  double get_scale(int index) { return scale_vec[index]; }
  
  /*! \brief Print the contents of the configuration object to terminal.
   *
   * In case of quick debug testing, `ScattererConfiguration.print()` allows printing
+23 −2
Original line number Diff line number Diff line
@@ -535,7 +535,7 @@ ScattererConfiguration* ScattererConfiguration::from_hdf5(string file_name) {
  herr_t status = hdf_file->get_status();
  string str_name, str_type;
  if (status == 0) {
    int nsph;
    int nsph, ies;
    int *iog;
    double _exdc, _wp, _xip;
    int _idfc, nxi;
@@ -545,6 +545,7 @@ ScattererConfiguration* ScattererConfiguration::from_hdf5(string file_name) {
    double **rcf_vector;
    complex<double> ***dc0m;
    status = hdf_file->read("NSPH", "INT32_(1)", &nsph);
    status = hdf_file->read("IES", "INT32_(1)", &ies);
    status = hdf_file->read("EXDC", "FLOAT64_(1)", &_exdc);
    status = hdf_file->read("WP", "FLOAT64_(1)", &_wp);
    status = hdf_file->read("XIP", "FLOAT64_(1)", &_xip);
@@ -613,7 +614,7 @@ ScattererConfiguration* ScattererConfiguration::from_hdf5(string file_name) {
				      rcf_vector,
				      _idfc,
				      dc0m,
				      false,
				      (ies == 1),
				      _exdc,
				      _wp,
				      _xip
@@ -709,6 +710,23 @@ ScattererConfiguration* ScattererConfiguration::from_legacy(string file_name) {
  return conf;
}

double ScattererConfiguration::get_param(string param_name) {
  double value;
  if (param_name.compare("number_of_spheres") == 0) value = 1.0 * number_of_spheres;
  else if (param_name.compare("nsph") == 0) value = 1.0 * number_of_spheres;
  else if (param_name.compare("number_of_scales") == 0) value = 1.0 * number_of_scales;
  else if (param_name.compare("nxi") == 0) value = 1.0 * number_of_scales;
  else if (param_name.compare("idfc") == 0) value = 1.0 * idfc;
  else if (param_name.compare("exdc") == 0) value = exdc;
  else if (param_name.compare("wp") == 0) value = wp;
  else if (param_name.compare("xip") == 0) value = xip;
  else {
    // TODO: add exception code for unknown parameter.
    return 0.0;
  }
  return value;
}

void ScattererConfiguration::print() {
  int ies = (use_external_sphere)? 1 : 0;
  int configurations = 0;
@@ -782,6 +800,9 @@ void ScattererConfiguration::write_hdf5(string file_name) {
  rec_name_list.set(0, "NSPH");
  rec_type_list.set(0, "INT32_(1)");
  rec_ptr_list.set(0, &number_of_spheres);
  rec_name_list.append("IES");
  rec_type_list.append("INT32_(1)");
  rec_ptr_list.append(&ies);
  rec_name_list.append("IOGVEC");
  str_type = "INT32_(" + to_string(number_of_spheres) + ")";
  rec_type_list.append(str_type);