# complex numbers in escript

I am trying to solve the Helmholtz equation for frequency domain acoustics. There is only one variable, the acoustic pressure.
This pressure is a complex quantity and the parameters of the boundary conditions are often complex numbers too.

First question: should I be able to make that work with escript?

As an example, I try to set a complex value to a boundary condition with:
bc = Scalar(0., FunctionOnBoundary(mydomain))
bc.setTaggedValue(1, 1.j*wavenumber)

but it seems the Scalar object does not support the complex data type...

## Question information

Language:
English Edit question
Status:
Solved
For:
esys-escript Edit question
Assignee:
No assignee Edit question
Solved by:
Lutz Gross
Solved:
Last query:
 Revision history for this message Joel Fenwick (j-fenwick1) said on 2011-11-07: #1

You are correct, internally escript only supports scalars, vectors, ... over R.
Would it be possible to reform your equation into a system of equations separating real and imaginary parts?

 Revision history for this message Lutz Gross (l-gross) said on 2011-11-08: #2

As Joel pointed out, escript does not support complex numbers. To solve your problem you need to represent your PDE solution as a vector u with two component where u[0] represents the real and u[1] represents the imaginary part. The Helmholtz equation is then a system of two PDEs of the form

- u[0]_{,ii} + w_r * u[0] - w_i * u[1] = 0
- u[1]_{,ii} + w_i * u[0] + w_r * u[1] = 0

In escript this would look like:

myode=LinearPDE(domain, numEquation=2)
A=mypde.createCoefficient("A")
for i in range(domain.getDim()):
A[0,i,0,i]=1
A[1,i,1,i]=1
D=mypde.createCoefficient("D")
D[0,0]=w_r
D[1,0]=w_i
D[1,1]=w_r
D[0,1]=-w_i
myode.setValue(A=A, D=D)
u=mypde.getSolution()

 Revision history for this message Antoine Lefebvre (antoine-lefebvre2) said on 2011-11-08: #3

Thanks Lutz Gross, that solved my question.

 Revision history for this message Antoine Lefebvre (antoine-lefebvre2) said on 2011-11-08: #4

Thanks. It works. I am now working on a a validation test case for Acoustics.

 Revision history for this message Lutz Gross (l-gross) said on 2016-10-10: #5

version 5 provides now some support for complex data. This is still is still in beta testing.