Accessing external software tools

49 views
Skip to first unread message

Andreas

unread,
Jun 26, 2015, 8:33:29 AM6/26/15
to am...@googlegroups.com
Hello,
 
we are thinking about using AMPL for our work. Therefore we need to know whether there is some interface to access data evaluated by an external tool.
 
We have a system for thermodynamic properties, that can return for example the value (not the function) of the temperature of a mixture at a given pressure. Finding the optimum temperature could be our modelling task. So, is it possible to declare temperature and pressure as variables, that are evaluated the described way? If it is possible, do we need to provide derivative information, too?
 
Many thanks in advance,
Andreas

Robert Fourer

unread,
Jun 27, 2015, 7:41:23 PM6/27/15
to am...@googlegroups.com
It is possible to write a C function that defines your own AMPL function temp, so that you can write in your model temp(Press) where Press is a variable representing the pressure. In fact you can write temp(...) where ... is an expression involving one or more variables.

If you want your solver to use derivative information, then your function temp must return a derivative as well as a function value. There are solvers that can work without derivative calculations, by estimating derivatives through finite differencing, but usually solvers work faster when derivatives are available.

Instructions for writing the C function are given in the section on "user-defined functions" here: http://ampl.com/REFS/hooking2.pdf#page=19.

Bob Fourer
am...@googlegroups.com

=======

Andreas

unread,
Jun 29, 2015, 5:03:25 AM6/29/15
to am...@googlegroups.com
Thanks a lot for your answer!

maziar kermani

unread,
Sep 22, 2016, 2:53:55 AM9/22/16
to AMPL Modeling Language
Hello,

I was wondering if we can load "coolprop" library in AMPL using loadlib. https://github.com/CoolProp/CoolProp. (It is a C++ library http://www.coolprop.org/)
Do I need to write all the functions in C myself and then compile it into a dll file or I can just load the main dll of coolprop?

Thanks in advance,
Maziar

Robert Fourer

unread,
Sep 23, 2016, 6:28:35 PM9/23/16
to am...@googlegroups.com

To load an external program and call it from AMPL statements, you need to wrap it in a C function following the instructions for "User-defined functions" in Section 4 of Hooking Your Solver to AMPL.  This facility allows for passing arguments to the external program and getting return values.

You can also invoke an external binary by using AMPL's shell command, described in Section A.21 of the AMPL book.  The external program is then spawned as a separate process, however, and communication must be by files.

Bob Fourer
am...@googlegroups.com


maziar kermani

unread,
Sep 26, 2016, 3:10:24 AM9/26/16
to AMPL Modeling Language, 4...@ampl.com
Thank you for the explanation, I will read the book to see if I can write this wrapper for my case.
Reply all
Reply to author
Forward
0 new messages