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

More flexibility for internal types #802

Merged
merged 24 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c0a3e16
More flexible sparsity pattern and allow different types than Float64…
termi-official Sep 29, 2023
0e616d4
Allow interpolations to eval to something different than Float64
termi-official Sep 29, 2023
1cffad6
Fix type stability issue regarding the throw for shape_value.
termi-official Sep 29, 2023
38742cc
Fix test.
termi-official Sep 29, 2023
b49b4c9
Revert sparsity pattern stuff. Development happens in the branch fe/d…
termi-official Oct 11, 2023
2fc1c14
Fix tests.
termi-official Oct 11, 2023
16b86b5
oops.
termi-official Oct 12, 2023
ccc6323
Merge branch 'master' into do/flexible-sparsity-pattern
termi-official Oct 12, 2023
a320eea
Add JET coverage on reinit to be sure.
termi-official Oct 12, 2023
b02e925
Partial revert of interpolation parametrization
termi-official Oct 12, 2023
7e3798e
Fix CI.
termi-official Oct 13, 2023
5ca39e7
Partial revert.
termi-official Oct 18, 2023
77eec99
Derp.
termi-official Oct 19, 2023
ba651c2
Derp.
termi-official Oct 19, 2023
b3a102e
Try to address Knut's comments
termi-official Oct 23, 2023
cc6ab96
More debris.
termi-official Oct 23, 2023
0abbece
Merge branch 'master' into do/flexible-sparsity-pattern
termi-official Nov 15, 2023
81adc0b
Apply suggestions from code review
termi-official Dec 6, 2023
09d5bee
Merge branch 'master' into do/flexible-sparsity-pattern
termi-official Dec 7, 2023
fbdfa23
review
fredrikekre Dec 10, 2023
01b8149
more review
fredrikekre Dec 10, 2023
d95de98
rev
fredrikekre Dec 10, 2023
1a09753
back out per
fredrikekre Dec 10, 2023
4843a07
Merge remote-tracking branch 'origin/master' into do/flexible-sparsit…
fredrikekre Dec 10, 2023
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
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ FerriteGmsh = "4f95f4f8-b27c-4ae5-9a39-ea55e634e36b"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Gmsh = "705231aa-382f-11e9-3f0c-b7cb4346fdeb"
IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Metis = "2679e427-3c69-5b7f-982b-ece356f1e94b"
NBInclude = "0db19996-df87-5ea3-a455-e3a50d440464"
Expand All @@ -49,4 +50,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"

[targets]
test = ["BlockArrays", "Downloads", "FerriteGmsh", "ForwardDiff", "Gmsh", "IterativeSolvers", "Metis", "NBInclude", "ProgressMeter", "Random", "SHA", "Test", "TimerOutputs", "Logging"]
test = ["BlockArrays", "Downloads", "FerriteGmsh", "ForwardDiff", "Gmsh", "IterativeSolvers", "JET", "Metis", "NBInclude", "ProgressMeter", "Random", "SHA", "Test", "TimerOutputs", "Logging"]
117 changes: 60 additions & 57 deletions src/Dofs/ConstraintHandler.jl
termi-official marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/FEValues/face_values.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ A `FaceValues` object facilitates the process of evaluating values of shape func
values of nodal functions, gradients and divergences of nodal functions etc. on the faces of finite elements.

**Arguments:**

* `T`: an optional argument to determine the type the internal data is stored as.
* `T`: an optional argument (default to `Float64`) to determine the type the internal data is stored as.
* `quad_rule`: an instance of a [`FaceQuadratureRule`](@ref)
* `func_interpol`: an instance of an [`Interpolation`](@ref) used to interpolate the approximated function
* `geom_interpol`: an optional instance of an [`Interpolation`](@ref) which is used to interpolate the geometry.
Expand Down
2 changes: 1 addition & 1 deletion src/PointEval/point_values.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
PointValues(cv::CellValues)
PointValues(ip_f::Interpolation, ip_g::Interpolation=ip_f)
PointValues([::Type{T}], func_interpol::Interpolation, [geom_interpol::Interpolation])

Similar to `CellValues` but with a single updateable
"quadrature point". `PointValues` are used for evaluation of functions/gradients in
Expand Down
6 changes: 4 additions & 2 deletions src/assembler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ struct Assembler{T}
V::Vector{T}
end

function Assembler(N)
Assembler(N) = Assembler(Float64, N)

function Assembler(T, N)
termi-official marked this conversation as resolved.
Show resolved Hide resolved
I = Int[]
J = Int[]
V = Float64[]
V = T[]
sizehint!(I, N)
sizehint!(J, N)
sizehint!(V, N)
Expand Down
137 changes: 69 additions & 68 deletions src/interpolations.jl
termi-official marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -461,16 +461,16 @@ function shape_value(::DiscontinuousLagrange{shape, order}, ξ::Vec{dim}, i::Int
end

# Excepting the L0 element.
function reference_coordinates(ip::DiscontinuousLagrange{RefHypercube{dim},0}) where dim
function reference_coordinates(ip::DiscontinuousLagrange{RefHypercube{dim},0}) where {dim}
return [Vec{dim, Float64}(ntuple(x->0.0, dim))]
end

function reference_coordinates(ip::DiscontinuousLagrange{RefTriangle,0})
return [Vec{2,Float64}((1/3,1/3))]
return [Vec{2, Float64}((1/3,1/3))]
end

function reference_coordinates(ip::DiscontinuousLagrange{RefTetrahedron,0})
return [Vec{3,Float64}((1/4,1/4,1/4))]
return [Vec{3, Float64}((1/4,1/4,1/4))]
end

function shape_value(ip::DiscontinuousLagrange{shape, 0}, ::Vec{dim, T}, i::Int) where {dim, shape <: AbstractRefShape{dim}, T}
Expand Down Expand Up @@ -517,8 +517,8 @@ end

function shape_value(ip::Lagrange{RefLine, 1}, ξ::Vec{1}, i::Int)
ξ_x = ξ[1]
i == 1 && return (1 - ξ_x) * 0.5
i == 2 && return (1 + ξ_x) * 0.5
i == 1 && return (1 - ξ_x) / 2
i == 2 && return (1 + ξ_x) / 2
throw(ArgumentError("no shape function $i for interpolation $ip"))
end

Expand All @@ -538,8 +538,8 @@ end

function shape_value(ip::Lagrange{RefLine, 2}, ξ::Vec{1}, i::Int)
ξ_x = ξ[1]
i == 1 && return ξ_x * (ξ_x - 1) * 0.5
i == 2 && return ξ_x * (ξ_x + 1) * 0.5
i == 1 && return ξ_x * (ξ_x - 1) / 2
i == 2 && return ξ_x * (ξ_x + 1) / 2
i == 3 && return 1 - ξ_x^2
throw(ArgumentError("no shape function $i for interpolation $ip"))
end
Expand All @@ -561,10 +561,10 @@ end
function shape_value(ip::Lagrange{RefQuadrilateral, 1}, ξ::Vec{2}, i::Int)
ξ_x = ξ[1]
ξ_y = ξ[2]
i == 1 && return (1 - ξ_x) * (1 - ξ_y) * 0.25
i == 2 && return (1 + ξ_x) * (1 - ξ_y) * 0.25
i == 3 && return (1 + ξ_x) * (1 + ξ_y) * 0.25
i == 4 && return (1 - ξ_x) * (1 + ξ_y) * 0.25
i == 1 && return (1 - ξ_x) * (1 - ξ_y) / 4
i == 2 && return (1 + ξ_x) * (1 - ξ_y) / 4
i == 3 && return (1 + ξ_x) * (1 + ξ_y) / 4
i == 4 && return (1 - ξ_x) * (1 + ξ_y) / 4
throw(ArgumentError("no shape function $i for interpolation $ip"))
end

Expand Down Expand Up @@ -592,14 +592,14 @@ end
function shape_value(ip::Lagrange{RefQuadrilateral, 2}, ξ::Vec{2}, i::Int)
ξ_x = ξ[1]
ξ_y = ξ[2]
i == 1 && return (ξ_x^2 - ξ_x) * (ξ_y^2 - ξ_y) * 0.25
i == 2 && return (ξ_x^2 + ξ_x) * (ξ_y^2 - ξ_y) * 0.25
i == 3 && return (ξ_x^2 + ξ_x) * (ξ_y^2 + ξ_y) * 0.25
i == 4 && return (ξ_x^2 - ξ_x) * (ξ_y^2 + ξ_y) * 0.25
i == 5 && return (1 - ξ_x^2) * (ξ_y^2 - ξ_y) * 0.5
i == 6 && return (ξ_x^2 + ξ_x) * (1 - ξ_y^2) * 0.5
i == 7 && return (1 - ξ_x^2) * (ξ_y^2 + ξ_y) * 0.5
i == 8 && return (ξ_x^2 - ξ_x) * (1 - ξ_y^2) * 0.5
i == 1 && return (ξ_x^2 - ξ_x) * (ξ_y^2 - ξ_y) / 4
i == 2 && return (ξ_x^2 + ξ_x) * (ξ_y^2 - ξ_y) / 4
i == 3 && return (ξ_x^2 + ξ_x) * (ξ_y^2 + ξ_y) / 4
i == 4 && return (ξ_x^2 - ξ_x) * (ξ_y^2 + ξ_y) / 4
i == 5 && return (1 - ξ_x^2) * (ξ_y^2 - ξ_y) / 2
i == 6 && return (ξ_x^2 + ξ_x) * (1 - ξ_y^2) / 2
i == 7 && return (1 - ξ_x^2) * (ξ_y^2 + ξ_y) / 2
i == 8 && return (ξ_x^2 - ξ_x) * (1 - ξ_y^2) / 2
i == 9 && return (1 - ξ_x^2) * (1 - ξ_y^2)
throw(ArgumentError("no shape function $i for interpolation $ip"))
end
Expand Down Expand Up @@ -635,8 +635,8 @@ end
function shape_value(ip::Lagrange{RefQuadrilateral, 3}, ξ::Vec{2}, i::Int)
# See https://defelement.com/elements/examples/quadrilateral-Q-3.html
# Transform domain from [-1, 1] × [-1, 1] to [0, 1] × [0, 1]
ξ_x = ξ[1]*0.5 + 0.5
ξ_y = ξ[2]*0.5 + 0.5
ξ_x = (ξ[1]+1)/2
ξ_y = (ξ[2]+1)/2
i == 1 && return (81*ξ_x^3*ξ_y^3)/4 - (81*ξ_x^3*ξ_y^2)/2 + (99*ξ_x^3*ξ_y)/4 - (9*ξ_x^3)/2 - (81*ξ_x^2*ξ_y^3)/2 + (81*ξ_x^2*ξ_y^2) - (99*ξ_x^2*ξ_y)/2 + (9*ξ_x^2) + (99*ξ_x*ξ_y^3)/4 - (99*ξ_x*ξ_y^2)/2 + (121*ξ_x*ξ_y)/4 - (11*ξ_x)/2 - (9*ξ_y^3)/2 + 9*ξ_y^2 - (11*ξ_y)/2 + 1
i == 2 && return (ξ_x*( - 81*ξ_x^2*ξ_y^3 + 162*ξ_x^2*ξ_y^2 - 99*ξ_x^2*ξ_y + 18*ξ_x^2 + 81*ξ_x*ξ_y^3 - 162*ξ_x*ξ_y^2 + 99*ξ_x*ξ_y - 18*ξ_x - 18*ξ_y^3 + 36*ξ_y^2 - 22*ξ_y + 4))/4
i == 4 && return (ξ_y*( - 81*ξ_x^3*ξ_y^2 + 81*ξ_x^3*ξ_y - 18*ξ_x^3 + 162*ξ_x^2*ξ_y^2 - 162*ξ_x^2*ξ_y + 36*ξ_x^2 - 99*ξ_x*ξ_y^2 + 99*ξ_x*ξ_y - 22*ξ_x + 18*ξ_y^2 - 18*ξ_y + 4))/4
Expand Down Expand Up @@ -674,7 +674,7 @@ function shape_value(ip::Lagrange{RefTriangle, 1}, ξ::Vec{2}, i::Int)
ξ_y = ξ[2]
i == 1 && return ξ_x
i == 2 && return ξ_y
i == 3 && return 1. - ξ_x - ξ_y
i == 3 && return 1 - ξ_x - ξ_y
throw(ArgumentError("no shape function $i for interpolation $ip"))
end

Expand All @@ -698,7 +698,7 @@ end
function shape_value(ip::Lagrange{RefTriangle, 2}, ξ::Vec{2}, i::Int)
ξ_x = ξ[1]
ξ_y = ξ[2]
γ = 1. - ξ_x - ξ_y
γ = 1 - ξ_x - ξ_y
i == 1 && return ξ_x * (2ξ_x - 1)
i == 2 && return ξ_y * (2ξ_y - 1)
i == 3 && return γ * (2γ - 1)
Expand Down Expand Up @@ -822,7 +822,7 @@ function shape_value(ip::Lagrange{RefTetrahedron, 1}, ξ::Vec{3}, i::Int)
ξ_x = ξ[1]
ξ_y = ξ[2]
ξ_z = ξ[3]
i == 1 && return 1.0 - ξ_x - ξ_y - ξ_z
i == 1 && return 1 - ξ_x - ξ_y - ξ_z
i == 2 && return ξ_x
i == 3 && return ξ_y
i == 4 && return ξ_z
Expand Down Expand Up @@ -893,14 +893,14 @@ function shape_value(ip::Lagrange{RefHexahedron, 1}, ξ::Vec{3}, i::Int)
ξ_x = ξ[1]
ξ_y = ξ[2]
ξ_z = ξ[3]
i == 1 && return 0.125(1 - ξ_x) * (1 - ξ_y) * (1 - ξ_z)
i == 2 && return 0.125(1 + ξ_x) * (1 - ξ_y) * (1 - ξ_z)
i == 3 && return 0.125(1 + ξ_x) * (1 + ξ_y) * (1 - ξ_z)
i == 4 && return 0.125(1 - ξ_x) * (1 + ξ_y) * (1 - ξ_z)
i == 5 && return 0.125(1 - ξ_x) * (1 - ξ_y) * (1 + ξ_z)
i == 6 && return 0.125(1 + ξ_x) * (1 - ξ_y) * (1 + ξ_z)
i == 7 && return 0.125(1 + ξ_x) * (1 + ξ_y) * (1 + ξ_z)
i == 8 && return 0.125(1 - ξ_x) * (1 + ξ_y) * (1 + ξ_z)
i == 1 && return (1 - ξ_x) * (1 - ξ_y) * (1 - ξ_z) / 8
i == 2 && return (1 + ξ_x) * (1 - ξ_y) * (1 - ξ_z) / 8
i == 3 && return (1 + ξ_x) * (1 + ξ_y) * (1 - ξ_z) / 8
i == 4 && return (1 - ξ_x) * (1 + ξ_y) * (1 - ξ_z) / 8
i == 5 && return (1 - ξ_x) * (1 - ξ_y) * (1 + ξ_z) / 8
i == 6 && return (1 + ξ_x) * (1 - ξ_y) * (1 + ξ_z) / 8
i == 7 && return (1 + ξ_x) * (1 + ξ_y) * (1 + ξ_z) / 8
i == 8 && return (1 - ξ_x) * (1 + ξ_y) * (1 + ξ_z) / 8
throw(ArgumentError("no shape function $i for interpolation $ip"))
end

Expand Down Expand Up @@ -977,11 +977,11 @@ function reference_coordinates(::Lagrange{RefHexahedron,2})
]
end

function shape_value(ip::Lagrange{RefHexahedron, 2}, ξ::Vec{3, T}, i::Int) where {T}
function shape_value(ip::Lagrange{RefHexahedron, 2}, ξ::Vec{3, T}, i::Int) where T
# Some local helpers.
@inline φ₁(x::T) = -0.5*x*(1-x)
@inline φ₁(x::T) = -x*(1-x)/2
@inline φ₂(x::T) = (1+x)*(1-x)
@inline φ₃(x::T) = 0.5*x*(1+x)
@inline φ₃(x::T) = x*(1+x)/2
(ξ_x, ξ_y, ξ_z) = ξ
# vertices
i == 1 && return φ₁(ξ_x) * φ₁(ξ_y) * φ₁(ξ_z)
Expand Down Expand Up @@ -1333,14 +1333,14 @@ end
function shape_value(ip::Serendipity{RefQuadrilateral,2}, ξ::Vec{2}, i::Int)
ξ_x = ξ[1]
ξ_y = ξ[2]
i == 1 && return (1 - ξ_x) * (1 - ξ_y) * 0.25(-ξ_x - ξ_y - 1)
i == 2 && return (1 + ξ_x) * (1 - ξ_y) * 0.25( ξ_x - ξ_y - 1)
i == 3 && return (1 + ξ_x) * (1 + ξ_y) * 0.25( ξ_x + ξ_y - 1)
i == 4 && return (1 - ξ_x) * (1 + ξ_y) * 0.25(-ξ_x + ξ_y - 1)
i == 5 && return 0.5(1 - ξ_x * ξ_x) * (1 - ξ_y)
i == 6 && return 0.5(1 + ξ_x) * (1 - ξ_y * ξ_y)
i == 7 && return 0.5(1 - ξ_x * ξ_x) * (1 + ξ_y)
i == 8 && return 0.5(1 - ξ_x) * (1 - ξ_y * ξ_y)
i == 1 && return (1 - ξ_x) * (1 - ξ_y) * (-ξ_x - ξ_y - 1) / 4
i == 2 && return (1 + ξ_x) * (1 - ξ_y) * ( ξ_x - ξ_y - 1) / 4
i == 3 && return (1 + ξ_x) * (1 + ξ_y) * ( ξ_x + ξ_y - 1) / 4
i == 4 && return (1 - ξ_x) * (1 + ξ_y) * (-ξ_x + ξ_y - 1) / 4
i == 5 && return (1 - ξ_x * ξ_x) * (1 - ξ_y) / 2
i == 6 && return (1 + ξ_x) * (1 - ξ_y * ξ_y) / 2
i == 7 && return (1 - ξ_x * ξ_x) * (1 + ξ_y) / 2
i == 8 && return (1 - ξ_x) * (1 - ξ_y * ξ_y) / 2
throw(ArgumentError("no shape function $i for interpolation $ip"))
end

Expand Down Expand Up @@ -1401,30 +1401,31 @@ function reference_coordinates(::Serendipity{RefHexahedron,2})
Vec{3, Float64}((-1.0, 1.0, 0.0)),]
end

function shape_value(ip::Serendipity{RefHexahedron, 2}, ξ::Vec{3}, i::Int)
# Inlined to resolve the recursion properly
@inline function shape_value(ip::Serendipity{RefHexahedron, 2}, ξ::Vec{3}, i::Int)
ξ_x = ξ[1]
ξ_y = ξ[2]
ξ_z = ξ[3]
i == 1 && return 0.125(1 - ξ_x) * (1 - ξ_y) * (1 - ξ_z) - 0.5(shape_value(ip, ξ, 12) + shape_value(ip, ξ, 9) + shape_value(ip, ξ, 17))
i == 2 && return 0.125(1 + ξ_x) * (1 - ξ_y) * (1 - ξ_z) - 0.5(shape_value(ip, ξ, 9) + shape_value(ip, ξ, 10) + shape_value(ip, ξ, 18))
i == 3 && return 0.125(1 + ξ_x) * (1 + ξ_y) * (1 - ξ_z) - 0.5(shape_value(ip, ξ, 10) + shape_value(ip, ξ, 11) + shape_value(ip, ξ, 19))
i == 4 && return 0.125(1 - ξ_x) * (1 + ξ_y) * (1 - ξ_z) - 0.5(shape_value(ip, ξ, 11) + shape_value(ip, ξ, 12) + shape_value(ip, ξ, 20))
i == 5 && return 0.125(1 - ξ_x) * (1 - ξ_y) * (1 + ξ_z) - 0.5(shape_value(ip, ξ, 16) + shape_value(ip, ξ, 13) + shape_value(ip, ξ, 17))
i == 6 && return 0.125(1 + ξ_x) * (1 - ξ_y) * (1 + ξ_z) - 0.5(shape_value(ip, ξ, 13) + shape_value(ip, ξ, 14) + shape_value(ip, ξ, 18))
i == 7 && return 0.125(1 + ξ_x) * (1 + ξ_y) * (1 + ξ_z) - 0.5(shape_value(ip, ξ, 14) + shape_value(ip, ξ, 15) + shape_value(ip, ξ, 19))
i == 8 && return 0.125(1 - ξ_x) * (1 + ξ_y) * (1 + ξ_z) - 0.5(shape_value(ip, ξ, 15) + shape_value(ip, ξ, 16) + shape_value(ip, ξ, 20))
i == 9 && return 0.25(1 - ξ_x^2) * (1 - ξ_y) * (1 - ξ_z)
i == 10 && return 0.25(1 + ξ_x) * (1 - ξ_y^2) * (1 - ξ_z)
i == 11 && return 0.25(1 - ξ_x^2) * (1 + ξ_y) * (1 - ξ_z)
i == 12 && return 0.25(1 - ξ_x) * (1 - ξ_y^2) * (1 - ξ_z)
i == 13 && return 0.25(1 - ξ_x^2) * (1 - ξ_y) * (1 + ξ_z)
i == 14 && return 0.25(1 + ξ_x) * (1 - ξ_y^2) * (1 + ξ_z)
i == 15 && return 0.25(1 - ξ_x^2) * (1 + ξ_y) * (1 + ξ_z)
i == 16 && return 0.25(1 - ξ_x) * (1 - ξ_y^2) * (1 + ξ_z)
i == 17 && return 0.25(1 - ξ_x) * (1 - ξ_y) * (1 - ξ_z^2)
i == 18 && return 0.25(1 + ξ_x) * (1 - ξ_y) * (1 - ξ_z^2)
i == 19 && return 0.25(1 + ξ_x) * (1 + ξ_y) * (1 - ξ_z^2)
i == 20 && return 0.25(1 - ξ_x) * (1 + ξ_y) * (1 - ξ_z^2)
i == 1 && return (1 - ξ_x) * (1 - ξ_y) * (1 - ξ_z) / 8 - (shape_value(ip, ξ, 12) + shape_value(ip, ξ, 9) + shape_value(ip, ξ, 17)) / 2
i == 2 && return (1 + ξ_x) * (1 - ξ_y) * (1 - ξ_z) / 8 - (shape_value(ip, ξ, 9) + shape_value(ip, ξ, 10) + shape_value(ip, ξ, 18)) / 2
i == 3 && return (1 + ξ_x) * (1 + ξ_y) * (1 - ξ_z) / 8 - (shape_value(ip, ξ, 10) + shape_value(ip, ξ, 11) + shape_value(ip, ξ, 19)) / 2
i == 4 && return (1 - ξ_x) * (1 + ξ_y) * (1 - ξ_z) / 8 - (shape_value(ip, ξ, 11) + shape_value(ip, ξ, 12) + shape_value(ip, ξ, 20)) / 2
i == 5 && return (1 - ξ_x) * (1 - ξ_y) * (1 + ξ_z) / 8 - (shape_value(ip, ξ, 16) + shape_value(ip, ξ, 13) + shape_value(ip, ξ, 17)) / 2
i == 6 && return (1 + ξ_x) * (1 - ξ_y) * (1 + ξ_z) / 8 - (shape_value(ip, ξ, 13) + shape_value(ip, ξ, 14) + shape_value(ip, ξ, 18)) / 2
i == 7 && return (1 + ξ_x) * (1 + ξ_y) * (1 + ξ_z) / 8 - (shape_value(ip, ξ, 14) + shape_value(ip, ξ, 15) + shape_value(ip, ξ, 19)) / 2
i == 8 && return (1 - ξ_x) * (1 + ξ_y) * (1 + ξ_z) / 8 - (shape_value(ip, ξ, 15) + shape_value(ip, ξ, 16) + shape_value(ip, ξ, 20)) / 2
i == 9 && return (1 - ξ_x^2) * (1 - ξ_y) * (1 - ξ_z) / 4
i == 10 && return (1 + ξ_x) * (1 - ξ_y^2) * (1 - ξ_z) / 4
i == 11 && return (1 - ξ_x^2) * (1 + ξ_y) * (1 - ξ_z) / 4
i == 12 && return (1 - ξ_x) * (1 - ξ_y^2) * (1 - ξ_z) / 4
i == 13 && return (1 - ξ_x^2) * (1 - ξ_y) * (1 + ξ_z) / 4
i == 14 && return (1 + ξ_x) * (1 - ξ_y^2) * (1 + ξ_z) / 4
i == 15 && return (1 - ξ_x^2) * (1 + ξ_y) * (1 + ξ_z) / 4
i == 16 && return (1 - ξ_x) * (1 - ξ_y^2) * (1 + ξ_z) / 4
i == 17 && return (1 - ξ_x) * (1 - ξ_y) * (1 - ξ_z^2) / 4
i == 18 && return (1 + ξ_x) * (1 - ξ_y) * (1 - ξ_z^2) / 4
i == 19 && return (1 + ξ_x) * (1 + ξ_y) * (1 - ξ_z^2) / 4
i == 20 && return (1 - ξ_x) * (1 + ξ_y) * (1 - ξ_z^2) / 4
throw(ArgumentError("no shape function $i for interpolation $ip"))
end

Expand Down Expand Up @@ -1458,12 +1459,12 @@ function reference_coordinates(::CrouzeixRaviart)
Vec{2, Float64}((0.5, 0.0))]
end

function shape_value(ip::CrouzeixRaviart, ξ::Vec{2}, i::Int)
function shape_value(ip::CrouzeixRaviart{RefTriangle, 1}, ξ::Vec{2}, i::Int)
ξ_x = ξ[1]
ξ_y = ξ[2]
i == 1 && return 2*ξ_x + 2*ξ_y - 1.0
i == 2 && return 1.0 - 2*ξ_x
i == 3 && return 1.0 - 2*ξ_y
i == 1 && return 2*ξ_x + 2*ξ_y - 1
i == 2 && return 1 - 2*ξ_x
i == 3 && return 1 - 2*ξ_y
throw(ArgumentError("no shape function $i for interpolation $ip"))
end

Expand Down
4 changes: 2 additions & 2 deletions src/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ function CellCache(dh::DofHandler{dim}, flags::UpdateFlags=UpdateFlags()) where
end

function CellCache(sdh::SubDofHandler, flags::UpdateFlags=UpdateFlags())
dim = getdim(sdh.dh.grid)
CellCache(flags, sdh.dh.grid, ScalarWrapper(-1), Int[], Vec{dim,Float64}[], sdh, Int[])
Tv = get_coordinate_type(sdh.dh.grid)
CellCache(flags, sdh.dh.grid, ScalarWrapper(-1), Int[], Tv[], sdh, Int[])
end

function reinit!(cc::CellCache, i::Int)
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ if HAS_EXTENSIONS && MODULE_CAN_BE_TYPE_PARAMETER
import Metis
end

const TEST_TYPE_STABILITY = VERSION >= v"1.9"

if TEST_TYPE_STABILITY
using JET
else
# Just eat the macro on incompatible versions
macro test_call(args...)
nothing
end
end

include("test_utils.jl")

# Unit tests
Expand Down
7 changes: 7 additions & 0 deletions test/test_cellvalues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

x, n = valid_coordinates_and_normals(func_interpol)
reinit!(cv, x)
@test_call reinit!(cv, x)

# We test this by applying a given deformation gradient on all the nodes.
# Since this is a linear deformation we should get back the exact values
Expand Down Expand Up @@ -179,6 +180,7 @@ end
## sdim = 2, Consistency with 1D
csv2 = CellValues(qr, ip, ip_base^2)
reinit!(csv2, [Vec((0.0, 0.0)), Vec((1.0, 0.0))])
@test_call skip=true reinit!(csv2, [Vec((0.0, 0.0)), Vec((1.0, 0.0))]) # External error in pinv
# Test spatial interpolation
@test spatial_coordinate(csv2, 1, [Vec((0.0, 0.0)), Vec((1.0, 0.0))]) == Vec{2}((0.5, 0.0))
# Test volume
Expand All @@ -199,6 +201,7 @@ end
## sdim = 3, Consistency with 1D
csv3 = CellValues(qr, ip, ip_base^3)
reinit!(csv3, [Vec((0.0, 0.0, 0.0)), Vec((1.0, 0.0, 0.0))])
@test_call skip=true reinit!(csv3, [Vec((0.0, 0.0, 0.0)), Vec((1.0, 0.0, 0.0))]) # External error in pinv
# Test spatial interpolation
@test spatial_coordinate(csv3, 1, [Vec((0.0, 0.0, 0.0)), Vec((1.0, 0.0, 0.0))]) == Vec{3}((0.5, 0.0, 0.0))
# Test volume
Expand Down Expand Up @@ -261,7 +264,9 @@ end
csv2 = CellValues(qr, ip)
csv3 = CellValues(qr, ip, ip_base^3)
reinit!(csv2, [Vec((-1.0,-1.0)), Vec((1.0,-1.0)), Vec((1.0,1.0)), Vec((-1.0,1.0))])
@test_call skip=true reinit!(csv2, [Vec((-1.0,-1.0)), Vec((1.0,-1.0)), Vec((1.0,1.0)), Vec((-1.0,1.0))]) # External error in pinv
reinit!(csv3, [Vec((-1.0,-1.0,0.0)), Vec((1.0,-1.0,0.0)), Vec((1.0,1.0,0.0)), Vec((-1.0,1.0,0.0))])
@test_call skip=true reinit!(csv3, [Vec((-1.0,-1.0,0.0)), Vec((1.0,-1.0,0.0)), Vec((1.0,1.0,0.0)), Vec((-1.0,1.0,0.0))]) # External error in pinv
# Test spatial interpolation
@test spatial_coordinate(csv2, 1, [Vec((-1.0,-1.0)), Vec((1.0,-1.0)), Vec((1.0,1.0)), Vec((-1.0,1.0))]) == Vec{2}((0.0, 0.0))
@test spatial_coordinate(csv3, 1, [Vec((-1.0,-1.0,0.0)), Vec((1.0,-1.0,0.0)), Vec((1.0,1.0,0.0)), Vec((-1.0,1.0,0.0))]) == Vec{3}((0.0, 0.0, 0.0))
Expand Down Expand Up @@ -307,6 +312,8 @@ end
@test Ferrite.shape_gradient_type(cv) == grad_type(Float32)
@test cv.gip == scalar_ip(geo_ip)
end
x = Ferrite.reference_coordinates(fun_ip)
@test_call reinit!(cv, x)
end
end

Expand Down
1 change: 1 addition & 0 deletions test/test_dofs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ end

# Full coupling (default)
K = create_sparsity_pattern(dh)
@test eltype(K) == Float64
for j in 1:ndofs(dh), i in 1:ndofs(dh)
@test is_stored(K, i, j)
end
Expand Down
Loading