dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #19171
Re: [Question #121743]: How to specify a variable coefficient tensor
Question #121743 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/121743
Status: Open => Answered
Garth Wells proposed the following answer:
On Wed, 2010-08-18 at 19:29 +0000, Jack wrote:
> New question #121743 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/121743
>
> Hi
>
> I'd like to specify a variable coefficient tensor, but not in the ufl form file. A snippet of the ufl form file is:
>
> ==
> D = TensorConstant("triangle")
>
> ....
>
> a = u*v*dx + dt*theta*inner( D*grad(u), grad(v) )*dx
> L = u_old*v*dx - dt*(1-theta) * inner( D*grad(u_old), grad(v) )*dx + dt*theta*f*v*dx
> ==
>
> D is a 2x2 tensor which I construct from main.cpp in a subclass of expression. So, I have:
>
>
> class VariableCoefficientTensor : public Expression {
> public:
> ....
> void eval(Array<double>& values, const Array<double>& x) const {
> ...
> values[0] = some_value;
> values[1] = some_value_too
> };
>
> int main()
> {
> ...
> VariableCoefficientTensor D;
> a.D = D;
> ...
> }
> ==
>
> When I execute the program, I get:
>
> terminate called after throwing an instance of 'std::runtime_error'
> what(): *** Error: Invalid value rank for coefficient 0, got 0 but expecting 2. Did you forget to specify the value rank correctly in an Expression sub class?
>
>
> What's the correct way to go about this?
>
Try
class VariableCoefficientTensor : public Expression
{
public:
VariableCoefficientTensor() : Expression(2, 2) ();
void eval(Array<double>& values, const Array<double>& x) const
{ . . . . }
}
Have a look in dolfin/function/Expression.h for details.
Garth
> Thanks
>
> Jack
>
>
--
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.