Commit 64261bf3 authored by frey_m's avatar frey_m
Browse files

Optimiser: Additional expression for #peaks (~ #turns)

modified:   optimizer/Drivers/pisa-opal/pisa-opal.cpp
modified:   optimizer/Expression/CMakeLists.txt
new file:   optimizer/Expression/NumberOfPeaks.cpp
new file:   optimizer/Expression/NumberOfPeaks.h
modified:   optimizer/Util/PeakReader.cpp
modified:   optimizer/Util/PeakReader.h
modified:   src/Optimize/OptimizeCmd.cpp
parent 912ebac7
......@@ -33,6 +33,7 @@
#include "Expression/RadialPeak.h"
#include "Expression/SumErrSqRadialPeak.h"
#include "Expression/MaxNormRadialPeak.h"
#include "Expression/NumberOfPeaks.h"
#include "Expression/ProbeVariable.h"
//////////////////////////////////////////////////////////////////////////////
......@@ -82,6 +83,9 @@ int main(int argc, char** argv) {
ff = MaxNormRadialPeak();
funcs.insert(std::pair<std::string, client::function::type>
("maxNormRadialPeak", ff));
ff = NumberOfPeaks();
funcs.insert(std::pair<std::string, client::function::type>
("numberOfPeaks", ff));
ff = SumErrSqRadialPeak();
funcs.insert(std::pair<std::string, client::function::type>
("sumErrSqRadialPeak", ff));
......
......@@ -3,6 +3,7 @@ SET (_EXPR_SRCS
SumErrSq.cpp
FromFile.cpp
MaxNormRadialPeak.cpp
NumberOfPeaks.h
RadialPeak.cpp
SumErrSqRadialPeak.cpp
Parser/expression.cpp
......
#include "Expression/NumberOfPeaks.h"
const std::string name = "NumberOfPeaks";
#ifndef __NUMBER_OF_PEAKS_H__
#define __NUMBER_OF_PEAKS_H__
#include <string>
#include <cmath>
#include "boost/type_traits/remove_cv.hpp"
#include "boost/variant/get.hpp"
#include "boost/variant/variant.hpp"
#include "boost/smart_ptr.hpp"
#include "Util/Types.h"
#include "Util/PeakReader.h"
#include "Expression/Parser/function.hpp"
/**
* A simple expression to check the number of turns in a circular machine. It checks
* probe files (*.peaks) and counts the number of turns.
*/
struct NumberOfPeaks {
static const std::string name;
Expressions::Result_t operator()(client::function::arguments_t args) {
sim_filename_ = boost::get<std::string>(args[0]);
bool is_valid = true;
boost::scoped_ptr<PeakReader> sim_peaks(new PeakReader(sim_filename_));
try {
sim_peaks->parseFile();
} catch (OptPilotException &ex) {
std::cout << "Caught exception: " << ex.what() << std::endl;
is_valid = false;
}
std::size_t nPeaks = sim_peaks->getNumberOfPeaks();
is_valid = true;
return boost::make_tuple(nPeaks, is_valid);
}
private:
std::string sim_filename_;
// define a mapping to arguments in argument vector
boost::tuple<std::string> argument_types;
};
#endif
// vi: set et ts=4 sw=4 sts=4:
// Local Variables:
// mode:c
// c-basic-offset: 4
// indent-tabs-mode:nil
// End:
......@@ -54,3 +54,8 @@ void PeakReader::getPeak(int nPeak, double& radius) {
"peak not found!");
}
}
std::size_t PeakReader::getNumberOfPeaks() {
return peaks_m.size();
}
\ No newline at end of file
......@@ -25,6 +25,11 @@ public:
*/
void getPeak(int nPeak, double& radius);
/**
* @returns the number of peaks in the file
*/
std::size_t getNumberOfPeaks();
private:
/// Peak filename
std::string filename_m;
......
......@@ -33,6 +33,7 @@
#include "Expression/SDDSVariable.h"
#include "Expression/RadialPeak.h"
#include "Expression/MaxNormRadialPeak.h"
#include "Expression/NumberOfPeaks.h"
#include "Expression/SumErrSqRadialPeak.h"
#include "Expression/ProbeVariable.h"
......@@ -197,7 +198,11 @@ void OptimizeCmd::execute() {
ff = MaxNormRadialPeak();
funcs.insert(std::pair<std::string, client::function::type>
("maxNormRadialPeak", ff));
ff = NumberOfPeaks();
funcs.insert(std::pair<std::string, client::function::type>
("numberOfPeaks", ff));
ff = SumErrSqRadialPeak();
funcs.insert(std::pair<std::string, client::function::type>
("sumErrSqRadialPeak", ff));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment