subroutine ibmwallfun use modglobal, only : libm, iwallmom, iwalltemp, xhat, yhat, zhat, ltempeq, lmoist, & ib, ie, ih, ihc, jb, je, jh, jhc, kb, ke, kh, khc, nsv, totheatflux, totqflux, nfcts, rk3step, timee, nfcts, lwritefac, dt, dtfac, tfac, tnextfac use modfields, only : u0, v0, w0, thl0, qt0, sv0, up, vp, wp, thlp, qtp, svp, & tau_x, tau_y, tau_z, thl_flux use modsubgriddata, only : ekm, ekh use modmpi, only : myid, comm3d, MPI_SUM, mpierr, MY_REAL use modstat_nc, only : writestat_nc, writestat_1D_nc, writestat_2D_nc real, allocatable :: rhs(:,:,:) integer n real :: thl_flux_sum, thl_flux_tot, mom_flux_sum, mom_flux_tot logical thl_flux_file_exists, mom_flux_file_exists if (.not. libm) return allocate(rhs(ib-ih:ie+ih,jb-jh:je+jh,kb:ke+kh)) if (iwallmom > 1) then rhs = up call wallfunmom(xhat, up, bound_info_u) tau_x(:,:,kb:ke+kh) = tau_x(:,:,kb:ke+kh) + (up - rhs) rhs = vp call wallfunmom(yhat, vp, bound_info_v) tau_y(:,:,kb:ke+kh) = tau_y(:,:,kb:ke+kh) + (vp - rhs) rhs = wp call wallfunmom(zhat, wp, bound_info_w) tau_z(:,:,kb:ke+kh) = tau_z(:,:,kb:ke+kh) + (wp - rhs) ! mom_flux_sum = sum(tau_x(ib:ie,jb:je,kb+1:ke) + tau_y(ib:ie,jb:je,kb+1:ke) + tau_z(ib:ie,jb:je,kb+1:ke)) ! call MPI_ALLREDUCE(mom_flux_sum, mom_flux_tot, 1, MY_REAL, MPI_SUM, comm3d, mpierr) ! if (myid == 0) then ! if (rk3step == 3) then ! inquire(file="mom_flux.txt", exist=mom_flux_file_exists) ! if (mom_flux_file_exists) then ! open(12, file="mom_flux.txt", status="old", position="append", action="write") ! else ! open(12, file="mom_flux.txt", status="new", action="write") ! end if ! write(12, *) timee, -mom_flux_tot ! close(12) ! end if ! end if end if call diffu_corr call diffv_corr call diffw_corr if (ltempeq .or. lmoist .or. lwritefac) then rhs = thlp totheatflux = 0 ! Reset total heat flux to zero so we only account for that in this step. totqflux = 0 call wallfunheat thl_flux(:,:,kb:ke+kh) = thl_flux(:,:,kb:ke+kh) + (thlp - rhs) if (ltempeq) call diffc_corr(thl0, thlp, ih, jh, kh) if (lmoist) call diffc_corr(qt0, qtp, ih, jh, kh) ! thl_flux_sum = sum(thl_flux(ib:ie,jb:je,kb+1:ke)) ! call MPI_ALLREDUCE(thl_flux_sum, thl_flux_tot, 1, MY_REAL, MPI_SUM, comm3d, mpierr) ! if (myid == 0) then ! if (rk3step == 3) then ! inquire(file="thl_flux.txt", exist=thl_flux_file_exists) ! if (thl_flux_file_exists) then ! open(12, file="thl_flux.txt", status="old", position="append", action="write") ! else ! open(12, file="thl_flux.txt", status="new", action="write") ! end if ! write(12, *) timee, thl_flux_tot ! close(12) ! end if ! end if end if do n = 1,nsv call diffc_corr(sv0(:,:,:,n), svp(:,:,:,n), ihc, jhc, khc) end do deallocate(rhs) if (lwritefac .and. rk3step==3) then if (myid == 0) then fac_tau_x_av = fac_tau_x_av + dt*fac_tau_x fac_tau_y_av = fac_tau_y_av + dt*fac_tau_y fac_tau_z_av = fac_tau_z_av + dt*fac_tau_z fac_pres_av = fac_pres_av + dt*fac_pres fac_htc_av = fac_htc_av + dt*fac_htc fac_cth_av = fac_cth_av + dt*fac_cth if (timee >= tnextfac) then tfac = timee - tfac allocate(varsfac(nfcts,nstatfac)) varsfac(:,1) = fac_tau_x_av(1:nfcts)/tfac varsfac(:,2) = fac_tau_y_av(1:nfcts)/tfac varsfac(:,3) = fac_tau_z_av(1:nfcts)/tfac varsfac(:,4) = fac_pres_av(1:nfcts)/tfac varsfac(:,5) = fac_htc_av(1:nfcts)/tfac varsfac(:,6) = fac_cth_av(1:nfcts)/tfac call writestat_nc(ncidfac,1,tncstatfac,(/timee/),nrecfac,.true.) call writestat_1D_nc(ncidfac,nstatfac,ncstatfac,varsfac,nrecfac,nfcts) deallocate(varsfac) tfac = timee tnextfac = NINT((timee + dtfac))*1.0 fac_tau_x_av = 0. fac_tau_y_av = 0. fac_tau_z_av = 0. fac_pres_av = 0. fac_htc_av = 0. fac_cth_av = 0. end if end if !myid end if end subroutine ibmwallfun