# The 'nan' issue occurs when solving in Bempp 3.3.4

**URL:** <https://bempp.discourse.group/t/the-nan-issue-occurs-when-solving-in-bempp-3-3-4/346>\
**Category:** Applications\
**Created:** [6 November 2025 06:08 UTC](https://bempp.discourse.group/t/the-nan-issue-occurs-when-solving-in-bempp-3-3-4/346 "2025-11-06T06:08:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shelton](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@Shelton](https://bempp.discourse.group/u/Shelton)\
**Post date:** [6 November 2025 06:08 UTC](https://bempp.discourse.group/t/the-nan-issue-occurs-when-solving-in-bempp-3-3-4/346/1 "2025-11-06T06:08:14Z")

</div>

Hello everyone,

When using version Bempp3.3.4 to solve the scattering field of a cube, I encountered ‘nan’ values in the computed scattered electric field on the surface. However, when running the following code multiple times:

```python
points_values = -ME*sol

num_nan = np.sum(np.isnan(points_values)) print(num_nan)

```

the number of ‘nan’ values varies each time, and I am unsure why this occurs. I hope someone can provide a solution to this issue. In the latest version, bempp-cl 0.4.2, this ‘nan’ problem does not occur, but it lacks the feature for local mesh refinement ( **I mainly need the local mesh refinement functionality. Can bempp-cl0.4.2 achieve this, or can it be implemented through other packages?** ). Therefore, I would greatly appreciate it if anyone knows how to resolve this problem. The specific code is as follows.

```auto
import bempp.api
import numpy as np
from bempp.api.operators.boundary import maxwell
from bempp.api.operators.boundary.sparse import identity as ident

```

```auto
polarization = np.array([1.0, 0, 0.0])
direction = np.array([0.0, 0, 1.0])
def incident_field(point):return polarization * np.exp(1j * k * np.dot(point, direction))
@bempp.api.complex_callable#(jit=False)
def tangential_trace(point, n, domain_index, result):
value = polarization * np.exp(1j * k * np.dot(point, direction))
result[:] = np.cross(value, n)
grid = bempp.api.shapes.cube(length=1, origin=(0, 0, 0), h=0.1)
grid.plot()  

```

```auto
rwg_space = bempp.api.function_space(grid, “RWG”, 0)
snc_space = bempp.api.function_space(grid, “SNC”, 0)

Id = ident(rwg_space, rwg_space, snc_space)
tan_inc = bempp.api.GridFunction(rwg_space, fun = tangential_trace, dual_space = snc_space)

E = maxwell.electric_field(rwg_space, rwg_space, snc_space, k)
H = maxwell.magnetic_field(rwg_space, rwg_space, snc_space, k)

```

```auto
vertices = grid.leaf_view.vertices
elements = grid.leaf_view.elements

points = vertices[:, elements[1 , :]]

points = ( vertices[:, elements[0 , :]] + vertices[:, elements[1 , :]] + 
vertices[:, elements[2 , :]] ) / 3

```

```auto
ME = bempp.api.operators.potential.maxwell.electric_field(rwg_space, points, k)
points_values = -ME*sol
num_nan = np.sum(np.isnan(points_values))
print(num_nan)

```

 ![image](https://global.discourse-cdn.com/free1/uploads/bempp/original/1X/ecb1e5f5e8e1416efb29277b68a92f137b27d8c5.png)

 ![image](https://global.discourse-cdn.com/free1/uploads/bempp/original/1X/99fa6d3d9510dd741b86d6a3546eb577c160a70b.png)

The number of NaN is different each time.
