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
> 
> 



_______________________________________________
Mailing list: https://launchpad.net/~dolfin
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~dolfin
More help   : https://help.launchpad.net/ListHelp

Reply via email to