← Back to team overview

dolfin team mailing list archive

Re: [Branch ~dolfin-core/dolfin/main] Rev 5192: Added complex to include files for Expression, so one can use complex numbers

 

Nice.

--
Anders

On Fri, Sep 10, 2010 at 12:02:29PM -0700, Johan Hake wrote:
> Hello!
>
> I am helping a student that needs to use complex calculation in the eval
> method of an Expression. This is now possible using the compiled expression
> interface.
>
> Cheers!
>
> Johan
>
> ##################################################
> from dolfin import *
>
> code = """
>
> class SomeExpr : public Expression
> {
> public:
>
>   // Create expression with 3 components
>   SomeExpr() : Expression(3),param1(0.1), param2(0.2) {}
>   double param1;
>   double param2;
>
>   // Function for evaluating expression on each cell
>   void eval(Array<double>& values, const Data& data) const
>   {
>     std::complex<double> first (param1, param2);
>     std::complex<double> second(std::exp(first));
>     values[0] = second.real();
>   }
>
> };
> """
>
> e = Expression(code)
> e.param1 = 1
> e.param2 = 1
>
>
> On Friday September 10 2010 11:55:49 noreply@xxxxxxxxxxxxx wrote:
> > ------------------------------------------------------------
> > revno: 5192
> > committer: Johan Hake <hake.dev@xxxxxxxxx>
> > branch nick: dolfin
> > timestamp: Fri 2010-09-10 11:42:47 -0700
> > message:
> >   Added complex to include files for Expression, so one can use complex
> > numbers when calculating intermediate values.
> > modified:
> >   site-packages/dolfin/compilemodules/__init__.py
> >
> >
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/ListHelp

--
Anders



References