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

Mixed precision topography_mod #1250

Merged
merged 49 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
8a8f0ce
Seperate routines/functions
mcallic2 Dec 16, 2022
ea2f24a
Create macros
mcallic2 Dec 16, 2022
cfe8491
Adds include statements
mcallic2 Dec 19, 2022
75de129
Adds include and header files
mcallic2 Dec 19, 2022
4cc88fc
Adds fms kind to real declarations
mcallic2 Dec 19, 2022
f3a29c2
Adds fms kind around real numbers
mcallic2 Dec 19, 2022
6003889
Adds r8_kind to real variables and numbers in .F90 scripts
mcallic2 Dec 19, 2022
cd1c409
Adds interfaces, changes module procedures
mcallic2 Dec 19, 2022
b02be55
Spelling mistake
mcallic2 Dec 19, 2022
3c496e4
Fix include statement
mcallic2 Dec 20, 2022
6434674
Merge branch 'NOAA-GFDL:main' into topography
mcallic2 Dec 23, 2022
8d62b7b
Merge mixedmode 2023.01_mm
mcallic2 Apr 18, 2023
4b26098
merge mixedmode
mcallic2 Jun 7, 2023
e5dba69
add precision to module variables
mcallic2 Jun 7, 2023
a355b8b
fix spelling mistake
mcallic2 Jun 7, 2023
bbc3911
add kind parameter
mcallic2 Jun 7, 2023
d6f4fb1
merge
mcallic2 Jun 7, 2023
8ee9de3
trim trailing whitespace
mcallic2 Jul 17, 2023
a132932
add topography/include to cmake
mcallic2 Jul 17, 2023
08abb9c
change to flag path
mcallic2 Jul 17, 2023
3b3e1fd
begin adding unit tests for module
mcallic2 Jul 17, 2023
3b38ab5
merge mixed mode
mcallic2 Jul 17, 2023
bb4d1a7
forgetting include path
mcallic2 Jul 18, 2023
08c1ed7
trim trailing whitespace
mcallic2 Jul 18, 2023
6068731
that should stay an integer
mcallic2 Jul 18, 2023
9195444
need to stay integers
mcallic2 Jul 27, 2023
76d2ed5
merge mixedmode
mcallic2 Jul 28, 2023
10cbb64
merge mixedmode
mcallic2 Aug 2, 2023
7bc1823
need to start a seperate branch/pr for unit tests
mcallic2 Aug 16, 2023
6950d2c
unit tests to be in seperate pr
mcallic2 Aug 16, 2023
3637847
Merge branch 'mixedmode' into topography
mcallic2 Aug 16, 2023
1e00d9d
unit tests in seperate pr
mcallic2 Aug 16, 2023
c997d69
merge topography
mcallic2 Aug 16, 2023
5c637e6
missed test_fms makefile
mcallic2 Aug 16, 2023
b7400af
these are indices
mcallic2 Aug 28, 2023
7c63c01
Merge branch 'mixedmode' into topography
mcallic2 Aug 28, 2023
85b0345
removes unecessary precision
mcallic2 Aug 29, 2023
37ddf2f
merge mixedmode
mcallic2 Aug 29, 2023
6fde163
merge changes
mcallic2 Aug 29, 2023
58cd3d1
update topography
Aug 29, 2023
9b2d811
change to r4_kind in open_file
Aug 29, 2023
9dbd326
Merge pull request #5 from mlee03/mm_topography
mcallic2 Aug 30, 2023
7be92cd
change precision to r8_kind for mod variables
mcallic2 Aug 30, 2023
b55e5da
change comment block for documentation
mcallic2 Aug 30, 2023
d9ed145
fixed indentation
mcallic2 Aug 30, 2023
f39b7c4
removes repetative random_numbers
mcallic2 Aug 30, 2023
6c7b785
remove print statement
mcallic2 Aug 30, 2023
be19229
moves comments
mcallic2 Aug 31, 2023
23548a3
fixes conversion error
mcallic2 Aug 31, 2023
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
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ foreach(kind ${kinds})
random_numbers/include
diag_manager/include
constants4
topography/include
axis_utils/include
constants
astronomy/include
Expand Down Expand Up @@ -362,9 +363,10 @@ foreach(kind ${kinds})
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/horiz_interp/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/string_utils/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/mpp/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/topography/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/random_numbers/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/diag_integral/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/diag_manager/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/random_numbers/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tracer_manager/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/interpolator/include>)

Expand Down
26 changes: 21 additions & 5 deletions topography/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,34 @@
# Ed Hartnett 2/22/19

# Include .h and .mod files.
AM_CPPFLAGS = -I$(top_srcdir)/include
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/topography/include

AM_FCFLAGS = $(FC_MODINC). $(FC_MODOUT)$(MODDIR)

# Build these uninstalled convenience libraries.
noinst_LTLIBRARIES = libtopography.la

# Each convenience library depends on its source.
libtopography_la_SOURCES = \
topography.F90 \
gaussian_topog.F90

topography_mod.$(FC_MODEXT): gaussian_topog_mod.$(FC_MODEXT)
topography.F90 \
include/topography_r4.fh \
include/topography_r8.fh \
include/topography.inc \
gaussian_topog.F90 \
include/gaussian_topog_r4.fh \
include/gaussian_topog_r8.fh \
include/gaussian_topog.inc

gaussian_topog_mod.$(FC_MODEXT): \
include/gaussian_topog_r4.fh \
include/gaussian_topog_r8.fh \
include/gaussian_topog.inc

topography_mod.$(FC_MODEXT): \
gaussian_topog_mod.$(FC_MODEXT) \
include/topography_r4.fh \
include/topography_r8.fh \
include/topography.inc

# Mod files are built and then installed as headers.
MODFILES = \
Expand Down
141 changes: 20 additions & 121 deletions topography/gaussian_topog.F90
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,22 @@ module gaussian_topog_mod
use constants_mod, only: pi

use mpp_mod, only: input_nml_file
use platform_mod, only: r4_kind, r8_kind

implicit none
private

public :: gaussian_topog_init, get_gaussian_topog

interface gaussian_topog_init
module procedure gaussian_topog_init_r4
module procedure gaussian_topog_init_r8
end interface gaussian_topog_init

interface get_gaussian_topog
module procedure get_gaussian_topog_r4, get_gaussian_topog_r8
end interface get_gaussian_topog

!-----------------------------------------------------------------------
! <NAMELIST NAME="gaussian_topog_nml">
! <DATA NAME="height" UNITS="meter" TYPE="real" DIM="(mxmtns)" DEFAULT="0.">
Expand All @@ -71,13 +81,13 @@ module gaussian_topog_mod

integer, parameter :: maxmts = 10

real, dimension(maxmts) :: height = 0.
real, dimension(maxmts) :: olon = 0.
real, dimension(maxmts) :: olat = 0.
real, dimension(maxmts) :: wlon = 0.
real, dimension(maxmts) :: wlat = 0.
real, dimension(maxmts) :: rlon = 0.
real, dimension(maxmts) :: rlat = 0.
real(kind=r8_kind), dimension(maxmts) :: height = 0.0_r8_kind
real(kind=r8_kind), dimension(maxmts) :: olon = 0.0_r8_kind
real(kind=r8_kind), dimension(maxmts) :: olat = 0.0_r8_kind
real(kind=r8_kind), dimension(maxmts) :: wlon = 0.0_r8_kind
real(kind=r8_kind), dimension(maxmts) :: wlat = 0.0_r8_kind
real(kind=r8_kind), dimension(maxmts) :: rlon = 0.0_r8_kind
real(kind=r8_kind), dimension(maxmts) :: rlat = 0.0_r8_kind

namelist /gaussian_topog_nml/ height, olon, olat, wlon, wlat, rlon, rlat
! </NAMELIST>
Expand All @@ -96,120 +106,6 @@ module gaussian_topog_mod

!#######################################################################

!> Returns a surface height field that consists
!! of the sum of one or more Gaussian-shaped mountains.
!!
!> Returns a land surface topography that consists of a "set" of
!! simple Gaussian-shaped mountains. The height, position,
!! width, and elongation of the mountains can be controlled
!! by variables in the namelist.
subroutine gaussian_topog_init ( lon, lat, zsurf )

real, intent(in) :: lon(:) !< The mean grid box longitude in radians
real, intent(in) :: lat(:) !< The mean grid box latitude in radians
real, intent(out) :: zsurf(:,:) !< The surface height (meters). Size must be size(lon) by size(lat)

integer :: n

if (.not.module_is_initialized) then
call write_version_number("GAUSSIAN_TOPOG_MOD", version)
endif

if(any(shape(zsurf) /= (/size(lon(:)),size(lat(:))/))) then
call error_mesg ('get_gaussian_topog in topography_mod', &
'shape(zsurf) is not equal to (/size(lon),size(lat)/)', FATAL)
endif

if (do_nml) call read_namelist

! compute sum of all non-zero mountains
zsurf(:,:) = 0.
do n = 1, maxmts
if ( height(n) == 0. ) cycle
zsurf = zsurf + get_gaussian_topog ( lon, lat, height(n), &
olon(n), olat(n), wlon(n), wlat(n), rlon(n), rlat(n))
enddo
module_is_initialized = .TRUE.

end subroutine gaussian_topog_init

!#######################################################################

!> @brief Returns a simple surface height field that consists of a single
!! Gaussian-shaped mountain.
!!
!> The height, position, width, and elongation of the mountain
!! is controlled by optional arguments.
!! @param real lon The mean grid box longitude in radians.
!! @param real lat The mean grid box latitude in radians.
!! @param real height Maximum surface height in meters.
!! @param real olond, olatd Position/origin of mountain in degrees longitude and latitude.
!! This is the location of the maximum height.
!! @param real wlond, wlatd Gaussian half-width of mountain in degrees longitude and latitude.
!! @param real rlond, rlatd Ridge half-width of mountain in degrees longitude and latitude.
!! This is the elongation of the maximum height.
!! @param real zsurf The surface height (in meters).
!! The size of the returned field is size(lon) by size(lat).
!! </OUT>
!!
!! @throws FATAL shape(zsurf) is not equal to (/size(lon),size(lat)/)
!! Check the input grid size and output field size.
!! The input grid is defined at the midpoint of grid boxes.
!!
!! @note
!! Mountains do not wrap around the poles.
!
!! <br>Example usage:
!! @code{.F90} zsurf = <B>get_gaussian_topog</B> ( lon, lat, height
!! [, olond, olatd, wlond, wlatd, rlond, rlatd ] )@endcode
function get_gaussian_topog ( lon, lat, height, &
olond, olatd, wlond, wlatd, rlond, rlatd ) &
result ( zsurf )

real, intent(in) :: lon(:), lat(:)
real, intent(in) :: height
real, intent(in), optional :: olond, olatd, wlond, wlatd, rlond, rlatd
real :: zsurf(size(lon,1),size(lat,1))

integer :: i, j
real :: olon, olat, wlon, wlat, rlon, rlat
real :: tpi, dtr, dx, dy, xx, yy

if (do_nml) call read_namelist

! no need to compute mountain if height=0
if ( height == 0. ) then
zsurf(:,:) = 0.
return
endif

tpi = 2.0*pi
dtr = tpi/360.

! defaults and convert degrees to radians (dtr)
olon = 90.*dtr; if (present(olond)) olon=olond*dtr
olat = 45.*dtr; if (present(olatd)) olat=olatd*dtr
wlon = 15.*dtr; if (present(wlond)) wlon=wlond*dtr
wlat = 15.*dtr; if (present(wlatd)) wlat=wlatd*dtr
rlon = 0. ; if (present(rlond)) rlon=rlond*dtr
rlat = 0. ; if (present(rlatd)) rlat=rlatd*dtr

! compute gaussian-shaped mountain
do j=1,size(lat(:))
dy = abs(lat(j) - olat) ! dist from y origin
yy = max(0., dy-rlat)/wlat
do i=1,size(lon(:))
dx = abs(lon(i) - olon) ! dist from x origin
dx = min(dx, abs(dx-tpi)) ! To ensure that: -pi <= dx <= pi
xx = max(0., dx-rlon)/wlon
zsurf(i,j) = height*exp(-xx**2 - yy**2)
enddo
enddo

end function get_gaussian_topog

!#######################################################################

subroutine read_namelist

integer :: unit, ierr, io
Expand All @@ -232,6 +128,9 @@ end subroutine read_namelist

!#######################################################################

#include "gaussian_topog_r4.fh"
#include "gaussian_topog_r8.fh"

end module gaussian_topog_mod

! <INFO>
Expand Down
Loading
Loading