Ian Jauslin
summaryrefslogtreecommitdiff
blob: f6f044a075cd3a4ef8ac573d69487c935c20d647 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# \hat u_n
function hatun_iteration(e,order,d,v,maxiter)
  # gauss legendre weights
  weights=gausslegendre(order)

  # init V and Eta
  (V,V0,Eta,Eta0)=init_veta(weights,d,v)

  # init u and rho
  u=Array{Array{Complex{Float64}}}(undef,maxiter+1)
  u[1]=zeros(Complex{Float64},order)
  rho=zeros(Complex{Float64},maxiter+1)

  # iterate
  for n in 1:maxiter
    u[n+1]=A(e,weights,Eta)\b(u[n],e,rho[n],V)
    rho[n+1]=rhon(u[n+1],e,weights,V0,Eta0)
  end

  return (u,rho)
end

# A
function A(e,weights,Eta)
  N=length(weights[1])
  out=zeros(Complex{Float64},N,N)
  for i in 1:N
    k=(1-weights[1][i])/(1+weights[1][i])
    out[i,i]=k^2+4*e
    for j in 1:N
      y=(weights[1][j]+1)/2
      out[i,j]+=weights[2][j]*(1-y)*Eta[i][j]/(2*(2*pi)^3*y^3)
    end
  end
  return out
end

# b
function b(u,e,rho,V)
  out=zeros(Complex{Float64},length(V))
  for i in 1:length(V)
    out[i]=V[i]+2*e*rho*u[i]^2
  end
  return out
end

# rho_n
function rhon(u,e,weights,V0,Eta0)
  S=V0
  for i in 1:length(weights[1])
    y=(weights[1][i]+1)/2
    S+=-weights[2][i]*(1-y)*u[i]*Eta0[i]/(2*(2*pi)^3*y^3)
  end
  return 2*e/S
end