Skip to content

Commit d7bb9e0

Browse files
committed
adding rad2diam utility function with test
1 parent a534d2b commit d7bb9e0

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

src/pypartmc.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ PYBIND11_MODULE(_PyPartMC, m) {
201201
"Convert mass-equivalent volume (m^3) to geometric radius (m) for spherical particles."
202202
);
203203

204+
m.def(
205+
"rad2diam", &rad2diam, py::return_value_policy::copy,
206+
"Convert radius (m) to diameter (m)."
207+
);
208+
204209
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
205210

206211
m.attr("__all__") = py::make_tuple(
@@ -218,6 +223,7 @@ PYBIND11_MODULE(_PyPartMC, m) {
218223
"pow2_above",
219224
"histogram_1d",
220225
"histogram_2d",
221-
"sphere_vol2rad"
226+
"sphere_vol2rad",
227+
"rad2diam"
222228
);
223229
}

src/util.F90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,12 @@ subroutine f_sphere_vol2rad(v, rad) bind(C)
2727

2828
end subroutine
2929

30+
subroutine f_rad2diam(rad, d) bind(C)
31+
real(c_double), intent(in) :: rad
32+
real(c_double), intent(out) :: d
33+
34+
d = rad2diam(rad)
35+
36+
end subroutine
37+
3038
end module

src/util.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
extern "C" void py_pow2_above(int*, int*);
1010
extern "C" void f_sphere_vol2rad(const double*, double*);
11+
extern "C" void f_rad2diam(const double*, double*);
1112

1213
auto pow2_above(int n) {
1314
int res;
@@ -21,5 +22,11 @@ double sphere_vol2rad(double v) {
2122
return rad;
2223
}
2324

25+
double rad2diam(double rad) {
26+
double d;
27+
f_rad2diam(&rad, &d);
28+
return d;
29+
}
30+
2431
extern "C" double py_deg2rad(double);
2532

tests/test_util.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,14 @@ def test_sphere_vol2rad():
3434

3535
# assert
3636
np.testing.assert_almost_equal(1e-6, rad)
37+
38+
@staticmethod
39+
def test_rad2diam():
40+
# arrange
41+
arg = 0.5e-6
42+
43+
# act
44+
diam = ppmc.rad2diam(arg)
45+
46+
# assert
47+
assert diam == 2*arg

0 commit comments

Comments
 (0)