diff --git a/photochem/cython/EvoAtmosphere.pyx b/photochem/cython/EvoAtmosphere.pyx index 290e05d..0857c7e 100644 --- a/photochem/cython/EvoAtmosphere.pyx +++ b/photochem/cython/EvoAtmosphere.pyx @@ -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 = fcn_l - - ea_pxd.evoatmosphere_set_albedo_fcn_wrapper(&self._ptr, fcn_c) - property T_surf: "double. The surface temperature (K)" def __get__(self): @@ -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 = 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). diff --git a/photochem/cython/EvoAtmosphere_pxd.pxd b/photochem/cython/EvoAtmosphere_pxd.pxd index 69d1ed9..520f285 100644 --- a/photochem/cython/EvoAtmosphere_pxd.pxd +++ b/photochem/cython/EvoAtmosphere_pxd.pxd @@ -26,8 +26,6 @@ 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) @@ -35,6 +33,8 @@ 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) diff --git a/photochem/fortran/EvoAtmosphere_wrapper.f90 b/photochem/fortran/EvoAtmosphere_wrapper.f90 index 28df811..f60f29c 100644 --- a/photochem/fortran/EvoAtmosphere_wrapper.f90 +++ b/photochem/fortran/EvoAtmosphere_wrapper.f90 @@ -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 !!! !!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -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 diff --git a/src/evoatmosphere/photochem_evoatmosphere.f90 b/src/evoatmosphere/photochem_evoatmosphere.f90 index 8f99283..5c794df 100644 --- a/src/evoatmosphere/photochem_evoatmosphere.f90 +++ b/src/evoatmosphere/photochem_evoatmosphere.f90 @@ -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 @@ -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 \ No newline at end of file diff --git a/src/evoatmosphere/photochem_evoatmosphere_utils.f90 b/src/evoatmosphere/photochem_evoatmosphere_utils.f90 index 3a8d39a..f42b71b 100644 --- a/src/evoatmosphere/photochem_evoatmosphere_utils.f90 +++ b/src/evoatmosphere/photochem_evoatmosphere_utils.f90 @@ -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 \ No newline at end of file