Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion applications/io_demo/example/configuration.nml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ coord_system='native'
/

&logging
run_log_level='info'
run_log_level='trace'
/

&time
Expand Down
6 changes: 5 additions & 1 deletion applications/io_demo/example/iodef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
time_counter="none">

<file id="lfric_diag" name="diffusion_diag" output_freq="1ts" convention="UGRID" enabled=".TRUE.">
<field field_ref="diffusion_field" />
<field field_ref="diffusion_field_Wth" />
<field field_ref="diffusion_field_W0" />
<field field_ref="diffusion_field_W2H" />
<field field_ref="diffusion_field_W2V" />
<field field_ref="diffusion_field_W3" />
</file>

</file_definition>
Expand Down
6 changes: 5 additions & 1 deletion applications/io_demo/metadata/field_dictionary.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<field_definition>
<field_group id="io_demo_fields" prec="8" operation="instant">
<field id="diffusion_field" name="diffusion_field" long_name="diffusion_field" unit="1" grid_ref="full_level_face_grid" />
<field id="diffusion_field_Wth" name="diffusion_field_Wth" long_name="diffusion_field_Wth" unit="1" grid_ref="full_level_face_grid" />
<field id="diffusion_field_W0" name="diffusion_field_W0" long_name="diffusion_field_W0" unit="1" grid_ref="node_grid" />
<field id="diffusion_field_W2H" name="diffusion_field_W2H" long_name="diffusion_field_W2H" unit="1" grid_ref="half_level_edge_grid" />
<field id="diffusion_field_W2V" name="diffusion_field_W2V" long_name="diffusion_field_W2V" unit="1" grid_ref="full_level_face_grid" />
<field id="diffusion_field_W3" name="diffusion_field_W3" long_name="diffusion_field_W3" unit="1" grid_ref="half_level_face_grid" />
</field_group>
</field_definiton>
69 changes: 50 additions & 19 deletions applications/io_demo/source/algorithm/io_demo_alg_mod.x90
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ module io_demo_alg_mod
use mesh_mod, only: mesh_type

use field_mod, only: field_type
use fs_continuity_mod, only: Wtheta
use field_collection_mod, only: field_collection_type
use fs_continuity_mod, only: Wtheta, W0, W2, W3
use function_space_collection_mod, only: function_space_collection
use function_space_mod, only: function_space_type
use operator_mod, only: operator_type
use matrix_vector_kernel_mod, only: matrix_vector_kernel_type
use io_demo_constants_mod, only: get_dx_at_w2
use tracer_tutorial_diff_kernel_mod, only: tracer_tutorial_diff_kernel_type
use sci_sample_wtheta_to_w3_kernel_mod, only: sample_wtheta_to_w3_kernel_type
use sci_wth_to_w0_average_kernel_mod, only: wth_to_w0_average_kernel_type
use sci_w3_to_w2_average_kernel_mod, only: w3_to_w2_average_kernel_type
use sci_multiplicity_kernel_mod, only: multiplicity_kernel_type
use sci_field_minmax_alg_mod, only: log_field_minmax

implicit none
Expand All @@ -34,28 +39,30 @@ contains

!> @details Calculates the diffusion increment for a field, and adds it to said field.
!> @param[in] modeldb Application state object
!> @param[inout] field_in Input Wtheta field
!> @param[inout] depository Collection of core IO_demo fields
!> @param[in] visc_in Optional setting for viscosity value
subroutine io_demo_alg( modeldb, field_in, visc_in )
subroutine io_demo_alg( modeldb, depository, visc_in )

implicit none

type(modeldb_type), intent(in) :: modeldb

! Prognostic fields
type( field_type ), intent( inout ) :: field_in
real(r_def), optional, intent( in ) :: visc_in
type( field_collection_type ), intent(inout) :: depository
real(r_def), optional, intent(in) :: visc_in

! Diagnostic fields
type( field_type ) :: dfield_in
type( field_type ), pointer :: field_W0, field_W2, field_W3, field_Wth
type( field_type ) :: dfield_Wth
type( field_type ) :: rmul_w2, rmul_w0
type( field_type ) :: visc

real(r_def) :: visc_val
integer(kind=i_def), parameter :: stencil_depth = 1_i_def

type(mesh_type), pointer :: mesh
type(field_type), pointer :: dx_at_w2
type(function_space_type), pointer :: fs
type(function_space_type), pointer :: fs_wth, fs_w0, fs_w2, fs_w3

integer(i_def) :: order_h, order_v
! Set viscosity to default value if not present
Expand All @@ -67,34 +74,58 @@ contains

call log_event( "io_demo: Running algorithm", LOG_LEVEL_TRACE )

call depository%get_field("diffusion_field_Wtheta", field_Wth)
call depository%get_field("diffusion_field_W0", field_W0)
call depository%get_field("diffusion_field_W2", field_W2)
call depository%get_field("diffusion_field_W3", field_W3)

order_h = modeldb%config%finite_element%element_order_h()
order_v = modeldb%config%finite_element%element_order_v()

mesh => field_in%get_mesh()
mesh => field_Wth%get_mesh()
dx_at_w2 => get_dx_at_w2(mesh)

fs => function_space_collection%get_fs(mesh, order_h, order_v, Wtheta)
fs_wth => function_space_collection%get_fs(mesh, order_h, order_v, Wtheta)
fs_w0 => function_space_collection%get_fs(mesh, order_h, order_v, W0)
fs_w2 => function_space_collection%get_fs(mesh, order_h, order_v, W2)

call dfield_in%initialise(fs)
call visc%initialise(fs)
call dfield_Wth%initialise(fs_wth)
call visc%initialise(fs_wth)
call rmul_w2%initialise(fs_w2)
call rmul_w0%initialise(fs_w0)

call invoke( name = "compute_diffusion", &
setval_c(visc, visc_val), &
setval_c(dfield_in, 0.0_r_def), &
tracer_tutorial_diff_kernel_type(dfield_in, &
field_in, &
setval_c(dfield_Wth, 0.0_r_def), &
tracer_tutorial_diff_kernel_type(dfield_Wth, &
field_Wth, &
stencil_depth, &
visc, &
dx_at_w2) )

! Printing the min/max values in field_in and dfield_in
call log_field_minmax( LOG_LEVEL_INFO, 'dfield_in', dfield_in )
call log_field_minmax( LOG_LEVEL_INFO, 'field_in', field_in )
! Printing the min/max values in field_Wth and dfield_Wth
call log_field_minmax( LOG_LEVEL_INFO, 'dfield_Wth', dfield_Wth )

! Increment Wtheta field
call invoke(inc_X_plus_Y( field_Wth, dfield_Wth ))

! Sample diffusion field onto other function spaces
call invoke( name = "sample_diffusion_on_all_fs", &
setval_c(rmul_w2, 1.0_r_def), &
setval_c(rmul_w0, 1.0_r_def), &
sample_wtheta_to_w3_kernel_type(field_W3, field_Wth), &
wth_to_w0_average_kernel_type(field_W0, field_Wth, rmul_w0), &
w3_to_w2_average_kernel_type(field_W2, field_W3, rmul_w2) )

! Incrementing field
call invoke( inc_X_plus_Y( field_in, dfield_in ) )
call log_field_minmax( LOG_LEVEL_INFO, 'field_Wth', field_Wth )
call log_field_minmax( LOG_LEVEL_INFO, 'field_W0', field_W0 )
call log_field_minmax( LOG_LEVEL_INFO, 'field_W2', field_W2 )
call log_field_minmax( LOG_LEVEL_INFO, 'field_W3', field_W3 )

nullify(mesh)
nullify(dx_at_w2)
nullify(field_Wth, field_W0, field_W2, field_W3)
nullify(fs_wth, fs_w0, fs_w2, fs_w3)

call log_event( "io_demo: finished algorithm", LOG_LEVEL_TRACE )

Expand Down
37 changes: 20 additions & 17 deletions applications/io_demo/source/driver/init_io_demo_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module init_io_demo_mod
use field_parent_mod, only : write_interface
use function_space_collection_mod, only : function_space_collection
use function_space_mod, only : function_space_type
use fs_continuity_mod, only : Wtheta
use fs_continuity_mod, only : W0, W2, W3, Wtheta, &
name_from_functionspace
use key_value_mod, only : abstract_value_type
use log_mod, only : log_event, &
LOG_LEVEL_TRACE, &
Expand Down Expand Up @@ -51,17 +52,19 @@ subroutine init_io_demo(modeldb, mesh, chi, panel_id)

class(abstract_value_type), pointer :: abstract_value
type(random_number_generator_type), pointer :: rng
type(field_type) :: diffusion_field
type(field_type), allocatable :: io_demo_fields(:)
type(field_collection_type), pointer :: depository
procedure(write_interface), pointer :: tmp_ptr
real(kind=r_def), parameter :: min_val = 280.0_r_def
real(kind=r_def), parameter :: max_val = 330.0_r_def

type(function_space_type), pointer :: fs

integer(i_def) :: order_h, order_v
integer(i_def) :: order_h, order_v, i
integer(i_def) :: fs_list(4) = [W0, W2, W3, Wtheta]
logical(l_def) :: write_diag
logical(l_def) :: use_xios_io
character(len=:), allocatable :: domain_fs_name

call log_event( 'io_demo: Initialising miniapp ...', LOG_LEVEL_TRACE )

Expand All @@ -84,24 +87,24 @@ subroutine init_io_demo(modeldb, mesh, chi, panel_id)
end select
call rng%check_seed()

! Create prognostic fields
! Creates a field in the Wtheta function space
fs => function_space_collection%get_fs(mesh, order_h, order_v, Wtheta)
call diffusion_field%initialise(fs, name="diffusion_field")
depository => modeldb%fields%get_field_collection("depository")

! Set up field with an IO behaviour (XIOS only at present)
if (write_diag .and. use_xios_io) then
tmp_ptr => write_field_generic
call diffusion_field%set_write_behaviour(tmp_ptr)
end if
! Create prognostic fields
! Creates fields for all common function spaces
allocate(io_demo_fields(size(fs_list)))
do i = 1, size(fs_list)
fs => function_space_collection%get_fs(mesh, order_h, order_v, fs_list(i))
domain_fs_name = name_from_functionspace(fs_list(i))
call io_demo_fields(i)%initialise(fs, name="diffusion_field_"//trim(domain_fs_name))

! Add field to modeldb
depository => modeldb%fields%get_field_collection("depository")
tmp_ptr => write_field_generic
call io_demo_fields(i)%set_write_behaviour(tmp_ptr)

! Initialising field
call assign_field_random_range( diffusion_field, min_val, max_val )
! Initialising field
call assign_field_random_range( io_demo_fields(i), min_val, max_val )
call depository%add_field(io_demo_fields(i))

call depository%add_field(diffusion_field)
end do

! Create io_demo runtime constants. This creates various things
! needed by the fem algorithms such as mass matrix operators, mass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contains
type(field_collection_iterator_type) :: field_iter
class(field_parent_type), pointer :: step_field
type(field_type), pointer :: kernel_field
type(field_type), pointer :: diffusion_field
type(field_type), pointer :: diffusion_field_Wth

integer(i_def) :: i, sleep_duration
real(r_def) :: loop_factor
Expand All @@ -51,7 +51,7 @@ contains
! Get field data ready
depository => modeldb%fields%get_field_collection("depository")
io_benchmark_fields => modeldb%fields%get_field_collection("io_benchmark_fields")
call depository%get_field("diffusion_field", diffusion_field)
call depository%get_field("diffusion_field_Wtheta", diffusion_field_Wth)

call field_iter%initialise(io_benchmark_fields)
do i = 1, io_benchmark_fields%get_length()
Expand All @@ -62,7 +62,7 @@ contains
! Copy diffusion field values to new fields and adjust values
kernel_field => step_field
loop_factor = real(i, r_def)
call invoke( setval_X(kernel_field, diffusion_field), &
call invoke( setval_X(kernel_field, diffusion_field_Wth), &
inc_X_divideby_a(kernel_field, loop_factor) )
end select

Expand All @@ -74,7 +74,7 @@ contains

nullify(step_field)
nullify(kernel_field)
nullify(diffusion_field)
nullify(diffusion_field_Wth)

end subroutine step_io_benchmark

Expand Down
Loading