By

MNA Theta Method Capacitor Discretization

This post is on the technical side and has a good bit of math in it. In fact, it will not make much sense to you unless you happen to have done some background study on circuit simulation in the modified nodal analysis (MNA) tradition. But for those that are on that path, it may be helpful (it would have been for me) and so I’m sharing for that reason.

To provide a little background, as I began studying analog modeling using MNA techniques, I of course came across Andy Simper’s well known presentation from ADC20 From Circuit to Code: Under the Hood of Analog Modelling.

In his discussion of capacitor discretization formulas, he mentioned the idea that the Forward Euler (FE), Backward Euler (BE) and trapezoidal rule (TR) numerical integration methods can be combined using “mixing”. In his formulation, this is controlled by a mixing variable mm. At m=12m=\frac{1}{2}, you get TR, m=1m=1 is BE, and as m0m \to 0, you approach the FE formula (if we actually set mm to zero we would get a divide-by-zero in the update equation).

If you happen to be doing something very similar, you of course can use Andy’s equations directly. But as I have been developing a more general simulation code base, and since I was interested in experimenting with this “mixing” formulation, I had a need to understand where it came from so that I could put it in the context of the more general MNA formulation I was working in.

I had bought the book Circuit Simulation by Farid N. Najm, and was working through it to develop my understanding of MNA. It has good coverage of all three basic numerical integration methods (FE, BE, and TR), but makes no mention of this “mixing” technique. So I searched high and low for a reference and did eventually find one in the 2012 paper “Parallel Spectral Numerical Methods” which was written by Gong Chen, Brandon Cloutier, Ning Li, Benson K. Muite and Paul Rigge (henceforth “Chen et al”), where it is referred to as the Theta Method. In their formulation, we get BE at θ=0\theta=0 and approximate FE as θ1\theta\to1 i.e. it is effectively a flipped version of Andy’s formulation. So let us note here that θ\theta (or Andy’s mm) is arbitrary in definition and we are free to select either.

I later picked up a copy of the book Fundamentals of Computer-Aided Circuit Simulation by William J. McCalla. This book is frequently referenced by the Najm book, and covers some of the same material, but in places feels more like a survey of the methods in use at the time (1987), unlike Najm which generally feels like more of rigorous introduction to the topic (the Najm book is also much more recent and was first published in 2010).

The McCalla book actually does mention the Theta Method, but only very briefly, without explaining it in any depth or deriving the element companion model equations. In the formulation that is discussed, the controlling variable is μ\mu and it is defined similarly to Chen at al’s definition of θ\theta i.e. BE is given with μ=0\mu=0. McCalla cites W. Liniger and R.A. Willoughby’s 1970 paper “Efficient Integration Methods for Stiff Systems of Ordinary Differential Equations”. I am left to assume what is now known as the Theta Method may therefore have originated with Liniger and Willoughby, but I must admit I haven’t read the paper.

What follows here is a derivation of the MNA stamping equations for both linear and non-linear capacitors using the Theta Method. To this end I first review the patterns established by Najm in the derivation of the BE and TR equations before applying the same approach to the Theta Method. After that I also derive PLTE estimates (again following Najm’s lead) and finally re-derive the minimal (and efficient) update equations that Andy shows in his presentation.

Please note that, much like how the definition of θ\theta can vary arbitrarily from one reference to the next, companion model conventions do also. With capacitor companion models this comes up around the polarity of the current source. Indeed, even within the Najm book, the convention used for the BE and TR derivations differs in a way that I found confusing. To minimize this kind of confusion, I will start by defining a single convention that will be applied for all examples, and when presenting Najm’s derivations I make adjustments as needed to match this convention. As such my equations do not match Najm’s exactly in some places. In general I have made an effort to point out where this is the case.

As is probably obvious, I have borrowed very heavily from Najm throughout, and so I think it’s appropriate that I direct you to buy his book if you are interested in learning more about any of these techniques. I must say it is certainly one of the more expensive books I’ve bought, and I do have an occasional quibble prompted by my own confusion, but that is just as likely because my linear algebra background is pretty thin as it is because of how the material is presented (not to mention that I’m surely just not as smart as Najm). Overall the book is of high quality and delivers the material in a thoughtful, organized way, so I’d absolutely recommend it.

Lastly let me just say I do not claim to be an expert on any of this, and indeed I am still working to deepen my understanding of many aspects of MNA. Without following Najm’s lead I doubt I’d have been able to derive anything on my own. Just sharing as I learn is all. If you notice I’ve made a mistake somewhere, please let me know.

So without any further rambling, here is the companion model we will use for all derivations below:

And therefore in all cases we will use the following element stamp:

[GeqGeqGeqGeq][v+v]=[IeqIeq]\begin{bmatrix} G_{eq} & -G_{eq} \\ -G_{eq} & G_{eq} \end{bmatrix} \begin{bmatrix} v^+ \\ v^- \end{bmatrix} = \begin{bmatrix} -I_{eq} \\ I_{eq} \end{bmatrix}

Likewise will express the linearization at time tn+1t_{n+1} in the following form:

in+1=Gequn+1+Ieqi_{n+1} = G_{eq} u_{n+1} + I_{eq}

Where implicitly IeqIeq,n+1I_{eq} \equiv I_{eq,n+1} and (for non-linear capacitors) GeqGeq,n+1G_{eq} \equiv G_{eq,n+1}.

Linear Capacitor

In the case of a linear capacitor, we will use the usual capacitance-based model, where we are given:

i(t)=Cdudti(t) = C \frac{du}{dt}

Backward Euler

Given the Backward Euler discretization formula:

xn+1=xn+hf(xn+1,tn+1)(Najm 5.54)x_{n+1} = x_n + h f(x_{n+1}, t_{n+1}) \tag{Najm 5.54}

And given the initial value problem (IVP) specified by x(t)=f(x,t)x'(t) = f(x, t) and x(t0)=x0x(t_0)=x_0, we have:

xn+1=xn+hx(tn+1)x(tn+1)=1h(xn+1xn)\begin{gather} x_{n+1} = x_n + hx'(t_{n+1}) \\ x'(t_{n+1}) = \frac{1}{h} (x_{n+1} – x_n) \end{gather}

Applying this to the capacitor state:

i(tn+1)=Cu(tn+1)(Najm 5.297)in+1Cu(tn+1)(Najm 5.298)in+1C[1h(un+1un)](Najm 5.299)\begin{gather} i(t_{n+1}) = Cu'(t_{n+1}) \tag{Najm 5.297} \\\\ i_{n+1} \approx Cu'(t_{n+1}) \tag{Najm 5.298} \\\\ i_{n+1} \approx C \left[\frac{1}{h} (u_{n+1} – u_n)\right] \tag{Najm 5.299} \\\\ \end{gather}

Leads to the following direct discretization:

in+1=Chun+1+[Chun](Najm 5.300)i_{n+1} = \frac{C}{h} u_{n+1} + \left[-\frac{C}{h} u_n\right] \tag{Najm 5.300}

And the companion model equations:

Geq=Ch and Ieq=Chun(Najm 5.308)G_{eq} = \frac{C}{h} \text{ \quad and \quad} I_{eq} = -\frac{C}{h} u_n \tag{Najm 5.308}

Trapezoidal Rule

Given the Trapezoidal Rule discretization formula:

xn+1=h2[f(xn+1,tn+1)+f(xn,tn)](Najm 5.62)x_{n+1} = \frac{h}{2}[f(x_{n+1}, t_{n+1}) + f(x_n, t_n)] \tag{Najm 5.62}

And given the IVP specified by x(t)=f(x,t)x'(t) = f(x, t) and x(t0)=x0x(t_0)=x_0, we have:

xn+1=xn+h2[x(tn+1)+x(tn)]x(tn+1)=2hxn+12hxnx(tn)(Najm 5.324)\begin{gather} x_{n+1} = x_n + \frac{h}{2} \left[x'(t_{n+1}) + x'(t_n)\right] \\ x'(t_{n+1}) = \frac{2}{h} x_{n+1} – \frac{2}{h} x_n – x'(t_n) \tag{Najm 5.324} \end{gather}

Applying this to capacitor state:

i(tn+1)=Cu(tn+1)(Najm 5.322)in+1Cu(tn+1)(Najm 5.323)in+1C[2hun+12hunu(tn)](Najm 5.325)\begin{gather} i(t_{n+1}) = Cu'(t_{n+1}) \tag{Najm 5.322} \\\\ i_{n+1} \approx Cu'(t_{n+1}) \tag{Najm 5.323} \\\\ i_{n+1} \approx C \left[\frac{2}{h} u_{n+1} – \frac{2}{h} u_n – u'(t_n)\right] \tag{Najm 5.325} \end{gather}

Leads to the following direct discretization, where we’ve also made use of inCu(tn)i_n \approx Cu'(t_n):

in+1=2Chun+1+[2Chunin](Najm 5.335)i_{n+1} = \frac{2C}{h} u_{n+1} + \left[-\frac{2C}{h} u_n – i_n\right] \tag{Najm 5.335}

And the companion model equations:

Geq=2Chand Ieq=2Chunin(Najm 5.337)G_{eq} = \frac{2C}{h} \text{\quad and \quad} I_{eq} = -\frac{2C}{h} u_n – i_n \tag{Najm 5.337}

Theta Method

Given the Theta Method (θM) discretization formula:

xn+1=xn+h[θf(xn+1,tn+1)+(1θ)f(xn,tn)](Chen et al 9.20)x_{n+1} = x_n + h\left[\theta f(x_{n+1}, t_{n+1}) + (1-\theta) f(x_n, t_n)\right] \tag{Chen et al 9.20}

Note that we have flipped the definition of θ\theta in comparison with Chen et al by making the substitution θ(1θ)\theta\mapsto(1-\theta). This gives us BE at θ=1\theta=1 which is consistent with Andy Simper’s definition of mm.

Given the IVP specified by x(t)=f(x,t)x'(t) = f(x, t) and x(t0)=x0x(t_0)=x_0, we have:

xn+1=xn+h[θx(tn+1)+(1θ)x(tn)]x(tn+1)=1θ[1h(xn+1xn)(1θ)x(tn)]x(tn+1)=1θhxn+11θhxn1θθx(tn)\begin{gather} x_{n+1} = x_n + h\left[\theta x'(t_{n+1}) + (1-\theta) x'(t_n)\right] \\\\ x'(t_{n+1}) = \frac{1}{\theta} \left[\frac{1}{h}(x_{n+1}-x_n) – (1-\theta) x'(t_n)\right] \\\\ x'(t_{n+1}) = \frac{1}{\theta h} x_{n+1} – \frac{1}{\theta h} x_n – \frac{1-\theta}{\theta} x'(t_n) \end{gather}

Applying this to the capacitor state:

i(tn+1)=Cu(tn+1)in+1Cu(tn+1)in+1C[1θhun+11θhun1θθu(tn)]\begin{gather} i(t_{n+1}) = Cu'(t_{n+1}) \\\\ i_{n+1} \approx Cu'(t_{n+1}) \\\\ i_{n+1} \approx C \left[\frac{1}{\theta h} u_{n+1} – \frac{1}{\theta h} u_n – \frac{1-\theta}{\theta} u'(t_n)\right] \end{gather}

Leads to the following direct discretization, where we’ve also made use of inCu(tn)i_n \approx Cu'(t_n):

in+1=Cθhun+1+[θ1θinCθhun]i_{n+1} = \frac{C}{\theta h} u_{n+1} + \left[\frac{\theta-1}{\theta} i_n -\frac{C}{\theta h} u_n \right]

And the companion model equations:

Geq=Cθhand Ieq=θ1θinCθhunG_{eq} = \frac{C}{\theta h} \text{\quad and \quad} I_{eq} = \frac{\theta-1}{\theta} i_n – \frac{C}{\theta h} u_n

Note that with θ=12\theta=\frac{1}{2} we recover the TR equations, and with θ=1\theta=1 we recover the BE equations.

Non-Linear Capacitor

In the case of a non-linear capacitor, we will use the charge-based model (as presented by Najm) rather than the capacitance-based model. With the charge based model, we are given:

C(u)dqdu(Najm 5.351)i(t)=dqdt(Najm 5.352)\begin{gather} C(u) \triangleq \frac{dq}{du} \tag{Najm 5.351} \\\\ i(t) = \frac{dq}{dt} \tag{Najm 5.352} \end{gather}

Backward Euler

Recall the BE finite difference equation used previously:

x(tn+1)1h(xn+1xn)x'(t_{n+1}) \approx \frac{1}{h} (x_{n+1} – x_n)

Applied to the capacitor state:

i(tn+1)=q(tn+1)1h[q(tn+1)q(tn)](Najm 5.353)\begin{gather} i(t_{n+1}) = q'(t_{n+1}) \approx \frac{1}{h} \left[q(t_{n+1})-q(t_n)\right] \tag{Najm 5.353} \end{gather}

Leads to the following direct discretization, where we’ve also made use of i(tn)ini(t_n) \approx i_n and q(tn)q(un)q(t_n) \approx q(u_n):

in+1=1hq(un+1)1hq(un)gC(un+1)(Najm 5.354)i_{n+1} = \frac{1}{h} q(u_{n+1}) – \frac{1}{h} q(u_n) \triangleq g_C(u_{n+1}) \tag{Najm 5.354}

Recall that the first order Taylor expansion is written like this:

f(b)f(a)+f(a)(ba)f(b) \approx f(a) + f'(a)(b-a)

Linearizing ii in the Newton loop at tn+1t_{n+1} (we are solving for unknown uun+1u \equiv u_{n+1}):

i=gC(u)gC(un+1(k))+gC(un+1(k))(uun+1(k))(Najm 5.314)i=gC(un+1(k))u+[gC(un+1(k))gC(un+1(k))un+1(k)]Gequ+Ieq(Najm 5.316)\begin{gather} i = g_C(u) \approx g_C\left(u_{n+1}^{(k)}\right) + g’_C\left(u_{n+1}^{(k)})(u-u_{n+1}^{(k)}\right) \tag{Najm 5.314} \\\\ i = g’_C\left(u_{n+1}^{(k)}\right) u + \left[g_C\left(u_{n+1}^{(k)}\right) – g’_C\left(u_{n+1}^{(k)}\right) u_{n+1}^{(k)}\right] \triangleq G_{eq} u + I_{eq} \tag{Najm 5.316} \end{gather}

Taking the derivative of gC(u)g_C(u) and evaluating at un+1(k)u_{n+1}^{(k)}:

gC(u)=ddugC(u)=ddu[1hq(u)1hq(un)]]=1hdqdugC(un+1(k))=1hdqdu|un+1(k)=1hC(un+1(k))\begin{gather} g’_C(u) = \frac{d}{du} g_C(u) = \frac{d}{du} \left[\frac{1}{h} q(u) – \frac{1}{h} q(u_n)]\right] = \frac{1}{h} \frac{dq}{du} \\\\ g’_C\left(u_{n+1}^{(k)}\right) = \left. \frac{1}{h} \frac{dq}{du} \right\rvert_{u_{n+1}^{(k)}} = \frac{1}{h} C\left(u_{n+1}^{(k)}\right) \end{gather}

Leads to the companion model equations:

Geq=gC(un+1(k))Ieq=gC(un+1(k))gC(un+1(k))un+1(k)=gC(un+1(k))Gequn+1(k)\begin{gather} G_{eq} = g’_C\left(u_{n+1}^{(k)}\right) \\\\ I_{eq} = g_C\left(u_{n+1}^{(k)}\right) – g’_C\left(u_{n+1}^{(k)}\right) u_{n+1}^{(k)} = g_C\left(u_{n+1}^{(k)}\right) – G_{eq} u_{n+1}^{(k)} \end{gather}

The above form is derived identically for the TR and θM integration methods. Only the derivation of gC(u)g_C(u) and gC(u)g_C'(u) differs.

Trapezoidal Rule

Recall the TR finite difference equation used previously:

x(tn+1)=2hxn+12hxnx(tn)x'(t_{n+1}) = \frac{2}{h} x_{n+1} – \frac{2}{h} x_n – x'(t_n)

Applied to the capacitor state:

i(tn+1)=q(tn+1)2hq(tn+1)2hq(tn)q(tn)i(t_{n+1}) = q'(t_{n+1}) \approx \frac{2}{h} q(t_{n+1}) – \frac{2}{h} q(t_n) – q'(t_n)

Leads to the following direct discretization, where we’ve also made use of i(tn)ini(t_n) \approx i_n, q(tn)q(un)q(t_n) \approx q(u_n), and inq(tn)i_n \approx q'(t_n):

in+1=2hq(un+1)2hq(un)ingC(un+1)i_{n+1} = \frac{2}{h} q(u_{n+1}) – \frac{2}{h} q(u_n) – i_n \triangleq g_C(u_{n+1})

Taking the derivative of gC(u)g_C(u) and evaluating at un+1(k)u_{n+1}^{(k)}:

gC(u)=ddugC(u)=ddu[2hq(u)2hq(un)in)]=2hdqdugC(un+1(k))=2hdqdu|un+1(k)=2hC(un+1(k))\begin{gather} g’_C(u) = \frac{d}{du} g_C(u) = \frac{d}{du} \left[\frac{2}{h} q(u) – \frac{2}{h} q(u_n) – i_n)\right] = \frac{2}{h} \frac{dq}{du} \\\\ g’_C\left(u_{n+1}^{(k)}\right) = \frac{2}{h} \left.\frac{dq}{du}\right\rvert_{u_{n+1}^{(k)}} = \frac{2}{h} C\left(u_{n+1}^{(k)}\right) \end{gather}

Where, having derived the above, we can reuse the companion model equations from the BE method.

Theta Method

Recall the θM finite difference equation used previously:

x(tn+1)=1θhxn+11θhxn1θθx(tn)x'(t_{n+1}) = \frac{1}{\theta h} x_{n+1} – \frac{1}{\theta h} x_n – \frac{1-\theta}{\theta} x'(t_n)

Applied to the capacitor state:

i(tn+1)=q(tn+1)1θhq(tn+1)1θhq(tn)1θθq(tn)i(t_{n+1}) = q'(t_{n+1}) \approx \frac{1}{\theta h} q(t_{n+1}) – \frac{1}{\theta h} q(t_n) – \frac{1-\theta}{\theta}q'(t_n)

Leads to the following direct discretization, where we’ve also made use of i(tn)ini(t_n) \approx i_n, q(tn)q(un)q(t_n) \approx q(u_n), and inq(tn)i_n \approx q'(t_n):

in+1=1θhq(un+1)1θhq(un)1θθingC(un+1)i_{n+1} = \frac{1}{\theta h} q(u_{n+1}) – \frac{1}{\theta h} q(u_n) – \frac{1-\theta}{\theta}i_n \triangleq g_C(u_{n+1})

Taking the derivative of gC(u)g_C(u) and evaluating at un+1(k)u_{n+1}^{(k)}:

gC(u)=ddugC(u)=ddu[1θhq(u)1θhq(un)1θθin)]=1θhdqdugC(un+1(k))=1θhdqdu|un+1(k)=1θhC(un+1(k))\begin{gather} g’_C(u) = \frac{d}{du} g_C(u) = \frac{d}{du} \left[\frac{1}{\theta h} q(u) – \frac{1}{\theta h} q(u_n) – \frac{1-\theta}{\theta}i_n)\right] = \frac{1}{\theta h} \frac{dq}{du} \\\\ g’_C\left(u_{n+1}^{(k)}\right) = \left.\frac{1}{\theta h} \frac{dq}{du} \right\rvert_{u_{n+1}^{(k)}} = \frac{1}{\theta h} C\left(u_{n+1}^{(k)}\right) \end{gather}

Where, having derived the above, we can reuse the companion model equations from the BE method.

PLTE Computation For Theta Method

Given local truncation error for θM as:

en+1,h={112h3x(tn)+𝒪(h4)θ=12(12θ)h2x(tn)+𝒪(h3)θ12(Chen et al 9.23)e_{n+1,h} = \begin{cases} -\frac{1}{12} h^3 x”’\left(t_n\right) + \mathcal{O}\left(h^4\right) & \theta = \frac{1}{2} \\ \left(\frac{1}{2}-\theta\right) h^2 x”\left(t_n\right) + \mathcal{O}\left(h^3\right) & \theta \neq \frac{1}{2} \end{cases} \tag{Chen et al 9.23}

Where, once again, we have flipped Chen et al’s definition of θ\theta via substitution θ(1θ)\theta\mapsto(1-\theta).

We can derive the order pp and error constants C0Cp+1C_0 \ldots C_{p+1} as follows:

θ=12p=2C0=0C1=0C2=0and C3=112θ12p=1C0=0C1=0and C2=12θ\begin{align} \theta = \frac{1}{2} \quad \implies \quad & p = 2 \text{, \quad} C_0 = 0 \text{, \quad} C_1 = 0 \text{, \quad} C_2 = 0 \text{, \quad and \quad} C_3 = -\frac{1}{12} \\ \theta \neq \frac{1}{2} \quad \implies \quad & p=1 \text{, \quad} C_0 = 0 \text{, \quad} C_1 = 0 \text{, \quad and \quad} C_2 = \frac{1}{2}-\theta \end{align}

Equidistant Data (Fixed Time Step)

Given:

2xn=xn2xn1+xn2(Najm 5.137)3xn=xn3xn1+3xn2xn3(Najm 5.139)\begin{align} \nabla^{2} x_n & = x_n – 2 x_{n-1} + x_{n-2}\tag{Najm 5.137} \\ \nabla^{3} x_n & = x_n – 3 x_{n-1} + 3 x_{n-2} – x_{n-3} \tag{Najm 5.139} \end{align}

For equidistant data, we can estimate PLTE as follows:

PLTECp+1p+1xn(Najm 5.188)PLTE \approx C_{p+1} \nabla^{p+1} x_n \tag{Najm 5.188}

Applying this to the Theta Method, we get:

PLTE{112(xn3xn1+3xn2xn3)θ=12(θ12)(xn2xn1+xn2)θ12PLTE \approx \begin{cases} -\frac{1}{12}(x_n – 3 x_{n-1} + 3 x_{n-2} – x_{n-3}) & \theta=\frac{1}{2} \\ \left(\theta – \frac{1}{2}\right)(x_n – 2 x_{n-1} + x_{n-2}) & \theta\neq\frac{1}{2} \end{cases}

Note that for θ=12\theta = \frac{1}{2} we simply have the TR case, and that when θ=1\theta = 1 we recover the PLTE estimate for the BE case. However, note also that as θ12\theta \to \frac{1}{2}, our PLTE estimate becomes vanishingly small before “switching“ to the TR form. This occurs simply because we generally ignore the 2nd order error term when using a 1st order integration method such as BE (or θM when not in the vicinity of θ=12\theta=\frac{1}{2}. However, it would likely only cause issues for us if we are implementing a variable θ\theta algorithm, which I currently am not doing!

Non-Equidistant Data (Variable Time Step)

With p=1p=1, we are given:

PLTE2C2hn+12hn+1+hn(xn+1xnhn+1xnxn1hn)(Najm 5.196)PLTE \approx \frac{2C_2h_{n+1}^2}{h_{n+1} + h_n}\left(\frac{x_{n+1}-x_n}{h_{n+1}} – \frac{x_n-x_{n-1}}{h_n}\right) \tag{Najm 5.196}

For p=2p=2, we are given:

PLTE6C3hn+13tn+1tn2(xn+1xntn+1tnxnxn1tntn1tn+1tn1xnxn1tntn1xn1xn2tn1tn2tntn2)(Najm 5.197)PLTE \approx \frac{6C_3h_{n+1}^3}{t_{n+1}-t_{n-2}} \left(\frac{\frac{x_{n+1}-x_n}{t_{n+1}-t_n} – \frac{x_n-x_{n-1}}{t_n-t_{n-1}}}{t_{n+1}-t_{n-1}} – \frac{\frac{x_{n}-x_{n-1}}{t_n-t_{n-1}} – \frac{x_{n-1}-x_{n-2}}{t_{n-1}-t_{n-2}}}{t_n-t_{n-2}}\right) \tag{Najm 5.197}

To apply for the Theta Method, we need only plug in the correct error constants.

For θ12\theta\neq\frac{1}{2} we use the p=1p=1 form:

PLTE(12θ)hn+12hn+1+hn(xn+1xnhn+1xnxn1hn)PLTE \approx \frac{(1-2\theta)h_{n+1}^2}{h_{n+1} + h_n}\left(\frac{x_{n+1}-x_n}{h_{n+1}} – \frac{x_n-x_{n-1}}{h_n}\right)

Note that with θ=1\theta=1 we recover the BE result.

And for θ=12\theta=\frac{1}{2} we use the p=2p=2 form:

PLTE12hn+13tn+1tn2(xn+1xntn+1tnxnxn1tntn1tn+1tn1xnxn1tntn1xn1xn2tn1tn2tntn2)PLTE \approx \frac{-\frac{1}{2}h_{n+1}^3}{t_{n+1}-t_{n-2}} \left(\frac{\frac{x_{n+1}-x_n}{t_{n+1}-t_n} – \frac{x_n-x_{n-1}}{t_n-t_{n-1}}}{t_{n+1}-t_{n-1}} – \frac{\frac{x_{n}-x_{n-1}}{t_n-t_{n-1}} – \frac{x_{n-1}-x_{n-2}}{t_{n-1}-t_{n-2}}}{t_n-t_{n-2}}\right)

Note that this is simply the TR result.

Deriving Andy’s Update Equations

In his presentation, Andy wrote:

Ieq,n+1=Chmun+1mmin(Simper)I_{eq,n+1} = \frac{C}{hm} u_n + \frac{1-m}{m} i_n \tag{Simper}

I have adjusted his notation to match ours, except that I’ve used his mm instead of our θ\theta to avoid confusion with our own equations. I have also made the IeqI_{eq} index explicit since we will be expressing Ieq,n+1I_{eq,n+1} in terms of Ieq,nI_{eq,n}. Finally, notice that Andy’s companion model current source is defined with opposite polarity from ours, and as such the IeqI_{eq} expression would have to be negated to match ours exactly (I have not gone this far).

Andy goes on to derive the following:

Ieq,n+1=Ieq,n+1m(GequnIeq,n)(Simper) I_{eq,n+1} = I_{eq,n} + \frac{1}{m} (G_{eq} u_n – I_{eq,n}) \tag{Simper}

This is nice for a few reasons. First, it is a little more efficient to compute, both because mm appears only once in this formulation, but also because the results from evaluating the companion model equations are reused. And thus, it also only requires us to retain a single value from the previous time step: IeqI_{eq}.

However, I will note that this more minimal formulation will not work if we are doing a separate DC Analysis step, since we generally treat capacitors as an open circuit in the DC Analysis. For this reason, we need separate voltage and current history terms if we are doing DC analysis prior to proceeding with Transient Analysis.

Now let’s derive Andy’s minimal IeqI_{eq} update equation, starting with our companion model equations and KCL. Note that I’ve once again made the IeqI_{eq} index explicit here.

Geq=CθhIeq,n+1=θ1θinCθhunin=Gequn+Ieq,n \begin{gather} G_{eq} = \frac{C}{\theta h} \\\\ I_{eq,n+1} = \frac{\theta-1}{\theta} i_n – \frac{C}{\theta h} u_n \\\\ i_n = G_{eq} u_n + I_{eq,n} \end{gather}

We proceed with the following algebraic manipulations:

Ieq,n+1=θ1θ(Gequn+Ieq,n)GequnθIeq,n+1=(θ1)(Gequn+Ieq,n)θGequnθIeq,n+1=θIeq,nIeq,nGequnIeq,n+1=Ieq,n1θ(Gequn+Ieq,n)\begin{align} I_{eq,n+1} & = \frac{\theta-1}{\theta} (G_{eq} u_n + I_{eq,n}) – G_{eq} u_n \\\\ \theta I_{eq,n+1} & = (\theta-1) (G_{eq} u_n + I_{eq,n}) – \theta G_{eq} u_n \\\\ \theta I_{eq,n+1} & = \theta I_{eq,n} – I_{eq,n} – G_{eq} u_n \\\\ I_{eq,n+1} & = I_{eq,n} – \frac{1}{\theta}\left(G_{eq} u_n + I_{eq,n}\right) \end{align}

Where, finally, we note that this is exactly the result we’d have gotten by simply applying a sign flip to each of the IeqI_{eq} variables in Andy’s equation.

References

Andrew Simper. (2020). “From Circuit to Code: Under the Hood of Analog Modelling”.
https://www.youtube.com/watch?v=eGcqomH6aAc

Farid N. Najm. (2010). Circuit Simulation.

William J. McCalla. (1987). Fundamentals of Computer-Aided Circuit Simulation.

Gong Chen, Brandon Cloutier, Ning Li, Benson K. Muite and Paul Rigge. (2012).
“Parallel Spectral Numerical Methods”.

Stefan Jahn, Michael Margraf, Vincent Habchi, Raimund Jacob. (2003).
QUCS Technical Papers and in particular the subsection “Energy Storage Components”
https://qucs.sourceforge.net/tech/node26.html

Leave a Reply

Discover more from Minor Drama

Subscribe now to keep reading and get access to the full archive.

Continue reading