ARTS 2.5.9 (git: 825fa5f2)
test_integration.cc
Go to the documentation of this file.
1/* Copyright (C) 2003-2012 Claas Teichmann <claas@sat.physik.uni-bremen.de>
2
3 This program is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 USA.
17
18*/
19
29#include <sys/time.h>
30#include <cmath>
31#include <iostream>
32#include <stdexcept>
33
34#include "array.h"
35#include "arts.h"
36#include "arts_constants.h"
37#include "arts_conversions.h"
38#include "logic.h"
39#include "math_funcs.h"
40#include "matpackI.h"
41
43inline constexpr Numeric PI=Constant::pi;
44
45void init_xy(float stepsize,
46 int frequency,
47 Matrix& Integrand,
48 Vector& za_grid,
49 Vector& aa_grid);
50
51void init_x(
52 int vsize, float stepsize, int frequency, Vector& Integrand, Vector& Theta);
53
55 ConstVectorView za_grid,
56 ConstVectorView aa_grid);
57
59 ConstVectorView za_grid,
60 ConstVectorView aa_grid);
61
63 ConstVectorView za_grid,
64 ConstVectorView aa_grid,
65 Numeric stepsize);
66
68 ConstVectorView za_grid,
69 ConstVectorView aa_grid,
70 Numeric stepsize);
71
73 ConstVectorView za_grid,
74 ConstVectorView aa_grid,
75 Numeric stepsize);
76
78 ConstVectorView za_grid);
79
81 ConstVectorView za_grid,
82 Numeric stepsize);
83
84Numeric test_xy(int z_size, int a_size, float stepsize, int frequency);
85
86Numeric test_xy_opt(int z_size, int a_size, float stepsize, int frequency);
87
88Numeric test_xy_fixedstep(int z_size,
89 int a_size,
90 float stepsize,
91 int frequency);
92
94 int a_size,
95 float stepsize,
96 int frequency);
97
99 int a_size,
100 float stepsize,
101 int frequency);
102
104 int a_size,
105 float stepsize,
106 int frequency);
107
108Numeric test_x(int vsize, float stepsize, int frequency);
109
110Numeric test_x_fixedstep(int vsize, int frequency);
111
112int main(int argc, char* argv[]) {
113 if (argc == 1) {
114 cerr << argv[0] << " requires one parameter" << endl;
115 exit(1);
116 }
117
118 cout << "Uebergabewert von argv : " << argv[1] << endl;
119
120 int frequency = (int)strtol(argv[1], NULL, 10); // Zahl zur Basis 10
121 cout << "Wert von frequency : " << frequency << endl;
122
123 // test_x(1801, 0.1, frequency);
124 // test_x_fixedstep(1801, frequency);
125 // test_x(181, 1, frequency);
126 // test_x(19, 10, frequency);
127
128 test_xy(181, 361, 1.0, frequency);
129 // test_xy_opt(1801, 3601, 0.1, frequency);
130 // test_xy_fixedstep(1801, 3601, 0.1, frequency);
131 // test_xy_fixedstep_opt(1801, 3601, 0.1, frequency);
132 // test_xy_fixedstep_opt(181, 361, 1.0, frequency);
133 // test_xy_fixedstep_opt(19, 37, 10, frequency);
134 // test_xy_fixedstep_opt2(1801, 3601, 0.1, frequency);
135 // test_xy_fixedstep_opt2(181, 361, 1.0, frequency);
136 test_AngIntegrate_trapezoid_opti(181, 361, 1.0, frequency);
137 // test_xy_fixedstep_opt2(19, 37, 10, frequency);
138}
139
141
145void init_x(int vsize,
146 float stepsize,
147 int frequency,
148 Vector& Integrand,
149 Vector& Theta) {
150 cout << "----------------init_x---------------\n";
151
152 // Integrand.resize(vsize); // function to be integrated
153 // Theta.resize(vsize); // Theta values
154
155 for (int i = 0; i < Integrand.nelem(); i++)
156 Integrand[i] = (float)i * stepsize;
157
158 //Theta is between 0 and 180
159 for (int i = 0; i < Theta.nelem(); i++) Theta[i] = (float)i * stepsize;
160
161 cout << "function Y = X" << endl
162 << "vsize = " << vsize << endl
163 << "stepsize = " << stepsize << endl
164 << "frequency = " << frequency << endl
165 << "Integrand: von " << Integrand[0] << " bis "
166 << Integrand[Integrand.nelem() - 1] << endl
167 << "Theta: von " << Theta[0] << " bis " << Theta[Theta.nelem() - 1]
168 << endl;
169}
170
172
176void init_xy(float stepsize,
177 int frequency,
178 Matrix& Integrand,
179 Vector& za_grid,
180 Vector& aa_grid) {
181 cout << ">>>>>-----------init_xy---------------\n";
182 Index n_za = za_grid.nelem();
183 Index n_aa = aa_grid.nelem();
184
185 // The r=1 so we get a circle
186 for (Index i = 0; i < n_za; i++)
187 for (Index j = 0; j < n_aa; j++) Integrand(i, j) = 1;
188
189 //za_grid (Theta) is between 0 and 180
190 for (Index i = 0; i < n_za; i++) za_grid[i] = (float)i * stepsize;
191
192 //aa_grid (Phi) is between 0 and 360
193 for (Index i = 0; i < n_aa; i++) aa_grid[i] = (float)i * stepsize;
194
195 cout << "function x^2 + y^2 + z^2 = 1" << endl
196 << "n_za = " << n_za << endl
197 << "n_aa = " << n_aa << endl
198 << "stepsize = " << stepsize << endl
199 << "frequency = " << frequency << endl
200 << "Integrand(*,0): von " << Integrand(0, 0) << " bis "
201 << Integrand(n_za - 1, 0) << endl
202 << "Integrand(0,*): von " << Integrand(0, 0) << " bis "
203 << Integrand(0, n_aa - 1) << endl
204 << "za_grid (Theta): von " << za_grid[0] << " bis "
205 << za_grid[za_grid.nelem() - 1] << endl
206 << "aa_grid (Phi) : von " << aa_grid[0] << " bis "
207 << aa_grid[aa_grid.nelem() - 1] << endl;
208 cout << "---------------init_xy---------------<<<<<\n";
209}
210
212
224 ConstVectorView za_grid,
225 ConstVectorView aa_grid) {
226 Index n = za_grid.nelem();
227 Index m = aa_grid.nelem();
228 Vector res1(n);
229 ARTS_ASSERT(is_size(Integrand, n, m));
230
231 for (Index i = 0; i < n; ++i) {
232 res1[i] = 0.0;
233
234 for (Index j = 0; j < m - 1; ++j) {
235 res1[i] += 0.5 * DEG2RAD * (Integrand(i, j) + Integrand(i, j + 1)) *
236 (aa_grid[j + 1] - aa_grid[j]) * sin(za_grid[i] * DEG2RAD);
237 }
238 }
239 Numeric res = 0.0;
240 for (Index i = 0; i < n - 1; ++i) {
241 res +=
242 0.5 * DEG2RAD * (res1[i] + res1[i + 1]) * (za_grid[i + 1] - za_grid[i]);
243 }
244
245 //cout<<res<<"\n";
246 return res;
247}
249
261 ConstVectorView za_grid,
262 ConstVectorView aa_grid) {
263 Index n = za_grid.nelem();
264 Index m = aa_grid.nelem();
265 Vector res1(n);
266 ARTS_ASSERT(is_size(Integrand, n, m));
267
268 for (Index i = 0; i < n; ++i) {
269 res1[i] = 0.0;
270
271 for (Index j = 0; j < m - 1; ++j) {
272 res1[i] += 0.5 * DEG2RAD * (Integrand(i, j) + Integrand(i, j + 1)) *
273 (aa_grid[j + 1] - aa_grid[j]) * sin(za_grid[i] * DEG2RAD);
274 }
275 }
276 Numeric res = 0.0;
277 for (Index i = 0; i < n - 1; ++i) {
278 res +=
279 0.5 * DEG2RAD * (res1[i] + res1[i + 1]) * (za_grid[i + 1] - za_grid[i]);
280 }
281
282 //cout<<res<<"\n";
283 return res;
284}
285
287
300 ConstVectorView za_grid,
301 ConstVectorView aa_grid,
302 Numeric stepsize) {
303 Index n = za_grid.nelem();
304 Index m = aa_grid.nelem();
305 Vector res1(n);
306 ARTS_ASSERT(is_size(Integrand, n, m));
307
308 for (Index i = 0; i < n; ++i) {
309 res1[i] = 0.0;
310
311 for (Index j = 0; j < m - 1; ++j) {
312 res1[i] += 0.5 * DEG2RAD * (Integrand(i, j) + Integrand(i, j + 1)) *
313 stepsize * sin(za_grid[i] * DEG2RAD);
314 }
315 }
316 Numeric res = 0.0;
317 for (Index i = 0; i < n - 1; ++i) {
318 res += 0.5 * DEG2RAD * (res1[i] + res1[i + 1]) * stepsize;
319 }
320
321 //cout<<res<<"\n";
322 return res;
323}
324
326
339 ConstVectorView za_grid,
340 ConstVectorView aa_grid,
341 Numeric stepsize) {
342 Index n = za_grid.nelem();
343 Index m = aa_grid.nelem();
344 Vector res1(n);
345 ARTS_ASSERT(is_size(Integrand, n, m));
346
347 for (Index i = 0; i < n; ++i) {
348 res1[i] = 0.0;
349
350 res1[i] += Integrand(i, 0);
351 for (Index j = 1; j < m - 1; j++) {
352 res1[i] += Integrand(i, j) * 2;
353 }
354 res1[i] += Integrand(i, m - 1);
355 res1[i] *= 0.5 * DEG2RAD * stepsize * sin(za_grid[i] * DEG2RAD);
356 }
357 Numeric res = 0.0;
358 res += res1[0];
359 for (Index i = 1; i < n - 1; i++) {
360 res += res1[i] * 2;
361 }
362 res += res1[n - 1];
363 res *= 0.5 * DEG2RAD * stepsize;
364
365 //cout<<res<<"\n";
366 return res;
367}
368
370
384 ConstVectorView za_grid,
385 ConstVectorView aa_grid,
386 Numeric stepsize) {
387 Index n = za_grid.nelem();
388 Index m = aa_grid.nelem();
389 Vector res1(n);
390 ARTS_ASSERT(is_size(Integrand, n, m));
391
392 Numeric temp = 0.0;
393
394 for (Index i = 0; i < n; ++i) {
395 temp = Integrand(i, 0);
396 for (Index j = 1; j < m - 1; j++) {
397 temp += Integrand(i, j) * 2;
398 }
399 temp += Integrand(i, m - 1);
400 temp *= 0.5 * DEG2RAD * stepsize * sin(za_grid[i] * DEG2RAD);
401 res1[i] = temp;
402 }
403
404 Numeric res = res1[0];
405 for (Index i = 1; i < n - 1; i++) {
406 res += res1[i] * 2;
407 }
408 res += res1[n - 1];
409 res *= 0.5 * DEG2RAD * stepsize;
410
411 //cout<<res<<"\n";
412 return res;
413}
414
416
420 ConstVectorView za_grid) {
421 Index n = za_grid.nelem();
422 ARTS_ASSERT(is_size(Integrand, n));
423
424 Numeric res = 0.0;
425 for (Index i = 0; i < n - 1; ++i) {
426 // in this place 0.5 * 2 * PI is calculated:
427 res += PI * DEG2RAD *
428 (Integrand[i] * sin(za_grid[i] * DEG2RAD) +
429 Integrand[i + 1] * sin(za_grid[i + 1] * DEG2RAD)) *
430 (za_grid[i + 1] - za_grid[i]);
431 }
432
433 //cout<<res<<"\n";
434 return res;
435}
436
438
442 ConstVectorView za_grid,
443 Numeric stepsize) {
444 Index n = za_grid.nelem();
445 ARTS_ASSERT(is_size(Integrand, n));
446
447 Numeric res = 0.0;
448 // cout << "Stepsize: " << stepsize << endl;
449 res += (Integrand[0] * sin(za_grid[0] * DEG2RAD));
450 for (Index i = 1; i < n - 1; ++i) {
451 res += (Integrand[i] * sin(za_grid[i] * DEG2RAD) * 2);
452 // cout << i << endl;
453 }
454 res += ((Integrand[n - 1] * sin(za_grid[n - 1] * DEG2RAD)));
455 // cout << n-1 << endl;
456 // normally ther would be a 2* here, but it's already in the equations above
457 res *= PI * DEG2RAD * stepsize;
458
459 //cout<<res<<"\n";
460 return res;
461}
462
464
475Numeric test_xy(int z_size, int a_size, float stepsize, int frequency) {
476 cout << ">>>>>-----------test_xy---------------\n";
477 Matrix Integrand(z_size, a_size); // function to be integrated
478 Vector za_grid(z_size); // zenith (Theta) values
479 Vector aa_grid(a_size); // azimuth (Phi) values
480
481 init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
482
483 Numeric result = 0;
484
485 struct timeval start;
486 struct timeval ende;
487 gettimeofday(&start, NULL);
488 // cout << "Sekunden : " << start.tv_sec << endl
489 // << "Milisekunden: " << start.tv_usec << endl;
490
491 for (int i = 0; i < frequency; i++)
492 result = AngIntegrate_trapezoid_original(Integrand, za_grid, aa_grid);
493
494 gettimeofday(&ende, NULL);
495
496 double error = result / (4 * PI) - 1;
497
498 double diffs = (double)(ende.tv_sec - start.tv_sec) +
499 (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
500 cout.precision(15);
501 cout << "stepsize is : " << stepsize << endl
502 << "z_size : " << z_size << endl
503 << "a_size : " << a_size << endl
504 << "1 is : " << result / (4 * PI) << endl
505 << "The result is : " << result << endl
506 << "The error is : " << error * 100 << " %\n"
507 << "Number of loops: " << frequency << endl
508 << "elapsed time : " << diffs << "s" << endl
509 << "----------------test_xy----------<<<<<\n";
510
511 return result;
512}
513
515
526Numeric test_xy_opt(int z_size, int a_size, float stepsize, int frequency) {
527 cout << ">>>>>-----------test_xy_opt---------------\n";
528 Matrix Integrand(z_size, a_size); // function to be integrated
529 Vector za_grid(z_size); // zenith (Theta) values
530 Vector aa_grid(a_size); // azimuth (Phi) values
531
532 init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
533
534 Numeric result = 0;
535
536 struct timeval start;
537 struct timeval ende;
538 gettimeofday(&start, NULL);
539 // cout << "Sekunden : " << start.tv_sec << endl
540 // << "Milisekunden: " << start.tv_usec << endl;
541
542 for (int i = 0; i < frequency; i++)
543 result = AngIntegrate_trapezoid_opt(Integrand, za_grid, aa_grid);
544
545 gettimeofday(&ende, NULL);
546
547 double error = result / (4 * PI) - 1;
548
549 double diffs = (double)(ende.tv_sec - start.tv_sec) +
550 (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
551 cout.precision(15);
552 cout << "stepsize is : " << stepsize << endl
553 << "z_size : " << z_size << endl
554 << "a_size : " << a_size << endl
555 << "1 is : " << result / (4 * PI) << endl
556 << "The result is : " << result << endl
557 << "The error is : " << error * 100 << " %\n"
558 << "Number of loops: " << frequency << endl
559 << "elapsed time : " << diffs << "s" << endl
560 << "----------------test_xy_opt----------<<<<<\n";
561
562 return result;
563}
564
566
578 int a_size,
579 float stepsize,
580 int frequency) {
581 cout << ">>>>>-----------test_xy_fixedstep---------------\n";
582 Matrix Integrand(z_size, a_size); // function to be integrated
583 Vector za_grid(z_size); // zenith (Theta) values
584 Vector aa_grid(a_size); // azimuth (Phi) values
585
586 init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
587
588 Numeric result = 0;
589
590 struct timeval start;
591 struct timeval ende;
592 gettimeofday(&start, NULL);
593 // cout << "Sekunden : " << start.tv_sec << endl
594 // << "Milisekunden: " << start.tv_usec << endl;
595
596 for (int i = 0; i < frequency; i++)
597 result =
598 AngIntegrate_trapezoid_fixedstep(Integrand, za_grid, aa_grid, stepsize);
599
600 gettimeofday(&ende, NULL);
601
602 double error = result / (4 * PI) - 1;
603
604 double diffs = (double)(ende.tv_sec - start.tv_sec) +
605 (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
606 cout.precision(15);
607 cout << diffs << endl;
608 cout << "stepsize is : " << stepsize << endl
609 << "z_size : " << z_size << endl
610 << "a_size : " << a_size << endl
611 << "1 is : " << result / (4 * PI) << endl
612 << "The result is : " << result << endl
613 << "The error is : " << error * 100 << " %\n"
614 << "Number of loops: " << frequency << endl
615 << "elapsed time : " << diffs << "s" << endl
616 << "----------------test_xy_fixedstep----------<<<<<\n";
617
618 return result;
619}
620
622
634 int a_size,
635 float stepsize,
636 int frequency) {
637 cout << ">>>>>-----------test_xy_fixedstep_opt---------------\n";
638 Matrix Integrand(z_size, a_size); // function to be integrated
639 Vector za_grid(z_size); // zenith (Theta) values
640 Vector aa_grid(a_size); // azimuth (Phi) values
641
642 init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
643
644 Numeric result = 0;
645
646 struct timeval start;
647 struct timeval ende;
648 gettimeofday(&start, NULL);
649 // cout << "Sekunden : " << start.tv_sec << endl
650 // << "Milisekunden: " << start.tv_usec << endl;
651
652 for (int i = 0; i < frequency; i++)
654 Integrand, za_grid, aa_grid, stepsize);
655
656 gettimeofday(&ende, NULL);
657
658 double error = result / (4 * PI) - 1;
659
660 double diffs = (double)(ende.tv_sec - start.tv_sec) +
661 (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
662 cout.precision(15);
663 cout << diffs << endl;
664 cout << "stepsize is : " << stepsize << endl
665 << "z_size : " << z_size << endl
666 << "a_size : " << a_size << endl
667 << "1 is : " << result / (4 * PI) << endl
668 << "The result is : " << result << endl
669 << "The error is : " << error * 100 << " %\n"
670 << "Number of loops: " << frequency << endl
671 << "elapsed time : " << diffs << "s" << endl
672 << "----------------test_xy_fixedstep_opt----------<<<<<\n";
673
674 return result;
675}
676
678
690 int a_size,
691 float stepsize,
692 int frequency) {
693 cout << ">>>>>-----------test_xy_fixedstep_opt2---------------\n";
694 Matrix Integrand(z_size, a_size); // function to be integrated
695 Vector za_grid(z_size); // zenith (Theta) values
696 Vector aa_grid(a_size); // azimuth (Phi) values
697
698 init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
699
700 Numeric result = 0;
701
702 struct timeval start;
703 struct timeval ende;
704 gettimeofday(&start, NULL);
705 // cout << "Sekunden : " << start.tv_sec << endl
706 // << "Milisekunden: " << start.tv_usec << endl;
707
708 for (int i = 0; i < frequency; i++)
710 Integrand, za_grid, aa_grid, stepsize);
711
712 gettimeofday(&ende, NULL);
713
714 double error = result / (4 * PI) - 1;
715
716 double diffs = (double)(ende.tv_sec - start.tv_sec) +
717 (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
718 cout.precision(15);
719 cout << diffs << endl;
720 cout << "stepsize is : " << stepsize << endl
721 << "z_size : " << z_size << endl
722 << "a_size : " << a_size << endl
723 << "1 is : " << result / (4 * PI) << endl
724 << "The result is : " << result << endl
725 << "The error is : " << error * 100 << " %\n"
726 << "Number of loops: " << frequency << endl
727 << "elapsed time : " << diffs << "s" << endl
728 << "----------------test_xy_fixedstep_opt2----------<<<<<\n";
729
730 return result;
731}
732
734
748 int a_size,
749 float stepsize,
750 int frequency) {
751 cout << ">>>>>-----------test_AngIntegrate_trapezoid_opti---------------\n";
752 Matrix Integrand(z_size, a_size); // function to be integrated
753 Vector za_grid(z_size); // zenith (Theta) values
754 Vector aa_grid(a_size); // azimuth (Phi) values
755
756 Vector grid_stepsize(2);
757
758 init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
759
760 grid_stepsize[0] = za_grid[1] - za_grid[0];
761 grid_stepsize[1] = aa_grid[1] - aa_grid[0];
762 //grid_stepsize[0] = -1;
763 //grid_stepsize[1] = -1;
764
765 // cout << za_grid << endl;
766 // cout << grid_stepsize[0] << endl;
767 // cout << grid_stepsize[1] << endl;
768
769 Numeric result = 0;
770
771 struct timeval start;
772 struct timeval ende;
773 gettimeofday(&start, NULL);
774 // cout << "Sekunden : " << start.tv_sec << endl
775 // << "Milisekunden: " << start.tv_usec << endl;
776
777 for (int i = 0; i < frequency; i++)
778 result =
779 AngIntegrate_trapezoid_opti(Integrand, za_grid, aa_grid, grid_stepsize);
780
781 gettimeofday(&ende, NULL);
782
783 double error = result / (4 * PI) - 1;
784
785 double diffs = (double)(ende.tv_sec - start.tv_sec) +
786 (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
787 cout.precision(15);
788 cout << diffs << endl;
789 cout << "stepsize is : " << stepsize << endl
790 << "z_size : " << z_size << endl
791 << "a_size : " << a_size << endl
792 << "1 is : " << result / (4 * PI) << endl
793 << "The result is : " << result << endl
794 << "The error is : " << error * 100 << " %\n"
795 << "Number of loops: " << frequency << endl
796 << "elapsed time : " << diffs << "s" << endl
797 << "----------------test_AngIntegrate_trapezoid_opti----------<<<<<\n";
798
799 return result;
800}
801
803
813Numeric test_x(int vsize, float stepsize, int frequency) {
814 cout << ">>>>>-----------test_x---------------\n";
815 Vector Integrand(vsize); // function to be integrated
816 Vector Theta(vsize); // Theta values
817
818 init_x(vsize, stepsize, frequency, Integrand, Theta);
819
820 Numeric result = 0;
821
822 struct timeval start;
823 struct timeval ende;
824 gettimeofday(&start, NULL);
825 cout << "Sekunden : " << start.tv_sec << endl
826 << "Milisekunden: " << start.tv_usec << endl;
827
828 for (int i = 0; i < frequency; i++)
829 result = AngIntegrate_trapezoid_original(Integrand, Theta);
830
831 gettimeofday(&ende, NULL);
832
833 // norming the result to Pi
834 result = result / (2 * 180);
835
836 double error = result / PI - 1;
837
838 double diffs = (double)(ende.tv_sec - start.tv_sec) +
839 (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
840 cout.precision(15);
841 cout << diffs << endl;
842 cout << "stepsize is : " << stepsize << endl
843 << "number of steps: " << vsize << endl
844 << "1 is : " << PI / PI << endl
845 << "The result is : " << result / PI << endl
846 << "The error is : " << error * 100 << "%\n"
847 << "Number of loops: " << frequency << endl
848 << "elapsed time : " << diffs << "s" << endl
849 << "---------------test_x-----------<<<<<\n";
850
851 return result;
852}
854
863Numeric test_x_fixedstep(int vsize, int frequency) {
864 cout << ">>>>>-----------test_x_fixedstep---------------\n";
865 cout.precision(12);
866 Vector Integrand(vsize); // function to be integrated
867 Vector Theta(vsize); // Theta values
868
869 double stepsize;
870 stepsize =
871 180.0 /
872 (vsize - 1); // attention this only works with eaqually spaced intervals
873 cout << "Neue berechnete Stepsize: " << stepsize << endl;
874
875 for (int i = 0; i < Integrand.nelem(); i++) Integrand[i] = i * stepsize;
876
877 //Theta is between 0 and 180
878 for (int i = 0; i < Theta.nelem(); i++) Theta[i] = i * stepsize;
879
880 cout << "Integrand: von " << Integrand[0] << " bis "
881 << Integrand[Integrand.nelem() - 1] << endl
882 << "Theta: von " << Theta[0] << " bis " << Theta[Theta.nelem() - 1]
883 << endl;
884
885 Numeric result = 0;
886
887 struct timeval start;
888 struct timeval ende;
889 gettimeofday(&start, NULL);
890 cout << "Sekunden : " << start.tv_sec << endl
891 << "Milisekunden: " << start.tv_usec << endl;
892
893 for (int i = 0; i < frequency; i++)
894 result = AngIntegrate_trapezoid_fixedstep(Integrand, Theta, stepsize);
895
896 gettimeofday(&ende, NULL);
897
898 // norming the result to Pi
899 result = result / (2 * 180);
900
901 double error = result / PI - 1;
902
903 double diffs = (double)(ende.tv_sec - start.tv_sec) +
904 (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
905 cout.precision(15);
906 cout << diffs << endl;
907 cout << "stepsize is : " << stepsize << endl
908 << "number of steps: " << vsize << endl
909 << "1 is : " << PI / PI << endl
910 << "The result is : " << result / PI << endl
911 << "The error is : " << error * 100 << "%\n"
912 << "Number of loops: " << frequency << endl
913 << "elapsed time : " << diffs << "s" << endl
914 << "---------------test_x_fixedstep----------<<<<<\n";
915
916 return result;
917}
This file contains the definition of Array.
The global header file for ARTS.
Constants of physical expressions as constexpr.
Common ARTS conversions.
A constant view of a Vector.
Definition: matpackI.h:521
Index nelem() const noexcept
Returns the number of elements.
Definition: matpackI.h:547
The MatrixView class.
Definition: matpackI.h:1188
The Matrix class.
Definition: matpackI.h:1285
The Vector class.
Definition: matpackI.h:910
#define ARTS_ASSERT(condition,...)
Definition: debug.h:82
int main()
bool is_size(ConstVectorView x, const Index &n)
Verifies that the size of x is l.
Definition: logic.cc:82
Header file for logic.cc.
Numeric AngIntegrate_trapezoid_opti(ConstMatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid, ConstVectorView grid_stepsize)
AngIntegrate_trapezoid_opti.
Definition: math_funcs.cc:359
Implementation of Matrix, Vector, and such stuff.
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
constexpr Numeric pi
The following mathematical constants are generated in python Decimal package by the code:
constexpr auto deg2rad(auto x) noexcept
Converts degrees to radians.
Numeric test_xy_fixedstep(int z_size, int a_size, float stepsize, int frequency)
test_xy_fixedstep
Numeric test_xy_fixedstep_opt2(int z_size, int a_size, float stepsize, int frequency)
test_xy_fixedstep_opt2
Numeric test_AngIntegrate_trapezoid_opti(int z_size, int a_size, float stepsize, int frequency)
test_AngIntegrate_trapezoid_opti
Numeric AngIntegrate_trapezoid_fixedstep_opt2(MatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid, Numeric stepsize)
AngIntegrate_trapezoid_fixedstep_opt2.
Numeric AngIntegrate_trapezoid_original(MatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid)
AngIntegrate_trapezoid_original.
void init_x(int vsize, float stepsize, int frequency, Vector &Integrand, Vector &Theta)
init_x
constexpr Numeric DEG2RAD
Numeric test_xy_fixedstep_opt(int z_size, int a_size, float stepsize, int frequency)
test_xy_fixedstep_opt
Numeric AngIntegrate_trapezoid_fixedstep_opt(MatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid, Numeric stepsize)
AngIntegrate_trapezoid_fixedstep_opt.
Numeric AngIntegrate_trapezoid_fixedstep(MatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid, Numeric stepsize)
AngIntegrate_trapezoid_fixedstep.
Numeric test_x(int vsize, float stepsize, int frequency)
test_x
void init_xy(float stepsize, int frequency, Matrix &Integrand, Vector &za_grid, Vector &aa_grid)
init_xy
Numeric test_x_fixedstep(int vsize, int frequency)
test_x_fixedstep
constexpr Numeric PI
Numeric AngIntegrate_trapezoid_opt(MatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid)
AngIntegrate_trapezoid_opt.
Numeric test_xy_opt(int z_size, int a_size, float stepsize, int frequency)
test_xy_opt
Numeric test_xy(int z_size, int a_size, float stepsize, int frequency)
test_xy