Boundary Condition and coefficient from discrete data

Hello everyone,

My problem is that I want to create a boundary condition with discrete data and interpolation and here is my code:

class gaussian_boundary(Expression):

     def __init__(self, field, xx, yy):

         self._f = scipy.interpolate.RectBivariateSpline(xx, yy, field)

     def eval(self, value, x):

         value = self._f(x[0], x[1])

     def value_shape(self):

     return (1,)

And if I use this expression the following way:

u_D = gaussian_boundary2(field, xx, yy)
def boundary(x, on_boundary):**
      return on_boundary
bc = DirichletBC(V, u_D, boundary)

I get the following error:
RecursionError: maximum recursion depth exceeded
But I don’t see how there is a recursion there. Does anyone have a solution to this or an idea how I could use my discrete data as boundary condition(discrete data is not on the boundary itself but around and inside the domain.

Kind regards

Please format your code using 3x` to make it readable.

For your actual question, consider:

Ok thank you for your answer, that seemed to work, I implemented it the way it was suggested and now I got a new error:

Expecting a scalar boundary value but given function is vector-valued

But the f is clearly scalar valued, I evaluated it and it gives only 1d data as output

You can do one out of two things:

  1. Remove value_shape (it defaults to scalar value).
  2. Change value_shape to:
def value_shape(self):
    return ()

Thank you again for your help. Works like a charm

Have a nice day