Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basis - fix scaling for mesh #36

Merged
merged 1 commit into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 8 additions & 23 deletions src/Basis/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1230,31 +1230,25 @@ function getdXdxgradient(basis::TensorBasis, mesh::Mesh)

# coordinate transformation
gradient = basis.gradient
dxdX = (basis.gradient1d*basis.nodes1d)[1]

# adjust for mesh
if dimension == 1
# 1D
return gradient / (dxdX * mesh.dx)
return gradient / mesh.dx
elseif dimension == 2
# 2D
scalex = 1 / (dxdX * mesh.dx)
scaley = 1 / (dxdX * mesh.dy)
numberquadraturepoints = basis.numberquadraturepoints
return [
gradient[1:numberquadraturepoints, :] * scalex
gradient[numberquadraturepoints+1:end, :] * scaley
gradient[1:numberquadraturepoints, :] / mesh.dx
gradient[numberquadraturepoints+1:end, :] / mesh.dy
]
elseif dimension == 3
# 3D
scalex = 1 / (dxdX * mesh.dx)
scaley = 1 / (dxdX * mesh.dy)
scalez = 1 / (dxdX * mesh.dz)
numberquadraturepoints = basis.numberquadraturepoints
return [
gradient[1:numberquadraturepoints, :] * scalex
gradient[numberquadraturepoints+1:2*numberquadraturepoints, :] * scaley
gradient[2*numberquadraturepoints+1:end, :] * scalez
gradient[1:numberquadraturepoints, :] / mesh.dx
gradient[numberquadraturepoints+1:2*numberquadraturepoints, :] / mesh.dy
gradient[2*numberquadraturepoints+1:end, :] / mesh.dz
]
end
end
Expand Down Expand Up @@ -1288,7 +1282,7 @@ basis = TensorH1LagrangeBasis(4, 3, 1, 1);
weights = LFAToolkit.getdxdXquadratureweights(basis, mesh);

# verify
@assert basis.quadratureweights / 2 ≈ weights
@assert basis.quadratureweights * mesh.volume / basis.volume ≈ weights

# output

Expand All @@ -1303,17 +1297,8 @@ function getdxdXquadratureweights(basis::TensorBasis, mesh::Mesh)
error("mesh dimension must match basis dimension") # COV_EXCL_LINE
end

# coordinate transformation
dxdX = (basis.gradient1d*basis.nodes1d)[1]

# adjust for mesh
if dimension == 1
return dxdX * basis.quadratureweights / mesh.dx
elseif dimension == 2
return dxdX^2 * basis.quadratureweights / (mesh.dx * mesh.dy)
elseif dimension == 3
return dxdX^3 * basis.quadratureweights / (mesh.dx * mesh.dy * mesh.dz)
end
return basis.quadratureweights * mesh.volume / basis.volume
end

function getdxdXquadratureweights(basis::NonTensorBasis, mesh::Mesh)
Expand Down
5 changes: 1 addition & 4 deletions src/Operator/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,11 @@ function getelementmatrix(operator::Operator)
end

# quadrature weight input index
weightscale = 1.0
if weightinputindex != 0
quadratureweights = getdxdXquadratureweights(
operator.inputs[weightinputindex].basis,
operator.mesh,
)
weightscale =
operator.mesh.volume / operator.inputs[weightinputindex].basis.volume
end

# outputs
Expand Down Expand Up @@ -423,7 +420,7 @@ function getelementmatrix(operator::Operator)
for q = 1:numberquadraturepoints
# set quadrature weight
if weightinputindex != 0
weakforminputs[weightinputindex][1] = quadratureweights[q] * weightscale
weakforminputs[weightinputindex][1] = quadratureweights[q]
end

# fill sparse matrix
Expand Down