Like I said before, the diode model is not complete because the diode doesn't know when and where to freewheel. To highlight this, I made the ideal switch model and tried to simulate a buck converter. Here's the code for the ideal switch (click on view raw below the code box to see the code in another window):
This is the circuit for the buck converter.
And this is the control code - actually just an open loop with a constant 50% duty ratio (click on view raw below the code box to see the code in another window):
And on execution, the current (measured by Ammeter_La) through the inductor La is:
And as can be seen, the diode does not free wheel at all. The current rises when the switch turns on and drops to zero when it is turned off.
The strategy to overcome this will be my next blog entry as it is a fairly detailed algorithm.