Skip to content

Commit

Permalink
expose additive kernel coefficient property in Python
Browse files Browse the repository at this point in the history
  • Loading branch information
emmacware committed Dec 6, 2024
1 parent 7310b51 commit ce9c623
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gitmodules/partmc
Submodule partmc updated 78 files
+0 −15 .github/workflows/tchem.yml
+3 −81 CMakeLists.txt
+0 −177 Dockerfile.tchem
+0 −1 scenarios/1_urban_plume/urban_plume.spec
+0 −1 scenarios/2_urban_plume2/urban_plume2.spec
+0 −1 scenarios/3_condense/cond_template.spec
+0 −1 scenarios/4_chamber/chamber.spec
+0 −1 scenarios/5_coag_brownian/example.spec
+0 −1 scenarios/6_camp/camp.spec
+1 −1 src/camp_interface.F90
+0 −22 src/env_state.F90
+18 −10 src/gas_state.F90
+1 −7 src/partmc.F90
+7 −49 src/run_part.F90
+1 −1 src/scenario.F90
+0 −309 src/tchem_interface.F90
+0 −13 src/util.F90
+1 −2 test/additive/run_part.spec
+1 −2 test/average/run_part.spec
+1 −2 test/bidisperse/run_part.spec
+1 −2 test/brownian/run_part.spec
+0 −1 test/camp/camp.spec
+1 −2 test/condense/run_part.spec
+1 −2 test/emission/run_part.spec
+1 −2 test/fractal/run_part_brown_cont_df_1_8_restart.spec
+1 −2 test/fractal/run_part_brown_cont_df_1_8_upto1000s.spec
+1 −2 test/fractal/run_part_brown_free_df_2_4_restart.spec
+1 −2 test/fractal/run_part_brown_free_df_2_4_upto1000s.spec
+1 −2 test/loss/run_chamber_part.spec
+1 −2 test/loss/run_constant_part.spec
+1 −2 test/loss/run_drydep_part.spec
+1 −2 test/loss/run_volume_part.spec
+1 −2 test/mixing_state/run_part.spec
+1 −2 test/mosaic/run_part.spec
+1 −2 test/mosaic/run_part_restarted.spec
+1 −2 test/nucleate/run_part.spec
+1 −2 test/parallel/run_part_parallel_dist.spec
+1 −2 test/parallel/run_part_parallel_dist_single.spec
+1 −2 test/parallel/run_part_parallel_mix.spec
+1 −2 test/parallel/run_part_serial.spec
+1 −2 test/sedi/run_part.spec
+0 −8 test/tchem/README
+0 −6 test/tchem/aero_back.dat
+0 −2 test/tchem/aero_back_comp.dat
+0 −0 test/tchem/aero_back_dist.dat
+0 −4 test/tchem/aero_data.dat
+0 −6 test/tchem/aero_emit.dat
+0 −2 test/tchem/aero_emit_comp.dat
+0 −0 test/tchem/aero_emit_dist.dat
+0 −2 test/tchem/aero_init_comp.dat
+0 −6 test/tchem/aero_init_dist.dat
+0 −2,614 test/tchem/chem.yaml
+0 −2,840 test/tchem/config_cb05cl_ae5.yaml
+0 −129 test/tchem/config_chapman.yaml
+0 −7 test/tchem/gas_back.dat
+0 −7 test/tchem/gas_data.dat
+0 −5 test/tchem/gas_emit_empty.dat
+0 −37 test/tchem/gas_init_cb05cl_ae5.dat
+0 −7 test/tchem/gas_init_chapman.dat
+0 −4 test/tchem/height.dat
+0 −4 test/tchem/pressure_cb05cl_ae5.dat
+0 −4 test/tchem/pressure_chapman.dat
+0 −50 test/tchem/run_part_cb05cl_ae5.spec
+0 −50 test/tchem/run_part_chapman.spec
+0 −9 test/tchem/solver_cb05cl_ae5.yaml
+0 −9 test/tchem/solver_chapman.yaml
+0 −11 test/tchem/tchem_cb05cl_ae5_gas_saved.txt
+0 −1,001 test/tchem/tchem_chapman_gas_saved.txt
+0 −4 test/tchem/temp_cb05cl_ae5.dat
+0 −4 test/tchem/temp_chapman.dat
+0 −14 test/tchem/test_tchem_1.sh
+0 −14 test/tchem/test_tchem_2.sh
+1 −2 test/weighting/run_part_flat.spec
+1 −2 test/weighting/run_part_flat_source.spec
+1 −2 test/weighting/run_part_flat_specified.spec
+1 −2 test/weighting/run_part_nummass.spec
+1 −2 test/weighting/run_part_nummass_source.spec
+1 −2 test/weighting/run_part_nummass_specified.spec
22 changes: 22 additions & 0 deletions src/env_state.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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, additive_kernel_coefficient) bind(C)
type(env_state_t), pointer :: ptr_f => null()
type(c_ptr), intent(in) :: ptr_c
real(c_double), intent(in) :: additive_kernel_coefficient

call c_f_pointer(ptr_c, ptr_f)

ptr_f%additive_kernel_coefficient = additive_kernel_coefficient

end subroutine

subroutine f_env_state_get_additive_kernel_coefficient(ptr_c, additive_kernel_coefficient) bind(C)
type(env_state_t), pointer :: ptr_f => null()
type(c_ptr), intent(in) :: ptr_c
real(c_double), intent(out) :: additive_kernel_coefficient

call c_f_pointer(ptr_c, ptr_f)

additive_kernel_coefficient = 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
Expand Down
19 changes: 19 additions & 0 deletions src/env_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions src/pypartmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_<Photolysis>(m,
Expand Down
12 changes: 12 additions & 0 deletions tests/test_env_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ce9c623

Please sign in to comment.