46 #include <Xyce_config.h>
50 #ifdef Xyce_DEBUG_DEVICE
69 #include <N_ERH_ErrorMgr.h>
74 #define BP0_BERN -3.742945958815751e+01
75 #define BP1_BERN -1.948848145621305e-02
76 #define BP2_BERN 1.230611609815494e-02
77 #define BP3_BERN 3.742945958815751e+01
78 #define BP4_BERN 7.451332191019408e+02
79 #define BP0_DBERN -4.117119704160766e+01
80 #define BP1_DBERN -3.742945958815751e+01
81 #define BP2_DBERN -1.848271746976161e-02
82 #define BP3_DBERN 8.806697697210611e-03
83 #define BP4_DBERN 3.742945958815751e+01
84 #define BP5_DBERN 7.451332191019408e+02
85 #define BP0_AUX1 -8.301056680276218e-03
86 #define BP1_AUX1 8.301056680276218e-03
87 #define BP0_DAUX1 -4.826242066078996e-03
88 #define BP1_DAUX1 4.826242066078996e-03
89 #define BP0_AUX2 -4.436141955583643e+01
90 #define BP1_AUX2 3.680808162809191e+01
91 #define BP2_AUX2 7.451332191019419e+02
92 #define BP0_DAUX2 -7.451332191019419e+02
93 #define BP1_DAUX2 -4.436141955583643e+01
94 #define BP2_DAUX2 3.680808162809191e+01
95 #define BP3_DAUX2 7.451332191019419e+02
96 #define BP0_MISC 7.097827128183643e+02
99 #define PRECISION 1.0e-15
100 #define MAX_ITERATIONS 100
103 #define MAXDOUBLE 1.797693E+308
120 double Bbp0a(
double x) {
return exp(x) - 1.0; }
121 double Bbp0b(
double x) {
return - 1.0; }
123 double Bbp1a(
double x) {
return x / (exp(x) - 1.0); }
124 double Bbp1b(
double x)
126 return 1.0 - x/2.0 * (1.0 - x/6.0 * (1.0 - x*x/60.0));
129 double Bbp2a(
double x)
131 return 1.0 - x/2.0 * (1.0 - x/6.0 * (1.0 - x*x/60.0));
134 double Bbp2b(
double x)
136 return x * exp(-x) / (1.0 - exp(-x));
139 double Bbp3a(
double x) {
return 1.0 - exp(-x); }
140 double Bbp3b(
double x) {
return 1.0; }
142 double Bbp4a(
double x) {
return x * exp(-x); }
143 double Bbp4b(
double x) {
return 0.0; }
145 double dBbp0a(
double x) {
return (1.0 - x) * exp(x) - 1.0; }
146 double dBbp0b(
double x) {
return -1.0; }
148 double dBbp2a(
double x)
150 return ((1.0 - x) * exp(x) - 1.0) / ((exp(x) - 1.0) * (exp(x) - 1.0));
153 double dBbp2b(
double x) {
return -0.5 + x/6.0 * (1.0 - x*x/30.0); }
155 double dBbp3a(
double x) {
return -0.5 + x/6.0 * (1.0 - x*x/30.0); }
156 double dBbp3b(
double x)
158 return (exp(-x)*(1.0 - x) - exp(-2.0 * x))/((1.0 - exp(-x))*(1.0 - exp(-x)));
161 double dBbp5a(
double x) {
return exp(-x) * (1.0 - x) - exp(-2.0 * x); }
162 double dBbp5b(
double x) {
return 0.0; }
164 double AUX1bp0a(
double x) {
return x / sinh(x); }
165 double AUX1bp0b(
double x) {
return 1.0 - x*x/6.0 * (1.0 - 7.0*x*x/60.0); }
167 double dAUX1bp0a(
double x)
169 return (sinh(x) - x*cosh(x)) / (sinh(x) * sinh(x));
172 double dAUX1bp0b(
double x) {
return -x/3.0 * (1.0 - 7*x*x/30.0); }
174 double AUX2bp0a(
double x) {
return 1.0; }
175 double AUX2bp0b(
double x) {
return 1.0 + exp(x); }
177 double AUX2bp1a(
double x) {
return 1.0 + exp(x); }
178 double AUX2bp1b(
double x) {
return exp(x); }
180 double AUX2bp2a(
double x) {
return exp(-x); }
181 double AUX2bp2b(
double x) {
return 0.0; }
183 double dAUX2bp0a(
double x) {
return exp(x); }
184 double dAUX2bp0b(
double x) {
return 0.0; }
237 #define Xyce_NEW_BERN_CALCULATION 1
238 #ifndef Xyce_NEW_BERN_CALCULATION
285 #ifdef Xyce_DEBUG_DEVICE
287 Xyce::dout() << Xyce::section_divider << std::endl;
288 Xyce::dout().width(21); Xyce::dout().precision(13); Xyce::dout().setf(std::ios::scientific);
289 Xyce::dout() << std::endl;
290 Xyce::dout() <<
"Bernouli function breakpoints: " <<endl;
291 Xyce::dout() <<
"bp0_AUX1 = " <<
bp0_AUX1 << std::endl;
292 Xyce::dout() <<
"bp1_AUX1 = " <<
bp1_AUX1 << std::endl;
293 Xyce::dout() <<
"bp0_DAUX1 = " <<
bp0_DAUX1 << std::endl;
294 Xyce::dout() <<
"bp1_DAUX1 = " <<
bp1_DAUX1 << std::endl;
296 Xyce::dout() <<
"bp0_AUX2 = " <<
bp0_AUX2 << std::endl;
297 Xyce::dout() <<
"bp1_AUX2 = " <<
bp1_AUX2 << std::endl;
298 Xyce::dout() <<
"bp2_AUX2 = " <<
bp2_AUX2 << std::endl;
299 Xyce::dout() <<
"bp0_DAUX2 = " <<
bp0_DAUX2 << std::endl;
300 Xyce::dout() <<
"bp1_DAUX2 = " <<
bp1_DAUX2 << std::endl;
301 Xyce::dout() <<
"bp2_DAUX2 = " <<
bp2_DAUX2 << std::endl;
302 Xyce::dout() <<
"bp3_DAUX2 = " <<
bp3_DAUX2 << std::endl;
303 Xyce::dout() <<
"bp0_MISC = " <<
bp0_MISC << std::endl;
304 Xyce::dout() << Xyce::section_divider << std::endl;
346 if (x < 0.0)
return(-1);
347 else if (x > 0.0)
return(+1);
362 double Fpos = func1(Xpos) - func2(Xpos);
363 double Fneg = func1(Xneg) - func2(Xneg);
364 double Xmid, Fmid, Xlast;
366 if (Fpos == 0.0)
return(Xpos);
367 else if (Fneg == 0.0)
return(Xneg);
368 else if ((Fpos > 0.0) && (Fneg < 0.0)) ;
369 else if ((Fpos < 0.0) && (Fneg > 0.0))
377 std::string msg =
"BernouliSupport::Bisection ";
378 msg +=
" Initial interval may not contain a root";
379 N_ERH_ErrorMgr::report( N_ERH_ErrorMgr::DEV_FATAL_0,msg);
385 Xmid = 0.5 * (Xpos + Xneg);
386 Fmid = func1(Xmid) - func2(Xmid);
387 if (Fmid < 0.0) Xneg = Xmid;
388 else if (Fmid > 0.0) Xpos = Xmid;
389 if (Xlast == Xmid)
return(Xmid);
391 }
while (Xneg != Xpos);
407 double slope, dx, x3, f3;
410 double x2 = 0.9 * x1;
411 double f1 = func1(x1) - func2(x1);
412 double f2 = func1(x2) - func2(x2);
418 slope = (f2 - f1) / (x2 - x1);
421 f3 = func1(x3) - func2(x3);
424 while ((fabs(f3) >= fabs(f2)) || (s3 != s2))
428 f3 = func1(x3) - func2(x3);
432 if (fabs(f2) <= 100.0 *
PRECISION)
return(x2);
433 std::string msg =
"BernouliSupport::Secant ";
434 msg +=
" method not converging.";
435 N_ERH_ErrorMgr::report( N_ERH_ErrorMgr::DEV_FATAL_0,msg);
464 if (x==0.0) test = 1.0;
465 else test = fabs(dx/x);
468 while (func1(x) != func2(x))
472 if (x==0.0) test = 1.0;
473 else test = fabs(dx/x);
476 while (func1(x) == func2(x))