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.

plotwhilesolving using java API

Please login with a confirmed email address before reporting spam

I followed the end of the java guide for setting up a gui to run comsol. that worked perfectly. Then, I managed to do it for a time dependent study where it shows the progress bar and everything and then plots the final 2D plot group at the end.

Now, my question, is there a way to have it plot while solving in the GUI window? The guide gives a "PlotWhileSolving" command which I have tried and a few other things but I have not been able to figure it out. Can someone send me the lines of code I would need for the .java file and the .class file to have it show for example a 2D plot while solving?

My idea if this was not possible was have it run in a "for" loop for each output time and have it show the plots that way where the it used a stored solution.

Also, is there some special code needed to have comsol export an image file versus a .txt file? I can get comsol to export a .txt file but not the image file for some reason.

Thank you
Alex

2 Replies Last Post 24 nov 2015, 16:25 GMT-5
COMSOL Moderator

Hello Alexander Warning

Your Discussion has gone 30 days without a reply. If you still need help with COMSOL and have an on-subscription license, please visit our Support Center for help.

If you do not hold an on-subscription license, you may find an answer in another Discussion or in the Knowledge Base.


Josh Thomas Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 28 feb 2013, 17:47 GMT-5
Alex,

Did you ever get the plot while solving to work?

I am newer to using the Java API, but I do have a solution to this (sort of). Follow these steps:

1) Add this line to your main method somewhere before any calls to solving:

model.study("std1").feature("time").set("plot", "on");

2) Add a JButton to the GUI that executes the following commands when clicked:

model.result("pg1").set("window", "window1");
model.result("pg1").run();

Note: This assumes you already have the plot group "pg1" set up to display in the GUI.

3) Now, as the simulation proceeds, anytime you click the JButton the plot group results will refresh and show the current results.

There may be a better way to do this. But, this has worked for me.

Hope that helps some and I would be interested if you have found a different way.

BTW - You seem to be a little more experienced using Java API and Eclipse. In Eclipse, would you be able to explain to me how to package a JAR file that is easily executed in Windows? I have only been able to run my API codes through Eclipse thus far.

Best regards,
Josh Thomas
Alex, Did you ever get the plot while solving to work? I am newer to using the Java API, but I do have a solution to this (sort of). Follow these steps: 1) Add this line to your main method somewhere before any calls to solving: model.study("std1").feature("time").set("plot", "on"); 2) Add a JButton to the GUI that executes the following commands when clicked: model.result("pg1").set("window", "window1"); model.result("pg1").run(); Note: This assumes you already have the plot group "pg1" set up to display in the GUI. 3) Now, as the simulation proceeds, anytime you click the JButton the plot group results will refresh and show the current results. There may be a better way to do this. But, this has worked for me. Hope that helps some and I would be interested if you have found a different way. BTW - You seem to be a little more experienced using Java API and Eclipse. In Eclipse, would you be able to explain to me how to package a JAR file that is easily executed in Windows? I have only been able to run my API codes through Eclipse thus far. Best regards, Josh Thomas

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 24 nov 2015, 16:25 GMT-5
Hello Josh,

an answer to your question to export a jar file using Eclipse:
File->Export...->Java->JAR file
Follow the instructions and fill out the text boxes as you wish.

Greetings
Michael
Hello Josh, an answer to your question to export a jar file using Eclipse: File->Export...->Java->JAR file Follow the instructions and fill out the text boxes as you wish. Greetings Michael

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.