OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
Shear.cpp
Go to the documentation of this file.
4
5#include <cmath>
6#include <iostream>
7#include <memory>
8#include <stdexcept>
9#include <string>
10#include <vector>
11
12namespace mslang {
13 void Shear::print(int indentwidth) {
14 std::string indent(indentwidth, ' ');
15 std::string indent2(indentwidth + 8, ' ');
16 std::cout << indent << "shear, " << std::endl;
17 func_m->print(indentwidth + 8);
18 if (std::abs(angleX_m) > 0.0) {
19 std::cout << ",\n"
20 << indent2 << "angle X: " << angleX_m;
21 } else {
22 std::cout << ",\n"
23 << indent2 << "angle Y: " << angleY_m;
24 }
25 }
26
27 void Shear::applyShear(std::vector<std::shared_ptr<Base> > &bfuncs) {
28 AffineTransformation shear(Vector_t({1.0, std::tan(angleX_m), 0.0}),
29 Vector_t({-std::tan(angleY_m), 1.0, 0.0}));
30
31 const unsigned int size = bfuncs.size();
32
33 for (unsigned int j = 0; j < size; ++ j) {
34 std::shared_ptr<Base> &obj = bfuncs[j];
35 obj->trafo_m = obj->trafo_m.mult(shear);
36
37 if (!obj->divisor_m.empty())
38 applyShear(obj->divisor_m);
39 }
40 }
41
42 void Shear::apply(std::vector<std::shared_ptr<Base> > &bfuncs) {
43 func_m->apply(bfuncs);
44 applyShear(bfuncs);
45 }
46
48 Shear *shr = static_cast<Shear*>(fun);
49 if (!parse(it, end, shr->func_m)) return false;
50
51 ArgumentExtractor arguments(std::string(++ it, end));
52 try {
53 shr->angleX_m = parseMathExpression(arguments.get(0));
54 shr->angleY_m = parseMathExpression(arguments.get(1));
55 } catch (std::runtime_error &e) {
56 std::cout << e.what() << std::endl;
57 return false;
58 }
59
60 it += (arguments.getLengthConsumed() + 1);
61
62 return true;
63 }
64}
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
double parseMathExpression(const std::string &str)
Definition matheval.cpp:4
std::string::iterator iterator
Definition MSLang.h:13
virtual void apply(std::vector< std::shared_ptr< Base > > &bfuncs)=0
static bool parse(iterator &it, const iterator &end, Function *&fun)
Definition MSLang.cpp:46
virtual void print(int indent)=0
std::string get(unsigned int i) const
unsigned int getLengthConsumed() const
Function * func_m
Definition Shear.h:11
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition Shear.cpp:47
virtual void apply(std::vector< std::shared_ptr< Base > > &bfuncs)
Definition Shear.cpp:42
void applyShear(std::vector< std::shared_ptr< Base > > &bfuncs)
Definition Shear.cpp:27
virtual void print(int indentwidth)
Definition Shear.cpp:13
double angleX_m
Definition Shear.h:12
double angleY_m
Definition Shear.h:13
Vektor< double, 3 > Vector_t
Definition Vektor.h:6