Skip to content

Commit

Permalink
Improved bookkeeping of scalar field numbers and names
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco de Bruine committed Sep 15, 2020
1 parent 13e4129 commit 78e6594
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
11 changes: 5 additions & 6 deletions src/modemisdata.f90
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ module modemisdata
! Namelist variables

logical :: l_emission = .false.
integer :: kemis = -1
integer :: kemis = -1, &
sv_skip = 0
integer :: i
character(len = 6), dimension(100) :: svlist = (/ ('abcdef', i=1, 100) /)

! Main variables

Expand All @@ -47,10 +50,6 @@ module modemisdata
! For example, nchem, firstchem etc, but also structure for species
! 'location', i.e. switch scalar field represents which species?

character (len = 3), dimension(1) :: svlist = (/'co2' /)
logical, dimension(1) :: emislist = (/.true./)

! character (len = 3), dimension(4) :: svlist = (/'nr', 'qr', 'co2', 'ch4' /)
! logical, dimension(4) :: emislist = (/.false., .false., .true., .false./)
! character(len = 3), dimension(1) :: svlist = (/'co2' /)

end module modemisdata
38 changes: 19 additions & 19 deletions src/modemission.f90
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module modemission
subroutine initemission

use modglobal, only : i2, j2,kmax, nsv, ifnamopt, fname_options
use modmpi, only : myid, comm3d, mpi_logical, mpi_integer
use modmpi, only : myid, comm3d, mpi_logical, mpi_integer, mpi_character
use moddatetime, only : datex, prevday, nextday

implicit none
Expand All @@ -42,7 +42,7 @@ subroutine initemission
integer :: ierr

! --- Read & broadcast namelist EMISSION -----------------------------------
namelist/NAMEMISSION/ l_emission, kemis
namelist/NAMEMISSION/ l_emission, kemis, sv_skip, svlist

if (myid == 0) then

Expand All @@ -59,8 +59,10 @@ subroutine initemission

endif

call mpi_bcast(l_emission, 1, mpi_logical, 0, comm3d, ierr)
call mpi_bcast(kemis, 1, mpi_integer, 0, comm3d, ierr)
call mpi_bcast(l_emission, 1, mpi_logical, 0, comm3d, ierr)
call mpi_bcast(kemis, 1, mpi_integer, 0, comm3d, ierr)
call mpi_bcast(sv_skip, 1, mpi_integer, 0, comm3d, ierr)
call mpi_bcast(svlist(1:100), 100, mpi_character, 0, comm3d, ierr)

! --- Local pre-calculations and settings
if (.not. (l_emission)) return
Expand All @@ -72,7 +74,7 @@ subroutine initemission
! Two hourly emission fields are loaded at all times:
! (1) before model time, t_field < t_model, "in-the-past"
! (2) ahead of model time, t_field > t_model, "in-the-future"
allocate(svemis(i2, j2, kemis, nsv, 2))
allocate(svemis(i2, j2, kemis, sv_skip+1:nsv, 2))

if (datex(5) >= 30) then
call reademission( datex(1), datex(2), datex(3), datex(4), svemis(:,:,:,:,1))
Expand Down Expand Up @@ -111,7 +113,7 @@ subroutine reademission(iyear, imonth, iday, ihour, emisfield)
implicit none

integer, intent(in) :: iyear, imonth, iday, ihour
real, intent(out) :: emisfield(i2, j2, kemis, nsv)
real, intent(out) :: emisfield(i2, j2, kemis, 1+sv_skip:nsv)

integer, parameter :: ndim = 3
integer :: start(ndim), count(ndim)
Expand All @@ -125,17 +127,15 @@ subroutine reademission(iyear, imonth, iday, ihour, emisfield)

write(6,"(A18, A12)") "Reading emission: ", sdatetime

do isv = 1, nsv
do isv = 1+sv_skip, nsv

if (emislist(isv)) then
call check( nf90_open( svlist(isv)//'_emis_'//sdatetime//'_3d.nc', IOR(NF90_NOWRITE, NF90_MPIIO), &
ncid, comm = comm3d, info = MPI_INFO_NULL) )
call check( nf90_inq_varid( ncid, svlist(isv), varid) )
call check( nf90_get_var ( ncid, varid, emisfield(2:i1,2:j1,1:kemis,isv), &
start = (/1 + myidx * imax, 1 + myidy * jmax, 1, 1/), &
count = (/imax, jmax, kemis, 1/) ) )
call check( nf90_close( ncid ) )
endif
call check( nf90_open( trim(svlist(isv-sv_skip))//'_emis_'//sdatetime//'_3d.nc', IOR(NF90_NOWRITE, NF90_MPIIO), &
ncid, comm = comm3d, info = MPI_INFO_NULL) )
call check( nf90_inq_varid( ncid, svlist(isv-sv_skip), varid) )
call check( nf90_get_var ( ncid, varid, emisfield(2:i1,2:j1,1:kemis,isv), &
start = (/1 + myidx * imax, 1 + myidy * jmax, 1, 1/), &
count = (/imax, jmax, kemis, 1/) ) )
call check( nf90_close( ncid ) )

end do

Expand Down Expand Up @@ -191,9 +191,9 @@ subroutine emission
! rhof and dzf to svemis. For now, loop over k.

do k = 1,kemis
svp(2:i1, 2:j1, k, 1:nsv) = svp(2:i1, 2:j1, k, 1:nsv) + &
((1. - emistime_s)*svemis(2:i1, 2:j1, k, 1:nsv, 1) + &
emistime_s *svemis(2:i1, 2:j1, k, 1:nsv, 2))/(3600.*rhof(k)*dzf(k)*dx*dy*1e-6)
svp(2:i1, 2:j1, k, sv_skip+1:nsv) = svp(2:i1, 2:j1, k, sv_skip+1:nsv) + &
((1. - emistime_s)*svemis(2:i1, 2:j1, k, sv_skip+1:nsv, 1) + &
emistime_s *svemis(2:i1, 2:j1, k, sv_skip+1:nsv, 2))/(3600.*rhof(k)*dzf(k)*dx*dy*1e-6)
end do

! --------------------------------------------------------------------------
Expand Down
32 changes: 18 additions & 14 deletions src/modnudgeboundary.f90
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ subroutine initnudgeboundary
use modmpi, only : myid, mpierr, comm3d, mpi_logical, mpi_int, my_real
use modglobal, only : ifnamopt, fname_options, imax, jmax, dx, dy, i1, j1, k1, ih, jh, lwarmstart, kmax, zf, checknamelisterror, nsv
use modboundary, only : boundary
use modemisdata, only : sv_skip

implicit none

integer :: ierr, k
Expand Down Expand Up @@ -175,7 +177,7 @@ subroutine initnudgeboundary
allocate( lbc_v (2-ih:i1+ih, 2-jh:j1+jh, k1, 2) )
allocate( lbc_thl(2-ih:i1+ih, 2-jh:j1+jh, k1, 2) )
allocate( lbc_qt (2-ih:i1+ih, 2-jh:j1+jh, k1, 2) )
if (lnudge_boundary_sv) allocate( lbc_sv (2-ih:i1+ih, 2-jh:j1+jh, k1, nsv, 2) )
if (lnudge_boundary_sv) allocate( lbc_sv (2-ih:i1+ih, 2-jh:j1+jh, k1, 1+sv_skip:nsv, 2) )

! Read the first two input times
call read_new_LBCs(0.)
Expand Down Expand Up @@ -220,10 +222,11 @@ end subroutine initnudgeboundary
subroutine read_initial_fields

! BvS - this should really go somewhere else, probably modstartup...
use modfields, only : u0, v0, um, vm, thlm, thl0, qtm, qt0, sv0, svm
use modfields, only : u0, v0, um, vm, thlm, thl0, qtm, qt0, sv0, svm
use modsurfdata, only : tskin
use modglobal, only : i1, j1, iexpnr, kmax, nsv
use modmpi, only : myidx, myidy
use modglobal, only : i1, j1, iexpnr, kmax, nsv
use modmpi, only : myidx, myidy
use modemisdata, only : sv_skip

implicit none

Expand Down Expand Up @@ -260,12 +263,12 @@ subroutine read_initial_fields
print*,'Reading initial field: ', input_file_sv

open(777, file=input_file_sv, form='unformatted', status='unknown', action='read', access='stream')
do isv = 1,nsv
do isv = sv_skip+1,nsv
read(777) sv0(2:i1,2:j1,1:kmax,isv)
end do
close(777)

svm (2:i1,2:j1,1:kmax,1:nsv) = sv0(2:i1,2:j1,1:kmax,1:nsv)
svm (2:i1,2:j1,1:kmax,sv_skip+1:nsv) = sv0(2:i1,2:j1,1:kmax,sv_skip+1:nsv)
endif

end subroutine read_initial_fields
Expand Down Expand Up @@ -315,9 +318,9 @@ end subroutine read_new_LBCs

subroutine read_new_LBCs_sv(time)

use modglobal, only : i1, j1, iexpnr, kmax, nsv
use modmpi, only : myidx, myidy, nprocx, nprocy

use modglobal, only : i1, j1, iexpnr, kmax, nsv
use modmpi, only : myidx, myidy, nprocx, nprocy
use modemisdata, only : sv_skip
implicit none
real, intent(in) :: time !< Input: time to read (seconds)
integer :: ihour, imin, isv
Expand All @@ -343,7 +346,7 @@ subroutine read_new_LBCs_sv(time)

! Read new LBC for next time
open(777, file=input_file, form='unformatted', status='unknown', action='read', access='stream')
do isv = 1,nsv
do isv = sv_skip+1,nsv
read(777) lbc_sv (2:i1,2:j1,1:kmax,isv,2)
end do
close(777)
Expand All @@ -354,9 +357,10 @@ end subroutine read_new_LBCs_sv

subroutine nudgeboundary

use modglobal, only : i1, j1, imax, jmax, kmax, rdt, cu, cv, eps1, rtimee, nsv
use modfields, only : u0, up, v0, vp, w0, wp, thl0, thlp, qt0, qtp, sv0, svp
use modmpi, only : myidx, myidy, nprocx, nprocy
use modglobal, only : i1, j1, imax, jmax, kmax, rdt, cu, cv, eps1, rtimee, nsv
use modfields, only : u0, up, v0, vp, w0, wp, thl0, thlp, qt0, qtp, sv0, svp
use modmpi, only : myidx, myidy, nprocx, nprocy
use modemisdata, only : sv_skip

!#ifdef __INTEL_COMPILER
use ifport
Expand Down Expand Up @@ -413,7 +417,7 @@ subroutine nudgeboundary
lbc_w_int = 0.

if (lnudge_boundary_sv) then
do isv = 1,nsv
do isv = 1+sv_skip, nsv
lbc_sv_int = tfac_sv * lbc_sv (i,j,k,isv,1) + (1.-tfac_sv) * lbc_sv (i,j,k,isv,2)
svp(i,j,k,isv) = svp(i,j,k,isv) + nudge_factor(i,j) * tau_i * (lbc_sv_int - sv0(i,j,k,isv))
end do
Expand Down

0 comments on commit 78e6594

Please sign in to comment.