CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PadeTableODE.cc
Go to the documentation of this file.
1 #include <cassert>
3 
5 
6 PadeTableODE::PadeTableODE(const unsigned padeRow, const unsigned padeColumn)
7  : row_(padeRow),
8  col_(padeColumn)
9 {
10  if (row_ > 2U) throw cms::Exception(
11  "In PadeTableODE constructor: Pade table row number out of range");
12  if (col_ > 3U) throw cms::Exception(
13  "In PadeTableODE constructor: Pade table column number out of range");
14 }
15 
16 void PadeTableODE::calculate(const double tau, const double currentIn,
17  const double dIdt, const double d2Id2t,
18  const double* x, const unsigned lenX,
19  const unsigned firstNode, double* derivative) const
20 {
21  // Check input sanity
22  if (lenX < firstNode + col_) throw cms::Exception(
23  "In PadeTableODE::calculate: insufficient number of variables");
24  if (tau <= 0.0) throw cms::Exception(
25  "In PadeTableODE::calculate: delay time is not positive");
26  if (col_) assert(x);
27  assert(derivative);
28 
29  switch (col_)
30  {
31  case 0U:
32  // Special case: no ODE to solve
33  derivative[firstNode] = 0.0;
34  switch (row_)
35  {
36  case 2U:
37  derivative[firstNode] += 0.5*tau*tau*d2Id2t;
38  case 1U:
39  derivative[firstNode] -= tau*dIdt;
40  case 0U:
41  derivative[firstNode] += currentIn;
42  break;
43 
44  default:
45  assert(0);
46  }
47  break;
48 
49  case 1U:
50  // First order ODE to solve
51  switch (row_)
52  {
53  case 0U:
54  derivative[firstNode] = (currentIn - x[firstNode])/tau;
55  break;
56 
57  case 1U:
58  derivative[firstNode] = 2.0*(currentIn - x[firstNode])/tau - dIdt;
59  break;
60 
61  case 2U:
62  derivative[firstNode] = 3.0*(currentIn - x[firstNode])/tau -
63  2.0*dIdt + 0.5*tau*d2Id2t;
64  break;
65 
66  default:
67  assert(0);
68  }
69  break;
70 
71  case 2U:
72  // Second order ODE to solve
73  derivative[firstNode] = x[firstNode+1];
74  switch (row_)
75  {
76  case 0U:
77  derivative[firstNode+1] =
78  2.0*(currentIn-x[firstNode]-tau*x[firstNode+1])/tau/tau;
79  break;
80 
81  case 1U:
82  derivative[firstNode+1] = (6.0*(currentIn - x[firstNode]) -
83  2.0*tau*dIdt -
84  4.0*tau*x[firstNode+1])/tau/tau;
85  break;
86 
87  case 2U:
88  derivative[firstNode+1] =
89  12.0*(currentIn - x[firstNode])/tau/tau -
90  6.0*(x[firstNode+1] + dIdt)/tau + d2Id2t;
91  break;
92 
93  default:
94  assert(0);
95  }
96  break;
97 
98  case 3U:
99  // Third order ODE to solve
100  derivative[firstNode] = x[firstNode+1];
101  derivative[firstNode+1] = x[firstNode+2];
102  switch (row_)
103  {
104  case 0U:
105  derivative[firstNode+2] =
106  6.0*(currentIn - x[firstNode] - tau*x[firstNode+1] -
107  0.5*tau*tau*x[firstNode+2])/tau/tau/tau;
108  break;
109 
110  case 1U:
111  derivative[firstNode+2] = 24.0/tau/tau/tau*(
112  currentIn - x[firstNode] - 0.25*tau*dIdt -
113  0.75*tau*x[firstNode+1] - 0.25*tau*tau*x[firstNode+2]);
114  break;
115 
116  case 2U:
117  derivative[firstNode+2] = 60.0/tau/tau/tau*(
118  currentIn - x[firstNode] - 0.4*tau*dIdt +
119  0.05*tau*tau*d2Id2t - 0.6*tau*x[firstNode+1] -
120  0.15*tau*tau*x[firstNode+2]);
121  break;
122 
123  default:
124  assert(0);
125  }
126  break;
127 
128  default:
129  //
130  // In principle, it is possible to proceed a bit further, but
131  // we will soon encounter difficulties. For example, row 0 and
132  // column 4 is going to generate a 4th order differential
133  // equation for which all roots of the characteristic equation
134  // still have negative real parts. The most "inconvenient" pair
135  // of roots there is (-0.270556 +- 2.50478 I) which leads
136  // to oscillations with damping. The characteristic equation
137  // of 5th and higher order ODEs are going to have roots with
138  // positive real parts. Unless additional damping is
139  // purposefully introduced into the system, numerical
140  // solutions of such equations will just blow up.
141  //
142  assert(0);
143  }
144 }
145 
146 void PadeTableODE::setParameters(const double* /* pars */, const unsigned nPars)
147 {
148  assert(nPars == 0U);
149 }
Derivative< X, A >::type derivative(const A &_)
Definition: Derivative.h:18
assert(m_qm.get())
void setParameters(const double *pars, unsigned nPars)
T x() const
Cartesian x coordinate.
PadeTableODE(unsigned padeRow, unsigned padeColumn)
Definition: PadeTableODE.cc:6
unsigned col_
Definition: PadeTableODE.h:28
void calculate(double tau, double inputCurrent, double dIdt, double d2Id2t, const double *x, unsigned lenX, unsigned firstNode, double *derivative) const
Definition: PadeTableODE.cc:16
unsigned row_
Definition: PadeTableODE.h:27