From 3a03c3aedd66d6f4e410bc3421a567531dbfe676 Mon Sep 17 00:00:00 2001 From: Jacob Gunnarsson Date: Wed, 10 Jun 2026 09:34:24 +0200 Subject: [PATCH] Added function that copies old state to new state --- src/DomainBuffers.jl | 9 +++++++++ src/Simulation.jl | 1 + src/states.jl | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/src/DomainBuffers.jl b/src/DomainBuffers.jl index 208e5f7b..67914a33 100644 --- a/src/DomainBuffers.jl +++ b/src/DomainBuffers.jl @@ -86,6 +86,13 @@ function update_states!(dbs::DomainBuffers) end end + +function set_new_to_old_states!(dbs::DomainBuffers) + for db in values(dbs) + set_new_to_old_states!(db) + end +end + """ set_time_increment!(db::Dict{String,AbstractDomainBuffer}, Δt) set_time_increment!(db::AbstractDomainBuffer, Δt) @@ -181,6 +188,8 @@ get_material(b::StdDomainBuffer) = get_material(get_base(get_itembuffer(b))) # Update old_states = new_states after convergence update_states!(b::StdDomainBuffer) = update_states!(b.states) +set_new_to_old_states!(b::StdDomainBuffer) = set_new_to_old_states!(b.states) + function set_time_increment!(b::StdDomainBuffer, Δt) set_time_increment!(get_base(get_itembuffer(b)), Δt) end diff --git a/src/Simulation.jl b/src/Simulation.jl index 8983c754..9194babb 100644 --- a/src/Simulation.jl +++ b/src/Simulation.jl @@ -32,6 +32,7 @@ get_old_state(sim::Simulation, args::Vararg{Any, N}) where N = get_old_state(sim getset(sim::Simulation, args::Vararg{Any, N}) where N = getset(sim.db, args...) update_states!(sim::Simulation) = update_states!(sim.db) set_time_increment!(sim::Simulation, Δt) = set_time_increment!(sim.db, Δt) +set_new_to_old_states!(sim::Simulation) = set_new_to_old_states!(sim.db) # Forwarding for internal API get_num_tasks(sim::Simulation) = get_num_tasks(sim.db) diff --git a/src/states.jl b/src/states.jl index 364dad6d..abfe1727 100644 --- a/src/states.jl +++ b/src/states.jl @@ -18,6 +18,12 @@ function update_states!(sv::StateVariables) sv.new.vals = tmp end +function set_new_to_old_states!(sv::StateVariables) + for key in keys(sv.old.vals) + copyto!(sv.new.vals[key], sv.old.vals[key]) + end +end + # Experimental, basically copy!, but use separate name for clarity function replace_states!(dst::StateVariables, src::StateVariables) dst.old.vals = src.old.vals