50 using namespace transient;
56 nr_double_t * coefficients,
57 nr_double_t * delta) {
59 tmatrix<nr_double_t>
A (order + 1);
60 tvector<nr_double_t>
x (order + 1);
61 tvector<nr_double_t> b (order + 1);
62 eqnsys<nr_double_t> e;
71 for (i = 0; i < order + 1; i++) b.set (i, 1);
72 for (i = 1; i < order + 1; i++) {
76 for (c = 1; c <= order - 1; c++) {
77 nr_double_t entry = -
c;
78 for (r = 1; r <= order; r++) {
79 A.set (r, c + 1, entry);
83 e.passEquationSys (&A, &x, &b);
89 for (i = 0; i < x.getRows (); i++) {
94 nr_double_t k = x.get (0);
95 coefficients[
COEFF_G] = 1 / delta[0] / k;
96 for (i = 1; i <= order; i++) {
97 coefficients[
i] = - 1 / delta[0] / k * x.get (i);
102 b.set (1, -1 / delta[0]);
104 for (c = 0; c < order + 1; c++) A.set (0, c, 1);
106 for (f = 0, c = 0; c < order; c++) {
108 for (a = 1, r = 0; r < order; r++) {
110 A.set (r + 1, c + 1, a);
113 e.passEquationSys (&A, &x, &b);
115 for (r = 0; r <= order; r++) coefficients[r] = x.get (r);
120 coefficients[
COEFF_G] = 1 / delta[0];
121 coefficients[1] = - 1 / delta[0];
124 coefficients[
COEFF_G] = 2 / delta[0];
125 coefficients[1] = - 2 / delta[0];
131 for (i = 0; i < order + 1; i++) b.set (i, 1);
132 for (i = 1; i < order + 1; i++) {
137 for (c = 1; c <= order - 2; c++) {
138 nr_double_t entry = -
c;
139 for (r = 2; r <= order; r++) {
140 A.set (r, c + 2, r * entry);
144 e.passEquationSys (&A, &x, &b);
150 for (i = 0; i < x.getRows (); i++) {
155 nr_double_t k = x.get (1);
156 coefficients[
COEFF_G] = 1 / delta[0] / k;
157 coefficients[1] = -x.get (0) / delta[0] / k;
158 for (i = 2; i <= order; i++) {
159 coefficients[
i] = -x.get (i) / k;
170 nr_double_t * coefficients,
171 nr_double_t * delta) {
173 tmatrix<nr_double_t>
A (order + 1);
174 tvector<nr_double_t>
x (order + 1);
175 tvector<nr_double_t> b (order + 1);
176 eqnsys<nr_double_t> e;
186 for (c = 0; c < order + 1; c++) A.set (0, c, 1);
188 for (f = 0, c = 0; c < order + 1; c++) {
190 for (a = 1, r = 0; r < order; r++) {
195 e.passEquationSys (&A, &x, &b);
197 for (r = 0; r <= order; r++) coefficients[r] = x.get (r);
204 for (i = 0; i < order + 1; i++) b.set (i, 1);
205 for (i = 1; i < order + 1; i++) A.set (1, i, 1);
207 for (c = 1; c <= order - 1; c++) {
208 nr_double_t entry = -
c;
209 for (r = 2; r <= order; r++) {
210 A.set (r, c + 1, r * entry);
214 e.passEquationSys (&A, &x, &b);
220 for (i = 0; i < x.getRows (); i++) {
225 coefficients[
COEFF_G] = x.get (0);
226 for (i = 1; i <= order; i++) {
227 coefficients[
i] = x.get (i) * delta[0];
231 nr_double_t f = - delta[0] / (2 * delta[1]);
233 coefficients[1] = (1 - f) * delta[0];
234 coefficients[2] = f * delta[0];
241 coefficients[1] = delta[0];
249 nr_double_t * coeff = c->getCoefficients ();
255 nr_double_t& geq, nr_double_t& ceq) {
256 nr_double_t * coeff = c->getCoefficients ();
257 int cstate = qstate + 1;
260 ceq = c->getState (qstate, 1) * coeff[1];
261 cur = c->getState (qstate) * coeff[
COEFF_G] + ceq;
262 c->setState (cstate, cur);
267 nr_double_t& geq, nr_double_t& ceq) {
268 nr_double_t * coeff = c->getCoefficients ();
269 int cstate = qstate + 1;
272 ceq = c->getState (qstate, 1) * coeff[1] - c->getState (cstate, 1);
273 cur = c->getState (qstate) * coeff[
COEFF_G] + ceq;
274 c->setState (cstate, cur);
279 nr_double_t& geq, nr_double_t& ceq) {
280 nr_double_t * coeff = c->getCoefficients ();
281 int i, cstate = qstate + 1;
284 for (ceq = 0, i = 1; i <= c->getOrder (); i++) {
285 ceq += c->getState (qstate, i) * coeff[
i];
287 cur = c->getState (qstate) * coeff[
COEFF_G] + ceq;
288 c->setState (cstate, cur);
293 nr_double_t& geq, nr_double_t& ceq) {
294 nr_double_t * coeff = c->getCoefficients ();
295 int i, cstate = qstate + 1;
298 ceq = c->getState (qstate, 1) * coeff[1];
299 for (i = 2; i <= c->getOrder (); i++) {
300 ceq += c->getState (cstate, i - 1) * coeff[
i];
302 cur = c->getState (qstate) * coeff[
COEFF_G] + ceq;
303 c->setState (cstate, cur);
323 c->setIntegration (NULL);
332 if (!strcmp (Method,
"Gear")) {
333 if (MaxOrder > 6) MaxOrder = 6;
334 if (MaxOrder < 1) MaxOrder = 1;
337 else if (!strcmp (Method,
"Trapezoidal")) {
341 else if (!strcmp (Method,
"Euler")) {
345 else if (!strcmp (Method,
"AdamsMoulton")) {
346 if (MaxOrder > 6) MaxOrder = 6;
347 if (MaxOrder < 1) MaxOrder = 1;
350 else if (!strcmp (Method,
"AdamsBashford")) {
351 if (MaxOrder > 6) MaxOrder = 6;
352 if (MaxOrder < 1) MaxOrder = 1;
363 switch (corrMethod) {
377 predOrder = corrOrder;
384 int integratorType[6];
385 nr_double_t corrErrorConstant[6];
386 nr_double_t predErrorConstant[6];
403 { -1.0/2, -2.0/9, -3.0/22, -12.0/125, -10.0/137, -20.0/343 },
404 { +1.0, +1.0, +1.0, +1.0, +1.0, +1.0 }
410 { -1.0/2, -1.0/12, -1.0/24, -19.0/720, -3.0/160, -863.0/60480 },
411 { +1.0/2, +1.0/12, +1.0/24, +19.0/720, +3.0/160, +863.0/60480 }
417 { -1.0/2, -5.0/12, -3.0/8, -251.0/720, -95.0/288, -19087.0/60480 },
418 { +1.0/2, +5.0/12, +3.0/8, +251.0/720, +95.0/288, +19087.0/60480 }
nr_double_t getCorrectorError(int, int)
int correctorType(char *, int &)
void calcCorrectorCoeff(int, int, nr_double_t *, nr_double_t *)
void getConductance(integrator *, nr_double_t, nr_double_t &)
void setIntegrationMethod(circuit *, int)
nr_double_t getPredictorError(int, int)
void calcPredictorCoeff(int, int, nr_double_t *, nr_double_t *)
void integrateEuler(integrator *, int, nr_double_t, nr_double_t &, nr_double_t &)
int predictorType(int, int, int &)
The circuit class header file.
void integrateMoulton(integrator *, int, nr_double_t, nr_double_t &, nr_double_t &)
nr_double_t corrErrorConstant[6]
static struct integration_types_t integration_types[]
nr_double_t predErrorConstant[6]
void integrateGear(integrator *, int, nr_double_t, nr_double_t &, nr_double_t &)
void logprint(int level, const char *format,...)
void integrateBilinear(integrator *, int, nr_double_t, nr_double_t &, nr_double_t &)