Author Topic: Kirchhoff (Laplacian matrix) with diodes  (Read 2179 times)

0 Members and 1 Guest are viewing this topic.

Offline happylexTopic starter

  • Contributor
  • Posts: 11
Kirchhoff (Laplacian matrix) with diodes
« on: July 25, 2017, 01:27:11 pm »
Hello world,

I have a quite complex directed electrical network (10000+ components). Now my problem is how to formulate this in a systematic and efficient way. I would like to solve it with linear algebra because of the size. When I was only using resistors and linear sources in the network, it worked fine. However, when diodes were included to direct some currents, the calculations don't work anymore.

You make me super happy if you can help me to solve this simplified example network:
We have nodes 1 to 4
between node 1-2: Normal 1 Ohm resistor
from node 2->3: 0.5 Ohm (Forward resistance+diode)
from node 3->2: 1 Ohm (Backward resistance+diode)
between node 3-4: Normal 1 Ohm resistor

The ground is connected to 4. The constant current source input is connected between ground and node 1 and can be both positive and negative.

Thank you in advance
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22435
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Kirchhoff (Laplacian matrix) with diodes
« Reply #1 on: July 25, 2017, 01:44:19 pm »
Load the netlist into SPICE and run DC OP.  (Node 0 is traditionally ground, so remember to name that accordingly.)

What SPICE is doing internally, is solving that matrix using nonlinear convergence methods (source and GMIN stepping), and, IIRC, L-U decomposition for solving the matrix inverse at each iteration.

Of course, the result will be numeric, not symbolic, and the output in general will depend on source magnitude (depending on how many diodes are in series through a given path in your circuit).  You may want to sweep the sources (DC Sweep analysis) to get a representative idea of overall system response (which could be used to create some kind of approximate symbolic model, if you need it).

You can use the built-in diode (the DC parameters are very accurate to real silicon PN junction diodes), or you can use a subcircuit for a custom diode (a "shallow" diode, like the 0.5/1 ohm example) using nonlinear sources and a formula.  (Beware of convergence issues with naive functions.  SPICE does not like discontinuities or singularities: avoid MAX/MIN, IF, division, and negative inputs to odd exponents.  TANH is great for making limiting and crossover functions like diodes, amplifiers, and limiters/MIN/MAX.)

Obviously(?), linear algebra cannot express such a system, but it can be used as a framework to compute the result as above.

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline happylexTopic starter

  • Contributor
  • Posts: 11
Re: Kirchhoff (Laplacian matrix) with diodes
« Reply #2 on: July 25, 2017, 02:33:13 pm »
Thank you Tim,

I tried and am not happy with memory and time use of PSpice. I was already afraid I can't solve this with linear algebra.
What I do now is not very memory consuming and takes not much more than 10 minutes.
1. put the diodes all on conducting
2. make a system sparse matrices, and do the super fast sparse U/L linear algebra trick to calculate voltages   ::)
3. Correct the state of diodes with the help of the voltages (if needed)   :-/O
4. If not happy goto 2 again. Else done!  :-DMM

I guess PSpice is not just specialized in this, and therefore taking much more time.
 

Offline orolo

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: es
Re: Kirchhoff (Laplacian matrix) with diodes
« Reply #3 on: July 25, 2017, 03:42:44 pm »
The problem as I see it is "correct state of diodes". I guess your idea is:

Assume a steady state DC circuit, with only resistors and diodes (DC + steady state render capactiors and inductors irrelevant).

The steady state solution will have some of the diodes working as open circuits, and some others ideally working as -0.6 voltage drops (or resistors).

So if we could locate the open circuit diodes, we could approach the steady state of the system as a purely linear network.

I think the approach you have made consists of:

1) Initally, solve assuming each diode is "on", that is, it works as a -0.6V voltage source (or resistor).
2) Given the solution, check if some diode is conducting in reverse.
3) (?!) All the reverse biased diodes are converted to open circuits.
4) Return to 2) until all diodes are either open circuit or conducting in the forward direction.

The problem is step 3: the diodes cascade and affect each other.

Consider the diode circuit attached. The real solution has all resistors conducting (I_R1=I_R5=22.7mA, I_R2=82.9mA).
Now, if you change the diodes by either resistors or -0.6V sources, you will have both D1 and D3 marked as reversed, and taken away from the circuit. Then, in step 4 you converge to a solution that has I_R1=I_R5=0, which is not correct. The problem is that the fact that D1 is turned on makes D3 to be reverse biased. However, if you turn D1 off, then D3 is forward biased.

I hope the problem is clear: depending on which diodes you choose to turn off, you converge to different solutions. This gives, in principle, an exponential choosing complexity. Even worse, if you arrive at an incorrect solution, how do you know it's wrong?

I think step 3) could be improved imposing an elimination order to the diodes, based on which diode turning off could affect subsequent diodes, but I think that could wind up being more complicated than solving a nonlinear system.
« Last Edit: July 25, 2017, 03:44:26 pm by orolo »
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22435
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Kirchhoff (Laplacian matrix) with diodes
« Reply #4 on: July 25, 2017, 04:01:08 pm »
Thank you Tim,

I tried and am not happy with memory and time use of PSpice. I was already afraid I can't solve this with linear algebra.
What I do now is not very memory consuming and takes not much more than 10 minutes.
1. put the diodes all on conducting
2. make a system sparse matrices, and do the super fast sparse U/L linear algebra trick to calculate voltages   ::)
3. Correct the state of diodes with the help of the voltages (if needed)   :-/O
4. If not happy goto 2 again. Else done!  :-DMM

I guess PSpice is not just specialized in this, and therefore taking much more time.

How much memory do you have to spare?  Is this embedded or something?

How much time can you spare?  Is this a real time problem, or are you just doing, like, thousands of netlists and you don't want it to take weeks?

I have no idea how much is added onto the SPICE core, in PSpice.  Maybe you need a simpler one, like NGSpice (which is FOSS) command line interface?  Heck, you can even test it online (there's a web interface at ngspice.com). :)

That process is basically what SPICE does.  Assuming diodes are on is similar to GMIN stepping (set all branch conductances very low, then relax the conductance towards the value calculated by the branch component's formula).

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf