last day (34 days later) » 

3:22 PM
Hello. This is a room for discussion about this answer. Thes idea is to simulate a electrical circuit including a diode with NDSolve
First a warning : The approach of the problem proposed in the question is unconventional. The conventional approach is to use a dedicated software like Spice or Analog Inside. I have no idea if it is possible to make serious simulation in this way. As a hobbyist there is no risk for me, except time wasting.
 
3:45 PM
Information : I have a serious background in Mathematica, spice, diode modeling. I may be difficult to be understandable for novices.
 
4:03 PM
Just a correction : conventional approach are rather : the spice family - Analog Insyde - but also : SystemModeler.
 
4:15 PM
Hello andre. Thank you again for your help. To my background I studied physics and now I am working for a company, where my task is to solve problems from different fields, such as mechanics (static and dynamic) and now the electronics we have here.
I am aware of the spice family and use it as a reference to proof my results. Nevertheless I want to stick to Mathematica due to the following reason: The solution of this problem will be part of a bigger toolchain I have developed within the las year. I am currently optimizing elektromechanical systems and I need the algorithms of Mathematica to run this calculations (We could not implement them in Spice).
This is the first Problem I have to counter fully numerically, usually I try to solve as much as possible in an analytical way. Anyway to my mind you solution works well. The problems I run in have (to my mind) numerical reasons.
Unfortunately I dont have my source code with me over the weekend, so I will need some time to write a the small part again here on my laptop ...
 
 
1 hour later…
5:43 PM
I made a simplification where I took out the rswitch. Then I added my PWM Signal
timeStart = 0;
timeEnd = 15;

r = 0.1;
l = 1;


uPWM = 1;
PWMFreq = 1;
PulseDuration = 10;
uPart[t_, PulseDuration_] :=
Piecewise[{{Sin[\[Pi]*t/PulseDuration], 0 <= t <= PulseDuration}}, 0]

u[t_, PWMFreq_, PulseDuration_] :=
If[Mod[t, 1/PWMFreq] > uPart[t, PulseDuration], 0, uPWM]

Plot[u[t, PWMFreq, PulseDuration], {t, timeStart, timeEnd},
Exclusions -> None, ImageSize -> Large]

res = NDSolveValue[{l i'[t] ==
u[t, PWMFreq, PulseDuration] -
r i[t] - (i[t] - 10^-14 Exp[vdiode[t]/0.025]) ,
vdiode[t] + l i'[t] + r i[t] == 0, vdiode[0] == 0,
Here is one example. It works like this. Unfortunately it is not numerically stable.
 
6:34 PM
I'm available here on the chat for 3 hours and probably tomorrow.
I have tried your code with the following supplementary code :
timeStart=0;timeEnd=10;r=1;l=0.3;
I obtain :
It seems OK. Do you have the same thing ? I don't see numerical instability.
My Mathematica version : 11.0.0
Forget my last messages. I have missed the beginning of your code.
I'm now trying to delete my last messages.
I can't find any way to delete the messages. I give up with this story of deletion. Never mind. Back to the real problem : diode simulation.
 
6:52 PM
No problem :-) If you take my code and change uPWM to 12 you run into the first problem.
NDSolveValue::ssres: NDSolve has computed values that give a zero residual for the differential-algebraic system, but some components are different from those specified.
 
This time, with exactly your code, I obtain this :
It looks good. I don't see any stability problem. Have you the same result ?
OK I just become aware of your message with uPWM = 12
 
Yes I have the same
This is one of the problems I ran into during my day of testing this type of solution.
the other one I try to reproduce now
The second problem you get when you take the initial code and change the l to 0.001
Then I get
NDSolveValue::nderr: Error test failure at t == 1.0000000000000016`; unable to continue.
The second one looks like, I could compensate it by scaling the values. Possibly I could do this in a way, that It works automatically, but the first one I dont understand yet.
 
7:10 PM
Concerning the first problem, I don't know at this time how to interpret the error message about zero residual, but I'm very confident about the validity of the result, whic is :
 
Ok, so you suggest, that we should see the error message more like a warning
That would be good for me, because that would mean I only have to take care about the second one.
 
I'm not sure that this should be considered as a warning or not, but I prefer to have first an overview of all the problems you have, and eventually go back to this problem if there nothing more annoying.
 
7:28 PM
That makes sense. One question: You set this inital condition i[0] == -1/2*10^-14 . What is the reason you dont set it to zero?
 
I can reproduce your second problem. Concerning your remark about automatic scaling,be carefull, don't underestimate the difficulty of scaling. In electronics, unlike in mechanics (I think) the magnitude of the values of the quantities can be very large (for example, for a diode Ireverse=10^-14A, Iforward=1A).
 
Yes this is definitely a point I have to face. But I am sure there Is a way around, as PSpice and so on, also find a way for that.
 
I was waiting for the question about i[0]==-1/2*10^-14 !. The answer is not simple (I hope this is to critical). The short answer is that the diode is modelised by idiode==Is Exp[q V/(k T)], so if I had set is to 0, that would be equivalent to set V to -Infinity.
Now i try the long answer. I don't know if it will be clear...
 
I do my best :-)
But the short explenation makes sense to me ...
 
8:05 PM
First point : Is it valid to remove the -1 of the equation : I=Is (Exp[q V/(k T]-1) ? Answer : yes. It is equivalent to add a current generator of Is=10^-14 amperes in parallel to the diode. Physically speaking, it is insignifiant. If the simulation is realistic it should work.
Generally speaking, that the kind reason why I try to make realistic simulation, that is to say : no discontinuties, for example in u[t], no perfect switch (0 Ohms when on, Infinity when off) etc... The problem is that is the contrary of the approach of beginner (ideals components)
 
I understand what you are saying. I also can try to change the Signal in a way that there is no discontinuity anymore, the fact why I did not try it until now is, that the function for the PWM Signal is already complex and without diode this worked well. I try always a simple approach first and expand it when I see, I run into problems.
 
The problem is what you call "simple". For example Spice often crash desesperatly at the beginning of a study because the components models are too "ideal" ("simple"), and at the end it works fine though there are many more components.
All this is interesting, but I think you prefer that I solve the problem of NDSolve (if I can) and that I delay explanations for later.
 
8:24 PM
Oh I have time we can do this in the way you prefer it. I always like to learn :-)
From what you tell me I estimate, that the discontinuities are a main problem for the numerical evaluation, thats why the more sophisticated models don't fail. In view of the exponential function my feeling agrees with that.
 
Yes, the exponential is smooth, but it is stiff, another souce of problems eventually.
 
So do you agree, when I say: It is more suitable to blew up the function for signal generation in a way to avoid discontinuities?
 
9:05 PM
"more suitable" : yes, sure, but i can't garantee that the problem will be solved, or worse, that it doesn't reappears if you use too steep slopes for the edges of u[t]. At the moment i'm rather trying to see if there is some interesting option in NDSolve.
 
I also tried options of NDSolve ... but I got a rather odd message, that different methods are not yet implemented.
That there is no guarantee I know. Otherwise it would not be science :-D
 
9:59 PM
I'm leaving the chat now. I'll Be back tomorrow.
 

  last day (34 days later) »