OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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#include <tuple>
26#include <variant>
27
28#include "Util/Types.h"
29#include "Util/ProbeReader.h"
31
33
34 static const std::string name;
35
37 if (args.size() != 3) {
38 throw OptPilotException("ProbeVariable::operator()",
39 "probeVariable expects 3 arguments, " + std::to_string(args.size()) + " given");
40 }
41
42 var_name_ = std::get<std::string>(args[0]);
43 id_ = std::get<double>(args[1]); //FIXME Can't we use integer?
44 probe_filename_ = std::get<std::string>(args[2]);
45
46 bool is_valid = true;
47
48 const std::unique_ptr<ProbeReader> sim_probe(new ProbeReader(probe_filename_));
49
50 try {
51 sim_probe->parseFile();
52 } catch (OptPilotException &ex) {
53 std::cout << "Caught exception: " << ex.what() << std::endl;
54 is_valid = false;
55 }
56
57 double sim_value = 0.0;
58 try {
59 sim_probe->getVariableValue(id_, var_name_, sim_value);
60 } catch(OptPilotException &e) {
61 std::cout << "Exception while getting value "
62 << "from Probe file: " << e.what()
63 << std::endl;
64 is_valid = false;
65 }
66
67 return std::make_tuple(sim_value, is_valid);
68 }
69
70private:
71 std::string var_name_;
72 int id_;
73 std::string probe_filename_;
74
75 // define a mapping to arguments in argument vector
76 std::tuple<std::string, int, std::string> argument_types;
77 // :FIXME: unused
78#if 0
79 enum {
80 var_name
81 , id
82 , probe_filename
83 } argument_type_id;
84#endif
85};
86
87#endif
std::tuple< double, bool > Result_t
Definition Expression.h:65
std::vector< argument_t > arguments_t
Definition function.hpp:14
std::string var_name_
std::tuple< std::string, int, std::string > argument_types
Expressions::Result_t operator()(client::function::arguments_t args)
static const std::string name
std::string probe_filename_
virtual const char * what() const