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.

Load materials from library with Java API

Please login with a confirmed email address before reporting spam

Hello COMSOL aficianados,

We are working with the Java API for COMSOL here. Let's say you want to load the material copper into your model. It seems, according to the manual, that the only way to get all the material properties is to define them all yourself using e.g.:

myModel.material().create("mat1");
myModel.material("mat1").name("Material name");
myModel.material("mat1").set("roughness",0.1);
myModel.material("mat1").set("shininess",200);
myModel.material("mat1").propertyGroup("def").set("density","8700[kg/m^3]");

etc. ad nauseum for every single material property.

My question - is there a way to just do, using the API, what I would do in the GUI, which is to load the pre-defined material from the COMSOL materials library? Something like:

myModel.material().loadFromLibrary("copper")

and that would automatically just load up everything into the model?


Link to COMSOL 4.2 Java API manual:
nf.nci.org.au/facilities/software/COMSOL/4.2/doc/pdf/mph/COMSOLJavaAPIReferenceGuide.pdf

2 Replies Last Post 2013年3月25日 GMT-4 11:50

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2013年3月22日 GMT-4 13:28
On the suggestion of Mia Johansson at COMSOL, I have submitted this as a support case:

www.comsol.com/support/case/1306339/

I should note that this question applies to LiveLink for MATLAB too, not just the Java API.
On the suggestion of Mia Johansson at COMSOL, I have submitted this as a support case: http://www.comsol.com/support/case/1306339/ I should note that this question applies to LiveLink for MATLAB too, not just the Java API.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2013年3月25日 GMT-4 11:50
From COMSOL support today:


Dear Geoff,

I agree with you, it would be nice if there was a more compact notation for this in the Java API. Unfortunately there is not at this time. The only simplification I guess you could do is to delete the rows which set material parameters which you do not currently use in the model. But on the other hand they may come in handy if you later on develop the model further and add more physics nodes, so really I think the best is just to leave this part of the code "as is" when you save as .java or .m file from the graphical user interface.

Let me know if anything is unclear or if you have any further questions.

Best Regards,

Anna Juhasz
COMSOL Support


I think the way we'll deal with it for now is to write a separate Java library that basically returns COMSOL materials as objects (essentially re-implementing the materials library in Java) so that we only have to write it once. Because we'll be using these materials in many Java files.
From COMSOL support today: [quote] Dear Geoff, I agree with you, it would be nice if there was a more compact notation for this in the Java API. Unfortunately there is not at this time. The only simplification I guess you could do is to delete the rows which set material parameters which you do not currently use in the model. But on the other hand they may come in handy if you later on develop the model further and add more physics nodes, so really I think the best is just to leave this part of the code "as is" when you save as .java or .m file from the graphical user interface. Let me know if anything is unclear or if you have any further questions. Best Regards, Anna Juhasz COMSOL Support [/quote] I think the way we'll deal with it for now is to write a separate Java library that basically returns COMSOL materials as objects (essentially re-implementing the materials library in Java) so that we only have to write it once. Because we'll be using these materials in many Java files.

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.