Skip to content

Commit

Permalink
revert data rof changes on data atm branch
Browse files Browse the repository at this point in the history
  • Loading branch information
iulian787 committed Apr 3, 2024
1 parent a60f2c2 commit c904ee3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 252 deletions.
185 changes: 2 additions & 183 deletions components/data_comps/drof/src/drof_comp_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ module drof_comp_mod
use drof_shr_mod , only: rest_file ! namelist input
use drof_shr_mod , only: rest_file_strm ! namelist input
use drof_shr_mod , only: nullstr
#ifdef HAVE_MOAB
use seq_comm_mct, only : mrofid ! id of moab rof app
use seq_comm_mct, only : mbrof_data ! turn on if the data rof
use iso_c_binding
#endif

!
! !PUBLIC TYPES:
implicit none
Expand Down Expand Up @@ -71,12 +67,6 @@ subroutine drof_comp_init(Eclock, x2r, r2x, &
SDROF, gsmap, ggrid, mpicom, compid, my_task, master_task, &
inst_suffix, inst_name, logunit, read_restart)

#ifdef HAVE_MOAB
use iMOAB, only: iMOAB_DefineTagStorage, iMOAB_GetDoubleTagStorage, &
iMOAB_SetIntTagStorage, iMOAB_SetDoubleTagStorage, &
iMOAB_ResolveSharedEntities, iMOAB_CreateVertices, &
iMOAB_GetMeshInfo, iMOAB_UpdateMeshInfo, iMOAB_WriteMesh
#endif
! !DESCRIPTION: initialize drof model
implicit none

Expand All @@ -102,18 +92,7 @@ subroutine drof_comp_init(Eclock, x2r, r2x, &
logical :: exists ! file existance logical
integer(IN) :: nu ! unit number
character(CL) :: calendar ! model calendar
#ifdef HAVE_MOAB
character*400 tagname
real(R8) latv, lonv
integer iv, tagindex, ilat, ilon, ierr !, arrsize, nfields
real(R8), allocatable, target :: data(:)
integer(IN), pointer :: idata(:) ! temporary
real(r8), dimension(:), allocatable :: moab_vert_coords ! temporary
!real(R8), allocatable, target :: vtags_zero(:, :)
#ifdef MOABDEBUG
character*100 outfile, wopts
#endif
#endif

!--- formats ---
character(*), parameter :: F00 = "('(drof_comp_init) ',8a)"
character(*), parameter :: F0L = "('(drof_comp_init) ',a, l2)"
Expand Down Expand Up @@ -185,122 +164,6 @@ subroutine drof_comp_init(Eclock, x2r, r2x, &

call t_stopf('drof_initmctdom')

! copy from data atm ; just need mrofid

#ifdef HAVE_MOAB
ilat = mct_aVect_indexRA(ggrid%data,'lat')
ilon = mct_aVect_indexRA(ggrid%data,'lon')
allocate(moab_vert_coords(lsize*3))
do iv = 1, lsize
lonv = ggrid%data%rAttr(ilon, iv) * SHR_CONST_PI/180.
latv = ggrid%data%rAttr(ilat, iv) * SHR_CONST_PI/180.
moab_vert_coords(3*iv-2)=COS(latv)*COS(lonv)
moab_vert_coords(3*iv-1)=COS(latv)*SIN(lonv)
moab_vert_coords(3*iv )=SIN(latv)
enddo

! create the vertices with coordinates from MCT domain
ierr = iMOAB_CreateVertices(mrofid, lsize*3, 3, moab_vert_coords)
if (ierr .ne. 0) &
call shr_sys_abort('Error: fail to create MOAB vertices in land model')

tagname='GLOBAL_ID'//C_NULL_CHAR
ierr = iMOAB_DefineTagStorage(mrofid, tagname, &
0, & ! dense, integer
1, & ! number of components
tagindex )
if (ierr .ne. 0) &
call shr_sys_abort('Error: fail to retrieve GLOBAL_ID tag ')

! get list of global IDs for Dofs
call mct_gsMap_orderedPoints(gsMap, my_task, idata)

ierr = iMOAB_SetIntTagStorage ( mrofid, tagname, lsize, &
0, & ! vertex type
idata)
if (ierr .ne. 0) &
call shr_sys_abort('Error: fail to set GLOBAL_ID tag ')

ierr = iMOAB_ResolveSharedEntities( mrofid, lsize, idata );
if (ierr .ne. 0) &
call shr_sys_abort('Error: fail to resolve shared entities')

deallocate(moab_vert_coords)
deallocate(idata)

ierr = iMOAB_UpdateMeshInfo( mrofid )
if (ierr .ne. 0) &
call shr_sys_abort('Error: fail to update mesh info ')

allocate(data(lsize))
ierr = iMOAB_DefineTagStorage( mrofid, "area:aream:frac:mask"//C_NULL_CHAR, &
1, & ! dense, double
1, & ! number of components
tagindex )
if (ierr > 0 ) &
call shr_sys_abort('Error: fail to create tag: area:aream:frac:mask' )

data(:) = ggrid%data%rAttr(mct_aVect_indexRA(ggrid%data,'area'),:)
tagname='area'//C_NULL_CHAR
ierr = iMOAB_SetDoubleTagStorage ( mrofid, tagname, lsize, &
0, & ! set data on vertices
data)
if (ierr > 0 ) &
call shr_sys_abort('Error: fail to get area tag ')

! set the same data for aream (model area) as area
! data(:) = ggrid%data%rAttr(mct_aVect_indexRA(ggrid%data,'aream'),:)
tagname='aream'//C_NULL_CHAR
ierr = iMOAB_SetDoubleTagStorage ( mrofid, tagname, lsize, &
0, & ! set data on vertices
data)
if (ierr > 0 ) &
call shr_sys_abort('Error: fail to set aream tag ')

data(:) = ggrid%data%rAttr(mct_aVect_indexRA(ggrid%data,'mask'),:)
tagname='mask'//C_NULL_CHAR
ierr = iMOAB_SetDoubleTagStorage ( mrofid, tagname, lsize, &
0, & ! set data on vertices
data)
if (ierr > 0 ) &
call shr_sys_abort('Error: fail to set mask tag ')

data(:) = ggrid%data%rAttr(mct_aVect_indexRA(ggrid%data,'frac'),:)
tagname='frac'//C_NULL_CHAR
ierr = iMOAB_SetDoubleTagStorage ( mrofid, tagname, lsize, &
0, & ! set data on vertices
data)
if (ierr > 0 ) &
call shr_sys_abort('Error: fail to set frac tag ')

deallocate(data)

! define tags
ierr = iMOAB_DefineTagStorage( mrofid, trim(seq_flds_x2r_fields)//C_NULL_CHAR, &
1, & ! dense, double
1, & ! number of components
tagindex )
if (ierr > 0 ) &
call shr_sys_abort('Error: fail to create seq_flds_x2r_fields tags ')

ierr = iMOAB_DefineTagStorage( mrofid, trim(seq_flds_r2x_fields)//C_NULL_CHAR, &
1, & ! dense, double
1, & ! number of components
tagindex )
if (ierr > 0 ) &
call shr_sys_abort('Error: fail to create seq_flds_r2x_fields tags ')
mbrof_data = .true. ! will have effects
#ifdef MOABDEBUG
! debug test
outfile = 'RofDataMesh.h5m'//C_NULL_CHAR
wopts = ';PARALLEL=WRITE_PART'//C_NULL_CHAR !
! write out the mesh file to disk
ierr = iMOAB_WriteMesh(mrofid, trim(outfile), trim(wopts))
if (ierr .ne. 0) then
call shr_sys_abort(subname//' ERROR in writing data mesh rof ')
endif
#endif
#endif
!----------------------------------------------------------------------------
! Initialize MCT attribute vectors
!----------------------------------------------------------------------------
Expand Down Expand Up @@ -393,13 +256,6 @@ subroutine drof_comp_run(EClock, x2r, r2x, &
SDROF, gsmap, ggrid, mpicom, compid, my_task, master_task, &
inst_suffix, logunit, case_name)

#ifdef MOABDEBUG
use iMOAB, only: iMOAB_WriteMesh
#endif
#ifdef HAVE_MOAB
use seq_flds_mod , only: seq_flds_r2x_fields
use seq_flds_mod , only: moab_set_tag_from_av
#endif
! !DESCRIPTION: run method for drof model
implicit none

Expand Down Expand Up @@ -429,18 +285,7 @@ subroutine drof_comp_run(EClock, x2r, r2x, &
integer(IN) :: nu ! unit number
integer(IN) :: nflds_r2x
character(len=18) :: date_str
#ifdef HAVE_MOAB
real(R8), allocatable, target :: datam(:)
type(mct_list) :: temp_list
integer :: size_list, index_list
type(mct_string) :: mctOStr !
character*400 tagname, mct_field
#ifdef MOABDEBUG
integer :: cur_drof_stepno, ierr
character*100 outfile, wopts, lnum
#endif

#endif
character(*), parameter :: F00 = "('(drof_comp_run) ',8a)"
character(*), parameter :: F04 = "('(drof_comp_run) ',2a,2i8,'s')"
character(*), parameter :: subName = "(drof_comp_run) "
Expand Down Expand Up @@ -539,32 +384,6 @@ subroutine drof_comp_run(EClock, x2r, r2x, &
!----------------------------------------------------------------------------
! Log output for model date
!----------------------------------------------------------------------------
#ifdef HAVE_MOAB
lsize = mct_avect_lsize(r2x) ! is it the same as mct_avect_lsize(avstrm) ?
allocate(datam(lsize)) !
call mct_list_init(temp_list ,seq_flds_r2x_fields)
size_list=mct_list_nitem (temp_list)
do index_list = 1, size_list
call mct_list_get(mctOStr,index_list,temp_list)
mct_field = mct_string_toChar(mctOStr)
tagname= trim(mct_field)//C_NULL_CHAR
call moab_set_tag_from_av(tagname, r2x, index_list, mrofid, datam, lsize) ! loop over all a2x fields, not just a few
enddo
call mct_list_clean(temp_list)
deallocate(datam) ! maybe we should keep it around, deallocate at the final only?

#ifdef MOABDEBUG
call seq_timemgr_EClockGetData( EClock, stepno=cur_drof_stepno )
write(lnum,"(I0.2)")cur_drof_stepno
outfile = 'drof_comp_run_'//trim(lnum)//'.h5m'//C_NULL_CHAR
wopts = 'PARALLEL=WRITE_PART'//C_NULL_CHAR
ierr = iMOAB_WriteMesh(mrofid, outfile, wopts)
if (ierr > 0 ) then
write(logunit,*) 'Failed to write data rof component state '
endif
#endif

#endif

call t_startf('drof_run2')
if (my_task == master_task) then
Expand Down
16 changes: 1 addition & 15 deletions components/data_comps/drof/src/rof_comp_mct.F90
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ module rof_comp_mct
use drof_comp_mod , only: drof_comp_init, drof_comp_run, drof_comp_final
use drof_shr_mod , only: drof_shr_read_namelists
use seq_flds_mod , only: seq_flds_x2r_fields, seq_flds_r2x_fields
#ifdef HAVE_MOAB
use seq_comm_mct, only : mrofid ! iMOAB app id for rof
use iso_c_binding
use iMOAB , only: iMOAB_RegisterApplication
#endif

! !PUBLIC TYPES:
implicit none
private ! except
Expand Down Expand Up @@ -144,16 +140,6 @@ subroutine rof_init_mct( EClock, cdata, x2r, r2x, NLFilename )
! Initialize drof
!----------------------------------------------------------------------------

#ifdef HAVE_MOAB
ierr = iMOAB_RegisterApplication(trim("DROF")//C_NULL_CHAR, mpicom, compid, mrofid)
if (ierr .ne. 0) then
write(logunit,*) subname,' error in registering data rof comp'
call shr_sys_abort(subname//' ERROR in registering data rof comp')
endif
! send path of atm domain file to MOAB coupler. Note that here we may have the land domain in some cases?
!call seq_infodata_PutData( infodata, atm_mesh=SDATM%domainFile)
#endif

call drof_comp_init(Eclock, x2r, r2x, &
seq_flds_x2r_fields, seq_flds_r2x_fields, &
SDROF, gsmap, ggrid, mpicom, compid, my_task, master_task, &
Expand Down
64 changes: 20 additions & 44 deletions driver-moab/main/cplcomp_exchange_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module cplcomp_exchange_mod
use seq_comm_mct, only : mphaid ! iMOAB app id for phys atm; comp atm is 5, phys 5+200
use seq_comm_mct, only : MPSIID, mbixid ! sea-ice on comp pes and on coupler pes
use seq_comm_mct, only : mrofid, mbrxid ! iMOAB id of moab rof app on comp pes and on coupler too
use seq_comm_mct, only : mbrof_data ! if data rof
use shr_mpi_mod, only: shr_mpi_max
! use dimensions_mod, only : np ! for atmosphere
use iso_c_binding
Expand Down Expand Up @@ -1214,7 +1213,7 @@ subroutine cplcomp_moab_Init(infodata,comp)
outfile = 'recMeshAtm.h5m'//C_NULL_CHAR
endif
wopts = ';PARALLEL=WRITE_PART'//C_NULL_CHAR
! write out the mesh file to diskocn_domain
! write out the mesh file to disk
ierr = iMOAB_WriteMesh(mbaxid, trim(outfile), trim(wopts))
if (ierr .ne. 0) then
write(logunit,*) subname,' error in writing mesh '
Expand Down Expand Up @@ -1623,43 +1622,21 @@ subroutine cplcomp_moab_Init(infodata,comp)
call seq_comm_getinfo(cplid ,mpigrp=mpigrp_cplid) ! receiver group
call seq_comm_getinfo(id_old,mpigrp=mpigrp_old) ! component group pes

call seq_infodata_GetData(infodata,rof_mesh=rtm_mesh)

if (MPI_COMM_NULL /= mpicom_old ) then ! it means we are on the component pes (rof)
comp%mbApCCid = mrofid ! rof comp app in moab
if ( trim(rtm_mesh) == 'none' ) then ! mbrof_data is .true. also
! send mesh to coupler
ierr = iMOAB_SendMesh(mrofid, mpicom_join, mpigrp_cplid, id_join, partMethod)
if (ierr .ne. 0) then
write(logunit,*) subname,' error in sending rof mesh to coupler '
call shr_sys_abort(subname//' ERROR in sending rof mesh to coupler ')
endif
endif
endif
if (MPI_COMM_NULL /= mpicom_new ) then ! we are on the coupler pes
appname = "COUPLE_MROF"//C_NULL_CHAR
ierr = iMOAB_RegisterApplication(trim(appname), mpicom_new, id_join, mbrxid)

if ( trim(rtm_mesh) == 'none' ) then
mbrof_data = .true. ! turn it on the coupler pes too;
ierr = iMOAB_ReceiveMesh(mbrxid, mpicom_join, mpigrp_old, id_old)
if (ierr .ne. 0) then
write(logunit,*) subname,' error in receiving mesh on rof coupler '
call shr_sys_abort(subname//' ERROR in receiving mesh on rof coupler ')
endif
else
! load mesh from scrip file passed from river model
outfile = trim(rtm_mesh)//C_NULL_CHAR
ropts = 'PARALLEL=READ_PART;PARTITION_METHOD=RCBZOLTAN'//C_NULL_CHAR

nghlay = 0 ! no ghost layers
ierr = iMOAB_LoadMesh(mbrxid, outfile, ropts, nghlay)
if ( ierr .ne. 0 ) then
call shr_sys_abort( subname//' ERROR: cannot read rof mesh on coupler' )
end if

endif
! need to add global id tag to the app, it will be used in restart
call seq_infodata_GetData(infodata,rof_mesh=rtm_mesh)
outfile = trim(rtm_mesh)//C_NULL_CHAR
ropts = 'PARALLEL=READ_PART;PARTITION_METHOD=RCBZOLTAN'//C_NULL_CHAR

nghlay = 0 ! no ghost layers
ierr = iMOAB_LoadMesh(mbrxid, outfile, ropts, nghlay)
if ( ierr .ne. 0 ) then
call shr_sys_abort( subname//' ERROR: cannot read rof mesh on coupler' )
end if
! need to add global id tag to the app, it will be used in restart
tagtype = 0 ! dense, integer
numco = 1
tagname='GLOBAL_ID'//C_NULL_CHAR
Expand All @@ -1668,6 +1645,7 @@ subroutine cplcomp_moab_Init(infodata,comp)
write(logunit,*) subname,' error in adding global id tag to rof'
call shr_sys_abort(subname//' ERROR in adding global id tag to rof ')
endif

#ifdef MOABDEBUG
! debug test
outfile = 'recRof.h5m'//C_NULL_CHAR
Expand Down Expand Up @@ -1707,16 +1685,14 @@ subroutine cplcomp_moab_Init(infodata,comp)
comp%mbGridType = 0 ! 0 or 1, pc or cells
comp%mblsize = nvert(1) ! vertices
endif
if ( trim(rtm_mesh) /= 'none' ) then ! we are in full mesh case
! we are now on joint pes, compute comm graph between rof and coupler model
typeA = 2 ! point cloud on component PEs
typeB = 3 ! full mesh on coupler pes, we just read it
ierr = iMOAB_ComputeCommGraph( mrofid, mbrxid, mpicom_join, mpigrp_old, mpigrp_cplid, &
typeA, typeB, id_old, id_join)
if (ierr .ne. 0) then
write(logunit,*) subname,' error in computing comm graph for rof model '
call shr_sys_abort(subname//' ERROR in computing comm graph for rof model ')
endif
! we are now on joint pes, compute comm graph between rof and coupler model
typeA = 2 ! point cloud on component PEs
typeB = 3 ! full mesh on coupler pes, we just read it
ierr = iMOAB_ComputeCommGraph( mrofid, mbrxid, mpicom_join, mpigrp_old, mpigrp_cplid, &
typeA, typeB, id_old, id_join)
if (ierr .ne. 0) then
write(logunit,*) subname,' error in computing comm graph for rof model '
call shr_sys_abort(subname//' ERROR in computing comm graph for rof model ')
endif

! if (mrofid .ge. 0) then ! we are on component rof pes
Expand Down
11 changes: 2 additions & 9 deletions driver-moab/main/seq_frac_mct.F90
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ module seq_frac_mct
! for tri grid, sameg_al would be false

use seq_comm_mct, only : mbrxid ! iMOAB id of moab rof migrated to coupler pes
use seq_comm_mct, only : mbrof_data ! different logic for data rof model

use iMOAB, only : iMOAB_DefineTagStorage, iMOAB_SetDoubleTagStorage, &
iMOAB_GetMeshInfo, iMOAB_SetDoubleTagStorageWithGid, iMOAB_WriteMesh, &
Expand Down Expand Up @@ -517,15 +516,9 @@ subroutine seq_frac_init( infodata, &
call shr_sys_abort(subname//' ERROR in defining tags on rof phys mesh on cpl')
endif
ierr = iMOAB_GetMeshInfo ( mbrxid, nvert, nvise, nbl, nsurf, nvisBC );
if (mbrof_data) then ! then the coupler has point cloud too
arrSize = 3 * nvert(1)
ent_type = 0 ! vertex type on rof
else
arrSize = 3 * nvise(1) ! there are 3 tags
ent_type = 1 ! cell type, rof is now FV on coupler side
endif
arrSize = 3 * nvise(1) ! there are 3 tags
allocate(tagValues(arrSize) )

ent_type = 1 ! vertex type, rof is now FV
tagValues = 0.
ierr = iMOAB_SetDoubleTagStorage ( mbrxid, tagname, arrSize , ent_type, tagValues)
deallocate(tagValues)
Expand Down
Loading

0 comments on commit c904ee3

Please sign in to comment.