← Back to team overview

fenics team mailing list archive

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

 

In C++, do

  real value = assemble(M, mesh);

or from Python, do

  value = assemble(M, mesh)

Please direct any further questions to dolfin-dev or ffc-dev.

Thanks
/Anders


On Sat, Nov 10, 2007 at 12:36:18PM -0800, Chong Luo wrote:
> 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
> 
> 
> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> @yahoo.cn                       ע  


References