Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving assert messages #4399

Open
HansOlsson opened this issue Apr 26, 2024 · 0 comments
Open

Improving assert messages #4399

HansOlsson opened this issue Apr 26, 2024 · 0 comments
Labels
L: Media Issue addresses Modelica.Media

Comments

@HansOlsson
Copy link
Contributor

HansOlsson commented Apr 26, 2024

Consider the following model:

model ThreeTanksMod
  extends Modelica.Fluid.Examples.Tanks.ThreeTanks(tank1(T_start=272.151));
  annotation (uses(Modelica(version="4.0.0")));
end ThreeTanksMod;

The problem is that tank1.T slightly drops (about 2.5 mK) during the first 100 s, and thus it triggers the following assert:

  assert(tank1.medium.T >= 272.15 and tank1.medium.T <= 403.15, "
Temperature T (= "  +       String(tank1.medium.T)+" K) is not in the allowed range (
"+    "272.15"+" K <= T <= "+"403.15"+" K) required from medium model \""+   "SimpleLiquidWater"+"\".");

Generating:

Temperature T (= 272.15 K) is not
in the allowed range (272.15 K <= T <= 403.15 K)
required from medium model "SimpleLiquidWater".

Failed condition: tank1.medium.T >= 272.15 and tank1.medium.T <= 403.15

It is not clear from the error message that the temperate is just outside the range.
Note that the first part is a string that is generated according to the Modelica specification.

It could be improved as follows:

  • Use more digits in the message, by using String(T, 11) or so
  • Exclude the boundaries in the message, but that would conflict with the actual condition, and excluding that might lead to more problems.
  • Make the assert-text even simpler (perhaps "Temperature is not in the allowed range") and leave the debugging messages to the tools; especially avoid duplicating information that is already part of the code (such as boundaries).

Note that there are may be many such messages so we need a consistent update. And it is likely that most cases of hitting the boundaries will generate such messages, as continuous variables are likely to slowly drift over the boundaries.

@HansOlsson HansOlsson added the L: Media Issue addresses Modelica.Media label Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: Media Issue addresses Modelica.Media
Projects
None yet
Development

No branches or pull requests

1 participant