10 vector<double> (*func)(
const vector<double>&,
ThermalModel*),
12 const double TOLF = 1.0e-8, EPS = 1.0e-12;
13 const int MAXITS = 200;
14 vector<double>
h = xin, xh1 = xin, xh2 = xin;
15 for (
unsigned int i = 0;
i < xin.size(); ++
i) {
16 h[
i] = EPS * abs(
h[
i]);
17 if (
h[
i] == 0.0)
h[
i] = EPS;
19 xh1[
i] = xin[
i] +
h[
i];
21 xh2[
i] = xin[
i] +
h[
i];
23 vector<double> r1 = func(xin, ThM), r21 = func(xh1, ThM),
25 if (
fabs(r1[0]) < TOLF &&
fabs(r1[1]) < TOLF)
return;
27 J[0][0] = (r21[0] - r1[0]) /
h[0];
28 J[0][1] = (r22[0] - r1[0]) /
h[1];
29 J[1][0] = (r21[1] - r1[1]) /
h[0];
30 J[1][1] = (r22[1] - r1[1]) /
h[1];
32 double det = J[0][0] * J[1][1] - J[0][1] * J[1][0];
35 if (det == 0.0)
throw(
"singular Jacobian in broyden22");
36 Jinv[0][0] = J[1][1] / det;
37 Jinv[0][1] = -J[0][1] / det;
38 Jinv[1][0] = -J[1][0] / det;
39 Jinv[1][1] = J[0][0] / det;
40 vector<double> xold = xin;
41 vector<double> rold = r1;
42 vector<double> rprevten = r1;
43 for (
int iter = 1; iter <= MAXITS; ++iter) {
45 xin[0] = xold[0] - Jinv[0][0] * rold[0] - Jinv[0][1] * rold[1];
46 xin[1] = xold[1] - Jinv[1][0] * rold[0] - Jinv[1][1] * rold[1];
48 if (
fabs(r1[0]) < TOLF &&
fabs(r1[1]) < TOLF) {
60 DF[0] = (r1[0] - rold[0]);
61 DF[1] = (r1[1] - rold[1]);
68 JF[0] = Jinv[0][0] * DF[0] + Jinv[0][1] * DF[1];
69 JF[1] = Jinv[1][0] * DF[0] + Jinv[1][1] * DF[1];
70 dx[0] = xin[0] - xold[0];
71 dx[1] = xin[1] - xold[1];
72 double znam = dx[0] * JF[0] + dx[1] * JF[1];
73 if (znam == 0.0)
throw(
"singular Jacobian in broyden22");
75 JF[0] = dx[0] - JF[0];
76 JF[1] = dx[1] - JF[1];
77 xJ[0] = dx[0] * Jinv[0][0] + dx[1] * Jinv[1][0];
78 xJ[1] = dx[0] * Jinv[0][1] + dx[1] * Jinv[1][1];
79 Jinv[0][0] = Jinv[0][0] + JF[0] * xJ[0] / znam;
80 Jinv[0][1] = Jinv[0][1] + JF[0] * xJ[1] / znam;
81 Jinv[1][0] = Jinv[1][0] + JF[1] * xJ[0] / znam;
82 Jinv[1][1] = Jinv[1][1] + JF[1] * xJ[1] / znam;
88 throw(
"exceed MAXITS in broyden");
93 vector<double> ret(2);
112 if (
fabs(Parameters.muB) < 1e-6) {
113 Parameters.muS = Parameters.muQ = 0.;
116 vector<double> x2(2), xinit(2);
117 xinit[0] = x2[0] = Parameters.muQ;
118 xinit[1] = x2[1] = Parameters.muS;
120 int iter = 0, iterMAX = 10;
121 while (iter < iterMAX) {
125 if (
fabs(Parameters.muB / Parameters.muS) > 1.
126 &&
fabs(Parameters.muB / Parameters.muQ) > 1.)
128 xinit[0] = x2[0] = xinit[0] / 10.;
129 xinit[1] = x2[1] = xinit[1] / 10.;