Skip to content

Commit

Permalink
clima update. futils update. forwarddiff update.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Apr 13, 2024
1 parent d5077b6 commit 84f3992
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 79 deletions.
2 changes: 1 addition & 1 deletion src/atmosphere/photochem_atmosphere_utils.f90
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ module subroutine set_press_temp_edd(self, P, T, edd, trop_p, err)
z_ = var%z
z_ = z_(var%nz:1:-1)

call interp(1, var%nz, [log10(trop_p)], log10P_wrk, z_, trop_alt(1), ierr)
call interp(1, var%nz, [log10(trop_p)], log10P_wrk, z_, trop_alt, ierr)
if (ierr /= 0) then
err = 'Subroutine interp returned an error.'
return
Expand Down
12 changes: 6 additions & 6 deletions src/dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

CPMAddPackage(
NAME futils
VERSION 0.1.7
VERSION 0.1.8
GITHUB_REPOSITORY "Nicholaswogan/futils"
GIT_TAG "v0.1.7"
GIT_TAG "v0.1.8"
EXCLUDE_FROM_ALL ON
)

Expand Down Expand Up @@ -49,24 +49,24 @@ CPMAddPackage(

CPMAddPackage(
NAME clima
VERSION 0.4.2
VERSION 0.4.3
OPTIONS
"BUILD_EXECUTABLE OFF"
"BUILD_WITH_OPENMP ${BUILD_WITH_OPENMP}"
"SKBUILD ${SKBUILD}"
"BUILD_PYTHON_CLIMA ${BUILD_PYTHON_PHOTOCHEM}"
"PYTHON_CLIMA_DESTINATION photochem"
GITHUB_REPOSITORY "Nicholaswogan/clima"
GIT_TAG "v0.4.2"
GIT_TAG "v0.4.3"
EXCLUDE_FROM_ALL OFF
)

CPMAddPackage(
NAME forwarddiff
VERSION 0.1.1
VERSION 0.1.2
OPTIONS
"BUILD_EXECUTABLE OFF"
GITHUB_REPOSITORY "Nicholaswogan/forwarddiff"
GIT_TAG "v0.1.1"
GIT_TAG "v0.1.2"
EXCLUDE_FROM_ALL ON
)
8 changes: 4 additions & 4 deletions src/evoatmosphere/photochem_evoatmosphere_utils.f90
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ module subroutine set_press_temp_edd(self, P, T, edd, trop_p, hydro_pressure, er
z_ = var%z
z_ = z_(var%nz:1:-1)

call interp(1, var%nz, [log10(trop_p)], log10P_wrk, z_, trop_alt(1), ierr)
call interp(1, var%nz, [log10(trop_p)], log10P_wrk, z_, trop_alt, ierr)
if (ierr /= 0) then
err = 'Subroutine interp returned an error.'
return
Expand Down Expand Up @@ -605,7 +605,7 @@ subroutine properties_for_new_TOA(self, usol, top_atmos_new, &
particle_radius_new, pressure_new, err)
use photochem_enum, only: DensityBC, PressureBC
use futils, only: interp
use photochem_eqns, only: vertical_grid, molar_weight, press_and_den, gravity, interp_new
use photochem_eqns, only: vertical_grid, molar_weight, press_and_den, gravity
use photochem_const, only: small_real, k_boltz
class(EvoAtmosphere), target, intent(inout) :: self
real(dp), intent(in) :: usol(:,:)
Expand Down Expand Up @@ -662,7 +662,7 @@ subroutine properties_for_new_TOA(self, usol, top_atmos_new, &
enddo
! Interpolate mixing ratios, with constant extrapolation
do i = 1,dat%nq
call interp_new(z_new, var%z, log10(max(mix(i,:),small_real)), mix_new(i,:), ierr=ierr)
call interp(z_new, var%z, log10(max(mix(i,:),small_real)), mix_new(i,:), ierr=ierr)
if (ierr /= 0) then
err = 'Subroutine interp returned an error.'
return
Expand All @@ -671,7 +671,7 @@ subroutine properties_for_new_TOA(self, usol, top_atmos_new, &
mix_new = 10.0_dp**mix_new

! Interpolate density, with linear extrapolation
call interp_new(z_new, var%z, log10(density), density_new, linear_extrap=.true., ierr=ierr)
call interp(z_new, var%z, log10(density), density_new, linear_extrap=.true., ierr=ierr)
if (ierr /= 0) then
err = 'Subroutine interp returned an error.'
return
Expand Down
3 changes: 1 addition & 2 deletions src/input/photochem_input_after_read.f90
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ subroutine interp2atmosfile_mixconserving(dat, var, err)

subroutine interp2atmosfile_mix(dat, var, err)
use futils, only: interp
use photochem_eqns, only: interp_new
use photochem_const, only: small_real
type(PhotochemData), intent(in) :: dat
type(PhotochemVars), intent(inout) :: var
Expand All @@ -174,7 +173,7 @@ subroutine interp2atmosfile_mix(dat, var, err)
allocate(density(var%nz))

! Interpolate file density to model grid
call interp_new(var%z, dat%z_file, log10(dat%den_file), density, linear_extrap=.true., ierr=ierr)
call interp(var%z, dat%z_file, log10(dat%den_file), density, linear_extrap=.true., ierr=ierr)
if (ierr /= 0) then
err = 'Subroutine interp returned an error.'
return
Expand Down
66 changes: 0 additions & 66 deletions src/photochem_eqns.f90
Original file line number Diff line number Diff line change
Expand Up @@ -364,70 +364,4 @@ pure function zahnle_Hescape_coeff(S1) result(coeff)

end function

!> Better new interp that allows for linear extrapolation.
subroutine interp_new(xg, x, y, yg, linear_extrap, ierr)
use futils, only: interp
real(dp), intent(in) :: xg(:) !! new grid
real(dp), intent(in) :: x(:), y(:) !! old data
real(dp), intent(out) :: yg(:) !! new data
logical, optional, intent(in) :: linear_extrap
integer, optional, intent(out) :: ierr

logical :: linear_extrap_
integer :: ng, n
real(dp), allocatable :: x_copy(:), y_copy(:)
real(dp) :: slope, intercept, tmp

ng = size(xg)
n = size(x)

if (present(ierr)) then
ierr = 0
if (ng /= size(yg)) then
ierr = -3
return
endif
if (n /= size(y)) then
ierr = -4
return
endif
if (n < 2) then
ierr = -5
return
endif
endif

if (present(linear_extrap)) then
linear_extrap_ = linear_extrap
else
linear_extrap_ = .false.
endif

if (.not.linear_extrap_) then
call interp(ng, n, xg, x, y, yg, ierr)
return
endif

! We do linear extrapolation
x_copy = x
y_copy = y
if (xg(ng) > x(n)) then
slope = (y(n) - y(n-1))/(x(n) - x(n-1))
intercept = y(n) - slope*x(n)
tmp = slope*xg(ng) + intercept
x_copy = [x_copy,xg(ng)]
y_copy = [y_copy,tmp]
endif
if (xg(1) < x(1)) then
slope = (y(2) - y(1))/(x(2) - x(1))
intercept = y(1) - slope*x(1)
tmp = slope*xg(1) + intercept
x_copy = [xg(1),x_copy]
y_copy = [tmp,y_copy]
endif

call interp(ng, size(x_copy), xg, x_copy, y_copy, yg, ierr)

end subroutine

end module

0 comments on commit 84f3992

Please sign in to comment.