Subject: [Viper-dev] update() not working for Functions?

From: Anders Logg <[email-masked]>
Date: Wed, 19 Mar 2008 23:45:37 +0100

It seems like update() is not working for Functions.

I want to do something like this:

  plot(u, interactive=False)
 
  while t < T:
    
    update(u)

This works when u is a mesh and I move the coordinates, but not when u
is a Function. (The plot never gets redrawn.)

-- 
Anders

---

From: Anders Logg <[email-masked]>
Date: Tue, 25 Mar 2008 12:50:47 +0100

> is a Function. (The plot never gets redrawn.)

I saw that there have been some updates to Viper. Is this one included
among the fixes?

-- 
Anders

---

From: "Martin Sandve Alnæs" <[email-masked]>
Date: Tue, 25 Mar 2008 13:13:03 +0100

No, I just changed Function -> cpp_Function to remove the FFC-dependency.

2008/3/25, Anders Logg <[email-masked]>:
>  _______________________________________________
>  Viper-dev mailing list
>  [email-masked]
>  http://fenics.org/mailman/listinfo/viper-dev
>

-- 
Martin

---

From: Ola Skavhaug <[email-masked]>
Date: Tue, 25 Mar 2008 13:39:06 +0100

> I saw that there have been some updates to Viper. Is this one included

Can you provide a small and self contained example? I'll have a look at it.

Ola

---

From: Anders Logg <[email-masked]>
Date: Tue, 25 Mar 2008 13:55:39 +0100

> Can you provide a small and self contained example? I'll have a look at it.

Yes. Looks like it works for scalars but not for vectors:

from dolfin import *

mesh = UnitSquare(10, 10)

class ScalarFunction(Function):
    def __init__(self, mesh):
        self.t = 0.0
        Function.__init__(self, mesh)

    def eval(self, values, x):
        dx = x[0] - self.t
        dy = x[1] - self.t
        values[0] = exp(-10.0*(dx*dx + dy*dy))

class VectorFunction(Function):
    def __init__(self, mesh):
        self.t = 0.0
        Function.__init__(self, mesh)

    def eval(self, values, x):
        dx = x[0] - self.t
        dy = x[1] - self.t
        values[0] = -dy*exp(-10.0*(dx*dx + dy*dy))
        values[1] = dx*exp(-10.0*(dx*dx + dy*dy))

    def rank(self):
        return 1

    def dim(self, i):
        return 2

# Works nicely for f
f = ScalarFunction(mesh)
plot(f, interactive=False)
for i in range(1000):
    f.t += 0.001
    update(f)

# But not for g
g = VectorFunction(mesh)
plot(g, interactive=False)
for i in range(1000):
    g.t += 0.001
    update(g)

---

From: Ola Skavhaug <[email-masked]>
Date: Tue, 25 Mar 2008 14:49:38 +0100

[snip]

> Yes. Looks like it works for scalars but not for vectors:

[snap]

Should work now. Just pull the latest change set.

Ola

---

From: Anders Logg <[email-masked]>
Date: Tue, 25 Mar 2008 16:07:37 +0100

> Should work now. Just pull the latest change set.

Yes! Looks really nice.

I think I will add this as a demo in DOLFIN.

-- 
Anders