This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

solving expression with log10

0 votes

Hello.
I am trying to solve an non linear problem where one of the expressions is depended on the solution and has a log10 in it. Unfortunatly I can't solve the problem as it fails to compile. i have tried the following all leaving me with errors. The T is the TrialFunction, and S is just a constant.

k_T=Expression('pow(10,log10(240+0.00002*S)+0.434*(2.3-(343.5+0.037*S)/(T))*\
            pow((1-(T)/(647+0.03*S)),0.333))/1000.0',T=T,S=S)

This fails to work and gives me an error that it was not complied with Verbose=1.

def thermlaConductivity(T):

      k_T=pow(10,log10(240+0.00002*S)+0.434*(2.3-(343.5+0.037*S)/(T))*\
            pow((1-(T)/(647+0.03*S)),0.333))/1000.0
      return k_T

Doing this will lead error
Couldn't map 'v_1' to a float, returning ufl object without evaluation.

If I do not import math i get that log10 is not defined.

Any help would be appreciated.

asked May 6, 2016 by soviet911 FEniCS Novice (180 points)

I think you cannot use math.log10 for symbolic expressions. However, you can always use the 'change of base formula' to replace log10(x) by log(x)/log(10) if log10 is not defined in UFL (or the subset of C which is used in the compiled expressions). Don't import math.log if you use the UFL way.

Thanks for the response. I have a problem when I try to solve this, how do you define a solution depended expression, my PDE is non linear and the equation is dependent on the value of the solution (the trial function) if I try to solve the following.

 kTest=Expression('1+T',T=T)

where T is a trial function I get the following error.

TypeError: expected default arguments for member variables to be scalars or a scalar GenericFunctions.

So my question is how do I set up an expression like this? and if I write it using Jit-compiling how do I pass T into it?

Thank you.

You should read up on the non-linear syntax of DOLFIN, see the book https://launchpadlibrarian.net/84116499/fenics-manual-2011-10-31.pdf

You have to use Functions instead of trial functions.

Thank you for the suggestion That fixed it. I was following the following guide and you use action to update the TrialFunction with Function (last example) ( http://fenicsproject.org/documentation/tutorial/nonlinear.html )

I replaced it as you suggested and it works now. I have a question when defining a complex expression, is this going to solve just as fast if I typed it out into a single Expression function? I assume it just replaces the variables during compilation and builds a single huge equation? ( The if statements also appear to properly evaluate so you can use if statements as you would in C++?) I really wish some one would write a detailed tutorial on how to write complex Expressions.

T=Function(V)
S=Constant(50.0)
Cp=Expression('(a+b*t+c*t*t+d*t*t*t)*1000.0',a=Constant(1),b=Constant(1) \
          ,c=Constant(1),d=Constant(1),t=T)
Cp.a=Expression('5.328-s*9.76e-2+s*s*4.04e-4',s=S)
Cp.b=Expression('-6.913e-3+s*7.351e-4-s*s*3.15e-6',s=S)
Cp.c=Expression('9.6e-6-s*1.927e-6+s*s*8.23e-9',s=S)
Cp.d=Expression('2.5e-9+s*1.666e-9-s*s*7.125e-12',s=S)
Cp.t=Expression('275.15*(temp<275.15)+375.15*(temp>375.15)+temp*(temp<375.15 &&       temp>275.15)',temp=T)
...