Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Cubic Class Reference

#include <cubic.h>

Public Types

typedef std::complex< double > double_complex
 

Public Member Functions

double a (void) const
 
double b (void) const
 
double c (void) const
 
double d (void) const
 
double s_xzero (void) const
 
void put_a (double fa)
 
void put_b (double fb)
 
void put_c (double fc)
 
void put_d (double fd)
 
 Cubic (void)
 
 Cubic (double fa, double fb, double fc, double fd)
 
double y (double x) const
 
void find_zero (double_complex &z1, double_complex &z2, double_complex &z3) const
 
int find_real_zero (double z[3]) const
 
int find_maxmin (double xmm[2], double ymm[2], int s_mm[2]) const
 

Detailed Description

Definition at line 18 of file cubic.h.

Member Typedef Documentation

◆ double_complex

typedef std::complex<double> Cubic::double_complex

Definition at line 20 of file cubic.h.

Constructor & Destructor Documentation

◆ Cubic() [1/2]

Cubic::Cubic ( void  )
inline

Definition at line 45 of file cubic.h.

45: da(0.0), db(0.0), dc(0.0), dd(0.0), s_dxzero(0) {}

◆ Cubic() [2/2]

Cubic::Cubic ( double  fa,
double  fb,
double  fc,
double  fd 
)
inline

Definition at line 46 of file cubic.h.

47 : da(fa), db(fb), dc(fc), dd(fd), s_dxzero(0) {}

Member Function Documentation

◆ a()

double Cubic::a ( void  ) const
inline

Definition at line 21 of file cubic.h.

21{ return da; }

Referenced by find_maxmin(), and operator<<().

◆ b()

double Cubic::b ( void  ) const
inline

Definition at line 22 of file cubic.h.

22{ return db; }

Referenced by operator<<().

◆ c()

double Cubic::c ( void  ) const
inline

Definition at line 23 of file cubic.h.

23{ return dc; }

Referenced by operator<<().

◆ d()

double Cubic::d ( void  ) const
inline

Definition at line 24 of file cubic.h.

24{ return dd; }

Referenced by operator<<().

◆ find_maxmin()

int Cubic::find_maxmin ( double  xmm[2],
double  ymm[2],
int  s_mm[2] 
) const

Definition at line 122 of file cubic.cpp.

122 {
123 mfunname("int Cubic::find_maxmin(double xmm[2], double ymm[2], int s_mm[2]) "
124 "const");
125 double ap = 3 * da;
126 double bp = 2 * db;
127 double cp = dc;
128 Parabol par(ap, bp, cp);
129 s_mm[0] = 0;
130 s_mm[1] = 0;
131 int qz = par.find_zero(xmm);
132 if (qz == 1) {
133 s_mm[0] = 0;
134 }
135 if (qz == 2) {
136 if (a() > 0) {
137 s_mm[0] = 1;
138 s_mm[1] = -1;
139 } else {
140 s_mm[0] = -1;
141 s_mm[1] = 1;
142 }
143 }
144 for (int n = 0; n < qz; ++n) {
145 ymm[n] = y(xmm[n]);
146 }
147 return qz;
148}
#define mfunname(string)
Definition: FunNameStack.h:67
double y(double x) const
Definition: cubic.h:49
double a(void) const
Definition: cubic.h:21

Referenced by operator<<().

◆ find_real_zero()

int Cubic::find_real_zero ( double  z[3]) const

Definition at line 76 of file cubic.cpp.

76 {
77 mfunname("int Cubic::find_real_zero(double z[3]) const");
81 find_zero(zc1, zc2, zc3);
82 double thresh = 10.0 * DBL_MIN;
83 int q = 0;
84 if (fabs(zc1.imag()) < thresh ||
85 (zc1.real() != 0.0 && fabs(zc1.imag() / zc1.real()) < thresh)) {
86 z[q] = zc1.real();
87 q++;
88 }
89 if (fabs(zc2.imag()) < thresh ||
90 (zc2.real() != 0.0 && fabs(zc2.imag() / zc2.real()) < thresh)) {
91 z[q] = zc2.real();
92 q++;
93 }
94 if (fabs(zc3.imag()) < thresh ||
95 (zc3.real() != 0.0 && fabs(zc3.imag() / zc3.real()) < thresh)) {
96 z[q] = zc3.real();
97 q++;
98 }
99 int n1 = 0, n2 = 0;
100 for (n1 = 0; n1 < q - 1; n1++) {
101 for (n2 = n1; n2 < q; n2++) {
102 if (z[n1] > z[n2]) {
103 double t = z[n1];
104 z[n1] = z[n2];
105 z[n2] = t;
106 }
107 }
108 }
109 for (n1 = 0; n1 < q - 1; n1++) {
110 if ((fabs(z[n1]) < thresh && fabs(z[n2]) < thresh) ||
111 fabs((z[n1] - z[n1 + 1]) / (z[n1] + z[n1 + 1])) < thresh) {
112 for (n2 = n1 + 1; n2 < q - 1; n2++) {
113 z[n2] = z[n2 + 1];
114 }
115 q--;
116 n1--;
117 }
118 }
119 return q;
120}
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:616
void find_zero(double_complex &z1, double_complex &z2, double_complex &z3) const
Definition: cubic.cpp:25
std::complex< double > double_complex
Definition: cubic.h:20

Referenced by operator<<().

◆ find_zero()

void Cubic::find_zero ( double_complex z1,
double_complex z2,
double_complex z3 
) const

Definition at line 25 of file cubic.cpp.

26 {
27 mfunname("void Cubic::find_zero(double_complex &z1, double_complex &z2, "
28 "double_complex &z3) const");
30 if (s_dxzero == 0) {
31 check_econd11a(da, == 0.0, "this is not cubic polynomial!", mcerr);
32 double a2 = db / da;
33 double a1 = dc / da;
34 double a0 = dd / da;
35 double Q = (3.0 * a1 - a2 * a2) / 9.0;
36 double R = (9.0 * a2 * a1 - 27.0 * a0 - 2.0 * a2 * a2 * a2) / 54.0;
37 double D = Q * Q * Q + R * R;
38 double sD = sqrt(fabs(D));
41 if (D >= 0.0) {
42 double t = R + sD;
43 if (t > 0.0) {
44 S = pow(t, 1 / 3.0);
45 } else if (t < 0.0) {
46 S = -pow(-t, 1 / 3.0);
47 } else {
48 S = 0.0;
49 }
50 t = R - sD;
51 if (t > 0.0) {
52 T = pow(t, 1 / 3.0);
53 } else if (t < 0.0) {
54 T = -pow(-t, 1 / 3.0);
55 } else {
56 T = 0.0;
57 }
58 } else {
59 S = pow(R + iu * sD, 1 / 3.0);
60 T = pow(R - iu * sD, 1 / 3.0);
61 }
62 z1 = -a2 / 3.0 + (S + T);
63 z2 = -a2 / 3.0 - (S + T) / 2.0 + 0.5 * iu * sqrt(3.0) * (S - T);
64 z3 = -a2 / 3.0 - (S + T) / 2.0 - 0.5 * iu * sqrt(3.0) * (S - T);
65 t.dz1 = z1;
66 t.dz2 = z2;
67 t.dz3 = z3;
68 t.s_dxzero = 3;
69 } else {
70 z1 = dz1;
71 z2 = dz2;
72 z3 = dz3;
73 }
74}
DoubleAc pow(const DoubleAc &f, double p)
Definition: DoubleAc.cpp:336
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:313
#define check_econd11a(a, signb, add, stream)
Definition: FunNameStack.h:395
Definition: cubic.h:18
#define convmut(type)
#define mcerr
Definition: prstream.h:135

Referenced by find_real_zero(), and operator<<().

◆ put_a()

void Cubic::put_a ( double  fa)
inline

Definition at line 28 of file cubic.h.

28 {
29 da = fa;
30 s_dxzero = 0;
31 }

◆ put_b()

void Cubic::put_b ( double  fb)
inline

Definition at line 32 of file cubic.h.

32 {
33 db = fb;
34 s_dxzero = 0;
35 }

◆ put_c()

void Cubic::put_c ( double  fc)
inline

Definition at line 36 of file cubic.h.

36 {
37 dc = fc;
38 s_dxzero = 0;
39 }

◆ put_d()

void Cubic::put_d ( double  fd)
inline

Definition at line 40 of file cubic.h.

40 {
41 dd = fd;
42 s_dxzero = 0;
43 }

◆ s_xzero()

double Cubic::s_xzero ( void  ) const
inline

Definition at line 25 of file cubic.h.

25 {
26 return s_dxzero;
27 } // for debug

Referenced by operator<<().

◆ y()

double Cubic::y ( double  x) const
inline

Definition at line 49 of file cubic.h.

49 {
50 return da * x * x * x + db * x * x + dc * x + dd;
51 }

Referenced by find_maxmin().


The documentation for this class was generated from the following files: