Incorrect Gradient Calculated

Asked by Charles Cook

I have a peculiar problem. I am trying to calculate the gradient of a solution and am obtaining incorrect solutions for a particular vector. When I provide another vector I get an apparently correct solution (the sign and trend are correct). When I provide the vector which has trouble, I obtain a strong jump at the boundary with an incorrect sign in the gradient after the boundary.

I am working in C++

ts is the vector which gives me trouble

L_gradT.q = ts;
solve(a_gradT == L_gradT, gradt);

My UFL file

element = FiniteElement("Lagrange", interval, 4)

#Q : Value
q = Coefficient(element)

# gradq : Total derivative of variable
u= TrialFunction(element)
w = TestFunction(element)

a = inner(u,w)*dx
L = inner(grad(q),w)*dx

I know this is open ended, but how should I go about debugging this? Can I change solvers?

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Charles Cook
Solved:
Last query:
Last reply:
Revision history for this message
Charles Cook (charles-4w) said :
#1

Note, the solution also changes with the number of points in the mesh.

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

You need to send the simplest possible complete solver.

Garth

On 17 Nov 2011, at 21:05, Charles Cook <email address hidden> wrote:

> Question #179150 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/179150
>
> Charles Cook posted a new comment:
> Note, the solution also changes with the number of points in the mesh.
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#3

On 17 November 2011 22:05, Charles Cook
<email address hidden> wrote:
> My UFL file
>
> element = FiniteElement("Lagrange", interval, 4)
> q = Coefficient(element)
> u= TrialFunction(element)
> w = TestFunction(element)
>
> a = inner(u,w)*dx
> L = inner(grad(q),w)*dx

Try just

a = u*w*dx
L = q.dx(0)*w*dx

and see if you get the same results.

Then send a minimal runnable code that reproduces the problem.

It's not unlikely that there is a bug related to intervals
somewhere, I believe that is much less used and thus
less tested than 2d and 3d problems in fenics.

Martin

Revision history for this message
Charles Cook (charles-4w) said :
#4

Unfortunately I get the same result with u.dx(0).

Where should I send a minimum runnable example?

Charles

-----Original Message-----
From: <email address hidden> [mailto:<email address hidden>] On Behalf Of Martin Sandve Alnæs
Sent: Friday, November 18, 2011 10:41 AM
To: <email address hidden>
Subject: Re: [Question #179150]: Incorrect Gradient Calculated

Your question #179150 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/179150

Martin Sandve Alnæs proposed the following answer:
On 17 November 2011 22:05, Charles Cook
<email address hidden> wrote:
> My UFL file
>
> element = FiniteElement("Lagrange", interval, 4) q =
> Coefficient(element) u= TrialFunction(element) w =
> TestFunction(element)
>
> a = inner(u,w)*dx
> L = inner(grad(q),w)*dx

Try just

a = u*w*dx
L = q.dx(0)*w*dx

and see if you get the same results.

Then send a minimal runnable code that reproduces the problem.

It's not unlikely that there is a bug related to intervals somewhere, I believe that is much less used and thus less tested than 2d and 3d problems in fenics.

Martin

--
If this answers your question, please go to the following page to let us know that it is solved:
https://answers.launchpad.net/dolfin/+question/179150/+confirm?answer_id=2

If you still need help, you can reply to this email or go to the following page to enter your feedback:
https://answers.launchpad.net/dolfin/+question/179150

You received this question notification because you asked the question.

Revision history for this message
Charles Cook (charles-4w) said :
#5

Also, anyway to get my email out of the message?

Revision history for this message
Charles Cook (charles-4w) said :
#6

I did a fresh install/update of fenics and the problem still occurs with Beta 2.

Revision history for this message
Charles Cook (charles-4w) said :
#7

I believe I have found the cause. The input might be too 'stiff' or 'sharp'.

I observe the same behaviour by:

- Creating an interval mesh with 100 elements (number of elements doesnt matter much)
- Solving from x=0, to x=1
- Setting the input vector = 1 everywhere except at x=0, setting it equal to 0.955.

Solving with the above system then shows the same behavior.

In short, this is a numerical issue and not a bug :)

Revision history for this message
Charles Cook (charles-4w) said :
#8

This was definitely a resolution problem. I distributed the nodes with a tanh distribution and solved the problem.

Thank you!