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.

Any way to export/import analytic functions (without MATLAB)?

Please login with a confirmed email address before reporting spam

Perhaps I am missing something, but I don't find any way to export a comsol (user defined) analytic function from a model and to import it in another one.
It is rather heavy to save a .m file, or the generate a Report, and then to cut&paste tens of functions....

Global parameters can be saved, why global functions do not?

A possibility should be that of using the Comsol/Matlab connection and defining all my functions in matlab, but I would like to avoid it.

Suggestions?

6 Replies Last Post 19 juil. 2016, 16:25 UTC−4

Please login with a confirmed email address before reporting spam

Posted: 10 years ago 7 août 2014, 07:53 UTC−4
I am not quite sure what you mean, but you can open Comsol more than once and copy-paste between windows.
I am not quite sure what you mean, but you can open Comsol more than once and copy-paste between windows.

Please login with a confirmed email address before reporting spam

Posted: 10 years ago 7 août 2014, 08:09 UTC−4
Thanks Lasse,

but that's pretty similar to copy and paste from a generated Comsolo Report.
When developing a model sometimes I write 20-30 functions, that I would like to re-use in another model. Today, for example, I build an EM model in 3D and I would like to import functions for dielectric mixtures coming from a different 2D model... I had to do it by hand (with copy & paste).

Roberto
Thanks Lasse, but that's pretty similar to copy and paste from a generated Comsolo Report. When developing a model sometimes I write 20-30 functions, that I would like to re-use in another model. Today, for example, I build an EM model in 3D and I would like to import functions for dielectric mixtures coming from a different 2D model... I had to do it by hand (with copy & paste). Roberto

Maxim Electromobility

Please login with a confirmed email address before reporting spam

Posted: 10 years ago 15 oct. 2014, 11:01 UTC−4
I am looking for the solution too. It seems, that there is no other solution for now, but copy-paste in text format, and manualy adjusting all parameters such as "May produce complex output for real arguments".

Sometimes one can use a workaround:
1) create a user defined material;
2) drag and drope all your functions into the material;
3) save the material in a user difined materil library;
4) in a new (target) file import your new material definded at previous steps, it will be imported with all the functions;
5) drag and drope the functions to the Global definitions node.

The above mentioned scenario works only with Analytic, Interpolation, and Piecewise functions.

The user defined material library is stored in the mph-file. "The file path on Windows might be similar to C:\Users\Your_Name\.comsol\v44\materials" You can take this file with you, to your new COMSOL vertion or to another computer, and import it.

In new vertion 5.0 I still cannot find any sign that one can export functions. However in v5.0 you can refer to the functions stored in your material during solution or postprocessing. Say, in Global probe you can add mat4.def.Cp(T) in an Expression field, or select the corresponding line in the "Replace Expression" drope down menu.

Maxim
I am looking for the solution too. It seems, that there is no other solution for now, but copy-paste in text format, and manualy adjusting all parameters such as "May produce complex output for real arguments". Sometimes one can use a workaround: 1) create a user defined material; 2) drag and drope all your functions into the material; 3) save the material in a user difined materil library; 4) in a new (target) file import your new material definded at previous steps, it will be imported with all the functions; 5) drag and drope the functions to the Global definitions node. The above mentioned scenario works only with Analytic, Interpolation, and Piecewise functions. The user defined material library is stored in the mph-file. "The file path on Windows might be similar to C:\Users\Your_Name\.comsol\v44\materials" You can take this file with you, to your new COMSOL vertion or to another computer, and import it. In new vertion 5.0 I still cannot find any sign that one can export functions. However in v5.0 you can refer to the functions stored in your material during solution or postprocessing. Say, in Global probe you can add mat4.def.Cp(T) in an Expression field, or select the corresponding line in the "Replace Expression" drope down menu. Maxim

Please login with a confirmed email address before reporting spam

Posted: 10 years ago 15 janv. 2015, 12:09 UTC−5


Sometimes one can use a workaround:
1) create a user defined material;
2) drag and drope all your functions into the material;



Pretty cool. This works great. How in the _world_ did you think of it :)
[QUOTE] Sometimes one can use a workaround: 1) create a user defined material; 2) drag and drope all your functions into the material; [/QUOTE] Pretty cool. This works great. How in the _world_ did you think of it :)

Gerardo E. Villarreal-Garcia

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 9 nov. 2015, 13:09 UTC−5
Thanks for the "trick". It's been very useful.

Kind regards
--
Gerardo E. Villarreal-Garcia

Centre for Quantum Photonics
H.H. Wills Physics Laboratory
University of Bristol
Tyndall Avenue
Bristol
BS8 1TL, UK

Email: g.villarreal@bristol.ac.uk
Thanks for the "trick". It's been very useful. Kind regards -- Gerardo E. Villarreal-Garcia Centre for Quantum Photonics H.H. Wills Physics Laboratory University of Bristol Tyndall Avenue Bristol BS8 1TL, UK Email: g.villarreal@bristol.ac.uk

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 19 juil. 2016, 16:25 UTC−4
It's worth adding to this thread the general trick of File -> SaveAs -> File type JAVA model.

If you save your functions to a material library, open that mph file, then save as JAVA,
you'll get a relatively small file with all your functions in it. Yes, there's some cruft you'll
need to delete to use it in another application, but it's better than typing in all those equations from scratch, or cut/pasting them individually.

Also, since you can also import the JAVA file, you can use your favorite editor to
mess with the functions and not have to deal with COMSOL's "assistance" during
their reformulation.
It's worth adding to this thread the general trick of File -> SaveAs -> File type JAVA model. If you save your functions to a material library, open that mph file, then save as JAVA, you'll get a relatively small file with all your functions in it. Yes, there's some cruft you'll need to delete to use it in another application, but it's better than typing in all those equations from scratch, or cut/pasting them individually. Also, since you can also import the JAVA file, you can use your favorite editor to mess with the functions and not have to deal with COMSOL's "assistance" during their reformulation.

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.