# How to define a spatially dependent dielectric tensor

Hi all,

Very new FEniCS user here, in way over my head with a tricky problem. I’ve been tasked with modifying some previously written FEniCS code (which solves for an electric field) to implement an absorbing boundary layer, and if I understand the theory correctly, I can do this by defining the absorbing layers as having a complex permittivity tensor that is spatially dependent. The code I’m modifying is using the 2019.1.0 version.

Currently the code includes a region of free space and a region with a dielectric scalar value, and the dielectric values are set using this class:

class Permittivity(UserExpression):

``````def __init__(self, markers, **kwargs):
super(Permittivity, self).__init__(**kwargs)
self.markers = markers

def eval_cell(self, values, x, cell):
if self.markers[cell.index] == 0:  # this (subdomain 0) is free space
values[0] = 1.0  # vacuum
elif self.markers[cell.index] == 1:  # this (subdomain 1) is dielectric material
values[0] = diel
else:
values[0] = 1.0  # there shouldn't be any other domains, included just in case

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

This code is then called in the main function like this (mesh is generated using mshr):

mesh = generate_mesh(domain, 150)
subdomains = MeshFunction(‘size_t’, mesh, 2, mesh.domains())
eps_r = Permittivity(subdomains, degree=1)

I think I get how to define the needed subdomains for my absorbing boundary layers, but what I’m not sure about is how to modify the above code to implement a spatially dependent dielectric tensor instead of just a scalar value (of course, the other issue is working around the fact that this version doesn’t support complex numbers, as this code is complicated enough I don’t want to try converting it into FEniCSx, but I’m guessing that’s a separate question). I’ve tried reading the documentation on the Expression class, checking potentially related forum posts, and reaching out to the writer of the original code, but I haven’t gotten anywhere. Could anybody point me in the right direction?

Apologies if this is a dumb question, or if it’s in the wrong category, etc.

I have not tried the following code, but I saw the following GSoC project this past summer. There are PML and scattering boundary examples. The code is for FEniCSx, but you needed complex number support so you should consider switching. Someone please correct me if I’m wrong → complex number support in old FenicS will double the number of unknowns which will affect performance. In FEniCSx this is no longer an issue. It should also be much simpler to write complex valued weak forms in FEniCSx.

https://mikics.github.io/gsoc-jupyterbook/submission.html

This is about all the help I can provide. If you want help from others, you need to provide a complete minimal working example that someone can copy, paste and run on their machine.

1 Like