The problem with the approach that I have been using is that it is based exclusively on loop analysis. This breaks almost every time with every modification to the logic I try to make for every variation of the circuit. Nothing universal seems to be coming out. I have been spending the entire week drawing circuits, writing loops, scratching them out and repeating over and over again.
So need to change my approach. How about I mix in some nodal analysis as well? The loop analysis gives me all the loop currents for any one iteration. The control changes the circuit. Now, to determine how the currents will be rearranged, nodal analysis seems to be the only solution.
I am thinking about it this way:
1. At the end of an iteration, mark which loops were non-stiff and therefore may have had inductors carrying a non-negligible current.
2. When an event occurs, we need to rearrange the circuit, the loops, the loop currents and also decide any freewheeling effects.
3. At this point, the one circuit law that should be obeyed is - the current through an inductor cannot change instantaneously. Using this as a starting point, apply nodal analysis to calculate the current through all the branches.
4. Based on the preliminary calculations, check if the branch currents result in any changes in circuit topology - diodes freewheeling or IGBTs conducting. This seems a bit complicated - will need to expand on this.
5. Now that circuit topology is updated, another nodal analysis will update the branch currents. Using these updated branch currents, the loop currents will need to be calculated for the next round of loop analysis.
Only worry is that these tasks seem computationally heavy. Even if they are executed only when events occur, every effort will need to be made to make them simpler.