Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

saving comsol model from matlab livelink

Please login with a confirmed email address before reporting spam

Hi,

Until 3.5a, there used to be nice flsave which would save fem structure as comsol's model file. Can somebody tell what is its counterpart in 4.x series? May be I missed something but looking into docs only highlighted mphload. Since comsol's model can no longer be saved even in a mat file using save command, I was wondering how to save results for post-processing?

Thanks

12 Replies Last Post 01.07.2015, 10:43 GMT-4

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 10.02.2011, 03:50 GMT-5
We have exactly the same question. Does anyone have an answer ?

In our case, we lost 5 hours of processing-work because of Windows automatical updates during the night. We weren't able to save or export our work. So, is there any way to save or export a model with matlab ?

Best regards
We have exactly the same question. Does anyone have an answer ? In our case, we lost 5 hours of processing-work because of Windows automatical updates during the night. We weren't able to save or export our work. So, is there any way to save or export a model with matlab ? Best regards

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 10.02.2011, 04:53 GMT-5
in 4.X, if you want save a model object in mph from matlab, you can use :

model.save('filename');

eg. model.save('d:\users\OSCsavetest');

(the 'model' is the object you create with command: model = ModelUtil.create('Model'); it could be other names)

with this command, it allows you to save you model object in m-file too

you can find more detail in documentation: LiveLinkForMATLABUsersGuide.pdf

I don't know if my answer is something you guys expected.

hope it is useful to you

Regards
Honghui
in 4.X, if you want save a model object in mph from matlab, you can use : model.save('filename'); eg. model.save('d:\users\OSCsavetest'); (the 'model' is the object you create with command: model = ModelUtil.create('Model'); it could be other names) with this command, it allows you to save you model object in m-file too you can find more detail in documentation: LiveLinkForMATLABUsersGuide.pdf I don't know if my answer is something you guys expected. hope it is useful to you Regards Honghui

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 10.02.2011, 07:01 GMT-5
If you say it works then this is exactly what I was looking for :)
If you say it works then this is exactly what I was looking for :)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 11.02.2011, 05:46 GMT-5
It works and it was exactly what we were looking for.

Thanx a lot Honghui

Best regards

Alex
It works and it was exactly what we were looking for. Thanx a lot Honghui Best regards Alex

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 09.03.2011, 11:19 GMT-5
And what if you have a M-file that you edited/modified and now want to save it back into the "model" or COMSOL?

Unfortunately, model = ModelUtil.load(<tag>, <filename>) is only for loading a .mph file.

Doing .mph to .m is easy (in COMSOL, File > Save as Model M-file...).
Doing .mph to model is easy (in MATLAB, see above)
Doing model to .mph is easy (in MATLAB, model.save(<filename>))
Doing model to .m is easy (in MATLAB, model.save(<filename>, 'm')

But how to do:
.m to .mph ???
or
.m to model ???


(NOTE: In COMSOL 4.1 there is no option to do a "File open" of a M-file directly)
And what if you have a M-file that you edited/modified and now want to save it back into the "model" or COMSOL? Unfortunately, model = ModelUtil.load(, ) is only for loading a .mph file. Doing .mph to .m is easy (in COMSOL, File > Save as Model M-file...). Doing .mph to model is easy (in MATLAB, see above) Doing model to .mph is easy (in MATLAB, model.save()) Doing model to .m is easy (in MATLAB, model.save(, 'm') But how to do: .m to .mph ??? or .m to model ??? (NOTE: In COMSOL 4.1 there is no option to do a "File open" of a M-file directly)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 08.04.2011, 10:57 GMT-4
I think you can still use model.save('youmodle.mph'); but do not run "model.sol().runAll"

I didn't try, hope it works
I think you can still use model.save('youmodle.mph'); but do not run "model.sol().runAll" I didn't try, hope it works

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 15.08.2012, 09:54 GMT-4
I'm using 4.3, and have found I get an error when I try to save. For example, if I run the following:

Matlab Script:

import com.comsol.model.*
import com.comsol.model.util.*

model = ModelUtil.create('Model');

model.modelPath('N:\Projects\MicFEAModelingPrograms\COMSOL42\BumpedBP\Matlab\');

model.save('test')

I receive the error:

"Error using com.comsol.model.impl.ModelImpl/save
Java exception occurred:
Exception:
com.comsol.util.exceptions.FlException: Could not create temporary model file on server
Messages:
Could not create temporary model file on server"
<stack info>

Any thoughts on what is causing this?
I'm using 4.3, and have found I get an error when I try to save. For example, if I run the following: Matlab Script: import com.comsol.model.* import com.comsol.model.util.* model = ModelUtil.create('Model'); model.modelPath('N:\Projects\MicFEAModelingPrograms\COMSOL42\BumpedBP\Matlab\'); model.save('test') I receive the error: "Error using com.comsol.model.impl.ModelImpl/save Java exception occurred: Exception: com.comsol.util.exceptions.FlException: Could not create temporary model file on server Messages: Could not create temporary model file on server" Any thoughts on what is causing this?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 15.08.2012, 10:55 GMT-4
model.modelPath('N:\Projects\MicFEAModelingPrograms\COMSOL42\BumpedBP\Matlab\');

I don't know what the purpose of the modelPath property is, the documentation is mum on this. But as far as I can tell, it has no purpose.

However, the documentation does have this to say:
Use the function mphsave to save the model object linked to the MATLAB object model:

mphsave(model,'filename')

If the filename specified 'filename' [sic] does not provide a path the file is saved relatively to the local MATLAB path. The file extension determines which format to use (*.mph, *.m or *.java).

Alternatively you can use the save method:

model.save('filename');

If 'filename' does not provide a path the file is saved relatively to the local COMSOL server path.


So I guess in your case, you don't have write access to whatever the "local COMSOL server path" is. (On my machine, model.save() writes to [ComsolDir]\mli\startup for some reason.) I prefer to use mphsave() anyway, as the current Matlab working directory is usually the path I want to write to.
[quote]model.modelPath('N:\Projects\MicFEAModelingPrograms\COMSOL42\BumpedBP\Matlab\');[/quote] I don't know what the purpose of the modelPath property is, the documentation is mum on this. But as far as I can tell, it has no purpose. However, the documentation does have this to say: [quote]Use the function mphsave to save the model object linked to the MATLAB object model: mphsave(model,'filename') If the filename specified 'filename' [sic] does not provide a path the file is saved relatively to the local MATLAB path. The file extension determines which format to use (*.mph, *.m or *.java). Alternatively you can use the save method: model.save('filename'); If 'filename' does not provide a path the file is saved relatively to the local COMSOL server path. [/quote] So I guess in your case, you don't have write access to whatever the "local COMSOL server path" is. (On my machine, model.save() writes to [ComsolDir]\mli\startup for some reason.) I prefer to use mphsave() anyway, as the current Matlab working directory is usually the path I want to write to.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 10.06.2014, 06:58 GMT-4
I have tried to introduce that but there are many things that scapes me. After saving your Matlab file as mphsave, is the file generated a .mph or a .m? what do you do to open it with comsol?
Thanks a lot.
I have tried to introduce that but there are many things that scapes me. After saving your Matlab file as mphsave, is the file generated a .mph or a .m? what do you do to open it with comsol? Thanks a lot.

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 30.06.2015, 15:52 GMT-4
Hi,

I'm now using comsol4.3a and get the same error as yours. Have you figured out the reason for this error?

Thank you!
Hi, I'm now using comsol4.3a and get the same error as yours. Have you figured out the reason for this error? Thank you!

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 01.07.2015, 10:27 GMT-4
This seems to be an issue with that version. I tried the above code in 5.1 and it worked.
This seems to be an issue with that version. I tried the above code in 5.1 and it worked.

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 01.07.2015, 10:43 GMT-4
In my case, it seems that we were running out of the space of server. The problem is solved after I released some space. Anyway, thank you for your response.
In my case, it seems that we were running out of the space of server. The problem is solved after I released some space. Anyway, thank you for your response.

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.