Skip to content

Commit 3a7cc41

Browse files
committed
Fix to Courant-based timestepping
1 parent 69b68ff commit 3a7cc41

File tree

4 files changed

+64
-11
lines changed

4 files changed

+64
-11
lines changed

ICFERST/src/Extract_From_State.F90

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,9 +2209,22 @@ subroutine Adaptive_NonLinear(Mdims, packed_state, reference_field, its, itime,&
22092209
call real_from_python(pyfunc, acctim, min_ts)
22102210
end if
22112211
!Now check the CFL ones just in case that approach is being used in combination with the non-linear case
2212-
call get_option('/timestepping/adaptive_timestep/minimum_timestep', auxR, stat= auxI)
2212+
if (have_option('/timestepping/adaptive_timestep/minimum_timestep/constant')) then
2213+
call get_option('/timestepping/adaptive_timestep/minimum_timestep/constant', auxR, stat= auxI)
2214+
else if (have_option('/timestepping/adaptive_timestep/minimum_timestep/python')) then
2215+
call get_option('/timestepping/adaptive_timestep/minimum_timestep/python', pyfunc)
2216+
call real_from_python(pyfunc, acctim, auxR)
2217+
end if
2218+
22132219
if (auxI == 0) min_ts = min(min_ts, auxR)
2214-
call get_option('/timestepping/adaptive_timestep/maximum_timestep', auxR, stat= auxI)
2220+
2221+
if (have_option('/timestepping/adaptive_timestep/maximum_timestep/constant')) then
2222+
call get_option('/timestepping/adaptive_timestep/maximum_timestep/constant', auxR, stat= auxI)
2223+
else if (have_option('/timestepping/adaptive_timestep/maximum_timestep/python')) then
2224+
call get_option('/timestepping/adaptive_timestep/maximum_timestep/python', pyfunc)
2225+
call real_from_python(pyfunc, acctim, auxR)
2226+
end if
2227+
22152228
if (auxI == 0) max_ts = min(max_ts, auxR)
22162229

22172230
!Ensure that even adapting the time, the final time is matched

ICFERST/src/Multiphase_TimeLoop.F90

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ subroutine MultiFluids_SolveTimeLoop( state, &
254254
double precision, ALLOCATABLE, dimension(:,:) :: concetration_phreeqc
255255
real :: total_mass_metal_before_adapt, total_mass_metal_after_adapt, total_mass_metal_after_correction, total_mass_metal_after_bound
256256
logical :: viscosity_EOS
257+
character(len=PYTHON_FUNC_LEN) :: pyfunc
258+
257259
#ifdef HAVE_ZOLTAN
258260
real(zoltan_float) :: ver
259261
integer(zoltan_int) :: ierr
@@ -1021,8 +1023,19 @@ subroutine MultiFluids_SolveTimeLoop( state, &
10211023
nonlinear_dt = dt!To use if also the nonlinear adapt time-step is on
10221024
c = -66.6 ; minc = 0. ; maxc = 66.e6 ; ic = 1.1!66.e6
10231025
call get_option( '/timestepping/adaptive_timestep/requested_cfl', rc )
1024-
call get_option( '/timestepping/adaptive_timestep/minimum_timestep', minc, stat, default = 0.)
1025-
call get_option( '/timestepping/adaptive_timestep/maximum_timestep', maxc, stat, default = 66.e6)
1026+
1027+
call get_option('/timestepping/adaptive_timestep/minimum_timestep/constant', minc, stat, default = 0.)
1028+
if (have_option('/timestepping/adaptive_timestep/minimum_timestep/python')) then
1029+
call get_option('/timestepping/adaptive_timestep/minimum_timestep/python', pyfunc)
1030+
call real_from_python(pyfunc, acctim, minc)
1031+
end if
1032+
1033+
call get_option('/timestepping/adaptive_timestep/maximum_timestep/constant', maxc, stat, default = 66.e6)
1034+
if (have_option('/timestepping/adaptive_timestep/maximum_timestep/python')) then
1035+
call get_option('/timestepping/adaptive_timestep/maximum_timestep/python', pyfunc)
1036+
call real_from_python(pyfunc, acctim, maxc)
1037+
end if
1038+
10261039
call get_option( '/timestepping/adaptive_timestep/increase_tolerance', ic, stat, default = 1.1)
10271040
!For porous media we need to use the Courant number obtained in cv_assemb
10281041
if (is_porous_media) then

femtools/Adaptive_Timestepping.F90

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module adaptive_timestepping
3131
!!< Contains new style adaptive timestepping routines
3232

3333
use fldebug
34-
use global_parameters, only : OPTION_PATH_LEN, FIELD_NAME_LEN
34+
use global_parameters, only : OPTION_PATH_LEN, FIELD_NAME_LEN, PYTHON_FUNC_LEN
3535
use spud
3636
use unittest_tools
3737
use fields
@@ -70,6 +70,8 @@ subroutine calc_cflnumber_field_based_dt(state, dt, force_calculation)
7070
type(scalar_field), pointer :: cflnumber_field
7171
type(vector_field), pointer :: velocity_field
7272
type(mesh_type), pointer :: mesh
73+
character(len=PYTHON_FUNC_LEN) :: pyfunc
74+
real :: current_time
7375

7476
ewrite(1, *) "In calc_cflnumber_field_based_dt"
7577

@@ -79,9 +81,19 @@ subroutine calc_cflnumber_field_based_dt(state, dt, force_calculation)
7981
lforce_calculation = .false.
8082
end if
8183

84+
call get_option("/timestepping/current_time", current_time)
85+
8286
call get_option(base_path // "/requested_cfl", max_cfl)
83-
call get_option(base_path // "/minimum_timestep", min_dt, default = tiny(0.0))
84-
call get_option(base_path // "/maximum_timestep", max_dt, default = huge(0.0))
87+
call get_option(base_path // "/minimum_timestep/constant", min_dt, default = tiny(0.0))
88+
if (have_option(base_path // '/minimum_timestep/python')) then
89+
call get_option(base_path // '/minimum_timestep/python', pyfunc)
90+
call real_from_python(pyfunc, current_time, min_dt)
91+
end if
92+
call get_option(base_path // "/maximum_timestep/constant", max_dt, default = huge(0.0))
93+
if (have_option(base_path // '/maximum_timestep/python')) then
94+
call get_option(base_path // '/maximum_timestep/python', pyfunc)
95+
call real_from_python(pyfunc, current_time, max_dt)
96+
end if
8597
call get_option(base_path // "/increase_tolerance", increase_tolerance, default = huge(0.0) * epsilon(0.0))
8698
! what type of cfl number are we using?
8799
call get_option(base_path//"/courant_number[0]/name", cfl_type)
@@ -187,6 +199,8 @@ subroutine adaptive_timestepping_check_options
187199
character(len = OPTION_PATH_LEN) :: base_path
188200
integer :: stat
189201
real :: max_cfl, max_dt, min_dt, increase_tolerance
202+
character(len=PYTHON_FUNC_LEN) :: pyfunc
203+
real :: current_time
190204

191205
base_path = "/timestepping/adaptive_timestep"
192206

@@ -205,7 +219,15 @@ subroutine adaptive_timestepping_check_options
205219
FLExit("Maximum adaptive timestepping CFL number must be positive")
206220
end if
207221

208-
call get_option(trim(base_path) // "/minimum_timestep", min_dt, stat)
222+
call get_option("/timestepping/current_time", current_time)
223+
224+
if (have_option(trim(base_path) // '/minimum_timestep/constant')) then
225+
call get_option(trim(base_path) // "/minimum_timestep/constant", min_dt, stat)
226+
else if (have_option(trim(base_path) // '/minimum_timestep/python')) then
227+
call get_option(trim(base_path) // '/minimum_timestep/python', pyfunc)
228+
call real_from_python(pyfunc, current_time, min_dt)
229+
end if
230+
209231
if(stat == SPUD_NO_ERROR) then
210232
if(min_dt < 0.0) then
211233
FLExit("Minimum timestep size cannot be negative")

main/Fluids.F90

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module fluids_module
3636
simulation_start_time, &
3737
simulation_start_cpu_time, &
3838
simulation_start_wall_time, &
39-
topology_mesh_name, FIELD_NAME_LEN, is_porous_media
39+
topology_mesh_name, FIELD_NAME_LEN, is_porous_media, PYTHON_FUNC_LEN
4040
use futils, only: int2str
4141
use reference_counting, only: print_references
4242
use parallel_tools
@@ -912,6 +912,7 @@ subroutine update_state_post_adapt(state, metric_tensor, dt, sub_state, nonlinea
912912
real, intent(inout) :: dt
913913
integer, intent(inout) :: nonlinear_iterations, nonlinear_iterations_adapt
914914
type(state_type), dimension(:), pointer :: sub_state
915+
character(len=PYTHON_FUNC_LEN) :: pyfunc
915916

916917
! Overwrite the number of nonlinear iterations if the option is switched on
917918
if(have_option("/timestepping/nonlinear_iterations/nonlinear_iterations_at_adapt")) then
@@ -939,8 +940,12 @@ subroutine update_state_post_adapt(state, metric_tensor, dt, sub_state, nonlinea
939940
call enforce_discrete_properties(state)
940941

941942
if (have_option("/mesh_adaptivity/hr_adaptivity/adaptive_timestep_at_adapt")) then
942-
if (have_option("/timestepping/adaptive_timestep/minimum_timestep")) then
943-
call get_option("/timestepping/adaptive_timestep/minimum_timestep", dt)
943+
if (have_option('/timestepping/adaptive_timestep/minimum_timestep/constant')) then
944+
call get_option('/timestepping/adaptive_timestep/minimum_timestep/constant', dt)
945+
call set_option("/timestepping/timestep", dt)
946+
else if (have_option('/timestepping/adaptive_timestep/minimum_timestep/python')) then
947+
call get_option('/timestepping/adaptive_timestep/minimum_timestep/python', pyfunc)
948+
call real_from_python(pyfunc, current_time, dt)
944949
call set_option("/timestepping/timestep", dt)
945950
else
946951
ewrite(-1,*) "Warning: you have adaptive timestep adjustment after &&

0 commit comments

Comments
 (0)