Qucs / qucsator

Circuit simulator of the Qucs project
http://qucs.sourceforge.net
GNU General Public License v2.0
24 stars 12 forks source link

Lack of Lambert W function in Qucsator #50

Open domi8space opened 1 month ago

domi8space commented 1 month ago

Hi all,

I am new to GitHub, which I join to help improving Qucs-based softwares (including Qucs-S), and this is my first post. Unfortunately, despite being an extensive user, I fear I cannot bring much in coding skills...

A famous mathematical function, often found when it is needed to solve equations with a linear term and either a logarithmic or exponential term, is lacking in the Qucs family's set of mathematical functions: the Lambert's W function. https://en.wikipedia.org/wiki/Lambert_W_function

There are some papers which give some examples of such electronic circuits, and even Wikipedia mentions the "diode and resistor" circuit solving with this function.

Most numerical computation softwares (Maple, Mathematica, Matlab, Scilab, Octave, Python, etc.) have this feature. Because this function can solve many problems that can be found in electronic circuits involving diodes or bipolar transistors, I think it would be useful to see it in Qucsator-based simulation softwares. I personally have to export the simulation data from Qucs(-S) and use an external software to plot the simulated results with the theoretical ones that use the Lambert W function, which makes it painful for repetitive iterations.

Thanks!

felix-salfelder commented 1 month ago

On Wed, Oct 23, 2024 at 09:33:14AM -0700, domi8space wrote:

I am new to GitHub, which i join to help improving Qucs-based softwares (including Qucs-S), and this is my first post.

(Sorry about Github. Many would prefer keeping the stuff together. E.g. on the mailing list. But switching off the message boards here might leave us with even less ...)

https://en.wikipedia.org/wiki/Lambert_W_function

Thanks for sharing. Can you give a quick explanation how you would use the function? Do you intend to use it in device modelling or in postprocessing? Do you need real or also complex arguments? How about the branch selection? Please provide an example use, e.g. in terms of a Qucsator netlist?

Most numerical computation softwares (Maple, Mathematica, Matlab, Scilab, Octave, Python, etc.)

I found a C++ implementation in scipy under a suitable license. According to a comment in the code, it has an issue "close to the branch point". It uses some of the scipy infrastructure. But it might serve as a starting point.

ra3xdh commented 1 month ago

I am new to GitHub, which I join to help improving Qucs-based softwares (including Qucs-S)

This repository is not related to Qucs-S. The issues and proposals for Qucs-S should be reported here: https://github.com/ra3xdh/qucs_s/issues https://github.com/ra3xdh/qucs_s/discussions https://github.com/ra3xdh/qucsator_rf/issues

Because this function can solve many problems that can be found in electronic circuits involving diodes or bipolar transistors

I need more info how this is used for circuit modelling. Usually the resistor connected in series to p-n junction is sufficient and explicit Lambert function is not required. I cannot remember if proprietary circuit simulation software (Spectre, HSPICE) have the support of Lambert function.

domi8space commented 4 weeks ago

Thanks for your replies.

Let me add a few more useful materials to my previous post's mention of existing research about the Lambert W function in the analog electronics domain:

I personally think to use such a function for postprocessing (to plot a theoretical quantity along with the same quantity simulated). However I do not exclude that other people may find it useful for device modelling.

As far as I know, only real arguments are needed. This is the case for the few examples I know.

Please find below the code of a Qucs schematic using Qucsator (Qucs-S 1.1.0). This case uses only the W0 branch with wexp(w)>=0, but there exist circuits that use both branches (W0 and W-1) with wexp(w)<0.

<Qucs Schematic 1.1.0>

<.DC DC1 1 120 -330 0 40 0 0 "26.85" 0 "0.001" 0 "1 pA" 0 "1 uV" 0 "no" 0 "150" 0 "no" 0 "none" 0 "CroutLU" 0> <.SW SW1 1 290 -330 0 65 0 0 "DC1" 1 "lin" 1 "w_ew" 1 "0" 1 "6" 1 "601" 1 "false" 0> <_BJT T1 1 260 70 -81 -26 1 2 "npn" 1 "1e-16" 1 "1" 1 "1" 0 "0" 0 "0" 0 "0" 1 "0" 0 "0" 0 "1.5" 0 "0" 0 "2" 0 "Beta" 1 "1" 0 "0" 0 "0" 0 "0" 0 "0" 0 "0" 0 "0" 0 "0.75" 0 "0.33" 0 "0" 0 "0.75" 0 "0.33" 0 "1.0" 0 "0" 0 "0.75" 0 "0" 0 "0.5" 0 "0.0" 0 "0.0" 0 "0.0" 0 "0.0" 0 "0.0" 0 "26.85" 0 "0.0" 0 "1.0" 0 "1.0" 0 "0.0" 0 "1.0" 0 "1.0" 0 "0.0" 0 "0.0" 0 "3.0" 0 "1.11" 0 "26.85" 0 "1.0" 0> <_BJT T2 1 410 70 8 -26 0 0 "npn" 1 "1e-16" 1 "1" 1 "1" 0 "0" 0 "0" 0 "0" 1 "0" 0 "0" 0 "1.5" 0 "0" 0 "2" 0 "Beta" 1 "1" 0 "0" 0 "0" 0 "0" 0 "0" 0 "0" 0 "0" 0 "0.75" 0 "0.33" 0 "0" 0 "0.75" 0 "0.33" 0 "1.0" 0 "0" 0 "0.75" 0 "0" 0 "0.5" 0 "0.0" 0 "0.0" 0 "0.0" 0 "0.0" 0 "0.0" 0 "26.85" 0 "0.0" 0 "1.0" 0 "1.0" 0 "0.0" 0 "1.0" 0 "1.0" 0 "0.0" 0 "0.0" 0 "3.0" 0 "1.11" 0 "26.85" 0 "1.0" 0> <290 40 290 70 "" 0 0 0 ""> <260 40 290 40 "" 0 0 0 ""> <290 70 380 70 "" 0 0 0 ""> <410 100 410 150 "" 0 0 0 ""> <260 100 260 210 "" 0 0 0 ""> <410 0 410 40 "" 0 0 0 ""> <260 20 260 40 "" 0 0 0 ""> <410 -110 410 -60 "" 0 0 0 ""> <260 -110 260 -40 "" 0 0 0 ""> <140 -110 140 -100 "" 0 0 0 ""> <140 -110 260 -110 "" 0 0 0 ""> <260 -110 410 -110 "" 0 0 0 ""> <"w_sim" #0000ff 2 3 0 0 0> <"Iref" #0000ff 0 3 1 0 0> <"w_sim" #0000ff 0 3 1 0 0> =0. \nThere are other circuits whose electrical quantities depend on the Lambert W function. \nThe most simple is a diode in series with a resistor. \nThere are other circuits, with more complicated expressions, including some \nthat would use the branch W-1 (w*ew<0) as well as the branch W0 with w*ew<0 too. \n\ndomi8space, 25/10/2024">
domi8space commented 4 weeks ago

This repository is not related to Qucs-S. The issues and proposals for Qucs-S should be reported here: https://github.com/ra3xdh/qucs_s/issues https://github.com/ra3xdh/qucs_s/discussions https://github.com/ra3xdh/qucsator_rf/issues

Is it a good practice here to duplicate this request, if justified, in Qucs-S' GitHub as well? If yes I can do it.

I need more info how this is used for circuit modelling. Usually the resistor connected in series to p-n junction is sufficient and explicit Lambert function is not required. I cannot remember if proprietary circuit simulation software (Spectre, HSPICE) have the support of Lambert function.

As stated above, from my point of view this function would be more useful for postprocessing, however I do not exclude that some users may need it for device modelling.

ra3xdh commented 4 weeks ago

Is it a good practice here to duplicate this request, if justified, in Qucs-S' GitHub as well?

No duplication is required. I will keep this in mind while preparing the next version of QucsatorRF.