Page 1 of 1

Solving for implicit functions before starting time

Posted: Fri Dec 29, 2023 2:37 am
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?

Re: Solving for implicit functions before starting time

Posted: Fri Dec 29, 2023 7:57 am
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).

Re: Solving for implicit functions before starting time

Posted: Fri Dec 29, 2023 4:02 pm
by tomfid
Another option would be to put a table of solutions (Moody diagram) into a lookup or fitted function.

Re: Solving for implicit functions before starting time

Posted: Tue Jan 02, 2024 12:36 am
by geo_curious
This (FIND ZERO) worked perfectly. Thank you.

Re: Solving for implicit functions before starting time

Posted: Tue Jan 02, 2024 12:58 am
by geo_curious
@tomfid, do you know which would be computationally faster? Would it be the iterative solve with FIND ZERO or the LOOKUP?

Re: Solving for implicit functions before starting time

Posted: Tue Jan 02, 2024 8:41 am
by Administrator
The lookup would almost certainly be faster.

Re: Solving for implicit functions before starting time

Posted: Tue Jan 02, 2024 10:46 pm
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.

Re: Solving for implicit functions before starting time

Posted: Thu Jan 04, 2024 3:42 pm
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.