OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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 <string>
25#include <iostream>
26
27#include "boost/variant/get.hpp"
28#include "boost/variant/variant.hpp"
29#include "boost/smart_ptr.hpp"
30
31#include "Util/Types.h"
32#include "Util/PeakReader.h"
34
36
37struct SeptumExpr {
38
39 static const std::string name;
40
42 if (args.size() != 1) {
43 throw OptPilotException("SeptumExpr::operator()",
44 "SeptumExpr expects 1 arguments, " + std::to_string(args.size()) + " given");
45 }
46
47 std::string probe = boost::get<std::string>(args[0]);
48
49 bool is_valid = true;
50
51 double result = 0.0;
52
53 try {
54 boost::scoped_ptr<PeakReader> sim_peaks(new PeakReader(probe + std::string(".peaks")));
55 sim_peaks->parseFile();
56
57 boost::scoped_ptr<ProbeHistReader> sim_hist(new ProbeHistReader(probe + std::string(".hist")));
58 sim_hist->parseFile();
59
60 double upperBound = 0.0;
61 double lowerBound = 0.0;
62
63 size_t nTurns = sim_peaks->getNumberOfPeaks();
64 sim_peaks->getPeak(nTurns, upperBound);
65 sim_peaks->getPeak(nTurns - 1, lowerBound);
66
67 result = sim_hist->minimum(lowerBound, upperBound);
68
69 } catch (OptPilotException &ex) {
70 std::cout << "Exception while getting septum value "
71 << ex.what()
72 << std::endl;
73 is_valid = false;
74 }
75
76 return boost::make_tuple(result, is_valid);
77 }
78};
79
80#endif
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
boost::tuple< double, bool > Result_t
Definition: Expression.h:66
std::vector< argument_t > arguments_t
Definition: function.hpp:19
static const std::string name
Definition: SeptumExpr.h:39
Expressions::Result_t operator()(client::function::arguments_t args)
Definition: SeptumExpr.h:41
virtual const char * what() const