test_interpolation4d.jl 1.35 KB
Newer Older
1
@testset "Hermite 4D" begin
Pierre Navaro's avatar
Pierre Navaro committed
2

3
    f(x, y, z, v) = cos(x^2 + y^2 + z^2 + v^2)
Pierre Navaro's avatar
Pierre Navaro committed
4

5
6
7
8
    xmin, xmax, nx = -1, 1, 32
    ymin, ymax, ny = -1, 1, 32
    zmin, zmax, nz = -1, 1, 32
    vmin, vmax, nv = -1, 1, 32
Pierre Navaro's avatar
Pierre Navaro committed
9

10
11
    ϵ = 0.1
    γ = 3.0
Pierre Navaro's avatar
Pierre Navaro committed
12

13
14
15
16
    hermite_x = Hermite(Chebyshev( xmin, xmax, nx ), ϵ, γ)
    hermite_y = Hermite(Chebyshev( ymin, ymax, ny ), ϵ, γ)
    hermite_z = Hermite(Chebyshev( zmin, zmax, nz ), ϵ, γ)
    hermite_v = Hermite(Chebyshev( vmin, vmax, nv ), ϵ, γ)
Pierre Navaro's avatar
Pierre Navaro committed
17

18
19
20
21
    xk = hermite_x.nodes
    yk = hermite_y.nodes
    zk = hermite_z.nodes
    vk = hermite_v.nodes
22

23
    nxe, nye, nze, nve = 32, 16, 16, 32
24

25
26
27
28
29
30
31
32
    xe = collect(range(xmin, stop=xmax, length=nxe))
    ye = collect(range(ymin, stop=ymax, length=nye))
    ze = collect(range(zmin, stop=zmax, length=nze))
    ve = collect(range(vmin, stop=vmax, length=nve))
    dx = abs(xe[2] - xe[1])
    dy = abs(ye[2] - ye[1])
    dz = abs(ze[2] - ze[1])
    dv = abs(ve[2] - ve[1])
33

34
35
    fk = [f(x, y, z, v) for x in xk, y in yk, z in zk, v in vk]
    fe = [f(x, y, z, v) for x in xe, y in ye, z in ze, v in ve]
36

37
    @time s  = interpolate(hermite_x, hermite_y, hermite_z, hermite_v, fk, xe, ye, ze, ve)
38

39
    max_error = maximum(abs.(s .- fe))
40

41
    l2_error  = sqrt(trapz((s - fe).^2, dx, dy, dz, dv))
42

43
44
    println(" Hermite 4d max error : $max_error ")
    println(" Hermite 4d L2  error : $l2_error  ")
45

46
    @test true
47

Pierre Navaro's avatar
Pierre Navaro committed
48
end