Opened 8 years ago

Last modified 7 years ago

#4115 assigned enhancement

Clarify error message in the absence of voltage reference (ground)

Reported by: Pierre Haessig <pierre.haessig@…> Owned by: Volker Waurich
Priority: normal Milestone: Future
Component: Backend Version: v1.11.0
Keywords: Cc:

Description

When trying to simulate a simple electrical circuit (for example: constant voltage source + resistance) while foregetting to put a voltage reference (ground), the error message is not helpful. It complains about circular inequalities and singular linear systems (see attached Model and log). These messages actually miss the point which that one equation is missing to define electrical potentials. Is is possible to clarify the error message?

In an ideal world, the error message would even suggest the user to add a Ground, but this is maybe too complex (I've no idea of the difficulty of detecting this kind of beginner's mistake).

Attachments (5)

CircuitNoGround.mo (973 bytes ) - added by Pierre Haessig <pierre.haessig@…> 8 years ago.
example model
CircuitNoGround compile log (2.6 KB ) - added by Pierre Haessig <pierre.haessig@…> 8 years ago.
error message when trying to simulate the simple circuit model
VINoGround.mo (1.3 KB ) - added by Pierre Haessig <pierre.haessig@…> 8 years ago.
Electrical circuit with V and I sources
VINoGround translation.log (701 bytes ) - added by Pierre Haessig <pierre.haessig@…> 8 years ago.
translation error of VINoGround.mo model
rL_loops_1.png (9.3 KB ) - added by Volker Waurich 7 years ago.
bipartite graph

Download all attachments as: .zip

Change History (12)

by Pierre Haessig <pierre.haessig@…>, 8 years ago

Attachment: CircuitNoGround.mo added

example model

by Pierre Haessig <pierre.haessig@…>, 8 years ago

Attachment: CircuitNoGround compile log added

error message when trying to simulate the simple circuit model

comment:1 by massimo ceraolo, 8 years ago

Indeed when ground is not there the number of equations is equal to the number of variables, but the system of equations is singular (null determinant).
Consider for instance a circuit composed by a single inductor, without any connection: it has 6 equations and 6 variables (that are easy to list)
But two of the variables are terminal potentials, that cannot be determined; more in general electrical potentials cannot be determined without grounds, even if circuit are balanced (# of equations=number of variables).

The bad news is that a system without ground is balanced in terms of equations and variables, and therefore equation-based simulators have some difficulty in inferring the lack of a ground.
The good news is that this is perhaps the only important case in which people dealing with electrical circuits are disappointed with Modelica. Once this step is overcome, everything is smooth. This is what I've learned from several years of teaching modelica-based simulations.

comment:2 by Pierre Haessig <pierre.haessig@…>, 8 years ago

Thanks for your feedback. I've only some weeks of experience with Modelica, so I don't have all the concepts in mind. When I look at the translation log, I see things like:

The linear system: 
1 : constantVoltage1.p.i + resistor1.p.i = 0.0
2 : resistor1.p.i = -constantVoltage1.p.i
[...] might be structurally or numerically singular for variable resistor1.p.i [...]


which is indeed singular. However, going one step further, the two equations are in fact redundant, so one can be removed. And this is what I mean with "one missing equation".

comment:3 by massimo ceraolo, 8 years ago

Modelica tools count numbers of equations and variables.
A circuit without ground is balanced because the two numbers are equal to each other.

That's why I think that in circuits without ground it would be wrong to say that "one equation is missing".
This is a terminology that can be used in human speaking, but is not correct when the equations and variables are rigidly defined as per Modelica circuits.

Adding ground adds two equations and two variables, keeping the balancing, but thus eliminating the singularity.

by Pierre Haessig <pierre.haessig@…>, 8 years ago

Attachment: VINoGround.mo added

Electrical circuit with V and I sources

by Pierre Haessig <pierre.haessig@…>, 8 years ago

Attachment: VINoGround translation.log added

translation error of VINoGround.mo model

comment:4 by Pierre Haessig <pierre.haessig@…>, 8 years ago

I fully agree with your equation counting. Your detailed explanations have clarified my understanding of the internal modeling process of OMC.

I've made some further experiments with another simple circuit, this time using a current source
instead of a resistor. For this circuit, the error message is quite different, and slightly clearer, since it mentions a lack of equations for voltage potentials:

[1] 09:40:04 Symbolic Error
An independent subset of the model has imbalanced number of equations (5) and variables (6).
variables:
constantCurrent1.n.v
constantCurrent1.p.v
constantCurrent1.v
constantVoltage1.n.v
constantVoltage1.p.v
constantVoltage1.v
equations:
1 : constantVoltage1.v = constantVoltage1.V
2 : constantVoltage1.v = constantVoltage1.p.v - constantVoltage1.n.v
3 : constantCurrent1.v = constantCurrent1.p.v - constantCurrent1.n.v
4 : constantCurrent1.n.v = constantVoltage1.n.v
5 : constantCurrent1.p.v = constantVoltage1.p.v

Anyway, coming back to the original issue, the question is not so much whether the equation system is singular or if there is one missing equation. Instead, it is on how to make OMC detect the lack of a voltage ground in order to print a useful error message like "your circuit may be missing an electrical ground".

Since it seems from the two examples I've tried that the error message from the symbolic engine is very dependent on the particular model, it may not be very reliable to catch the error at this stage.

Instead, a simple approach could be to automatically raise a warning when a model contains electrical components (in particular Modelica.Electrical.Analog.Interfaces.Pin instances), and that no Modelica.Electrical.Analog.Basic.Ground is found. This detection would be crude (it would generate false positives if people have a model that contain a custom Ground-like component), but would be helpful for simple absent-minded/beginner modeling mistakes.

What do people think ?

comment:5 by Francesco Casella, 7 years ago

Component: *unknown*Backend
Owner: changed from somebody to Volker Waurich
Status: newassigned

Five years ago, I published a possible solution to this problem in a paper to the 2012 Modelica Conference, see http://dx.doi.org/10.3384/ecp12076215, Section 5.

The idea is still looking for an implementation.

@vwaurich, do you want to have a look? It may be related to your work on reshuffling.

by Volker Waurich, 7 years ago

Attachment: rL_loops_1.png added

bipartite graph

comment:6 by Volker Waurich, 7 years ago

wrong upload. the graph belongs to ticket #4535

comment:7 by Martin Sjölund, 7 years ago

I guess if we had information about the connectors and the connection sets, the backend could analyze the system. (Just as a diagnostic to be able to print a message to the that grounding some component seems to help)

If we get a singular system and there is a potential variable from a connection set referenced in there, we could force that variable to be set to 0 and see if that improves things. Naturally it could be a bit tricky to find the relevant equation since it might have become 0.0 = 0.0 at this point in time.

But the backend doesn't have information about the connections, and I also suppose there are several different places where the backend fails due to missing ground.

Note: See TracTickets for help on using tickets.