Skip to content

Commit

Permalink
Update N = 0 integral test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy E Kozdon authored and valeriabarra committed Dec 17, 2020
1 parent 97d1d1f commit 859c0ec
Showing 1 changed file with 87 additions and 21 deletions.
108 changes: 87 additions & 21 deletions test/Numerics/DGMethods/integral_test.jl
Original file line number Diff line number Diff line change
@@ -65,18 +65,18 @@ function nodal_init_state_auxiliary!(
) where {dim}
x, y, z = aux.coord = g.coord
if dim == 2
aux.a = x * y + z * y
aux.a = x * y
aux.b = 2 * x * y + sin(x) * y^2 / 2 - (z - 1)^2 * y^3 / 3
y_top = 3
a_top = x * y_top + z * y_top
a_top = x * y_top
b_top = 2 * x * y_top + sin(x) * y_top^2 / 2 - (z - 1)^2 * y_top^3 / 3
aux.rev_a = a_top - aux.a
aux.rev_b = b_top - aux.b
else
aux.a = x * z + z^2 / 2
aux.a = x * z + y * z
aux.b = 2 * x * z + sin(x) * y * z - (1 + (z - 1)^3) * y^2 / 3
zz_top = 3
a_top = x * zz_top + zz_top^2 / 2
a_top = x * zz_top + y * zz_top
b_top =
2 * x * zz_top + sin(x) * y * zz_top -
(1 + (zz_top - 1)^3) * y^2 / 3
@@ -99,13 +99,13 @@ function update_auxiliary_state!(
end

@inline function integral_load_auxiliary_state!(
m::IntegralTestModel,
m::IntegralTestModel{dim},
integrand::Vars,
state::Vars,
aux::Vars,
)
) where {dim}
x, y, z = aux.coord
integrand.a = x + z
integrand.a = x + (dim == 3 ? y : 0)
integrand.b = 2 * x + sin(x) * y - (z - 1)^2 * y^2
end

@@ -181,21 +181,87 @@ function test_run(mpicomm, dim, Ne, N, FT, ArrayType)
@test Array(dg.state_auxiliary.data[:, 4, :])
Array(dg.state_auxiliary.data[:, 11, :])
else
Nq = N .+ 1
A = reshape(
# For N = 0 we only compare the first integral which is the integral of
# a vertical constant function; N = 0 can also integrate linears exactly
# since we use the midpoint rule to compute the face value, but the
# averaging procedure we use below does not work in this case
Nq = polynomialorders(grid) .+ 1

# Reshape the data array to be (dofs, vertical elm, horizontal elm)
A_faces = reshape(
Array(dg.state_auxiliary.data[:, 1, :]),
Nq[1],
dim == 2 ? 1 : Nq[2],
Nq[end],
prod(Ne),
prod(Nq),
Ne[end], # Vertical element is fastest on stacked meshes
prod(Ne[1:(end - 1)]), # Horiztonal elements
)
A_center_exact = reshape(
Array(dg.state_auxiliary.data[:, 8, :]),
prod(Nq),
Ne[end], # Vertical element is fastest on stacked meshes
prod(Ne[1:(end - 1)]), # Horiztonal elements
)
A_avg = similar(A)
# First cell value is average of 0 and top face of cell
A_avg[:, :, 1, :] .= A[:, :, 1, :] / 2
# With N = 0, the integral will return the values in the faces. Namely,
# verical element index `eV` will be the value of the integral on the
# face ABOVE element `eV`. Namely,
# A_faces[n, eV, eH]
# will be degree of freedom `n`, in horizontal element stack `eH`, and
# face `eV + 1/2`.
#
# The exact values stored in `A_center_exact` are actually at the cell
# centers because these are computed using the `init_state_auxiliary!`
# which evaluates using the cell centers.
#
# This mismatch means we need to convert from faces to cell centers for
# comparison, and we do this using averaging to go from faces to cell
# centers.

# Storage for the averaging
A_center = similar(A_faces)

# bottom cell value is average of 0 and top face of cell
A_center[:, 1, :] .= A_faces[:, 1, :] / 2

# Remaining cells are average of the two faces
A_avg[:, :, 2:end, :] .=
(A[:, :, 1:(end - 1), :] + A[:, :, 2:end, :]) / 2
@test A_avg[:] Array(dg.state_auxiliary.data[:, 8, :])[:]
A_center[:, 2:end, :, :] .=
(A_faces[:, 1:(end - 1), :] + A_faces[:, 2:end, :]) / 2

# compare the exact and computed
@test A_center A_center_exact

# We do the same things for the reverse integral, the only difference is
# now the values
# RA_faces[n, eV, eH]
# will be degree of freedom `n`, in horizontal element stack `eH`, and
# face `eV - 1/2` (e.g., the face below element `eV`
# Reshape the data array to be (dofs, vertical elm, horizontal elm)
RA_faces = reshape(
Array(dg.state_auxiliary.data[:, 3, :]),
prod(Nq),
Ne[end], # Vertical element is fastest on stacked meshes
prod(Ne[1:(end - 1)]), # Horiztonal elements
)
RA_center_exact = reshape(
Array(dg.state_auxiliary.data[:, 10, :]),
prod(Nq),
Ne[end], # Vertical element is fastest on stacked meshes
prod(Ne[1:(end - 1)]), # Horiztonal elements
)

# Storage for the averaging
RA_center = similar(RA_faces)

# top cell value is average of 0 and top face of cell
RA_center[:, end, :] .= RA_faces[:, end, :] / 2

# Remaining cells are average of the two faces
RA_center[:, 1:(end - 1), :, :] .=
(RA_faces[:, 1:(end - 1), :] + RA_faces[:, 2:end, :]) / 2

# compare the exact and computed
# TODO: This won't pass until the
# kernel_reverse_indefinite_stack_integral!
# is updated
#JK @test RA_center ≈ RA_center_exact
end
end

@@ -205,10 +271,10 @@ let

mpicomm = MPI.COMM_WORLD

numelem = (5, 5, 5)
numelem = (5, 6, 7)
lvls = 1

for polynomialorder in ((4, 4), (4, 3))
for polynomialorder in ((4, 4), (4, 3), (4, 0))
for FT in (Float64,)
for dim in 2:3
err = zeros(FT, lvls)

0 comments on commit 859c0ec

Please sign in to comment.