0

Ok, so I have something like this:

model MolarAmount
  import SI = Modelica.SIunits;
  SI.AmountOfSubstance nu "moles of stuff";
  parameter Real lambda = 42 "some variable on which nu depends";

equation
  nu = 1 - lambda;
end MolarAmount;

This runs just fine, but it complains about incompatible units, as expected. How do I get it to ignore this?

Chad
  • 1,434
  • 1
  • 15
  • 30

2 Answers2

1

That is odd. I always thought that Dymola threated literals (1) and variables without units (lambda) as wildcards in the unit checking. You might try setting the units attribute on lambda to be "1" (I thought that was the default). You might also take a look at the diode model in the standard library. It uses a parametric formulation that has to address this kind of unit checking problem as well.

Sorry for not validating any of these suggestions. I don't really have a copy of Dymola handy to test with.

HTH

Michael Tiller
  • 9,291
  • 3
  • 26
  • 41
  • I think the actual expression I WAS using in the code did not have any literals so that may be why it worked differently than you expected. Unfortunately, I am no longer using the section of code that caused this problem so I can't easily check this. It's probably somewhere in my git history, but I can't easily find it. – Chad Oct 06 '14 at 14:00
1

What version of Dymola are you running? Dymola 2015 (2014-04) accepts this model.

I would guess setting lambda(unit="mol") would solve your problems. It also leads to less magic in the unit checking.

sjoelund.se
  • 3,468
  • 12
  • 15
  • My example was not the exact code I'm having a problem with. In the actual code, the expression is a polynomial so a simple fix like this won't work. – Chad Oct 03 '14 at 18:45