Skip to content

Commit 9e258a3

Browse files
authored
Merge pull request #538 from xylar/add-smooth-topo-tool
Add ocean topography smoothing tool
2 parents e78dc20 + ef25978 commit 9e258a3

File tree

8 files changed

+1716
-1
lines changed

8 files changed

+1716
-1
lines changed

conda_package/recipe/build.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ cp -r ocean landice visualization mesh_tools conda_package
88
cd conda_package
99
${PYTHON} -m pip install . --no-deps -vv
1010

11+
# build and install ocean topography smoothing tool
12+
cd ${SRC_DIR}/conda_package/ocean/smooth_topo
13+
mkdir build
14+
cd build
15+
cmake \
16+
-D CMAKE_INSTALL_PREFIX=${PREFIX} \
17+
-D CMAKE_BUILD_TYPE=Release \
18+
..
19+
cmake --build .
20+
cmake --install .
21+
1122
# build and install sea ice partitioning tool
1223
cd ${SRC_DIR}/conda_package/mesh_tools/seaice_grid_tools
1324
mkdir build
@@ -40,4 +51,3 @@ cmake \
4051
..
4152
cmake --build .
4253
cmake --install .
43-

ocean/smooth_topo/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required (VERSION 3.0.2)
2+
enable_language(Fortran)
3+
project (ocean_smooth_topo)
4+
5+
list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
6+
7+
set (NETCDF_F90 "YES")
8+
find_package (NetCDF REQUIRED)
9+
10+
message (STATUS "NETCDF_INCLUDES=${NETCDF_INCLUDES}")
11+
message (STATUS "NETCDF_LIBRARIES=${NETCDF_LIBRARIES}")
12+
13+
include_directories(${NETCDF_INCLUDES})
14+
15+
add_executable (ocean_smooth_topo_skip_land_ice smooth_topo_skip_land_ice.F90)
16+
target_link_libraries (ocean_smooth_topo_skip_land_ice ${NETCDF_LIBRARIES})
17+
18+
add_executable (ocean_smooth_topo_before_init smooth_topo_before_init.F90)
19+
target_link_libraries (ocean_smooth_topo_before_init ${NETCDF_LIBRARIES})
20+
21+
install (TARGETS ocean_smooth_topo_skip_land_ice ocean_smooth_topo_before_init DESTINATION bin)

ocean/smooth_topo/README

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Authors: Adrian Turner, Mat Maltrud
2+
3+
Tools for smoothing bathymetry in an MPAS-Ocean with a Gaussian filter with a
4+
characteristic length scale (stdDeviation) and cut-off distance
5+
(distanceLimit). Smoothing is applied over a given number of iterations
6+
(numSmoothingPasses). The tools do not currently work on meshes without
7+
ice-shelf cavities.
8+
9+
The smooth_topo_skip_land_ice tool can be applied to topography after an
10+
initial condition has been created. The smoothing is only applied if the
11+
original maxLevelCell is deeper than a given threshold (minLevelForSmoothing)
12+
and ice-shelf cavities are ignored.
13+
14+
The smooth_topo_before_init tool is used to smooth topography data on the MPAS
15+
mesh before an initial condition has been created.
16+
17+
An example namelist file (smooth_depth_in) is:
18+
19+
&smooth
20+
filename_depth_in = "mpaso.IcoswISC30E3r2.20230901.nc"
21+
filename_depth_out = "smooth.IcoswISC30E3r2.r200e100.1pass.min5.skipLandIce.231115.nc"
22+
filename_mpas_mesh = "mpaso.IcoswISC30E3r2.20230901.nc"
23+
distanceLimit = 200.
24+
stdDeviation = 100.
25+
numSmoothingPasses = 1
26+
minLevelForSmoothing = 5
27+
/
28+
29+
The minLevelForSmoothing namelist option only applies to
30+
smooth_topo_skip_land_ice.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# - Find NetCDF
2+
# Find the native NetCDF includes and library
3+
#
4+
# NETCDF_INCLUDES - where to find netcdf.h, etc
5+
# NETCDF_LIBRARIES - Link these libraries when using NetCDF
6+
# NETCDF_FOUND - True if NetCDF found including required interfaces (see below)
7+
#
8+
# Your package can require certain interfaces to be FOUND by setting these
9+
#
10+
# NETCDF_CXX - require the C++ interface and link the C++ library
11+
# NETCDF_F77 - require the F77 interface and link the fortran library
12+
# NETCDF_F90 - require the F90 interface and link the fortran library
13+
#
14+
# The following are not for general use and are included in
15+
# NETCDF_LIBRARIES if the corresponding option above is set.
16+
#
17+
# NETCDF_LIBRARIES_C - Just the C interface
18+
# NETCDF_LIBRARIES_CXX - C++ interface, if available
19+
# NETCDF_LIBRARIES_F77 - Fortran 77 interface, if available
20+
# NETCDF_LIBRARIES_F90 - Fortran 90 interface, if available
21+
#
22+
# Normal usage would be:
23+
# set (NETCDF_F90 "YES")
24+
# find_package (NetCDF REQUIRED)
25+
# target_link_libraries (uses_f90_interface ${NETCDF_LIBRARIES})
26+
# target_link_libraries (only_uses_c_interface ${NETCDF_LIBRARIES_C})
27+
28+
if (NETCDF_INCLUDES AND NETCDF_LIBRARIES)
29+
# Already in cache, be silent
30+
set (NETCDF_FIND_QUIETLY TRUE)
31+
endif (NETCDF_INCLUDES AND NETCDF_LIBRARIES)
32+
33+
find_path (NETCDF_INCLUDES netcdf.h
34+
HINTS NETCDF_DIR ENV NETCDF_DIR)
35+
36+
find_library (NETCDF_LIBRARIES_C NAMES netcdf)
37+
mark_as_advanced(NETCDF_LIBRARIES_C)
38+
39+
set (NetCDF_has_interfaces "YES") # will be set to NO if we're missing any interfaces
40+
set (NetCDF_libs "${NETCDF_LIBRARIES_C}")
41+
42+
get_filename_component (NetCDF_lib_dirs "${NETCDF_LIBRARIES_C}" PATH)
43+
44+
macro (NetCDF_check_interface lang header libs)
45+
if (NETCDF_${lang})
46+
find_path (NETCDF_INCLUDES_${lang} NAMES ${header}
47+
HINTS "${NETCDF_INCLUDES}" NO_DEFAULT_PATH)
48+
find_library (NETCDF_LIBRARIES_${lang} NAMES ${libs}
49+
HINTS "${NetCDF_lib_dirs}" NO_DEFAULT_PATH)
50+
mark_as_advanced (NETCDF_INCLUDES_${lang} NETCDF_LIBRARIES_${lang})
51+
if (NETCDF_INCLUDES_${lang} AND NETCDF_LIBRARIES_${lang})
52+
list (INSERT NetCDF_libs 0 ${NETCDF_LIBRARIES_${lang}}) # prepend so that -lnetcdf is last
53+
else (NETCDF_INCLUDES_${lang} AND NETCDF_LIBRARIES_${lang})
54+
set (NetCDF_has_interfaces "NO")
55+
message (STATUS "Failed to find NetCDF interface for ${lang}")
56+
endif (NETCDF_INCLUDES_${lang} AND NETCDF_LIBRARIES_${lang})
57+
endif (NETCDF_${lang})
58+
endmacro (NetCDF_check_interface)
59+
60+
NetCDF_check_interface (CXX netcdfcpp.h netcdf_c++)
61+
NetCDF_check_interface (F77 netcdf.inc netcdff)
62+
NetCDF_check_interface (F90 netcdf.mod netcdff)
63+
64+
set (NETCDF_LIBRARIES "${NetCDF_libs}" CACHE STRING "All NetCDF libraries required for interface level")
65+
66+
# handle the QUIETLY and REQUIRED arguments and set NETCDF_FOUND to TRUE if
67+
# all listed variables are TRUE
68+
include (FindPackageHandleStandardArgs)
69+
find_package_handle_standard_args (NetCDF DEFAULT_MSG NETCDF_LIBRARIES NETCDF_INCLUDES NetCDF_has_interfaces)
70+
71+
mark_as_advanced (NETCDF_LIBRARIES NETCDF_INCLUDES)

ocean/smooth_topo/cmake/LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright $(git shortlog -s)
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice, this
11+
list of conditions and the following disclaimer in the documentation and/or
12+
other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

ocean/smooth_topo/cmake/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
These files are from https://github.com/jedbrown/cmake-modules

0 commit comments

Comments
 (0)