Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
cubic.h
Go to the documentation of this file.
1#ifndef CUBIC_H
2#define CUBIC_H
3
4#include <complex>
5
6/*
7Copyright (c) 2005 Igor B. Smirnov
8
9The file can be used, copied, modified, and distributed
10according to the terms of GNU Lesser General Public License version 2.1
11as published by the Free Software Foundation,
12and provided that the above copyright notice, this permission notice,
13and notices about any modifications of the original text
14appear in all copies and in supporting documentation.
15The file is provided "as is" without express or implied warranty.
16*/
17
18namespace Heed {
19
20/// Find solution to cubic equation.
21
22class Cubic {
23 public:
24 typedef std::complex<double> double_complex;
25 double a() const { return da; }
26 double b() const { return db; }
27 double c() const { return dc; }
28 double d() const { return dd; }
29 double s_xzero() const { return s_dxzero; } // for debug
30 void put_a(double fa) {
31 da = fa;
32 s_dxzero = 0;
33 }
34 void put_b(double fb) {
35 db = fb;
36 s_dxzero = 0;
37 }
38 void put_c(double fc) {
39 dc = fc;
40 s_dxzero = 0;
41 }
42 void put_d(double fd) {
43 dd = fd;
44 s_dxzero = 0;
45 }
46
47 Cubic() : da(0.0), db(0.0), dc(0.0), dd(0.0), s_dxzero(0) {}
48 Cubic(double fa, double fb, double fc, double fd)
49 : da(fa), db(fb), dc(fc), dd(fd), s_dxzero(0) {}
50
51 double y(double x) const {
52 return da * x * x * x + db * x * x + dc * x + dd;
53 }
54
56 double_complex& z3) const;
57 // They are not ordered and analysed
58 int find_real_zero(double z[3]) const;
59 // returns number of solutions
60 // Analysed and ordered real solutions
61
62 // returns number of solutions
63 // first is the least.
64 int find_maxmin(double xmm[2], double ymm[2],
65 int s_mm[2]) const; // 1 - maximum, -1 - minimum, 0 - non
66 private:
67 static const double_complex iu;
68 double da, db, dc, dd;
69 mutable int s_dxzero;
70 mutable double_complex dz1;
71 mutable double_complex dz2;
72 mutable double_complex dz3;
73};
74
75std::ostream& operator<<(std::ostream& file, const Cubic& f);
76}
77
78#endif
Find solution to cubic equation.
Definition: cubic.h:22
void find_zero(double_complex &z1, double_complex &z2, double_complex &z3) const
Definition: cubic.cpp:23
double s_xzero() const
Definition: cubic.h:29
void put_b(double fb)
Definition: cubic.h:34
void put_a(double fa)
Definition: cubic.h:30
Cubic(double fa, double fb, double fc, double fd)
Definition: cubic.h:48
std::complex< double > double_complex
Definition: cubic.h:24
Cubic()
Definition: cubic.h:47
double a() const
Definition: cubic.h:25
double b() const
Definition: cubic.h:26
double y(double x) const
Definition: cubic.h:51
int find_maxmin(double xmm[2], double ymm[2], int s_mm[2]) const
Definition: cubic.cpp:121
void put_d(double fd)
Definition: cubic.h:42
void put_c(double fc)
Definition: cubic.h:38
double c() const
Definition: cubic.h:27
int find_real_zero(double z[3]) const
Definition: cubic.cpp:74
double d() const
Definition: cubic.h:28
Definition: BGMesh.cpp:6
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
Definition: BGMesh.cpp:37