Page 1 of 1

Discrepancy between tvec and vector

Posted: Tue May 11, 2021 8:38 am
by NickHananeia
I hope this is something minor that I'm missing, but I've noticed a weird discrepancy between my tvec and a voltage vector when I need 1:1 correspondence, but only depending on the time step.

The program that I've written has a selectable time step as a parameter: 5us or 25us, and this is set pretty early in the program.

I declare my tvec like this:

tvec = new Vector()
tvec.indgen(0.000000, tstop, dt)

and I've verified after it's saved externally that it's correct for both the 5us and 25us case.

Then, I declare a list of voltage vectors...

obfunc recallv() { localobj tmplist, tmpvec
tmplist = new List()
forall for (x,0) {
tmpvec = new Vector()
tmpvec.record(&v(x), tvec)
tmplist.append(tmpvec)
}
return tmplist
}

For the 5us case, it works - my test case for a 10ms run has 2001 lines in the tvec and 2001 lines in the voltage trace.

For the 25us case, however, I have 401 lines in the tvec output and only 400 in the voltage trace. As minor as it is, I don't want to publish code with an off-by-one error.

Any thoughts on what could be happening here?

Re: Discrepancy between tvec and vector

Posted: Tue May 11, 2021 10:16 am
by ted
Roundoff error is your enemy. You have to rely on the standard run system to decide when the simulation ends, but you're using the Vector class's indgen method to fill the t vector. Instead, use Vector.record to capture t, and the resulting recorded t vector will be the same length as the v vectors.

Re: Discrepancy between tvec and vector

Posted: Tue May 11, 2021 10:33 am
by NickHananeia
That makes sense. I'd shifted to using the indgen method because of another issue, but I found a workaround for that.

Thanks for the quick solution!