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.

Catching errors in parametric sweeps

Please login with a confirmed email address before reporting spam

Dear all

Is there an elegant way to catch errors in large parametric sweeps?
E.g.: When varying values of parameters one might well reach a point when convergence (or other) problems are encountered.
It would be a very nice feature if COMSOL would log this error and continue the sweep with the next parameter value(s) instead of stopping the whole sweep.
Is this possible even when not running COMSOL via the Matlab interface?
Or would something like the "try catch" method in Matlab be the only way to achieve this?

How do you treat this issues?

Thanks for interesting hints on this and best regards,
Juergen


9 Replies Last Post 01.10.2014, 07:24 GMT-4
Sven Friedel COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 23.09.2014, 03:41 GMT-4
Guten Morgen Jürgen

thanks for your question - this gives me the opportunity to point you to a really nice feature of COMSOL's parametric solver that you might not yet be aware of: "On error"

If you have added a parametric sweep around for example a stationary step in the GUI and created the default solver, you find in the Solver configurations > Stationary Solver > Parametric 1 the setting "on error". The default is "stop" but you can also switch it to "store empty solution". In that case the solver will continue.

See my attached example where a electrical problem is solved for a conductivity = abs(p) for p=-1,0,1.
Clearly, for p=0 the problem is singular, but the solver moves on.

Best regards,
Sven
Guten Morgen Jürgen thanks for your question - this gives me the opportunity to point you to a really nice feature of COMSOL's parametric solver that you might not yet be aware of: "On error" If you have added a parametric sweep around for example a stationary step in the GUI and created the default solver, you find in the Solver configurations > Stationary Solver > Parametric 1 the setting "on error". The default is "stop" but you can also switch it to "store empty solution". In that case the solver will continue. See my attached example where a electrical problem is solved for a conductivity = abs(p) for p=-1,0,1. Clearly, for p=0 the problem is singular, but the solver moves on. Best regards, Sven

Sven Friedel COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 23.09.2014, 03:43 GMT-4
Here comes the file.
Here comes the file.


Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 23.09.2014, 04:44 GMT-4
Dear Sven,

thanks a lot for your reply.
This seems to be exactly what I am looking for.
Unfortunately I cannot open your example model, as we are using Version 4.3b at the moment.

When I tried to find a similar option setting up a parametric sweep around a transient solver, I did not find an "on error" option at a first glance.
There only is a "stop if error" checkbox in the "Job Configuration" node for "Parametric 1", which I could uncheck. But this would not cause anything useful for this issue I guess.
Is the "on error" option new in version 4.4?

Thanks again and best regards,
Juergen
Dear Sven, thanks a lot for your reply. This seems to be exactly what I am looking for. Unfortunately I cannot open your example model, as we are using Version 4.3b at the moment. When I tried to find a similar option setting up a parametric sweep around a transient solver, I did not find an "on error" option at a first glance. There only is a "stop if error" checkbox in the "Job Configuration" node for "Parametric 1", which I could uncheck. But this would not cause anything useful for this issue I guess. Is the "on error" option new in version 4.4? Thanks again and best regards, Juergen

Sven Friedel COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 23.09.2014, 05:11 GMT-4
Hi Jürgen,

that is why we really recommend the latest versions. We are constantly adding valuable features that make life easier. Just download 4.4 - your license does include that version, and you can also install it in parallel on your machine, in case you want some transition time.

Best regards,
Sven
Hi Jürgen, that is why we really recommend the latest versions. We are constantly adding valuable features that make life easier. Just download 4.4 - your license does include that version, and you can also install it in parallel on your machine, in case you want some transition time. Best regards, Sven

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 01.10.2014, 05:17 GMT-4
Dear Sven,

just had a first quick look at version 4.4.
The "on error" option that you mentioned seems to be only available for stationary problems.
I did not find any such thing as an "on error" option in the "time parametric" node of a transient solver.
Is there a similar option available for transient solvers? Should this not be the case do you know if there are any plans to implement one, soon?
This would be a really nice feature and quite a helpful one, too.

Thanks again for more information and best regards,
Juergen
Dear Sven, just had a first quick look at version 4.4. The "on error" option that you mentioned seems to be only available for stationary problems. I did not find any such thing as an "on error" option in the "time parametric" node of a transient solver. Is there a similar option available for transient solvers? Should this not be the case do you know if there are any plans to implement one, soon? This would be a really nice feature and quite a helpful one, too. Thanks again for more information and best regards, Juergen

Sven Friedel COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 01.10.2014, 06:19 GMT-4
Dear Jürgen,

well your initial question indeed did refer only to parametric problems and did not mention time-domain problems ("When varying values of parameters one might well reach a point when convergence (or other) problems are encountered.") I guess you might have both, i.e. a parametric sweep wrapped around a time-dependent study.

In that case you can combine the beforementioned feature "on error" with the "stop condition" in the time dependent solver. Have a look at my example: I have an outer loop for parameters p = -[2, 0.5, 2]
The inner loop solves a time dependent problem from t=0...1

Now I deliberately create a problem for p=0.5. I want that the time dependent solver stops, but the next paramnetr in the sweep will be executed.

1) Add a "stop condition" in Solver Configurations > Solver 1 > Time-dependent solver
In my cse this condition is abs(p)<t. This condition will never be true for p=-2 or p=2 because time runs only til 1. Hoevere for p=0.5 at t=0.5 we will have "a problem".

2) Now I go to Study 1 > Job Configurations > Parametric 1 (this is the wrapper that will call the time dependent solver as a subroutine). There disable the flag "stop if error".

Now you will get a complete solution for p=-2 and 2 but only a solution to t=0.4 for p=0.5.
In that way you can also use checks on your physical parameters, e.g. unphysical values created during a solution.

I hope that helps,

Best regards,
Sven



Dear Jürgen, well your initial question indeed did refer only to parametric problems and did not mention time-domain problems ("When varying values of parameters one might well reach a point when convergence (or other) problems are encountered.") I guess you might have both, i.e. a parametric sweep wrapped around a time-dependent study. In that case you can combine the beforementioned feature "on error" with the "stop condition" in the time dependent solver. Have a look at my example: I have an outer loop for parameters p = -[2, 0.5, 2] The inner loop solves a time dependent problem from t=0...1 Now I deliberately create a problem for p=0.5. I want that the time dependent solver stops, but the next paramnetr in the sweep will be executed. 1) Add a "stop condition" in Solver Configurations > Solver 1 > Time-dependent solver In my cse this condition is abs(p) Job Configurations > Parametric 1 (this is the wrapper that will call the time dependent solver as a subroutine). There disable the flag "stop if error". Now you will get a complete solution for p=-2 and 2 but only a solution to t=0.4 for p=0.5. In that way you can also use checks on your physical parameters, e.g. unphysical values created during a solution. I hope that helps, Best regards, Sven

Sven Friedel COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 01.10.2014, 06:21 GMT-4
The file attached
The file attached


Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 01.10.2014, 06:45 GMT-4
Hi Sven,

sorry that my first post on this issue was not too detailed, that's why I specified it in my second post from Sep, 23rd. And by coincidence that post also contained parts of the solution for the problem as well.
Unchecking the "stop if error" checkbox seems to work.

Thanks for your example model. Inspired by that I made a small change.
Instead of using a somewhat artificial stop condition I varied a certain parameter which I use as denominator to a value inside an "initial value" node.
When the sweep assigns "0" to that denominator value, this will cause an error due to division by zero.
And indeed the parametric sweep continues with the next parameter value.
This is exactly what I was looking for.

The list underneath the "stop if error" checkbox in the "Parametric 1" node now also contains the entry "val, 0" "The following Feature has encountered an error".
Is there a way to automatically export this list that contains all the erroneous parameter values when running the model in batch mode (e.g. with the matlab Interface)?

Many thanks again and best regards,
Juergen
Hi Sven, sorry that my first post on this issue was not too detailed, that's why I specified it in my second post from Sep, 23rd. And by coincidence that post also contained parts of the solution for the problem as well. Unchecking the "stop if error" checkbox seems to work. Thanks for your example model. Inspired by that I made a small change. Instead of using a somewhat artificial stop condition I varied a certain parameter which I use as denominator to a value inside an "initial value" node. When the sweep assigns "0" to that denominator value, this will cause an error due to division by zero. And indeed the parametric sweep continues with the next parameter value. This is exactly what I was looking for. The list underneath the "stop if error" checkbox in the "Parametric 1" node now also contains the entry "val, 0" "The following Feature has encountered an error". Is there a way to automatically export this list that contains all the erroneous parameter values when running the model in batch mode (e.g. with the matlab Interface)? Many thanks again and best regards, Juergen

Sven Friedel COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 01.10.2014, 07:24 GMT-4
Hi Jürgen,

in my example this list is empty. If it contains information in your case I would recommend you loading the file in the LiveLink for matlab interface and use mphnavigator(model) to explore it. In this way you will find the place whre the information is stroed in the model object. Moreover, once you know that you can use a method to extract this information into the workspace.

If you have problems with that I recommend creating a support case out of it, as this becomes a bit too specific for the forum.

Best regards,
Sven
Hi Jürgen, in my example this list is empty. If it contains information in your case I would recommend you loading the file in the LiveLink for matlab interface and use mphnavigator(model) to explore it. In this way you will find the place whre the information is stroed in the model object. Moreover, once you know that you can use a method to extract this information into the workspace. If you have problems with that I recommend creating a support case out of it, as this becomes a bit too specific for the forum. Best regards, Sven

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.