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:
The tutorial is out of date. Change your Permeability class to the following:
class Permeability(UserExpression): # UserExpression instead of Expression
def __init__(self, markers, **kwargs):
super().__init__(**kwargs) # This part is new!
self.markers = markers
def eval_cell(self, values, x, cell):
if self.markers[cell.index] == 0:
values[0] = 4*pi*1e-7 # vacuum
elif self.markers[cell.index] == 1:
values[0] = 1e-5 # iron (shou…
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:
Remove value_shape
(it defaults to scalar value).
Change value_shape
to:
def value_shape(self):
return ()
Thank you again for your help. Works like a charm
Have a nice day