Opened 10 years ago

Closed 9 years ago

Last modified 8 years ago

#2959 closed enhancement (fixed)

Use of partial, non-redeclared classes is not reported by the front-end

Reported by: Francesco Casella Owned by: Adrian Pop
Priority: blocker Milestone: 1.9.4
Component: Frontend Version: trunk
Keywords: Cc: paolodavide.solano01@…

Description

Consider the following model, obtained by dragging components from the Fluid library in OMEdit:

model Test
  Modelica.Fluid.Vessels.ClosedVolume volume
   (V = 1, use_portsData = false);
  inner Modelica.Fluid.System system;
end Test;

When checking the model, OMC reports:

Warning: Forcing full instantiation of partial class 
  BaseProperties$volume$medium during checkModel.
Error: Internal error - InstUtil.moveBindings:
  Mismatched number of equations and variables.
Error: Error occurred while flattening model Test

When trying to simulate it, OMC reports:

Error occurred while flattening model Test
Illegal to instantiate partial class BaseProperties$volume$medium

The problem with this model is that the replaceble package Medium of the component volume has not been redeclared and defaults to a partial class. The cure is of course to redeclare Medium (in fact, this is not yet possible with OMEdit but that's another story, see #2079).

The trouble is that the error messages refer to the consequences of this problem instead, and are totally obscure to non-experts of the Media/Fluid library, who are clueless about what the heck BaseProperties$volume$medium is. Even more important, they are also clueless about how to fix the problem, that is, redeclare the Medium package. On this issue, see, e.g., ticket:2079#comment:4 and ticket:2079#comment:7.

Would it be possible to get an error message along these lines (please use more appropriate terms if necessary):

Error: component volume contains the definition of a partial package Medium.
Please redeclare it to any package compatible with 
  Modelica.Media.Interfaces.PartialMedium.

This would be a lot more useful.

Change History (14)

comment:1 by Francesco Casella, 10 years ago

Summary: Use of partial, non-redeclared classes is not reported by the font-endUse of partial, non-redeclared classes is not reported by the front-end

comment:2 by Martin Sjölund, 10 years ago

Milestone: 1.9.21.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

comment:3 by Martin Sjölund, 9 years ago

Milestone: 1.9.31.9.4

Moved to new milestone 1.9.4

comment:4 by Francesco Casella, 9 years ago

Cc: paolodavide.solano01@… added
Priority: highblocker

I am constantly getting e-mail of desperate students who try to build some model using Modelica.Fluid, Buildings or ThermoPower, compile it and get reported that equations are missing.

Of course if one doesn't know that these libraries use medium packages and they need to be redeclared, they are completely clueless, as OMEdit currently doesn't show the replaceable package in the parameter window (see also #2079), and the error message doesn't even hint at the root cause of the problem.

I would urge to fix this bug ASAP (together with #2079), because it's really doing wonders at scaring people off OMC for thermofluid applications and building a bad reputation for the tool.

comment:5 by anonymous, 9 years ago

Hello, I just decided to deinstall OM and use alternative after spending 1.5 hours to arrive in this post to find that it will take me quite Long to get started with OM fluid modeling due to this "speciality" - sorry, but not doable for me.

comment:6 by Per Östlund, 9 years ago

This should now be fixed in 91f3526. The example model now gives the error:

[Modelica 3.2.1/Fluid/Interfaces.mo:535:19-537:49:writable] Notification: From here:
[bug2959.mo:2:3-3:34:writable] Error: component volume contains the definition of a partial class Medium.
Please redeclare it to any package compatible with Modelica.Media.Interfaces.PartialMedium.

comment:7 by Per Östlund, 9 years ago

Resolution: fixed
Status: newclosed

Closing since it seems to have been fixed. Please reopen if there are any remaining issues.

comment:8 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.4-1.9.x

Milestone renamed

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

Milestone: 1.9.4-1.9.x1.9.4

Milestone renamed

comment:10 by Christoph <buchner@…>, 8 years ago

When trying to build a reusable model (with an interchangeable Medium based on PartialMedium) containing a Fluid.Vessels.ClosedVolume, I can't successfully check it, and the error message reminds me of this issue. Interestingly, using a FluidPort in the same way is no problem.

model check_2959
  //Medium model common to all components
  replaceable package gas = Modelica.Media.Interfaces.PartialMedium;

  //this checks successfully
  //Check of check_2959 completed successfully.
  //Class check_2959 has 1 equation(s) and 3 variable(s).
  //1 of these are trivial equation(s).
  Modelica.Fluid.Interfaces.FluidPort_a gas_inlet(redeclare package Medium = gas);
  
  //Uncommenting the following line leads to errors when checking
  //Modelica.Fluid.Vessels.ClosedVolume free_volume(V = 0.01, use_portsData = false, redeclare package Medium = gas);  
  
  //Except warnings about a missing system (to be expected), I get
  //[Modelica.Media: 4475:17-4600:23]: Forcing full instantiation of partial class BaseProperties$free_volume$medium during checkModel.
  //[5] 13:54:27 Translation Error
  //Internal error - InstUtil.moveBindings: Mismatched number of equations and variables.

  //[6] 13:54:27 Translation Error
  //Error occurred while flattening model check_2959  
end check_2959;

Is this a recurrence of this bug? Is this a user error? If so, how am I supposed to build and check models containing some Modelica.Fluid components, and a medium selected on instantiation (via redeclare)?

comment:11 by Christoph <buchner@…>, 8 years ago

Additionally: adding a MassFlowSource like this
Modelica.Fluid.Sources.MassFlowSource_T gas_source(nPorts = 1, redeclare package Medium = gas);
works as expected - it warns about forcing full instantiation (as with the ClosedVolume), but the check completes successfully.

comment:12 by Christoph <buchner@…>, 8 years ago

Forgot to add: this is on OMEdit v1.10.0-dev-134-gb85235d, OpenModelica v1.10.0-dev-572-gcde23af.

in reply to:  10 comment:13 by Francesco Casella, 8 years ago

Replying to Christoph <buchner@…>:

When trying to build a reusable model (with an interchangeable Medium based on PartialMedium) containing a Fluid.Vessels.ClosedVolume, I can't successfully check it, and the error message reminds me of this issue. Interestingly, using a FluidPort in the same way is no problem.

Is this a recurrence of this bug? Is this a user error? If so, how am I supposed to build and check models containing some Modelica.Fluid components, and a medium selected on instantiation (via redeclare)?

Please refer to Section 4.7 of the Modelica Specifications for definitions of locally balanced and globally balanced models.

When checking a model with replaceable components (or components obtained by instantiating replaceable classes), only local balancedness should be verified. There is nothing wrong in library model with replaceable components that lack some equations because partial classes are used in the definition - obviously, these will have to be redeclared when actually using the component. On the contrary, if you want to simulate a model, then it has to be globally balanced.

Referring to your example, the connector only contains the package definition to access the medium types and constants, so it doesn't make a difference whether it is partial or non partial. If you instantiate a volume model, then the model is locally balanced, but not globally balanced, because it lacks the actual equations of the medium.

When checking, the tool should recognize the fact that there are partial replaceable classes or components involved, only check local balancedness, and possibly warn that the replaceable classes or components must be redeclared in order to get a working simulation model.

I've opened #3944 on this issue.

comment:14 by Christoph <buchner@…>, 8 years ago

Thanks!

Note: See TracTickets for help on using tickets.