| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "galkin_d_trapezoid_method/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include "galkin_d_trapezoid_method/common/include/common.hpp" | ||
| 4 | |||
| 5 | namespace galkin_d_trapezoid_method { | ||
| 6 | |||
| 7 | 32 | GalkinDTrapezoidMethodSEQ::GalkinDTrapezoidMethodSEQ(const InType &in) { | |
| 8 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 9 | 32 | GetInput() = in; | |
| 10 | GetOutput() = 0.0; | ||
| 11 | 32 | } | |
| 12 | |||
| 13 | 32 | bool GalkinDTrapezoidMethodSEQ::ValidationImpl() { | |
| 14 | const auto &in = GetInput(); | ||
| 15 | 32 | bool ok_n = in.n > 0; | |
| 16 | 32 | bool ok_interval = in.a < in.b; | |
| 17 | 32 | bool ok_func = (in.func_id >= 0) && (in.func_id <= 2); | |
| 18 | 32 | bool ok_output_init = (GetOutput() == 0.0); | |
| 19 | |||
| 20 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | return ok_n && ok_interval && ok_func && ok_output_init; |
| 21 | } | ||
| 22 | |||
| 23 | 32 | bool GalkinDTrapezoidMethodSEQ::PreProcessingImpl() { | |
| 24 | 32 | GetOutput() = 0.0; | |
| 25 | 32 | return true; | |
| 26 | } | ||
| 27 | |||
| 28 | 32 | bool GalkinDTrapezoidMethodSEQ::RunImpl() { | |
| 29 | const auto &in = GetInput(); | ||
| 30 | |||
| 31 | 32 | const double a = in.a; | |
| 32 | 32 | const double b = in.b; | |
| 33 | 32 | const int n = in.n; | |
| 34 | 32 | const int func_id = in.func_id; | |
| 35 | |||
| 36 |
2/4✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
|
32 | if (n <= 0 || !(a < b)) { |
| 37 | return false; | ||
| 38 | } | ||
| 39 | |||
| 40 | 32 | const double h = (b - a) / static_cast<double>(n); | |
| 41 | |||
| 42 | double sum = 0.0; | ||
| 43 |
2/2✓ Branch 0 taken 59968 times.
✓ Branch 1 taken 32 times.
|
60000 | for (int i = 1; i < n; ++i) { |
| 44 | 59968 | const double x = a + (h * static_cast<double>(i)); | |
| 45 | 59968 | sum += Function(x, func_id); | |
| 46 | } | ||
| 47 | |||
| 48 | 32 | const double fa = Function(a, func_id); | |
| 49 | 32 | const double fb = Function(b, func_id); | |
| 50 | |||
| 51 | 32 | GetOutput() = h * ((fa + fb) * 0.5 + sum); | |
| 52 | |||
| 53 | 32 | return true; | |
| 54 | } | ||
| 55 | |||
| 56 | 32 | bool GalkinDTrapezoidMethodSEQ::PostProcessingImpl() { | |
| 57 | 32 | return true; | |
| 58 | } | ||
| 59 | |||
| 60 | } // namespace galkin_d_trapezoid_method | ||
| 61 |