Returning time value for a certain variable value ?

Use this forum to post Vensim related questions.
Post Reply
JdX33
Junior Member
Posts: 4
Joined: Thu May 12, 2016 4:08 pm
Vensim version: PLE

Returning time value for a certain variable value ?

Post by JdX33 »

Hello everyone,

I am trying to define an equation that return a time value for a certain auxiliary variable value. I'll explain with an exemple : calculation of an evaporation time.

We want to know how long it takes for rainwater into a container to evaporate. At time=0, there is no water in the container. At time=40, the container begins to fill with water.
We define two variables A and B, respectfully the time when the container water level became positive and the first time after emptying (water level=0).
We can define the emptying time as B-A.

My question is : Is there a function to define those two variables ?

I checked Vensim's help, it seems that it doesn't exist but I may probably be wrong. I precise that I'm working on PLE+ .

Thank you all,

J.
Administrator
Super Administrator
Posts: 4865
Joined: Wed Mar 05, 2003 3:10 am

Re: Returning time value for a certain variable value ?

Post by Administrator »

Try the SAMPLE IF TRUE function, that should do what you need.
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: 4027
Joined: Wed May 24, 2006 4:54 am

Re: Returning time value for a certain variable value ?

Post by tomfid »

SAMPLE IF TRUE solves this problem for advanced versions - I can't remember if it's available in PLE+, but I don't think so.

However, you can use a stock to keep track of times. Something like:
event time.mdl
(3.29 KiB) Downloaded 334 times
JdX33
Junior Member
Posts: 4
Joined: Thu May 12, 2016 4:08 pm
Vensim version: PLE

Re: Returning time value for a certain variable value ?

Post by JdX33 »

SAMPLE IF TRUE is available on PLE+ version, but I don't see how it can solve the problem.
Let's say A=SAMPLE IF TRUE (Container water volume>0, Time, 0), it will not give me the time corresponding to the first positive value for "Container water volume".

Is there a function that formalize that type of equantion : WHEN Container water volume>0, DO A=TIME(first value of "Container water volume">0) ?

J.
tomfid
Administrator
Posts: 4027
Joined: Wed May 24, 2006 4:54 am

Re: Returning time value for a certain variable value ?

Post by tomfid »

See the third example in the SAMPLE IF TRUE help:
https://www.vensim.com/documentation/in ... f_true.htm

The key is to make the condition for updating the sample contingent on:
(a) input>0
(b) sample not yet taken
JdX33
Junior Member
Posts: 4
Joined: Thu May 12, 2016 4:08 pm
Vensim version: PLE

Re: Returning time value for a certain variable value ?

Post by JdX33 »

Thank you all for your answers, it really helps me !

Indeed, I used the third example for my model. I noticed the logical operator :NOT: prevent the variable to give strange results. I'm wondering how it can be so different by defining ":NOT: defined variable" as a first condition ?

Regards,

J.
tomfid
Administrator
Posts: 4027
Joined: Wed May 24, 2006 4:54 am

Re: Returning time value for a certain variable value ?

Post by tomfid »

If you don't include the :NOT: statement, the SAMPLE will update every time the condition is true, so you get the time of the most recent event, not the time of the first event. The logic is essentially the same as in the stock-flow version of the model that I posted.

Incidentally, Vensim uses C-style boolean logic. So, if you use a variable X as the condition in an IF THEN ELSE or SAMPLE IF TRUE, without a comparison like X=0, the condition is false if X=0 and true otherwise. That means that the :NOT: starting time expression only works if starting time is initialized to 0, as it is in the example.
Post Reply