P1dc and Dirichlet BC

Hello to everybody,
I am wondering why the following simple code fails to set the homogeneous Dirichlet boundary condition to u in P1dc

macro dn(u) (N.x*dx(u)+N.y*dy(u) ) //  def the normal derivative

int Nn=8;
mesh Th = square(Nn,Nn);

fespace Vh(Th,P1dc); // Discontinous P1 finite element
Vh u,v;

func  fh =-2.0*(pi^2)*sin(pi*x)*sin(pi*y); // RHS

solve testondc(u,v)=
   int2d(Th)(dx(u)*dx(v)+dy(u)*dy(v))
 + intalledges(Th)((jump(v)*mean(dn(u))-jump(u)*mean(dn(v)))/nTonEdge)
 - int2d (Th)(fh*v)
 +on(1,2,3,4,u=0)
;

real testint=int1d(Th)(abs(u));
cout << "testint = " << testint << endl;

The result is
testint = 4.22009
Indeed setting the +on(1,2,3,4,u=0) or not setting it makes no difference.

It is not a bug it is due to the logical support of the degree of freedom ( interior of the triangle not on boundary for discontinuity),.

Thank you. Thus using an explicit penalty term +int1d(Th)(1.e10*u*v) is the right way to do it?

yes but you can use a lump quadrature formula to put big chef just on diagonal of the matrix.
Here you are in P1dc so the add qfe=qf1pElump

Got it, thank you! I understand that putting such strong Dirichlet condition on a discontinuous space is not “natural”. Nevertheless it can be useful sometimes.

Dear Frédéric,
Is the following code correct to set strong Dirichlet BC with tgv=-1 on a discontinuous fespace
(following example of examples/tutorial/LapDG2.edp)
dg-elliptic-test.edp (3.6 KB)
?
The main lines are

  //**** modify matrix and rhs to set the strong Dirichlet BC ****
   varf bdryTh(u,v)=int1d(Th,1,2,3,4)(v);
   real[int] bdryVhh=bdryTh(0,Vhh);// find the bdry dof
   setBC(A,bdryVhh,-1);//tgv=-1
   rhs= bdryVhh ? uexh[] : rhs ;
  //*************************

There is a problem in my code, now I understand what you said: the location of dof of P1dc are not on the boundary of the triangle, but slightly inside as the small circles in the picture below

It follows that the integral on a boundary will also involve dof out of the boundary (with a small negative weight).
I think then that the correct way should be with two additional lines

  //**** modify matrix and rhs to set the strong Dirichlet BC ****
   varf bdryTh(u,v)=int1d(Th,1,2,3,4)(v);
   real[int] bdryVhh=bdryTh(0,Vhh);// find the bdry dof
   real bdryVhhmax=bdryVhh.linfty;
   for [i,val : bdryVhh] val=(val>0.01*bdryVhhmax);
   setBC(A,bdryVhh,-1);//tgv=-1
   rhs= bdryVhh ? uexh[] : rhs ;
  //*************************