Subject: Re: [FFC-dev] source term in bilinear form

From: Reza Farrahi Moghaddam <[email-masked]>
Date: Mon, 14 Apr 2008 11:09:18 -0700 (PDT)

Thanks. But, my main problem is how the arguments of Bilinearform and linearform must be defined (to set up the PDE)? What is the order of arguments? Especially, in the linearized form of the weak equation; for example NonlinearPoisson demo, in the form file U0 is the solution and U is \delta U0. But, in the main.cpp, we have NonlinearPoissonBilinearForm a(u). How these three variables get connected to each other? Is there any pre-assumed notation for the solution or other variables?

Reza

----- Original Message ----
From: Garth N. Wells <[email-masked]>
To: Reza Farrahi Moghaddam <[email-masked]>
Cc: ffc-dev fenics <[email-masked]>; Discussion of DOLFIN development <[email-masked]>
Sent: Monday, April 14, 2008 11:10:44 AM
Subject: Re: [FFC-dev] source term in bilinear form

Reza Farrahi Moghaddam wrote:
> Thank you.
> 
> Is there any document on the NonlinearPDE or how to use it?
> 

No, but you can find some help on the NewtonSolver here:

http://www.fenics.org/pub/documents/dolfin/dolfin-user-manual/dolfin-user-manual.pdf

Also, at a look at the nonlinear PDE demo and the nonlinear solver (nls) 
demos.

Garth

>  
> 
> Bests,
> 
> Reza
> 
> 
> 
> ----- Original Message ----
> From: Mehdi Nikbakht <[email-masked]>
> To: Reza Farrahi Moghaddam <[email-masked]>
> Sent: Monday, April 14, 2008 10:03:27 AM
> Subject: Re: [FFC-dev] source term in bilinear form
> 
> Hello,
> Since in your bilinearform, you have two functions(U0 and f), then you 
> need to
> call "NonlinearPoissonBilinearForm" with two arguments.
> regards,
> --
> Mehdi
> 
> 
> 
> 
> Quoting Reza Farrahi Moghaddam <[email-masked] <mailto:[email-masked]>>:
> 
>  > Hello,
>  > 
>  > I am not sure if this post fits the ffc-dev list, but I would be 
> grateful if
>  > you send me some suggestions.
>  > 
>  > I want to use dolfin/ffc for solving image processing problems. I 
> start from
>  > Nonlinear Poisson demo. After linearization of the governing weak 
> equation,
>  > the input form file is as follows:
>  > element = FiniteElement("Lagrange", "triangle", 1)
>  > v = TestFunction(element)
>  > U = TrialFunction(element)
>  > U0= Function(element)
>  > f = Function(element)
>  > a = -v*(U0-f)*dot(grad(U0),grad(U))*dx
>  > L = v*(0.01+dot(grad(U0),grad(U0)))*(U0-f)*dx +
>  > 0.01*dot(grad(v),grad(U0))*dx
>  > 
>  > The "f" represents the input image (at moment only a simple analytic 
> function
>  > is used). The form file compiles well, but when I try to make the main
>  > program, there are some errors on NonlinearPoissonBilinearForm matching.
>  > The complete log of make:
>  > [rfarahi@alteran cpp]$ make
>  > `pkg-config --variable=compiler dolfin` `pkg-config --cflags dolfin` -c
>  > main.cpp
>  > main.cpp: In function `int main(int, char**)':
>  > main.cpp:89: error: no matching function for call to
>  > 
> `NonlinearPoissonBilinearForm::NonlinearPoissonBilinearForm(dolfin::Function&)'
>  > NonlinearPoisson.h:4672: note: candidates are:
>  > NonlinearPoissonBilinearForm::NonlinearPoissonBilinearForm(const
>  > NonlinearPoissonBilinearForm&)
>  > NonlinearPoisson.h:4675: note:              
>  > 
> NonlinearPoissonBilinearForm::NonlinearPoissonBilinearForm(dolfin::Function&,
>  > dolfin::Function&)
>  > mpic++: No such file or directory
>  > make: *** [main.o] Error 1
>  >
>  > 
>  > If I change the script and delete the "f" term from the bilinear 
> form, the
>  > error doesn't show up:
>  > element = FiniteElement("Lagrange", "triangle", 1)
>  > v = TestFunction(element)
>  > U = TrialFunction(element)
>  > U0= Function(element)
>  > f = Function(element)
>  > a = -v*(U0)*dot(grad(U0),grad(U))*dx
>  > L = v*(0.01+dot(grad(U0),grad(U0)))*(U0-f)*dx +
>  > 0.01*dot(grad(v),grad(U0))*dx
>  > 
>  > The input cpp file:
>  > // Copyright (C) 2006-2007 Garth N. Wells.
>  > // Licensed under the GNU LGPL Version 2.1.
>  > //
>  > // Modified by Anders Logg, 2005
>  > //
>  > // First added:  2005
>  > // Last changed: 2007-08-20
>  > //
>  >
>  > #include <dolfin.h>
>  > #include "NonlinearPoisson.h"
>  > 
>  > using namespace dolfin;
>  > // Right-hand side
>  > class Source : public Function
>  > {
>  >  public:
>  >    Source(Mesh& mesh) : Function(mesh) {}
>  >    real eval(const real* x) const
>  >    {
>  >      return x[0];
>  >    }
>  > };
>  > // Dirichlet boundary condition
>  > class DirichletBoundaryCondition : public Function, public TimeDependent
>  > {
>  >  public:
>  >    DirichletBoundaryCondition(Mesh& mesh, real& t) : Function(mesh),
>  > TimeDependent(t) {}
>  >    real eval(const real* x) const
>  >    {
>  >      return 1.0;
>  >    }
>  > };
>  > // Sub domain for Dirichlet boundary condition
>  > class DirichletBoundary : public SubDomain
>  > {
>  >  bool inside(const real* x, bool on_boundary) const
>  >  {
>  >    return std::abs(x[0] - 1.0) < DOLFIN_EPS && on_boundary;
>  >  }
>  > };
>  > int main(int argc, char* argv[])
>  > {
>  >  dolfin_init(argc, argv);
>  > 
>  >  // Set up problem
>  >  UnitSquare mesh(16, 16);
>  >  // Pseudo time
>  >  real t = 0.0;
>  >  // Create source function
>  >  Source f(mesh);
>  >  // Dirichlet boundary conditions
>  >  DirichletBoundary dirichlet_boundary;
>  >  DirichletBoundaryCondition g(mesh, t);
>  >  DirichletBC bc(g, mesh, dirichlet_boundary);
>  >  // Solution function
>  >  Function u;
>  >  // Create forms and nonlinear PDE
>  >  NonlinearPoissonBilinearForm a(u);
>  >  NonlinearPoissonLinearForm L(u, f);
>  >  NonlinearPDE pde(a, L, mesh, bc);
>  >  // Solve nonlinear problem in a series of steps
>  >  real dt = 1.0; real T  = 3.0;
>  > //  pde.dolfin_set("Newton relative tolerance", 1e-6);
>  > //  pde.dolfin_set("Newton convergence criterion", "incremental");
>  >  // Solve
>  >  pde.solve(u, t, T, dt);
>  >  // Plot solution
>  >  plot(u);
>  >  // Save function to file
>  >  File file("nonlinear_poisson.pvd");
>  >  file << u;
>  >  return 0;
>  > }
>  >
>  > 
>  > 
>  > 
>  > Any suggestion?
>  > 
>  > Bests,
>  > Reza
>  >
>  >
>  >      __________________________________________________________________
>  > Ask a question on any topic and get answers from real people. Go to 
> Yahoo!
>  > Answers and share what you know at http://ca.answers.yahoo.com 
> <http://ca.answers.yahoo.com/>
> 
> 
> ------------------------------------------------------------------------
> Be smarter than spam. See how smart SpamGuard is at giving junk email 
> the boot with the *All-new Yahoo! Mail * 
> <http://ca.promos.yahoo.com/newmail/overview2/>
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> FFC-dev mailing list
> [email-masked]
> http://www.fenics.org/mailman/listinfo/ffc-dev

      __________________________________________________________________
Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail.  Click on Options in Mail and switch to New Mail today or register for free at http://mail.yahoo.ca

---

From: Anders Logg <[email-masked]>
Date: Mon, 14 Apr 2008 20:19:25 +0200

On Mon, Apr 14, 2008 at 11:09:18AM -0700, Reza Farrahi Moghaddam wrote:
> Thanks. But, my main problem is how the arguments of Bilinearform and
> linearform must be defined (to set up the PDE)? What is the order of arguments?
> Especially, in the linearized form of the weak equation; for example
> NonlinearPoisson demo, in the form file U0 is the solution and U is \delta U0.
> But, in the main.cpp, we have NonlinearPoissonBilinearForm a(u). How these
> three variables get connected to each other? Is there any pre-assumed notation
> for the solution or other variables?
> 
>  
> 
> Reza

You must supply all Functions (like U0), but not the TrialFunction U,
and you must supply them in the order in which you defined the
Functions in the form file.

Look at some more demos.

-- 
Anders

> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> All new Yahoo! Mail - Get a sneak peak at messages with a handy reading pane.

> DOLFIN-dev mailing list
> [email-masked]
> http://www.fenics.org/mailman/listinfo/dolfin-dev