12 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"Getting Discrete Scattering Angles" <<
'\n';
14 for (
int m=0; m<mell.size(); m++)
16 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"Moment " << m <<
" " << mell[m];
19 std::vector<double> in_mell;
22 int N = in_mell.size()-1;
25 xn_wn_.resize(n, std::pair<double,double>(0.0, 0.0));
35 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"a,b,c:\n";
36 for(
int j=0; j<2*n; j++)
40 c[j] = (j+1.0)/(2*j+1);
48 MCA(in_mell, a, b, c);
52 for (
int i=0; i<n; i++)
54 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"i " <<
xn_wn_[i].first <<
" " <<
xn_wn_[i].second <<
'\n';
57 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"Done" <<
'\n';
66 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"MCA Start" <<
'\n';
68 int N = in_mell.size()-1;
71 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"N " << N <<
" n " << n <<
'\n';
72 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"alpha, beta" <<
'\n';
74 alpha_.resize(n + 1, 0.0);
75 beta_.resize(n + 1, 0.0);
77 std::vector<std::vector<double>> sigma(n+1,std::vector<double>(2*n+1,0.0));
80 for(
int ell=0; ell<2*n; ell++)
82 sigma[0][ell] = in_mell[ell];
85 alpha_[0] = a[0] + c[0] * sigma[0][1] / sigma[0][0];
86 beta_[0] = in_mell[0];
88 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) << 0 <<
" " << alpha_[0] <<
" " << beta_[0] <<
"\n";
91 for(
int k=1; k<n+1; k++)
93 for(
int ell=k; ell<(2*n-k+1); ell++)
95 double sigmakm2ell = 0.0;
103 sigmakm2ell = sigma[k-2][ell];
105 sigma[k][ell] = c[ell]*sigma[k-1][ell+1]
106 - (alpha_[k - 1] - a[ell]) * sigma[k - 1][ell]
107 - beta_[k - 1] * sigmakm2ell
108 +b[ell]*sigma[k-1][ell-1];
111 -c[k-1]*(sigma[k-1][k]/sigma[k-1][k-1])
112 +c[k]*(sigma[k][k+1]/sigma[k][k]);
113 beta_[k] = c[k - 1] * sigma[k][k] / sigma[k - 1][k - 1];
115 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) << k <<
" " << alpha_[k] <<
" " << beta_[k] <<
"\n";
118 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"Done" <<
'\n';
124 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"RootsOrtho Start" <<
'\n';
128 double adder = 0.999*2/std::max(N-1,1);
130 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"Check 1: Init guess" <<
'\n';
135 for(
int i=0; i<N; i++)
137 xn[i] = -0.999+i*adder;
138 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"x[" << i <<
"]=" << xn[i] <<
"\n";
143 Tvecdbl norm; norm.resize(N+1, 0.0);
144 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"Check 2 " << in_beta[0] <<
'\n';
145 norm[0] = in_beta[0];
146 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"Check 3a norms" <<
'\n';
147 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) << norm[0] <<
'\n';
148 for (
int i=1; i<(N+1); i++)
150 norm[i]=in_beta[i]*norm[i-1];
151 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) << norm[i] <<
'\n';
154 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"Check 3" <<
'\n';
156 for (
int k=0; k<N; k++)
163 double a = Ortho(N, xold, in_alpha, in_beta);
164 double b = dOrtho(N, xold, in_alpha, in_beta);
167 for (
int j=0; j<k; j++)
169 c = c+(1.0/(xold-xn[j]));
172 double xnew = xold-(a/(b-a*c));
173 if (std::isnan(xnew))
175 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"xnew " << i <<
" " << xnew <<
" y=" << a << std::endl;
179 double res = std::fabs(xnew-xold);
182 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"xnew " << i <<
" " << xnew <<
" y=" << a << std::endl;
194 for (
int i=0; i<N-1; i++)
196 for (
int j=0; j<N-i-1; j++)
200 double tempx = xn[j+1];
201 double tempw = wn[j+1];
210 for (
int i=0; i<N; i++)
214 for (
int k=0; k<N; k++)
216 wn[i] += Ortho(k, xn[i], in_alpha, in_beta)*
217 Ortho(k, xn[i], in_alpha, in_beta)/norm[k];
222 for (
int i=0; i<N; i++)
224 xn_wn_[i].first = xn[i];
225 xn_wn_[i].second = wn[i];
228 Chi::log.
Log(chi::ChiLog::LOG_LVL::LOG_0VERBOSE_2) <<
"Done" <<
'\n';
241 return (x-in_alpha[0]);
245 double Pn = (x-in_alpha[0]);
248 for (
int n=2; n<ell+1; n++)
251 Pnp1 = (x-in_alpha[ns])*Pn-in_beta[ns]*Pnm1;
263 double eps = 0.000001;
264 double y2 = Ortho(ell, x+eps, in_alpha, in_beta);
265 double y1 = Ortho(ell, x-eps, in_alpha, in_beta);
267 double m = (y2-y1)/2.0/eps;
std::vector< double > Tvecdbl
std::vector< std::pair< double, double > > AnglePairs
static void Exit(int error_code)
LogStream Log(LOG_LVL level=LOG_0)
void RootsOrtho(int &N, Tvecdbl &in_alpha, Tvecdbl &in_beta)
void MCA(Tvecdbl &in_mell, Tvecdbl &a, Tvecdbl &b, Tvecdbl &c)
double dOrtho(int ell, double x, Tvecdbl &in_alpha, Tvecdbl &in_beta)
AnglePairs & GetDiscreteScatAngles(Tvecdbl &mell)
double Ortho(int ell, double x, Tvecdbl &in_alpha, Tvecdbl &in_beta)