ARTS  2.3.1285(git:92a29ea9-dirty)
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 "logic.h"
37 #include "math_funcs.h"
38 #include "matpackI.h"
39 
40 extern const Numeric DEG2RAD;
41 extern const Numeric PI;
42 
43 void init_xy(float stepsize,
44  int frequency,
45  Matrix& Integrand,
46  Vector& za_grid,
47  Vector& aa_grid);
48 
49 void init_x(
50  int vsize, float stepsize, int frequency, Vector& Integrand, Vector& Theta);
51 
53  ConstVectorView za_grid,
54  ConstVectorView aa_grid);
55 
57  ConstVectorView za_grid,
58  ConstVectorView aa_grid);
59 
61  ConstVectorView za_grid,
62  ConstVectorView aa_grid,
63  Numeric stepsize);
64 
66  ConstVectorView za_grid,
67  ConstVectorView aa_grid,
68  Numeric stepsize);
69 
71  ConstVectorView za_grid,
72  ConstVectorView aa_grid,
73  Numeric stepsize);
74 
76  ConstVectorView za_grid);
77 
79  ConstVectorView za_grid,
80  Numeric stepsize);
81 
82 Numeric test_xy(int z_size, int a_size, float stepsize, int frequency);
83 
84 Numeric test_xy_opt(int z_size, int a_size, float stepsize, int frequency);
85 
86 Numeric test_xy_fixedstep(int z_size,
87  int a_size,
88  float stepsize,
89  int frequency);
90 
92  int a_size,
93  float stepsize,
94  int frequency);
95 
97  int a_size,
98  float stepsize,
99  int frequency);
100 
102  int a_size,
103  float stepsize,
104  int frequency);
105 
106 Numeric test_x(int vsize, float stepsize, int frequency);
107 
108 Numeric test_x_fixedstep(int vsize, int frequency);
109 
110 int main(int argc, char* argv[]) {
111  if (argc == 1) {
112  cerr << argv[0] << " requires one parameter" << endl;
113  exit(1);
114  }
115 
116  cout << "Uebergabewert von argv : " << argv[1] << endl;
117 
118  int frequency = (int)strtol(argv[1], NULL, 10); // Zahl zur Basis 10
119  cout << "Wert von frequency : " << frequency << endl;
120 
121  // test_x(1801, 0.1, frequency);
122  // test_x_fixedstep(1801, frequency);
123  // test_x(181, 1, frequency);
124  // test_x(19, 10, frequency);
125 
126  test_xy(181, 361, 1.0, frequency);
127  // test_xy_opt(1801, 3601, 0.1, frequency);
128  // test_xy_fixedstep(1801, 3601, 0.1, frequency);
129  // test_xy_fixedstep_opt(1801, 3601, 0.1, frequency);
130  // test_xy_fixedstep_opt(181, 361, 1.0, frequency);
131  // test_xy_fixedstep_opt(19, 37, 10, frequency);
132  // test_xy_fixedstep_opt2(1801, 3601, 0.1, frequency);
133  // test_xy_fixedstep_opt2(181, 361, 1.0, frequency);
134  test_AngIntegrate_trapezoid_opti(181, 361, 1.0, frequency);
135  // test_xy_fixedstep_opt2(19, 37, 10, frequency);
136 }
137 
139 
143 void init_x(int vsize,
144  float stepsize,
145  int frequency,
146  Vector& Integrand,
147  Vector& Theta) {
148  cout << "----------------init_x---------------\n";
149 
150  // Integrand.resize(vsize); // function to be integrated
151  // Theta.resize(vsize); // Theta values
152 
153  for (int i = 0; i < Integrand.nelem(); i++)
154  Integrand[i] = (float)i * stepsize;
155 
156  //Theta is between 0 and 180
157  for (int i = 0; i < Theta.nelem(); i++) Theta[i] = (float)i * stepsize;
158 
159  cout << "function Y = X" << endl
160  << "vsize = " << vsize << endl
161  << "stepsize = " << stepsize << endl
162  << "frequency = " << frequency << endl
163  << "Integrand: von " << Integrand[0] << " bis "
164  << Integrand[Integrand.nelem() - 1] << endl
165  << "Theta: von " << Theta[0] << " bis " << Theta[Theta.nelem() - 1]
166  << endl;
167 }
168 
170 
174 void init_xy(float stepsize,
175  int frequency,
176  Matrix& Integrand,
177  Vector& za_grid,
178  Vector& aa_grid) {
179  cout << ">>>>>-----------init_xy---------------\n";
180  Index n_za = za_grid.nelem();
181  Index n_aa = aa_grid.nelem();
182 
183  // The r=1 so we get a circle
184  for (Index i = 0; i < n_za; i++)
185  for (Index j = 0; j < n_aa; j++) Integrand(i, j) = 1;
186 
187  //za_grid (Theta) is between 0 and 180
188  for (Index i = 0; i < n_za; i++) za_grid[i] = (float)i * stepsize;
189 
190  //aa_grid (Phi) is between 0 and 360
191  for (Index i = 0; i < n_aa; i++) aa_grid[i] = (float)i * stepsize;
192 
193  cout << "function x^2 + y^2 + z^2 = 1" << endl
194  << "n_za = " << n_za << endl
195  << "n_aa = " << n_aa << endl
196  << "stepsize = " << stepsize << endl
197  << "frequency = " << frequency << endl
198  << "Integrand(*,0): von " << Integrand(0, 0) << " bis "
199  << Integrand(n_za - 1, 0) << endl
200  << "Integrand(0,*): von " << Integrand(0, 0) << " bis "
201  << Integrand(0, n_aa - 1) << endl
202  << "za_grid (Theta): von " << za_grid[0] << " bis "
203  << za_grid[za_grid.nelem() - 1] << endl
204  << "aa_grid (Phi) : von " << aa_grid[0] << " bis "
205  << aa_grid[aa_grid.nelem() - 1] << endl;
206  cout << "---------------init_xy---------------<<<<<\n";
207 }
208 
210 
222  ConstVectorView za_grid,
223  ConstVectorView aa_grid) {
224  Index n = za_grid.nelem();
225  Index m = aa_grid.nelem();
226  Vector res1(n);
227  assert(is_size(Integrand, n, m));
228 
229  for (Index i = 0; i < n; ++i) {
230  res1[i] = 0.0;
231 
232  for (Index j = 0; j < m - 1; ++j) {
233  res1[i] += 0.5 * DEG2RAD * (Integrand(i, j) + Integrand(i, j + 1)) *
234  (aa_grid[j + 1] - aa_grid[j]) * sin(za_grid[i] * DEG2RAD);
235  }
236  }
237  Numeric res = 0.0;
238  for (Index i = 0; i < n - 1; ++i) {
239  res +=
240  0.5 * DEG2RAD * (res1[i] + res1[i + 1]) * (za_grid[i + 1] - za_grid[i]);
241  }
242 
243  //cout<<res<<"\n";
244  return res;
245 }
247 
259  ConstVectorView za_grid,
260  ConstVectorView aa_grid) {
261  Index n = za_grid.nelem();
262  Index m = aa_grid.nelem();
263  Vector res1(n);
264  assert(is_size(Integrand, n, m));
265 
266  for (Index i = 0; i < n; ++i) {
267  res1[i] = 0.0;
268 
269  for (Index j = 0; j < m - 1; ++j) {
270  res1[i] += 0.5 * DEG2RAD * (Integrand(i, j) + Integrand(i, j + 1)) *
271  (aa_grid[j + 1] - aa_grid[j]) * sin(za_grid[i] * DEG2RAD);
272  }
273  }
274  Numeric res = 0.0;
275  for (Index i = 0; i < n - 1; ++i) {
276  res +=
277  0.5 * DEG2RAD * (res1[i] + res1[i + 1]) * (za_grid[i + 1] - za_grid[i]);
278  }
279 
280  //cout<<res<<"\n";
281  return res;
282 }
283 
285 
298  ConstVectorView za_grid,
299  ConstVectorView aa_grid,
300  Numeric stepsize) {
301  Index n = za_grid.nelem();
302  Index m = aa_grid.nelem();
303  Vector res1(n);
304  assert(is_size(Integrand, n, m));
305 
306  for (Index i = 0; i < n; ++i) {
307  res1[i] = 0.0;
308 
309  for (Index j = 0; j < m - 1; ++j) {
310  res1[i] += 0.5 * DEG2RAD * (Integrand(i, j) + Integrand(i, j + 1)) *
311  stepsize * sin(za_grid[i] * DEG2RAD);
312  }
313  }
314  Numeric res = 0.0;
315  for (Index i = 0; i < n - 1; ++i) {
316  res += 0.5 * DEG2RAD * (res1[i] + res1[i + 1]) * stepsize;
317  }
318 
319  //cout<<res<<"\n";
320  return res;
321 }
322 
324 
337  ConstVectorView za_grid,
338  ConstVectorView aa_grid,
339  Numeric stepsize) {
340  Index n = za_grid.nelem();
341  Index m = aa_grid.nelem();
342  Vector res1(n);
343  assert(is_size(Integrand, n, m));
344 
345  for (Index i = 0; i < n; ++i) {
346  res1[i] = 0.0;
347 
348  res1[i] += Integrand(i, 0);
349  for (Index j = 1; j < m - 1; j++) {
350  res1[i] += Integrand(i, j) * 2;
351  }
352  res1[i] += Integrand(i, m - 1);
353  res1[i] *= 0.5 * DEG2RAD * stepsize * sin(za_grid[i] * DEG2RAD);
354  }
355  Numeric res = 0.0;
356  res += res1[0];
357  for (Index i = 1; i < n - 1; i++) {
358  res += res1[i] * 2;
359  }
360  res += res1[n - 1];
361  res *= 0.5 * DEG2RAD * stepsize;
362 
363  //cout<<res<<"\n";
364  return res;
365 }
366 
368 
382  ConstVectorView za_grid,
383  ConstVectorView aa_grid,
384  Numeric stepsize) {
385  Index n = za_grid.nelem();
386  Index m = aa_grid.nelem();
387  Vector res1(n);
388  assert(is_size(Integrand, n, m));
389 
390  Numeric temp = 0.0;
391 
392  for (Index i = 0; i < n; ++i) {
393  temp = Integrand(i, 0);
394  for (Index j = 1; j < m - 1; j++) {
395  temp += Integrand(i, j) * 2;
396  }
397  temp += Integrand(i, m - 1);
398  temp *= 0.5 * DEG2RAD * stepsize * sin(za_grid[i] * DEG2RAD);
399  res1[i] = temp;
400  }
401 
402  Numeric res = res1[0];
403  for (Index i = 1; i < n - 1; i++) {
404  res += res1[i] * 2;
405  }
406  res += res1[n - 1];
407  res *= 0.5 * DEG2RAD * stepsize;
408 
409  //cout<<res<<"\n";
410  return res;
411 }
412 
414 
418  ConstVectorView za_grid) {
419  Index n = za_grid.nelem();
420  assert(is_size(Integrand, n));
421 
422  Numeric res = 0.0;
423  for (Index i = 0; i < n - 1; ++i) {
424  // in this place 0.5 * 2 * PI is calculated:
425  res += PI * DEG2RAD *
426  (Integrand[i] * sin(za_grid[i] * DEG2RAD) +
427  Integrand[i + 1] * sin(za_grid[i + 1] * DEG2RAD)) *
428  (za_grid[i + 1] - za_grid[i]);
429  }
430 
431  //cout<<res<<"\n";
432  return res;
433 }
434 
436 
440  ConstVectorView za_grid,
441  Numeric stepsize) {
442  Index n = za_grid.nelem();
443  assert(is_size(Integrand, n));
444 
445  Numeric res = 0.0;
446  // cout << "Stepsize: " << stepsize << endl;
447  res += (Integrand[0] * sin(za_grid[0] * DEG2RAD));
448  for (Index i = 1; i < n - 1; ++i) {
449  res += (Integrand[i] * sin(za_grid[i] * DEG2RAD) * 2);
450  // cout << i << endl;
451  }
452  res += ((Integrand[n - 1] * sin(za_grid[n - 1] * DEG2RAD)));
453  // cout << n-1 << endl;
454  // normally ther would be a 2* here, but it's already in the equations above
455  res *= PI * DEG2RAD * stepsize;
456 
457  //cout<<res<<"\n";
458  return res;
459 }
460 
462 
473 Numeric test_xy(int z_size, int a_size, float stepsize, int frequency) {
474  cout << ">>>>>-----------test_xy---------------\n";
475  Matrix Integrand(z_size, a_size); // function to be integrated
476  Vector za_grid(z_size); // zenith (Theta) values
477  Vector aa_grid(a_size); // azimuth (Phi) values
478 
479  init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
480 
481  Numeric result = 0;
482 
483  struct timeval start;
484  struct timeval ende;
485  gettimeofday(&start, NULL);
486  // cout << "Sekunden : " << start.tv_sec << endl
487  // << "Milisekunden: " << start.tv_usec << endl;
488 
489  for (int i = 0; i < frequency; i++)
490  result = AngIntegrate_trapezoid_original(Integrand, za_grid, aa_grid);
491 
492  gettimeofday(&ende, NULL);
493 
494  double error = result / (4 * PI) - 1;
495 
496  double diffs = (double)(ende.tv_sec - start.tv_sec) +
497  (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
498  cout.precision(15);
499  cout << "stepsize is : " << stepsize << endl
500  << "z_size : " << z_size << endl
501  << "a_size : " << a_size << endl
502  << "1 is : " << result / (4 * PI) << endl
503  << "The result is : " << result << endl
504  << "The error is : " << error * 100 << " %\n"
505  << "Number of loops: " << frequency << endl
506  << "elapsed time : " << diffs << "s" << endl
507  << "----------------test_xy----------<<<<<\n";
508 
509  return result;
510 }
511 
513 
524 Numeric test_xy_opt(int z_size, int a_size, float stepsize, int frequency) {
525  cout << ">>>>>-----------test_xy_opt---------------\n";
526  Matrix Integrand(z_size, a_size); // function to be integrated
527  Vector za_grid(z_size); // zenith (Theta) values
528  Vector aa_grid(a_size); // azimuth (Phi) values
529 
530  init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
531 
532  Numeric result = 0;
533 
534  struct timeval start;
535  struct timeval ende;
536  gettimeofday(&start, NULL);
537  // cout << "Sekunden : " << start.tv_sec << endl
538  // << "Milisekunden: " << start.tv_usec << endl;
539 
540  for (int i = 0; i < frequency; i++)
541  result = AngIntegrate_trapezoid_opt(Integrand, za_grid, aa_grid);
542 
543  gettimeofday(&ende, NULL);
544 
545  double error = result / (4 * PI) - 1;
546 
547  double diffs = (double)(ende.tv_sec - start.tv_sec) +
548  (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
549  cout.precision(15);
550  cout << "stepsize is : " << stepsize << endl
551  << "z_size : " << z_size << endl
552  << "a_size : " << a_size << endl
553  << "1 is : " << result / (4 * PI) << endl
554  << "The result is : " << result << endl
555  << "The error is : " << error * 100 << " %\n"
556  << "Number of loops: " << frequency << endl
557  << "elapsed time : " << diffs << "s" << endl
558  << "----------------test_xy_opt----------<<<<<\n";
559 
560  return result;
561 }
562 
564 
576  int a_size,
577  float stepsize,
578  int frequency) {
579  cout << ">>>>>-----------test_xy_fixedstep---------------\n";
580  Matrix Integrand(z_size, a_size); // function to be integrated
581  Vector za_grid(z_size); // zenith (Theta) values
582  Vector aa_grid(a_size); // azimuth (Phi) values
583 
584  init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
585 
586  Numeric result = 0;
587 
588  struct timeval start;
589  struct timeval ende;
590  gettimeofday(&start, NULL);
591  // cout << "Sekunden : " << start.tv_sec << endl
592  // << "Milisekunden: " << start.tv_usec << endl;
593 
594  for (int i = 0; i < frequency; i++)
595  result =
596  AngIntegrate_trapezoid_fixedstep(Integrand, za_grid, aa_grid, stepsize);
597 
598  gettimeofday(&ende, NULL);
599 
600  double error = result / (4 * PI) - 1;
601 
602  double diffs = (double)(ende.tv_sec - start.tv_sec) +
603  (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
604  cout.precision(15);
605  cout << diffs << endl;
606  cout << "stepsize is : " << stepsize << endl
607  << "z_size : " << z_size << endl
608  << "a_size : " << a_size << endl
609  << "1 is : " << result / (4 * PI) << endl
610  << "The result is : " << result << endl
611  << "The error is : " << error * 100 << " %\n"
612  << "Number of loops: " << frequency << endl
613  << "elapsed time : " << diffs << "s" << endl
614  << "----------------test_xy_fixedstep----------<<<<<\n";
615 
616  return result;
617 }
618 
620 
632  int a_size,
633  float stepsize,
634  int frequency) {
635  cout << ">>>>>-----------test_xy_fixedstep_opt---------------\n";
636  Matrix Integrand(z_size, a_size); // function to be integrated
637  Vector za_grid(z_size); // zenith (Theta) values
638  Vector aa_grid(a_size); // azimuth (Phi) values
639 
640  init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
641 
642  Numeric result = 0;
643 
644  struct timeval start;
645  struct timeval ende;
646  gettimeofday(&start, NULL);
647  // cout << "Sekunden : " << start.tv_sec << endl
648  // << "Milisekunden: " << start.tv_usec << endl;
649 
650  for (int i = 0; i < frequency; i++)
652  Integrand, za_grid, aa_grid, stepsize);
653 
654  gettimeofday(&ende, NULL);
655 
656  double error = result / (4 * PI) - 1;
657 
658  double diffs = (double)(ende.tv_sec - start.tv_sec) +
659  (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
660  cout.precision(15);
661  cout << diffs << endl;
662  cout << "stepsize is : " << stepsize << endl
663  << "z_size : " << z_size << endl
664  << "a_size : " << a_size << endl
665  << "1 is : " << result / (4 * PI) << endl
666  << "The result is : " << result << endl
667  << "The error is : " << error * 100 << " %\n"
668  << "Number of loops: " << frequency << endl
669  << "elapsed time : " << diffs << "s" << endl
670  << "----------------test_xy_fixedstep_opt----------<<<<<\n";
671 
672  return result;
673 }
674 
676 
688  int a_size,
689  float stepsize,
690  int frequency) {
691  cout << ">>>>>-----------test_xy_fixedstep_opt2---------------\n";
692  Matrix Integrand(z_size, a_size); // function to be integrated
693  Vector za_grid(z_size); // zenith (Theta) values
694  Vector aa_grid(a_size); // azimuth (Phi) values
695 
696  init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
697 
698  Numeric result = 0;
699 
700  struct timeval start;
701  struct timeval ende;
702  gettimeofday(&start, NULL);
703  // cout << "Sekunden : " << start.tv_sec << endl
704  // << "Milisekunden: " << start.tv_usec << endl;
705 
706  for (int i = 0; i < frequency; i++)
708  Integrand, za_grid, aa_grid, stepsize);
709 
710  gettimeofday(&ende, NULL);
711 
712  double error = result / (4 * PI) - 1;
713 
714  double diffs = (double)(ende.tv_sec - start.tv_sec) +
715  (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
716  cout.precision(15);
717  cout << diffs << endl;
718  cout << "stepsize is : " << stepsize << endl
719  << "z_size : " << z_size << endl
720  << "a_size : " << a_size << endl
721  << "1 is : " << result / (4 * PI) << endl
722  << "The result is : " << result << endl
723  << "The error is : " << error * 100 << " %\n"
724  << "Number of loops: " << frequency << endl
725  << "elapsed time : " << diffs << "s" << endl
726  << "----------------test_xy_fixedstep_opt2----------<<<<<\n";
727 
728  return result;
729 }
730 
732 
746  int a_size,
747  float stepsize,
748  int frequency) {
749  cout << ">>>>>-----------test_AngIntegrate_trapezoid_opti---------------\n";
750  Matrix Integrand(z_size, a_size); // function to be integrated
751  Vector za_grid(z_size); // zenith (Theta) values
752  Vector aa_grid(a_size); // azimuth (Phi) values
753 
754  Vector grid_stepsize(2);
755 
756  init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
757 
758  grid_stepsize[0] = za_grid[1] - za_grid[0];
759  grid_stepsize[1] = aa_grid[1] - aa_grid[0];
760  //grid_stepsize[0] = -1;
761  //grid_stepsize[1] = -1;
762 
763  // cout << za_grid << endl;
764  // cout << grid_stepsize[0] << endl;
765  // cout << grid_stepsize[1] << endl;
766 
767  Numeric result = 0;
768 
769  struct timeval start;
770  struct timeval ende;
771  gettimeofday(&start, NULL);
772  // cout << "Sekunden : " << start.tv_sec << endl
773  // << "Milisekunden: " << start.tv_usec << endl;
774 
775  for (int i = 0; i < frequency; i++)
776  result =
777  AngIntegrate_trapezoid_opti(Integrand, za_grid, aa_grid, grid_stepsize);
778 
779  gettimeofday(&ende, NULL);
780 
781  double error = result / (4 * PI) - 1;
782 
783  double diffs = (double)(ende.tv_sec - start.tv_sec) +
784  (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
785  cout.precision(15);
786  cout << diffs << endl;
787  cout << "stepsize is : " << stepsize << endl
788  << "z_size : " << z_size << endl
789  << "a_size : " << a_size << endl
790  << "1 is : " << result / (4 * PI) << endl
791  << "The result is : " << result << endl
792  << "The error is : " << error * 100 << " %\n"
793  << "Number of loops: " << frequency << endl
794  << "elapsed time : " << diffs << "s" << endl
795  << "----------------test_AngIntegrate_trapezoid_opti----------<<<<<\n";
796 
797  return result;
798 }
799 
801 
811 Numeric test_x(int vsize, float stepsize, int frequency) {
812  cout << ">>>>>-----------test_x---------------\n";
813  Vector Integrand(vsize); // function to be integrated
814  Vector Theta(vsize); // Theta values
815 
816  init_x(vsize, stepsize, frequency, Integrand, Theta);
817 
818  Numeric result = 0;
819 
820  struct timeval start;
821  struct timeval ende;
822  gettimeofday(&start, NULL);
823  cout << "Sekunden : " << start.tv_sec << endl
824  << "Milisekunden: " << start.tv_usec << endl;
825 
826  for (int i = 0; i < frequency; i++)
827  result = AngIntegrate_trapezoid_original(Integrand, Theta);
828 
829  gettimeofday(&ende, NULL);
830 
831  // norming the result to Pi
832  result = result / (2 * 180);
833 
834  double error = result / PI - 1;
835 
836  double diffs = (double)(ende.tv_sec - start.tv_sec) +
837  (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
838  cout.precision(15);
839  cout << diffs << endl;
840  cout << "stepsize is : " << stepsize << endl
841  << "number of steps: " << vsize << endl
842  << "1 is : " << PI / PI << endl
843  << "The result is : " << result / PI << endl
844  << "The error is : " << error * 100 << "%\n"
845  << "Number of loops: " << frequency << endl
846  << "elapsed time : " << diffs << "s" << endl
847  << "---------------test_x-----------<<<<<\n";
848 
849  return result;
850 }
852 
861 Numeric test_x_fixedstep(int vsize, int frequency) {
862  cout << ">>>>>-----------test_x_fixedstep---------------\n";
863  cout.precision(12);
864  Vector Integrand(vsize); // function to be integrated
865  Vector Theta(vsize); // Theta values
866 
867  double stepsize;
868  stepsize =
869  180.0 /
870  (vsize - 1); // attention this only works with eaqually spaced intervals
871  cout << "Neue berechnete Stepsize: " << stepsize << endl;
872 
873  for (int i = 0; i < Integrand.nelem(); i++) Integrand[i] = i * stepsize;
874 
875  //Theta is between 0 and 180
876  for (int i = 0; i < Theta.nelem(); i++) Theta[i] = i * stepsize;
877 
878  cout << "Integrand: von " << Integrand[0] << " bis "
879  << Integrand[Integrand.nelem() - 1] << endl
880  << "Theta: von " << Theta[0] << " bis " << Theta[Theta.nelem() - 1]
881  << endl;
882 
883  Numeric result = 0;
884 
885  struct timeval start;
886  struct timeval ende;
887  gettimeofday(&start, NULL);
888  cout << "Sekunden : " << start.tv_sec << endl
889  << "Milisekunden: " << start.tv_usec << endl;
890 
891  for (int i = 0; i < frequency; i++)
892  result = AngIntegrate_trapezoid_fixedstep(Integrand, Theta, stepsize);
893 
894  gettimeofday(&ende, NULL);
895 
896  // norming the result to Pi
897  result = result / (2 * 180);
898 
899  double error = result / PI - 1;
900 
901  double diffs = (double)(ende.tv_sec - start.tv_sec) +
902  (double)(ende.tv_usec - start.tv_usec) / 1000000.0;
903  cout.precision(15);
904  cout << diffs << endl;
905  cout << "stepsize is : " << stepsize << endl
906  << "number of steps: " << vsize << endl
907  << "1 is : " << PI / PI << endl
908  << "The result is : " << result / PI << endl
909  << "The error is : " << error * 100 << "%\n"
910  << "Number of loops: " << frequency << endl
911  << "elapsed time : " << diffs << "s" << endl
912  << "---------------test_x_fixedstep----------<<<<<\n";
913 
914  return result;
915 }
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Numeric AngIntegrate_trapezoid_opti(ConstMatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid, ConstVectorView grid_stepsize)
AngIntegrate_trapezoid_opti.
Definition: math_funcs.cc:340
The Vector class.
Definition: matpackI.h:860
void init_x(int vsize, float stepsize, int frequency, Vector &Integrand, Vector &Theta)
init_x
The MatrixView class.
Definition: matpackI.h:1093
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
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:51
const Numeric DEG2RAD
This file contains the definition of Array.
The global header file for ARTS.
Numeric test_xy_fixedstep_opt2(int z_size, int a_size, float stepsize, int frequency)
test_xy_fixedstep_opt2
Numeric test_x_fixedstep(int vsize, int frequency)
test_x_fixedstep
Numeric test_xy(int z_size, int a_size, float stepsize, int frequency)
test_xy
Numeric AngIntegrate_trapezoid_original(MatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid)
AngIntegrate_trapezoid_original.
#define temp
Numeric AngIntegrate_trapezoid_fixedstep_opt2(MatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid, Numeric stepsize)
AngIntegrate_trapezoid_fixedstep_opt2.
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
The Matrix class.
Definition: matpackI.h:1193
Implementation of Matrix, Vector, and such stuff.
Header file for logic.cc.
Numeric AngIntegrate_trapezoid_opt(MatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid)
AngIntegrate_trapezoid_opt.
const Numeric PI
Numeric test_xy_opt(int z_size, int a_size, float stepsize, int frequency)
test_xy_opt
A constant view of a Vector.
Definition: matpackI.h:476
Numeric test_AngIntegrate_trapezoid_opti(int z_size, int a_size, float stepsize, int frequency)
test_AngIntegrate_trapezoid_opti
Numeric test_xy_fixedstep_opt(int z_size, int a_size, float stepsize, int frequency)
test_xy_fixedstep_opt
bool is_size(ConstVectorView x, const Index &n)
Verifies that the size of x is l.
Definition: logic.cc:79
Numeric test_xy_fixedstep(int z_size, int a_size, float stepsize, int frequency)
test_xy_fixedstep
Numeric AngIntegrate_trapezoid_fixedstep_opt(MatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid, Numeric stepsize)
AngIntegrate_trapezoid_fixedstep_opt.
int main(int argc, char *argv[])