-
Notifications
You must be signed in to change notification settings - Fork 2
/
composite_elements.jl
133 lines (126 loc) · 8.92 KB
/
composite_elements.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
"""
This cache allows to combine multiple elements over the same volume.
If surface caches are passed they are handled properly. This requred dispatching
is_facet_in_cache(facet::FacetIndex, geometry_cache, my_cache::MyCacheType)
"""
struct CompositeVolumetricElementCache{CacheTupleType <: Tuple} <: AbstractVolumetricElementCache
inner_caches::CacheTupleType
end
# Main entry point for bilinear operators
assemble_element!(Kₑ::AbstractMatrix, cell::CellCache, element_cache::CompositeVolumetricElementCache, time) = assemble_element!(Kₑ, cell, element_cache.inner_caches, time)
@unroll function assemble_element!(Kₑ::AbstractMatrix, cell::CellCache, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
@unroll for inner_cache ∈ inner_caches
assemble_element!(Kₑ, cell, inner_cache, time)
end
end
# Update element matrix in nonlinear operators
assemble_element!(Kₑ::AbstractMatrix, uₑ::AbstractVector, cell::CellCache, element_cache::CompositeVolumetricElementCache, time) = assemble_element!(Kₑ, uₑ, cell, element_cache.inner_caches, time)
@unroll function assemble_element!(Kₑ::AbstractMatrix, uₑ::AbstractVector, cell::CellCache, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
@unroll for inner_cache ∈ inner_caches
assemble_element!(Kₑ, uₑ, cell, inner_cache, time)
end
end
# Update element matrix and residual in nonlinear operators
assemble_element!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, element_cache::CompositeVolumetricElementCache, time) = assemble_element!(Kₑ, residualₑ, uₑ, cell, element_cache.inner_caches, time)
@unroll function assemble_element!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
@unroll for inner_cache ∈ inner_caches
assemble_element!(Kₑ, residualₑ, uₑ, cell, inner_cache, time)
end
end
# Update residual in nonlinear operators
assemble_element!(residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, element_cache::CompositeVolumetricElementCache, time) = assemble_element!(residualₑ, uₑ, cell, element_cache.inner_caches, time)
@unroll function assemble_element!(residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
@unroll for inner_cache ∈ inner_caches
assemble_element!(residualₑ, uₑ, cell, inner_cache, time)
end
end
# If we compose a face cache into an element cache, then we loop over the faces of the elements and try to assemble
function assemble_element!(Kₑ::AbstractMatrix, uₑ::AbstractVector, cell::CellCache, facet_cache::AbstractSurfaceElementCache, time)
for local_facet_index ∈ 1:nfacets(cell)
if is_facet_in_cache(FacetIndex(cellid(cell), local_facet_index), cell, facet_cache)
assemble_face!(Kₑ, uₑ, cell, local_facet_index, facet_cache, time)
end
end
end
function assemble_element!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, facet_cache::AbstractSurfaceElementCache, time)
for local_facet_index ∈ 1:nfacets(cell)
if is_facet_in_cache(FacetIndex(cellid(cell), local_facet_index), cell, facet_cache)
assemble_face!(Kₑ, residualₑ, uₑ, cell, local_facet_index, facet_cache, time)
end
end
end
function assemble_element!(residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, facet_cache::AbstractSurfaceElementCache, time)
for local_facet_index ∈ 1:nfacets(cell)
if is_facet_in_cache(FacetIndex(cellid(cell), local_facet_index), cell, facet_cache)
assemble_face!(residualₑ, uₑ, cell, local_facet_index, facet_cache, time)
end
end
end
"""
This cache allows to combine multiple elements over the same surface.
"""
struct CompositeSurfaceElementCache{CacheTupleType <: Tuple} <: AbstractSurfaceElementCache
inner_caches::CacheTupleType
end
# Main entry point for bilinear operators
assemble_face!(Kₑ::AbstractMatrix, cell::CellCache, local_facet_index::Int, surface_cache::CompositeSurfaceElementCache, time) = assemble_face!(Kₑ, cell, surface_cache.inner_caches, local_facet_index, time)
@unroll function assemble_face!(Kₑ::AbstractMatrix, cell::CellCache, local_facet_index::Int, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
@unroll for inner_cache ∈ inner_caches
assemble_face!(Kₑ, cell, local_facet_index, inner_cache, time)
end
end
# Update element matrix in nonlinear operators
assemble_face!(Kₑ::AbstractMatrix, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, surface_cache::CompositeSurfaceElementCache, time) = assemble_face!(Kₑ, uₑ, cell, local_facet_index, surface_cache.inner_caches, time)
@unroll function assemble_face!(Kₑ::AbstractMatrix, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
@unroll for inner_cache ∈ inner_caches
assemble_face!(Kₑ, uₑ, cell, local_facet_index, inner_cache, time)
end
end
# Update element matrix and residual in nonlinear operators
assemble_face!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, surface_cache::CompositeSurfaceElementCache, time) = assemble_face!(Kₑ, residualₑ, uₑ, cell, local_facet_index, surface_cache.inner_caches, time)
@unroll function assemble_face!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
@unroll for inner_cache ∈ inner_caches
assemble_face!(Kₑ, residualₑ, uₑ, cell, local_facet_index, inner_cache, time)
end
end
# Update residual in nonlinear operators
assemble_face!(residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, surface_cache::CompositeSurfaceElementCache, time) = assemble_face!(residualₑ, uₑ, cell, local_facet_index, surface_cache.inner_caches, time)
@unroll function assemble_face!(residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
@unroll for inner_cache ∈ inner_caches
assemble_face!(residualₑ, uₑ, cell, local_facet_index, inner_cache, time)
end
end
"""
This cache allows to combine multiple elements over the same interface.
"""
struct CompositeInterfaceElementCache{CacheTupleType <: Tuple} <: AbstractInterfaceElementCache
inner_caches::CacheTupleType
end
# Main entry point for bilinear operators
assemble_interface!(Kₑ::AbstractMatrix, interface, interface_cache::CompositeInterfaceElementCache, time) = assemble_interface!(Kₑ, interface, interface_cache.inner_caches, time)
@unroll function assemble_interface!(Kₑ::AbstractMatrix, interface, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
@unroll for inner_cache ∈ inner_caches
assemble_interface!(Kₑ, interface, inner_cache, time)
end
end
# Update element matrix in nonlinear operators
assemble_interface!(Kₑ::AbstractMatrix, uₑ::AbstractVector, interface, interface_cache::CompositeInterfaceElementCache, time) = assemble_interface!(Kₑ, uₑ, interface, interface_cache.inner_caches, time)
@unroll function assemble_interface!(Kₑ::AbstractMatrix, uₑ::AbstractVector, interface, inner_caches::CacheTupleType, local_facet_index::Int, time) where CacheTupleType <: Tuple
@unroll for inner_cache ∈ inner_caches
assemble_interface!(Kₑ, uₑ, interface, inner_cache, local_facet_index, time)
end
end
# Update element matrix and residual in nonlinear operators
assemble_interface!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, interface, interface_cache::CompositeInterfaceElementCache, time) = assemble_interface!(Kₑ, residualₑ, uₑ, interface, interface_cache.inner_caches, time)
@unroll function assemble_interface!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, interface, inner_caches::CacheTupleType, local_facet_index::Int, time) where CacheTupleType <: Tuple
@unroll for inner_cache ∈ inner_caches
assemble_interface!(Kₑ, residualₑ, uₑ, interface, inner_cache, local_facet_index, time)
end
end
# Update residual in nonlinear operators
assemble_interface!(residualₑ::AbstractVector, uₑ::AbstractVector, interface, interface_cache::CompositeInterfaceElementCache, time) = assemble_interface!(Kₑ, interface, interface_cache.inner_caches, time)
@unroll function assemble_interface!(residualₑ::AbstractVector, uₑ::AbstractVector, interface, inner_caches::CacheTupleType, local_facet_index::Int, time) where CacheTupleType <: Tuple
@unroll for inner_cache ∈ inner_caches
assemble_interface!(residualₑ, uₑ, interface, inner_cache, local_facet_index, time)
end
end