Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IO prototype for History (and checkpoint) #2814

Merged
merged 20 commits into from
May 14, 2024
Merged
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ add_subdirectory (MAPL)
add_subdirectory (mapl3g)
add_subdirectory (gridcomps)
add_subdirectory (griddedio)
add_subdirectory (GeomIO)
if (BUILD_WITH_FARGPARSE)
add_subdirectory (docs)
add_subdirectory (benchmarks)
Expand Down
24 changes: 24 additions & 0 deletions GeomIO/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
esma_set_this (OVERRIDE MAPL.GeomIO)

set(srcs
GeomIO.F90 # package
SharedIO.F90
Geom_PFIO.F90
Grid_PFIO.F90
GeomCatagorizer.F90
)

esma_add_library(${this}
SRCS ${srcs}
DEPENDENCIES MAPL.geom_mgr MAPL.pfio MAPL.base MAPL.shared MAPL.hconfig_utils GFTL::gftl-v2
TYPE ${MAPL_LIBRARY_TYPE}
)

target_include_directories (${this} PUBLIC
$<BUILD_INTERFACE:${MAPL_SOURCE_DIR}/include>)
target_link_libraries (${this} PUBLIC ESMF::ESMF)

#if (PFUNIT_FOUND)
#add_subdirectory(tests EXCLUDE_FROM_ALL)
#endif ()

27 changes: 27 additions & 0 deletions GeomIO/GeomCatagorizer.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "MAPL_Generic.h"

module mapl3g_GeomCatagorizer
use mapl_ErrorHandling
use mapl3g_GridPFIO
use mapl3g_GeomPFIO
use pfio

implicit none
private

public make_geom_pfio

contains

function make_geom_pfio(metadata, rc) result(geom_pfio)
class(GeomPFIO), allocatable :: geom_pfio
type(FileMetadata), intent(in) :: metadata
integer, intent(out), optional :: rc

type(GridPFIO) :: grid_pfio

allocate(geom_pfio, source=grid_pfio)
_RETURN(_SUCCESS)
end function make_geom_pfio

end module mapl3g_GeomCatagorizer
8 changes: 8 additions & 0 deletions GeomIO/GeomIO.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module mapl3g_geomio

use mapl3g_GeomCatagorizer
use mapl3g_GeomPFIO
use mapl3g_sharedIO
implicit none

end module mapl3g_geomio
92 changes: 92 additions & 0 deletions GeomIO/Geom_PFIO.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include "MAPL_Generic.h"

module mapl3g_GeomPFIO
use mapl_ErrorHandling
use ESMF
use PFIO
use mapl3g_geom_mgr
use mapl3g_SharedIO
implicit none
private

public :: GeomPFIO
type, abstract :: GeomPFIO
private
integer :: collection_id
bena-nasa marked this conversation as resolved.
Show resolved Hide resolved
type(MaplGeom), pointer :: mapl_geom
contains
procedure(I_stage_data_to_file), deferred :: stage_data_to_file
procedure :: initialize
procedure :: update_time_on_server
procedure :: stage_time_to_file
procedure, non_overridable :: get_collection_id

end type GeomPFIO

abstract interface

subroutine I_stage_data_to_file(this, bundle, filename, time_index, rc)
use esmf
import GeomPFIO
class(GeomPFIO), intent(inout) :: this
type(ESMF_FieldBundle), intent(in) :: bundle
character(len=*), intent(in) :: filename
integer, intent(in) :: time_index
integer, intent(out), optional :: rc
end subroutine I_stage_data_to_file

end interface

contains

subroutine update_time_on_server(this, time, rc)
class(GeomPFIO), intent(inout) :: this
type(ESMF_Time), intent(in) :: time
integer, intent(out), optional :: rc

integer :: status
type(StringVariableMap) :: var_map
type(Variable) :: time_var

time_var = create_time_variable(time, _RC)
call var_map%insert('time',time_var)
call o_Clients%modify_metadata(this%collection_id, var_map=var_map, _RC)

_RETURN(_SUCCESS)

end subroutine update_time_on_server

subroutine stage_time_to_file(this,filename, times, rc)
class(GeomPFIO), intent(inout) :: this
character(len=*), intent(in) :: filename
real, intent(in) :: times
integer, optional, intent(out) :: rc

integer :: status
type(ArrayReference) :: ref

ref = ArrayReference(times)
call o_Clients%stage_nondistributed_data(this%collection_id, filename, 'time', ref)
bena-nasa marked this conversation as resolved.
Show resolved Hide resolved

end subroutine

subroutine initialize(this, metadata, mapl_geom, rc)
class(GeomPFIO), intent(inout) :: this
type(FileMetadata), intent(in) :: metadata
type(MaplGeom), intent(in), pointer :: mapl_geom
integer, optional, intent(out) :: rc

integer :: status

this%mapl_geom => mapl_geom
this%collection_id = o_Clients%add_hist_collection(metadata)
_RETURN(_SUCCESS)
end subroutine initialize

pure integer function get_collection_id(this)
class(GeomPFIO), intent(in) :: this

get_collection_id = this%collection_id
end function get_collection_id

end module mapl3g_GeomPFIO
63 changes: 63 additions & 0 deletions GeomIO/Grid_PFIO.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "MAPL_Generic.h"

module mapl3g_GridPFIO
use mapl_ErrorHandling
use mapl3g_GeomPFIO
use ESMF
use PFIO
use MAPL_BaseMod
implicit none
private

public :: GridPFIO
type, extends (GeomPFIO) :: GridPFIO
private
contains
procedure :: stage_data_to_file
end type GridPFIO


contains

subroutine stage_data_to_file(this, bundle, filename, time_index, rc)
class(GridPFIO), intent(inout) :: this
type(ESMF_FieldBundle), intent(in) :: bundle
character(len=*), intent(in) :: filename
integer, intent(in) :: time_index
integer, intent(out), optional :: rc

integer :: status, num_fields, i, collection_id
character(len=ESMF_MAXSTR), allocatable :: field_names(:)
type(ESMF_Field) :: field
type(ArrayReference) :: ref
real, pointer :: ptr2d(:,:)
integer, allocatable :: local_start(:), global_start(:), global_count(:)

type(ESMF_Grid) :: grid
integer :: global_dim(3), i1, j1, in, jn

collection_id = this%get_collection_id()
call ESMF_FieldBundleGet(bundle, fieldCount=num_fields, _RC)
allocate(field_names(num_fields))
call ESMF_FieldBundleGet(bundle, fieldNameList=field_names, _RC)
do i=1,num_fields
call ESMF_FieldBundleGet(bundle, field_names(i), field=field, _RC)
! all this logic needs to be generalized
call ESMF_FieldGet(field, farrayPtr=ptr2d, _RC)
bena-nasa marked this conversation as resolved.
Show resolved Hide resolved
allocate(global_start, source=[1,1,time_index])
call ESMF_FieldGet(field, grid=grid, _RC)
call MAPL_GridGet(grid, globalCellCountPerDim=global_dim, _RC)
allocate(global_count, source=[global_dim(1),global_dim(2),1])
call MAPL_GridGetInterior(grid, i1, in, j1, jn)
bena-nasa marked this conversation as resolved.
Show resolved Hide resolved
allocate(local_start, source=[i1, j1,1])
ref = ArrayReference(ptr2d)
bena-nasa marked this conversation as resolved.
Show resolved Hide resolved
! end generalization
call o_clients%collective_stage_data(collection_id,filename, trim(field_names(i)), &
ref, start=local_start, global_start=global_start, global_count=global_count)
enddo

_RETURN(_SUCCESS)

end subroutine stage_data_to_file

end module mapl3g_GridPFIO
Loading