Replies: 3 comments 3 replies
-
Hi Lukas, that's a great question. I don't know the answer, but would also be interested to know. So maybe we can make some, um… progress here. The Programming Manual of Comsol 5.6 has a section "Handling of Progress Information" on page 917. It mentions some classes which are further explained in section "GUI Classes" on page 925. I can't find those classes in the API reference, but >>> import mph
>>> mph.start()
>>> import com.comsol
>>> dir(com.comsol.model.util.ProgressContext)
['__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__',
'__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__',
'__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'cancel',
'cancelButtonVisibilityUpdated', 'equals', 'finished', 'getClass',
'handleEvent', 'handleProgressError', 'hashCode', 'isCanceled',
'isStopped', 'notify', 'notifyAll', 'progressDescriptionUpdated',
'progressLabelUpdated', 'progressLogUpdated', 'progressUpdated',
'reset', 'setStoppable', 'started', 'stop', 'stopButtonVisibilityUpdated',
'toString', 'wait'] Some of the method names look promising, but I haven't, at this point, looked into what they do at all. It just may be an avenue to pursue. The Programming Manual also explains how to display the progress window as either a Swing or SWT widget. I don't know if this even works from Python (via JPype). I do remember that the Matlab LiveLink has a way of displaying these progress windows as simulations are running. So maybe it is possible from Python as well. However, that's not really what you want here. You don't want Swing or SWT, you have your own GUI framework, Qt. You want access to the progress information only, so you can display it yourself. This could mean registering a callback function, which gets called whenever there is a change in progress, or keep polling the progress status from a separate thread, which could then send a (Qt) signal to the main thread so that the GUI can trigger an update. One thing that should already work, but is a little hacky, is diverting the log to a file, then read it back from disk and parse out the progress information. You can create the log file like so: import mph
client = mph.start()
model = client.load('capacitor.mph')
client.java.showProgress('log.txt')
model.solve() This puts lines containing strings such as |
Beta Was this translation helpful? Give feedback.
-
So it looks like creating and parsing that log file is the best option after all, whereas using Comsol's Here is why… The Java class What we would like to do is something like this: import mph
from jpype import JImplementationFor, JImplements, JOverride
@JImplementationFor('com.comsol.model.util.ProgressContext')
class _ProgressContext:
@JOverride
def started(self):
print('Starting step.')
@JOverride
def progressUpdated(self, value):
print(f'current progress: {round(value*100)}%')
@JOverride
def progressDescriptionUpdated(self, text):
print(f'current step: {text}')
@JOverride
def progressLogUpdated(self, message):
print(f'log message: {message}')
@JOverride
def finished(self, t):
print('Finished step.')
@JImplements('java.lang.Runnable', deferred=True)
class Runner:
@JOverride
def run(self):
model.solve()
client = mph.start()
model = client.load('capacitor.mph')
import com.comsol
worker = com.comsol.model.util.ProgressWorker()
context = com.comsol.model.util.ProgressContext()
worker.setContext(context)
runner = Runner()
worker.run(runner) Already this is a bit inconvenient. To get the progress information sent out, we have to use Comsol's The Java class can only be extended with Java code. Something like this: import com.comsol.model.util.ProgressContext;
public class ProgressContextExtension extends ProgressContext
{
public void started() {
System.out.println("Starting step.");
}
public void progressUpdated(double progress) {
System.out.println(progress);
}
public void progressDescriptionUpdated(String description) {
System.out.println(description);
}
public void progressLogUpdated(String message) {
System.out.println(message);
}
public void finished(Throwable t) {
System.out.println("Finished step.");
}
} Or rather, we'd have the class hold on to the status information it receives so that we can then query it from Python. That Java class needs to be compiled, with a JDK that is not newer than the one Comsol uses. Then put into a Using the Swing widgets should be possible, the JPype documentation has a section on that. But I haven't had the patience to actually try that out. It's certainly a hassle as well, if the Java demo in the Programming Manual (page 917) is any indication. In light of all that, just calling |
Beta Was this translation helpful? Give feedback.
-
Dear Lukas, Thanks by advance. Mat |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
first of all thanks for mph it is great. And now to my question.
Is there a smooth way to get the progress information of COMSOL during the solvation of the model? Like e.g. the progress bar or messages about the current calculation? Would be awesome if I can print it somewhere or illustrate it in my pyqt5 application.
Thanks and best regards,
Lukas
Beta Was this translation helpful? Give feedback.
All reactions