ARTS  2.2.66
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 <iostream>
30 #include <cmath>
31 #include <stdexcept>
32 #include <sys/time.h>
33 
34 #include "arts.h"
35 #include "array.h"
36 #include "math_funcs.h"
37 #include "matpackI.h"
38 #include "logic.h"
39 
40 extern const Numeric DEG2RAD;
41 extern const Numeric PI;
42 
43 void init_xy(float stepsize, int frequency,
44  Matrix& Integrand, Vector& za_grid, Vector& aa_grid);
45 
46 void init_x(int vsize, float stepsize, int frequency,
47  Vector& Integrand, Vector& Theta);
48 
50  ConstVectorView za_grid,
51  ConstVectorView aa_grid);
52 
54  ConstVectorView za_grid,
55  ConstVectorView aa_grid);
56 
58  ConstVectorView za_grid,
59  ConstVectorView aa_grid,
60  Numeric stepsize);
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 
76  ConstVectorView za_grid,
77  Numeric stepsize);
78 
79 Numeric test_xy(int z_size, int a_size,
80  float stepsize, int frequency);
81 
82 Numeric test_xy_opt(int z_size, int a_size,
83  float stepsize, int frequency);
84 
85 Numeric test_xy_fixedstep(int z_size, int a_size,
86  float stepsize, int frequency);
87 
88 Numeric test_xy_fixedstep_opt(int z_size, int a_size,
89  float stepsize, int frequency);
90 
91 Numeric test_xy_fixedstep_opt2(int z_size, int a_size,
92  float stepsize, int frequency);
93 
94 Numeric test_AngIntegrate_trapezoid_opti(int z_size, int a_size,
95  float stepsize, int frequency);
96 
97 Numeric test_x(int vsize,
98  float stepsize,
99  int frequency);
100 
101 Numeric test_x_fixedstep(int vsize,
102  int frequency);
103 
104 
105 int main(int argc, char *argv[])
106 {
107  if (argc == 1)
108  { cerr << argv[0] << " requires one parameter" << endl; exit (1); }
109 
110  cout << "Uebergabewert von argv : " << argv[1] << endl;
111 
112  int frequency = (int)strtol(argv[1], NULL, 10); // Zahl zur Basis 10
113  cout << "Wert von frequency : " << frequency << endl;
114 
115  // test_x(1801, 0.1, frequency);
116  // test_x_fixedstep(1801, frequency);
117  // test_x(181, 1, frequency);
118  // test_x(19, 10, frequency);
119 
120  test_xy(181, 361, 1.0, frequency);
121  // test_xy_opt(1801, 3601, 0.1, frequency);
122  // test_xy_fixedstep(1801, 3601, 0.1, frequency);
123  // test_xy_fixedstep_opt(1801, 3601, 0.1, frequency);
124  // test_xy_fixedstep_opt(181, 361, 1.0, frequency);
125  // test_xy_fixedstep_opt(19, 37, 10, frequency);
126  // test_xy_fixedstep_opt2(1801, 3601, 0.1, frequency);
127  // test_xy_fixedstep_opt2(181, 361, 1.0, frequency);
128  test_AngIntegrate_trapezoid_opti(181, 361, 1.0, frequency);
129  // test_xy_fixedstep_opt2(19, 37, 10, frequency);
130 }
131 
132 
134 
138 void init_x(int vsize, float stepsize, int frequency,
139  Vector& Integrand, Vector& Theta)
140 {
141  cout << "----------------init_x---------------\n";
142 
143  // Integrand.resize(vsize); // function to be integrated
144  // Theta.resize(vsize); // Theta values
145 
146  for (int i = 0; i < Integrand.nelem(); i++)
147  Integrand[i] = (float)i * stepsize;
148 
149  //Theta is between 0 and 180
150  for (int i = 0; i < Theta.nelem(); i++)
151  Theta[i] = (float)i * stepsize;
152 
153  cout << "function Y = X" << endl
154  << "vsize = " << vsize << endl
155  << "stepsize = " << stepsize << endl
156  << "frequency = " << frequency << endl
157  << "Integrand: von " << Integrand[0] << " bis "
158  << Integrand[Integrand.nelem() - 1] << endl
159  << "Theta: von " << Theta[0] << " bis "
160  << Theta[Theta.nelem() - 1] << endl;
161 }
162 
163 
165 
169 void init_xy(float stepsize, int frequency,
170  Matrix& Integrand, Vector& za_grid, Vector& aa_grid)
171 {
172  cout << ">>>>>-----------init_xy---------------\n";
173  Index n_za = za_grid.nelem();
174  Index n_aa = aa_grid.nelem();
175 
176  // The r=1 so we get a circle
177  for (Index i = 0; i < n_za; i++)
178  for (Index j = 0; j < n_aa; j++)
179  Integrand(i,j)=1;
180 
181  //za_grid (Theta) is between 0 and 180
182  for (Index i = 0; i < n_za; i++)
183  za_grid[i] = (float)i * stepsize;
184 
185  //aa_grid (Phi) is between 0 and 360
186  for (Index i = 0; i < n_aa; i++)
187  aa_grid[i] = (float)i * stepsize;
188 
189  cout << "function x^2 + y^2 + z^2 = 1" << endl
190  << "n_za = " << n_za << endl
191  << "n_aa = " << n_aa << endl
192  << "stepsize = " << stepsize << endl
193  << "frequency = " << frequency << endl
194  << "Integrand(*,0): von " << Integrand(0,0) << " bis "
195  << Integrand(n_za - 1, 0) << endl
196  << "Integrand(0,*): von " << Integrand(0,0) << " bis "
197  << Integrand(0, n_aa - 1) << endl
198  << "za_grid (Theta): von " << za_grid[0] << " bis "
199  << za_grid[za_grid.nelem() - 1] << endl
200  << "aa_grid (Phi) : von " << aa_grid[0] << " bis "
201  << aa_grid[aa_grid.nelem() - 1] << endl;
202  cout << "---------------init_xy---------------<<<<<\n";
203 }
204 
205 
207 
219  ConstVectorView za_grid,
220  ConstVectorView aa_grid)
221 {
222 
223  Index n = za_grid.nelem();
224  Index m = aa_grid.nelem();
225  Vector res1(n);
226  assert (is_size(Integrand, n, m));
227 
228  for (Index i = 0; i < n ; ++i)
229  {
230  res1[i] = 0.0;
231 
232  for (Index j = 0; j < m - 1; ++j)
233  {
234  res1[i] += 0.5 * DEG2RAD * (Integrand(i, j) + Integrand(i, j + 1)) *
235  (aa_grid[j + 1] - aa_grid[j]) * sin(za_grid[i] * DEG2RAD);
236  }
237  }
238  Numeric res = 0.0;
239  for (Index i = 0; i < n - 1; ++i)
240  {
241  res += 0.5 * DEG2RAD * (res1[i] + res1[i + 1]) *
242  (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 {
264 
265  Index n = za_grid.nelem();
266  Index m = aa_grid.nelem();
267  Vector res1(n);
268  assert (is_size(Integrand, n, m));
269 
270  for (Index i = 0; i < n ; ++i)
271  {
272  res1[i] = 0.0;
273 
274  for (Index j = 0; j < m - 1; ++j)
275  {
276  res1[i] += 0.5 * DEG2RAD * (Integrand(i, j) + Integrand(i, j + 1)) *
277  (aa_grid[j + 1] - aa_grid[j]) * sin(za_grid[i] * DEG2RAD);
278  }
279  }
280  Numeric res = 0.0;
281  for (Index i = 0; i < n - 1; ++i)
282  {
283  res += 0.5 * DEG2RAD * (res1[i] + res1[i + 1]) *
284  (za_grid[i + 1] - za_grid[i]);
285  }
286 
287  //cout<<res<<"\n";
288  return res;
289 }
290 
292 
305  ConstVectorView za_grid,
306  ConstVectorView aa_grid,
307  Numeric stepsize)
308 {
309  Index n = za_grid.nelem();
310  Index m = aa_grid.nelem();
311  Vector res1(n);
312  assert (is_size(Integrand, n, m));
313 
314  for (Index i = 0; i < n ; ++i)
315  {
316  res1[i] = 0.0;
317 
318  for (Index j = 0; j < m - 1; ++j)
319  {
320  res1[i] += 0.5 * DEG2RAD * (Integrand(i, j) + Integrand(i, j + 1)) *
321  stepsize * sin(za_grid[i] * DEG2RAD);
322  }
323  }
324  Numeric res = 0.0;
325  for (Index i = 0; i < n - 1; ++i)
326  {
327  res += 0.5 * DEG2RAD * (res1[i] + res1[i + 1]) * stepsize;
328  }
329 
330  //cout<<res<<"\n";
331  return res;
332 }
333 
335 
348  ConstVectorView za_grid,
349  ConstVectorView aa_grid,
350  Numeric stepsize)
351 {
352  Index n = za_grid.nelem();
353  Index m = aa_grid.nelem();
354  Vector res1(n);
355  assert (is_size(Integrand, n, m));
356 
357  for (Index i = 0; i < n ; ++i)
358  {
359  res1[i] = 0.0;
360 
361  res1[i] += Integrand(i, 0);
362  for (Index j = 1; j < m - 1; j++)
363  {
364  res1[i] += Integrand(i, j) * 2;
365  }
366  res1[i] += Integrand(i, m-1);
367  res1[i] *= 0.5 * DEG2RAD * stepsize * sin(za_grid[i] * DEG2RAD);
368  }
369  Numeric res = 0.0;
370  res += res1[0];
371  for (Index i = 1; i < n - 1; i++)
372  {
373  res += res1[i] * 2;
374  }
375  res += res1[n-1];
376  res *= 0.5 * DEG2RAD * stepsize;
377 
378  //cout<<res<<"\n";
379  return res;
380 }
381 
382 
384 
398  ConstVectorView za_grid,
399  ConstVectorView aa_grid,
400  Numeric stepsize)
401 {
402  Index n = za_grid.nelem();
403  Index m = aa_grid.nelem();
404  Vector res1(n);
405  assert (is_size(Integrand, n, m));
406 
407  Numeric temp = 0.0;
408 
409  for (Index i = 0; i < n ; ++i)
410  {
411  temp = Integrand(i, 0);
412  for (Index j = 1; j < m - 1; j++)
413  {
414  temp += Integrand(i, j) * 2;
415  }
416  temp += Integrand(i, m-1);
417  temp *= 0.5 * DEG2RAD * stepsize * sin(za_grid[i] * DEG2RAD);
418  res1[i] = temp;
419  }
420 
421  Numeric res = res1[0];
422  for (Index i = 1; i < n - 1; i++)
423  {
424  res += res1[i] * 2;
425  }
426  res += res1[n-1];
427  res *= 0.5 * DEG2RAD * stepsize;
428 
429  //cout<<res<<"\n";
430  return res;
431 }
432 
433 
435 
439  ConstVectorView za_grid)
440 {
441 
442  Index n = za_grid.nelem();
443  assert (is_size(Integrand, n));
444 
445  Numeric res = 0.0;
446  for (Index i = 0; i < n - 1; ++i)
447  {
448  // in this place 0.5 * 2 * PI is calculated:
449  res += PI * DEG2RAD * (Integrand[i]* sin(za_grid[i] * DEG2RAD)
450  + Integrand[i + 1] * sin(za_grid[i + 1] * DEG2RAD))
451  * (za_grid[i + 1] - za_grid[i]);
452  }
453 
454  //cout<<res<<"\n";
455  return res;
456 }
457 
459 
463  ConstVectorView za_grid,
464  Numeric stepsize)
465 {
466 
467  Index n = za_grid.nelem();
468  assert (is_size(Integrand, n));
469 
470  Numeric res = 0.0;
471  // cout << "Stepsize: " << stepsize << endl;
472  res += (Integrand[0] * sin(za_grid[0] * DEG2RAD));
473  for (Index i = 1; i < n - 1 ; ++i)
474  {
475  res += (Integrand[i] * sin(za_grid[i] * DEG2RAD) * 2);
476  // cout << i << endl;
477  }
478  res += ((Integrand[n-1] * sin(za_grid[n-1] * DEG2RAD)));
479  // cout << n-1 << endl;
480  // normally ther would be a 2* here, but it's already in the equations above
481  res *= PI * DEG2RAD * stepsize;
482 
483  //cout<<res<<"\n";
484  return res;
485 }
486 
487 
489 
500 Numeric test_xy(int z_size, int a_size,
501  float stepsize, int frequency)
502 {
503  cout << ">>>>>-----------test_xy---------------\n";
504  Matrix Integrand(z_size, a_size); // function to be integrated
505  Vector za_grid(z_size); // zenith (Theta) values
506  Vector aa_grid(a_size); // azimuth (Phi) values
507 
508  init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
509 
510  Numeric result = 0;
511 
512  struct timeval start;
513  struct timeval ende;
514  gettimeofday(&start, NULL);
515  // cout << "Sekunden : " << start.tv_sec << endl
516  // << "Milisekunden: " << start.tv_usec << endl;
517 
518  for (int i = 0; i < frequency; i++)
519  result = AngIntegrate_trapezoid_original(Integrand, za_grid, aa_grid);
520 
521  gettimeofday(&ende, NULL);
522 
523  double error = result/(4*PI) - 1;
524 
525  double diffs = (double)(ende.tv_sec - start.tv_sec)
526  + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
527  cout.precision(15);
528  cout << "stepsize is : " << stepsize << endl
529  << "z_size : " << z_size << endl
530  << "a_size : " << a_size << endl
531  << "1 is : " << result/(4*PI) << endl
532  << "The result is : " << result << endl
533  << "The error is : " << error*100 << " %\n"
534  << "Number of loops: " << frequency << endl
535  << "elapsed time : " << diffs << "s" << endl
536  << "----------------test_xy----------<<<<<\n";
537 
538  return result;
539 
540 }
541 
543 
554 Numeric test_xy_opt(int z_size, int a_size,
555  float stepsize, int frequency)
556 {
557  cout << ">>>>>-----------test_xy_opt---------------\n";
558  Matrix Integrand(z_size, a_size); // function to be integrated
559  Vector za_grid(z_size); // zenith (Theta) values
560  Vector aa_grid(a_size); // azimuth (Phi) values
561 
562  init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
563 
564  Numeric result = 0;
565 
566  struct timeval start;
567  struct timeval ende;
568  gettimeofday(&start, NULL);
569  // cout << "Sekunden : " << start.tv_sec << endl
570  // << "Milisekunden: " << start.tv_usec << endl;
571 
572  for (int i = 0; i < frequency; i++)
573  result = AngIntegrate_trapezoid_opt(Integrand, za_grid, aa_grid);
574 
575  gettimeofday(&ende, NULL);
576 
577  double error = result/(4*PI) - 1;
578 
579  double diffs = (double)(ende.tv_sec - start.tv_sec)
580  + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
581  cout.precision(15);
582  cout << "stepsize is : " << stepsize << endl
583  << "z_size : " << z_size << endl
584  << "a_size : " << a_size << endl
585  << "1 is : " << result/(4*PI) << endl
586  << "The result is : " << result << endl
587  << "The error is : " << error*100 << " %\n"
588  << "Number of loops: " << frequency << endl
589  << "elapsed time : " << diffs << "s" << endl
590  << "----------------test_xy_opt----------<<<<<\n";
591 
592  return result;
593 
594 }
595 
597 
608 Numeric test_xy_fixedstep(int z_size, int a_size,
609  float stepsize, int frequency)
610 {
611  cout << ">>>>>-----------test_xy_fixedstep---------------\n";
612  Matrix Integrand(z_size, a_size); // function to be integrated
613  Vector za_grid(z_size); // zenith (Theta) values
614  Vector aa_grid(a_size); // azimuth (Phi) values
615 
616  init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
617 
618  Numeric result = 0;
619 
620  struct timeval start;
621  struct timeval ende;
622  gettimeofday(&start, NULL);
623  // cout << "Sekunden : " << start.tv_sec << endl
624  // << "Milisekunden: " << start.tv_usec << endl;
625 
626  for (int i = 0; i < frequency; i++)
627  result = AngIntegrate_trapezoid_fixedstep(Integrand, za_grid, aa_grid, stepsize);
628 
629  gettimeofday(&ende, NULL);
630 
631  double error = result/(4*PI) - 1;
632 
633  double diffs = (double)(ende.tv_sec - start.tv_sec)
634  + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
635  cout.precision(15);
636  cout << diffs << endl;
637  cout << "stepsize is : " << stepsize << endl
638  << "z_size : " << z_size << endl
639  << "a_size : " << a_size << endl
640  << "1 is : " << result/(4*PI) << endl
641  << "The result is : " << result << endl
642  << "The error is : " << error*100 << " %\n"
643  << "Number of loops: " << frequency << endl
644  << "elapsed time : " << diffs << "s" << endl
645  << "----------------test_xy_fixedstep----------<<<<<\n";
646 
647  return result;
648 
649 }
650 
652 
663 Numeric test_xy_fixedstep_opt(int z_size, int a_size,
664  float stepsize, int frequency)
665 {
666  cout << ">>>>>-----------test_xy_fixedstep_opt---------------\n";
667  Matrix Integrand(z_size, a_size); // function to be integrated
668  Vector za_grid(z_size); // zenith (Theta) values
669  Vector aa_grid(a_size); // azimuth (Phi) values
670 
671  init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
672 
673  Numeric result = 0;
674 
675  struct timeval start;
676  struct timeval ende;
677  gettimeofday(&start, NULL);
678  // cout << "Sekunden : " << start.tv_sec << endl
679  // << "Milisekunden: " << start.tv_usec << endl;
680 
681  for (int i = 0; i < frequency; i++)
682  result = AngIntegrate_trapezoid_fixedstep_opt(Integrand, za_grid, aa_grid, stepsize);
683 
684  gettimeofday(&ende, NULL);
685 
686  double error = result/(4*PI) - 1;
687 
688  double diffs = (double)(ende.tv_sec - start.tv_sec)
689  + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
690  cout.precision(15);
691  cout << diffs << endl;
692  cout << "stepsize is : " << stepsize << endl
693  << "z_size : " << z_size << endl
694  << "a_size : " << a_size << endl
695  << "1 is : " << result/(4*PI) << endl
696  << "The result is : " << result << endl
697  << "The error is : " << error*100 << " %\n"
698  << "Number of loops: " << frequency << endl
699  << "elapsed time : " << diffs << "s" << endl
700  << "----------------test_xy_fixedstep_opt----------<<<<<\n";
701 
702  return result;
703 }
704 
705 
707 
718 Numeric test_xy_fixedstep_opt2(int z_size, int a_size,
719  float stepsize, int frequency)
720 {
721  cout << ">>>>>-----------test_xy_fixedstep_opt2---------------\n";
722  Matrix Integrand(z_size, a_size); // function to be integrated
723  Vector za_grid(z_size); // zenith (Theta) values
724  Vector aa_grid(a_size); // azimuth (Phi) values
725 
726  init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
727 
728  Numeric result = 0;
729 
730  struct timeval start;
731  struct timeval ende;
732  gettimeofday(&start, NULL);
733  // cout << "Sekunden : " << start.tv_sec << endl
734  // << "Milisekunden: " << start.tv_usec << endl;
735 
736  for (int i = 0; i < frequency; i++)
737  result = AngIntegrate_trapezoid_fixedstep_opt2(Integrand, za_grid, aa_grid, stepsize);
738 
739  gettimeofday(&ende, NULL);
740 
741  double error = result/(4*PI) - 1;
742 
743  double diffs = (double)(ende.tv_sec - start.tv_sec)
744  + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
745  cout.precision(15);
746  cout << diffs << endl;
747  cout << "stepsize is : " << stepsize << endl
748  << "z_size : " << z_size << endl
749  << "a_size : " << a_size << endl
750  << "1 is : " << result/(4*PI) << endl
751  << "The result is : " << result << endl
752  << "The error is : " << error*100 << " %\n"
753  << "Number of loops: " << frequency << endl
754  << "elapsed time : " << diffs << "s" << endl
755  << "----------------test_xy_fixedstep_opt2----------<<<<<\n";
756 
757  return result;
758 }
759 
761 
775  float stepsize, int frequency)
776 {
777  cout << ">>>>>-----------test_AngIntegrate_trapezoid_opti---------------\n";
778  Matrix Integrand(z_size, a_size); // function to be integrated
779  Vector za_grid(z_size); // zenith (Theta) values
780  Vector aa_grid(a_size); // azimuth (Phi) values
781 
782  Vector grid_stepsize(2);
783 
784  init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
785 
786  grid_stepsize[0] = za_grid[1] - za_grid[0];
787  grid_stepsize[1] = aa_grid[1] - aa_grid[0];
788  //grid_stepsize[0] = -1;
789  //grid_stepsize[1] = -1;
790 
791  // cout << za_grid << endl;
792  // cout << grid_stepsize[0] << endl;
793  // cout << grid_stepsize[1] << endl;
794 
795  Numeric result = 0;
796 
797  struct timeval start;
798  struct timeval ende;
799  gettimeofday(&start, NULL);
800  // cout << "Sekunden : " << start.tv_sec << endl
801  // << "Milisekunden: " << start.tv_usec << endl;
802 
803  for (int i = 0; i < frequency; i++)
804  result = AngIntegrate_trapezoid_opti(Integrand, za_grid, aa_grid, grid_stepsize);
805 
806  gettimeofday(&ende, NULL);
807 
808  double error = result/(4*PI) - 1;
809 
810  double diffs = (double)(ende.tv_sec - start.tv_sec)
811  + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
812  cout.precision(15);
813  cout << diffs << endl;
814  cout << "stepsize is : " << stepsize << endl
815  << "z_size : " << z_size << endl
816  << "a_size : " << a_size << endl
817  << "1 is : " << result/(4*PI) << endl
818  << "The result is : " << result << endl
819  << "The error is : " << error*100 << " %\n"
820  << "Number of loops: " << frequency << endl
821  << "elapsed time : " << diffs << "s" << endl
822  << "----------------test_AngIntegrate_trapezoid_opti----------<<<<<\n";
823 
824  return result;
825 }
826 
827 
828 
830 
840 Numeric test_x(int vsize,
841  float stepsize,
842  int frequency)
843 {
844  cout << ">>>>>-----------test_x---------------\n";
845  Vector Integrand(vsize); // function to be integrated
846  Vector Theta(vsize); // Theta values
847 
848  init_x(vsize, stepsize, frequency, Integrand, Theta);
849 
850  Numeric result = 0;
851 
852  struct timeval start;
853  struct timeval ende;
854  gettimeofday(&start, NULL);
855  cout << "Sekunden : " << start.tv_sec << endl
856  << "Milisekunden: " << start.tv_usec << endl;
857 
858  for (int i = 0; i < frequency; i++)
859  result = AngIntegrate_trapezoid_original(Integrand, Theta);
860 
861  gettimeofday(&ende, NULL);
862 
863  // norming the result to Pi
864  result = result / (2*180);
865 
866  double error = result/PI - 1;
867 
868 
869 
870  double diffs = (double)(ende.tv_sec - start.tv_sec)
871  + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
872  cout.precision(15);
873  cout << diffs << endl;
874  cout << "stepsize is : " << stepsize << endl
875  << "number of steps: " << vsize << endl
876  << "1 is : " << PI/PI << endl
877  << "The result is : " << result/PI << endl
878  << "The error is : " << error*100 << "%\n"
879  << "Number of loops: " << frequency << endl
880  << "elapsed time : " << diffs << "s" << endl
881  << "---------------test_x-----------<<<<<\n";
882 
883  return result;
884 
885 }
887 
897  int frequency)
898 {
899  cout << ">>>>>-----------test_x_fixedstep---------------\n";
900  cout.precision(12);
901  Vector Integrand(vsize); // function to be integrated
902  Vector Theta(vsize); // Theta values
903 
904  double stepsize;
905  stepsize = 180.0 / (vsize - 1); // attention this only works with eaqually spaced intervals
906  cout << "Neue berechnete Stepsize: " << stepsize << endl;
907 
908  for (int i = 0; i < Integrand.nelem(); i++)
909  Integrand[i] = i * stepsize;
910 
911  //Theta is between 0 and 180
912  for (int i = 0; i < Theta.nelem(); i++)
913  Theta[i] = i * stepsize;
914 
915 
916  cout << "Integrand: von " << Integrand[0] << " bis "
917  << Integrand[Integrand.nelem() - 1] << endl
918  << "Theta: von " << Theta[0] << " bis "
919  << Theta[Theta.nelem() - 1] << endl;
920 
921  Numeric result = 0;
922 
923  struct timeval start;
924  struct timeval ende;
925  gettimeofday(&start, NULL);
926  cout << "Sekunden : " << start.tv_sec << endl
927  << "Milisekunden: " << start.tv_usec << endl;
928 
929  for (int i = 0; i < frequency; i++)
930  result = AngIntegrate_trapezoid_fixedstep(Integrand, Theta, stepsize);
931 
932  gettimeofday(&ende, NULL);
933 
934  // norming the result to Pi
935  result = result / (2*180);
936 
937  double error = result/PI - 1;
938 
939 
940 
941  double diffs = (double)(ende.tv_sec - start.tv_sec)
942  + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
943  cout.precision(15);
944  cout << diffs << endl;
945  cout << "stepsize is : " << stepsize << endl
946  << "number of steps: " << vsize << endl
947  << "1 is : " << PI/PI << endl
948  << "The result is : " << result/PI << endl
949  << "The error is : " << error*100 << "%\n"
950  << "Number of loops: " << frequency << endl
951  << "elapsed time : " << diffs << "s" << endl
952  << "---------------test_x_fixedstep----------<<<<<\n";
953 
954  return result;
955 
956 }
Matrix
The Matrix class.
Definition: matpackI.h:788
MatrixView
The MatrixView class.
Definition: matpackI.h:679
test_AngIntegrate_trapezoid_opti
Numeric test_AngIntegrate_trapezoid_opti(int z_size, int a_size, float stepsize, int frequency)
test_AngIntegrate_trapezoid_opti
Definition: test_integration.cc:774
test_xy_fixedstep
Numeric test_xy_fixedstep(int z_size, int a_size, float stepsize, int frequency)
test_xy_fixedstep
Definition: test_integration.cc:608
test_xy_opt
Numeric test_xy_opt(int z_size, int a_size, float stepsize, int frequency)
test_xy_opt
Definition: test_integration.cc:554
test_xy_fixedstep_opt2
Numeric test_xy_fixedstep_opt2(int z_size, int a_size, float stepsize, int frequency)
test_xy_fixedstep_opt2
Definition: test_integration.cc:718
AngIntegrate_trapezoid_opti
Numeric AngIntegrate_trapezoid_opti(ConstMatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid, ConstVectorView grid_stepsize)
AngIntegrate_trapezoid_opti.
Definition: math_funcs.cc:377
temp
#define temp
Definition: continua.cc:20773
array.h
This file contains the definition of Array.
is_size
bool is_size(ConstVectorView x, const Index &n)
Verifies that the size of x is l.
Definition: logic.cc:91
test_x_fixedstep
Numeric test_x_fixedstep(int vsize, int frequency)
test_x_fixedstep
Definition: test_integration.cc:896
matpackI.h
DEG2RAD
const Numeric DEG2RAD
test_xy
Numeric test_xy(int z_size, int a_size, float stepsize, int frequency)
test_xy
Definition: test_integration.cc:500
AngIntegrate_trapezoid_fixedstep
Numeric AngIntegrate_trapezoid_fixedstep(MatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid, Numeric stepsize)
AngIntegrate_trapezoid_fixedstep.
Definition: test_integration.cc:304
ConstVectorView::nelem
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:180
init_x
void init_x(int vsize, float stepsize, int frequency, Vector &Integrand, Vector &Theta)
init_x
Definition: test_integration.cc:138
AngIntegrate_trapezoid_fixedstep_opt2
Numeric AngIntegrate_trapezoid_fixedstep_opt2(MatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid, Numeric stepsize)
AngIntegrate_trapezoid_fixedstep_opt2.
Definition: test_integration.cc:397
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:29
test_x
Numeric test_x(int vsize, float stepsize, int frequency)
test_x
Definition: test_integration.cc:840
init_xy
void init_xy(float stepsize, int frequency, Matrix &Integrand, Vector &za_grid, Vector &aa_grid)
init_xy
Definition: test_integration.cc:169
math_funcs.h
AngIntegrate_trapezoid_original
Numeric AngIntegrate_trapezoid_original(MatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid)
AngIntegrate_trapezoid_original.
Definition: test_integration.cc:218
logic.h
Header file for logic.cc.
AngIntegrate_trapezoid_fixedstep_opt
Numeric AngIntegrate_trapezoid_fixedstep_opt(MatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid, Numeric stepsize)
AngIntegrate_trapezoid_fixedstep_opt.
Definition: test_integration.cc:347
PI
const Numeric PI
test_xy_fixedstep_opt
Numeric test_xy_fixedstep_opt(int z_size, int a_size, float stepsize, int frequency)
test_xy_fixedstep_opt
Definition: test_integration.cc:663
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
Vector
The Vector class.
Definition: matpackI.h:556
main
int main(int argc, char *argv[])
Definition: test_integration.cc:105
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:292
arts.h
The global header file for ARTS.
AngIntegrate_trapezoid_opt
Numeric AngIntegrate_trapezoid_opt(MatrixView Integrand, ConstVectorView za_grid, ConstVectorView aa_grid)
AngIntegrate_trapezoid_opt.
Definition: test_integration.cc:260