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.

log function

Please login with a confirmed email address before reporting spam

There is a variable psi_init in my model which is defined as follows:
psi_init=((Vt*(((comp1.N<0)*(-log(abs(comp1.p init/ni))))+((comp1.N>=0)*log(abs(comp1.n init/ni)))))-X si)-(0.5*Egap)

The funny thing is that, the parameter inside the log function has an abs() enclosed. Why I got the following error from my solver? Does this mean that abs() function can return a negative value? Or there is a bug from COMSOL?

Failed to find a solution for all parameters,
even when using the minimum parameter step.
Attempt to evaluate real logarithm of negative number.
Function: log
Failed to evaluate variable.
Variable: comp1.psi init, Defined as: ((Vt*(((comp1.N<0)*(-log(abs(comp1.p init/ni))))+((comp1.N>=0)*log(abs(comp1.n init/ni)))))-X si)-(0.5*Egap)
Failed to evaluate variable.
Variable: comp1.es.V0, Defined as: comp1.psi init
Failed to evaluate expression.
Expression: comp1.es.V0-comp1.psi0
Returned solution is not converged.
- Feature: Stationary Solver 1 (sol1/s1)

2 Replies Last Post May 6, 2015, 10:51 a.m. EDT
Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 10 years ago May 6, 2015, 3:14 a.m. EDT
Hi,

It seems the error message is a bit misleading, so what happens here is probably that the value inside of log() becomes zero. The error message that you see then occurs, even if the value is not negative. We will look into improving the error message or behavior when log(0) appears in an expression. You could perhaps add a very small positive number to the expression inside of log() to make sure that the expression stays positive.

Best regards,
Magnus Ringh, COMSOL
Hi, It seems the error message is a bit misleading, so what happens here is probably that the value inside of log() becomes zero. The error message that you see then occurs, even if the value is not negative. We will look into improving the error message or behavior when log(0) appears in an expression. You could perhaps add a very small positive number to the expression inside of log() to make sure that the expression stays positive. Best regards, Magnus Ringh, COMSOL

Please login with a confirmed email address before reporting spam

Posted: 10 years ago May 6, 2015, 10:51 a.m. EDT
Thanks! That resolves the problem. I just add eps inside the log function:
log(blahblahblah+eps)
and it immediately got rid off the error!

Yeah!
Thanks! That resolves the problem. I just add eps inside the log function: log(blahblahblah+eps) and it immediately got rid off the error! Yeah!

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.