Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
integratefunction.cpp
Go to the documentation of this file.
1/*
2 * This file is part of Vlasiator.
3 * Copyright 2010-2016 Finnish Meteorological Institute
4 *
5 * For details of usage, see the COPYING file and read the "Rules of the Road"
6 * at http://www.physics.helsinki.fi/vlasiator/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22/*
23Background magnetic field class of Vlasiator.
24*/
25
26#include <string.h>
27#include <stdlib.h>
28#include <math.h>
29#include <iostream>
30
31#include "../common.h"
32#include "integratefunction.hpp"
33#include "functions.hpp"
34#include "quadr.hpp"
35
36
38 const T3DFunction& f1,
39 coordinate line,
40 double accuracy,
41 const std::array<double, 3>& r1,
42 double L
43) {
44 using namespace std::placeholders;
45 double value;
46 const double norm = 1/L;
47 const double acc = accuracy*L;
48 const double a = r1[line];
49 const double b = r1[line] + L;
50
51 switch (line) {
52 case X:
53 {
54 T1DFunction f=std::bind(f1,std::placeholders::_1,r1[1],r1[2]);
55 value= Romberg(f,a,b,acc)*norm;
56 }
57 break;
58 case Y:
59 {
60 T1DFunction f=std::bind(f1,r1[0],std::placeholders::_1,r1[2]);
61 value= Romberg(f,a,b,acc)*norm;
62 }
63 break;
64 case Z:
65 {
66 T1DFunction f=std::bind(f1,r1[0],r1[1],std::placeholders::_1);
67 value= Romberg(f,a,b,acc)*norm;
68 }
69 break;
70 default:
71 cerr << "*** lineAverage is bad\n";
72 value = 0.0;
73 break;
74 }
75 return value;
76}
77
78
80 const T3DFunction& f1,
81 coordinate face,
82 double accuracy,
83 const std::array<double, 3>& r1,
84 double L1,
85 double L2
86) {
87 using namespace std::placeholders;
88 double value;
89 const double acc = accuracy*L1*L2;
90 const double norm = 1/(L1*L2);
91 switch (face) {
92 case X:
93 {
94 T2DFunction f = std::bind(f1,r1[0],std::placeholders::_1,std::placeholders::_2);
95 value = Romberg(f, r1[1],r1[1]+L1, r1[2],r1[2]+L2, acc)*norm;
96 }
97 break;
98 case Y:
99 {
100 T2DFunction f = std::bind(f1,std::placeholders::_1,r1[1],std::placeholders::_2);
101 value = Romberg(f, r1[0],r1[0]+L1, r1[2],r1[2]+L2, acc)*norm;
102 }
103 break;
104 case Z:
105 {
106 T2DFunction f = std::bind(f1,std::placeholders::_1,std::placeholders::_2,r1[2]);
107 value = Romberg(f, r1[0],r1[0]+L1, r1[1],r1[1]+L2, acc)*norm;
108 }
109 break;
110 default:
111 cerr << "*** SurfaceAverage is bad\n";
112 exit(1);
113 break;
114 }
115 return value;
116}
117
118
120 const T3DFunction& f1,
121 double accuracy,
122 const std::array<double, 3>& r1,
123 const std::array<double, 3>& r2
124) {
125 double value;
126 const double acc = accuracy*(r2[0]-r1[0])*(r2[1]-r1[1])*(r2[2]-r1[2]);
127 const double norm = 1.0/((r2[0]-r1[0])*(r2[1]-r1[1])*(r2[2]-r1[2]));
128 value= Romberg(f1, r1[0],r2[0], r1[1],r2[1], r1[2],r2[2], acc)*norm;
129 return value;
130}
131
std::function< double(double, double)> T2DFunction
Definition functions.hpp:31
std::function< double(double, double, double)> T3DFunction
Definition functions.hpp:32
std::function< double(double)> T1DFunction
Definition functions.hpp:30
coordinate
Definition functions.hpp:28
@ Y
Definition functions.hpp:28
@ X
Definition functions.hpp:28
@ Z
Definition functions.hpp:28
double lineAverage(const T3DFunction &f1, coordinate line, double accuracy, const std::array< double, 3 > &r1, double L)
double volumeAverage(const T3DFunction &f1, double accuracy, const std::array< double, 3 > &r1, const std::array< double, 3 > &r2)
double surfaceAverage(const T3DFunction &f1, coordinate face, double accuracy, const std::array< double, 3 > &r1, double L1, double L2)
double Romberg(const T1DFunction &func, double a, double b, double absacc)
Definition quadr.cpp:179