# Boundary Condition and coefficient from discrete data

**URL:** <https://fenicsproject.discourse.group/t/boundary-condition-and-coefficient-from-discrete-data/5796>\
**Category:** Uncategorized\
**Created:** [May 14, 2021, 6:32am UTC](https://fenicsproject.discourse.group/t/boundary-condition-and-coefficient-from-discrete-data/5796 "2021-05-14T06:32:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![frederiksteiner](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/frederiksteiner/32/2499_2.png) [@frederiksteiner](https://fenicsproject.discourse.group/u/frederiksteiner)\
**Post date:** [May 14, 2021, 6:32am UTC](https://fenicsproject.discourse.group/t/boundary-condition-and-coefficient-from-discrete-data/5796/1 "2021-05-14T06:32:17Z")

</div>

Hello everyone,

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

```auto
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:

```auto
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

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [May 14, 2021, 6:49am UTC](https://fenicsproject.discourse.group/t/boundary-condition-and-coefficient-from-discrete-data/5796/2 "2021-05-14T06:49:16Z")

</div>

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

For your actual question, consider:

> [@RecursionError: maximum recursion depth exceeded in the ft11\_magnetostatics.py example of the "Solving PDEs in Python - The FEniCS tutorial Part 1"](https://fenicsproject.discourse.group/t/recursionerror-maximum-recursion-depth-exceeded-in-the-ft11-magnetostatics-py-example-of-the-solving-pdes-in-python-the-fenics-tutorial-part-1/1559/2):
>
> 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…

---

<div class="post-metadata">

**Author:** ![frederiksteiner](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/frederiksteiner/32/2499_2.png) [@frederiksteiner](https://fenicsproject.discourse.group/u/frederiksteiner)\
**Post date:** [May 14, 2021, 7:31am UTC](https://fenicsproject.discourse.group/t/boundary-condition-and-coefficient-from-discrete-data/5796/3 "2021-05-14T07:31:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [May 14, 2021, 7:43am UTC](https://fenicsproject.discourse.group/t/boundary-condition-and-coefficient-from-discrete-data/5796/4 "2021-05-14T07:43:19Z")

</div>

You can do one out of two things:

1. Remove `value_shape` (it defaults to scalar value).
2. Change `value_shape` to:

```auto
def value_shape(self):
    return ()

```

---

<div class="post-metadata">

**Author:** ![frederiksteiner](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/frederiksteiner/32/2499_2.png) [@frederiksteiner](https://fenicsproject.discourse.group/u/frederiksteiner)\
**Post date:** [May 14, 2021, 7:57am UTC](https://fenicsproject.discourse.group/t/boundary-condition-and-coefficient-from-discrete-data/5796/5 "2021-05-14T07:57:28Z")

</div>

Thank you again for your help. Works like a charm

Have a nice day
