← Back to team overview

dolfin team mailing list archive

Re: a question about dolfin

 

On Sun, Jan 21, 2007 at 10:44:11PM +0100, Johan Jansson wrote:
> On Sun, Jan 21, 2007 at 06:11:03PM -0300, Pablo De Napoli wrote:
> > Hi!
> > 
> > My name is Pablo De Nápoli, I work at the Department of  Mathematics atBuenos
> > Aires University, Argentina.
> > 
> > I'm new to Dolfin, and I'm planning to use for some numerical experiments in
> > my research. I think it is a very interesting software specially for
> > the close to the
> > mathematical-thinking way of representing the PDEs in weak formulation.
> > 
> 
> ...
> 
> > Could you please explain me what is wrong in this program?
> > User-defined functions can't be plotted? (exported to files?)
> > 
> 
> Hi Pablo,
> 
> Yes, user-defined functions cannot be directly plotted/exported to
> file. You need to project the function to a finite element space to do
> that. I've modified your program to achieve that:
> 
> #include <dolfin.h>
> #include "Projection.h"
> 
> using namespace dolfin;
> 
> int main()
> {
>   class Myfunction : public Function
>   {
>     real eval(const Point& p, unsigned int i)
>     {
>       real x= p.x();
>       real y= p.y();
>       return (x+y);
>     }
>   };
> 
> 
>   UnitSquare mesh(16, 16);
> 
>   Myfunction f;
>   Projection::BilinearForm a;
>   Projection::LinearForm L(f);
> 
>   LinearPDE pde(a, L, mesh);
> 
>   Function F;
>   pde.solve(F);
> 
>   File file("F.pvd");
>   file << F;
> 
>   return 0;
> }
> 
> with the form "Projection.form":
> 
> # Compile this form with FFC: ffc Projection.form.
> 
> element = FiniteElement("Lagrange", "triangle", 1)
> 
> v = TestFunction(element)
> U = TrialFunction(element)
> f = Function(element)
> 
> a = v * U * dx
> L = v * f * dx
> 
> There is experimental functionality to simplify the computation of
> projections, since it's so fundamental, but it's not quite stable yet.
> 
> Export of user-defined functions could be implemented by automatically
> performing a projection as above.
> 
> > By the way, I think that the code in section 4.3.2 Dolfin's manual
> > (User-defined functions) is not correct
> > 
> > for example Instead of
> > 
> > class Source : public Function
> > {
> >   real eval(const Point& p, unsigned int i)
> >   {
> >     return x*y*sin(z / DOLFIN_PI);
> >   }
> > };
> > 
> > (this form of the code didn't work for me)
> > it should be
> > 
> > class Source : public Function
> > {
> >   real eval(const Point& p, unsigned int i)
> >   {
> >     return p.x()*p.y()*sin(p.z() / DOLFIN_PI);
> >   }
> > };
> > 
> > and likewise in the other examples in that section....
> 
> You're right, this is because the mesh representation has recently
> changed. The documentation should be updated more frequently, but
> since fundamental interfaces are still being implemented/improved,
> that is given higher priority.

This will improve in the near future. The linear algebra interface
stabilized during the summer, the new mesh library is now in firm
place and the assembly/form evaluation will soon be in place (and stay
fixed).

After that, the interfaces will be remain mostly constant and we will
be able to write a useful manual.

/Anders


Follow ups

References