News:

alphaMELTS 2.3 standalone & for MATLAB/Python is now open source and available on GitHub (https://github.com/magmasource/alphaMELTS).
alphaMELTS 1.9 is available at the legacy download and information site.
For news of all MELTS software see the MELTS Facebook page.

Main Menu

C++ API for alphaMELTS 2 or MELTS

Started by Gabriel Girela, June 28, 2023, 06:26:27 AM

Previous topic - Next topic

Gabriel Girela

Hello,

I wanted to know if there is any C++ API so I can use rhyolite-MELTS inside another C++ code.

If this is not the case, is there a way of using alphaMELTS2 but passing the parameters like composition, pressure, temperature, etc. as terminal arguments, instead of through the input melts file?

Thank you very much,

Gabriel Girela

Paula

I believe ENKI has some C++ code but I don't know the current status.

The alphaMELTS for MATLAB/Python package includes a C library of functions that you could call from C++. Check the MELTSdynamic.h header file for the function prototypes.

Note: some of the variable names in MELTSdynamic.h could be a little deceptive e.g. *entropy is actually pointer to whatever reference quantity is relevant for the current calculation mode, so it could just as easily be reference enthalpy or reference volume, or it may be ignored for isobaric/isothermal calculations.

If you are comfortable reading either Python or MATLAB code then look at meltsengine.py or MELTSengine.m to see exactly what is passed and what is 'returned' (everything is passed by reference, though MATLAB kind of tries to hide this). Search for 'self.status.libalphamelts' in the Python file or 'calllib' in the MATLAB file to locate where the C library functions are invoked.

At one point I was planning to wrap the C library functions in C++, as calls to MATLAB's C++ Library interface resemble calls to Python's ctypes more closely. That had the potential of making it easier to develop and maintain both versions simultaneously, among other advantages.

At the time the MATLAB C++ Library interface was quite new and I couldn't find a way to force it to reload the C++ library, which is a useful feature of the current alphaMELTS for MATLAB version. It looks from the MATLAB documentation like it is possible to reload the library now, so I may revisit writing simple C++ wrappers soon and would welcome any input you have.

Thanks,
Paula