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:
- 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.
- 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
- 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')
...
where INTEGER_A and INTEGER_B are different integers given by enumerators that you have to initialize in prec_const.F90.
- Namelist is read (nothing to add here)
...
READ(lu_input, NML=nml)
...
- [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
...
Most of the operators have been overloaded in order to manipulate derived types as if they were just corresponding intrisic types.
- 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