ORB5  v4.9.4
Inputs

Inputs' operating principle, naming convention and instructions to add a new input.

Author
N. Ohana
Date
10/2017

Introduction

From version 2.0 of ORB5, an interface was introduced in between input parameters and variables stored in globals.F90. The motivation was to perform input consistency checks before storing their values, and to centralize input data at a single place to facilitate legibility and future development.

In this goal, the module derived_inputs implements derived data types gathering an input name, its description, and its default value.

Implemented derived input types are:

  • Real
  • Real array
  • Integer
  • Integer array
  • Integer of 8 bytes (for input with absolute values possibly greater than 2 147 483 647)
  • Logical
  • String
  • Selector (input string casted into one of some predefined integer values)

Naming convention

  • Logical inputs must start with nl_.
  • Selector inputs must start with nsel_.
  • Other types of input are free.

How to add a new input

Here are the steps to follow to add a new input to the code:

  1. Add a variable to one of the data structures in globals.F90:
    TYPE nml_variables
    ...
    REAL :: new_input
    ...
    END TYPE nml_variables
    TYPE(nml_variables) :: nml
    Those data structures map the input namelists.
  2. Add a derived type in readinput.F90:
    SUBROUTINE read_nml
    USE globals, ONLY: globals_nml=>nml
    TYPE(input_real) :: new_input
    NAMELIST /nml/ new_input
    ...
    Definition: globals.F90:1
  3. Initialize the derived type:
    ...
    CALL new_input%init('new_input', 'New input description', default_value)
    ...
    subroutine, public init(pos, np, np_new, npmax, run_on_device)
    Prepare the communications (who will send what where)
    Definition: parmove.F90:117
    The first argument is the literal name of the variable.
    Selectors are initialized as follows:
    ...
    CALL nsel_new_input%init('nsel_new_input', 'Selector description')
    CALL nsel_new_input%add_option('A', INTEGER_A, 'Option A description')
    CALL nsel_new_input%add_option('B', INTEGER_B, 'Option B description')
    ...
    subroutine add_option(this, input_key, key, key_desc, by_default)
    Add an option to the selector.
    Definition: derived_inputs.F90:780
    where INTEGER_A and INTEGER_B are different integers given by enumerators that you have to initialize in prec_const.F90.
  4. Namelist is read (nothing to add here)
    ...
    READ(lu_input, NML=nml)
    ...
  5. [optional] Perform consistency check
    ...
    IF(new_input < 0) THEN
    new_input = 0
    CALL warning('new_input must be positive, set it to 0', nwarnings)
    END IF
    ...
    subroutine warning(msg, counter)
    Print warning message and increment counter.
    Definition: readinput.F90:2181
    Most of the operators have been overloaded in order to manipulate derived types as if they were just corresponding intrisic types.
  6. Export the value to the globals variable:
    ...
    CALL new_input%apply_to('/parameters/nml/', globals_nml%new_input)
    ...
    END SUBROUTINE read_nml
    This is the place where the input value is exported to the code, and at the same time writen into the HDF5 file and displayed on screen.
See also
readinput
derived_inputs