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.

Solving same model in COMSOL and Matlab yields different results

Please login with a confirmed email address before reporting spam

Background:
I have a model created in COMSOL with mostly ellipsoids containing cylinders inside (different material), then joined with each other. Originally it gave me a hard time in meshing because I did not know how to "smooth out" the contact edges where the meshing gets extremely fine, so that it either threw meshing problem or divergent linear solution problem. With trial-and-error for a long time in every possible way, I simplified the model and perhaps marginally resolved the issue. At least, when I directly compute from COMSOL, it never complains.

Problem:
However, as I scripted it into Matlab because I needed to run different cases (where surface potential at some terminal differs), I got "divergence in linear solution," which threw me something like "java util exception."
What I did was simply save the working, solvable model as m-file, and called it from Matlab console, exactly same thing! But Matlab would not cooperate. And this error occurs only at some of the cases that I tried to run. e.g., case 1~4 passed, case 5, takes much longer than usual, then boom - error messages in red.
And also, even for the cases that did run, the solution was different from what was obtained by directly running from COMSOL. By "different," I mean off by more than 20% in some cases, which is way beyond the error margin that I am used to when running COMSOL.

Help:
Did anyone have similar experience? Different solution when running from COMSOL, than running through Matlab?
What differences may occur even though I simply save the COMSOL model as m-file?


Thank you.

8 Replies Last Post 9 apr 2012, 13:24 GMT-4

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2 apr 2012, 16:45 GMT-4
I think the problem is here: "perhaps marginally resolved the issue".
Try to make a model that's stable and doesn't have convergence issues. If the problem "marginally" converges, you might sometimes even see difference from running it in COMSOL twice.

Upload your model and maybe we can come up with better meshing.
I think the problem is here: "perhaps marginally resolved the issue". Try to make a model that's stable and doesn't have convergence issues. If the problem "marginally" converges, you might sometimes even see difference from running it in COMSOL twice. Upload your model and maybe we can come up with better meshing.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 3 apr 2012, 17:51 GMT-4
here is the model. thanks a lot if you can take a look.
here is the model. thanks a lot if you can take a look.


Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 4 apr 2012, 12:45 GMT-4
I can't open your model as I don't have AC/DC module. Can you copy your geometry to a model which uses only COMSOL multiphysics?
I can't open your model as I don't have AC/DC module. Can you copy your geometry to a model which uses only COMSOL multiphysics?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 6 apr 2012, 04:32 GMT-4
how about this time?
i do have a lot of difficulty with the meshing..
how about this time? i do have a lot of difficulty with the meshing..


Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 6 apr 2012, 12:49 GMT-4
I found the problem. It's not meshing but your geometry. You have two edges (130 and 150) which are extremely short: 0.00037 nm. I don't think you meant to have them at all. Modify you geometry sequence to get rid of these edges, and everything should be fine. Other than that, your geometry is very easy to mesh. You can even use default meshing. Unfortunately I can't see you geometry sequence as you provided only .mphbin file.
I found the problem. It's not meshing but your geometry. You have two edges (130 and 150) which are extremely short: 0.00037 nm. I don't think you meant to have them at all. Modify you geometry sequence to get rid of these edges, and everything should be fine. Other than that, your geometry is very easy to mesh. You can even use default meshing. Unfortunately I can't see you geometry sequence as you provided only .mphbin file.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 9 apr 2012, 04:42 GMT-4
Alex, thank you so much for looking at my file...
First of all, how did you find those two problems? I went into the selection list and went through all of them to double check for any unexpected small edges... and got rid of the two mentioned by "merging vertices," although it really isnt my original intention to create those two small parts and against the whole point of "automating creating the model."
However, the problem remains. i guess i really do not see any problem in meshing or else if running through COMSOL interface. but as soon as run it in Matlab, same old red errors occur.
I attached more error descriptions. Feel free to take a look.
P.S. the Matlab .m file needs AC/DC module to run. just thought it would be nice to see what code produced the error..
Alex, thank you so much for looking at my file... First of all, how did you find those two problems? I went into the selection list and went through all of them to double check for any unexpected small edges... and got rid of the two mentioned by "merging vertices," although it really isnt my original intention to create those two small parts and against the whole point of "automating creating the model." However, the problem remains. i guess i really do not see any problem in meshing or else if running through COMSOL interface. but as soon as run it in Matlab, same old red errors occur. I attached more error descriptions. Feel free to take a look. P.S. the Matlab .m file needs AC/DC module to run. just thought it would be nice to see what code produced the error..


Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 9 apr 2012, 04:42 GMT-4
??? Java exception occurred:
Exception:
com.comsol.util.exceptions.FlException: Failed to find a solution
(rethrown as com.comsol.util.exceptions.FlException)
(rethrown as com.comsol.util.exceptions.FlException)
Messages:
The following feature has encountered a problem

The following feature has encountered a problem

Failed to find a solution

Divergence of the linear iterations

Returned solution is not converged
- Feature: Stationary Solver 1 (sol1/s1)
- Error: Failed to find a solution.


Stack trace:

at com.comsol.solver.SolverOperation.addError(Unknown Source)

at com.comsol.solver.SolverOperation.execute(Unknown Source)

at com.comsol.model.internal.impl.SolverSequenceImpl.a(Unknown Source)

at com.comsol.model.internal.impl.SolverSequenceImpl.g(Unknown Source)

at com.comsol.model.internal.impl.SolverSequenceImpl.runAll(Unknown Source)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.comsol.clientserver.impl.JobImpl.run(Unknown Source)

at com.comsol.server.internal.a.a(Unknown Source)

at com.comsol.server.internal.a.a(Unknown Source)

at com.comsol.server.internal.a$a.a(Unknown Source)

at com.comsol.server.internal.a$a.a(Unknown Source)

at com.comsol.server.internal.a$a$a.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: Exception:
com.comsol.util.exceptions.FlException: Failed to find a solution
Messages:
The following feature has encountered a problem

Failed to find a solution

Divergence of the linear iterations

Returned solution is not converged
- Feature: Stationary Solver 1 (sol1/s1)
- Error: Failed to find a solution.


... 17 more



at com.comsol.model.clientserver.ClientManagerImpl.a(Unknown Source)

at com.comsol.model.clientserver.ClientManagerImpl.runServerJob(Unknown Source)

at com.comsol.model.internal.impl.SolverSequenceImpl$ak.a(Unknown Source)

at com.comsol.model.internal.impl.SolverSequenceImpl$ak.execute(Unknown Source)

at com.comsol.model.clientserver.ClientManagerImpl$e.call(Unknown Source)

at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: Exception:
com.comsol.util.exceptions.FlException: Failed to find a solution
(rethrown as com.comsol.util.exceptions.FlException)
Messages:
The following feature has encountered a problem

The following feature has encountered a problem

Failed to find a solution

Divergence of the linear iterations

Returned solution is not converged
- Feature: Stationary Solver 1 (sol1/s1)
- Error: Failed to find a solution.


at com.comsol.solver.SolverOperation.addError(Unknown Source)

at com.comsol.solver.SolverOperation.execute(Unknown Source)

at com.comsol.model.internal.impl.SolverSequenceImpl.a(Unknown Source)

at com.comsol.model.internal.impl.SolverSequenceImpl.g(Unknown Source)

at com.comsol.model.internal.impl.SolverSequenceImpl.runAll(Unknown Source)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.comsol.clientserver.impl.JobImpl.run(Unknown Source)

at com.comsol.server.internal.a.a(Unknown Source)

at com.comsol.server.internal.a.a(Unknown Source)

at com.comsol.server.internal.a$a.a(Unknown Source)

at com.comsol.server.internal.a$a.a(Unknown Source)

at com.comsol.server.internal.a$a$a.run(Unknown Source)

... 3 more

Caused by: Exception:
com.comsol.util.exceptions.FlException: Failed to find a solution
Messages:
The following feature has encountered a problem

The following feature has encountered a problem

Failed to find a solution

Divergence of the linear iterations

Returned solution is not converged
- Feature: Stationary Solver 1 (sol1/s1)
- Error: Failed to find a solution.


... 17 more


Error in ==> finger at 249
model.sol('sol1').runAll;
??? Java exception occurred: Exception: com.comsol.util.exceptions.FlException: Failed to find a solution (rethrown as com.comsol.util.exceptions.FlException) (rethrown as com.comsol.util.exceptions.FlException) Messages: The following feature has encountered a problem The following feature has encountered a problem Failed to find a solution Divergence of the linear iterations Returned solution is not converged - Feature: Stationary Solver 1 (sol1/s1) - Error: Failed to find a solution. Stack trace: at com.comsol.solver.SolverOperation.addError(Unknown Source) at com.comsol.solver.SolverOperation.execute(Unknown Source) at com.comsol.model.internal.impl.SolverSequenceImpl.a(Unknown Source) at com.comsol.model.internal.impl.SolverSequenceImpl.g(Unknown Source) at com.comsol.model.internal.impl.SolverSequenceImpl.runAll(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.comsol.clientserver.impl.JobImpl.run(Unknown Source) at com.comsol.server.internal.a.a(Unknown Source) at com.comsol.server.internal.a.a(Unknown Source) at com.comsol.server.internal.a$a.a(Unknown Source) at com.comsol.server.internal.a$a.a(Unknown Source) at com.comsol.server.internal.a$a$a.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: Exception: com.comsol.util.exceptions.FlException: Failed to find a solution Messages: The following feature has encountered a problem Failed to find a solution Divergence of the linear iterations Returned solution is not converged - Feature: Stationary Solver 1 (sol1/s1) - Error: Failed to find a solution. ... 17 more at com.comsol.model.clientserver.ClientManagerImpl.a(Unknown Source) at com.comsol.model.clientserver.ClientManagerImpl.runServerJob(Unknown Source) at com.comsol.model.internal.impl.SolverSequenceImpl$ak.a(Unknown Source) at com.comsol.model.internal.impl.SolverSequenceImpl$ak.execute(Unknown Source) at com.comsol.model.clientserver.ClientManagerImpl$e.call(Unknown Source) at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: Exception: com.comsol.util.exceptions.FlException: Failed to find a solution (rethrown as com.comsol.util.exceptions.FlException) Messages: The following feature has encountered a problem The following feature has encountered a problem Failed to find a solution Divergence of the linear iterations Returned solution is not converged - Feature: Stationary Solver 1 (sol1/s1) - Error: Failed to find a solution. at com.comsol.solver.SolverOperation.addError(Unknown Source) at com.comsol.solver.SolverOperation.execute(Unknown Source) at com.comsol.model.internal.impl.SolverSequenceImpl.a(Unknown Source) at com.comsol.model.internal.impl.SolverSequenceImpl.g(Unknown Source) at com.comsol.model.internal.impl.SolverSequenceImpl.runAll(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.comsol.clientserver.impl.JobImpl.run(Unknown Source) at com.comsol.server.internal.a.a(Unknown Source) at com.comsol.server.internal.a.a(Unknown Source) at com.comsol.server.internal.a$a.a(Unknown Source) at com.comsol.server.internal.a$a.a(Unknown Source) at com.comsol.server.internal.a$a$a.run(Unknown Source) ... 3 more Caused by: Exception: com.comsol.util.exceptions.FlException: Failed to find a solution Messages: The following feature has encountered a problem The following feature has encountered a problem Failed to find a solution Divergence of the linear iterations Returned solution is not converged - Feature: Stationary Solver 1 (sol1/s1) - Error: Failed to find a solution. ... 17 more Error in ==> finger at 249 model.sol('sol1').runAll;

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 9 apr 2012, 13:24 GMT-4

First of all, how did you find those two problems?


Just looking at your mesh, I noticed that it was very fine around those points. I zoomed in and spotted two extra edges.

I'm not sure what's the problem with running your model with Matlab. Hard to tell without AC/DC module :) But looking at your .m file, why don't you do it through COMSOL interface using parametric sweep? It should be easy enough to implement.
[QUOTE] First of all, how did you find those two problems? [/QUOTE] Just looking at your mesh, I noticed that it was very fine around those points. I zoomed in and spotted two extra edges. I'm not sure what's the problem with running your model with Matlab. Hard to tell without AC/DC module :) But looking at your .m file, why don't you do it through COMSOL interface using parametric sweep? It should be easy enough to implement.

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.