From 54cca718d5a7756777d32f9ece8ff1e77fcec499 Mon Sep 17 00:00:00 2001 From: Carsten Lemmen Date: Fri, 18 Feb 2022 15:38:39 -0500 Subject: [PATCH 1/3] Better hierarchy description in src/schism/Readme --- src/schism/Readme.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/schism/Readme.md b/src/schism/Readme.md index e5d9fd6..a5b5d79 100644 --- a/src/schism/Readme.md +++ b/src/schism/Readme.md @@ -1,8 +1,8 @@ -This directory contains NUOPC cap for schism instances of NUOPC_Model and for the -ESMF gridded component. +This directory contains the ESMF/NUOPC caps for the SCHISM model, as well as supporting infrastructure and interfaces. -For each NUOPC_Model, there is a corresponding Makefile snippet. Currently -available components are +The ESMF cap `schism_esmf_cap` relies on utilities in `schism_esmf_utils` and the basic model interface `schism_bmi`. +The NUOPC cap `schism_nuopc_cap` relies on utilities in `schism_nuop_utils`and `schism_esmf_utils`and the `schism_bmi`. + +For the NUOPC model instance in `schism_nuopc_cap` there are also corresponding Makefile snippets for standardized +inclusion in NUOPC compliant model systems. -schism_nuopc_cap -: NUOPC cap for SCHISM From d59227f52d68b59f0ec78e8b530ae1c1a9002c1a Mon Sep 17 00:00:00 2001 From: Carsten Lemmen Date: Fri, 18 Feb 2022 15:44:55 -0500 Subject: [PATCH 2/3] Code cleanup and copyright updates --- src/schism/Makefile | 4 ++-- src/schism/schism_bmi.F90 | 34 +++------------------------------- src/schism/schism_esmf_cap.F90 | 2 +- 3 files changed, 6 insertions(+), 34 deletions(-) diff --git a/src/schism/Makefile b/src/schism/Makefile index 0d12eff..2a24089 100644 --- a/src/schism/Makefile +++ b/src/schism/Makefile @@ -1,9 +1,9 @@ # This code is part of the SCHISM-ESMF interface. # -# @copyright (C) 2021 Helmholtz-Zentrum Hereon +# @copyright (C) 2021-2022 Helmholtz-Zentrum Hereon # @copyright (C) 2020-2021 Helmholtz-Zentrum Geesthacht # -# @author Carsten Lemmen carsten.lemmen@hereon.de +# @author Carsten Lemmen # # @license Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/schism/schism_bmi.F90 b/src/schism/schism_bmi.F90 index 072b015..5512e7b 100644 --- a/src/schism/schism_bmi.F90 +++ b/src/schism/schism_bmi.F90 @@ -1,10 +1,10 @@ ! This code is part of the SCHISM-ESMF interface and defines ! a generic BMI (basic model interface) to schism ! -! @copyright 2021 Helmholtz-Zentrum Hereon +! @copyright 2021-2022 Helmholtz-Zentrum Hereon ! @copyright 2018-2021 Helmholtz-Zentrum Geesthacht ! -! @author Carsten Lemmen carsten.lemmen@hereon.de +! @author Carsten Lemmen ! @author Richard Hofmeister ! ! @license Apache License, Version 2.0 (the "License"); @@ -32,7 +32,7 @@ module schism_bmi ! We *should not* use ESMF in a BMI, but this is used here for logging only - use ESMF!, only:: ESMF_LogFoundError, ESMF_END_ABORT, ESMF_Finalize, ESMF_SUCCESS + use esmf!, only:: ESMF_LogFoundError, ESMF_END_ABORT, ESMF_Finalize, ESMF_SUCCESS interface subroutine parallel_init(communicator) @@ -40,7 +40,6 @@ subroutine parallel_init(communicator) integer, optional :: communicator end subroutine parallel_init - subroutine parallel_finalize implicit none end subroutine parallel_finalize @@ -109,31 +108,4 @@ function schismPtr1(varname) result(farrayPtr) end function schismPtr1 - -! subroutine prepareMesh(nodeIds, nodeCoords2D, nodeOwners, nodeMask, & -! elementIds, elementCoords2d, elementTypes, elementMask, nv, & -! rc) -! -! use schism_glbl, only:: npa, np -! -! implicit none -! -! integer, dimension(:), allocatable :: nodeids,elementids,nv -! double precision, dimension(:), allocatable :: nodecoords2d, nodecoords3d -! double precision, dimension(:), allocatable :: elementcoords2d, elementcoords3d -! integer, dimension(:), allocatable :: nodeowners, elementtypes -! integer, dimension(:), allocatable :: nodemask, elementmask -! integer, dimension(:), allocatable :: tmpIdx, tmpIdx2, localNodes, nodeHaloIdx -! integer :: numLocalNodes, numNodeHaloIdx=0 -! -! ! prepare mesh -! ! a) take local elements and get number of nodes for definition -! ! b) get number of augmented nodes, which are not connected to local elements -! ! c) allocate node arrays such that nodeids gives all nods belonging to local -! ! elements, all other nodes as part of the augmented domain are outside the -! ! exclusive region -! ! d) allocate element arrays such that local elements (ne) are in array and -! ! augmented elements are defined in the computational domain outside the -! ! exclusive domain - end module schism_bmi diff --git a/src/schism/schism_esmf_cap.F90 b/src/schism/schism_esmf_cap.F90 index 467bab8..baf2004 100644 --- a/src/schism/schism_esmf_cap.F90 +++ b/src/schism/schism_esmf_cap.F90 @@ -1,6 +1,6 @@ ! This code is part of the SCHISM-ESMF interface ! -! @copyright (C) 2021 Helmholtz-Zentrum Hereon +! @copyright (C) 2021-2022 Helmholtz-Zentrum Hereon ! @copyright (C) 2018--2021 Helmholtz-Zentrum Geesthacht ! ! @author Carsten Lemmen From c378947ef453f72acfb1011eef8c0c7ac1736ab0 Mon Sep 17 00:00:00 2001 From: Carsten Lemmen Date: Fri, 18 Feb 2022 16:16:21 -0500 Subject: [PATCH 3/3] Cleaned up schism_esmf_util.F90, @TODO debugging shows missing logs and skipping of lines :=( --- src/schism/schism_esmf_util.F90 | 53 +++++++++++++++++---------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/schism/schism_esmf_util.F90 b/src/schism/schism_esmf_util.F90 index 2f79084..3c2a623 100644 --- a/src/schism/schism_esmf_util.F90 +++ b/src/schism/schism_esmf_util.F90 @@ -1,9 +1,12 @@ ! This code is part of the SCHISM-ESMF interface, it defines utility ! functions used both by the NUOPC and ESMF caps ! -! @copyright 2021 Helmholtz-Zentrum Hereon +! @copyright 2022 Virginia Institute of Marine Science +! @copyright 2021-2022 Helmholtz-Zentrum Hereon ! @copyright 2018-2021 Helmholtz-Zentrum Geesthacht +! ! @author Carsten Lemmen +! @author Joseph Zhang ! @author Richard Hofmeister ! ! @license Apache License, Version 2.0 (the "License"); @@ -51,19 +54,19 @@ subroutine addSchismMesh(comp, rc) type(ESMF_GridComp) :: comp integer, intent(out) :: rc - type(ESMF_Mesh) :: mesh2d, mesh3d + type(ESMF_Mesh) :: mesh2d type(ESMF_DistGrid) :: elementDistgrid, distgrid type(ESMF_CoordSys_Flag) :: coordsys integer, dimension(:), allocatable :: nodeids, elementids, nv - real(ESMF_KIND_R8), dimension(:), allocatable :: nodecoords2d, nodecoords3d - real(ESMF_KIND_R8), dimension(:), allocatable :: elementcoords2d, elementcoords3d + real(ESMF_KIND_R8), dimension(:), allocatable :: nodecoords2d + real(ESMF_KIND_R8), dimension(:), allocatable :: elementcoords2d integer, dimension(:), allocatable :: nodeowners, elementtypes integer, dimension(:), allocatable :: nodemask, elementmask integer, dimension(:), allocatable :: tmpIdx, tmpIdx2, localNodes, nodeHaloIdx integer, dimension(:), allocatable :: schismTolocalNodes,testids integer, dimension(1:4) :: elLocalNode integer :: numNodeHaloIdx - integer :: i,n,nvcount,nvcount2 + integer :: i,n,nvcount integer :: ii,ip,ie, localrc integer :: mynp,myne,rank2 type(llist_type),pointer :: nextp=>null() @@ -119,10 +122,6 @@ subroutine addSchismMesh(comp, rc) allocate(nodecoords2d(2*np), stat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - !Not used -! allocate(nodecoords3d(3*np), stat=localrc) -! _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - !A node is owned by same rank across PETs; interface nodes are owned by min rank allocate(nodeowners(np), stat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) @@ -143,10 +142,9 @@ subroutine addSchismMesh(comp, rc) allocate(elementcoords2d(2*ne), stat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - !nv (elemConn): 1D array for connectivity (packed from 2D array elnode). - !Outputs local node # - nvcount2=sum(i34(1:ne)) - allocate(nv(nvcount2), stat=localrc) + ! nv (elemConn): 1D array for connectivity (packed from 2D array elnode). + ! Outputs local node # + allocate(nv(sum(i34(1:ne))), stat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) ! set ESMF coordSys type @@ -217,7 +215,7 @@ subroutine addSchismMesh(comp, rc) elementcoords2d(2*i)=sum(nodecoords2d(2*elLocalNode(1:i34(i))))/i34(i) end do !i - if(nvcount2/=nvcount) then + if(ubound(nv,1)/=nvcount) then localrc=ESMF_RC_ARG_SIZE _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) endif @@ -248,37 +246,40 @@ subroutine addSchismMesh(comp, rc) elementConn=nv, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) -!#if 0 - ! output mesh information from schism and esmf - call ESMF_MeshGet(mesh2d,numOwnedNodes=mynp,numOwnedElements=myne,elementDistgrid=distgrid,rc=localrc) + call ESMF_MeshGet(mesh2d, numOwnedNodes=mynp, numOwnedElements=myne, elementDistgrid=distgrid, & + rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) + allocate(testids(myne)) call ESMF_DistGridGet(distgrid,localDE=0,seqIndexList=testids,rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - write(message,*) 'esmf owned nodes,elements:',mynp,myne + write(message, '(A,I3.3,A,I3.3,A)') trim(compName)//' created mesh from "', np, & + 'resident nodes and ', myne, ' resident elements in SCHISM' call ESMF_LogWrite(trim(message), ESMF_LOGMSG_WARNING) - write(message,*) 'schism owned nodes,elements:',np,ne + + write(message, '(A,I3.3,A,I3.3,A)') trim(compName)//' created mesh with "', mynp, & + 'owned nodes and ', myne, ' owned elements' call ESMF_LogWrite(trim(message), ESMF_LOGMSG_WARNING) + + !> @todo the following might overflow the message buffer easily ... write(message,*) 'elementIds:',elementIds call ESMF_LogWrite(trim(message), ESMF_LOGMSG_WARNING) + write(message,*) 'distgridElementIds:',testids call ESMF_LogWrite(trim(message), ESMF_LOGMSG_WARNING) + deallocate(testids) -!#endif call ESMF_GridCompSet(comp, mesh=mesh2d, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) -!YJZ: error -! return !> @todo the following steps don't work in the NUOPC cap yet !> Create fields for export to describe mesh (this information is not yet !> accessible with ESMF_MeshGet calls) !> @todo remove this part of the code once there is a suitable ESMF implementation -#if 0 !> Create a dummy field to satisfy ugrid conventions field = ESMF_FieldEmptyCreate(name='mesh_topology', rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) @@ -364,7 +365,6 @@ subroutine addSchismMesh(comp, rc) call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO) nullify(farrayPtrI42) -#endif ! clean up deallocate(nodeids, stat=localrc) @@ -376,8 +376,9 @@ subroutine addSchismMesh(comp, rc) deallocate(elementtypes, stat=localrc) if (allocated(elementCoords2d)) deallocate(elementCoords2d, stat=localrc) deallocate(nv, stat=localrc) -! deallocate(LocalNodes, stat=localrc) -! deallocate(schismToLocalNodes, stat=localrc) + + write(message, '(A)') trim(compName)//' created 2D mesh"' + call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO) end subroutine addSchismMesh