Skip to content

Commit 8e2f60a

Browse files
committed
moving properties down to block level.
1 parent 1098d1c commit 8e2f60a

File tree

12 files changed

+139
-108
lines changed

12 files changed

+139
-108
lines changed

ext/FiniteElementContainersAdaptExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function Adapt.adapt_structure(to, p::FiniteElementContainers.Parameters)
176176
adapt(to, p.properties),
177177
adapt(to, p.state_old),
178178
adapt(to, p.state_new),
179-
adapt(to, p.h1_dbcs),
179+
adapt(to, p.h1_coords),
180180
adapt(to, p.h1_field)
181181
)
182182
end

src/Parameters.jl

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
abstract type AbstractParameters end
22

33
# TODO need to break up bcs to different field types
4-
struct Parameters{D, N, T, Phys, Props, S, V, H1} <: AbstractParameters
4+
struct Parameters{
5+
D, N, T, Phys, Props, S,
6+
H1Coords, H1
7+
} <: AbstractParameters
58
# actual parameter fields
69
# TODO add boundary condition stuff and time stepping stuff
710
dirichlet_bcs::D
@@ -13,7 +16,7 @@ struct Parameters{D, N, T, Phys, Props, S, V, H1} <: AbstractParameters
1316
state_old::S
1417
state_new::S
1518
# scratch fields
16-
h1_dbcs::V # TODO remove this
19+
h1_coords::H1Coords
1720
h1_field::H1
1821
end
1922

@@ -30,7 +33,7 @@ function Parameters(
3033
neumann_bcs,
3134
times
3235
)
33-
h1_dbcs = create_bcs(assembler, H1Field)
36+
h1_coords = assembler.dof.H1_vars[1].fspace.coords
3437
h1_field = create_field(assembler, H1Field)
3538

3639
# TODO
@@ -47,8 +50,14 @@ function Parameters(
4750
end
4851

4952
# state_old = Array{Float64, 3}[]
53+
properties = []
5054
state_old = L2QuadratureField[]
5155
for (key, val) in pairs(physics)
56+
# create properties for this block physics
57+
# TODO specialize to allow for element level properties
58+
push!(properties, create_properties(val))
59+
60+
# create state variables for this block physics
5261
NS = num_states(val)
5362
NQ = ReferenceFiniteElements.num_quadrature_points(
5463
getfield(values(assembler.dof.H1_vars)[1].fspace.ref_fes, key)
@@ -57,10 +66,21 @@ function Parameters(
5766
getfield(values(assembler.dof.H1_vars)[1].fspace.elem_conns, key),
5867
2
5968
)
69+
6070
syms = tuple(map(x -> Symbol("state_variable_$x"), 1:NS)...)
61-
state_old_temp = L2QuadratureField(zeros(NS, NQ, NE), syms)
71+
state_old_temp = zeros(NS, NQ, NE)
72+
for e in 1:NE
73+
for q in 1:NQ
74+
state_old_temp[:, q, e] = create_initial_state(val)
75+
end
76+
end
77+
state_old_temp = L2QuadratureField(state_old_temp, syms)
78+
6279
push!(state_old, state_old_temp)
6380
end
81+
82+
properties = NamedTuple{keys(physics)}(tuple(properties...))
83+
6484
state_new = copy(state_old)
6585
state_old = NamedTuple{keys(physics)}(tuple(state_old...))
6686
state_new = NamedTuple{keys(physics)}(tuple(state_new...))
@@ -95,7 +115,7 @@ function Parameters(
95115
physics,
96116
properties,
97117
state_old, state_new,
98-
h1_dbcs, h1_field
118+
h1_coords, h1_field
99119
)
100120

101121
update_dofs!(assembler, p)
@@ -118,9 +138,7 @@ function create_parameters(
118138
end
119139

120140
function update_dofs!(asm::SparseMatrixAssembler, p::Parameters)
121-
# temp_dofs = mapreduce(x -> x.bookkeeping.dofs, vcat, values(p.dirichlet_bcs))
122141
update_dofs!(asm, p.dirichlet_bcs)
123-
Base.resize!(p.h1_dbcs, length(asm.dof.H1_bc_dofs))
124142
return nothing
125143
end
126144

src/assemblers/Assemblers.jl

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,60 +46,65 @@ function _check_backends(assembler, U, X, state_old, state_new, conns)
4646
@assert backend == KA.get_backend(conns)
4747
@assert backend == KA.get_backend(state_old)
4848
@assert backend == KA.get_backend(state_new)
49+
# props will be complicated...
50+
# TODO
4951
return backend
5052
end
5153

5254
function assemble!(assembler, ::Type{H1Field}, p, val_sym::Val{:mass})
53-
_zero_storage(assembler, val_sym)
5455
fspace = assembler.dof.H1_vars[1].fspace
55-
for (b, (conns, block_physics, state_old, state_new)) in enumerate(zip(
56+
_zero_storage(assembler, val_sym)
57+
for (b, (conns, block_physics, state_old, state_new, props)) in enumerate(zip(
5658
values(fspace.elem_conns),
5759
values(p.physics),
58-
values(p.state_old), values(p.state_new)
60+
values(p.state_old), values(p.state_new),
61+
values(p.properties)
5962
))
6063
ref_fe = values(fspace.ref_fes)[b]
61-
backend = _check_backends(assembler, p.h1_field, fspace.coords, state_old, state_new, conns)
64+
backend = _check_backends(assembler, p.h1_field, p.h1_coords, state_old, state_new, conns)
6265
_assemble_block_mass!(
6366
assembler, block_physics, ref_fe,
64-
p.h1_field, fspace.coords, state_old, state_new,
67+
p.h1_field, p.h1_coords, state_old, state_new, props,
6568
conns, b,
6669
backend
6770
)
6871
end
6972
end
7073

7174
function assemble!(assembler, ::Type{H1Field}, p, val_sym::Val{:residual})
72-
_zero_storage(assembler, val_sym)
7375
fspace = assembler.dof.H1_vars[1].fspace
74-
for (b, (conns, block_physics, state_old, state_new)) in enumerate(zip(
76+
_zero_storage(assembler, val_sym)
77+
for (b, (conns, block_physics, state_old, state_new, props)) in enumerate(zip(
7578
values(fspace.elem_conns),
7679
values(p.physics),
77-
values(p.state_old), values(p.state_new)
80+
values(p.state_old), values(p.state_new),
81+
values(p.properties)
7882
))
7983
ref_fe = values(fspace.ref_fes)[b]
80-
backend = _check_backends(assembler, p.h1_field, fspace.coords, state_old, state_new, conns)
84+
backend = _check_backends(assembler, p.h1_field, p.h1_coords, state_old, state_new, conns)
8185
_assemble_block_residual!(
8286
assembler, block_physics, ref_fe,
83-
p.h1_field, fspace.coords, state_old, state_new,
87+
p.h1_field, p.h1_coords, state_old, state_new, props,
8488
conns, b,
8589
backend
8690
)
8791
end
8892
end
8993

9094
function assemble!(assembler, ::Type{H1Field}, p, val_sym::Val{:residual_and_stiffness})
91-
_zero_storage(assembler, val_sym)
9295
fspace = assembler.dof.H1_vars[1].fspace
93-
for (b, (conns, block_physics, state_old, state_new)) in enumerate(zip(
96+
_zero_storage(assembler, val_sym)
97+
for (b, (conns, block_physics, state_old, state_new, props)) in enumerate(zip(
9498
values(fspace.elem_conns),
9599
values(p.physics),
96-
values(p.state_old), values(p.state_new)
100+
values(p.state_old), values(p.state_new),
101+
values(p.properties)
97102
))
98103
ref_fe = values(fspace.ref_fes)[b]
99-
backend = _check_backends(assembler, p.h1_field, fspace.coords, state_old, state_new, conns)
104+
backend = _check_backends(assembler, p.h1_field, p.h1_coords, state_old, state_new, conns)
100105
_assemble_block_residual_and_stiffness!(
101106
assembler, block_physics, ref_fe,
102-
p.h1_field, fspace.coords, state_old, state_new,
107+
p.h1_field, p.h1_coords, state_old, state_new, props,
103108
conns, b,
104109
backend
105110
)
@@ -109,16 +114,17 @@ end
109114
function assemble!(assembler, ::Type{H1Field}, p, val_sym::Val{:stiffness})
110115
_zero_storage(assembler, val_sym)
111116
fspace = assembler.dof.H1_vars[1].fspace
112-
for (b, (conns, block_physics, state_old, state_new)) in enumerate(zip(
117+
for (b, (conns, block_physics, state_old, state_new, props)) in enumerate(zip(
113118
values(fspace.elem_conns),
114119
values(p.physics),
115-
values(p.state_old), values(p.state_new)
120+
values(p.state_old), values(p.state_new),
121+
values(p.properties)
116122
))
117123
ref_fe = values(fspace.ref_fes)[b]
118-
backend = _check_backends(assembler, p.h1_field, fspace.coords, state_old, state_new, conns)
124+
backend = _check_backends(assembler, p.h1_field, p.h1_coords, state_old, state_new, conns)
119125
_assemble_block_stiffness!(
120126
assembler, block_physics, ref_fe,
121-
p.h1_field, fspace.coords, state_old, state_new,
127+
p.h1_field, p.h1_coords, state_old, state_new, props,
122128
conns, b,
123129
backend
124130
)

src/assemblers/CPUGeneral.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ TODO remove Float64 typing below for eventual unitful use
3535
"""
3636
function _assemble_block_residual!(
3737
assembler, physics, ref_fe,
38-
U, X, state_old, state_new,
38+
U, X, state_old, state_new, props,
3939
conns, block_id, ::KA.CPU
4040
)
4141
ND = size(U, 1)

src/assemblers/GPUGeneral.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Kernel for residual block assembly
66
"""
77
KA.@kernel function _assemble_block_residual_kernel!(
88
assembler, physics, ref_fe,
9-
U, X, state_old, state_new,
9+
U, X, state_old, state_new, props,
1010
conns, block_id
1111
)
1212
E = KA.@index(Global)
@@ -45,7 +45,7 @@ TODO add state variables and physics properties
4545
"""
4646
function _assemble_block_residual!(
4747
assembler, physics, ref_fe,
48-
U, X, state_old, state_new,
48+
U, X, state_old, state_new, props,
4949
conns, block_id, backend::KA.Backend
5050
)
5151
kernel! = _assemble_block_residual_kernel!(backend)
@@ -59,7 +59,7 @@ end
5959

6060
KA.@kernel function _assemble_block_stiffness_kernel!(
6161
assembler, physics, ref_fe,
62-
U, X, state_old, state_new,
62+
U, X, state_old, state_new, props,
6363
conns, block_id
6464
)
6565
E = KA.@index(Global)
@@ -98,7 +98,7 @@ TODO add state variables and physics properties
9898
"""
9999
function _assemble_block_stiffness!(
100100
assembler, physics, ref_fe,
101-
U, X, state_old, state_new,
101+
U, X, state_old, state_new, props,
102102
conns, block_id, backend::KA.Backend
103103
)
104104
kernel! = _assemble_block_stiffness_kernel!(backend)

src/assemblers/SparseMatrixAssembler.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ TODO add state variables and physics properties
100100
"""
101101
function _assemble_block_mass!(
102102
assembler, physics, ref_fe,
103-
U, X, state_old, state_new,
103+
U, X, state_old, state_new, props,
104104
conns, block_id, ::KA.CPU
105105
)
106106
ND = size(U, 1)
@@ -131,7 +131,7 @@ TODO add state variables and physics properties
131131
"""
132132
function _assemble_block_stiffness!(
133133
assembler, physics, ref_fe,
134-
U, X, state_old, state_new,
134+
U, X, state_old, state_new, props,
135135
conns, block_id, ::KA.CPU
136136
)
137137
ND = size(U, 1)
@@ -163,7 +163,7 @@ TODO remove Float64 typing below for eventual unitful use
163163
"""
164164
function _assemble_block_residual_and_stiffness!(
165165
assembler, physics, ref_fe,
166-
U, X, state_old, state_new,
166+
U, X, state_old, state_new, props,
167167
conns, block_id, ::KA.CPU
168168
)
169169
ND = size(U, 1)

src/integrators/Integrators.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,36 @@ abstract type AbstractIntegrator{
44
} end
55
# abstract type AbstractFirstOrderIntegrator <: AbstractIntegrator end
66
# abstract type AbstractSecondOrderIntegrator <: AbstractIntegrator end
7+
abstract type AbstractSecondOrderIntegrator{
8+
Solution,
9+
Solver
10+
} <: AbstractIntegrator{Solution, Solver} end
711
abstract type AbstractStaticIntegrator{
812
Solution,
913
Solver
1014
} <: AbstractIntegrator{Solution, Solver} end
1115

1216
function evolve! end
1317

18+
# TODO maybe move these methods below to BCs
19+
function _update_bcs!(bc, U, ::KA.CPU)
20+
for (dof, val) in zip(bc.bookkeeping.dofs, bc.vals)
21+
U[dof] = val
22+
end
23+
return nothing
24+
end
25+
26+
KA.@kernel function _update_bcs_kernel!(bc, U)
27+
I = KA.@index(Global)
28+
dof = bc.bookkeeping.dofs[I]
29+
val = bc.vals[I]
30+
U[dof] = val
31+
end
32+
33+
function _update_bcs!(bc, U, backend::KA.Backend)
34+
kernel! = _update_bcs_kernel!(backend)
35+
kernel!(bc, U, ndrange=length(bc.vals))
36+
return nothing
37+
end
38+
1439
include("QuasiStaticIntegrator.jl")

src/integrators/QuasiStaticIntegrator.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,20 @@ end
1414

1515
function evolve!(integrator::QuasiStaticIntegrator, p)
1616
update_time!(p)
17-
update_bcs!(H1Field, integrator.solver, integrator.solution, p)
17+
# update_bcs!(H1Field, integrator.solver, p)
18+
update_bcs!(integrator, p)
1819
solve!(integrator.solver, integrator.solution, p)
1920
return nothing
2021
end
22+
23+
function update_bcs!(::QuasiStaticIntegrator, p::Parameters)
24+
X = p.h1_coords # TODO won't work for mixed bcs
25+
t = current_time(p.times)
26+
27+
update_bc_values!(p.dirichlet_bcs, X, t)
28+
29+
for bc in values(p.dirichlet_bcs)
30+
_update_bcs!(bc, p.h1_field, KA.get_backend(bc))
31+
end
32+
return nothing
33+
end

src/physics/Physics.jl

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,34 @@ num_fields(::AbstractPhysics{NF, NP, NS}) where {NF, NP, NS} = NF
44
num_properties(::AbstractPhysics{NF, NP, NS}) where {NF, NP, NS} = NP
55
num_states(::AbstractPhysics{NF, NP, NS}) where {NF, NP, NS} = NS
66

7-
# this won't work
8-
# function create_physics(name, vars...)
9-
# # @show field_vars
10-
# # @show prop_vars
11-
# H1_vars = _filter_field_type(vars, H1Field)
12-
# # TODO setup Hdiv and Hcurl logic as well
13-
# L2_element_vars = _filter_field_type(vars, L2ElementField)
14-
# L2_quadrature_vars = _filter_field_type(vars, L2QuadratureField)
15-
16-
# H1_var_names = ()
17-
# for var in H1_vars
18-
# H1_var_names = (H1_var_names..., names(var)...)
19-
# end
20-
# H1_var_names = NamedTuple{H1_var_names}(1:length(H1_var_names))
7+
function create_properties(physics::AbstractPhysics{NF, NP, NS}) where {NF, NP, NS}
8+
@assert false "You need to implement the create_properties method for physics $(physics) or
9+
type $(typeof(physics))!"
10+
end
2111

22-
# L2_element_var_names = ()
23-
# for var in L2_element_vars
24-
# L2_element_var_names = (L2_element_var_names..., names(var)...)
25-
# end
26-
# L2_element_var_names = NamedTuple{L2_element_var_names}(1:length(L2_element_var_names))
12+
function create_properties(::AbstractPhysics{NF, 0, NS}) where {NF, NS}
13+
return SVector{0, Float64}()
14+
end
2715

28-
# L2_quadrature_var_names = ()
29-
# for var in L2_quadrature_vars
30-
# L2_quadrature_var_names = (L2_quadrature_var_names..., names(var)...)
31-
# end
32-
# L2_quadrature_var_names = NamedTuple{L2_quadrature_var_names}(1:length(L2_quadrature_var_names))
33-
34-
# end
16+
function create_initial_state(::AbstractPhysics{NF, NP, 0}) where {NF, NP}
17+
return SVector{0, Float64}()
18+
end
3519

36-
# function initialize_state(::AbstractPhysics{NF, NP, 0}) where {NF, NP}
37-
# return
38-
# end
20+
# Can we make something that makes interfacing with kernels easier?
21+
# How can we make something like this work nicely with AD?
22+
# struct PhysicsQuadratureState{T, ND, NN, NF, NP, NS, NDxNF, NNxND, NNxNNxND}
23+
# # u::SVector{NF, T}
24+
# # ∇u::SMatrix{NF, ND, T, NDxNF}
25+
# # props::SVector{NP, T}
26+
# # state_old::SVector{NS, T}
27+
# # interpolants and gauss weight at quadrature point
28+
# N::SVector{NN, T}
29+
# ∇N_ξ::SMatrix{NN, ND, T, NNxND}
30+
# ∇∇N_ξ::SArray{Tuple{NN, ND, ND}, T, 3, NNxNNxND}
31+
# JxW::T
32+
# # element level fields
33+
# u_el::SMatrix{}
34+
# end
3935

4036
# physics like methods
4137
function damping end

0 commit comments

Comments
 (0)