This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to implement Green's function boundary condition?

+1 vote

I'm in the process of solving a Poisson equation, where the Dirichlet boundary condition has to be defined via Green's function solution.

So far, if I've understood correctly, defining a boundary condition proceeds by

(1) defining the region of the boundary where the Dirichlet condition is to be applied (in my case it is the entire boundary)

def is_at_boundary(x,on_boundary): 
    return on_boundary

(2) providing an Expression to compute the value at the boundary

u0 = Expression( open('u0.cpp').read() )

(3) initializing a boundary condition object.

bc = DirichletBC(V, u0, is_at_boundary)

I have chosen to use a c++ class for defining the boundary expression, so the file 'u0.cpp' should look something like this:

namespace dolfin {

    class u0 : public Expression
    {
    public :
        u0 () : Expression () {}

        void eval (Array <double >& values ,
                   const Array <double >& x) const
        {
            // Somehow get access to the source function f
            // Compute integral over the computational 
            // domain given two parameters (x[0], x[1])

            values [0] = assemble( f(y) * K(y,x[0],x[1]) * dy ) ;
        }
    };
}

Assumably, I would have to first define a class for the function K(y,x[0],x[1]) which would be initialized with x[0] and x[1], and that class should provide an Expression. That I can do.

But how can I integrate an expression throughout the entire domain, inside a c++ class that defines an Expression?

Does the Expression that defines the value of the function at the boundary have to be a 'pure function', or can it take other arguments as well? If more than the argument x is allowed, how do I set the boundary condition then when calling 'DirichletBC(...)'?

Thank you.
Eero

asked Feb 3, 2016 by ehirvijo FEniCS Novice (130 points)

1 Answer

0 votes

You can use the more advanced Expression interface to pass more data. Take a look at dolfin/function/Expression.h.

answered Feb 23, 2016 by Garth N. Wells FEniCS Expert (35,930 points)

Could you please elaborate? I've been involved with the related question: https://fenicsproject.org/qa/10687/how-to-pass-numpy-array-compiled-expression-member-variable?show=10687#q10687

...