if else condition on fenics

5 months ago by
Hello everyone,

I am solving a hyperbolic PDE with fenics and using c++. My boundary data is discontinuous and I set the values with

class U : public Expressionclass U : public Expression{public:
U(double eps): _eps(eps) {}
void eval(Array<double>& values, const Array<double>& x)
const {           

if ((x[0]==0.0)and (0.0<x[1]<=0.5)) { values[0]=1.0; }    
  else if ((x[0]==0.0) and (0.5<x[1]<=1.0)) { values[0]=0.0; }
  else if ((x[1]==0.0) and (0.5<x[0]<=1.0)) { values[0]=0.0; }    
  else if ((x[1]==0.0) and (0.0<=x[0]<=0.5)) { values[0]=1.0; }
  else if ((x[0]==1.0) and (0.0<=x[1]<=1.0)) { values[0]=pow(sin(x[1]*M_PI),2); }

but visualizing my solution I see that the boundary data is not correctly set. Anyone knows what I am doing wrong here?

Thanks in advance

Community: FEniCS Project

1 Answer

5 months ago by
I'd be worried about comparing two floats exactly (likely to fail due to e.g., truncation). Suggest you try something like abs(x[0]-1)<1e-10 or something like this:
Please login to add an answer/comment or follow this question.

Similar posts:
Search »