Skip to content

Commit

Permalink
hotfix for md.wJq initialization error
Browse files Browse the repository at this point in the history
fix: wJq was not being reinitialized for a curved mesh
  • Loading branch information
jlchan committed Oct 1, 2022
1 parent 3fe0f35 commit 0235348
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 28 deletions.
6 changes: 4 additions & 2 deletions src/MeshData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,10 @@ function MeshData(rd::RefElemData, md::MeshData{Dim}, xyz...) where {Dim}
end
geof = compute_normals(rstxyzJ, rd.Vf, rd.nrstJ...)

setproperties(md, (xyz=xyz, xyzq=xyzq, xyzf=xyzf,
rstxyzJ=rstxyzJ, J=last(geo),
J = last(geo)
wJq = diagm(rd.wq) * (rd.Vq * J)

setproperties(md, (xyz, xyzq, xyzf, rstxyzJ, J, wJq,
nxyzJ=geof[1:Dim], Jf=last(geof)))
end

Expand Down
52 changes: 26 additions & 26 deletions src/geometric_functions.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
geometric_factors(x, y, Dr, Ds)
geometric_factors(x, y, z, Dr, Ds, Dt, Filters=(I,I,I))
geometric_factors(x, y, z, Dr, Ds, Dt, Filters=(I, I, I))
Compute metrics of mappings between "real" elements and reference elements,
outward pointing normals on faces of every elements, and Jacobian.
Expand All @@ -14,8 +14,8 @@ meshes' (Kopriva 2006).
"""

function geometric_factors(x, y, Dr, Ds)
xr, xs = Dr*x, Ds*x
yr, ys = Dr*y, Ds*y
xr, xs = Dr * x, Ds * x
yr, ys = Dr * y, Ds * y

J = @. -xs * yr + xr * ys
rxJ, sxJ = ys, -yr
Expand All @@ -24,29 +24,29 @@ function geometric_factors(x, y, Dr, Ds)
return rxJ, sxJ, ryJ, syJ, J
end

function geometric_factors(x, y, z, Dr, Ds, Dt, Filters=(I,I,I))

xr, xs, xt = Dr*x, Ds*x, Dt*x
yr, ys, yt = Dr*y, Ds*y, Dt*y
zr, zs, zt = Dr*z, Ds*z, Dt*z

Fr, Fs, Ft = (Dr*y).*z, (Ds*y).*z, (Dt*y).*z
Fr,Fs,Ft = ((A,x)->A*x).(Filters,(Fr,Fs,Ft))
rxJ = Dt*(Fs) - Ds*(Ft)
sxJ = Dr*(Ft) - Dt*(Fr)
txJ = Ds*(Fr) - Dr*(Fs)

Fr, Fs, Ft = (Dr*x).*z, (Ds*x).*z, (Dt*x).*z
Fr,Fs,Ft = ((A,x)->A*x).(Filters,(Fr,Fs,Ft))
ryJ = -(Dt*(Fs) - Ds*(Ft))
syJ = -(Dr*(Ft) - Dt*(Fr))
tyJ = -(Ds*(Fr) - Dr*(Fs))

Fr, Fs, Ft = (Dr*y).*x, (Ds*y).*x, (Dt*y).*x
Fr,Fs,Ft = ((A,x)->A*x).(Filters,(Fr,Fs,Ft))
rzJ = -(Dt*(Fs) - Ds*(Ft))
szJ = -(Dr*(Ft) - Dt*(Fr))
tzJ = -(Ds*(Fr) - Dr*(Fs))
function geometric_factors(x, y, z, Dr, Ds, Dt, Filters=(I, I, I))

xr, xs, xt = Dr * x, Ds * x, Dt * x
yr, ys, yt = Dr * y, Ds * y, Dt * y
zr, zs, zt = Dr * z, Ds * z, Dt * z

Fr, Fs, Ft = (Dr * y) .* z, (Ds * y) .* z, (Dt * y) .* z
Fr, Fs, Ft = ((A, x)-> A * x).(Filters, (Fr, Fs, Ft))
rxJ = Dt * Fs - Ds * Ft
sxJ = Dr * Ft - Dt * Fr
txJ = Ds * Fr - Dr * Fs

Fr, Fs, Ft = (Dr * x) .* z, (Ds * x) .* z, (Dt * x) .* z
Fr, Fs, Ft = ((A, x) -> A * x).(Filters, (Fr, Fs, Ft))
ryJ = -(Dt * Fs - Ds * Ft)
syJ = -(Dr * Ft - Dt * Fr)
tyJ = -(Ds * Fr - Dr * Fs)

Fr, Fs, Ft = (Dr * y) .* x, (Ds * y) .* x, (Dt * y) .* x
Fr, Fs, Ft = ((A, x) -> A * x).(Filters, (Fr, Fs, Ft))
rzJ = -(Dt * Fs - Ds * Ft)
szJ = -(Dr * Ft - Dt * Fr)
tzJ = -(Ds * Fr - Dr * Fs)

J = @. xr * (ys * zt - zs * yt) - yr * (xs * zt - zs * xt) + zr * (xs * yt - ys * xt)

Expand Down
11 changes: 11 additions & 0 deletions test/MeshData_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@
@test uf uf[mapP]
end

@testset "2D curved tests" begin
rd = RefElemData(Quad(), N=4)
md = MeshData(uniform_mesh(Quad(), 4, 4)..., rd)
(; x, y) = md
x_curved = @. x + 0.1 * sin(pi * x) * sin(pi * y)
y_curved = @. y + 0.1 * sin(pi * x) * sin(pi * y)
md = MeshData(md, rd, x_curved, y_curved)
@test sum(@. md.wJq) 4
@test sum(@. md.wJq * md.xq^2) 4/3
end

@testset "3D hex mesh initialization" begin
tol = 5e2*eps()

Expand Down

0 comments on commit 0235348

Please sign in to comment.