← Back to team overview

dolfin team mailing list archive

Re: [Question #154609]: compiled Expression error

 

Question #154609 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/154609

    Status: Open => Answered

Johan Hake proposed the following answer:
What version of DOLFIN are you running?

Johan

On Thursday April 28 2011 12:54:59 Chaffra wrote:
> New question #154609 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/154609
> 
> The following example gives me an error. I can't figure out where the
> problem is in my cpp code. Is it because I am using GenericFunction? The
> eval function is overloaded! Any help would be appreciated.
> 
> Thanks,
> Chaffra
> 
>   56 x = numpy.zeros(10)
> ---> 57 tau_n.compute_vertex_values(x,mesh)
>      58 print x
>      59
> RuntimeError: *** Error: Missing eval() function (must be overloaded).
> 
> 
> ______________EXAMPLE____________
> 
> from dolfin import *
> import numpy
> 
> cppcode = """
> class Tau_n1 : public Expression
> {
> public:
>     boost::shared_ptr<GenericFunction> vth;
>     boost::shared_ptr<GenericFunction> total_doping;
>     boost::shared_ptr<GenericFunction> nt_srh;
>     double nref_srh;
>     double sigma;
>     double gamma;
> 
>     Tau_n1() : Expression() {}
> 
>     void eval(Array<double>& values, const Array<double>& x) const
>     {
>         double _vth = (*vth)(x[0],x[1],x[2]);
>         double _nt_srh = (*nt_srh)(x[0],x[1],x[2]);
>         double _nt = std::abs( (*total_doping)(x[0],x[1],x[2]) );
> 
>         if (_nt == 0){
>             _nt = _nt_srh;
>         }
>         else{
>             _nt = _nt_srh*std::pow(_nt/nref_srh,gamma);
>         }
>         values[0] = 1.0/(sigma*_nt*_vth);
>     }
> 
>     void eval(Array<double>& values, const Array<double>& x,  const
> ufc::cell& cell) const {
>         eval(values,x);
>     }
> };
> """
> 
> mesh = UnitInterval(11)
> Q = FunctionSpace(mesh,'CG',1)
> 
> tau_n = Expression(cppcode=cppcode)
> tau_n.nt_srh = Constant(1e13)
> tau_n.total_doping = Function(Q)
> tau_n.vth = Constant(1.0)
> tau_n.nref_srh = 1e12
> tau_n.sigma = 1e-6
> tau_n.gamma = 1.76
> 
> x = numpy.zeros(10)
> tau_n.compute_vertex_values(x,mesh)
> print x

-- 
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.