Skip to content

Commit e959d56

Browse files
authored
Merge pull request #154 from zdaq12/debug
adding aero_particle_solute_kappa()
2 parents a4a3658 + 0b94f97 commit e959d56

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

src/aero_particle.F90

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,16 @@ subroutine f_aero_particle_species_masses( &
181181
masses = aero_particle_species_masses(aero_particle_ptr_f, aero_data_ptr_f)
182182
end subroutine
183183

184+
subroutine f_aero_particle_solute_kappa(aero_particle_ptr_c, aero_data_ptr_c, kappa) bind(C)
185+
type(aero_particle_t), pointer :: aero_particle_ptr_f => null()
186+
type(aero_data_t), pointer :: aero_data_ptr_f => null()
187+
type(c_ptr), intent(in) :: aero_particle_ptr_c, aero_data_ptr_c
188+
real(c_double), intent(out) :: kappa
189+
190+
call c_f_pointer(aero_particle_ptr_c, aero_particle_ptr_f)
191+
call c_f_pointer(aero_data_ptr_c, aero_data_ptr_f)
192+
193+
kappa = aero_particle_solute_kappa(aero_particle_ptr_f, aero_data_ptr_f)
194+
end subroutine
195+
184196
end module

src/aero_particle.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extern "C" void f_aero_particle_dry_diameter(const void *aero_particle_ptr, cons
2424
extern "C" void f_aero_particle_mass(const void *aero_particle_ptr, const void *aero_data_ptr, double *mass) noexcept;
2525
extern "C" void f_aero_particle_species_mass(const void *aero_particle_ptr, const int *i_spec, const void *aero_data_ptr, double *mass) noexcept;
2626
extern "C" void f_aero_particle_species_masses(const void *aero_particle_ptr, const void *aero_data_ptr, const int *size_masses, void *masses) noexcept;
27+
extern "C" void f_aero_particle_solute_kappa(const void *aero_particle_ptr, const void *aero_data_ptr, void *kappa) noexcept;
2728

2829

2930
namespace py = pybind11;
@@ -110,5 +111,11 @@ struct AeroParticle {
110111
return masses;
111112
}
112113

114+
static double solute_kappa(const AeroParticle &self) {
115+
double kappa;
116+
f_aero_particle_solute_kappa(&self.ptr, &self.aero_data, &kappa);
117+
return kappa;
118+
}
119+
113120
};
114121

src/pypartmc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ PYBIND11_MODULE(_PyPartMC, m) {
115115
"Mass of a single species in the particle (kg).")
116116
.def_property_readonly("species_masses", AeroParticle::species_masses,
117117
"Mass of all species in the particle (kg).")
118+
.def_property_readonly("solute_kappa", AeroParticle::solute_kappa,
119+
"Returns the average of the solute kappas (1).")
118120
;
119121

120122
py::class_<AeroState>(m, "AeroState",

tests/test_aero_particle.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
####################################################################################################
66

77
import pytest
8+
import numpy as np
89
import PyPartMC as ppmc
910
from PyPartMC import si
1011
from .test_aero_data import AERO_DATA_CTOR_ARG_MINIMAL
@@ -236,3 +237,21 @@ def test_species_masses():
236237

237238
# assert
238239
assert masses == check
240+
241+
@staticmethod
242+
def test_solute_kappa():
243+
# arrange
244+
aero_data_arg = (
245+
{"H2O": [1000 * si.kg / si.m**3, 0, 18e-3 * si.kg / si.mol, 0]},
246+
{"Cl": [2200 * si.kg / si.m**3, 1, 35.5e-3* si.kg / si.mol, 0]},
247+
{"Na": [2200 * si.kg / si.m**3, 1, 23e-3 * si.kg / si.mol, 0]}
248+
)
249+
aero_data = ppmc.AeroData(aero_data_arg)
250+
volumes = [1, 2, 3]
251+
sut = ppmc.AeroParticle(aero_data, volumes)
252+
253+
#act
254+
kappa = sut.solute_kappa
255+
256+
#assert
257+
np.testing.assert_almost_equal(kappa, 1.479240661)

0 commit comments

Comments
 (0)