Skip to content

Commit 043ce64

Browse files
mo-rickywongMatthewHambleyallynt
authored
Reworked Configuration Namelist Access API (#175)
Co-authored-by: Matthew Hambley <MatthewHambley@users.noreply.github.com> Co-authored-by: Allyn Treshansky <allyn.treshansky@metoffice.gov.uk>
1 parent 804d72a commit 043ce64

144 files changed

Lines changed: 4370 additions & 1330 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTORS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Contributors
2+
3+
=======
24
| GitHub user | Real Name | Affiliation | Date |
35
| ---------------- | ----------------- | ----------- | ---------- |
46
| andrewcoughtrie | Andrew Coughtrie | Met Office | 2025.12.12 |
57
| james-bruten-mo | James Bruten | Met Office | 2025-12-09 |
68
| jedbakerMO | Jed Baker | Met Office | 2025-12-29 |
79
| jennyhickson | Jenny Hickson | Met Office | 2025-12-10 |
810
| mo-marqh | Mark Hedley | Met Office | 2025-12-11 |
11+
| mo-rickywong | Ricky Wong | Met Office | 2025-01-30 |
912
| mike-hobson | Mike Hobson | Met Office | 2025-12-17 |
1013
| MatthewHambley | Matthew Hambley | Met Office | 2025-12-15 |
1114
| tommbendall | Thomas Bendall | Met Office | 2026-01-23 |

applications/coupled/source/coupled.f90

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ program coupled
4343
call modeldb%values%initialise( 'values', 5 )
4444

4545
call modeldb%configuration%initialise( program_name, table_len=10 )
46+
call modeldb%config%initialise( program_name )
4647

4748
write(log_scratch_space,'(A)') &
4849
'Application built with '// trim(precision_real) // &
@@ -53,8 +54,12 @@ program coupled
5354

5455
call modeldb%values%add_key_value('cpl_name', cpl_component_name)
5556
call init_comm( "coupled", modeldb )
56-
call init_config( filename, coupled_required_namelists, &
57-
modeldb%configuration )
57+
58+
call init_config( filename, &
59+
coupled_required_namelists, &
60+
configuration=modeldb%configuration, &
61+
config=modeldb%config )
62+
5863
call init_logger( modeldb%mpi%get_comm(), &
5964
program_name//"_"//cpl_component_name )
6065
call init_collections()

applications/coupled/source/driver/coupled_driver_mod.f90

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module coupled_driver_mod
3232
LOG_LEVEL_INFO
3333
use mesh_mod, only : mesh_type
3434
use mesh_collection_mod, only : mesh_collection
35-
use namelist_mod, only : namelist_type
35+
3636
use sci_checksum_alg_mod, only : checksum_alg
3737

3838
implicit none
@@ -69,10 +69,6 @@ subroutine initialise( program_name, modeldb, calendar )
6969
class(extrusion_type), allocatable :: extrusion
7070
type(uniform_extrusion_type), allocatable :: extrusion_2d
7171

72-
type(namelist_type), pointer :: base_mesh_nml
73-
type(namelist_type), pointer :: planet_nml
74-
type(namelist_type), pointer :: extrusion_nml
75-
7672
character(str_def) :: prime_mesh_name
7773

7874
integer(i_def) :: stencil_depth
@@ -89,18 +85,12 @@ subroutine initialise( program_name, modeldb, calendar )
8985

9086

9187
! Extract namelist variables
92-
base_mesh_nml => modeldb%configuration%get_namelist('base_mesh')
93-
planet_nml => modeldb%configuration%get_namelist('planet')
94-
extrusion_nml => modeldb%configuration%get_namelist('extrusion')
95-
call base_mesh_nml%get_value( 'prime_mesh_name', prime_mesh_name )
96-
call base_mesh_nml%get_value( 'geometry', geometry )
97-
call extrusion_nml%get_value( 'method', method )
98-
call extrusion_nml%get_value( 'domain_height', domain_height )
99-
call extrusion_nml%get_value( 'number_of_layers', number_of_layers )
100-
call planet_nml%get_value( 'scaled_radius', scaled_radius )
101-
base_mesh_nml => null()
102-
planet_nml => null()
103-
extrusion_nml => null()
88+
prime_mesh_name = modeldb%config%base_mesh%prime_mesh_name()
89+
geometry = modeldb%config%base_mesh%geometry()
90+
method = modeldb%config%extrusion%method()
91+
domain_height = modeldb%config%extrusion%domain_height()
92+
number_of_layers = modeldb%config%extrusion%number_of_layers()
93+
scaled_radius = modeldb%config%planet%scaled_radius()
10494

10595
! Initialise mesh
10696
! Determine the required meshes
@@ -118,7 +108,7 @@ subroutine initialise( program_name, modeldb, calendar )
118108
LOG_LEVEL_ERROR)
119109
end select
120110
allocate( extrusion, source=create_extrusion( method, &
121-
domain_height, &
111+
domain_height, &
122112
domain_bottom, &
123113
number_of_layers, &
124114
PRIME_EXTRUSION ) )

applications/coupled/source/driver/init_coupled_mod.X90

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ module init_coupled_mod
2121
use field_collection_mod, only : field_collection_type
2222
use field_mod, only : field_type
2323
use field_parent_mod, only : write_interface
24-
use finite_element_config_mod, only : element_order_h, element_order_v
2524
use function_space_collection_mod, only : function_space_collection
25+
use function_space_mod, only : function_space_type
2626
use fs_continuity_mod, only : W3
2727
use log_mod, only : log_event, &
2828
LOG_LEVEL_INFO, &
@@ -40,11 +40,12 @@ module init_coupled_mod
4040
!> @param[in,out] chi The co-ordinate field
4141
!> @param[in,out] panel_id 2d field giving the id for cubed sphere panels
4242
!> @param[in,out] modeldb The structure that holds model state
43-
subroutine init_coupled( mesh, chi, panel_id, modeldb)
43+
subroutine init_coupled(mesh, chi, panel_id, modeldb)
4444

4545
implicit none
4646

4747
type(mesh_type), intent(in), pointer :: mesh
48+
4849
! Coordinate field
4950
type( field_type ), intent(inout) :: chi(:)
5051
type( field_type ), intent(inout) :: panel_id
@@ -74,19 +75,23 @@ module init_coupled_mod
7475

7576
procedure(write_interface), pointer :: tmp_ptr
7677

78+
integer(i_def) :: order_h, order_v
79+
type(function_space_type), pointer :: fs
80+
7781
call log_event( 'coupled: Initialising app ...', LOG_LEVEL_INFO )
7882

7983
! Get the name of the coupling component
8084
call modeldb%values%get_value("cpl_name", cpl_component_name)
8185

86+
order_h = modeldb%config%finite_element%element_order_h()
87+
order_v = modeldb%config%finite_element%element_order_v()
88+
89+
fs => function_space_collection%get_fs(mesh, order_h, order_v, W3)
90+
8291
! Create prognostic fields
8392
! Creates a field in the W3 function space (fully discontinuous field)
84-
call field_1%initialise( vector_space = &
85-
function_space_collection%get_fs(mesh, element_order_h, element_order_v, W3), &
86-
name="field_1")
87-
call field_2%initialise( vector_space = &
88-
function_space_collection%get_fs(mesh, element_order_h, element_order_v, W3), &
89-
name="field_2")
93+
call field_1%initialise(fs, name="field_1")
94+
call field_2%initialise(fs, name="field_2")
9095

9196
! Add field to modeldb
9297
depository => modeldb%fields%get_field_collection("depository")

applications/io_demo/source/algorithm/io_demo_alg_mod.x90

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66

77
!>@brief Module containing io_demo_alg
88
module io_demo_alg_mod
9+
910
use constants_mod, only: i_def,r_def
11+
use driver_modeldb_mod, only: modeldb_type
1012
use log_mod, only: log_event, &
1113
LOG_LEVEL_INFO, &
1214
LOG_LEVEL_TRACE
1315
use mesh_mod, only: mesh_type
16+
1417
use field_mod, only: field_type
15-
use finite_element_config_mod, only: element_order_h, &
16-
element_order_v
17-
use fs_continuity_mod, only: Wtheta, W2
18+
use fs_continuity_mod, only: Wtheta
1819
use function_space_collection_mod, only: function_space_collection
20+
use function_space_mod, only: function_space_type
1921
use operator_mod, only: operator_type
2022
use matrix_vector_kernel_mod, only: matrix_vector_kernel_type
2123
use io_demo_constants_mod, only: get_dx_at_w2
@@ -31,11 +33,14 @@ module io_demo_alg_mod
3133
contains
3234

3335
!> @details Calculates the diffusion increment for a field, and adds it to said field.
36+
!> @param[in] modeldb Application state object
3437
!> @param[inout] field_in Input Wtheta field
35-
subroutine io_demo_alg( field_in )
38+
subroutine io_demo_alg( modeldb, field_in )
3639

3740
implicit none
3841

42+
type(modeldb_type), intent(in) :: modeldb
43+
3944
! Prognostic fields
4045
type( field_type ), intent( inout ) :: field_in
4146

@@ -44,20 +49,27 @@ contains
4449
type( field_type ) :: visc
4550

4651
real(r_def), parameter :: visc_val = 100000.0_r_def
47-
type(mesh_type), pointer :: mesh => null()
4852
integer(kind=i_def), parameter :: stencil_depth = 1_i_def
49-
type( field_type ), pointer :: dx_at_w2 => null()
5053

54+
type(mesh_type), pointer :: mesh
55+
type(field_type), pointer :: dx_at_w2
56+
type(function_space_type), pointer :: fs
57+
58+
integer(i_def) :: order_h, order_v
5159

5260
call log_event( "io_demo: Running algorithm", LOG_LEVEL_TRACE )
53-
mesh => field_in%get_mesh()
61+
62+
order_h = modeldb%config%finite_element%element_order_h()
63+
order_v = modeldb%config%finite_element%element_order_v()
64+
65+
mesh => field_in%get_mesh()
5466
dx_at_w2 => get_dx_at_w2(mesh)
55-
call dfield_in%initialise( &
56-
function_space_collection%get_fs( mesh, element_order_h, &
57-
element_order_v, Wtheta))
58-
call visc%initialise( &
59-
function_space_collection%get_fs( mesh, element_order_h, &
60-
element_order_v, Wtheta))
67+
68+
fs => function_space_collection%get_fs(mesh, order_h, order_v, Wtheta)
69+
70+
call dfield_in%initialise(fs)
71+
call visc%initialise(fs)
72+
6173
call invoke( name = "compute_diffusion", &
6274
setval_c(visc, visc_val), &
6375
setval_c(dfield_in, 0.0_r_def), &

applications/io_demo/source/algorithm/io_demo_constants_mod.x90

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
module io_demo_constants_mod
1616

1717
! Infrastructure
18-
use constants_mod, only: i_def, r_def, &
18+
use constants_mod, only: i_def, r_def, l_def, &
1919
str_def, str_short
20+
use driver_modeldb_mod, only: modeldb_type
2021
use field_collection_mod, only: field_collection_type
2122
use field_mod, only: field_type
2223
use fs_continuity_mod, only: W2
@@ -29,16 +30,16 @@ module io_demo_constants_mod
2930
tik, LPROF
3031

3132
! Kernels
32-
use sci_calc_dA_at_w2_kernel_mod, only: calc_dA_at_w2_kernel_type
33-
use sci_calc_detj_at_w2_kernel_mod, only: calc_detj_at_w2_kernel_type
34-
use sci_multiplicity_kernel_mod, only: multiplicity_kernel_type
33+
use sci_calc_dA_at_w2_kernel_mod, only: calc_dA_at_w2_kernel_type
34+
use sci_calc_detj_at_w2_kernel_mod, only: calc_detj_at_w2_kernel_type
35+
use sci_multiplicity_kernel_mod, only: multiplicity_kernel_type
3536

3637
implicit none
3738

3839
private
3940

4041
! Objects for dx_at_w2 functionality
41-
type(field_collection_type) :: dx_at_w2_collection
42+
type(field_collection_type) :: dx_at_w2_collection
4243

4344
private :: add_dx_at_w2
4445

@@ -48,22 +49,24 @@ module io_demo_constants_mod
4849
contains
4950

5051
!> @brief Subroutine to create the finite element constants
52+
!> @param[in] modeldb Application state object
5153
!> @param[in] mesh The prime model mesh
5254
!> @param[in] chi Coordinate fields
5355
!> @param[in] panel_id Panel_id field
54-
subroutine create_io_demo_constants(mesh, &
55-
chi, &
56-
panel_id )
56+
subroutine create_io_demo_constants(modeldb, mesh, chi, panel_id)
5757

5858
implicit none
5959

6060
! Arguments
61-
type(mesh_type), pointer, intent(in) :: mesh
62-
type(field_type), target, intent(in) :: chi(:)
63-
type(field_type), target, intent(in) :: panel_id
64-
integer(tik) :: id
61+
type(modeldb_type), intent(in) :: modeldb
62+
type(mesh_type), pointer, intent(in) :: mesh
63+
type(field_type), target, intent(in) :: chi(:)
64+
type(field_type), target, intent(in) :: panel_id
65+
66+
integer(tik) :: id
6567

6668
if ( LPROF ) call start_timing( id, 'io_demo_constants_alg' )
69+
6770
call log_event( "io_demo: creating runtime constants", LOG_LEVEL_TRACE )
6871

6972
!============================= dx_at_w2 setup =============================!

applications/io_demo/source/driver/init_io_demo_mod.F90

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@
1212
module init_io_demo_mod
1313

1414
use sci_assign_field_random_range_alg_mod, only: assign_field_random_range
15-
use constants_mod, only : i_def, r_def
15+
use constants_mod, only : i_def, r_def, l_def
1616
use driver_modeldb_mod, only : modeldb_type
1717
use field_collection_mod, only : field_collection_type
1818
use field_mod, only : field_type
1919
use field_parent_mod, only : write_interface
20-
use finite_element_config_mod, only : element_order_h, &
21-
element_order_v
2220
use function_space_collection_mod, only : function_space_collection
21+
use function_space_mod, only : function_space_type
2322
use fs_continuity_mod, only : Wtheta
2423
use key_value_mod, only : abstract_value_type
2524
use log_mod, only : log_event, &
2625
LOG_LEVEL_TRACE, &
2726
LOG_LEVEL_ERROR
2827
use mesh_mod, only : mesh_type
29-
use io_config_mod, only : write_diag, &
30-
use_xios_io
3128
use lfric_xios_write_mod, only : write_field_generic
3229
use io_demo_constants_mod, only : create_io_demo_constants
3330
use random_number_generator_mod, only : random_number_generator_type
@@ -37,20 +34,21 @@ module init_io_demo_mod
3734
contains
3835

3936
!> @details Initialises everything needed to run the io_demo miniapp
37+
!> @param[in,out] modeldb The structure that holds model state
4038
!> @param[in] mesh Representation of the mesh the code will run on
4139
!> @param[in,out] chi The co-ordinate field
4240
!> @param[in,out] panel_id 2d field giving the id for cubed sphere panels
43-
!> @param[in,out] modeldb The structure that holds model state
44-
subroutine init_io_demo( mesh, chi, panel_id, modeldb)
41+
subroutine init_io_demo(modeldb, mesh, chi, panel_id)
4542

4643
implicit none
4744

48-
type(mesh_type), intent(in), pointer :: mesh
45+
type(modeldb_type), intent(inout) :: modeldb
46+
type(mesh_type), intent(in), pointer :: mesh
4947

5048
! Coordinate field
51-
type(field_type), intent(inout) :: chi(:)
52-
type(field_type), intent(inout) :: panel_id
53-
type(modeldb_type), intent(inout) :: modeldb
49+
type(field_type), intent(inout) :: chi(:)
50+
type(field_type), intent(inout) :: panel_id
51+
5452
class(abstract_value_type), pointer :: abstract_value
5553
type(random_number_generator_type), pointer :: rng
5654
type(field_type) :: diffusion_field
@@ -59,8 +57,20 @@ subroutine init_io_demo( mesh, chi, panel_id, modeldb)
5957
real(kind=r_def), parameter :: min_val = 280.0_r_def
6058
real(kind=r_def), parameter :: max_val = 330.0_r_def
6159

60+
type(function_space_type), pointer :: fs
61+
62+
integer(i_def) :: order_h, order_v
63+
logical(l_def) :: write_diag
64+
logical(l_def) :: use_xios_io
65+
6266
call log_event( 'io_demo: Initialising miniapp ...', LOG_LEVEL_TRACE )
6367

68+
order_h = modeldb%config%finite_element%element_order_h()
69+
order_v = modeldb%config%finite_element%element_order_v()
70+
71+
write_diag = modeldb%config%io%write_diag()
72+
use_xios_io = modeldb%config%io%use_xios_io()
73+
6474
! seed the random number generator
6575
call modeldb%values%get_value("rng", abstract_value)
6676
select type(abstract_value)
@@ -76,10 +86,8 @@ subroutine init_io_demo( mesh, chi, panel_id, modeldb)
7686

7787
! Create prognostic fields
7888
! Creates a field in the Wtheta function space
79-
call diffusion_field%initialise( vector_space = &
80-
function_space_collection%get_fs(mesh, element_order_h, &
81-
element_order_v, Wtheta), &
82-
name="diffusion_field")
89+
fs => function_space_collection%get_fs(mesh, order_h, order_v, Wtheta)
90+
call diffusion_field%initialise(fs, name="diffusion_field")
8391

8492
! Set up field with an IO behaviour (XIOS only at present)
8593
if (write_diag .and. use_xios_io) then
@@ -98,7 +106,7 @@ subroutine init_io_demo( mesh, chi, panel_id, modeldb)
98106
! Create io_demo runtime constants. This creates various things
99107
! needed by the fem algorithms such as mass matrix operators, mass
100108
! matrix diagonal fields and the geopotential field
101-
call create_io_demo_constants(mesh, chi, panel_id)
109+
call create_io_demo_constants(modeldb, mesh, chi, panel_id)
102110

103111
call log_event( 'io_demo: Miniapp initialised', LOG_LEVEL_TRACE )
104112

0 commit comments

Comments
 (0)