Time stepping

step_time.f90

Quick access

Routines:

initialize_step_time(), start_from_another_scheme(), step_time(), transp_lmloc_to_rloc(), transp_rloc_to_lmloc(), transp_rloc_to_lmloc_io()

Needed modules

Variables

Subroutines and functions

subroutine  step_time_mod/initialize_step_time()
Called from:

magic

Call to:

initialize_signals()

subroutine  step_time_mod/step_time(time, tscheme, n_time_step, run_time_start)

This subroutine performs the actual time-stepping.

Parameters:
  • time [real ,inout]

  • tscheme [real ]

  • n_time_step [integer ,inout]

  • run_time_start [timer_type ,in]

Called from:

magic

Call to:

check_signals(), logwrite(), l_correct_step(), open_graph_file(), transp_lmloc_to_rloc(), radialloopg(), finish_explicit_assembly_rdist(), transp_rloc_to_lmloc(), get_b_nl_bcs(), finish_explicit_assembly(), scatter_from_rank0_to_lo(), transp_rloc_to_lmloc_io(), output(), close_graph_file(), dt_courant(), start_from_another_scheme(), lmloop_rdist(), lmloop(), assemble_stage_rdist(), assemble_stage(), formattime()

subroutine  step_time_mod/start_from_another_scheme(time, l_bridge_step, n_time_step, tscheme)

This subroutine is used to initialize multisteps schemes whenever previous steps are not known. In that case a CN/AB2 scheme is used to bridge the missing steps.

Parameters:
  • time [real ,in]

  • l_bridge_step [logical ,in]

  • n_time_step [integer ,in]

  • tscheme [real ]

Called from:

step_time()

Call to:

get_single_rhs_imp(), bulk_to_ghost(), exch_ghosts(), fill_ghosts_w(), get_pol_rhs_imp_ghost(), get_pol_rhs_imp(), fill_ghosts_s(), get_entropy_rhs_imp_ghost(), get_entropy_rhs_imp(), fill_ghosts_z(), get_tor_rhs_imp_ghost(), get_tor_rhs_imp(), fill_ghosts_xi(), get_comp_rhs_imp_ghost(), get_comp_rhs_imp(), fill_ghosts_phi(), get_phase_rhs_imp_ghost(), get_phase_rhs_imp(), fill_ghosts_b(), get_mag_rhs_imp_ghost(), get_mag_rhs_imp(), get_mag_ic_rhs_imp()

subroutine  step_time_mod/transp_lmloc_to_rloc(comm_counter, l_rloc, lpresscalc, lhtcalc)

Here now comes the block where the LM distributed fields are redistributed to Rloc distribution which is needed for the radialLoop.

Parameters:
  • comm_counter [timer_type ,inout]

  • l_rloc [logical ,in]

  • lpresscalc [logical ,in]

  • lhtcalc [logical ,in]

Called from:

step_time()

Call to:

get_dr_rloc(), get_ddr_rloc()

subroutine  step_time_mod/transp_rloc_to_lmloc(comm_counter, istage, lrloc, lpressnext)
  • MPI transposition from r-distributed to LM-distributed

Parameters:
  • comm_counter [timer_type ,inout]

  • istage [integer ,in]

  • lrloc [logical ,in]

  • lpressnext [logical ,in]

Called from:

step_time()

subroutine  step_time_mod/transp_rloc_to_lmloc_io(lpresscalc)

For now, most of the outputs use LM-distributed arrays as input. To handle that one has to transpose the missing fields.

Parameters:

lpresscalc [logical ,in]

Called from:

step_time()

Call to:

get_dr_rloc()

courant.f90

Description

This module handles the computation of Courant factors on grid space. It then checks whether the timestep size needs to be modified.

Quick access

Variables:

file_handle

Routines:

courant(), dt_courant(), finalize_courant(), initialize_courant()

Needed modules

Variables

  • courant_mod/file_handle [integer,private]

Subroutines and functions

subroutine  courant_mod/initialize_courant(time, dt, tag)

This subroutine opens the timestep.TAG file which stores the time step changes of MagIC.

Parameters:
  • time [real ,in] :: time

  • dt [real ,in] :: time step

  • tag [character(len=*),in] :: trailing of the fime

Called from:

magic

subroutine  courant_mod/finalize_courant()
Called from:

magic

subroutine  courant_mod/courant(n_r, dtrkc, dthkc, vr, vt, vp, br, bt, bp, courfac, alffac)

courant condition check: calculates Courant advection lengths in radial direction dtrkc and in horizontal direction dthkc on the local radial level n_r

for the effective velocity, the abs. sum of fluid velocity and Alfven velocity is taken

instead of the full Alfven velocity a modified Alfven velocity is employed that takes viscous and Joule damping into account. Different Courant factors are used for the fluid velocity and the such modified Alfven velocity

Parameters:
  • n_r [integer ,in] :: radial level

  • dtrkc [real ,inout] :: Courant step (based on radial advection)

  • dthkc [real ,inout] :: Courant step based on horizontal advection

  • vr (*,*) [real ,in] :: radial velocity

  • vt (*,*) [real ,in] :: longitudinal velocity

  • vp (*,*) [real ,in] :: azimuthal velocity

  • br (*,*) [real ,in] :: radial magnetic field

  • bt (*,*) [real ,in] :: longitudinal magnetic field

  • bp (*,*) [real ,in] :: azimuthal magnetic field

  • courfac [real ,in]

  • alffac [real ,in]

Called from:

radialloop()

subroutine  courant_mod/dt_courant(l_new_dt, dt, dt_new, dtmax, dtrkc, dthkc, time)

This subroutine checks if the Courant criterion based on combined fluid and Alfven velocity is satisfied. It returns a new value for the time step size.

Parameters:
  • l_new_dt [logical ,out] :: flag indicating that time step is changed (=1) or not (=0)

  • dt [real ,in] :: old time step size

  • dt_new [real ,out] :: new time step size

  • dtmax [real ,in] ::

  • dtrkc (1 - nrstart + nrstop) [real ,in] :: radial Courant time step as function of radial level

  • dthkc (1 - nrstart + nrstop) [real ,in] :: horizontal Courant time step as function of radial level

  • time [real ,in] :: Current time

Called from:

step_time()

Call to:

logwrite()

timing.f90

Description

This module contains functions that are used to measure the time spent.

Quick access

Types:

timer_type

Routines:

finalize(), formattime(), initialize(), start_count(), stop_count()

Needed modules

  • iso_fortran_env (output_unit())

  • mpimod

  • precision_mod: This module controls the precision used in MagIC

  • parallel_mod: This module contains the blocking information

Types

  • type  timing/timer_type
    Type fields:
    • % n_counts [integer ]

    • % tstart [real ]

    • % ttot [real ]

Variables

Subroutines and functions

subroutine  timing/initialize(this)
Parameters:

this [real ]

subroutine  timing/finalize(this[, message[, n_log_file]])
Parameters:

this [real ]

Options:
  • message [character(len=*),in,]

  • n_log_file [integer ,in,]

Call to:

formattime()

subroutine  timing/start_count(this)
Parameters:

this [real ]

subroutine  timing/stop_count(this[, l_increment])
Parameters:

this [real ]

Options:

l_increment [logical ,in,]

subroutine  timing/formattime(n_out, message, time_in_sec)
Parameters:
  • n_out [integer ,in]

  • message [character(len=*),in]

  • time_in_sec [real ,in]

Called from:

finalize(), step_time()

Time schemes

time_schemes.f90

Description

This module defines an abstract class type_tscheme which is employed for the time advance of the code.

Quick access

Types:

type_tscheme

Variables:

unknown_interface

Routines:

print_info()

Needed modules

  • iso_fortran_env (output_unit())

  • time_array: This module defines two types that are defined to store the implicit/explicit terms at the different sub-stage/step.

  • logic (l_save_out()): Module containing the logicals that control the run

  • output_data (log_file()): This module contains the parameters for output control

  • precision_mod: This module controls the precision used in MagIC

Types

  • type  time_schemes/type_tscheme
    Type fields:
    • % alffac [real ]

    • % courfac [real ]

    • % dt (*) [real ,allocatable]

    • % family [character(len=10)]

    • % intfac [real ]

    • % istage [integer ]

    • % l_assembly [logical ]

    • % l_exp_calc (*) [logical ,allocatable]

    • % l_imp_calc_rhs (*) [logical ,allocatable]

    • % nexp [integer ]

    • % nimp [integer ]

    • % nold [integer ]

    • % nstages [integer ]

    • % time_scheme [character(len=8)]

    • % wimp_lin (*) [real ,allocatable]

Variables

  • time_schemes/unknown_interface [private]

Subroutines and functions

subroutine  time_schemes/print_info(this, n_log_file)

This subroutine prints some informations about the time stepping scheme

Parameters:
  • this [real ]

  • n_log_file [integer ,inout] :: File unit of the log.TAG file

Called from:

readstartfields(), readstartfields_mpi()

multistep_schemes.f90

Description

This module defines the type_multistep which inherits from the abstract type_tscheme. It actually implements all the routine required to time-advance an IMEX multistep scheme such as CN/AB2, SBDF(2,3,4), CNLF, …

Quick access

Types:

type_multistep

Routines:

assemble_imex(), assemble_imex_scalar(), bridge_with_cnab2(), get_time_stage(), rotate_imex(), rotate_imex_scalar(), set_dt_array(), set_imex_rhs(), set_imex_rhs_ghost(), set_imex_rhs_scalar(), set_weights(), start_with_ab1()

Needed modules

Types

  • type  multistep_schemes/type_multistep
    Type fields:
    • % wexp (*) [real ,allocatable]

    • % wimp (*) [real ,allocatable]

Variables

Subroutines and functions

subroutine  multistep_schemes/initialize(this, time_scheme, courfac_nml, intfac_nml, alffac_nml)

This subroutine allocates the arrays involved in the time advance of an IMEX multistep scheme.

Parameters:
  • this [real ]

  • time_scheme [character(len=72),inout]

  • courfac_nml [real ,in]

  • intfac_nml [real ,in]

  • alffac_nml [real ,in]

subroutine  multistep_schemes/finalize(this)

This subroutine deallocates the arrays involved in the time advance of an IMEX multistep scheme.

Parameters:

this [real ]

subroutine  multistep_schemes/set_weights(this, lmatnext)

This subroutine computes the weights involved in the time advance of an IMEX multistep scheme.

Parameters:
  • this [real ]

  • lmatnext [logical ,inout]

subroutine  multistep_schemes/set_dt_array(this, dt_new, dt_min, time, n_log_file, n_time_step, l_new_dtnext)

This subroutine adjusts the time step

Parameters:
  • this [real ]

  • dt_new [real ,in] :: New time step size

  • dt_min [real ,in] :: Minimum elligible time step before MagIC stops

  • time [real ,in] :: Time

  • n_log_file [integer ,inout]

  • n_time_step [integer ,in]

  • l_new_dtnext [logical ,in]

Call to:

abortrun()

subroutine  multistep_schemes/set_imex_rhs(this, rhs, dfdt)

This subroutine assembles the right-hand-side of an IMEX scheme

Parameters:
  • this [real ]

  • rhs (1 - dfdt%llm + dfdt%ulm,1 - dfdt%nrstart + dfdt%nrstop) [complex ,out]

  • dfdt [type_tarray ,in]

Call to:

get_openmp_blocks()

subroutine  multistep_schemes/set_imex_rhs_ghost(this, rhs, dfdt, start_lm, stop_lm, ng)

This subroutine assembles the right-hand-side of an IMEX scheme for R-distributed arrays (finite difference with parallel solvers).

Parameters:
  • this [real ]

  • rhs (1 - dfdt%llm + dfdt%ulm,1 - dfdt%nrstart + dfdt%nrstop + 2 * ng) [complex ,out]

  • dfdt [type_tarray ,in]

  • start_lm [integer ,in] :: Starting lm index

  • stop_lm [integer ,in] :: Stopping lm index

  • ng [integer ,in] :: Number of ghosts zones

subroutine  multistep_schemes/set_imex_rhs_scalar(this, rhs, dfdt)

This subroutine assembles the right-hand-side of an IMEX scheme

Parameters:
  • this [real ]

  • rhs [real ,out]

  • dfdt [type_tscalar ,in]

subroutine  multistep_schemes/rotate_imex(this, dfdt)

This subroutine is used to roll the time arrays from one time step

Parameters:
  • this [real ]

  • dfdt [type_tarray ,inout]

Call to:

get_openmp_blocks()

subroutine  multistep_schemes/rotate_imex_scalar(this, dfdt)

This subroutine is used to roll the time arrays from one time step

Parameters:
  • this [real ]

  • dfdt [type_tscalar ,inout]

subroutine  multistep_schemes/bridge_with_cnab2(this)

This subroutine is used to run the first bridging steps of an IMEX multistep scheme using a CN/AB2 scheme.

Parameters:

this [real ]

subroutine  multistep_schemes/start_with_ab1(this)

This subroutine is used to compute the first explicit iteration with an explicit Euler (AB1) scheme.

Parameters:

this [real ]

subroutine  multistep_schemes/get_time_stage(this, tlast, tstage)
Parameters:
  • this [real ]

  • tlast [real ,in]

  • tstage [real ,out]

subroutine  multistep_schemes/assemble_imex(this, rhs, dfdt)
Parameters:
  • this [real ]

  • rhs (1 - dfdt%llm + dfdt%ulm,1 - dfdt%nrstart + dfdt%nrstop) [complex ,out]

  • dfdt [type_tarray ,in]

subroutine  multistep_schemes/assemble_imex_scalar(this, rhs, dfdt)
Parameters:
  • this [real ]

  • rhs [real ,out]

  • dfdt [type_tscalar ,in]

dirk_schemes.f90

Description

This module defines the type_dirk which inherits from the abstract type_tscheme. It actually implements all the routine required to time-advance an diagonally implicit Runge-Kutta scheme. It makes use of Butcher tables to construct the right-hand-sides.

Quick access

Types:

type_dirk

Needed modules

Types

  • type  dirk_schemes/type_dirk
    Type fields:
    • % butcher_ass_exp (*) [real ,allocatable]

    • % butcher_ass_imp (*) [real ,allocatable]

    • % butcher_c (*) [real ,allocatable]

    • % butcher_exp (*,*) [real ,allocatable]

    • % butcher_imp (*,*) [real ,allocatable]

Variables

Subroutines and functions

subroutine  dirk_schemes/initialize(this, time_scheme, courfac_nml, intfac_nml, alffac_nml)
Parameters:
  • this [real ]

  • time_scheme [character(len=72),inout]

  • courfac_nml [real ,in]

  • intfac_nml [real ,in]

  • alffac_nml [real ,in]

subroutine  dirk_schemes/finalize(this)
Parameters:

this [real ]

subroutine  dirk_schemes/set_weights(this, lmatnext)
Parameters:
  • this [real ]

  • lmatnext [logical ,inout]

subroutine  dirk_schemes/set_dt_array(this, dt_new, dt_min, time, n_log_file, n_time_step, l_new_dtnext)

This subroutine adjusts the time step

Parameters:
  • this [real ]

  • dt_new [real ,in]

  • dt_min [real ,in]

  • time [real ,in]

  • n_log_file [integer ,inout]

  • n_time_step [integer ,in]

  • l_new_dtnext [logical ,in]

Call to:

abortrun()

subroutine  dirk_schemes/set_imex_rhs(this, rhs, dfdt)

This subroutine assembles the right-hand-side of an IMEX scheme

Parameters:
  • this [real ]

  • rhs (1 - dfdt%llm + dfdt%ulm,1 - dfdt%nrstart + dfdt%nrstop) [complex ,out]

  • dfdt [type_tarray ,in]

Call to:

get_openmp_blocks()

subroutine  dirk_schemes/set_imex_rhs_ghost(this, rhs, dfdt, start_lm, stop_lm, ng)

This subroutine assembles the right-hand-side of an IMEX scheme in case an array with ghosts zones is provided

Parameters:
  • this [real ]

  • rhs (1 - dfdt%llm + dfdt%ulm,1 - dfdt%nrstart + dfdt%nrstop + 2 * ng) [complex ,out]

  • dfdt [type_tarray ,in]

  • start_lm [integer ,in]

  • stop_lm [integer ,in]

  • ng [integer ,in]

subroutine  dirk_schemes/assemble_imex(this, rhs, dfdt)

This subroutine performs the assembly stage of an IMEX-RK scheme

Parameters:
  • this [real ]

  • rhs (1 - dfdt%llm + dfdt%ulm,1 - dfdt%nrstart + dfdt%nrstop) [complex ,out]

  • dfdt [type_tarray ,in]

Call to:

get_openmp_blocks()

subroutine  dirk_schemes/set_imex_rhs_scalar(this, rhs, dfdt)

This subroutine assembles the right-hand-side of an IMEX scheme

Parameters:
  • this [real ]

  • rhs [real ,out]

  • dfdt [type_tscalar ,in]

subroutine  dirk_schemes/assemble_imex_scalar(this, rhs, dfdt)

This subroutine performs the assembly stage of an IMEX-RK scheme for a scalar quantity

Parameters:
  • this [real ]

  • rhs [real ,out]

  • dfdt [type_tscalar ,in]

subroutine  dirk_schemes/rotate_imex(this, dfdt)

This subroutine is used to roll the time arrays from one time step

Parameters:
  • this [real ]

  • dfdt [type_tarray ,inout]

subroutine  dirk_schemes/rotate_imex_scalar(this, dfdt)

This subroutine is used to roll the time arrays from one time step

Parameters:
  • this [real ]

  • dfdt [type_tscalar ,inout]

subroutine  dirk_schemes/bridge_with_cnab2(this)
Parameters:

this [real ]

subroutine  dirk_schemes/start_with_ab1(this)
Parameters:

this [real ]

subroutine  dirk_schemes/get_time_stage(this, tlast, tstage)
Parameters:
  • this [real ]

  • tlast [real ,in]

  • tstage [real ,out]

time_array.f90

Description

This module defines two types that are defined to store the implicit/explicit terms at the different sub-stage/step.

Quick access

Types:

type_tarray, type_tscalar

Routines:

finalize_scalar(), initialize_scalar()

Needed modules

Types

  • type  time_array/type_tarray
    Type fields:
    • % expl (*,*,*) [complex ,pointer]

    • % impl (*,*,*) [complex ,allocatable]

    • % l_exp [logical ]

    • % llm [integer ]

    • % nrstart [integer ]

    • % nrstop [integer ]

    • % old (*,*,*) [complex ,allocatable]

    • % ulm [integer ]

  • type  time_array/type_tscalar
    Type fields:
    • % expl (*) [real ,allocatable]

    • % impl (*) [real ,allocatable]

    • % old (*) [real ,allocatable]

Variables

Subroutines and functions

subroutine  time_array/initialize(this, llm, ulm, nrstart, nrstop, nold, nexp, nimp[, l_allocate_exp])

Memory allocation of the arrays and initial values set to zero

Parameters:
  • this [real ]

  • llm [integer ,in]

  • ulm [integer ,in]

  • nrstart [integer ,in]

  • nrstop [integer ,in]

  • nold [integer ,in]

  • nexp [integer ,in]

  • nimp [integer ,in]

Options:

l_allocate_exp [logical ,in,]

subroutine  time_array/finalize(this)

Memory deallocation

Parameters:

this [real ]

subroutine  time_array/initialize_scalar(this, nold, nexp, nimp)

This routine initializes time stepper help arrays in case of a scalar

Parameters:
  • this [real ]

  • nold [integer ,in] :: Number of old states

  • nexp [integer ,in] :: Number of explicit states

  • nimp [integer ,in] :: Number of implicit states

subroutine  time_array/finalize_scalar(this)

Memory deallocation

Parameters:

this [real ]