Skip to content

Commit

Permalink
Enable adaptive time stepping WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lxmota committed Feb 8, 2025
1 parent dcebb03 commit 9625a40
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 11 deletions.
Binary file added examples/adaptive-time-stepping/single/cube.g
Binary file not shown.
34 changes: 34 additions & 0 deletions examples/adaptive-time-stepping/single/cube.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
${side = 1.0}
${h_size = 0.5}

create brick x {side} y {side} z {side}
volume all size {h_size}
mesh volume all
block 1 volume 1
block 1 name "cube"
nodeset 1 surface with x_coord < 0
nodeset 1 name "nsx-"
nodeset 2 surface with x_coord > 0
nodeset 2 name "nsx+"
nodeset 3 surface with y_coord < 0
nodeset 3 name "nsy-"
nodeset 4 surface with y_coord > 0
nodeset 4 name "nsy+"
nodeset 5 surface with z_coord < 0
nodeset 5 name "nsz-"
nodeset 6 surface with z_coord > 0
nodeset 6 name "nsz+"
sideset 1 surface with x_coord < 0
sideset 1 name "ssx-"
sideset 2 surface with x_coord > 0
sideset 2 name "ssx+"
sideset 3 surface with y_coord < 0
sideset 3 name "ssy-"
sideset 4 surface with y_coord < 0
sideset 4 name "ssy+"
sideset 5 surface with z_coord < 0
sideset 5 name "ssz-"
sideset 6 surface with z_coord > 0
sideset 6 name "ssz+"
set large exodus file off
export mesh "cube.g" overwrite
45 changes: 45 additions & 0 deletions examples/adaptive-time-stepping/single/cube.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
type: single
input mesh file: cube.g
output mesh file: cube.e
Exodus output interval: 1
CSV output interval: 0
model:
type: solid mechanics
material:
blocks:
cube: elastic
elastic:
model: linear elastic
elastic modulus: 1.0e+09
Poisson's ratio: 0.25
density: 1000.0
time integrator:
type: quasi static
initial time: 0.0
final time: 1.0
time step: 1.0
maximum time step: 1.0
minimum time step: 0.01
increase factor: 1.1
decrease factor: 0.5
boundary conditions:
Dirichlet:
- node set: nsx-
component: x
function: "0.0"
- node set: nsy-
component: y
function: "0.0"
- node set: nsz-
component: z
function: "0.0"
- node set: nsz+
component: z
function: "-0.5 * t"
solver:
type: Hessian minimizer
step: full Newton
minimum iterations: 1
maximum iterations: 16
relative tolerance: 1.0e-12
absolute tolerance: 1.0e-08
8 changes: 5 additions & 3 deletions src/evolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function adapt_time_step(sim::SingleDomainSimulation)
". Enable adaptive time stepping.")
end
new_time_step = decrease_factor * time_step
if new_time_step < time_step
if new_time_step < minimum_time_step
error("Cannot adapt time step to ", new_time_step, " because minimum is ", minimum_time_step)
end
sim.integrator.time_step = new_time_step
Expand All @@ -67,15 +67,16 @@ function adapt_time_step(sim::SingleDomainSimulation)
end

function advance(sim::SingleDomainSimulation)
apply_bcs(sim)
save_stop_solutions(sim)
while true
apply_bcs(sim)
solve(sim)
if sim.failed == false
break
end
restore_stop_solutions(sim)
adapt_time_step(sim)
advance_time(sim)
sync_time(sim)
sim.failed = false
end
end
Expand Down Expand Up @@ -216,6 +217,7 @@ function synchronize(sim::MultiDomainSimulation)
end

function advance_time(sim::SingleDomainSimulation)
save_stop_solutions(sim)
sim.integrator.prev_time = sim.integrator.time
next_time = round(sim.integrator.time + sim.integrator.time_step; digits = 12)
sim.integrator.time = sim.model.time = next_time
Expand Down
1 change: 0 additions & 1 deletion src/schwarz_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ mutable struct SolidSchwarzController <: SchwarzController
end

mutable struct SolidSingleController <: SingleController
time_step::Float64
time::Float64
prev_time::Float64
stop::Int64
Expand Down
3 changes: 1 addition & 2 deletions src/simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ function SingleDomainSimulation(params::Dict{String, Any})
output_mesh = Exodus.ExodusDatabase(output_mesh_file, "rw")
params["output_mesh"] = output_mesh
params["input_mesh"] = input_mesh
controller = SolidSingleController(0.0, 0.0, 0.0, 0,
Vector{Float64}(), Vector{Float64}(), Vector{Float64}(), Vector{Float64}())
controller = SolidSingleController(0.0, 0.0, 0, Vector{Float64}(), Vector{Float64}(), Vector{Float64}(), Vector{Float64}())
model = create_model(params)
integrator = create_time_integrator(params, model)
solver = create_solver(params, model)
Expand Down
6 changes: 3 additions & 3 deletions src/time_integrator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ function QuasiStatic(params::Dict{String, Any}, model::Model)
time_step,
runtime_step,
minimum_time_step,
decrease_factor,
maximum_time_step,
decrease_factor,
increase_factor,
prev_time,
time,
Expand Down Expand Up @@ -100,8 +100,8 @@ function Newmark(params::Dict{String, Any}, model::Model)
time_step,
runtime_step,
minimum_time_step,
decrease_factor,
maximum_time_step,
decrease_factor,
increase_factor,
prev_time,
time,
Expand Down Expand Up @@ -143,8 +143,8 @@ function CentralDifference(params::Dict{String, Any}, model::Model)
time_step,
runtime_step,
minimum_time_step,
decrease_factor,
maximum_time_step,
decrease_factor,
increase_factor,
user_time_step,
stable_time_step,
Expand Down
2 changes: 1 addition & 1 deletion test/constitutive-model-energy-gradient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Random

include("../src/minitensor.jl")
include("../src/constitutive_def.jl")
include("../src/constitutive_types.jl")
include("../src/constitutive.jl")

function finite_difference(material::Solid, F::Matrix{Float64}, dF::Matrix{Float64}, h::Float64)
Expand Down
2 changes: 1 addition & 1 deletion test/j2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# the U.S. Government retains certain rights in this software. This software
# is released under the BSD license detailed in the file license.txt in the
# top-level Norma.jl directory.
include("../src/constitutive_def.jl")
include("../src/constitutive_types.jl")
include("../src/constitutive.jl")

using LinearAlgebra
Expand Down

0 comments on commit 9625a40

Please sign in to comment.