MPh-py / MPh

Pythonic scripting interface for Comsol Multiphysics
https://mph.readthedocs.io
MIT License
265 stars 67 forks source link

Fails to start with Comsol 5.3 #96

Closed Quicksilver666 closed 1 year ago

Quicksilver666 commented 1 year ago

Hello new user trying to run MPh with a COMSOL53 Problem is when starting I get an [WinError 126] JVM DLL not found: C:\Program Files\COMSOL\COMSOL53\Multiphysics\java\win64\jre\bin

the dll is actually in the server directory below. i.e. jpype.startJVM('C:/Program Files/COMSOL/COMSOL53/Multiphysics/java/win64/jre/bin/) fails jpype.startJVM('C:/Program Files/COMSOL/COMSOL53/Multiphysics/java/win64/jre/bin/server/') fails jpype.startJVM('C:/Program Files/COMSOL/COMSOL53/Multiphysics/java/win64/jre/bin/server/jvm.dll') works

What can I do to fix this?

john-hen commented 1 year ago

Hi. You can try downgrading: pip install MPh==1.1.6. Not sure if that helps, I can't test with Comsol 5.3.

Quicksilver666 commented 1 year ago

Hmm definitely getting a new error now:

Traceback (most recent call last): File "SourceFile", line 395, in com.comsol.model.util.ModelUtil.loadPreferences File "SourceFile", line 624, in com.comsol.model.util.ServerModelUtil.loadPreferences File "AccessController.java", line -2, in java.security.AccessController.doPrivileged File "SourceFile", line 627, in com.comsol.model.util.ServerModelUtil$16.run File "SourceFile", line 2022, in com.comsol.nativeutil.preferences.Preferences.loadPreferences File "SourceFile", line 2154, in com.comsol.nativeutil.preferences.Preferences.a File "SourceFile", line 2164, in com.comsol.nativeutil.preferences.Preferences.e File "SourceFile", line 45, in com.comsol.nativeutil.preferences.l.a File "SourceFile", line 60, in com.comsol.nativeutil.preferences.l.b File "SourceFile", line 2662, in com.comsol.nativeutil.preferences.Preferences.setPreference File "SourceFile", line 62, in com.comsol.nativeutil.preferences.j.a File "SourceFile", line 33, in com.comsol.nativeutil.preferences.l.preferenceChanged File "SourceFile", line 86, in com.comsol.nativeutil.preferences.l.c File "SourceFile", line 70, in com.comsol.util.classes.bm.k File "SourceFile", line 136, in com.comsol.util.internal.CsPlugin.unregisterPropertyPermission File "SourceFile", line 918, in com.comsol.util.internal.a.o File "SourceFile", line 640, in com.comsol.util.internal.a.G File "SourceFile", line 352, in com.comsol.util.internal.a.z File "SourceFile", line 357, in com.comsol.util.internal.a.a Exception: Java Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:/Projects/sawpython/sawlicious/src/comsolbridge/ComsolSimulation.py", line 13, in client = mph.start(cores=1) File "C:\Projects\sawpython\sawlicious\venv\lib\site-packages\mph\session.py", line 100, in start client = Client(cores=cores, version=version) File "C:\Projects\sawpython\sawlicious\venv\lib\site-packages\mph\client.py", line 203, in init java.loadPreferences() java.lang.NullPointerException: java.lang.NullPointerException

john-hen commented 1 year ago

Well, then I guess the conclusion is that MPh is not compatible with Comsol versions as old as 5.3. I will rephrase that in the documentation, but it already says that only Comsol 5.5 and up have actually been tested. So anything before that is iffy.

The first error is probably due to the fact that I refactored the discovery mechanism in MPh 1.2. Older Comsol versions maybe had a different folder structure, or the content of comsol.ini was somehow different. Hard to say, but not an easy fix even for someone with access to Comsol 5.3 (unlike me).

The second error, with MPh 1.1.6, seems more benign. Commenting out the line that triggers it https://github.com/MPh-py/MPh/blob/7c04ea0a456584e63bc2009564b0346167220d5a/mph/client.py#L203

might just do the trick. Though according to the Comsol 5.3 documentation it should actually work, so I don't know.

Best course of action would of course be to upgrade the Comsol version. Though if you can't do that and feel like hacking the source code, it may help to know that you can install MPh in "editable" mode, with pip install --editable . after downloading and unpacking the source-code archive (of whichever version).