modelica / ModelicaStandardLibrary

Free (standard conforming) library to model mechanical (1D/3D), electrical (analog, digital, machines), magnetic, thermal, fluid, control systems and hierarchical state machines. Also numerical functions and functions for strings, files and streams are included.
https://doc.modelica.org
BSD 3-Clause "New" or "Revised" License
479 stars 169 forks source link

Modelica.Electrical.Analog.Examples.Resistor is not very simple #4471

Open HansOlsson opened 1 month ago

HansOlsson commented 1 month ago

The documentation of Modelica.Electrical.Analog.Examples.Resistor says

This is a very simple circuit consisting of a voltage source and a resistor.

I don't agree with that. Clearly the model looks simple and the electrical part is in itself simple, but the thermal coupling makes the behavior more complicated:

If you look at the code generated by Dymola you see that there's a non-linear system of equations!

The reason is that the thermal part isn't connected to a heat capacitor as one would naïvely expect, but only to a linear thermal conductor. Since the resistor's resistance depend on temperature we therefore have a non-linear system of equations keeping the loss-power (that is v*i or v^2/R(T) right?) in balance with conducted heat power ( G*(T-293.15) ).

I see a number of possibilities:

The current model would be limit if we in the second possibility have a an epsilon-heat capacitor and let epsilon go to zero.

HansOlsson commented 1 month ago

(oops - wrong labels, both started on 'd').

casella commented 1 month ago

Well, the electrical circuit is simple, I can't imagine anything simpler than a resistor connected to an ideal voltage source. The circuit behaviour maybe is not completely trivial because of the dependency of the resistance on the quadratic losses, but the circuit and its behaviour are two different concepts.

Surfing the web I even found "A simple chaotic circuit with a light-emitting diode", so it seems that a simple circuit can even show chaotic behaviour with strange attractors.

Maybe we should include it the Modelica.Electrical examples 😃

AHaumer commented 1 month ago

@HansOlsson what's the problem with a nonlinear set of algebraic equations? @casella To be honest: The "simple chaotic circuit with a light-emitting diode" is not simple, it consists of 4 OpAmps besides the diode. Anyway, yes we could implement that circuit.

HansOlsson commented 1 month ago

@HansOlsson what's the problem with a nonlinear set of algebraic equations?

There's no problem with the equations. However, if a new user looks at the examples and sees a "very simple" circuit, and think that it will be a good starting point to understand models and then sees algebraic equations, they might be a bit surprised.

AHaumer commented 1 month ago

@HansOlsson What's easier with an additional ODE?

IMHO the example is simple and demonstrates:

It can even be solved analytically - witt a linear temperature dependency of resistance it leads to a quadratic equation for temperature.

The new user sees a circuit in the diagram layer which is nearly self-explanatory. Looking into the used components, he could obtain the above mentioned (quadratic) equation. ExamplesResistor

HansOlsson commented 1 month ago

Ok, but even if "simple" could we drop the "very"?

casella commented 1 month ago

No big deal, feel free to open a PR for that 😃

AHaumer commented 1 month ago

@HansOlsson yes we can drop the "very". I admit the circuit is simple but not very simple.

AHaumer commented 1 month ago

@casella here you go: have a preview on the PR. Feel free to comment / change ... I'm not familiar with optoelectronics and chaotic circuits, but I suppose it's a nice test example ;-) Now an ever nicer solution: ChaoticDiodeCircuit.zip For b=1 you can see the same chaotic behavior and for b=1.6 the same periodic behavior as shown in the paper. Hint: In OpenModelica use solver = cvode (works much better than dassl).