Error in calculating grid function in a particular grid


I am Woojun Lee and a PhD student at ECE department of Virginia tech.

I am just trying to use Bempp to calculate impedance on a two-ported microstrip structure.

For that, I meshed a cuboid structure with some holes using Ngsolve module, imported it into Bempp grid, and tested some grid functions.

I just tried to make the grid function of incident wave with +z direction, but the coefficients were ridiculously big and don’t make sense as below.


I am just trying to figure it out myself but I need some help!

Here are the codes I have tested.

from ngsolve import *

from netgen.occ import *

from ngsolve.webgui import Draw

from netgen.geom2d import CSG2d, Rectangle

import numpy as np

import re

import bempp.api

import pyopencl

import plotly

import meshio

import gmsh

import numba

import cmath

import math

epsilon_0 = 8.854187817e-12

mu_0 = 4 * np.pi * 1e-7

c_0 = 1 / math.sqrt(epsilon_0 * mu_0);

frequency = 1e9 #1GHz

w = 2 * np.pi * frequency

k = w * np.sqrt(epsilon_0 * mu_0)

f1 = WorkPlane(Axes((0,0,0), n=-Y, h=X)).Rectangle(1,1).Face()

f2 = WorkPlane(Axes((1,0,0), n=X, h=Y)).Rectangle(1,1).Face()

f3 = WorkPlane(Axes((1,1,0), n=Y, h=-X)).Rectangle(1,1).Face()

f4 = WorkPlane(Axes((0,1,0), n=-X, h=-Y)).Rectangle(1,1).Face()

microstrip1 = WorkPlane(Axes((0.1,0.1,1), n=Z, h=X)).Rectangle(0.1,0.1).Face()

microstrip2 = WorkPlane(Axes((0.15,0.15,1), n=Z, h=X)).Rectangle(0.1,0.1).Face()

dielectric = WorkPlane(Axes((0,0,1), n=Z, h=X)).Rectangle(1,1).Face()

geo = OCCGeometry(f1 + f2 + f3 + f4 + dielectric - microstrip1 - microstrip2)

mesh_test4 = Mesh(geo.GenerateMesh(maxh=0.1))

mesh_test4_vertices = np.zeros(shape=(mesh_test4.nv,3), dtype=np.float64)

vertices_count = 0;

for v in mesh_test4.vertices:

  mesh_test4_vertices[vertices_count] = np.asarray(v.point)

vertices_count += 1

mesh_test4_vertices = np.transpose(mesh_test4_vertices)

mesh_test4_elements = np.zeros(shape=(mesh_test4.nfacet,3), dtype = np.uint32)

for count1, v in enumerate(mesh_test4.facets):

  for count2 in range(len(v.vertices)):

    mesh_test4_elements[count1][count2] = int(re.findall(r'V(\d+)', str(v.vertices[count2]))[0])

mesh_test4_elements = np.transpose(mesh_test4_elements)

mesh_test4_bempp_grid = bempp.api.Grid(mesh_test4_vertices, mesh_test4_elements)

from bempp.api.external.viewers import visualize_with_jupyter_notebook



div_space = bempp.api.function_space(mesh_test4_bempp_grid, "RWG", 0)
curl_space = bempp.api.function_space(mesh_test4_bempp_grid, "SNC", 0)

def tangential_trace(x, n, domain_index, result):
  incident_field = np.array([np.exp(1j * k * x[2]), np.exp(1j * k * x[2]), 0. * x[2]])
  result[:] = np.cross(incident_field, n)

test_grid_func = bempp.api.GridFunction(div_space, fun=tangential_trace, dual_space=curl_space)


Pease ignore the question above.

I’ve just realized that grid function would be some projection values of incident field and my code above simply doesn’t make sense to plot such electric field!