Chi-Tech
sldfe_sq_02_test_integration.cc
Go to the documentation of this file.
1#include "sldfe_sq.h"
2
4
5#include "chi_runtime.h"
6#include "chi_log.h"
7
8//###################################################################
9/**Performs a simple Riemann integral of a base functor.*/
11{
12 double dangle = M_PI_2/Ni;
13 double dtheta = dangle;
14 double dphi = dangle;
15 double I_riemann = 0.0;
16 for (int i=0; i<Ni; ++i)
17 {
18 double theta = (0.5+i)*dtheta;
19 for (int j=0; j<Ni; ++j)
20 {
21 double phi = (0.5+j)*dphi;
22 double mu_r = cos(phi)*sin(theta);
23 double eta_r= sin(phi)*sin(theta);
24 double xi_r = cos(theta);
25
26 double fval = (*F)(mu_r,eta_r,xi_r);
27
28 I_riemann += fval*sin(theta)*dtheta*dphi;
29 }//for j
30 }//for i
31
32 return I_riemann;
33}
34
35//###################################################################
36/**Performs a quadrature integral of a base functor using the
37 * supplied SQs.*/
40{
41 double I_quadrature = 0.0;
42 for (const auto& sq : initial_octant_SQs_)
43 for (int i=0; i<4; ++i)
44 {
45 double mu = sq.sub_sqr_points[i][2];
46 double theta = acos(mu);
47 double phi = acos(sq.sub_sqr_points[i][0]/sin(theta));
48
49 double mu_r = cos(phi)*sin(theta);
50 double eta_r= sin(phi)*sin(theta);
51 double xi_r = cos(theta);
52
53 double fval = (*F)(mu_r,eta_r,xi_r);
54
55 I_quadrature += sq.sub_sqr_weights[i]*fval;
56 }
57
58 return I_quadrature;
59}
60
61//###################################################################
62/**Performs a test integration of predefined cases.*/
64TestIntegration(int test_case, double ref_solution, int RiemannN)
65{
66 struct Case1 : public BaseFunctor
67 {double operator()(double mu, double eta, double xi) override
68 {return pow(mu,1.0)*pow(eta,1.0)*pow(xi,0.0);}};
69
70 struct Case2 : public BaseFunctor
71 {double operator()(double mu, double eta, double xi) override
72 {return pow(mu,3.0)*pow(eta,1.0)*pow(xi,1.0);}};
73
74 struct Case3 : public BaseFunctor
75 {double operator()(double mu, double eta, double xi) override
76 {return pow(mu,3.0)*pow(eta,6.0)*pow(xi,15.0);}};
77
78 struct SphericalHarmonicF : public BaseFunctor
79 {double operator()(double mu, double eta, double xi) override
80 {
81 double theta = acos(xi);
82 double phi = acos(mu/sin(theta));
83
84 return chi_math::Ylm(15,3,phi,theta);
85 }};
86
87 Case1 case1;
88 Case2 case2;
89 Case3 case3;
90 SphericalHarmonicF SphF;
91 BaseFunctor* F = &case1;
92 switch (test_case)
93 {
94 case 1: F = &case1;break;
95 case 2: F = &case2;break;
96 case 3: F = &case3;break;
97 case 4: F = &SphF;break;
98 default: F = &case1;
99 }
100
101 const int Nd = initial_octant_SQs_.size() * 4;
102 const int NR = RiemannN;
103
104 double h = 1.0/sqrt(8.0*Nd);
105 double I_riemann = ref_solution;
106 if (NR>0)
107 I_riemann = std::fabs(RiemannIntegral(F,NR));
108
109 double I_quadrature = std::fabs(QuadratureSSIntegral(F));
110
111 char buff0[200],buff1[200],buff2[200];
112 snprintf(buff0,200,"Riemann integral: %.20e\n",I_riemann);
113 snprintf(buff1,200,"Quadrature integral: %.10e\n",I_quadrature);
114 snprintf(buff2, 200, "Error_RQ%05d_%06d: %2d %f %e\n", Nd,Nd*8,
115 initial_level_, h, std::fabs((I_riemann - I_quadrature) / ref_solution));
116
117 Chi::log.Log() << buff0;
118 Chi::log.Log() << buff1;
119 Chi::log.Log() << buff2;
120}
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream Log(LOG_LVL level=LOG_0)
Definition: chi_log.cc:35
double RiemannIntegral(BaseFunctor *F, int Ni=20000)
void TestIntegration(int test_case, double ref_solution, int RiemannN=0)
double Ylm(unsigned int ell, int m, double varphi, double theta)