Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

IPhreeqc error on MATLAB function

Please login with a confirmed email address before reporting spam

Hi

I'm currently working on COMSOL model which uses MATLAB function node to call IPhreeqc (Phreeqc that can be opened with MATLAB code).

The concept of model is simple, the MATLAB function takes the concentration of various ions from the COMSOL model, and returns fixed concentration calculated by IPhreeqc.

In MATLAB, I wrote a Phreeqc code based on the given information from COMSOL and saved the Phreeqc code as char variable, 'Full_text' in MATLAB. I attached the Full_text.txt, which was created by my code.

Actually, this 'Full_text' works really well if I ran it on MATLAB solely. However, when I tried to use MATLAB function in COMSOL, this 'Full_text' did not worked with error. I captured the error message and attached it.

The error message said that it was unable to open the dump file. The dump file is a kind of data-saving method of IPhreeqc, which saves the information about the result. It is necessary for solving next step calculation.

As you can see on the error message, this error was occurred when IPhreeqc was running (RunString), however, Phreeqc code (Full_text) works really well on MATLAB solely as I mentioned.

Therefore, I guess this problem is originated from COMSOL, but I don''t know how to fix this problem. Please help me with this problem.

I attached the database file for Phreeqc running, too.

Thanks for reading. If you need any more information, please leave me a comment.



5 Replies Last Post 2022年10月4日 GMT-4 06:04
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 2 years ago 2022年10月3日 GMT-4 04:17

Hi Wonwoo

I havne't tried Phreeq so I can't give any specific information.

There may be several problems.

Have you written the functions such as PHREEQC_C yourself? You must make sure that these functions allow a column vector as input. If there is more than one input then all inputs are columns vectors of the same size. We do this because calls to Matlab are expensive and by calling in large batches we save time.

The problem with Phreeq not being able to write a dump file may be due to Phreeq not being able to find a place where it has permission to write the file. Perhaps there is a configuration settings you can use to change this?

-------------------
Lars Gregersen
Comsol Denmark
Hi Wonwoo I havne't tried Phreeq so I can't give any specific information. There may be several problems. Have you written the functions such as PHREEQC_C yourself? You must make sure that these functions allow a column vector as input. If there is more than one input then all inputs are columns vectors of the same size. We do this because calls to Matlab are expensive and by calling in large batches we save time. The problem with Phreeq not being able to write a dump file may be due to Phreeq not being able to find a place where it has permission to write the file. Perhaps there is a configuration settings you can use to change this?

Please login with a confirmed email address before reporting spam

Posted: 2 years ago 2022年10月3日 GMT-4 08:42

Thanks for your reply.

First, yes I wrote PHREEQC_C function by myself. It can take column vectors as input, which I double checked.

Second, dump code in Phreeqc save the dump file in the same folder where the Phreeqc code launched. In this case, Phreeqc is launched on the MATLAB code called by COMSOL, therefore, the dump file should be saved on the folder where the .m file is.

Again thanks for your reply and have a nice day.

Wonwoo Yoon

Thanks for your reply. First, yes I wrote PHREEQC_C function by myself. It can take column vectors as input, which I double checked. Second, dump code in Phreeqc save the dump file in the same folder where the Phreeqc code launched. In this case, Phreeqc is launched on the MATLAB code called by COMSOL, therefore, the dump file should be saved on the folder where the .m file is. Again thanks for your reply and have a nice day. Wonwoo Yoon

Please login with a confirmed email address before reporting spam

Posted: 2 years ago 2022年10月3日 GMT-4 21:10

How about making "Allow externel MATLAB functions" to "Yes" and "File system access" to "All Files" in File > Preferences > Security?

How about making "Allow externel MATLAB functions" to "Yes" and "File system access" to "All Files" in File > Preferences > Security?

Please login with a confirmed email address before reporting spam

Posted: 2 years ago 2022年10月4日 GMT-4 04:49

How about making "Allow externel MATLAB functions" to "Yes" and "File system access" to "All Files" in File > Preferences > Security?

Thanks a lot for your reply Kim.

Now, my Preferences - Security is disabled so I can not change the setting.

However, I'll try that as soon as I figure out how to enable the security tab.

Thanks a lot! Have a nice day.

Wonwoo Yoon

>How about making "Allow externel MATLAB functions" to "Yes" and "File system access" to "All Files" in File > Preferences > Security? Thanks a lot for your reply Kim. Now, my Preferences - Security is disabled so I can not change the setting. However, I'll try that as soon as I figure out how to enable the security tab. Thanks a lot! Have a nice day. Wonwoo Yoon

Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 2 years ago 2022年10月4日 GMT-4 06:04

Thanks for your reply.

First, yes I wrote PHREEQC_C function by myself. It can take column vectors as input, which I double checked.

Can you show the content here?

Second, dump code in Phreeqc save the dump file in the same folder where the Phreeqc code launched. In this case, Phreeqc is launched on the MATLAB code called by COMSOL, therefore, the dump file should be saved on the folder where the .m file is.

Phreeq probably doesn't know where your M-files are stored.

If there isn't a setting in Phreeq that tells it where to look for files then you could try to insert a call to the "cd" command inside your M-files to see if Phreeq responds to setting the "current directory".

-------------------
Lars Gregersen
Comsol Denmark
>Thanks for your reply. > >First, yes I wrote PHREEQC_C function by myself. It can take column vectors as input, which I double checked. Can you show the content here? >Second, dump code in Phreeqc save the dump file in the same folder where the Phreeqc code launched. In this case, Phreeqc is launched on the MATLAB code called by COMSOL, therefore, the dump file should be saved on the folder where the .m file is. Phreeq probably doesn't know where your M-files are stored. If there isn't a setting in Phreeq that tells it where to look for files then you could try to insert a call to the "cd" command inside your M-files to see if Phreeq responds to setting the "current directory".

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.