-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathQuadratures.jl
144 lines (117 loc) · 3.37 KB
/
Quadratures.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"""
abstract type Quadrature{D,T} <: GridapType end
-[`get_coordinates(q::Quadrature)`](@ref)
-[`get_weights(q::Quadrature)`](@ref)
-[`test_quadrature`](@ref)
"""
abstract type Quadrature{D,T} <: GridapType end
# Abstract API
"""
get_coordinates(q::Quadrature)
"""
function get_coordinates(q::Quadrature)
@abstractmethod
end
"""
get_weights(q::Quadrature)
"""
function get_weights(q::Quadrature)
@abstractmethod
end
"""
get_name(q::Quadrature)
"""
function get_name(q::Quadrature)
@abstractmethod
end
# Default API
"""
num_points(q::Quadrature)
"""
num_points(q::Quadrature) = length(get_weights(q))
"""
num_point_dims(::Quadrature{D}) where D
num_point_dims(::Type{<:Quadrature{D}}) where D
"""
num_point_dims(::Quadrature{D}) where D = D
num_point_dims(::Type{<:Quadrature{D}}) where D = D
"""
num_dims(::Quadrature{D}) where D where D
num_dims(::Type{<:Quadrature{D}}) where D
"""
num_dims(::Quadrature{D}) where D = D
num_dims(::Type{<:Quadrature{D}}) where D = D
# Tester
"""
test_quadrature(q::Quadrature{D,T}) where {D,T}
"""
function test_quadrature(q::Quadrature{D,T}) where {D,T}
x = get_coordinates(q)
w = get_weights(q)
@test isa(x,AbstractVector{Point{D,T}})
@test isa(w,AbstractVector{T})
@test length(x) == num_points(q)
@test length(w) == num_points(q)
@test D == num_dims(q)
@test D == num_point_dims(q)
@test D == num_dims(typeof(q))
@test D == num_point_dims(typeof(q))
end
# Generic concrete implementation
"""
struct GenericQuadrature{D,T,C <: AbstractVector{Point{D,T}},W <: AbstractVector{T}} <: Quadrature{D,T}
coordinates::Vector{Point{D,T}}
weights::Vector{T}
name::String
end
"""
struct GenericQuadrature{D,T,C <: AbstractVector{Point{D,T}},W <: AbstractVector{T}} <: Quadrature{D,T}
coordinates::C
weights::W
name::String
end
function GenericQuadrature(
coordinates::AbstractVector{Point{D,T}}, weights::AbstractVector{T}) where {D,T}
name = "Unknown"
GenericQuadrature(coordinates,weights,name)
end
get_coordinates(q::GenericQuadrature) = q.coordinates
get_weights(q::GenericQuadrature) = q.weights
get_name(q::GenericQuadrature) = q.name
function GenericQuadrature(a::Quadrature)
GenericQuadrature(get_coordinates(a),get_weights(a),get_name(a))
end
function GenericQuadrature(a::GenericQuadrature)
a
end
# Quadrature factory
abstract type QuadratureName end
@noinline function Quadrature(p::Polytope,name::QuadratureName,args...;kwargs...)
@unreachable """\n
Undefined factory function Quadrature for name $name and the given arguments.
"""
end
Quadrature(name::QuadratureName,args...;kwargs...) = (name, args, kwargs)
"""
Quadrature(polytope::Polytope{D},degree) where D
"""
function Quadrature(p::Polytope,degree;T::Type{<:AbstractFloat}=Float64)
if is_n_cube(p)
quad = Quadrature(p,tensor_product,degree;T=T)
elseif is_simplex(p)
D = num_dims(p)
#if (D==2 && degree in keys(_strang_tri_k2n)) ||
# (D==3 && degree in keys(_strang_tet_k2n))
# For the moment strang only in 3d since
# there are some 2d strang quadratures that are not accurate
# as implemented here (to investigate why)
if (D==3 && degree in keys(_strang_tet_k2n))
quad = Quadrature(p,strang,degree;T=T)
else
quad = Quadrature(p,duffy,degree,T=T)
end
else
@notimplemented "Quadratures only implemented for n-cubes and simplices"
end
quad
end