dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #20845
Re: [Question #142116]: writing a tensor
> in the question 102501, I found similar question and it actually solved my
> problem. I can write the tensor as the answers in question 102501. FEniCS
> doesn't complain about it. But I think that it's not solving problem.
> Here are code and the result
No you are probably not solving you problem. u1c is here interpreted as a
scalar value, which is initiated to 0. You can set the value of that scalar
by:
f00.u1c = some_value
but I guess that ulc really is a Function or another Expression. Then you need
a bit more elaborated Expression. Something like:
code = """
class MyExpr: public Expression
{
public:
boost::shared_ptr<dolfin::GenericFunction> ulc;
MyExpr():Expression()
{}
void eval(dolfin::Array<double>& values, const dolfin::Array<double>& x)
const
{
assert(ulc);
ulc->eval(values, x);
values[0] = (10.45-9.96)/10.45*values[0];
}
};
"""
f00 = Expression(code)
f00.ulc = ulc
ulc.vector()[:]=1
f00(0,0,0)
=> 0.046889952153109919
But... I now see that your expression can be writte directly in ufl which is
much easier:
f00 = (10.45-9.96)/10.45 *u1c
f11 = (5.58-6.05)/5.58 *u1c
f22 = (4.86-4.74)/4.86 *u1c
z = 0
F2= as_matrix(((f00,z,z),(z,f11,z),(z,z,f22)))
Johan
Follow ups
References