Skip to content

Commit 8dd33c4

Browse files
authored
Merge pull request #222 from kaipartmann/contact-dynamic-relaxation
Added support for dynamic relaxation solver and multibody simulations
2 parents f4b9ada + e97e60f commit 8dd33c4

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

src/time_solvers/dynamic_relaxation.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ function init_density_matrix!(dh::AbstractThreadsBodyDataHandler, dr::DynamicRel
113113
return nothing
114114
end
115115

116+
function init_density_matrix!(dh::AbstractThreadsMultibodyDataHandler,
117+
dr::DynamicRelaxation)
118+
for body_idx in each_body_idx(dh)
119+
body_dh = get_body_dh(dh, body_idx)
120+
@threads :static for chunk in body_dh.chunks
121+
_init_density_matrix!(chunk, dr, chunk.paramsetup)
122+
end
123+
end
124+
return nothing
125+
end
126+
116127
function init_density_matrix!(dh::AbstractMPIBodyDataHandler, dr::DynamicRelaxation)
117128
_init_density_matrix!(dh.chunk, dr, dh.chunk.paramsetup)
118129
return nothing
@@ -216,6 +227,36 @@ function relaxation_timestep!(dh::AbstractMPIBodyDataHandler,
216227
return nothing
217228
end
218229

230+
function relaxation_timestep!(dh::AbstractThreadsMultibodyDataHandler,
231+
options::AbstractJobOptions, Δt, n)
232+
t = n * Δt
233+
for body_idx in each_body_idx(dh)
234+
body_dh = get_body_dh(dh, body_idx)
235+
@threads :static for chunk_id in eachindex(body_dh.chunks)
236+
chunk = body_dh.chunks[chunk_id]
237+
apply_boundary_conditions!(chunk, t)
238+
update_disp_and_pos!(chunk, Δt)
239+
end
240+
end
241+
calc_force_density!(dh, t, Δt)
242+
update_caches!(dh)
243+
calc_contact_force_densities!(dh)
244+
for body_idx in each_body_idx(dh)
245+
body_dh = get_body_dh(dh, body_idx)
246+
@threads :static for chunk_id in eachindex(body_dh.chunks)
247+
chunk = body_dh.chunks[chunk_id]
248+
cn = calc_damping(chunk, Δt)
249+
if n == 1
250+
relaxation_first_step!(chunk, Δt)
251+
else
252+
relaxation_step!(chunk, Δt, cn)
253+
end
254+
export_results(body_dh, options, chunk_id, n, t)
255+
end
256+
end
257+
return nothing
258+
end
259+
219260
function calc_damping(chunk::AbstractBodyChunk, Δt::Float64)
220261
s = chunk.storage
221262
cn1 = 0.0

test/time_solvers/test_dynamic_relaxation.jl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,57 @@ end
5555
msg = String(take!(io))
5656
@test contains(msg, "DynamicRelaxation:\n n_steps 1\n Δt 1\n Λ 1")
5757
end
58+
59+
@testitem "init_density_matrix! and relaxation_timestep! for all data handlers" begin
60+
import Peridynamics: init_density_matrix!, relaxation_timestep!
61+
# Setup single body
62+
position = [0.0 1.0 0.0 0.0;
63+
0.0 0.0 0.0 1.0;
64+
0.0 0.0 1.0 0.0]
65+
volume = fill(1.0, 4)
66+
body = Body(BBMaterial(), position, volume)
67+
material!(body; horizon=1.5, rho=8e-6, E=210e3)
68+
point_set!(body, :a, 1:2)
69+
material!(body, :a; horizon=3, rho=7.8e-6, E=200e3)
70+
forcedensity_bc!((p,t) -> 1e5 * p[1], body, :a, :x)
71+
dr = DynamicRelaxation(steps=2)
72+
options = Peridynamics.JobOptions(body)
73+
74+
# ThreadsBodyDataHandler
75+
dh_threads = Peridynamics.threads_data_handler(body, dr, 1)
76+
init_density_matrix!(dh_threads, dr)
77+
@test all(dh_threads.chunks[1].storage.density_matrix .>= 0)
78+
@test dh_threads.chunks[1].storage.position position
79+
relaxation_timestep!(dh_threads, options, dr.Δt, 1)
80+
relaxation_timestep!(dh_threads, options, dr.Δt, 2)
81+
# Check that the density matrix is updated correctly
82+
@test dh_threads.chunks[1].storage.position[1, 2] 1.05
83+
84+
# ThreadsMultibodyDataHandler
85+
b2 = Body(BBMaterial(), position, volume)
86+
material!(b2; horizon=1.5, rho=8e-6, E=210e3)
87+
ms = MultibodySetup(:b1 => body, :b2 => b2)
88+
dh_multibody = Peridynamics.threads_data_handler(ms, dr, 1)
89+
options_multi = Peridynamics.JobOptions(ms)
90+
init_density_matrix!(dh_multibody, dr)
91+
for body_idx in Peridynamics.each_body_idx(dh_multibody)
92+
for chunk in Peridynamics.get_body_dh(dh_multibody, body_idx).chunks
93+
@test all(chunk.storage.density_matrix .>= 0)
94+
@test chunk.storage.position position
95+
end
96+
end
97+
relaxation_timestep!(dh_multibody, options_multi, dr.Δt, 1)
98+
relaxation_timestep!(dh_multibody, options_multi, dr.Δt, 2)
99+
# Check that the density matrix is updated correctly
100+
@test dh_multibody.body_dhs[1].chunks[1].storage.position[1, 2] 1.05
101+
102+
# AbstractMPIBodyDataHandler
103+
dh_mpi = Peridynamics.mpi_data_handler(body, dr)
104+
init_density_matrix!(dh_mpi, dr)
105+
@test all(dh_mpi.chunk.storage.density_matrix .>= 0)
106+
@test dh_mpi.chunk.storage.position position
107+
relaxation_timestep!(dh_mpi, options, dr.Δt, 1)
108+
relaxation_timestep!(dh_mpi, options, dr.Δt, 2)
109+
# Check that the density matrix is updated correctly
110+
@test dh_mpi.chunk.storage.position[1, 2] 1.05
111+
end

0 commit comments

Comments
 (0)