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

Allow TUV-x radiator data to be updated through the API #182

Merged
merged 32 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e6b2c2a
add radiator wrapper
boulderdaze Jul 19, 2024
63a3fa2
working-on file of radiator header
boulderdaze Jul 19, 2024
42e2817
fix typos, and incomplete parts
boulderdaze Jul 19, 2024
0f4d39a
code clean up
boulderdaze Jul 19, 2024
6cdef23
add radiator src
boulderdaze Jul 19, 2024
2267552
fix bugs
boulderdaze Jul 19, 2024
b85b1b0
fix bugs
boulderdaze Jul 19, 2024
c248e1e
fix bugs in c sources
boulderdaze Jul 22, 2024
90bd69a
fix bugs in f90 sources
boulderdaze Jul 22, 2024
21ac00e
fix bugs
boulderdaze Jul 24, 2024
f5256ad
temp add radiator test
boulderdaze Jul 24, 2024
5ac631d
fix bugs
boulderdaze Jul 24, 2024
0ae60e1
passed test
boulderdaze Jul 26, 2024
80349d4
incomplete test
boulderdaze Jul 31, 2024
9cc7ad3
temp file for transfer
boulderdaze Jul 31, 2024
7b8714b
working version
boulderdaze Aug 1, 2024
cab7fb0
fix test
boulderdaze Aug 1, 2024
29e42f6
fix bugs
boulderdaze Aug 2, 2024
a6f302d
fix fortran bugs
boulderdaze Aug 2, 2024
18d47ca
add radiator fortran test
boulderdaze Aug 3, 2024
0101fe3
test tag
boulderdaze Aug 3, 2024
f82d417
add fortran test
boulderdaze Aug 5, 2024
07cde7d
add tests back:
boulderdaze Aug 5, 2024
0f4294d
Merge branch 'main' into 122-make-radiator-updatable
boulderdaze Aug 5, 2024
72362cc
fix docker integration
boulderdaze Aug 5, 2024
ceb64d5
revert cmake
boulderdaze Aug 5, 2024
b75e012
clean up
boulderdaze Aug 5, 2024
3611be0
code cleanup
boulderdaze Aug 5, 2024
24e863c
code clean up
boulderdaze Aug 5, 2024
b30c733
revert back to main branch
boulderdaze Aug 5, 2024
d41d152
Address review comments
boulderdaze Aug 7, 2024
2a419e9
fix tuvx git tag
boulderdaze Aug 7, 2024
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
2 changes: 1 addition & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ if (MUSICA_ENABLE_TUVX AND MUSICA_BUILD_C_CXX_INTERFACE)
set(TUVX_INSTALL_INCLUDE_DIR ${MUSICA_INSTALL_INCLUDE_DIR} CACHE STRING "" FORCE)

set_git_default(TUVX_GIT_REPOSITORY https://github.com/NCAR/tuv-x.git)
set_git_default(TUVX_GIT_TAG 80f896a0fb591987c2a79209377bd6f599b4fb6f)
set_git_default(TUVX_GIT_TAG 674ee1e72853bb44d23c36602fa73c955b2f021d)

FetchContent_Declare(tuvx
GIT_REPOSITORY ${TUVX_GIT_REPOSITORY}
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ RUN dnf -y update \
gfortran \
gdb \
git \
lapack-devel \
lcov \
make \
netcdf-fortran-devel \
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.fortran-gcc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ RUN dnf -y update \
git \
hdf5-devel \
json-devel \
lapack-devel \
lcov \
libcurl-devel \
m4 \
Expand All @@ -38,6 +37,7 @@ RUN cd musica \
&& cmake -S . \
-B build \
-D CMAKE_BUILD_TYPE=${BUILD_TYPE} \
-D MUSICA_GIT_TAG=${MUSICA_GIT_TAG} \
-D MUSICA_BUILD_FORTRAN_INTERFACE=ON \
-D MUSICA_ENABLE_MEMCHECK=ON \
&& cd build \
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile.fortran-gcc.integration
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ RUN dnf -y update \
git \
hdf5-devel \
json-devel \
lapack-devel \
lcov \
libcurl-devel \
m4 \
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile.memcheck
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ RUN dnf -y update \
gfortran \
gdb \
git \
lapack-devel \
lcov \
make \
netcdf-fortran-devel \
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile.mpi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ RUN sudo dnf -y install \
gcc-c++ \
gfortran \
git \
lapack-devel \
lcov \
make \
netcdf-fortran-devel \
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile.mpi_openmp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ RUN sudo dnf -y install \
gcc-c++ \
gfortran \
git \
lapack-devel \
lcov \
make \
netcdf-fortran-devel \
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile.openmp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ RUN sudo dnf -y install \
gcc-c++ \
gfortran \
git \
lapack-devel \
lcov \
make \
netcdf-fortran-devel \
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile.python
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ RUN dnf -y update \
gcc-fortran \
gdb \
git \
lapack-devel \
make \
netcdf-fortran-devel \
pip \
Expand Down
2 changes: 1 addition & 1 deletion fortran/test/fetch_content_integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ if (MUSICA_ENABLE_TUVX)
copy_tuvx_data_dir ALL ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/../../../build/_deps/tuvx-src/data ${CMAKE_BINARY_DIR}/data
)
endif()
endif()
173 changes: 161 additions & 12 deletions fortran/test/fetch_content_integration/test_tuvx_api.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
!
program combined_tuvx_tests
use iso_c_binding
use musica_tuvx, only: tuvx_t, grid_map_t, grid_t, profile_map_t, profile_t
use musica_tuvx, only: tuvx_t, grid_map_t, grid_t, profile_map_t, profile_t, &
radiator_map_t, radiator_t
use musica_util, only: assert, error_t

implicit none
Expand Down Expand Up @@ -55,22 +56,36 @@ end subroutine test_tuvx_api_invalid_config

subroutine test_tuvx_solve()

type(tuvx_t), pointer :: tuvx
type(error_t) :: error
type(grid_map_t), pointer :: grids
character(len=256) :: config_path
type(grid_t), pointer :: grid
type(profile_map_t), pointer :: profiles
type(profile_t), pointer :: profile, profile_copy
real*8, dimension(5), target :: edges, edge_values, temp_edge
real*8, dimension(4), target :: midpoints, midpoint_values, layer_densities, temp_midpoint
real*8 :: temp_real
type(tuvx_t), pointer :: tuvx
type(error_t) :: error
character(len=256) :: config_path
type(grid_map_t), pointer :: grids
type(grid_t), pointer :: grid, height_grid, wavelength_grid
type(profile_map_t), pointer :: profiles
type(profile_t), pointer :: profile, profile_copy
type(radiator_map_t), pointer :: radiators
type(radiator_t), pointer :: radiator, radiator_copy
real*8, dimension(5), target :: edges, edge_values, temp_edge
real*8, dimension(4), target :: midpoints, midpoint_values, layer_densities, temp_midpoint
real*8 :: temp_real
integer :: num_vertical_layers, num_wavelength_bins
real*8, dimension(3,2), target :: optical_depths, temp_od
real*8, dimension(3,2), target :: single_scattering_albedos, temp_ssa
real*8, dimension(3,2,1), target :: asymmetry_factors, temp_asym

edges = (/ 1.0, 2.0, 3.0, 4.0, 5.0 /)
midpoints = (/ 15.0, 25.0, 35.0, 45.0 /)
edge_values = (/ 10.0, 20.0, 30.0, 40.0, 50.0 /)
midpoint_values = (/ 15.0, 25.0, 35.0, 45.0 /)
layer_densities = (/ 2.0, 4.0, 1.0, 7.0 /)
num_vertical_layers = 3
num_wavelength_bins = 2
optical_depths(:,1) = (/ 30.0, 20.0, 10.0 /)
optical_depths(:,2) = (/ 70.0, 80.0, 90.0 /)
single_scattering_albedos(:,1) = (/ 300.0, 200.0, 100.0 /)
single_scattering_albedos(:,2) = (/ 700.0, 800.0, 900.0 /)
asymmetry_factors(:,1,1) = (/ 3.0, 2.0, 1.0 /)
asymmetry_factors(:,2,1) = (/ 7.0, 8.0, 9.0 /)

config_path = "examples/ts1_tsmlt.json"

Expand Down Expand Up @@ -312,12 +327,146 @@ subroutine test_tuvx_solve()
ASSERT_EQ( temp_edge(3), 36.0 )
ASSERT_EQ( temp_edge(4), 38.0 )
ASSERT_EQ( temp_edge(5), 40.0 )


radiators => tuvx%get_radiators( error )
ASSERT( error%is_success() )

radiator => radiators%get( "foo_radiator", error )
ASSERT( .not. error%is_success() )
deallocate( radiator )
deallocate( radiators )

radiators =>radiator_map_t( error )
ASSERT( error%is_success() )

height_grid => grid_t( "height", "km", num_vertical_layers, error )
wavelength_grid => grid_t( "wavelength", "nm", num_wavelength_bins, error )
radiator => radiator_t( "foo_radiator", height_grid, wavelength_grid, error )
ASSERT( error%is_success() )

call radiator%set_optical_depths( optical_depths, error )
ASSERT( error%is_success() )

call radiator%get_optical_depths( temp_od, error )
ASSERT( error%is_success() )
ASSERT_EQ( temp_od(1,1), 30.0 )
ASSERT_EQ( temp_od(2,1), 20.0 )
ASSERT_EQ( temp_od(3,1), 10.0 )
ASSERT_EQ( temp_od(1,2), 70.0 )
ASSERT_EQ( temp_od(2,2), 80.0 )
ASSERT_EQ( temp_od(3,2), 90.0 )

call radiator%set_single_scattering_albedos( single_scattering_albedos, error )
ASSERT( error%is_success() )

call radiator%get_single_scattering_albedos( temp_ssa, error )
ASSERT( error%is_success() )
ASSERT_EQ( temp_ssa(1,1), 300.0 )
ASSERT_EQ( temp_ssa(2,1), 200.0 )
ASSERT_EQ( temp_ssa(3,1), 100.0 )
ASSERT_EQ( temp_ssa(1,2), 700.0 )
ASSERT_EQ( temp_ssa(2,2), 800.0 )
ASSERT_EQ( temp_ssa(3,2), 900.0 )

call radiator%set_asymmetry_factors( asymmetry_factors, error )
ASSERT( error%is_success() )

call radiator%get_asymmetry_factors( temp_asym, error )
ASSERT( error%is_success() )
ASSERT_EQ( temp_asym(1,1,1), 3.0 )
ASSERT_EQ( temp_asym(2,1,1), 2.0 )
ASSERT_EQ( temp_asym(3,1,1), 1.0 )
ASSERT_EQ( temp_asym(1,2,1), 7.0 )
ASSERT_EQ( temp_asym(2,2,1), 8.0 )
ASSERT_EQ( temp_asym(3,2,1), 9.0 )
!
call radiators%add( radiator, error )
radiator_copy => radiators%get( "foo_radiator", error )

optical_depths(:,:) = 0.0
single_scattering_albedos(:,:) = 0.0
asymmetry_factors(:,:,:) = 0.0

call radiator_copy%get_optical_depths( optical_depths, error )
ASSERT( error%is_success() )
ASSERT_EQ( optical_depths(1,1), 30.0 )
ASSERT_EQ( optical_depths(2,1), 20.0 )
ASSERT_EQ( optical_depths(3,1), 10.0 )
ASSERT_EQ( optical_depths(1,2), 70.0 )
ASSERT_EQ( optical_depths(2,2), 80.0 )
ASSERT_EQ( optical_depths(3,2), 90.0 )

call radiator_copy%get_single_scattering_albedos( single_scattering_albedos, error )
ASSERT( error%is_success() )
ASSERT_EQ( single_scattering_albedos(1,1), 300.0 )
ASSERT_EQ( single_scattering_albedos(2,1), 200.0 )
ASSERT_EQ( single_scattering_albedos(3,1), 100.0 )
ASSERT_EQ( single_scattering_albedos(1,2), 700.0 )
ASSERT_EQ( single_scattering_albedos(2,2), 800.0 )
ASSERT_EQ( single_scattering_albedos(3,2), 900.0 )

call radiator_copy%get_asymmetry_factors( asymmetry_factors, error )
ASSERT( error%is_success() )
ASSERT_EQ( asymmetry_factors(1,1,1), 3.0 )
ASSERT_EQ( asymmetry_factors(2,1,1), 2.0 )
ASSERT_EQ( asymmetry_factors(3,1,1), 1.0 )
ASSERT_EQ( asymmetry_factors(1,2,1), 7.0 )
ASSERT_EQ( asymmetry_factors(2,2,1), 8.0 )
ASSERT_EQ( asymmetry_factors(3,2,1), 9.0 )

optical_depths(:,1) = (/ 90.0, 80.0, 70.0 /)
optical_depths(:,2) = (/ 75.0, 85.0, 95.0 /)
single_scattering_albedos(:,1) = (/ 900.0, 800.0, 700.0 /)
single_scattering_albedos(:,2) = (/ 750.0, 850.0, 950.0 /)
asymmetry_factors(:,1,1) = (/ 9.0, 8.0, 7.0 /)
asymmetry_factors(:,2,1) = (/ 5.0, 4.0, 3.0 /)

call radiator_copy%set_optical_depths( optical_depths, error )
call radiator_copy%set_single_scattering_albedos( single_scattering_albedos, error )
call radiator_copy%set_asymmetry_factors( asymmetry_factors, error )
ASSERT( error%is_success() )

optical_depths(:,:) = 0.0
single_scattering_albedos(:,:) = 0.0
asymmetry_factors(:,:,:) = 0.0

call radiator%get_optical_depths( optical_depths, error )
ASSERT( error%is_success() )
ASSERT_EQ( optical_depths(1,1), 90.0 )
ASSERT_EQ( optical_depths(2,1), 80.0 )
ASSERT_EQ( optical_depths(3,1), 70.0 )
ASSERT_EQ( optical_depths(1,2), 75.0 )
ASSERT_EQ( optical_depths(2,2), 85.0 )
ASSERT_EQ( optical_depths(3,2), 95.0 )

call radiator%get_single_scattering_albedos( single_scattering_albedos, error )
ASSERT( error%is_success() )
ASSERT_EQ( single_scattering_albedos(1,1), 900.0 )
ASSERT_EQ( single_scattering_albedos(2,1), 800.0 )
ASSERT_EQ( single_scattering_albedos(3,1), 700.0 )
ASSERT_EQ( single_scattering_albedos(1,2), 750.0 )
ASSERT_EQ( single_scattering_albedos(2,2), 850.0 )
ASSERT_EQ( single_scattering_albedos(3,2), 950.0 )

call radiator%get_asymmetry_factors( asymmetry_factors, error )
ASSERT( error%is_success() )
ASSERT_EQ( asymmetry_factors(1,1,1), 9.0 )
ASSERT_EQ( asymmetry_factors(2,1,1), 8.0 )
ASSERT_EQ( asymmetry_factors(3,1,1), 7.0 )
ASSERT_EQ( asymmetry_factors(1,2,1), 5.0 )
ASSERT_EQ( asymmetry_factors(2,2,1), 4.0 )
ASSERT_EQ( asymmetry_factors(3,2,1), 3.0 )

deallocate( grid )
deallocate( grids )
deallocate( profile )
deallocate( profile_copy )
deallocate( profiles )
deallocate( radiator_copy )
deallocate( radiator )
deallocate( radiators )
deallocate( height_grid )
deallocate( wavelength_grid )
deallocate( tuvx )

end subroutine test_tuvx_solve
Expand Down
2 changes: 2 additions & 0 deletions fortran/tuvx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ target_sources(musica-fortran
grid_map.F90
profile.F90
profile_map.F90
radiator.F90
radiator_map.F90
tuvx.F90
)
2 changes: 1 addition & 1 deletion fortran/tuvx/grid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ end subroutine get_grid_midpoints_c
procedure :: set_edges
! Get grid edges
procedure :: get_edges
! Set the grid edges and midpoints
! Set the grid midpoints
procedure :: set_midpoints
! Get the grid midpoints
procedure :: get_midpoints
Expand Down
2 changes: 1 addition & 1 deletion fortran/tuvx/profile.F90
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module musica_tuvx_profile
interface
function create_profile_c(profile_name, profile_units, grid, error) &
bind(C, name="CreateProfile")
use iso_c_binding, only: c_ptr, c_char, c_size_t
use iso_c_binding, only: c_ptr, c_char
use musica_util, only: error_t_c
character(len=1, kind=c_char), intent(in) :: profile_name(*)
character(len=1, kind=c_char), intent(in) :: profile_units(*)
Expand Down
Loading
Loading