Skip to content

Commit

Permalink
got rid of funciton that sets albedo_fcn
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Nov 10, 2023
1 parent 1634881 commit 02bf66b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 56 deletions.
52 changes: 24 additions & 28 deletions photochem/cython/EvoAtmosphere.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -191,34 +191,6 @@ cdef class EvoAtmosphere:
pl._ptr = pl_ptr
return pl

def set_albedo_fcn(self, object fcn):
"""Sets a function describing a temperature dependent surface albedo.
This is useful for modeling the ice-albedo feedback.
Parameters
----------
fcn : function
A Numba cfunc that describes the temperature dependent surface albedo
"""
cdef uintptr_t fcn_l
cdef ea_pxd.temp_dependent_albedo_fcn fcn_c

if fcn is None:
fcn_l = 0
fcn_c = NULL
else:
argtypes = (ct.c_double,)
restype = ct.c_double
if not fcn.ctypes.argtypes == argtypes:
raise PhotoException("The callback function has the wrong argument types.")
if not fcn.ctypes.restype == restype:
raise PhotoException("The callback function has the wrong return type.")

fcn_l = fcn.address
fcn_c = <ea_pxd.temp_dependent_albedo_fcn> fcn_l

ea_pxd.evoatmosphere_set_albedo_fcn_wrapper(&self._ptr, fcn_c)

property T_surf:
"double. The surface temperature (K)"
def __get__(self):
Expand All @@ -237,6 +209,30 @@ cdef class EvoAtmosphere:
def __set__(self, double val):
ea_pxd.evoatmosphere_t_trop_set(&self._ptr, &val)

property albedo_fcn:
"""A function describing a temperature dependent surface albedo.
This is useful for modeling the ice-albedo feedback.
"""
def __set__(self, object fcn):
cdef uintptr_t fcn_l
cdef ea_pxd.temp_dependent_albedo_fcn fcn_c

if fcn is None:
fcn_l = 0
fcn_c = NULL
else:
argtypes = (ct.c_double,)
restype = ct.c_double
if not fcn.ctypes.argtypes == argtypes:
raise PhotoException("The callback function has the wrong argument types.")
if not fcn.ctypes.restype == restype:
raise PhotoException("The callback function has the wrong return type.")

fcn_l = fcn.address
fcn_c = <ea_pxd.temp_dependent_albedo_fcn> fcn_l

ea_pxd.evoatmosphere_albedo_fcn_set(&self._ptr, fcn_c)

property P_top_min:
"""double. When running the `evolve` routine, this determines
the minimum pressure of the top of the model domain (bars).
Expand Down
4 changes: 2 additions & 2 deletions photochem/cython/EvoAtmosphere_pxd.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ cdef extern void evoatmosphere_evolve_wrapper(void *ptr, char *filename,
cdef extern void evoatmosphere_production_and_loss_wrapper(void *ptr, char *species, int *nq,
int *nz, double *usol, double *top_atmos, void *pl_ptr, char *err)

cdef extern void evoatmosphere_set_albedo_fcn_wrapper(void *ptr, temp_dependent_albedo_fcn fcn)

# getters and setters
cdef extern void evoatmosphere_t_surf_get(void *ptr, double *val)
cdef extern void evoatmosphere_t_surf_set(void *ptr, double *val)

cdef extern void evoatmosphere_t_trop_get(void *ptr, double *val)
cdef extern void evoatmosphere_t_trop_set(void *ptr, double *val)

cdef extern void evoatmosphere_albedo_fcn_set(void *ptr, temp_dependent_albedo_fcn fcn)

cdef extern void evoatmosphere_p_top_min_get(void *ptr, double *val)
cdef extern void evoatmosphere_p_top_min_set(void *ptr, double *val)

Expand Down
28 changes: 14 additions & 14 deletions photochem/fortran/EvoAtmosphere_wrapper.f90
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,6 @@ subroutine evoatmosphere_production_and_loss_wrapper(ptr, species, nq, nz, usol,
endif
end subroutine

subroutine evoatmosphere_set_albedo_fcn_wrapper(ptr, albedo_fcn_c) bind(c)
use photochem_evoatmosphere, only: temp_dependent_albedo_fcn
type(c_ptr), intent(in) :: ptr
type(c_funptr), value, intent(in) :: albedo_fcn_c

procedure(temp_dependent_albedo_fcn), pointer :: albedo_fcn_f
type(EvoAtmosphere), pointer :: pc

call c_f_pointer(ptr, pc)
call c_f_procpointer(albedo_fcn_c, albedo_fcn_f)
call pc%set_albedo_fcn(albedo_fcn_f)

end subroutine

!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! getters and setters !!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand Down Expand Up @@ -236,6 +222,20 @@ subroutine evoatmosphere_t_trop_set(ptr, val) bind(c)
call c_f_pointer(ptr, pc)
pc%T_trop = val
end subroutine

subroutine evoatmosphere_albedo_fcn_set(ptr, albedo_fcn_c) bind(c)
use photochem_evoatmosphere, only: temp_dependent_albedo_fcn
type(c_ptr), intent(in) :: ptr
type(c_funptr), value, intent(in) :: albedo_fcn_c

procedure(temp_dependent_albedo_fcn), pointer :: albedo_fcn_f
type(EvoAtmosphere), pointer :: pc

call c_f_pointer(ptr, pc)
call c_f_procpointer(albedo_fcn_c, albedo_fcn_f)
pc%albedo_fcn => albedo_fcn_f

end subroutine

subroutine evoatmosphere_p_top_min_get(ptr, val) bind(c)
type(c_ptr), intent(in) :: ptr
Expand Down
6 changes: 0 additions & 6 deletions src/evoatmosphere/photochem_evoatmosphere.f90
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ function temp_dependent_albedo_fcn(T_surf) result(albedo)
procedure :: out2atmosphere_txt
procedure :: rebin_update_vertical_grid
procedure :: regrid_prep_atmosphere
procedure :: set_albedo_fcn

end type
interface EvoAtmosphere
Expand Down Expand Up @@ -211,11 +210,6 @@ module subroutine regrid_prep_atmosphere(self, usol_new, top_atmos, err)
character(:), allocatable, intent(out) :: err
end subroutine

module subroutine set_albedo_fcn(self, albedo_fcn)
class(EvoAtmosphere), target, intent(inout) :: self
procedure(temp_dependent_albedo_fcn), pointer :: albedo_fcn
end subroutine

end interface

end module
6 changes: 0 additions & 6 deletions src/evoatmosphere/photochem_evoatmosphere_utils.f90
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,4 @@ module subroutine regrid_prep_atmosphere(self, usol_new, top_atmos, err)

end subroutine

module subroutine set_albedo_fcn(self, albedo_fcn)
class(EvoAtmosphere), target, intent(inout) :: self
procedure(temp_dependent_albedo_fcn), pointer :: albedo_fcn
self%albedo_fcn => albedo_fcn
end subroutine

end submodule

0 comments on commit 02bf66b

Please sign in to comment.