Quoting Martin Sandve Alnæs <martinal@xxxxxxxxx>:
On Thu, May 14, 2009 at 5:59 PM, Garth N. Wells <gnw20@xxxxxxxxx> wrote:
Martin Sandve Alnæs wrote:
On Thu, May 14, 2009 at 9:43 AM, Anders Logg <logg@xxxxxxxxx> wrote:
On Thu, May 14, 2009 at 08:40:41AM +0100, Garth N. Wells wrote:
Martin Sandve Alnæs wrote:
Is there a mathematical difference?
Splitting hairs, I would say yes and that grad(u('+')) is correct and
grad(u)('+') is not because grad(u) is not defined in a classical sense.
I prefer grad(u('+')), but FFC used to use grad(u)('+'). My preference
is however not strong.
My immediate question is will the generated code differ for grad(u('+'))
and grad(u)('+')?
Garth
No, since the restriction will be propagated to the leaves... :-)
The leaves are terminal expressions, that is literal constants,
geometric quantities, functions and basis functions.
"Propagating to the leaves" means modifying for example
(grad(f) + grad(g))('+')
So the above works now? It would be super useful for me.
I don't know what FFC does.
But I implemented the propagation right now, only tested
for a simple case but it's a simple algorithm:
# test_restrictions.py:
from ufl import *
e = FiniteElement("DG", triangle, 1)
f = Function(e)
g = Function(e)
a = (grad(f) + grad(g))('-')
print a
from ufl.algorithms import propagate_restrictions
b = propagate_restrictions(a)
print b
martinal@martinal-znote:~/dev/fenics/ufl/sandbox/algorithmtests$
python test_restrictions.py
((grad(w_0)) + (grad(w_1)))('-')
(grad((w_0)('-'))) + (grad((w_1)('-')))
FFC just needs to apply propagate_restrictions to the integrand of
interior facet integrals.
I just tried it and it appears to be working. However, I got the error:
*** FFC: Not expecting twice restricted expression.
/home/oelgaard/fenics/clone/ffc/scripts/ffc:131: DeprecationWarning:
BaseException.message has been deprecated as of Python 2.6
error(exception.message)
*** FFC: Not expecting twice restricted expression.
*** FFC: To get more information about this error, rerun FFC with --debug.
for the following form (from Garth)
sigma_a = -b*u - gamma*b*(uhat - u)
sigma_d = kappa*grad(u) + (alpha/h)*kappa*(uhat -u)*n('+')
sigma_i = dot(sigma_a + sigma_d, n)
sigma_plus = sigma_i('+')
a = v('+')*sigma_plus*dS
The reason is that sigma_d already contains n('+'). What should happen in a case
like this? For complex forms it is sometimes easier to declare temporary
expressions and in these cases one might accidentally (or intentionally?)
restrict a function multiple times. Should a restriction just be overwritten or
what would you expect Garth for this form?