Skip to content

Commit

Permalink
Merge pull request #36 from jeremylt/jeremy/scaling
Browse files Browse the repository at this point in the history
basis - fix scaling for mesh
  • Loading branch information
jeremylt authored Dec 13, 2021
2 parents d7760ee + 06421cb commit e3cf43d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
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

0 comments on commit e3cf43d

Please sign in to comment.