Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Added abs() function which can handle arrays of CompSol to interface-…
Browse files Browse the repository at this point in the history
…test.jl
  • Loading branch information
sonVishal committed Apr 9, 2016
1 parent ea10a9d commit d68c1a0
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions test/interface-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,42 @@ ODE.isoutofdomain(y::CompSol) = any(isnan, vcat(y.rho[:], y.x, y.p))


################################################################################

# TODO: test a vector-like state variable, i.e. one which can be indexed.
function getZeroVector(y::Array{CompSol,1})
numElems = length(y)
tmp = Array{CompSol,1}(numElems)
for i = 1:numElems
tmp[i] = CompSol(complex(zeros(2,2)), 0., 0.)
end
return tmp
end
Base.zeros(y::Array{CompSol,1}) = getZeroVector(y)

function getAbsVector(y::Array{CompSol,1})
numElems = length(y)
absVec = Array{Float64}(numElems)
for i = 1:numElems
absVec[i] = norm(y[i], 2.)
end
return absVec
end
Base.abs(y::Array{CompSol,1}) = getAbsVector(y)


################################################################################

# define RHSs of differential equations
# delta, V and g are parameters
function rhs(t, y, delta, V, g)
H = [[-delta/2 V]; [V delta/2]]

rho_dot = -im*H*y.rho + im*y.rho*H
x_dot = y.p
p_dot = -y.x

return CompSol( rho_dot, x_dot, p_dot)
end

# inital conditons
rho0 = zeros(2,2);
rho0[1,1]=1.;
Expand All @@ -77,6 +100,3 @@ for solver in solvers
@test norm(y1[end]-y2[end])<0.1
end
println("ok.")

################################################################################
# TODO: test a vector-like state variable, i.e. one which can be indexed.

0 comments on commit d68c1a0

Please sign in to comment.