-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_interface.jl
More file actions
168 lines (124 loc) · 5.35 KB
/
test_interface.jl
File metadata and controls
168 lines (124 loc) · 5.35 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
module TestInterface
using Test
using LibTrixi
@testset verbose=true showtiming=true "Version information" begin
libtrixi_version = VersionNumber(unsafe_string(trixi_version_library()))
@test libtrixi_version.major == trixi_version_library_major()
@test libtrixi_version.minor == trixi_version_library_minor()
@test libtrixi_version.patch == trixi_version_library_patch()
@test occursin("OrdinaryDiffEq", unsafe_string(trixi_version_julia()))
@test occursin("Trixi", unsafe_string(trixi_version_julia()))
@test occursin("StartUpDG", unsafe_string(trixi_version_julia_extended()))
end
@testset verbose=true showtiming=true "Evaluate string as code (trixi_eval_string)" begin
# We can't really do much more than a smoke test, since the C API does not return
# anything useful
@test_throws UndefVarError trixi_eval_julia(Cstring(pointer("wololo")))
end
libelixir = joinpath(dirname(pathof(LibTrixi)),
"../examples/libelixir_tree1d_dgsem_advection_basic.jl")
# initialize a simulation via API, receive a handle
handle = trixi_initialize_simulation(libelixir)
# initialize the same simulation directly from julia, get a simstate object
simstate_jl = trixi_initialize_simulation_jl(libelixir)
@testset verbose=true showtiming=true "Simulation handle" begin
# one handle was created
@test LibTrixi.simstate_counter[] == handle == 1
# simstates are not the same
@test LibTrixi.simstates[handle] != simstate_jl
# using a non-existent handle
@test_throws ErrorException trixi_is_finished(Int32(42))
end
@testset verbose=true showtiming=true "Simulation control" begin
# do a step via API
trixi_step(handle)
# do a step via julia
trixi_step_jl(simstate_jl)
# compare time step length
dt_c = trixi_calculate_dt(handle)
dt_jl = trixi_calculate_dt_jl(simstate_jl)
@test dt_c == dt_jl
# compare time
time_c = trixi_get_simulation_time(handle)
time_jl = trixi_get_simulation_time_jl(simstate_jl)
@test time_c == time_jl
# compare finished status
@test trixi_is_finished(handle) == 0
@test !trixi_is_finished_jl(simstate_jl)
# manually increase registries (for testing only!)
push!(simstate_jl.registry, Vector{Float64}())
push!(LibTrixi.simstates[handle].registry, Vector{Float64}())
# store a vector
test_data = [1.0, 2.0, 3.0]
trixi_register_data(handle, Int32(1), Int32(3), pointer(test_data))
trixi_register_data_jl(simstate_jl, 1, test_data)
# check that the same memory is referenced
@test pointer(simstate_jl.registry[1]) ==
pointer(LibTrixi.simstates[handle].registry[1])
end
@testset verbose=true showtiming=true "Data access" begin
# compare number of dimensions
ndims_c = trixi_ndims(handle)
ndims_jl = trixi_ndims_jl(simstate_jl)
@test ndims_c == ndims_jl
# compare number of elements
nelements_c = trixi_nelements(handle)
nelements_jl = trixi_nelements_jl(simstate_jl)
@test nelements_c == nelements_jl
nelementsglobal_c = trixi_nelementsglobal(handle)
nelementsglobal_jl = trixi_nelementsglobal_jl(simstate_jl)
@test nelementsglobal_c == nelementsglobal_jl
# compare number of dofs
ndofs_c = trixi_ndofs(handle)
ndofs_jl = trixi_ndofs_jl(simstate_jl)
@test ndofs_c == ndofs_jl
ndofsglobal_c = trixi_ndofsglobal(handle)
ndofsglobal_jl = trixi_ndofsglobal_jl(simstate_jl)
@test ndofsglobal_c == ndofsglobal_jl
ndofselement_c = trixi_ndofselement(handle)
ndofselement_jl = trixi_ndofselement_jl(simstate_jl)
@test ndofselement_c == ndofselement_jl
# compare number of variables
nvariables_c = trixi_nvariables(handle)
nvariables_jl = trixi_nvariables_jl(simstate_jl)
@test nvariables_c == nvariables_jl
# compare number of quadrature nodes
nnodes_c = trixi_nnodes(handle)
nnodes_jl = trixi_nnodes_jl(simstate_jl)
@test nnodes_c == nnodes_jl
# compare coordinates of quadrature nodes
data_c = zeros(nnodes_c)
trixi_load_node_reference_coordinates(handle, pointer(data_c))
data_jl = zeros(nnodes_jl)
trixi_load_node_reference_coordinates_jl(simstate_jl, data_jl)
@test data_c == data_jl
# compare weights of quadrature nodes
data_c = zeros(nnodes_c)
trixi_load_node_weights(handle, pointer(data_c))
data_jl = zeros(nnodes_jl)
trixi_load_node_weights_jl(simstate_jl, data_jl)
@test data_c == data_jl
# compare element averaged values
data_c = zeros(nelements_c)
trixi_load_element_averaged_primitive_vars(handle, Int32(1), pointer(data_c))
data_jl = zeros(nelements_jl)
trixi_load_element_averaged_primitive_vars_jl(simstate_jl, 1, data_jl)
@test data_c == data_jl
# compare primitive variable values on all dofs
data_c = zeros(ndofs_c)
trixi_load_primitive_vars(handle, Int32(1), pointer(data_c))
data_jl = zeros(ndofs_jl)
trixi_load_primitive_vars_jl(simstate_jl, 1, data_jl)
@test data_c == data_jl
end
@testset verbose=true showtiming=true "Finalization" begin
# finalize simulation from julia
trixi_finalize_simulation_jl(simstate_jl)
# finalize simulation from API
trixi_finalize_simulation(handle)
# handle is now invalid
@test_throws ErrorException trixi_is_finished(handle)
# simulation cannot be finalized a second time
@test_throws ErrorException trixi_finalize_simulation(handle)
end
end # module