Remove unused variable debarr.

Add another example.
This commit is contained in:
Holger Vogt 2022-11-29 23:23:42 +01:00
parent 45574cecb2
commit e28d3feee0
3 changed files with 33 additions and 17 deletions

View File

@ -1,4 +1,4 @@
dd test 2 with .func
ddt test 2 with .func
V1 1 0 dc 0 pulse 0 2 0 1 1 1 4

View File

@ -0,0 +1,17 @@
ddt test 3 with RC
V1 1 0 dc 0 pulse 0 2 1u 1n 1n 100u 200u
R1 1 2 1k
C1 2 0 1u
B2 22 0 v = ddt(V(2))/1000
.tran 100n 3m
.control
run
plot v(2) v(22)
*print v(22)
.endc
.end

View File

@ -413,15 +413,18 @@ PTnint(double arg1)
return nearbyint(arg1);
}
/* Calculate the derivative during a transient simulation.
If time == 0, return 0.
If not transient sim, return 0.
The derivative is then (y2-y1)/(t2-t1).
*/
double
PTddt(double arg, void* data)
{
struct ddtdata { int n; double* vals; } *thing = (struct ddtdata*)data;
double y, time;
double debarr[7];
int i;
CKTcircuit* ckt = ft_curckt->ci_ckt;
time = ckt->CKTtime;
@ -431,10 +434,9 @@ PTddt(double arg, void* data)
return 0;
}
if (!(ckt->CKTmode & MODETRAN) /*&& !(ckt->CKTmode & MODEINITTRAN)*/)
if (!(ckt->CKTmode & MODETRAN))
return 0;
if (time > thing->vals[0]) {
thing->vals[4] = thing->vals[2];
thing->vals[5] = thing->vals[3];
@ -443,24 +445,21 @@ PTddt(double arg, void* data)
thing->vals[0] = time;
thing->vals[1] = arg;
for (i = 0; i < 7; i++)
debarr[i] = thing->vals[i];
/* // Some less effective smoothing option
if (thing->vals[2] > 0) {
thing->vals[6] = 0.5 * ((arg - thing->vals[3]) / (time - thing->vals[2]) + thing->vals[6]);
}
*/
if (thing->n > 1) {
// if (thing->vals[2] > 0) {
// debarr[6] = thing->vals[6] = 0.5 * ((arg - thing->vals[3]) / (time - thing->vals[2]) + thing->vals[6]);
debarr[6] = thing->vals[6] = (thing->vals[1] - thing->vals[3]) / (thing->vals[2] - thing->vals[4]);
thing->vals[6] = (thing->vals[1] - thing->vals[3]) / (thing->vals[2] - thing->vals[4]);
}
else {
debarr[6] = thing->vals[6] = 0;
debarr[3] = thing->vals[3] = arg;
thing->vals[6] = 0;
thing->vals[3] = arg;
}
thing->n += 1;
}
for (i = 0; i < 7; i++)
debarr[i] = thing->vals[i];
y = thing->vals[6];
return y;