Skip to content

Commit 240e61c

Browse files
authored
Merge pull request #184 from Cthonios/more-testing-before-v0.9
some more testing.
2 parents edd6b95 + 3f5333e commit 240e61c

File tree

10 files changed

+140
-79
lines changed

10 files changed

+140
-79
lines changed

ext/FiniteElementContainersAdaptExt.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,23 @@ function Adapt.adapt_structure(to, bk::FiniteElementContainers.BCBookKeeping{V})
6060
end
6161

6262
function Adapt.adapt_structure(to, bc::FiniteElementContainers.DirichletBCContainer)
63-
bk = adapt(to, bc.bookkeeping)
63+
dofs = adapt(to, bc.dofs)
64+
nodes = adapt(to, bc.nodes)
6465
vals = adapt(to, bc.vals)
6566
vals_dot = adapt(to, bc.vals_dot)
6667
vals_dot_dot = adapt(to, bc.vals_dot_dot)
67-
return FiniteElementContainers.DirichletBCContainer(bk, vals, vals_dot, vals_dot_dot)
68+
return FiniteElementContainers.DirichletBCContainer(dofs, nodes, vals, vals_dot, vals_dot_dot)
6869
end
6970

7071
function Adapt.adapt_structure(to, bc::FiniteElementContainers.NeumannBCContainer)
71-
bk = adapt(to, bc.bookkeeping)
7272
el_conns = adapt(to, bc.element_conns)
73+
elements = adapt(to, bc.elements)
74+
side_nodes = adapt(to, bc.side_nodes)
75+
sides = adapt(to, bc.sides)
7376
surf_conns = adapt(to, bc.surface_conns)
7477
ref_fe = adapt(to, bc.ref_fe)
7578
vals = adapt(to, bc.vals)
76-
return FiniteElementContainers.NeumannBCContainer(bk, el_conns, surf_conns, ref_fe, vals)
79+
return FiniteElementContainers.NeumannBCContainer(el_conns, elements, side_nodes, sides, surf_conns, ref_fe, vals)
7780
end
7881

7982
# DofManagers

src/Parameters.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ function create_parameters(
196196
return Parameters(mesh, assembler, physics, props, ics, dirichlet_bcs, neumann_bcs, times)
197197
end
198198

199+
function initialize!(p::Parameters)
200+
update_ic_values!(p.ics, p.ic_funcs, p.h1_coords)
201+
update_field_ics!(p.h1_field, p.ics)
202+
return nothing
203+
end
204+
199205
"""
200206
$(TYPEDSIGNATURES)
201207
This method is used to update the stored bc values.

src/assemblers/NeumannBC.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function _assemble_block_vector_neumann_bc!(
3939
for e in axes(conns, 2)
4040
x_el = _element_level_fields(X, ref_fe, conns, e)
4141
R_el = _element_scratch_vector(surface_element(ref_fe.element), U)
42-
side = bc.bookkeeping.sides[e]
42+
side = bc.sides[e]
4343
for q in 1:num_quadrature_points(surface_element(ref_fe.element))
4444
interps = MappedSurfaceInterpolants(ref_fe, x_el, q, side)
4545
Nvec = interps.N_reduced
@@ -54,7 +54,7 @@ function _assemble_block_vector_neumann_bc!(
5454
R_el = R_el + JxW * Nvec * f_val
5555
end
5656
block_id = 1 # doesn't matter for this method
57-
el_id = bc.bookkeeping.elements[e]
57+
el_id = bc.elements[e]
5858
@views _assemble_element!(field, R_el, bc.surface_conns[:, e], el_id, block_id)
5959
end
6060
end
@@ -83,7 +83,7 @@ KA.@kernel function _assemble_block_vector_neumann_bc_kernel!(
8383

8484
x_el = _element_level_fields(X, ref_fe, conns, E)
8585
R_el = _element_scratch_vector(surface_element(ref_fe.element), U)
86-
side = bc.bookkeeping.sides[E]
86+
side = bc.sides[E]
8787

8888
for q in 1:num_quadrature_points(surface_element(ref_fe.element))
8989
interps = MappedSurfaceInterpolants(ref_fe, x_el, q, side)

src/assemblers/SparseMatrixAssembler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function update_dofs!(assembler::SparseMatrixAssembler, dirichlet_bcs)
228228
use_condensed = _is_condensed(assembler.dof)
229229

230230
if length(dirichlet_bcs) > 0
231-
dirichlet_dofs = mapreduce(x -> x.bookkeeping.dofs, vcat, dirichlet_bcs)
231+
dirichlet_dofs = mapreduce(x -> x.dofs, vcat, dirichlet_bcs)
232232
dirichlet_dofs = unique(sort(dirichlet_dofs))
233233
else
234234
dirichlet_dofs = Vector{Int}(undef, 0)

src/bcs/BoundaryConditions.jl

Lines changed: 78 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ function _unique_sort_perm(array::AbstractArray{T, 1}) where T <: Number
2828
return [id_map[x] for x in sorted_unique]
2929
end
3030

31+
const SetName = Union{Nothing, Symbol}
32+
3133
"""
3234
$(TYPEDEF)
3335
$(TYPEDSIGNATURES)
@@ -55,36 +57,81 @@ end
5557
$(TYPEDSIGNATURES)
5658
"""
5759
function BCBookKeeping(
58-
mesh, dof::DofManager, var_name::Symbol, sset_name::Symbol
60+
mesh, dof::DofManager, var_name::Symbol; #sset_name::Symbol
61+
block_name::SetName = nothing,
62+
nset_name::SetName = nothing,
63+
sset_name::SetName = nothing
5964
)
65+
# check to ensure at least one name is supplied
66+
if block_name === nothing &&
67+
nset_name === nothing &&
68+
sset_name === nothing
69+
@assert false "Need to specify either a block, nodeset or sideset."
70+
end
71+
72+
# now check to make sure only one name is not nothing
73+
if block_name !== nothing
74+
@assert nset_name === nothing && sset_name === nothing
75+
elseif nset_name !== nothing
76+
@assert block_name === nothing && sset_name === nothing
77+
elseif sset_name !== nothing
78+
@assert block_name === nothing && nset_name === nothing
79+
end
80+
6081
# get dof index associated with this var
6182
dof_index = _dof_index_from_var_name(dof, var_name)
62-
6383
fspace = function_space(dof)
6484

6585
# get sset specific fields
66-
elements = getproperty(mesh.sideset_elems, sset_name)
67-
nodes = getproperty(mesh.sideset_nodes, sset_name)
68-
sides = getproperty(mesh.sideset_sides, sset_name)
69-
side_nodes = getproperty(mesh.sideset_side_nodes, sset_name)
70-
71-
blocks = Vector{Int64}(undef, 0)
72-
73-
# gather the blocks that are present in this sideset
74-
# TODO this isn't quite right
75-
for (n, val) in enumerate(values(mesh.element_id_maps))
76-
# note these are the local elem id to the block, e.g. starting from 1.
77-
indices_in_sset = indexin(val, elements)
78-
filter!(x -> x !== nothing, indices_in_sset)
79-
80-
if length(indices_in_sset) > 0
81-
append!(blocks, repeat([n], length(indices_in_sset)))
86+
all_dofs = reshape(1:length(dof), size(dof))
87+
88+
if block_name !== nothing
89+
# for this case it is likely a DirichletBC or InitialCondition
90+
# so we really only need the nodes/dofs although this might
91+
# not be the case for say Hdiv or Hcurl fields...
92+
# TODO eventually set the blocks, could be useful maybe?
93+
blocks = Vector{Int64}(undef, 0)
94+
conns = getproperty(mesh.element_conns, block_name)
95+
nodes = sort(unique(conns.data))
96+
dofs = all_dofs[dof_index, nodes]
97+
elements = getproperty(mesh.element_id_maps, block_name)
98+
# below 2 don't make sense for other mesh entity types
99+
sides = Vector{Int64}(undef, 0)
100+
side_nodes = Matrix{Int64}(undef, 0, 0)
101+
elseif nset_name !== nothing
102+
# for this case we only setup the "nodes" and "dofs"
103+
blocks = Vector{Int64}(undef, 0) # TODO we could eventually put the blocks present here
104+
nodes = getproperty(mesh.nodeset_nodes, nset_name)
105+
dofs = all_dofs[dof_index, nodes]
106+
elements = Vector{Int64}(undef, 0) # TODO we could eventually put the elements present here
107+
# below 2 don't make sense for other mesh entity types
108+
sides = Vector{Int64}(undef, 0)
109+
side_nodes = Matrix{Int64}(undef, 0, 0)
110+
elseif sset_name !== nothing
111+
112+
elements = getproperty(mesh.sideset_elems, sset_name)
113+
nodes = getproperty(mesh.sideset_nodes, sset_name)
114+
sides = getproperty(mesh.sideset_sides, sset_name)
115+
side_nodes = getproperty(mesh.sideset_side_nodes, sset_name)
116+
117+
blocks = Vector{Int64}(undef, 0)
118+
119+
# gather the blocks that are present in this sideset
120+
# TODO this isn't quite right
121+
for (n, val) in enumerate(values(mesh.element_id_maps))
122+
# note these are the local elem id to the block, e.g. starting from 1.
123+
indices_in_sset = indexin(val, elements)
124+
filter!(x -> x !== nothing, indices_in_sset)
125+
126+
if length(indices_in_sset) > 0
127+
append!(blocks, repeat([n], length(indices_in_sset)))
128+
end
82129
end
83-
end
84130

85-
# setup dofs local to this BC
86-
all_dofs = reshape(1:length(dof), size(dof))
87-
dofs = all_dofs[dof_index, nodes]
131+
# setup dofs local to this BC
132+
# all_dofs = reshape(1:length(dof), size(dof))
133+
dofs = all_dofs[dof_index, nodes]
134+
end
88135

89136
return BCBookKeeping(
90137
blocks, dofs, elements, nodes, sides, side_nodes
@@ -143,14 +190,15 @@ $(TYPEDEF)
143190
$(TYPEDSIGNATURES)
144191
$(TYPEDFIELDS)
145192
"""
146-
abstract type AbstractBCContainer{
147-
IT <: Integer,
148-
VT <: Union{<:Number, <:SVector},
149-
N,
150-
IV <: AbstractArray{IT, 1},
151-
IM <: AbstractArray{IT, 2},
152-
VV <: AbstractArray{VT, N}
153-
} end
193+
# abstract type AbstractBCContainer{
194+
# IT <: Integer,
195+
# VT <: Union{<:Number, <:SVector},
196+
# N,
197+
# IV <: AbstractArray{IT, 1},
198+
# IM <: AbstractArray{IT, 2},
199+
# VV <: AbstractArray{VT, N}
200+
# } end
201+
abstract type AbstractBCContainer end
154202

155203
KA.get_backend(x::AbstractBCContainer) = KA.get_backend(x.vals)
156204

src/bcs/DirichletBCs.jl

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
abstract type AbstractDirichletBC{F} <: AbstractBC{F} end
2-
abstract type AbstractDirichletBCContainer{
3-
IT, VT, IV, IM, VV
4-
} <: AbstractBCContainer{IT, VT, 1, IV, IM, VV} end
2+
# abstract type AbstractDirichletBCContainer{
3+
# IT, VT, IV, IM, VV
4+
# } <: AbstractBCContainer{IT, VT, 1, IV, IM, VV} end
55

66
"""
77
$(TYPEDEF)
@@ -43,10 +43,10 @@ struct DirichletBCContainer{
4343
IT <: Integer,
4444
VT <: Number,
4545
IV <: AbstractArray{IT, 1},
46-
IM <: AbstractArray{IT, 2},
4746
VV <: AbstractArray{VT, 1}
48-
} <: AbstractDirichletBCContainer{IT, VT, IV, IM, VV}
49-
bookkeeping::BCBookKeeping{IT, IV, IM}
47+
} <: AbstractBCContainer
48+
dofs::IV
49+
nodes::IV
5050
vals::VV
5151
vals_dot::VV
5252
vals_dot_dot::VV
@@ -58,7 +58,7 @@ $(TYPEDSIGNATURES)
5858
$(TYPEDFIELDS)
5959
"""
6060
function DirichletBCContainer(mesh, dof::DofManager, dbc::DirichletBC)
61-
bk = BCBookKeeping(mesh, dof, dbc.var_name, dbc.sset_name)
61+
bk = BCBookKeeping(mesh, dof, dbc.var_name, sset_name=dbc.sset_name)
6262

6363
# sort nodes and dofs for dirichlet bc
6464
dof_perm = _unique_sort_perm(bk.dofs)
@@ -72,11 +72,11 @@ function DirichletBCContainer(mesh, dof::DofManager, dbc::DirichletBC)
7272
vals = zeros(length(bk.nodes))
7373
vals_dot = zeros(length(bk.nodes))
7474
vals_dot_dot = zeros(length(bk.nodes))
75-
return DirichletBCContainer(bk, vals, vals_dot, vals_dot_dot)
75+
return DirichletBCContainer(bk.dofs, bk.nodes, vals, vals_dot, vals_dot_dot)
7676
end
7777

7878
function Base.length(bc::DirichletBCContainer)
79-
return length(bc.bookkeeping.dofs)
79+
return length(bc.dofs)
8080
end
8181

8282
# need checks on if field types are compatable
@@ -87,7 +87,7 @@ based on the stored function
8787
"""
8888
function _update_bc_values!(bc::DirichletBCContainer, func, X, t, ::KA.CPU)
8989
ND = num_fields(X)
90-
for (n, node) in enumerate(bc.bookkeeping.nodes)
90+
for (n, node) in enumerate(bc.nodes)
9191
X_temp = @views SVector{ND, eltype(X)}(X[:, node])
9292
bc.vals[n] = func.func(X_temp, t)
9393
bc.vals_dot[n] = func.func_dot(X_temp, t)
@@ -104,7 +104,7 @@ GPU kernel for updating stored bc values based on the stored function
104104
KA.@kernel function _update_bc_values_kernel!(bc::DirichletBCContainer, func, X, t)
105105
I = KA.@index(Global)
106106
ND = num_fields(X)
107-
node = bc.bookkeeping.nodes[I]
107+
node = bc.nodes[I]
108108

109109
# hacky for now, but it works
110110
# can't do X[:, node] on the GPU, this results in a dynamic
@@ -134,22 +134,22 @@ end
134134

135135
# TODO change below names to be more specific to dbcs
136136
function _update_field_dirichlet_bcs!(U, bc::DirichletBCContainer, ::KA.CPU)
137-
for (dof, val) in zip(bc.bookkeeping.dofs, bc.vals)
137+
for (dof, val) in zip(bc.dofs, bc.vals)
138138
U[dof] = val
139139
end
140140
return nothing
141141
end
142142

143143
function _update_field_dirichlet_bcs!(U, V, bc::DirichletBCContainer, ::KA.CPU)
144-
for (dof, val, val_dot) in zip(bc.bookkeeping.dofs, bc.vals, bc.vals_dot)
144+
for (dof, val, val_dot) in zip(bc.dofs, bc.vals, bc.vals_dot)
145145
U[dof] = val
146146
V[dof] = val_dot
147147
end
148148
return nothing
149149
end
150150

151151
function _update_field_dirichlet_bcs!(U, V, A, bc::DirichletBCContainer, ::KA.CPU)
152-
for (dof, val, val_dot, val_dot_dot) in zip(bc.bookkeeping.dofs, bc.vals, bc.vals_dot, bc.vals_dot_dot)
152+
for (dof, val, val_dot, val_dot_dot) in zip(bc.dofs, bc.vals, bc.vals_dot, bc.vals_dot_dot)
153153
U[dof] = val
154154
V[dof] = val_dot
155155
A[dof] = val_dot_dot
@@ -160,16 +160,15 @@ end
160160
# COV_EXCL_START
161161
KA.@kernel function _update_field_dirichlet_bcs_kernel!(U, bc::DirichletBCContainer)
162162
I = KA.@index(Global)
163-
dof = bc.bookkeeping.dofs[I]
164-
# val = bc.vals[I]
163+
dof = bc.dofs[I]
165164
U[dof] = bc.vals[I]
166165
end
167166
# COV_EXCL_STOP
168167

169168
# COV_EXCL_START
170169
KA.@kernel function _update_field_dirichlet_bcs_kernel!(U, V, A, bc::DirichletBCContainer)
171170
I = KA.@index(Global)
172-
dof = bc.bookkeeping.dofs[I]
171+
dof = bc.dofs[I]
173172
val = bc.vals[I]
174173
U[dof] = bc.vals[I]
175174
V[dof] = bc.vals_dot[I]
@@ -232,7 +231,7 @@ function create_dirichlet_bcs(mesh, dof::DofManager, dirichlet_bcs::Vector{<:Dir
232231
dirichlet_bcs = DirichletBCContainer.((mesh,), (dof,), dirichlet_bcs)
233232

234233
if length(dirichlet_bcs) > 0
235-
temp_dofs = mapreduce(x -> x.bookkeeping.dofs, vcat, dirichlet_bcs)
234+
temp_dofs = mapreduce(x -> x.dofs, vcat, dirichlet_bcs)
236235
temp_dofs = unique(sort(temp_dofs))
237236
update_dofs!(dof, temp_dofs)
238237
end

0 commit comments

Comments
 (0)