From afc09f9f95a6a0a157f90cf127e57b7288eba6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 25 Aug 2026 15:43:48 +0200 Subject: [PATCH] Added update_displacements! function --- .../ComputationalModels.jl | 2 ++ src/ComputationalModels/Drivers.jl | 30 +++++++++++++++---- src/Exports.jl | 2 ++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/ComputationalModels/ComputationalModels.jl b/src/ComputationalModels/ComputationalModels.jl index 59484e3a..b27f582f 100644 --- a/src/ComputationalModels/ComputationalModels.jl +++ b/src/ComputationalModels/ComputationalModels.jl @@ -69,6 +69,8 @@ export get_spaces export get_assemblers export get_trial_space export get_test_space +export update_velocity! +export update_displacements! include("PostProcessors.jl") export PostProcessor diff --git a/src/ComputationalModels/Drivers.jl b/src/ComputationalModels/Drivers.jl index 024431ba..16226236 100644 --- a/src/ComputationalModels/Drivers.jl +++ b/src/ComputationalModels/Drivers.jl @@ -283,13 +283,31 @@ get_spaces(m::DynamicNonlinearModel) = m.spaces get_assemblers(m::DynamicNonlinearModel) = (m.caches[4]) +""" +Update the velocity field `vh` based on the current displacement field `xh⁺` +and the previous displacement `xh⁻` using a midpoint time-stepping scheme. +The velocity is updated in place. +""" +function update_velocity!(vh, xh⁺, xh⁻, Δt) + v = get_free_dof_values(vh) + v .*= -1.0 + v .-= (2.0 / Δt) * get_free_dof_values(xh⁻) + v .+= (2.0 / Δt) * get_free_dof_values(xh⁺) + return vh +end + -function update_velocity!(vh, x, x⁻, Δt) - vh_ = get_free_dof_values(vh) - vh_ .*= -1.0 - vh_ .-= (2.0 / Δt) .* x⁻ - vh_ .+= (2.0 / Δt) .* x - return vh +""" +Update the old displacement field `xh⁻` with the new displacement field `xh⁺`. +The update is performed in place, modifying `xh⁻` to match both the free dof values +and the dirichlet dof values of `xh⁺`. +""" +function update_displacements!(xh⁻, xh⁺) + x = get_free_dof_values(xh⁻) + x .= get_free_dof_values(xh⁺) + x_dir = get_dirichlet_dof_values(get_fe_space(xh⁻)) + x_dir .= get_dirichlet_dof_values(get_fe_space(xh⁺)) + return xh⁻ end diff --git a/src/Exports.jl b/src/Exports.jl index 406bc8db..ad033c40 100644 --- a/src/Exports.jl +++ b/src/Exports.jl @@ -144,6 +144,8 @@ end @publish ComputationalModels dirichlet_preconditioning! @publish ComputationalModels GmshDiscreteModel @publish ComputationalModels updateBC! +@publish ComputationalModels update_velocity! +@publish ComputationalModels update_displacements! @publish ComputationalModels PostProcessor @publish ComputationalModels vtk_save @publish ComputationalModels get_pvd