MPh-py / MPh

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

Error: `Native object of type MESH is null` #124

Closed sylvanace closed 1 year ago

sylvanace commented 1 year ago

I am trying to run the simulation with a series of values for a parameter in python (same as parametric study, but can export data easier) but I get this issue for some of the values, and if I run it again for this particular value it works.

Code:

import mph
client = mph.start(cores=6)
model=client.load('20230225-Comsol(3D)-ParticleApproach(Cube_vertex_xaxis).mph')
r_ede=model.parameter('r_ede')
l_cube='173.21[um]'
xdises=[0,2,4,6,8,10,15,20,25,30,50,100,300,500,1000,1500,2000]
for x_dis in xdises:
    x_dis=str(x_dis)+'[um]'
    model.parameter('x_dis',x_dis)
    print(model.parameters())
    model.build()
    model.mesh()
    model.solve()
    print('experiment done') 
    model.export(model.exports()[0],f'20230225-Comsol(3D)-Bode_Real-ParticleApproach(Cube_vertex_xaxis,r_ede={r_ede},l_cube={l_cube},x_dis={x_dis}.txt')
    model.export(model.exports()[1],f'20230225-Comsol(3D)-Bode_Imag-ParticleApproach(Cube_vertex_xaxis,r_ede={r_ede},l_cube={l_cube},x_dis={x_dis}.txt')
    model.save(f'2202302025-Comsol(3D)-ParticleApproach(Cube_vertex_xaxis)-{x_dis}')
print('Exp Series Done')

Error: Traceback (most recent call last): File "SourceFile", line 282, in com.comsol.model.impl.StudyImpl.run Exception: Java Exception

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

Traceback (most recent call last): File "d:\OneDrive - University of Southampton\PhD\Second Project\Comsol\20230224-Comsol(3D)-ParticleApproach(Cube_vertex-xaxis)\20230225-Comsol(3D)-ParticleApproach(Cube_vertex_xaxis).py", line 16, in model.solve() 49, in solve node.run() File "C:\Users\jy1u18\AppData\Local\Programs\Python\Python311\Lib\site-packages\mph\node.py", line 546, in run java.run() com.comsol.util.exceptions.com.comsol.util.exceptions.FlException: Exception: com.comsol.util.exceptions.FlException: Native object of type MESH is null. (rethrown as com.comsol.util.exceptions.FlException) Messages: Error in multiphysics compilation Failed to load object Native object of type MESH is null.

john-hen commented 1 year ago

You got a meshing error. That's par for the course when working with Comsol. 🤷 Anyway, this is clearly not an issue with MPh. All it does is tell Comsol to mesh and solve the model. And in this case, it then reports back the error Comsol encountered. That's exactly what it's supposed to do.

sylvanace commented 1 year ago

Hmmm, I'm not sure there is a problem with the mesh, I use the same mesh setting for every loop. It is true that it changes the geometry a little bit but, as I said, it would be fine if I run it again, without changing anything, and running directly in Comsol is not raising any error either.