Subject: [Ufl] [Question #164419]: How to compute a pointwise vector product within an ufl-file

From: Norman Lang <[email-masked]>
Date: Mon, 11 Jul 2011 13:25:59 -0000

New question #164419 on UFL:
https://answers.launchpad.net/ufl/+question/164419

i am really new in working with fenics and the packages around. So i have got a question about ufl. I want to generate an input Matrix for an optimal control problem.
So i am writing down my variational form and want to get the expression

                                    L = c*inner(1,v)*ds(1)

in my matrix (c is only an constant). For that i am assembling L to an Vector B via

                          assemble(B, L, NULL, & sub_domains, NULL);

Now i want to pointwise multiply this vector with another vector, called z.
I am writing my main programm in C++ and the pointwise multiplying doesn't make any problem.

My question is now. How could i get the pointwise multiplication into the ufl-file, such that, i don't have to do the multiplication after assembling my vector.

I tried to use the Coefficient class in ufl and later on i tried it with the Function class via

elem=FiniteElement("Lagrange",tetrahedron,1)

z = Coefficient(elem) or z = Function(elem).

With the Coefficient class the multiplication

                        L = z*c*inner(1,v)*ds(1)

does not create an error but the result isn't correct when i'm comparing it with the pointwise operation

                z.*B,        where B is the assembled Vector from above

in MATLAB. So i'm sure i'm not computing a pointwise multiplication of two vectors.
Could you please help me with this problem. It would really help me.

Regards,

Norman

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

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Mon, 11 Jul 2011 16:55:03 +0200

> So i am writing down my variational form and want to get the expression

inner(1, v) does not make any sense to me.
You need to specify more clearly what you're
doing with a small but complete code example.
If v is a scalar, it is the same as just v.
If v is not a scalar, it will trigger an error.

> My question is now. How could i get the pointwise multiplication into the ufl-file, such that, i don't have to do the multiplication after assembling my vector.

Unless you can write what you want into the PDE, you cannot express it with UFL.

UFL is a language for variational forms, not for linear algebra
operations on the assembled global vectors and matrices.

> _______________________________________________
> Mailing list: https://launchpad.net/~ufl
> Post to     : [email-masked]
> Unsubscribe : https://launchpad.net/~ufl
> More help   : https://help.launchpad.net/ListHelp
>

---

From: Norman Lang <[email-masked]>
Date: Mon, 11 Jul 2011 15:51:18 -0000

Question #164419 on UFL changed:
https://answers.launchpad.net/ufl/+question/164419

    Status: Answered => Open

Norman Lang is still having a problem:
elem=FiniteElement("Lagrange",tetrahedron,1) 
v = TestFunction(element)

The expression inner(1, v)*ds(1)  should do the same like v*ds(1) i guess. With that expression i want to generate a vector of length n, where n is the number of grid nodes (because of use of Lagrange, 1) and the vector only has some constant entries on node places of the boundary one (ds(1)).
Later on this should be an input vector of an optimal control problem.

Now i want to create a vector which depends on my spatial coordinate z.
More precise i want to generate a vector of the form

                              B(i)=exp(-50*z(i))*v(i)*ds(1).

The entries of vector should vary over the hight of my working piece.
In my C++ code i could realize that via a pointwise multiplication.

But i want to get that expression into my variational form to generate the right hand side of my system of linear equations which i want to solve with FEniCS.
Because of your answer 

'Unless you can write what you want into the PDE, you cannot express it
with UFL.

UFL is a language for variational forms, not for linear algebra
operations on the assembled global vectors and matrices.'

i think it isn't really possible. So i would be happy if some has got an
other approach for this problem.

I hope one can understand my problem now and i want to thank for the previous answer.

Regards,

Norman

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Mon, 11 Jul 2011 19:06:23 +0200

Hi Norman,

>                              B(i)=exp(-50*z(i))*v(i)*ds(1).

This is ambiguous. Can you write it in (pseudo-)LaTeX?
I interpret your line above as roughly:

V := span{ v_i(x) }
z \in V
z(x) := \sum_i z_i v_i(x)
B_i = exp(-50 z_i)  (  \int_{d\Omega} v_i(x) dx  )

Is that right? Then no, you can't express that in UFL.

> But i want to get that expression into my variational form to generate the right hand side of my system of linear equations which i want to solve with FEniCS.

The variational forms you define in UFL will always be integrated, i.e.
expression*ds(1) means "the integral of (expression) over boundary 1".

> other approach for this problem.

I think your original approach of doing pointwise multiplication
at the linear algebra level is what you have to do.
Unless you can formulate your problem differently.
I don't understand where your equations come from,
so I can't help any more than that.

Martin

---

From: Norman Lang <[email-masked]>
Date: Tue, 12 Jul 2011 06:41:27 -0000

Status: Answered => Solved

Norman Lang confirmed that the question is solved:
I think your help was quite good allthough my explanation wasn't so good. I think i have to search for an other way then writing the pointwise product into the ufl file. Maybe the way has to be computing that stuff on algerbaic level.
At the end i want to thank you for your help.

Norman