Skip to content

Commit 0c1ffcf

Browse files
committed
adding vol2diam to aero_data with tests
1 parent c869837 commit 0c1ffcf

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

src/aero_data.F90

+12
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,16 @@ subroutine f_aero_data_diam2vol(ptr_c, diam, vol) bind(C)
161161

162162
end subroutine
163163

164+
subroutine f_aero_data_vol2diam(ptr_c, vol, diam) bind(C)
165+
type(aero_data_t), pointer :: ptr_f => null()
166+
type(c_ptr), intent(in) :: ptr_c
167+
real(c_double), intent(in) :: vol
168+
real(c_double), intent(out) :: diam
169+
170+
call c_f_pointer(ptr_c, ptr_f)
171+
172+
diam = aero_data_vol2diam(ptr_f, vol)
173+
174+
end subroutine
175+
164176
end module

src/aero_data.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extern "C" void f_aero_data_get_prime_radius(const void *ptr, double*) noexcept;
2323
extern "C" void f_aero_data_rad2vol(const void *ptr, const double*, double*) noexcept;
2424
extern "C" void f_aero_data_vol2rad(const void *ptr, const double*, double*) noexcept;
2525
extern "C" void f_aero_data_diam2vol(const void *ptr, const double*, double*) noexcept;
26+
extern "C" void f_aero_data_vol2diam(const void *ptr, const double*, double*) noexcept;
2627

2728
struct AeroData {
2829
PMCResource ptr;
@@ -97,5 +98,11 @@ struct AeroData {
9798
return vol;
9899
}
99100

101+
static double vol2diam(const AeroData &self, const double vol) {
102+
double diam;
103+
f_aero_data_vol2diam(&self.ptr, &vol, &diam);
104+
return diam;
105+
}
106+
100107
};
101108

src/pypartmc.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ PYBIND11_MODULE(_PyPartMC, m) {
7777
"Convert mass-equivalent volume (m^3) to geometric radius (m)")
7878
.def("diam2vol", AeroData::diam2vol,
7979
"Convert geometric diameter (m) to mass-equivalent volume (m^3).")
80+
.def("vol2diam", AeroData::vol2diam,
81+
"Convert mass-equivalent volume (m^3) to geometric diameter (m).")
8082
;
8183

8284
py::class_<AeroParticle>(m, "AeroParticle",

tests/test_aero_data.py

+35
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,38 @@ def test_diam2vol_fractal(aero_data_params:dict):
197197
# assert
198198
np.testing.assert_almost_equal(value, (4/3)*np.pi*(sut.prime_radius)**3 *
199199
(1e-6/sut.prime_radius)**sut.frac_dim / sut.vol_fill_factor)
200+
201+
@staticmethod
202+
def test_vol2diam_sphere():
203+
# arrange
204+
sut = ppmc.AeroData(AERO_DATA_CTOR_ARG_MINIMAL)
205+
vol = 4.19e-18
206+
sut.frac_dim = 3.0
207+
sut.vol_fill_factor = 1.0
208+
sut.prime_radius = 1e-8
209+
210+
# act
211+
value = sut.vol2diam(vol)
212+
213+
# arrange
214+
np.testing.assert_almost_equal(value, 2e-6)
215+
216+
@staticmethod
217+
@pytest.mark.parametrize("aero_data_params", (
218+
{"frac_dim": 2.4, "vol_fill_factor": 1.2, 'prime_radius': 1e-7},
219+
{"frac_dim": 2.5, "vol_fill_factor": 1.1, "prime_radius": 1e-8},
220+
{"frac_dim": 2.2, "vol_fill_factor": 1.3, 'prime_radius': 1e-6}))
221+
def test_vol2diam_fractal(aero_data_params:dict):
222+
# arrange
223+
sut = ppmc.AeroData(AERO_DATA_CTOR_ARG_MINIMAL)
224+
vol = 4.19e-18
225+
for key,value in aero_data_params.items():
226+
setattr(sut, key, value)
227+
228+
# act
229+
value = sut.vol2diam(vol)
230+
231+
# assert
232+
np.testing.assert_almost_equal(value, 2*(sut.prime_radius *
233+
(((3*vol/4/np.pi)**(1/3)/sut.prime_radius)**3 * sut.vol_fill_factor)**
234+
(1/sut.frac_dim)))

0 commit comments

Comments
 (0)