﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
3939	unitChecking does not always find mismatched units	Christoph <buchner@…>	Lennart Ochel	"I just found out that unitChecking does not find some inconsistent units. I had inexplicable simulation problems, until I found out that I had a term in an equation that was accidentally copied in.

The thing is, the term made the equations dimensionally inconsistent, and I have switched on unitChecking to prevent exactly these mistakes. However, this was not picked up when simulating in OMEdit.

Minimal repro example: (equations were enabled one at a time to narrow down the issue)

{{{
model unitCheckingFailure
  parameter Modelica.SIunits.MolarEnthalpy deltaH = -200e3 ""J/mol"";
  parameter Modelica.SIunits.MolarEntropy deltaS = -100 ""J/(mol.K)"";
  parameter Modelica.SIunits.Temperature T0 = 1 ""K"";
  Modelica.SIunits.Temperature T ""K"";
  //Modelica.Constants.R: J/(mol.K)
equation

  //-1/T0 = deltaH - T; //this is wrong and gets picked up, so unit checking works

  //-1/T0 = deltaH/T - deltaS; //(correctly) does not get complaints
  //the following also (correctly) does not get complaints
  //-1/T0 = deltaH/(Modelica.Constants.R*T) - deltaS/(Modelica.Constants.R); 
  
  //the following, however, is dimensionally wrong, but not detected! 
  // compare last term to above equation, additional *T
  -1/T0 = deltaH/(Modelica.Constants.R*T) - deltaS/(Modelica.Constants.R*T); 

  //if we remove Modelica.Constants.R, it starts to detect the unit mismatch!
  //-1/T0 = deltaH/(T) - deltaS/(T); 
end unitCheckingFailure;
}}}

In OMEdit-Options-Simulation, I have +d=initialization --preOptModules+=unitChecking, and the above analysis confirms that it works in principle.
This is on OM nightly OMEdit v1.10.0-dev-134-gb85235d, OpenModelica v1.10.0-dev-572-gcde23af."	defect	closed	high	1.11.0	Backend		fixed		Adrian Pop
