Page 1 of 1

How to force a value in a level variable?

Posted: Mon Dec 14, 2015 8:13 am
by sibanez
Hi,

I need a level variable to not go below zero and so I am using an IF THEN condition in the 'emptying' rate so that if the level is greater than zero, the 'emptying' rate is non-zero and when the level is equal or less than zero, the 'emptying' rate becomes zero (see simple example attached).

The problem is that, because of timing issues, when the 'emptying rate' is very large, the level goes below zero anyway. So, is there any way I can force a zero value at the level variable when it's level actually goes below zero?

Thank you very much.

Santiago

Re: How to force a value in a level variable?

Posted: Mon Dec 14, 2015 9:23 am
by LAUJJL
Hi

The joined model should work. I have modified the time step to one minute instead of a month to correct unit errors and set an initial level to make it possible to change it in synthesim mode. I have added a value warning that jumps to 1 if the level goes below 0, to make it easy to see it.
Joined is a run that forces the level to negative with synthesim, to make the warning work.
i have added too minimum and maximum for constants for the synthesim and for variables, for checking reasons, a good practice that shows too if the level goes negative.

Regards.

JJ

Re: How to force a value in a level variable?

Posted: Mon Dec 14, 2015 9:40 am
by Administrator
To prevent the level from going below zero, you need to remove the rate you want (RATE) or everything. This is the same as

IF THEN ELSE ( Level / TIME STEP < RATE , Level / TIME STEP , RATE )

Or the following (which is essentially the same thing).

min ( Level / TIME STEP , RATE )

Take out everything (level/time step) or just what you want (RATE).

Re: How to force a value in a level variable?

Posted: Mon Dec 14, 2015 2:39 pm
by tomfid
I tend to use something like the following:

Code: Select all

Indicated outflow = ... (something that could be too big)
Actual outflow = MIN( Indicated outflow, Max outflow )
Max outflow = stock/min time to empty
Min time to empty = ... (TIME STEP or greater)
If there are multiple outflows, you can do something like:

Code: Select all

Desired outflow A = ...
Desired outflow B = ...
Indicated outflow = Desired outflow A + Desired outflow B
Fraction available = MIN(1, ZIDZ(Max outflow/Indicated outflow) )
Actual outflow A = Fraction available * Desired outflow A
Actual outflow B = Fraction available * Desired outflow B
Max outflow = stock/min time to empty
Min time to empty = ... (TIME STEP or greater)

Re: How to force a value in a level variable?

Posted: Mon Dec 14, 2015 8:06 pm
by sibanez
Hi,

Great hints. Very useful, as usual :)

Thanks a lot!

Santiago

Re: How to force a value in a level variable?

Posted: Wed Jan 20, 2016 7:29 pm
by Jacobusdt
Hi All

I have installed Vensim and worked through some examples.

My solution for the problem is fairly simple I think. Just replace the original expression in the model with the following:

IF THEN ELSE(Level>0,IF THEN ELSE( Level>Rate, Rate, Level),0)

The second if then else would check if the level is larger than the rate if it is then the rate would be use, if not the Rate would become the level value. When Level is not >0 the rate would be 0.

It might not be fancy but it all depends on what you want to achieve.

Regards

Jacobus

Re: How to force a value in a level variable?

Posted: Wed Jan 20, 2016 8:28 pm
by tomfid
This is dimensionally inconsistent, because Level has units of stuff, and Rate has units of stuff/time.

The unit error is a hint that you are implicitly assuming TIME STEP = 1, which is not a good idea in general.