← Back to team overview

fenics team mailing list archive

回复: How to get one function minus another function?

 

Thank you for taking time to give this very clear tutorial.
It's very helpful. 
 
Could you also elaborate a little bit more on how to 
assemble the value of the functional M?

Thank you so much!

Best regards,
Chong
----- 原始邮件 ----
发件人: Anders Logg <logg@xxxxxxxxx>
收件人: fenics-dev@xxxxxxxxxx
已发送: 2007/11/10(周六), 上午5:26:51
主题: Re: [FEniCS-dev] How to get one function minus another function?

You need to define a form for the norm of the difference. As an
example, to compute the L2 norm of the difference of two functions
u_h (approximate solution) and u (exact solution) define the following
form:

  u_h = Function(element)
  u  = Function(element)
  e  = u_h - u

  M = e*e*dx

Then assemble the value of the functional M (a scalar) and take the
square root to obtain the error in the L2 norm.

Other norms, like the H1 norm can be computed similarly:

  M = e*e*dx + dot(grad(e), grad(e))*dx

However, it's important to note here that what gets computed is the
norm of the difference between the approximate solution and the
*interpolation* of the exact solution into the finite element space.
This might not be what you want and you may be fooled when computing
convergence rates etc. So to be on the safe side, use a higher order
approximation for the exact solution:

  k  = <suitable value of k here, say k = 5>
  Pk = FiniteElement("Lagrange", shape, k)

  u = Function(Pq)

(I have added this to the FAQ now.)

/Anders


On Fri, Nov 09, 2007 at 09:33:41AM -0800, Chong Luo wrote:
> Hi,
> 
> I want to compare the solution given by FEniCS to the exact solution, so that I
> can get the convergence rate. However, I don't know how to find the difference
> between two functions. It seems that the solution given by FEniCS is a
> DiscreteFunction, while the exact solution was defined by me via overriding
> "eval()", thus a UserFunction. But I don't know how to get a function whose
> value is the difference of these two functions.
> 
> Could you help me with this? Thank you!
> 
> Best,
> Chong
> 
> 
> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> @yahoo.cn 新域名、无限量,快来抢注!

> _______________________________________________
> FEniCS-dev mailing list
> FEniCS-dev@xxxxxxxxxx
> http://www.fenics.org/mailman/listinfo/fenics-dev

_______________________________________________
FEniCS-dev mailing list
FEniCS-dev@xxxxxxxxxx
http://www.fenics.org/mailman/listinfo/fenics-dev


      ___________________________________________________________ 
雅虎邮箱,终生伙伴! 
http://mail.yahoo.com.cn/

Follow ups