14 vector<double> (*func)(
const vector<double>&)) {
15 const double TOLF = 1.0e-8, EPS = 1.0e-8;
16 const int MAXITS = 200;
17 vector<double>
h = xin, xh1 = xin, xh2 = xin;
18 for (
unsigned int i = 0;
i < xin.size(); ++
i) {
20 if (
h[
i] == 0.0)
h[
i] = EPS;
22 xh1[
i] = xin[
i] +
h[
i];
24 xh2[
i] = xin[
i] +
h[
i];
26 vector<double> r1 = func(xin), r21 = func(xh1), r22 = func(xh2);
27 if (
fabs(r1[0]) < TOLF &&
fabs(r1[1]) < TOLF)
return;
29 J[0][0] = (r21[0] - r1[0]) /
h[0];
30 J[0][1] = (r22[0] - r1[0]) /
h[1];
31 J[1][0] = (r21[1] - r1[1]) /
h[0];
32 J[1][1] = (r22[1] - r1[1]) /
h[1];
34 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) {
44 xin[0] = xold[0] - Jinv[0][0] * rold[0] - Jinv[0][1] * rold[1];
45 xin[1] = xold[1] - Jinv[1][0] * rold[0] - Jinv[1][1] * rold[1];
47 if (
fabs(r1[0]) < TOLF &&
fabs(r1[1]) < TOLF)
return;
49 if (
fabs(r1[0] / rprevten[0]) > 1e-2
50 &&
fabs(r1[1] / rprevten[1]) > 1e-2)
51 throw(
"broyden is stuck");
57 DF[0] = (r1[0] - rold[0]);
58 DF[1] = (r1[1] - rold[1]);
59 JF[0] = Jinv[0][0] * DF[0] + Jinv[0][1] * DF[1];
60 JF[1] = Jinv[1][0] * DF[0] + Jinv[1][1] * DF[1];
61 dx[0] = xin[0] - xold[0];
62 dx[1] = xin[1] - xold[1];
63 double znam = dx[0] * JF[0] + dx[1] * JF[1];
64 if (znam == 0.0)
throw(
"singular Jacobian in broyden22");
66 JF[0] = dx[0] - JF[0];
67 JF[1] = dx[1] - JF[1];
68 xJ[0] = dx[0] * Jinv[0][0] + dx[1] * Jinv[1][0];
69 xJ[1] = dx[0] * Jinv[0][1] + dx[1] * Jinv[1][1];
70 Jinv[0][0] = Jinv[0][0] + JF[0] * xJ[0] / znam;
71 Jinv[0][1] = Jinv[0][1] + JF[0] * xJ[1] / znam;
72 Jinv[1][0] = Jinv[1][0] + JF[1] * xJ[0] / znam;
73 Jinv[1][1] = Jinv[1][1] + JF[1] * xJ[1] / znam;
77 throw(
"exceed MAXITS in broyden");
81 vector<double> ret(2);
101 if (
fabs(Parameters.muB) < 1e-6) {
102 Parameters.muS = Parameters.muQ = 0.;
105 vector<double> x22(2);
106 x22[0] = Parameters.muQ;
107 x22[1] = Parameters.muS;
108 vector<double> x2(2), xinit(2);
109 xinit[0] = x2[0] = Parameters.muQ;
110 xinit[1] = x2[1] = Parameters.muS;
112 int iter = 0, iterMAX = 10;
113 while (iter < iterMAX) {
117 if (
fabs(Parameters.muB / Parameters.muS) > 1.
118 &&
fabs(Parameters.muB / Parameters.muQ) > 1.)
120 xinit[0] = x2[0] = xinit[0] / 10.;
121 xinit[1] = x2[1] = xinit[1] / 10.;
136 for (
unsigned int i = 0;
i < TPS->fParticles.size(); ++
i) {
138 vo = 4. * 4. *
xMath::Pi() / 3. * RHad * RHad * RHad;
139 double dMu = -UVdW(n, Parameters.T, vo);
140 ret += TPS->fParticles[
i].CalculateDensity(Parameters.T,
152 vo = 4. * 4. *
xMath::Pi() / 3. * RHad * RHad * RHad;
153 double dMu = -UVdW(n, Parameters.T, vo);
154 ret += fHag.CalculateDensity(Parameters.T, Parameters.muB, 0, dMu);
162 double vo = 4. * 4. *
xMath::Pi() / 3. * RHad * RHad * RHad;
163 if (fDensity * vo > 1.) fDensity = 1. / vo / 2.;
164 const double TOLF = 1.0e-8, EPS = 1.0e-8;
165 const int MAXITS = 200;
169 if (
h == 0.0)
h = EPS;
171 double r1 =
x - Density(
x);
172 double r2 = xh - Density(xh);
173 double Jinv =
h / (r1 - r2);
174 double xold =
x, rold = r1;
175 for (
int iter = 1; iter <= MAXITS; ++iter) {
176 x = xold - Jinv * rold;
177 if (fMode == 0 &&
x * vo > 1.)
178 x = 1. / vo * (rand() /
static_cast<double>(RAND_MAX));
179 if (fMode == 1 &&
x * vo > 0.5)
180 x = 0.5 / vo * (rand() /
static_cast<double>(RAND_MAX));
182 Jinv = (
x - xold) / (r1 - rold);
183 if (
fabs(r1) < TOLF)
break;
189 for (
unsigned int i = 0;
i < TPS->fParticles.size(); ++
i) {
191 vo = 4. * 4. *
xMath::Pi() / 3. * RHad * RHad * RHad;
192 double dMu = -UVdW(fDensity, Parameters.T, vo);
193 densitiesid[
i] = TPS->fParticles[
i].CalculateDensity(Parameters.T,
205 vo = 4. * 4. *
xMath::Pi() / 3. * RHad * RHad * RHad;
206 double dMu = -UVdW(fDensity, Parameters.T, vo);
208 fHag.CalculateDensity(Parameters.T, Parameters.muB, 0, dMu);
211 for (
unsigned int i = 0;
i < TPS->fParticles.size(); ++
i)
212 densities[
i] = densitiesid[
i];
213 for (
int i = 0; i < static_cast<int>(TPS->fParticles.size()); ++
i) {
215 densitiestotal[
i] = densities[
i];
217 j < static_cast<int>(TPS->fParticles[
i].ResonanceBR.size());
219 if (
i != TPS->fParticles[
i].ResonanceBR[j].second)
221 TPS->fParticles[
i].ResonanceBR[j].first
222 * densities[TPS->fParticles[
i].ResonanceBR[j].second];
229 if (!fCalculated) CalculateDensities();
231 double TotalDensity = 0.;
232 for (
unsigned int i = 0;
i < TPS->fParticles.size(); ++
i) {
233 TotalDensity += densities[
i];
234 ret +=
sqrt(TPS->fParticles[
i].fMass)
241 * 5.06 / TotalDensity;