Subject: [FEniCS-users] using functionals, and trying to find gradients

From: phil marinier <[email-masked]>
Date: Thu, 13 Aug 2009 10:41:27 -0400

Thank you guys for your help, I assumed that V was the default naming convention for FunctionSpaces and never even thought to look.

I have another problem. I hope this one isn't as stupid as the other one. I was going to try and use a functional to get the gradients over my space, then I realised that functionals are scalar, and so obviously I can't do that. My final goal is to get the gradient at a boundary so I can work with them to set a new boundary condition in an iterative process. What I ended up writing was this:

element = FiniteElement("Lagrange", triangle, 1)

v = TestFunction(element)
f = Function(element)

L = v*grad(f)[0]*dx

It compiles and my test program runs:

    Rectangle rectangle(0.0, 0.0, height, length, numH, numL, type);
    Laplace::FunctionSpace V(rectangle);
    Gradients::FunctionSpace VGrad(rectangle);
    Function Phi0(V);
    Function PhiBC0(V);

    PhiBC0.vector().set(phi0);
    Laplace::BilinearForm a(V, V);
    Laplace::LinearForm L(V);
    Gradients::LinearForm LGrad(VGrad);
    Source f(V);
    L.f = f;
    
    Interface interface(height);
    DirichletBC bc0(V, PhiBC0, interface);
    
    VariationalProblem problem0(a, L, bc0);
    problem0.solve(Phi0);
    
    LGrad.f = Phi0;

The problem is that I don't know what to do next. I obviously can't do a VariationalProblem because there is only a linear form, no bilinear form.
I think my problem might be that I don't understand the math enough to figure this out. If that does seem to be the problem, sry for bothering you guys, I'll find a textbook or something and try it again later.

Thanks for your help,

Phil

---

From: Anders Logg <[email-masked]>
Date: Sun, 16 Aug 2009 23:20:47 +0200

On Thu, Aug 13, 2009 at 10:41:27AM -0400, phil marinier wrote:
> Thank you guys for your help, I assumed that V was the default naming
> convention for FunctionSpaces and never even thought to look.
>
> I have another problem. I hope this one isn't as stupid as the other one. I was
> going to try and use a functional to get the gradients over my space, then I
> realised that functionals are scalar, and so obviously I can't do that. My
> final goal is to get the gradient at a boundary so I can work with them to set
> a new boundary condition in an iterative process. What I ended up writing was
> this:
>
>
> The problem is that I don't know what to do next. I obviously can't do a
> VariationalProblem because there is only a linear form, no bilinear form.
> I think my problem might be that I don't understand the math enough to figure
> this out. If that does seem to be the problem, sry for bothering you guys, I'll
> find a textbook or something and try it again later.
>
> Thanks for your help,
>
> Phil

I'm not sure what you are trying to do, but my guess is you want to
project the gradient back to your finite element space. Is that so?

Then just do

 element = VectorElement("Lagrange", triangle, 1)

 v = TestFunction(element)
 u = TrialFunction(element)
 f = Function(element)

 a = (v, du)
 L = (v, grad(f))

Then solve the variational problem to obtain the gradient of f.

--
Anders