Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/ItemBuffers/CellBuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ function reinit_coupled!(coupled_buffers::NamedTuple, coupled::CoupledSimulation
if length(coupled_buffers) != length(coupled.sims)
throw(ArgumentError("When using coupled simulations, the coupled buffers must match the coupled simulations"))
end
tuple((reinit_buffer!(cb, coupled.sims[k], CoupledSimulations(), cellnum) for (k, cb) in pairs(coupled_buffers))...)
for (k, cb) in pairs(coupled_buffers)
sim = coupled.sims[k]
set_time_increment!(cb, get_time_increment(get_base(get_itembuffer(sim))))
reinit_buffer!(cb, sim, CoupledSimulations(), cellnum)
end
return nothing
end

Expand Down
21 changes: 21 additions & 0 deletions test/replacements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ end
FerriteAssembly.create_cell_state(::MA, cv, x, ae, args...) = [function_value(cv, i, ae) for i in 1:getnquadpoints(cv)]
FerriteAssembly.create_cell_state(::MB, cv, x, ae, args...) = [2 * function_value(cv, i, ae)[1] for i in 1:getnquadpoints(cv)]

Δt2 = 0.25
# Test case to check that values have been updated correctly
function FerriteAssembly.element_routine!(Ke, re, state, ae, m::MA, cv, buffer)
cb_b = FerriteAssembly.get_coupled_buffer(buffer, :b)
Expand All @@ -72,6 +73,8 @@ end
@test FerriteAssembly.get_aeold(buffer) ≈ FerriteAssembly.get_aeold(cb_b)[2:2:end]
# Check that state variables have been updated
@test 6 * state ≈ FerriteAssembly.get_state(cb_b)
# Check that the coupled buffer's time increment reflects the partner's current value
@test FerriteAssembly.get_time_increment(cb_b) == Δt2
end

a1 = rand(ndofs(dh1))
Expand Down Expand Up @@ -101,7 +104,25 @@ end
K = allocate_matrix(dh1)
r = zeros(ndofs(dh1))
assembler = start_assemble(K, r)
Δt2 = 0.25
set_time_increment!(d2, Δt2)
work!(assembler, sim1, CoupledSimulations(b = sim2)) # Test
# Change the partner's time increment before the next staggered iteration
# and check it isn't stale (BUG-003 regression)
Δt2 = 0.75
set_time_increment!(d2, Δt2)
assembler = start_assemble(K, r)
work!(assembler, sim1, CoupledSimulations(b = sim2)) # Test
# An independently coupled copy (a distinct buffer object from the one
# captured by `couple_buffers(d1; b = d2)` above, as occurs e.g. after
# `replace_material`, cf. the fracture tutorial) must also give a fresh,
# non-stale time increment (BUG-003 regression)
d2_indep = FerriteAssembly.replace_material(d2, identity)
sim2_indep = Simulation(d2_indep, a2, aold2)
Δt2 = 0.4
set_time_increment!(d2_indep, Δt2)
assembler = start_assemble(K, r)
work!(assembler, sim1, CoupledSimulations(b = sim2_indep)) # Test
end
end
end
Expand Down