Solving for implicit functions before starting time

Use this forum to post Vensim related questions.
Post Reply
geo_curious
Member
Posts: 46
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Solving for implicit functions before starting time

Post by geo_curious »

Hi,

I am trying to run a simulation with the Colebrook equation to solve for the Darcy-Weisbach friction coefficient in a flow problem. This is usually solved numerically with iterations. The trick is that I need to solve for the coefficient before proceeding with the rest of the simulation. Is there a way to delay the start of the entire Vensim simulation until the point of convergence for the coefficient? Assume that this initial convergence is simply finding a minimum, then the rest of the model time begins.

Is this possible in one file? If so, could you please recommend a few functions to try with this?
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Solving for implicit functions before starting time

Post by Administrator »

The FIND ZERO function should do what you need. It can loop a section of model structure to try and numerically solve something. There is an example in the help system on how to use it (I'm travelling otherwise I would have pasted the link for you).
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: Solving for implicit functions before starting time

Post by tomfid »

Another option would be to put a table of solutions (Moody diagram) into a lookup or fitted function.
geo_curious
Member
Posts: 46
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Solving for implicit functions before starting time

Post by geo_curious »

This (FIND ZERO) worked perfectly. Thank you.
geo_curious
Member
Posts: 46
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Solving for implicit functions before starting time

Post by geo_curious »

@tomfid, do you know which would be computationally faster? Would it be the iterative solve with FIND ZERO or the LOOKUP?
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Solving for implicit functions before starting time

Post by Administrator »

The lookup would almost certainly be faster.
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: Solving for implicit functions before starting time

Post by tomfid »

I agree. The drawback of a lookup is that it might not be totally general (i.e. you'd have to recompute the values if some assumption changed).

My guess is that the speed penalty for FIND ZERO is small. Unfortunately, you can't wrap FIND ZERO in an INITIAL statement, but you could set the error vector to 0 after INITIAL TIME, which I think would prevent recomputation of the result, making the iteration penalty negligible.
geo_curious
Member
Posts: 46
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Solving for implicit functions before starting time

Post by geo_curious »

In this case, I think it would be sufficient to assume the tubulars I am working with will not change, but if adding complexity to future production changes this would be a problem. Ok, thank you for the responses.
Post Reply