OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
ProbeVariable.h
Go to the documentation of this file.
1 //
2 // Struct ProbeVariable
3 //
4 // Copyright (c) 2010 - 2013, Yves Ineichen, ETH Zürich
5 // All rights reserved
6 //
7 // Implemented as part of the PhD thesis
8 // "Toward massively parallel multi-objective optimization with application to
9 // particle accelerators" (https://doi.org/10.3929/ethz-a-009792359)
10 //
11 // This file is part of OPAL.
12 //
13 // OPAL is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20 //
21 #ifndef __PROBEVARIABLE_H__
22 #define __PROBEVARIABLE_H__
23 
24 #include <string>
25 
26 #include "boost/variant/get.hpp"
27 #include "boost/variant/variant.hpp"
28 #include "boost/smart_ptr.hpp"
29 
30 #include "Util/Types.h"
31 #include "Util/ProbeReader.h"
33 
34 struct ProbeVariable {
35 
36  static const std::string name;
37 
39  if (args.size() != 3) {
40  throw OptPilotException("ProbeVariable::operator()",
41  "probeVariable expects 3 arguments, " + std::to_string(args.size()) + " given");
42  }
43 
44  var_name_ = boost::get<std::string>(args[0]);
45  id_ = boost::get<double>(args[1]); //FIXME Can't we use integer?
46  probe_filename_ = boost::get<std::string>(args[2]);
47 
48  bool is_valid = true;
49 
50  boost::scoped_ptr<ProbeReader> sim_probe(new ProbeReader(probe_filename_));
51 
52  try {
53  sim_probe->parseFile();
54  } catch (OptPilotException &ex) {
55  std::cout << "Caught exception: " << ex.what() << std::endl;
56  is_valid = false;
57  }
58 
59  double sim_value = 0.0;
60  try {
61  sim_probe->getVariableValue(id_, var_name_, sim_value);
62  } catch(OptPilotException &e) {
63  std::cout << "Exception while getting value "
64  << "from Probe file: " << e.what()
65  << std::endl;
66  is_valid = false;
67  }
68 
69  return boost::make_tuple(sim_value, is_valid);
70  }
71 
72 private:
73  std::string var_name_;
74  int id_;
75  std::string probe_filename_;
76 
77  // define a mapping to arguments in argument vector
78  boost::tuple<std::string, int, std::string> argument_types;
79  // :FIXME: unused
80 #if 0
81  enum {
82  var_name
83  , id
84  , probe_filename
85  } argument_type_id;
86 #endif
87 };
88 
89 #endif
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
boost::tuple< double, bool > Result_t
Definition: Expression.h:66
constexpr double e
The value of.
Definition: Physics.h:39
std::vector< argument_t > arguments_t
Definition: function.hpp:19
std::string var_name_
Definition: ProbeVariable.h:73
Expressions::Result_t operator()(client::function::arguments_t args)
Definition: ProbeVariable.h:38
static const std::string name
Definition: ProbeVariable.h:36
std::string probe_filename_
Definition: ProbeVariable.h:75
boost::tuple< std::string, int, std::string > argument_types
Definition: ProbeVariable.h:78
virtual const char * what() const