OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
SeptumExpr.h
Go to the documentation of this file.
1//
2// Struct SeptumExpr
3// Objective to obtain a nice septum in cyclotron simulations.
4//
5// Copyright (c) 2019, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved
7//
8// Implemented as part of the PhD thesis
9// "Precise Simulations of Multibunches in High Intensity Cyclotrons"
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 __SEPTUM_EXPRESSION_H__
22#define __SEPTUM_EXPRESSION_H__
23
24#include <iostream>
25#include <string>
26#include <tuple>
27#include <variant>
28
29#include "Util/Types.h"
30#include "Util/PeakReader.h"
32
34
35struct SeptumExpr {
36
37 static const std::string name;
38
40 if (args.size() != 1) {
41 throw OptPilotException("SeptumExpr::operator()",
42 "SeptumExpr expects 1 arguments, " + std::to_string(args.size()) + " given");
43 }
44
45 std::string probe = std::get<std::string>(args[0]);
46
47 bool is_valid = true;
48
49 double result = 0.0;
50
51 try {
52 const std::unique_ptr<PeakReader> sim_peaks(new PeakReader(probe + std::string(".peaks")));
53 sim_peaks->parseFile();
54
55 const std::unique_ptr<ProbeHistReader> sim_hist(new ProbeHistReader(probe + std::string(".hist")));
56 sim_hist->parseFile();
57
58 double upperBound = 0.0;
59 double lowerBound = 0.0;
60
61 size_t nTurns = sim_peaks->getNumberOfPeaks();
62 sim_peaks->getPeak(nTurns, upperBound);
63 sim_peaks->getPeak(nTurns - 1, lowerBound);
64
65 result = sim_hist->minimum(lowerBound, upperBound);
66
67 } catch (OptPilotException &ex) {
68 std::cout << "Exception while getting septum value "
69 << ex.what()
70 << std::endl;
71 is_valid = false;
72 }
73
74 return std::make_tuple(result, is_valid);
75 }
76};
77
78#endif
std::tuple< double, bool > Result_t
Definition Expression.h:65
std::vector< argument_t > arguments_t
Definition function.hpp:14
static const std::string name
Definition SeptumExpr.h:37
Expressions::Result_t operator()(client::function::arguments_t args)
Definition SeptumExpr.h:39
virtual const char * what() const