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

3-D vector in expression

+1 vote

I need to make a vectorial function $\vec{\beta} \colon (0,9) \times \Omega \to \mathbb{R}^3$ defined like this:

$$
\beta_0(s,x) = -\frac{1}{2} \frac{x_0}{25-s},\qquad
\beta_1(s,x) = -\frac{1}{2} \frac{x_1}{9-s},\qquad
\beta_2(s,x) = -\frac{1}{2} \frac{x_2}{9-s}
$$

in python-dolfin I do this:

beta = Expression(("(-1/2)*x[0]/(25-s)", "(-1/2)*x[1]/(9-s)", "(-1/2)*x[2]/(25-s)"), s = 0)

but when I call it, return (0,0,0)

>>beta(2,2,2)
array([ 0.,  0.,  0.])

what is wrong?

asked Aug 10, 2013 by ljofre FEniCS Novice (720 points)

1 Answer

+4 votes
 
Best answer

You perform some integer operations instead of floating-point operations. Do rather

beta = Expression(("-0.5*x[0]/(25.0-s)", "-0.5*x[1]/(9.0-s)", "-0.5*x[2]/(25.0-s)"), s=0.0)

(Generally write decimal dot . or scientific notation sign E every time you intent a number being float to avoid many programming errors.)

answered Aug 10, 2013 by Jan Blechta FEniCS Expert (51,420 points)
selected Aug 10, 2013 by Garth N. Wells
...