Skip to content

Commit 47ce3e6

Browse files
authored
Merge pull request #103 from egyaa20/AA/adaptive-dt
Add adaptive timestepping
2 parents 9e5b343 + ecd05fe commit 47ce3e6

25 files changed

+351
-43
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66
## Version [v0.5.3] - 2026-02-19
77

88
### Added
9-
* No new functionality added
9+
* Added optional adaptive time stepping based on Courant number control (`AdaptiveTimeStepping`) [#98](@ref)
1010

1111

1212
### Fixed

examples/2D_flatplate_fixedT_KOmega.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ solvers = (
9999
solver = Gmres(), # Bicgstab(), Gmres()
100100
preconditioner = Jacobi(),
101101
convergence = 1e-7,
102-
relax = 0.3,
102+
# relax = 0.3,
103+
relax = 0.2,
103104
atol = 1e-2
104105
),
105106
h = SolverSetup(

src/Calculate/Calculate_0_gradient.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,9 @@ function grad!(grad::Grad{Midpoint,F,R,I,M}, phif, phi, BCs, time, config) where
255255
correct_interpolation!(grad, phif, phi, config)
256256
green_gauss!(grad, phif, config)
257257
end
258+
end
259+
260+
# This is a gradient method that does not take BCs as arguments (implicitly assuming the the gradient at boundaries is 0)
261+
function grad!(grad::Grad{Gauss,F,R,I,M}, phif, phi, time, config) where {F,R<:VectorField,I,M}
262+
green_gauss!(grad, phif, config)
258263
end

src/Discretise/Discretise_1_schemes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ end
3030
@inline scheme_source!(
3131
term::Operator{F,P,I,Time{Euler}}, cell, cID, cIndex, prev, runtime) where {F,P,I} = begin
3232
volume = cell.volume
33-
vol_rdt = volume/runtime.dt
33+
vol_rdt = volume/runtime.dt[1]
3434

3535
# Increment sparse and b arrays
3636
ac = vol_rdt
@@ -48,7 +48,7 @@ end
4848
@inline scheme_source!(
4949
term::Operator{F,P,I,Time{CrankNicolson}}, cell, cID, cIndex, prev, runtime) where {F,P,I} = begin
5050
volume = cell.volume
51-
vol_rdt = volume/runtime.dt
51+
vol_rdt = volume/runtime.dt[1]
5252

5353
# Increment sparse and b arrays
5454
ac = vol_rdt

src/ModelPhysics/0_type_definition.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export Momentum
44
export AbstractTimeModel
55
export Transient, Steady
66

7+
78
"""
89
struct Physics{T,F,SO,M,Tu,E,D,BI}
910
time::T
@@ -159,4 +160,4 @@ end
159160
mutable struct ModelState{T1}
160161
residuals::T1
161162
converged::Bool
162-
end
163+
end

src/ModelPhysics/Energy/Energy.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ include("energy_types.jl")
1919

2020
# Energy models
2121
include("Sensible_Enthalpy.jl")
22-
# include("Laplace_Energy.jl")
2322
include("Conduction.jl")
2423

2524
# Property Models

src/ModelPhysics/Energy/Sensible_Enthalpy.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function energy!(
159159
# Kbounded = ScalarField(mesh)
160160
Pr = model.fluid.Pr
161161

162-
dt = runtime.dt
162+
dt = runtime.dt[1]
163163

164164
# Pre-allocate auxiliary variables
165165
TF = _get_float(mesh)

src/ModelPhysics/ModelPhysics.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ include("Turbulence/Turbulence.jl")
3434
include("FluidProperties/FluidProperties.jl")
3535

3636

37+
3738
end # end module

src/ModelPhysics/Turbulence/RANS_laminar.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ function save_output(model::Physics{T,F,SO,M,Tu,E,D,BI}, outputWriter, iteration
102102
write_results(iteration, time, model.domain, outputWriter, config.boundaries, args...)
103103
end
104104

105+
# function save_output(model::Physics{T,F,SO,M,Tu,E,D,BI}, outputWriter, iteration, time, config
106+
# ) where {T,F<:Multiphase,SO,M,Tu<:Laminar,E<:Nothing,D,BI}
107+
108+
# args = (
109+
# ("U", model.momentum.U),
110+
# ("p", model.momentum.p),
111+
# ("alpha", model.fluid.alpha),
112+
# ("rho", model.fluid.rho),
113+
# # ("p_rgh", model.fluid.p_rgh)
114+
# )
115+
# write_results(iteration, time, model.domain, outputWriter, config.boundaries, args...)
116+
# end
117+
105118
function save_output(model::Physics{T,F,SO,M,Tu,E,D,BI}, outputWriter, iteration, time, config
106119
) where {T,F,SO,M,Tu<:Laminar,E<:Nothing,D,BI}
107120
args = (

src/Simulate/Simulate_0_types.jl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ export Configuration
22
export Hardware
33

44
"""
5-
@kwdef struct Configuration{SC,SL,RT,HW,PP}
5+
struct Configuration{SC,SL,RT,HW,PP}
66
schemes::SC
77
solvers::SL
88
runtime::RT
99
hardware::HW
10-
postprocess::PP = nothing
10+
postprocess::PP
1111
end
1212
1313
The `Configuration` type is passed to all flow solvers and provides all the relevant information to run a simulation.
@@ -29,16 +29,29 @@ config = Configuration(
2929
solvers=solvers, schemes=schemes, runtime=runtime, hardware=hardware, boundaries=BCs)
3030
```
3131
"""
32-
@kwdef struct Configuration{SC,SL,RT,HW,BC,PP}
32+
struct Configuration{SC,SL,RT,HW,BC,PP}
3333
schemes::SC
3434
solvers::SL
3535
runtime::RT
3636
hardware::HW
3737
boundaries::BC
38-
postprocess::PP = nothing
38+
postprocess::PP
3939
end
4040
Adapt.@adapt_structure Configuration
4141

42+
Configuration(; schemes, solvers, runtime, hardware, boundaries, postprocess=nothing) = begin
43+
Configuration(
44+
schemes,
45+
solvers,
46+
adapt(hardware.backend, runtime),
47+
hardware,
48+
boundaries,
49+
postprocess
50+
)
51+
end
52+
53+
54+
4255

4356
"""
4457
hardware = Hardware(backend, workgroup)

0 commit comments

Comments
 (0)