OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Repeat.cpp
Go to the documentation of this file.
4
5namespace mslang {
6 void Repeat::print(int indentwidth) {
7 std::string indent(indentwidth, ' ');
8 std::string indent2(indentwidth + 8, ' ');
9 std::cout << indent << "repeat, " << std::endl;
10 func_m->print(indentwidth + 8);
11 std::cout << ",\n"
12 << indent2 << "N: " << N_m << ", \n"
13 << indent2 << "dx: " << shiftx_m << ", \n"
14 << indent2 << "dy: " << shifty_m;
15 }
16
17 void Repeat::apply(std::vector<std::shared_ptr<Base> > &bfuncs) {
20
21 func_m->apply(bfuncs);
22 const unsigned int size = bfuncs.size();
23
24 AffineTransformation current_trafo = trafo;
25 for (unsigned int i = 0; i < N_m; ++ i) {
26 for (unsigned int j = 0; j < size; ++ j) {
27 std::shared_ptr<Base> obj(bfuncs[j]->clone());
28 obj->trafo_m = obj->trafo_m.mult(current_trafo);
29 bfuncs.emplace_back(std::move(obj));
30 }
31
32 current_trafo = current_trafo.mult(trafo);
33 }
34 }
35
37 Repeat *rep = static_cast<Repeat*>(fun);
38 if (!parse(it, end, rep->func_m)) return false;
39
40 int numRepetitions = 0;
41 ArgumentExtractor arguments(std::string(++ it, end));
42 try {
43 if (arguments.getNumArguments() == 3) {
44 numRepetitions = parseMathExpression(arguments.get(0));
45 rep->shiftx_m = parseMathExpression(arguments.get(1));
46 rep->shifty_m = parseMathExpression(arguments.get(2));
47 rep->rot_m = 0.0;
48
49 } else if (arguments.getNumArguments() == 2) {
50 numRepetitions = parseMathExpression(arguments.get(0));
51 rep->shiftx_m = 0.0;
52 rep->shifty_m = 0.0;
53 rep->rot_m = parseMathExpression(arguments.get(1));
54 } else {
55 std::cout << "Repeat: number of arguments not supported" << std::endl;
56 return false;
57 }
58 } catch (std::runtime_error &e) {
59 std::cout << e.what() << std::endl;
60 return false;
61 }
62
63 if (numRepetitions < 0) {
64 std::cout << "Repeat: a negative number of repetitions provided '"
65 << arguments.get(0) << " = " << rep->N_m << "'"
66 << std::endl;
67 return false;
68 }
69
70 rep->N_m = numRepetitions;
71
72 it += (arguments.getLengthConsumed() + 1);
73
74 return true;
75 }
76}
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
Tps< T > cos(const Tps< T > &x)
Cosine.
Definition: TpsMath.h:129
Tps< T > sin(const Tps< T > &x)
Sine.
Definition: TpsMath.h:111
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
constexpr double e
The value of.
Definition: Physics.h:39
double parseMathExpression(const std::string &str)
Definition: matheval.cpp:4
std::string::iterator iterator
Definition: MSLang.h:16
virtual void apply(std::vector< std::shared_ptr< Base > > &bfuncs)=0
static bool parse(iterator &it, const iterator &end, Function *&fun)
Definition: MSLang.cpp:48
virtual void print(int indent)=0
AffineTransformation mult(const AffineTransformation &B)
unsigned int getNumArguments() const
std::string get(unsigned int i) const
unsigned int getLengthConsumed() const
double shifty_m
Definition: Repeat.h:11
virtual void apply(std::vector< std::shared_ptr< Base > > &bfuncs)
Definition: Repeat.cpp:17
double rot_m
Definition: Repeat.h:12
virtual void print(int indentwidth)
Definition: Repeat.cpp:6
Function * func_m
Definition: Repeat.h:8
double shiftx_m
Definition: Repeat.h:10
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition: Repeat.cpp:36
unsigned int N_m
Definition: Repeat.h:9
Vektor< double, 3 > Vector_t
Definition: Vektor.h:6