Help - Search - Members - Calendar
Full Version: Problem with storing some values at a specific time
Modelica Forum > Modelica > Modelica
Jan
Hello,

I am a newby in Modelica and Dymola. I try to develop a wall heat transfer block for an internal combustion engine.
For this heat transfer I want to store the temperature, the volume and the pressure at the time, the intake valve closes (IVC). Realizing this by the following expression leads to an error message:

CODE

if (Einlass) and mdot_integer==0 then
         Einlass =  false;
         ES =  true;
elseif (Einlass==false) and mdot_integer <> 0 then
         Einlass =  true;
else
      ES =  false;
end if;
  
if ES then
           T_ES =  gas.T;
           p_ES =  gas.P;
           V_ES =  V;
end if;

---------error message:-----------------
QUOTE

Check of heattransfer:
Error: Unable to expand if-statement:
equation
if (Einlass and mdot_integer == 0) then
Einlass = false;
ES = true;
elseif (Einlass == false and mdot_integer <> 0) then
Einlass = true;
else
ES = false;
end if;

Since it was not possible to expand all equations into scalar ones.
the current version can only handle if-statements where
1. The conditions are parameter expressions that can be evaluated
2. The same variable occurs as left-hand-side variable in all branches
3. The equations can be expanded into scalar real equations
4. Combinations of the above.
5. When-statements are only supported if controlled by parameter expresssions that can be evaluated.
Errors or failure to expand the equation:
if (Einlass and mdot_integer == 0) then
Einlass = false;
ES = true;
elseif (Einlass == false and mdot_integer <> 0) then
Einlass = true;
else
ES = false;
end if;
Found in class heattransfer, declaration window at line 52.

Error: Unable to expand if-statement:
if (ES) then
T_ES = gas.T;
p_ES = gas.P;
V_ES = V;
end if;

Since it does not end with an else-clause.
if-statements must end with an else-clause even if they logically exhaust all possibilites.
unless: the conditions are parameters that can be evaluated
or the "equations" are assert or similar constructs.
Errors or failure to expand the equation:
if (ES) then
T_ES = gas.T;
p_ES = gas.P;
V_ES = V;
end if;
Found in class heattransfer, declaration window at line 61.

Errors or failure to expand vector or matrix expressions.
Check aborted.
ERROR: 2 errors were found

---------------------------------------------

Does someone know how to manage this?

Thanks for your help in advance.

Regards,

Jan
Dietmar Winkler
Just have a careful look at the error message. It already states your solution: if-statements must end with an else-clause

QUOTE

Error: Unable to expand if-statement:
if (ES) then
T_ES = gas.T;
p_ES = gas.P;
V_ES = V;
end if;

Since it does not end with an else-clause.
if-statements must end with an else-clause even if they logically exhaust all possibilites.
unless: the conditions are parameters that can be evaluated
or the "equations" are assert or similar constructs.
Jan
I am aware of the error message, but I already tried to append an else part without a content or with a content that did not change anything. It did not work that way.

And what about the other error for the first if clause? There is no problem linked to a missing else part.

So do you know how I can manage to simply store these values (temp., pressure, volume) at a specific time and keep them stored for one turn where they should be replaced with the new values. I already tried to work with an algorithm expression, but there I got some new errors.

---------------------------------
Update:
I managed the error part with the "else clause". By setting only the "if then" part in an "algorithm" it works.
Now is only the upper error message left.
wagner
Hello Jan,

the general problem with your posted model code is the number of equations. As Dietmar Winkler posted before, in an equation section each if-clause needs and else part. More precisely, the number of equations in the if and the else part needs to be the same. In your case, you have 2 equations in the if part, 1 equation in the else if part and 1 equation in the else part.

As an example for storing Real variables over many iterations I've attached a sample model to this post. The model describes a tank system with an prescribed input flow (sine-wave) and an output flow depending of the liquid level in the tank an the control signal to an output valve. The output valve is controlled by a two point controller with hysteresis. It's task is to keep the liquid level in a certain range.

For some reason ( rolleyes.gif ) we want to store the input flow when we close the valve (VdotInOld).

This model should fit to the problem you have. I put a lot of annotations to the model. If this doesn't help, just ask me again.

Regards

Florian
Jan
Hello Florian,

thanks for your help!
As I could see in your code you set the condition part, where it could have some problems of the declaration, to the algorithm section. This is what I did now, as well.

That solved my problem, but a new error message appears. First, I did not read the new appearing error messages carefully. There are not enough equations in the code for the number of unknowns. This problem was not shown before. It seems that Modelica does not show "lighter" errors if more serious ones are present.

Thanks again an Regards,
Jan
____update:_____
I could fix the errors but the values were stored correctly. Instead of the correct the values the start values were set. Then I tried to use "when" expressions instead of the "if" expressions. Now my variables keep their value until they are changed (as it should be :-) )

Tu sum it up for other people who have the same problem: If you do not want to set events for all possibilities it is better to use a "when" expression. "If" is more suitable if you want to define all possible cases.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.