How to force a value in a level variable?

Use this forum to post Vensim related questions.
Post Reply
sibanez
Member
Posts: 34
Joined: Sun Jul 05, 2015 10:11 pm
Vensim version: PRO

How to force a value in a level variable?

Post 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
Attachments
Sample forcing zero value in level variable.mdl
(1.6 KiB) Downloaded 368 times
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

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

Post 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
Attachments
Sample forcing zero value in level variable2.mdl
(2.31 KiB) Downloaded 412 times
forcing the level negative with synthesim.vdf
(7.7 KiB) Downloaded 353 times
Last edited by LAUJJL on Mon Dec 14, 2015 9:45 am, edited 1 time in total.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

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

Post 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).
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

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

Post 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)
sibanez
Member
Posts: 34
Joined: Sun Jul 05, 2015 10:11 pm
Vensim version: PRO

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

Post by sibanez »

Hi,

Great hints. Very useful, as usual :)

Thanks a lot!

Santiago
Jacobusdt
Junior Member
Posts: 3
Joined: Wed Dec 09, 2015 9:31 am
Vensim version: PLE

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

Post 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
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

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

Post 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.
Post Reply