Skip to content

Commit

Permalink
Merge pull request #538 from xylar/add-smooth-topo-tool
Browse files Browse the repository at this point in the history
Add ocean topography smoothing tool
  • Loading branch information
xylar authored Nov 21, 2023
2 parents e78dc20 + ef25978 commit 9e258a3
Show file tree
Hide file tree
Showing 8 changed files with 1,716 additions and 1 deletion.
12 changes: 11 additions & 1 deletion conda_package/recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ cp -r ocean landice visualization mesh_tools conda_package
cd conda_package
${PYTHON} -m pip install . --no-deps -vv

# build and install ocean topography smoothing tool
cd ${SRC_DIR}/conda_package/ocean/smooth_topo
mkdir build
cd build
cmake \
-D CMAKE_INSTALL_PREFIX=${PREFIX} \
-D CMAKE_BUILD_TYPE=Release \
..
cmake --build .
cmake --install .

# build and install sea ice partitioning tool
cd ${SRC_DIR}/conda_package/mesh_tools/seaice_grid_tools
mkdir build
Expand Down Expand Up @@ -40,4 +51,3 @@ cmake \
..
cmake --build .
cmake --install .

21 changes: 21 additions & 0 deletions ocean/smooth_topo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required (VERSION 3.0.2)
enable_language(Fortran)
project (ocean_smooth_topo)

list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

set (NETCDF_F90 "YES")
find_package (NetCDF REQUIRED)

message (STATUS "NETCDF_INCLUDES=${NETCDF_INCLUDES}")
message (STATUS "NETCDF_LIBRARIES=${NETCDF_LIBRARIES}")

include_directories(${NETCDF_INCLUDES})

add_executable (ocean_smooth_topo_skip_land_ice smooth_topo_skip_land_ice.F90)
target_link_libraries (ocean_smooth_topo_skip_land_ice ${NETCDF_LIBRARIES})

add_executable (ocean_smooth_topo_before_init smooth_topo_before_init.F90)
target_link_libraries (ocean_smooth_topo_before_init ${NETCDF_LIBRARIES})

install (TARGETS ocean_smooth_topo_skip_land_ice ocean_smooth_topo_before_init DESTINATION bin)
30 changes: 30 additions & 0 deletions ocean/smooth_topo/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Authors: Adrian Turner, Mat Maltrud

Tools for smoothing bathymetry in an MPAS-Ocean with a Gaussian filter with a
characteristic length scale (stdDeviation) and cut-off distance
(distanceLimit). Smoothing is applied over a given number of iterations
(numSmoothingPasses). The tools do not currently work on meshes without
ice-shelf cavities.

The smooth_topo_skip_land_ice tool can be applied to topography after an
initial condition has been created. The smoothing is only applied if the
original maxLevelCell is deeper than a given threshold (minLevelForSmoothing)
and ice-shelf cavities are ignored.

The smooth_topo_before_init tool is used to smooth topography data on the MPAS
mesh before an initial condition has been created.

An example namelist file (smooth_depth_in) is:

&smooth
filename_depth_in = "mpaso.IcoswISC30E3r2.20230901.nc"
filename_depth_out = "smooth.IcoswISC30E3r2.r200e100.1pass.min5.skipLandIce.231115.nc"
filename_mpas_mesh = "mpaso.IcoswISC30E3r2.20230901.nc"
distanceLimit = 200.
stdDeviation = 100.
numSmoothingPasses = 1
minLevelForSmoothing = 5
/

The minLevelForSmoothing namelist option only applies to
smooth_topo_skip_land_ice.
71 changes: 71 additions & 0 deletions ocean/smooth_topo/cmake/FindNetCDF.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# - Find NetCDF
# Find the native NetCDF includes and library
#
# NETCDF_INCLUDES - where to find netcdf.h, etc
# NETCDF_LIBRARIES - Link these libraries when using NetCDF
# NETCDF_FOUND - True if NetCDF found including required interfaces (see below)
#
# Your package can require certain interfaces to be FOUND by setting these
#
# NETCDF_CXX - require the C++ interface and link the C++ library
# NETCDF_F77 - require the F77 interface and link the fortran library
# NETCDF_F90 - require the F90 interface and link the fortran library
#
# The following are not for general use and are included in
# NETCDF_LIBRARIES if the corresponding option above is set.
#
# NETCDF_LIBRARIES_C - Just the C interface
# NETCDF_LIBRARIES_CXX - C++ interface, if available
# NETCDF_LIBRARIES_F77 - Fortran 77 interface, if available
# NETCDF_LIBRARIES_F90 - Fortran 90 interface, if available
#
# Normal usage would be:
# set (NETCDF_F90 "YES")
# find_package (NetCDF REQUIRED)
# target_link_libraries (uses_f90_interface ${NETCDF_LIBRARIES})
# target_link_libraries (only_uses_c_interface ${NETCDF_LIBRARIES_C})

if (NETCDF_INCLUDES AND NETCDF_LIBRARIES)
# Already in cache, be silent
set (NETCDF_FIND_QUIETLY TRUE)
endif (NETCDF_INCLUDES AND NETCDF_LIBRARIES)

find_path (NETCDF_INCLUDES netcdf.h
HINTS NETCDF_DIR ENV NETCDF_DIR)

find_library (NETCDF_LIBRARIES_C NAMES netcdf)
mark_as_advanced(NETCDF_LIBRARIES_C)

set (NetCDF_has_interfaces "YES") # will be set to NO if we're missing any interfaces
set (NetCDF_libs "${NETCDF_LIBRARIES_C}")

get_filename_component (NetCDF_lib_dirs "${NETCDF_LIBRARIES_C}" PATH)

macro (NetCDF_check_interface lang header libs)
if (NETCDF_${lang})
find_path (NETCDF_INCLUDES_${lang} NAMES ${header}
HINTS "${NETCDF_INCLUDES}" NO_DEFAULT_PATH)
find_library (NETCDF_LIBRARIES_${lang} NAMES ${libs}
HINTS "${NetCDF_lib_dirs}" NO_DEFAULT_PATH)
mark_as_advanced (NETCDF_INCLUDES_${lang} NETCDF_LIBRARIES_${lang})
if (NETCDF_INCLUDES_${lang} AND NETCDF_LIBRARIES_${lang})
list (INSERT NetCDF_libs 0 ${NETCDF_LIBRARIES_${lang}}) # prepend so that -lnetcdf is last
else (NETCDF_INCLUDES_${lang} AND NETCDF_LIBRARIES_${lang})
set (NetCDF_has_interfaces "NO")
message (STATUS "Failed to find NetCDF interface for ${lang}")
endif (NETCDF_INCLUDES_${lang} AND NETCDF_LIBRARIES_${lang})
endif (NETCDF_${lang})
endmacro (NetCDF_check_interface)

NetCDF_check_interface (CXX netcdfcpp.h netcdf_c++)
NetCDF_check_interface (F77 netcdf.inc netcdff)
NetCDF_check_interface (F90 netcdf.mod netcdff)

set (NETCDF_LIBRARIES "${NetCDF_libs}" CACHE STRING "All NetCDF libraries required for interface level")

# handle the QUIETLY and REQUIRED arguments and set NETCDF_FOUND to TRUE if
# all listed variables are TRUE
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (NetCDF DEFAULT_MSG NETCDF_LIBRARIES NETCDF_INCLUDES NetCDF_has_interfaces)

mark_as_advanced (NETCDF_LIBRARIES NETCDF_INCLUDES)
23 changes: 23 additions & 0 deletions ocean/smooth_topo/cmake/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright $(git shortlog -s)
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions ocean/smooth_topo/cmake/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
These files are from https://github.com/jedbrown/cmake-modules
Loading

0 comments on commit 9e258a3

Please sign in to comment.