From 6b412ca78e0f25d422243e38f05c4fe620335ec4 Mon Sep 17 00:00:00 2001 From: Emma Ware Date: Fri, 6 Dec 2024 16:34:11 +0100 Subject: [PATCH] bump PartMC submodule and expose additive kernel coefficient property (#385) --- gitmodules/partmc | 2 +- src/env_state.F90 | 22 ++++++++++++++++++++++ src/env_state.hpp | 19 +++++++++++++++++++ src/pypartmc.cpp | 2 ++ tests/test_env_state.py | 12 ++++++++++++ 5 files changed, 56 insertions(+), 1 deletion(-) diff --git a/gitmodules/partmc b/gitmodules/partmc index 8d46edbc..ecc26d3e 160000 --- a/gitmodules/partmc +++ b/gitmodules/partmc @@ -1 +1 @@ -Subproject commit 8d46edbc65dde105ad9a53e6e91f0899e4b95b0b +Subproject commit ecc26d3ee4a36fb2c91a0dd2589235ac88033954 diff --git a/src/env_state.F90 b/src/env_state.F90 index 43cc72e2..fd66e1cd 100644 --- a/src/env_state.F90 +++ b/src/env_state.F90 @@ -94,6 +94,28 @@ subroutine f_env_state_get_height(ptr_c, height) bind(C) end subroutine + subroutine f_env_state_set_additive_kernel_coefficient(ptr_c, value) bind(C) + type(env_state_t), pointer :: ptr_f => null() + type(c_ptr), intent(in) :: ptr_c + real(c_double), intent(in) :: value + + call c_f_pointer(ptr_c, ptr_f) + + ptr_f%additive_kernel_coefficient = value + + end subroutine + + subroutine f_env_state_get_additive_kernel_coefficient(ptr_c, target) bind(C) + type(env_state_t), pointer :: ptr_f => null() + type(c_ptr), intent(in) :: ptr_c + real(c_double), intent(out) :: target + + call c_f_pointer(ptr_c, ptr_f) + + target = ptr_f%additive_kernel_coefficient + + end subroutine + subroutine f_env_state_set_pressure(ptr_c, pressure) bind(C) type(env_state_t), pointer :: ptr_f => null() type(c_ptr), intent(in) :: ptr_c diff --git a/src/env_state.hpp b/src/env_state.hpp index e9e9a856..5a443cdc 100644 --- a/src/env_state.hpp +++ b/src/env_state.hpp @@ -14,6 +14,8 @@ extern "C" void f_env_state_dtor(void *ptr) noexcept; extern "C" void f_env_state_from_json(const void *ptr) noexcept; extern "C" void f_env_state_set_temperature(const void *ptr, const double *temperature) noexcept; extern "C" void f_env_state_get_temperature(const void *ptr, double *temperature) noexcept; +extern "C" void f_env_state_set_additive_kernel_coefficient(const void *ptr, const double *additive_kernel_coefficient) noexcept; +extern "C" void f_env_state_get_additive_kernel_coefficient(const void *ptr, double *additive_kernel_coefficient) noexcept; extern "C" void f_env_state_get_rel_humid(const void *ptr, double *rel_humid) noexcept; extern "C" void f_env_state_set_height(const void *ptr, const double *height) noexcept; extern "C" void f_env_state_get_height(const void *ptr, double *height) noexcept; @@ -82,6 +84,23 @@ struct EnvState { return height; } + static void set_additive_kernel_coefficient(const EnvState &self, const double additive_kernel_coefficient) { + f_env_state_set_additive_kernel_coefficient( + self.ptr.f_arg(), + &additive_kernel_coefficient + ); + } + + static auto get_additive_kernel_coefficient(const EnvState &self) { + double additive_kernel_coefficient; + + f_env_state_get_additive_kernel_coefficient( + self.ptr.f_arg(), + &additive_kernel_coefficient + ); + return additive_kernel_coefficient; + } + static void set_pressure(const EnvState &self, const double pressure) { f_env_state_set_pressure( self.ptr.f_arg(), diff --git a/src/pypartmc.cpp b/src/pypartmc.cpp index 94b200b6..f21b24e1 100644 --- a/src/pypartmc.cpp +++ b/src/pypartmc.cpp @@ -324,6 +324,8 @@ PYBIND11_MODULE(_PyPartMC, m) { "Ambient pressure (Pa)") .def_property_readonly("air_density", &EnvState::air_density, "Air density (kg m^{-3})") + .def_property("additive_kernel_coefficient", &EnvState::get_additive_kernel_coefficient, &EnvState::set_additive_kernel_coefficient, + "Scaling coefficient for additive coagulation kernel.") ; py::class_(m, diff --git a/tests/test_env_state.py b/tests/test_env_state.py index 9c106d31..45ce141f 100644 --- a/tests/test_env_state.py +++ b/tests/test_env_state.py @@ -72,6 +72,18 @@ def test_pressure(): # assert assert value == sut.pressure + @staticmethod + def test_additive_kernel_coefficient(): + # arrange + sut = ppmc.EnvState(ENV_STATE_CTOR_ARG_MINIMAL) + value = 1500.0 + + # act + sut.additive_kernel_coefficient = value + + # assert + assert value == sut.additive_kernel_coefficient + @staticmethod def test_humidity_ctor(): # arrange and act