Skip to content

Commit ab85690

Browse files
authored
Merge pull request #84 from Cthonios/physics-tweak
adding num props and num states to abstract physics type. Also fixed …
2 parents a3e3df3 + 74979a8 commit ab85690

File tree

7 files changed

+32
-14
lines changed

7 files changed

+32
-14
lines changed

src/FiniteElementContainers.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ export SymmetricTensorFunction
7979
export TensorFunction
8080
export VectorFunction
8181

82+
# Physics
83+
export AbstractPhysics
84+
export num_properties
85+
export num_states
86+
8287
# dependencies
8388
import AcceleratedKernels as AK
8489
import KernelAbstractions as KA

src/assemblers/Assemblers.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,11 @@ KA.@kernel function _assemble_block_stiffness_kernel!(assembler, physics, ref_fe
136136
K_el = K_el + K_q
137137
end
138138

139-
# start_id = (block_id - 1) * assembler.pattern.block_sizes[block_id] +
140-
# (el_id - 1) * assembler.pattern.block_offsets[block_id] + 1
141-
# end_id = start_id + assembler.pattern.block_offsets[block_id] - 1
142-
# TODO patch this up for multi-block later
143-
# hardcoded for single block quad4
144-
start_id = (E - 1) * 16 + 1
145-
end_id = start_id + 16 - 1
139+
block_size = values(assembler.pattern.block_sizes)[block_id]
140+
block_offset = values(assembler.pattern.block_offsets)[block_id]
141+
start_id = (block_id - 1) * block_size +
142+
(E - 1) * block_offset + 1
143+
end_id = start_id + block_offset - 1
146144
ids = start_id:end_id
147145
for (i, id) in enumerate(ids)
148146
Atomix.@atomic assembler.stiffness_storage[id] += K_el.data[i]
@@ -174,9 +172,10 @@ function assemble!(assembler, physics, U::H1Field, sym::Symbol)
174172
# fill!(assembler.residual_storage, zero(eltype(assembler.residual_storage)))
175173
_zero_storage(assembler, Val{sym}())
176174
fspace = assembler.dof.H1_vars[1].fspace
175+
X = fspace.coords
177176
for (b, conns) in enumerate(values(fspace.elem_conns))
178177
ref_fe = values(fspace.ref_fes)[b]
179-
_assemble_block!(assembler, physics, sym, ref_fe, U, fspace.coords, conns, b)
178+
_assemble_block!(assembler, physics, sym, ref_fe, U, X, conns, b)
180179
end
181180
return nothing
182181
end

src/physics/Physics.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
abstract type AbstractPhysics end
1+
abstract type AbstractPhysics{NP, NS} end
2+
num_properties(::AbstractPhysics{NP, NS}) where {NP, NS} = NP
3+
num_states(::AbstractPhysics{NP, NS}) where {NP, NS} = NS
24

35
# better define this interface
6+
# function damping end
7+
function damping end
48
function energy end
9+
function mass end
510
function residual end
611
function stiffness end

test/TestPhysics.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@testset ExtendedTestSet "Physics" begin
2+
struct MyPhysics <: AbstractPhysics{2, 3}
3+
end
4+
5+
physics = MyPhysics()
6+
@test num_properties(physics) == 2
7+
@test num_states(physics) == 3
8+
end

test/poisson/TestPoisson2.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ output_file = "./poisson/poisson.e"
1313
f(X, _) = 2. * π^2 * sin* X[1]) * sin* X[2])
1414
bc_func(_, _) = 0.
1515

16-
struct Poisson <: FiniteElementContainers.AbstractPhysics
16+
struct Poisson <: AbstractPhysics{0, 0}
1717
end
1818

1919
function FiniteElementContainers.residual(::Poisson, cell, u_el, args...)

test/poisson/TestPoissonCUDA.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using SparseArrays
1414
f(X, _) = 2. * π^2 * sin(2π * X[1]) * sin(2π * X[2])
1515
bc_func(_, _) = 0.
1616

17-
struct Poisson <: FiniteElementContainers.AbstractPhysics
17+
struct Poisson <: AbstractPhysics{0, 0}
1818
end
1919

2020
function FiniteElementContainers.residual(::Poisson, cell, u_el, args...)
@@ -94,7 +94,7 @@ function poisson_cuda()
9494
close(exo)
9595
end
9696

97-
# @time poisson_cuda()
98-
# @time poisson_cuda()
97+
@time poisson_cuda()
98+
@time poisson_cuda()
9999

100-
@benchmark poisson_cuda()
100+
# @benchmark poisson_cuda()

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ include("TestFields.jl")
1818
include("TestFormulations.jl")
1919
# include("TestFunctionSpaces.jl")
2020
include("TestMesh.jl")
21+
include("TestPhysics.jl")
2122

2223
# @testset ExtendedTestSet "Eigen problem" begin
2324
# include("eigen/TestEigen.jl")

0 commit comments

Comments
 (0)