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

boundary condition that depends on facet normal

+1 vote

I'm using the c++ interface and trying to solve a vector Laplace equation equation where my boundary condition is a vector that depends on the normal vector. How can I create this kind of boundary condition?

The class DirichletBC will only take a GenericFunction as an argument, and GenericFunctions will only operate on points, not facets, so I can't just call facet.normal(). Any advice would be appreciated

Here is the problem I'm trying to solve:

let u in C. I want to find

laplacian(u) = 0
u = g(u) on boundary

where g(u) is the complex number obtained by multiplying the boundary normal (represented as a complex number on s^1) by e^{i4theta} where theta is the angle that the boundary normal makes with the real axis.

asked Nov 23, 2016 by rviertel FEniCS Novice (700 points)
edited Nov 23, 2016 by rviertel

It would be clearer what you're trying to achieve if you succinctly state the simplest formulation of your PDE and boundary conditions.

I just edited the question

I would suggest you have a look at how the Neumann BC is enforced in the Poisson demo here, note how it is incorporated into the linear form as an integral around the exterior boundary. Here it should be relatively straightforward to incorporate the FacetNormal of the mesh into the function $g$.

1 Answer

0 votes
 
Best answer

I was able to do this by subclassing GenericFunction and implementing the eval function. Turns out that the ufc::cell index corresponds to the mesh index, so I was able to get the mesh cells, then get the facets to compute the boundary normal.

class RepresentationVectorFunction : public dolfin::Expression
{
  public:
    RepresentationVectorFunction(dolfin::Mesh &Amesh):m_mesh(Amesh){}

  private:
    void eval(dolfin::Array<double> &values, const dolfin::Array<double> &x,
                                            const ufc::cell &cell) const
    {
      dolfin::Cell c(m_mesh,cell.index);

      dolfin::MeshEntityIterator fac_it(c, 1);
      dolfin::Point normal;

      for(; !fac_it.end(); ++fac_it)
      {
        dolfin::Facet f(m_mesh,fac_it->global_index());
        if(f.exterior())
          normal = f.normal();
      }

      values[0] = normal[0];
      values[1] = normal[1];
    }

    dolfin::Mesh m_mesh;
};
answered Nov 24, 2016 by rviertel FEniCS Novice (700 points)
selected Nov 24, 2016 by rviertel
...