← Back to team overview

dolfin team mailing list archive

Re: DOLFIN_EPS and Expressions

 

On Fri, Feb 11, 2011 at 10:10:51AM -0800, Johan Hake wrote:
> On Friday February 11 2011 09:54:39 Anders Logg wrote:
> > On Fri, Feb 11, 2011 at 08:08:32AM -0800, Johan Hake wrote:
> > > On Friday February 11 2011 01:16:31 Anders Logg wrote:
> > > > How is DOLFIN_EPS treated in Expressions and boundary conditions
> > > > (using compile_subdomains)?
> > > >
> > > > I thought that DOLFIN_EPS was known to the JIT compiler.
> > > >
> > > > Here are somethings I noted while debugging a code:
> > > >
> > > > 1. f = Expression("sin(x[0] + DOLFIN_EPS)") does not compile.
> > > >
> > > > The log file pointed to by the JIT compiler says "syntax error" and the
> > > > generated code in .i file found in the same directory contains this:
> > > >
> > > > class Expression_5d66d4e2b02f54f6088fc61767e40073: public Expression
> > > > {
> > > >
> > > > public:
> > > >   double DOLFIN_EPS;
> > > >   Expression_5d66d4e2b02f54f6088fc61767e40073():Expression()
> > > >   {
> > > >
> > > >     DOLFIN_EPS = 0.0;
> > > >
> > > >   }
> > > >
> > > >   void eval(dolfin::Array<double>& values, const
> > > >   dolfin::Array<double>& x) const
> > > >   {
> > > >
> > > >     values[0] = sin(x[0] + DOLFIN_EPS);
> > > >
> > > >   }
> > > >
> > > > };
> > > >
> > > > So there are two problems here:
> > > >
> > > > 1.a) The JIT compiler fails to compile the Expression f which looks
> > > > like a valid expression to me
> > > >
> > > > 1.b) DOLFIN_EPS is set to zero.
> > >
> > > Now it doesn't.
> >
> > Thanks!
> >
> > > > 2. When trying something similar with compile_subdomains, it seems
> > > > that
> > > >
> > > >   compile_subdomains("x[0] < DOLFIN_EPS")
> > > >
> > > > compiles and produces correct code. In particular the .i file does not
> > > > contain DOLFIN_EPS = 0.0.
> > >
> > > subdomain treats DOLFIN_EPS and on_boundary seperately.
> > >
> > > > But the magic for creating variables is a bit too clever. I had a typo
> > > > which said "DOFLIN_EPS" instead of "DOLFIN_EPS" which compiles without
> > > > any warnings and DOFLIN_EPS is set to zero. That's a litle dangerous.
> > >
> > > You cannot blame your typos on compile expressions ;)
> >
> > I just did! ;-)
> >
> > Would it be possible (and desirable) to require default values for all
> > variables in an Expression?
> >
> > f = Expression("a*x[0]", a=2.0)
> > f.a = 3.0
>
> A good point. It would probably require to hide the kwarg: element, cell,
> degree, into a **kwargs, making them less transparent. We could also add the
> default value **kwargs after the above mention kwargs. If we go for this we
> can end up with syntax like:
>
>   f = Expression("a*x[0]", element=some_element, a=2.0)
>
> instead of:
>
>   f = Expression("a*x[0]", a=2.0, element=some_element)
>
> I think the last syntax makes more sense, but it requires more hidden logics.

If it's important to keep the default argumets visible, you could add
something like variabes = {"a": 2.0, "b": 3.0}.

> > The current implementation is impressively clever to figure out variable
> > names automatically, but it also means that all variable names that
> > are misspelled are automatically set to zero without warning.
>
> It is called a feature ;)

A feature that is almost too clever for its own good. :-)

--
Anders



Follow ups

References