News:

alphaMELTS 1.9 is available at the download and information site.
alphaMELTS 2 standalone & for MATLAB/Python are available on request
(see the Version 2 tab on the download site for more details).
For news of all MELTS software see the MELTS Facebook page.

Main Menu

MATLAB for looping T,P space for specific composition

Started by Ri Cao, February 22, 2023, 06:24:39 AM

Previous topic - Next topic

Ri Cao

Dear Paula and Paul,
This is Ri. It is really nice to meet you in person during the MELTS workshop in Rotorua.

Sorry for my interruption again but I am currently trying to setup the MELTS MATLAB version for Rhyolite-MELTS 1.2.0 to try to run a loop over a wide range of pressures, temperatures and water content.

I started from RC12frac.m script, which we discussed during the workshop. I have some naive questions there:

1: I was wondering are there a way to compute the redox state automatically at a given composition, and a specific redox buffering as we did on Rhyolite-MELTS GUI or AlphaMELTS?

2: I am currently obtaining the major elements LLD data through 'ptpath.getListProperty('dispComposition', 'liquid1', 'FeO')'. I was wondering if that's possible to get the melts.out or phase.tbl files, as generated by RMELTS GUI after each run in Matlab? so that based on the discussion with Paula and Bradley during the poster session, if I loop the script at different pressures (constant T exercise), presumably I can find a path that saves all the output files (i.e., melts-loiq.csv) separately? Thank you very much and I look forward to your response.

Sincerely,
Ri Cao

3: Perhaps

Paula

Hi Ri,

Nice to meet you too! I hope you enjoyed the rest of your time in NZ. To answer your questions:

  • You can add a string that looks like the line in the .melts file to the settings. See tutorial.m in the tutorial folder that came with MELTS_Matlab for more details.
  • By default, the normal *_tbl.txt alphaMELTS output files are written. You can control whether you want the GUI-style melts.out and .tbl files with a string in settings (e.g. "Output: both"). If you open Matlab by double-clicking the application then the output files will go to your home space. Instead, make sure to open Terminal first, navigate to where you want the output files to do and then call Matlab from there, something like "/Applications/MATLAB_R2021b.app/bin/matlab".
You can also use standalone alphaMELTS to post-process the files and make the Phase_mass_tbl.txt file with "run-alphamelts.command -x". See "run-alphamelts.command -h" for more details.

Best wishes,
Paula


Ri Cao

Dear Paula,
Thank you very much for your response and clarification. Sorry for the slow response since I was involved in fieldwork and many teaching assignments this term.

The above questions have all been resolved. I can now successfully use MATLAB-MELTS to reproduce the results of LLD predicted from Rhyolite-MELTS

I have a follow-up question there regarding setting up the automatic running for looping different temperatures, pressures, or bulk compositions (keeping T, P the same for each run).

For instance, I was wondering shall I write a ''for loop'' based on the RC12frac.m file so that can loop around different pressures? What kind of strings or code can I add on top of the original Matlab script that can help me save the output of each run (i.e., at each pressure) separately? Any thoughts on this would be really helpful! Thank you very much.

Best regards,
Ri Cao  [/b]

Paula

Hi Ri,

From memory I think you are on a Mac(?) If so, you can start MATLAB from the Terminal, which is the recommended way anyway, and then you can do terminal shell commands from within your scripts by adding an exclamation point at the start. In fact, it looks like some of the commands you might want (e.g. pwd for 'print working directory', 'cd' for change directory, 'ls' for list) are built into MATLAB itself. E.g.

mkdir testoutput
!mv *.tbl testoutput
!mv *_tbl.txt testoutput
!mv melts.out testoutput

If you are on Windows, it may be a bit more complicated but there is more information in the 'system' command documentation: https://www.mathworks.com/help/matlab/ref/system.html

Paula

Ri Cao

Dear Paula,
Thank you very much for your prompt response and clarification.

Yes, I use a Mac computer so the code below works!

For looping around different pressures or FMQ for the same bulk compositions using Matlab-MELTS, perhaps I can just add a ''for'' loop on top of the original RC12frac.m script so that can work? Thank you very much and I look forward to your response.

Best regards,
Ri Cao


Ri Cao

Great, thanks and that works now. Just a quick question there:

Sometimes, when I tried to loop around different bulk compositions or pressures, MATLAB stopped working and closed automatically. Is there something we can do there to optimize/ resolve this issue? Thank you very much.

Best regards,
Ri

Paula

So, there can be various reasons for that. Have a look at the output in the Terminal for clues. That's why I strongly recommend starting MATLAB from the Terminal command line. It's also possible you are hitting a bug in the code.

You can help it a bit by minimizing how much you jump around in P-T-composition space. So, for example, if you are looping over a random selection of pressures then sort the pressures before you start the loop. Also make sure you stay in the range of compositions that MELTS can deal with (that's an error that will show up in the Terminal output).


Ri Cao

Dear Paula,
Thank you very much for your prompt response and clarification.

Yes, I run the Matlab-MELTS from the terminal.

I have documented the error message from terminal there:
%%%%%%%
Assertion failed: (mxCreateString called with non-UTF-8 input: bulk                oxygen              olivine            orthopyroxene      clinopyroxene      clinopyroxene      biotite            plagioclase        rutile              spinel              water              ?
), function mxArray *(anonymous namespace)::MxCreateStringNCharsT_safe<char>::operator()(const char *, const SourceType *, size_t) const [SourceType = char], file array2.cpp, line 500.
Caught SIGABRT: usually caused by an abort() or assert()
MATLAB_maci64(50312,0x11249be00) malloc: Incorrect checksum for freed object 0x7faf38edf838: probably modified after being freed.
Corrupt value: 0x4500010001000100
MATLAB_maci64(50312,0x11249be00) malloc: *** set a breakpoint in malloc_error_break to debug
Caught SIGABRT: usually caused by an abort() or assert()
Caught SIGILL: illegal instruction
%%%%
Perhaps this is caused by so many minerals precipitating in the system that closes Matlab automatically?


Another scenario where the systems stop automatically and leave an error message. there is:
%%%%%
MATLAB_maci64(51628,0x700003183000) malloc: Incorrect checksum for freed object 0x7f8ba7b2f400: probably modified after being freed.
Corrupt value: 0x0
MATLAB_maci64(51628,0x700003183000) malloc: *** set a breakpoint in malloc_error_break to debug
%%%%%
I have a thought about this, and it seems that this is related to the inhibition of leucite precipitation. For instance, if I remove "Suppress" "leucite" in the settings, then that works.

One exercise I am currently trying to do is generate 1000 random parental magma datasets of Venus composition within the errorbar (1 sigma). I was wondering if there is a way we could ask Matlab to jump or ignore automatically during the run. For instance, perhaps there is a range for each oxide (i.e., SiO2) that we can set before each run? Any thoughts on this will be really helpful! Thank you very much.

Best regards,
Ri Cao

Paula

Hi Ri,

Can you email me the MATLAB script and input that produced these errors, please? From what you say about removing the "Suppress: leucite" line fixing things, I suspect you've hit a genuine bug and the files would be very helpful to track it down.

Are you calling the Find Liquidus function at the start? If so, make sure to check the status string for errors. I think the RCfrac script just prints the status, rather than examining it. I would expect Find Liquidus to return without crashing MATLAB, even if the liquid composition is outside the range spanned by the MELTS liquid model, so you could use that to bypass the equilibration steps that are more likely to crash MATLAB for an illegal composition.

Thanks,
Paula

Ri Cao

Dear Paula,
Thank you very much for your prompt response.

Yes, I have emailed you my modified RC12frac.m.

I incorporated the Find Liquidus function from tutorial.m into RC12frac.m at the beginning of the script, but the problem still exists. Please have a look through it. Thank you very much.

Best regards,
Ri