Skip to content

Commit 8505d76

Browse files
Fix composite element test
1 parent 909506a commit 8505d76

1 file changed

Lines changed: 51 additions & 38 deletions

File tree

src/modeling/core/composite_elements.jl

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@ struct CompositeVolumetricElementCache{CacheTupleType <: Tuple} <: AbstractVolum
77
inner_caches::CacheTupleType
88
end
99
# Main entry point for bilinear operators
10-
assemble_element!(Kₑ::AbstractMatrix, cell::CellCache, element_cache::CompositeVolumetricElementCache, time) = assemble_element!(Kₑ, cell, element_cache.inner_caches, time)
11-
@unroll function assemble_element!(Kₑ::AbstractMatrix, cell::CellCache, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
10+
assemble_element!(Kₑ::AbstractMatrix, cell::CellCache, element_cache::CompositeVolumetricElementCache, time) = assemble_composite_element!(Kₑ, cell, element_cache.inner_caches, time)
11+
@unroll function assemble_composite_element!(Kₑ::AbstractMatrix, cell::CellCache, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
1212
@unroll for inner_cache inner_caches
1313
assemble_element!(Kₑ, cell, inner_cache, time)
1414
end
1515
end
1616
# Update element matrix in nonlinear operators
17-
assemble_element!(Kₑ::AbstractMatrix, uₑ::AbstractVector, cell::CellCache, element_cache::CompositeVolumetricElementCache, time) = assemble_element!(Kₑ, uₑ, cell, element_cache.inner_caches, time)
18-
@unroll function assemble_element!(Kₑ::AbstractMatrix, uₑ::AbstractVector, cell::CellCache, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
17+
assemble_element!(Kₑ::AbstractMatrix, uₑ::AbstractVector, cell::CellCache, element_cache::CompositeVolumetricElementCache, time) = assemble_composite_element!(Kₑ, uₑ, cell, element_cache.inner_caches, time)
18+
@unroll function assemble_composite_element!(Kₑ::AbstractMatrix, uₑ::AbstractVector, cell::CellCache, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
1919
@unroll for inner_cache inner_caches
2020
assemble_element!(Kₑ, uₑ, cell, inner_cache, time)
2121
end
2222
end
2323
# Update element matrix and residual in nonlinear operators
24-
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)
25-
@unroll function assemble_element!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
24+
assemble_element!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, element_cache::CompositeVolumetricElementCache, time) = assemble_composite_element!(Kₑ, residualₑ, uₑ, cell, element_cache.inner_caches, time)
25+
@unroll function assemble_composite_element!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
2626
@unroll for inner_cache inner_caches
2727
assemble_element!(Kₑ, residualₑ, uₑ, cell, inner_cache, time)
2828
end
2929
end
3030
# Update residual in nonlinear operators
31-
assemble_element!(residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, element_cache::CompositeVolumetricElementCache, time) = assemble_element!(residualₑ, uₑ, cell, element_cache.inner_caches, time)
32-
@unroll function assemble_element!(residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
31+
assemble_element!(residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, element_cache::CompositeVolumetricElementCache, time) = assemble_composite_element!(residualₑ, uₑ, cell, element_cache.inner_caches, time)
32+
@unroll function assemble_composite_element!(residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
3333
@unroll for inner_cache inner_caches
3434
assemble_element!(residualₑ, uₑ, cell, inner_cache, time)
3535
end
@@ -67,44 +67,57 @@ struct CompositeSurfaceElementCache{CacheTupleType <: Tuple} <: AbstractSurfaceE
6767
inner_caches::CacheTupleType
6868
end
6969
# Main entry point for bilinear operators
70-
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)
71-
@unroll function assemble_face!(Kₑ::AbstractMatrix, cell::CellCache, local_facet_index::Int, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
70+
assemble_face!(Kₑ::AbstractMatrix, cell::CellCache, local_facet_index::Int, surface_cache::CompositeSurfaceElementCache, time) = assemble_composite_face!(Kₑ, cell, surface_cache.inner_caches, local_facet_index, time)
71+
@unroll function assemble_composite_face!(Kₑ::AbstractMatrix, cell::CellCache, local_facet_index::Int, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
7272
@unroll for inner_cache inner_caches
73-
if is_facet_in_cache(FacetIndex(cellid(cell), local_facet_index), cell, inner_cache)
74-
assemble_face!(Kₑ, cell, local_facet_index, inner_cache, time)
75-
end
73+
assemble_face!(Kₑ, cell, local_facet_index, inner_cache, time)
7674
end
7775
end
7876
# Update element matrix in nonlinear operators
79-
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)
80-
@unroll function assemble_face!(Kₑ::AbstractMatrix, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
77+
assemble_face!(Kₑ::AbstractMatrix, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, surface_cache::CompositeSurfaceElementCache, time) = assemble_composite_face!(Kₑ, uₑ, cell, local_facet_index, surface_cache.inner_caches, time)
78+
@unroll function assemble_composite_face!(Kₑ::AbstractMatrix, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
8179
@unroll for inner_cache inner_caches
82-
if is_facet_in_cache(FacetIndex(cellid(cell), local_facet_index), cell, inner_cache)
83-
assemble_face!(Kₑ, uₑ, cell, local_facet_index, inner_cache, time)
84-
end
80+
assemble_face!(Kₑ, uₑ, cell, local_facet_index, inner_cache, time)
8581
end
8682
end
8783
# Update element matrix and residual in nonlinear operators
88-
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)
89-
@unroll function assemble_face!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
84+
assemble_face!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, surface_cache::CompositeSurfaceElementCache, time) = assemble_composite_face!(Kₑ, residualₑ, uₑ, cell, local_facet_index, surface_cache.inner_caches, time)
85+
@unroll function assemble_composite_face!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
9086
@unroll for inner_cache inner_caches
91-
if is_facet_in_cache(FacetIndex(cellid(cell), local_facet_index), cell, inner_cache)
92-
assemble_face!(Kₑ, residualₑ, uₑ, cell, local_facet_index, inner_cache, time)
93-
end
87+
assemble_face!(Kₑ, residualₑ, uₑ, cell, local_facet_index, inner_cache, time)
9488
end
9589
end
9690
# Update residual in nonlinear operators
97-
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)
98-
@unroll function assemble_face!(residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
91+
assemble_face!(residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, surface_cache::CompositeSurfaceElementCache, time) = assemble_composite_face!(residualₑ, uₑ, cell, local_facet_index, surface_cache.inner_caches, time)
92+
@unroll function assemble_composite_face!(residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
9993
@unroll for inner_cache inner_caches
100-
if is_facet_in_cache(FacetIndex(cellid(cell), local_facet_index), cell, inner_cache)
101-
assemble_face!(residualₑ, uₑ, cell, local_facet_index, inner_cache, time)
102-
end
94+
assemble_face!(residualₑ, uₑ, cell, local_facet_index, inner_cache, time)
10395
end
10496
end
105-
#
106-
is_facet_in_cache(fi::FacetIndex, cell, cache::CompositeSurfaceElementCache) = true # We check again for the inner caches
10797

98+
# If we compose a face cache into an element cache, then we loop over the faces of the elements and try to assemble
99+
# Standard element assembly wrapper
100+
# Update element matrix in nonlinear operators
101+
assemble_element!(Kₑ::AbstractMatrix, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, surface_cache::CompositeSurfaceElementCache, time) = assemble_composite_element!(Kₑ, uₑ, cell, local_facet_index, surface_cache.inner_caches, time)
102+
@unroll function assemble_composite_element!(Kₑ::AbstractMatrix, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
103+
@unroll for inner_cache inner_caches
104+
assemble_element!(Kₑ, uₑ, cell, local_facet_index, inner_cache, time)
105+
end
106+
end
107+
# Update element matrix and residual in nonlinear operators
108+
assemble_element!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, surface_cache::CompositeSurfaceElementCache, time) = assemble_composite_element!(Kₑ, residualₑ, uₑ, cell, local_facet_index, surface_cache.inner_caches, time)
109+
@unroll function assemble_composite_element!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
110+
@unroll for inner_cache inner_caches
111+
assemble_element!(Kₑ, residualₑ, uₑ, cell, local_facet_index, inner_cache, time)
112+
end
113+
end
114+
# Update residual in nonlinear operators
115+
assemble_element!(residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, surface_cache::CompositeSurfaceElementCache, time) = assemble_composite_element!(residualₑ, uₑ, cell, local_facet_index, surface_cache.inner_caches, time)
116+
@unroll function assemble_composite_element!(residualₑ::AbstractVector, uₑ::AbstractVector, cell::CellCache, local_facet_index::Int, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
117+
@unroll for inner_cache inner_caches
118+
assemble_element!(Kₑ, cell, local_facet_index, inner_cache, time)
119+
end
120+
end
108121

109122

110123
"""
@@ -114,29 +127,29 @@ struct CompositeInterfaceElementCache{CacheTupleType <: Tuple} <: AbstractInterf
114127
inner_caches::CacheTupleType
115128
end
116129
# Main entry point for bilinear operators
117-
assemble_interface!(Kₑ::AbstractMatrix, interface, interface_cache::CompositeInterfaceElementCache, time) = assemble_interface!(Kₑ, interface, interface_cache.inner_caches, time)
118-
@unroll function assemble_interface!(Kₑ::AbstractMatrix, interface, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
130+
assemble_interface!(Kₑ::AbstractMatrix, interface, interface_cache::CompositeInterfaceElementCache, time) = assemble_composite_interface!(Kₑ, interface, interface_cache.inner_caches, time)
131+
@unroll function assemble_composite_interface!(Kₑ::AbstractMatrix, interface, inner_caches::CacheTupleType, time) where CacheTupleType <: Tuple
119132
@unroll for inner_cache inner_caches
120133
assemble_interface!(Kₑ, interface, inner_cache, time)
121134
end
122135
end
123136
# Update element matrix in nonlinear operators
124-
assemble_interface!(Kₑ::AbstractMatrix, uₑ::AbstractVector, interface, interface_cache::CompositeInterfaceElementCache, time) = assemble_interface!(Kₑ, uₑ, interface, interface_cache.inner_caches, time)
125-
@unroll function assemble_interface!(Kₑ::AbstractMatrix, uₑ::AbstractVector, interface, inner_caches::CacheTupleType, local_facet_index::Int, time) where CacheTupleType <: Tuple
137+
assemble_interface!(Kₑ::AbstractMatrix, uₑ::AbstractVector, interface, interface_cache::CompositeInterfaceElementCache, time) = assemble_composite_interface!(Kₑ, uₑ, interface, interface_cache.inner_caches, time)
138+
@unroll function assemble_composite_interface!(Kₑ::AbstractMatrix, uₑ::AbstractVector, interface, inner_caches::CacheTupleType, local_facet_index::Int, time) where CacheTupleType <: Tuple
126139
@unroll for inner_cache inner_caches
127140
assemble_interface!(Kₑ, uₑ, interface, inner_cache, local_facet_index, time)
128141
end
129142
end
130143
# Update element matrix and residual in nonlinear operators
131-
assemble_interface!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, interface, interface_cache::CompositeInterfaceElementCache, time) = assemble_interface!(Kₑ, residualₑ, uₑ, interface, interface_cache.inner_caches, time)
132-
@unroll function assemble_interface!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, interface, inner_caches::CacheTupleType, local_facet_index::Int, time) where CacheTupleType <: Tuple
144+
assemble_interface!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, interface, interface_cache::CompositeInterfaceElementCache, time) = assemble_composite_interface!(Kₑ, residualₑ, uₑ, interface, interface_cache.inner_caches, time)
145+
@unroll function assemble_composite_interface!(Kₑ::AbstractMatrix, residualₑ::AbstractVector, uₑ::AbstractVector, interface, inner_caches::CacheTupleType, local_facet_index::Int, time) where CacheTupleType <: Tuple
133146
@unroll for inner_cache inner_caches
134147
assemble_interface!(Kₑ, residualₑ, uₑ, interface, inner_cache, local_facet_index, time)
135148
end
136149
end
137150
# Update residual in nonlinear operators
138-
assemble_interface!(residualₑ::AbstractVector, uₑ::AbstractVector, interface, interface_cache::CompositeInterfaceElementCache, time) = assemble_interface!(Kₑ, interface, interface_cache.inner_caches, time)
139-
@unroll function assemble_interface!(residualₑ::AbstractVector, uₑ::AbstractVector, interface, inner_caches::CacheTupleType, local_facet_index::Int, time) where CacheTupleType <: Tuple
151+
assemble_interface!(residualₑ::AbstractVector, uₑ::AbstractVector, interface, interface_cache::CompositeInterfaceElementCache, time) = assemble_composite_interface!(Kₑ, interface, interface_cache.inner_caches, time)
152+
@unroll function assemble_composite_interface!(residualₑ::AbstractVector, uₑ::AbstractVector, interface, inner_caches::CacheTupleType, local_facet_index::Int, time) where CacheTupleType <: Tuple
140153
@unroll for inner_cache inner_caches
141154
assemble_interface!(residualₑ, uₑ, interface, inner_cache, local_facet_index, time)
142155
end

0 commit comments

Comments
 (0)