UFL

How can I specify a constant vector as form coefficient in UFL?

Asked by Florian Rathgeber

I want to evaluate the overhead for coefficient evaluation and with a form like this:

scalar = FiniteElement("Lagrange", "triangle", 1)
vector = VectorElement("Lagrange", "triangle", 1)

v = TestFunction(scalar)
u = TrialFunction(scalar)
u0 = Coefficient(scalar)
b = Coefficient(vector)
f = Coefficient(scalar)

c = 0.05
k = 0.1
alpha = 1.0

a = v*u*dx + k*alpha*u*v*dx + k*c*dot(grad(v), grad(u))*dx
L = v*u0*dx - k*v*dot(b, grad(u0))*dx + k*v*f*dx

My question is how to set the vector coefficient to a UFL form compilation time constant (i.e. they won't show up as coefficients in the generated code).

For u0 and f I can just set them to a float value, but what is the syntax for b? If possible at all.

I tried
tuple: b = (-1.0, 0.0)
list: b = [-1.0, 0.0]
which both give an AttributeError: 'float' object has no attribute 'cell'

Question information

Language:
English Edit question
Status:
Solved
For:
UFL Edit question
Assignee:
No assignee Edit question
Solved by:
Garth Wells
Solved:
Last query:
Last reply:
Revision history for this message
Best Garth Wells (garth-wells) said :
#1

On Wed, 2010-07-21 at 17:06 +0000, Florian Rathgeber wrote:
> New question #118493 on UFL:
> https://answers.launchpad.net/ufl/+question/118493
>
> I want to evaluate the overhead for coefficient evaluation and with a form like this:
>
> scalar = FiniteElement("Lagrange", "triangle", 1)
> vector = VectorElement("Lagrange", "triangle", 1)
>
> v = TestFunction(scalar)
> u = TrialFunction(scalar)
> u0 = Coefficient(scalar)
> b = Coefficient(vector)
> f = Coefficient(scalar)
>
> c = 0.05
> k = 0.1
> alpha = 1.0
>
> a = v*u*dx + k*alpha*u*v*dx + k*c*dot(grad(v), grad(u))*dx L = v*u0*dx
> - k*v*dot(b, grad(u0))*dx + k*v*f*dx
>
> My question is how to set the vector coefficient to a UFL form compilation time constant (i.e. they won't show up as coefficients in the generated code).
>
> For u0 and f I can just set them to a float value, but what is the syntax for b? If possible at all.
>
> I tried
> tuple: b = (-1.0, 0.0)
> list: b = [-1.0, 0.0]
> which both give an AttributeError: 'float' object has no attribute 'cell'
>

b = as_vector([-1.0, 0.0])

I expect that you'll find that the overhead is not insignificant when a
lot of coefficients are present.

Garth

Revision history for this message
Florian Rathgeber (florian-rathgeber) said :
#2

Thanks, had found it in the user manual in the meantime.

The overhead is pretty significant, that is what I found out, yes.

Revision history for this message
Florian Rathgeber (florian-rathgeber) said :
#3

Thanks Garth Wells, that solved my question.

Revision history for this message
Garth Wells (garth-wells) said :
#4

On Fri, 2010-07-23 at 08:47 +0000, Florian Rathgeber wrote:
> Question #118493 on UFL changed:
> https://answers.launchpad.net/ufl/+question/118493
>
> Status: Answered => Solved
>
> Florian Rathgeber confirmed that the question is solved:
> Thanks, had found it in the user manual in the meantime.
>
> The overhead is pretty significant, that is what I found out, yes.
>

Could you post a summary of your results?

Garth

Revision history for this message
Florian Rathgeber (florian-rathgeber) said :
#5

I'll put it together for my thesis, but I can post some results as soon as I have them in digestible form.

Florian