OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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) {
21
22 func_m->apply(bfuncs);
23 const unsigned int size = bfuncs.size();
24
25 AffineTransformation current_trafo = trafo;
26 for (unsigned int i = 0; i < N_m; ++i) {
27 for (unsigned int j = 0; j < size; ++j) {
28 std::shared_ptr<Base> obj(bfuncs[j]->clone());
29 obj->trafo_m = obj->trafo_m.mult(current_trafo);
30 bfuncs.emplace_back(std::move(obj));
31 }
32
33 current_trafo = current_trafo.mult(trafo);
34 }
35 }
36
37 bool Repeat::parse_detail(iterator& it, const iterator& end, Function*& fun) {
38 Repeat* rep = static_cast<Repeat*>(fun);
39 if (!parse(it, end, rep->func_m)) return false;
40
41 int numRepetitions = 0;
42 ArgumentExtractor arguments(std::string(++it, end));
43 try {
44 if (arguments.getNumArguments() == 3) {
45 numRepetitions = parseMathExpression(arguments.get(0));
46 rep->shiftx_m = parseMathExpression(arguments.get(1));
47 rep->shifty_m = parseMathExpression(arguments.get(2));
48 rep->rot_m = 0.0;
49
50 } else if (arguments.getNumArguments() == 2) {
51 numRepetitions = parseMathExpression(arguments.get(0));
52 rep->shiftx_m = 0.0;
53 rep->shifty_m = 0.0;
54 rep->rot_m = parseMathExpression(arguments.get(1));
55 } else {
56 std::cout << "Repeat: number of arguments not supported" << std::endl;
57 return false;
58 }
59 } catch (std::runtime_error& e) {
60 std::cout << e.what() << std::endl;
61 return false;
62 }
63
64 if (numRepetitions < 0) {
65 std::cout << "Repeat: a negative number of repetitions provided '" << arguments.get(0)
66 << " = " << rep->N_m << "'" << std::endl;
67 return false;
68 }
69
70 rep->N_m = numRepetitions;
71
72 it += (arguments.getLengthConsumed() + 1);
73
74 return true;
75 }
76} // namespace mslang
ippl::Vector< T, Dim > Vector_t
double parseMathExpression(const std::string &str)
Definition matheval.cpp:4
std::string::iterator iterator
Definition MSLang.h:14
AffineTransformation mult(const AffineTransformation &B)
unsigned int getNumArguments() const
std::string get(unsigned int i) const
unsigned int getLengthConsumed() const
virtual void apply(std::vector< std::shared_ptr< Base > > &bfuncs)=0
static bool parse(iterator &it, const iterator &end, Function *&fun)
Definition MSLang.cpp:47
virtual void print(int indent)=0
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:37
unsigned int N_m
Definition Repeat.h:9