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?
Solving for implicit functions before starting time
-
- Senior Member
- Posts: 136
- Joined: Tue Mar 14, 2023 2:05 am
- Vensim version: DSS
-
- Super Administrator
- Posts: 4827
- Joined: Wed Mar 05, 2003 3:10 am
Re: Solving for implicit functions before starting time
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Solving for implicit functions before starting time
Another option would be to put a table of solutions (Moody diagram) into a lookup or fitted function.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
-
- Senior Member
- Posts: 136
- Joined: Tue Mar 14, 2023 2:05 am
- Vensim version: DSS
Re: Solving for implicit functions before starting time
This (FIND ZERO) worked perfectly. Thank you.
-
- Senior Member
- Posts: 136
- Joined: Tue Mar 14, 2023 2:05 am
- Vensim version: DSS
Re: Solving for implicit functions before starting time
@tomfid, do you know which would be computationally faster? Would it be the iterative solve with FIND ZERO or the LOOKUP?
-
- Super Administrator
- Posts: 4827
- Joined: Wed Mar 05, 2003 3:10 am
Re: Solving for implicit functions before starting time
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Solving for implicit functions before starting time
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.
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.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
-
- Senior Member
- Posts: 136
- Joined: Tue Mar 14, 2023 2:05 am
- Vensim version: DSS
Re: Solving for implicit functions before starting time
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.