### How to set the complex coefficient of the differential equation?

164

views

1

I am modeling electric stimulation of biological tissues. I need to solve the following complex equation:

\begin{equation}

- \nabla ( [ \sigma + j \omega \varepsilon ] \nabla V) = 0

\end{equation}

I solve the real part of the equation:

\begin{equation}

- \nabla ( [ \sigma ] \nabla V) = 0

\end{equation}

using the following code:

How can I specify a complex coefficient for a differential equation?

\begin{equation}

- \nabla ( [ \sigma + j \omega \varepsilon ] \nabla V) = 0

\end{equation}

I solve the real part of the equation:

\begin{equation}

- \nabla ( [ \sigma ] \nabla V) = 0

\end{equation}

using the following code:

```
from fenics import *
# Mesh
mesh = UnitCubeMesh(5, 5, 5)
V = FunctionSpace(mesh, 'P', 1)
# Boundary conditions
u_Left = Constant(1)
def boundary_Left(x, on_boundary):
tol = 1e-14
return on_boundary and near(x[0], 0, tol)
bc_L = DirichletBC(V, u_Left, boundary_Left)
u_Right = Constant(0)
def boundary_Right(x, on_boundary):
tol = 1e-14
return on_boundary and near(x[0], 1, tol)
bc_R = DirichletBC(V, u_Right, boundary_Right)
# Problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(0)
coefficient = Constant(1) # Coefficient, which should be complex
a = coefficient * dot(grad(u), grad(v)) * dx
L = f * v * dx
u = Function(V)
# Solve
solve(a == L, u, [bc_L, bc_R])
```

As I understand it, I can not just make the coefficient complex because in that case I get ComplexWarning during the simulation. How can I specify a complex coefficient for a differential equation?

Community: FEniCS Project

Please login to add an answer/comment or follow this question.

Solution code:

In the code, I define a complex FunctionSpace and solve equation in it. The code works, but it seems that in this case imaginary part always equals to zero.

In theory, the should be bouth real and imaginary parts.

It seems that mistake is in definition of a and L. How to make variables a and L correctly?