Subject: [Ufl] Zero form

From: Johan Hake <[email-masked]>
Date: Mon, 1 Nov 2010 16:44:13 -0700

Hello!

I am automating the building of a ufl form. Something like:

  # create list_of_forms
  my_form = Zero()*dx
  for form in list_of_forms:
      my_form += form

For the for loop to work I need to initate my_form to Zero()*dx, because it 
need to be a form. 

Any other ideas of how this can be done? If this is the only way can 
someone(TM) expose 'Zero' to the main ufl namespace? 

It resides in:

  constantvalue.py

Johan

---

From: Kristian Ølgaard <[email-masked]>
Date: Tue, 2 Nov 2010 11:12:09 +0100

> someone(TM) expose 'Zero' to the main ufl namespace?

my_form = reduce(lambda x,y:x+y, list_of_forms)

should do the trick.

On the other hand, I don't see a problem in exposing Zero in the ufl
namespace, it might be convenient in other cases too?

Kristian

> It resides in:
>
>  constantvalue.py
>
> Johan
>
> _______________________________________________
> Mailing list: https://launchpad.net/~ufl
> Post to     : [email-masked]
> Unsubscribe : https://launchpad.net/~ufl
> More help   : https://help.launchpad.net/ListHelp
>

---

From: Andy Ray Terrel <[email-masked]>
Date: Tue, 2 Nov 2010 08:21:10 -0500

If you add Zero, you should probably add One as well.

-- Andy

---

From: Kristian Ølgaard <[email-masked]>
Date: Tue, 2 Nov 2010 14:34:06 +0100

> If you add Zero, you should probably add One as well.

One  is not defined in UFL, Identity is, but I don't know if that can
be used as One if the dimension is equal to 1?
If not, it should not be a problem to add One using Zero as the prototype.

Kristian

---

From: Johan Hake <[email-masked]>
Date: Tue, 2 Nov 2010 09:11:23 -0700

On Tuesday November 2 2010 03:12:09 Kristian Ølgaard wrote:
> > For the for loop to work I need to initate my_form to Zero()*dx, because
> > it need to be a form.
> > 

Thanks for the tip. The loop is a little bit more convoluted than showned here 
so I will probable stick to using Zero().

> namespace, it might be convenient in other cases too?

Thanks!

Johan

---

From: Kristian Ølgaard <[email-masked]>
Date: Tue, 2 Nov 2010 17:34:04 +0100

> so I will probable stick to using Zero().

But still you could loop your forms, append to a list and then use reduce?

Kristian

---

From: Johan Hake <[email-masked]>
Date: Tue, 2 Nov 2010 09:42:00 -0700

On Tuesday November 2 2010 09:34:04 Kristian Ølgaard wrote:
> >> > For the for loop to work I need to initate my_form to Zero()*dx,
> >> > because it need to be a form.
> >> > 
> > Thanks for the tip. The loop is a little bit more convoluted than showned
> > here so I will probable stick to using Zero().
> 

Sure, but doing it my way saves me one line of code! ;)

Johan