Skip to content

Commit 370cb1e

Browse files
authored
Merge pull request #147 from zdaq12/aero_particle_improvements
additions to AeroParticle
2 parents f568c54 + 00cd97c commit 370cb1e

File tree

4 files changed

+427
-1
lines changed

4 files changed

+427
-1
lines changed

src/aero_particle.F90

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,136 @@ subroutine f_aero_particle_volumes(ptr_c, arr_data, arr_size) bind(C)
4949
call c_f_pointer(ptr_c, aero_particle)
5050
arr_data = aero_particle%vol
5151
end subroutine
52+
53+
subroutine f_aero_particle_volume(ptr_c, vol) bind(C)
54+
type(aero_particle_t), pointer :: ptr_f => null()
55+
type(c_ptr), intent(in) :: ptr_c
56+
real(c_double), intent(out) :: vol
57+
58+
call c_f_pointer(ptr_c, ptr_f)
59+
60+
vol = aero_particle_volume(ptr_f)
61+
end subroutine
62+
63+
subroutine f_aero_particle_species_volume(ptr_c, i_spec, vol) bind(C)
64+
type(aero_particle_t), pointer :: ptr_f => null()
65+
type(c_ptr), intent(in) :: ptr_c
66+
integer(c_int), intent(in) :: i_spec
67+
real(c_double), intent(out) :: vol
68+
69+
call c_f_pointer(ptr_c, ptr_f)
70+
71+
vol = aero_particle_species_volume(ptr_f, i_spec+1)
72+
end subroutine
73+
74+
subroutine f_aero_particle_dry_volume(aero_particle_ptr_c, aero_data_ptr_c, vol) bind(C)
75+
type(aero_particle_t), pointer :: aero_particle_ptr_f => null()
76+
type(aero_data_t), pointer :: aero_data_ptr_f => null()
77+
type(c_ptr), intent(in) :: aero_particle_ptr_c, aero_data_ptr_c
78+
real(c_double), intent(out) :: vol
79+
80+
call c_f_pointer(aero_particle_ptr_c, aero_particle_ptr_f)
81+
call c_f_pointer(aero_data_ptr_c, aero_data_ptr_f)
82+
83+
vol = aero_particle_dry_volume(aero_particle_ptr_f, aero_data_ptr_f)
84+
end subroutine
85+
86+
subroutine f_aero_particle_radius(aero_particle_ptr_c, aero_data_ptr_c, radius) bind(C)
87+
type(aero_particle_t), pointer :: aero_particle_ptr_f => null()
88+
type(aero_data_t), pointer :: aero_data_ptr_f => null()
89+
type(c_ptr), intent(in) :: aero_particle_ptr_c, aero_data_ptr_c
90+
real(c_double), intent(out) :: radius
91+
92+
call c_f_pointer(aero_particle_ptr_c, aero_particle_ptr_f)
93+
call c_f_pointer(aero_data_ptr_c, aero_data_ptr_f)
94+
95+
radius = aero_particle_radius(aero_particle_ptr_f, aero_data_ptr_f)
96+
end subroutine
97+
98+
subroutine f_aero_particle_dry_radius(aero_particle_ptr_c, aero_data_ptr_c, radius) bind(C)
99+
type(aero_particle_t), pointer :: aero_particle_ptr_f => null()
100+
type(aero_data_t), pointer :: aero_data_ptr_f => null()
101+
type(c_ptr), intent(in) :: aero_particle_ptr_c, aero_data_ptr_c
102+
real(c_double), intent(out) :: radius
103+
104+
call c_f_pointer(aero_particle_ptr_c, aero_particle_ptr_f)
105+
call c_f_pointer(aero_data_ptr_c, aero_data_ptr_f)
106+
107+
radius = aero_particle_dry_radius(aero_particle_ptr_f, aero_data_ptr_f)
108+
end subroutine
109+
110+
subroutine f_aero_particle_diameter(aero_particle_ptr_c, aero_data_ptr_c, diameter) bind(C)
111+
type(aero_particle_t), pointer :: aero_particle_ptr_f => null()
112+
type(aero_data_t), pointer :: aero_data_ptr_f => null()
113+
type(c_ptr), intent(in) :: aero_particle_ptr_c, aero_data_ptr_c
114+
real(c_double), intent(out) :: diameter
115+
116+
call c_f_pointer(aero_particle_ptr_c, aero_particle_ptr_f)
117+
call c_f_pointer(aero_data_ptr_c, aero_data_ptr_f)
118+
119+
diameter = aero_particle_diameter(aero_particle_ptr_f, aero_data_ptr_f)
120+
end subroutine
121+
122+
subroutine f_aero_particle_dry_diameter(aero_particle_ptr_c, aero_data_ptr_c, diameter) bind(C)
123+
type(aero_particle_t), pointer :: aero_particle_ptr_f => null()
124+
type(aero_data_t), pointer :: aero_data_ptr_f => null()
125+
type(c_ptr), intent(in) :: aero_particle_ptr_c, aero_data_ptr_c
126+
real(c_double), intent(out) :: diameter
127+
128+
call c_f_pointer(aero_particle_ptr_c, aero_particle_ptr_f)
129+
call c_f_pointer(aero_data_ptr_c, aero_data_ptr_f)
130+
131+
diameter = aero_particle_dry_diameter(aero_particle_ptr_f, aero_data_ptr_f)
132+
end subroutine
133+
134+
subroutine f_aero_particle_mass(aero_particle_ptr_c, aero_data_ptr_c, mass) bind(C)
135+
type(aero_particle_t), pointer :: aero_particle_ptr_f => null()
136+
type(aero_data_t), pointer :: aero_data_ptr_f => null()
137+
type(c_ptr), intent(in) :: aero_particle_ptr_c, aero_data_ptr_c
138+
real(c_double), intent(out) :: mass
139+
140+
call c_f_pointer(aero_particle_ptr_c, aero_particle_ptr_f)
141+
call c_f_pointer(aero_data_ptr_c, aero_data_ptr_f)
142+
143+
mass = aero_particle_mass(aero_particle_ptr_f, aero_data_ptr_f)
144+
end subroutine
145+
146+
subroutine f_aero_particle_species_mass( &
147+
aero_particle_ptr_c, &
148+
i_spec, &
149+
aero_data_ptr_c, &
150+
mass &
151+
) bind(C)
152+
153+
type(aero_particle_t), pointer :: aero_particle_ptr_f => null()
154+
type(aero_data_t), pointer :: aero_data_ptr_f => null()
155+
type(c_ptr), intent(in) :: aero_particle_ptr_c, aero_data_ptr_c
156+
integer(c_int), intent(in) :: i_spec
157+
real(c_double), intent(out) :: mass
158+
159+
call c_f_pointer(aero_particle_ptr_c, aero_particle_ptr_f)
160+
call c_f_pointer(aero_data_ptr_c, aero_data_ptr_f)
161+
162+
mass = aero_particle_species_mass(aero_particle_ptr_f, i_spec+1, aero_data_ptr_f)
163+
end subroutine
164+
165+
subroutine f_aero_particle_species_masses( &
166+
aero_particle_ptr_c, &
167+
aero_data_ptr_c, &
168+
size_masses, &
169+
masses &
170+
) bind(C)
171+
172+
type(aero_particle_t), pointer :: aero_particle_ptr_f => null()
173+
type(aero_data_t), pointer :: aero_data_ptr_f => null()
174+
type(c_ptr), intent(in) :: aero_particle_ptr_c, aero_data_ptr_c
175+
integer(c_int), intent(in) :: size_masses
176+
real(c_double), dimension(size_masses), intent(out) :: masses
177+
178+
call c_f_pointer(aero_particle_ptr_c, aero_particle_ptr_f)
179+
call c_f_pointer(aero_data_ptr_c, aero_data_ptr_f)
180+
181+
masses = aero_particle_species_masses(aero_particle_ptr_f, aero_data_ptr_f)
182+
end subroutine
183+
52184
end module

src/aero_particle.hpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ extern "C" void f_aero_particle_ctor(void *ptr) noexcept;
1414
extern "C" void f_aero_particle_dtor(void *ptr) noexcept;
1515
extern "C" void f_aero_particle_init(const void *ptr, const void *, const void *arr_data, const int *arr_size) noexcept;
1616
extern "C" void f_aero_particle_volumes(const void *ptr, void *arr_data, const int *arr_size) noexcept;
17+
extern "C" void f_aero_particle_volume(const void *ptr, double *vol) noexcept;
18+
extern "C" void f_aero_particle_species_volume(const void *ptr, const int *i_spec, double *vol) noexcept;
19+
extern "C" void f_aero_particle_dry_volume(const void *aero_particle_ptr, const void *aero_data_ptr, double *vol) noexcept;
20+
extern "C" void f_aero_particle_radius(const void *aero_particle_ptr, const void *aero_data_ptr, double *radius) noexcept;
21+
extern "C" void f_aero_particle_dry_radius(const void *aero_particle_ptr, const void *aero_data_ptr, double *radius) noexcept;
22+
extern "C" void f_aero_particle_diameter(const void *aero_particle_ptr, const void *aero_data_ptr, double *diameter) noexcept;
23+
extern "C" void f_aero_particle_dry_diameter(const void *aero_particle_ptr, const void * aero_data_ptr, double *diameter) noexcept;
24+
extern "C" void f_aero_particle_mass(const void *aero_particle_ptr, const void *aero_data_ptr, double *mass) noexcept;
25+
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;
26+
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+
1728

1829
namespace py = pybind11;
1930
struct AeroParticle {
@@ -37,5 +48,67 @@ struct AeroParticle {
3748
f_aero_particle_volumes(&self.ptr, begin(data), &len);
3849
return data;
3950
}
51+
52+
static double volume(const AeroParticle &self) {
53+
double vol;
54+
f_aero_particle_volume(&self.ptr, &vol);
55+
return vol;
56+
}
57+
58+
static double species_volume(const AeroParticle &self, const int &i_spec) {
59+
double vol;
60+
f_aero_particle_species_volume(&self.ptr, &i_spec, &vol);
61+
return vol;
62+
}
63+
64+
static double dry_volume(const AeroParticle &self) {
65+
double vol;
66+
f_aero_particle_dry_volume(&self.ptr, &self.aero_data, &vol);
67+
return vol;
68+
}
69+
70+
static double radius(const AeroParticle &self) {
71+
double radius;
72+
f_aero_particle_radius(&self.ptr, &self.aero_data, &radius);
73+
return radius;
74+
}
75+
76+
static double dry_radius(const AeroParticle &self) {
77+
double radius;
78+
f_aero_particle_dry_radius(&self.ptr, &self.aero_data, &radius);
79+
return radius;
80+
}
81+
82+
static double diameter(const AeroParticle &self) {
83+
double diameter;
84+
f_aero_particle_diameter(&self.ptr, &self.aero_data, &diameter);
85+
return diameter;
86+
}
87+
88+
static double dry_diameter(const AeroParticle &self) {
89+
double diameter;
90+
f_aero_particle_dry_diameter(&self.ptr, &self.aero_data, &diameter);
91+
return diameter;
92+
}
93+
94+
static double mass(const AeroParticle &self) {
95+
double mass;
96+
f_aero_particle_mass(&self.ptr, &self.aero_data, &mass);
97+
return mass;
98+
}
99+
100+
static double species_mass(const AeroParticle &self, const int &i_spec) {
101+
double mass;
102+
f_aero_particle_species_mass(&self.ptr, &i_spec, &self.aero_data, &mass);
103+
return mass;
104+
}
105+
106+
static std::valarray<double> species_masses(const AeroParticle &self) {
107+
int len = AeroData::__len__(self.aero_data);
108+
std::valarray<double> masses(len);
109+
f_aero_particle_species_masses(&self.ptr, &self.aero_data, &len, begin(masses));
110+
return masses;
111+
}
112+
40113
};
41114

src/pypartmc.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,26 @@ PYBIND11_MODULE(_PyPartMC, m) {
9595
)
9696
.def(py::init<const AeroData&, const std::valarray<double>&>())
9797
.def_property_readonly("volumes", AeroParticle::volumes)
98+
.def_property_readonly("volume", AeroParticle::volume,
99+
"Total volume of the particle (m^3).")
100+
.def("species_volume", AeroParticle::species_volume,
101+
"Volume of a single species in the particle (m^3).")
102+
.def_property_readonly("dry_volume", AeroParticle::dry_volume,
103+
"Total dry volume of the particle (m^3).")
104+
.def_property_readonly("radius", AeroParticle::radius,
105+
"Total radius of the particle (m).")
106+
.def_property_readonly("dry_radius", AeroParticle::dry_radius,
107+
"Total dry radius of the particle (m).")
108+
.def_property_readonly("diameter", AeroParticle::diameter,
109+
"Total diameter of the particle (m).")
110+
.def_property_readonly("dry_diameter", AeroParticle::dry_diameter,
111+
"Total dry diameter of the particle (m).")
112+
.def_property_readonly("mass", AeroParticle::mass,
113+
"Total mass of the particle (kg).")
114+
.def("species_mass", AeroParticle::species_mass,
115+
"Mass of a single species in the particle (kg).")
116+
.def_property_readonly("species_masses", AeroParticle::species_masses,
117+
"Mass of all species in the particle (kg).")
98118
;
99119

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

0 commit comments

Comments
 (0)