Skip to content

Commit bb1581b

Browse files
committed
add saturation vapor pressure
1 parent fde7138 commit bb1581b

4 files changed

Lines changed: 87 additions & 51 deletions

File tree

src/env_state.F90

Lines changed: 62 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ subroutine f_env_state_get_height(ptr_c, height) bind(C)
8787
type(env_state_t), pointer :: ptr_f => null()
8888
type(c_ptr), intent(in) :: ptr_c
8989
real(c_double), intent(out) :: height
90-
90+
9191
call c_f_pointer(ptr_c, ptr_f)
9292

9393
height = ptr_f%height
@@ -109,7 +109,7 @@ subroutine f_env_state_get_additive_kernel_coefficient(ptr_c, target) bind(C)
109109
type(env_state_t), pointer :: ptr_f => null()
110110
type(c_ptr), intent(in) :: ptr_c
111111
real(c_double), intent(out) :: target
112-
112+
113113
call c_f_pointer(ptr_c, ptr_f)
114114

115115
target = ptr_f%additive_kernel_coefficient
@@ -141,7 +141,7 @@ subroutine f_env_state_get_pressure(ptr_c, pressure) bind(C)
141141
subroutine f_env_state_get_elapsed_time(ptr_c, elapsed_time) bind(C)
142142
type(env_state_t), pointer :: ptr_f => null()
143143
type(c_ptr), intent(in) :: ptr_c
144-
real(c_double), intent(out) :: elapsed_time
144+
real(c_double), intent(out) :: elapsed_time
145145

146146
call c_f_pointer(ptr_c, ptr_f)
147147

@@ -172,103 +172,114 @@ subroutine f_env_state_air_dens(ptr_c, air_density) bind(C)
172172
end subroutine
173173

174174
subroutine f_env_state_air_molar_dens(ptr_c, air_molar_density) bind(C)
175-
type(env_state_t), pointer :: ptr_f => null()
176-
type(c_ptr), intent(in) :: ptr_c
177-
real(c_double), intent(out) :: air_molar_density
175+
type(env_state_t), pointer :: ptr_f => null()
176+
type(c_ptr), intent(in) :: ptr_c
177+
real(c_double), intent(out) :: air_molar_density
178178

179-
call c_f_pointer(ptr_c, ptr_f)
179+
call c_f_pointer(ptr_c, ptr_f)
180180

181-
air_molar_density = env_state_air_molar_den(ptr_f)
181+
air_molar_density = env_state_air_molar_den(ptr_f)
182182

183183
end subroutine
184184

185185
subroutine f_env_state_get_latitude(ptr_c, latitude) bind(C)
186-
type(env_state_t), pointer :: ptr_f => null()
187-
type(c_ptr), intent(in) :: ptr_c
188-
real(c_double), intent(out) :: latitude
186+
type(env_state_t), pointer :: ptr_f => null()
187+
type(c_ptr), intent(in) :: ptr_c
188+
real(c_double), intent(out) :: latitude
189189

190-
call c_f_pointer(ptr_c, ptr_f)
190+
call c_f_pointer(ptr_c, ptr_f)
191+
192+
latitude = ptr_f%latitude
191193

192-
latitude = ptr_f%latitude
193-
194194
end subroutine
195195

196196
subroutine f_env_state_set_latitude(ptr_c, latitude) bind(C)
197-
type(env_state_t), pointer :: ptr_f => null()
198-
type(c_ptr), intent(inout) :: ptr_c
199-
real(c_double), intent(in) :: latitude
197+
type(env_state_t), pointer :: ptr_f => null()
198+
type(c_ptr), intent(inout) :: ptr_c
199+
real(c_double), intent(in) :: latitude
200200

201-
call c_f_pointer(ptr_c, ptr_f)
201+
call c_f_pointer(ptr_c, ptr_f)
202202

203-
ptr_f%latitude = latitude
203+
ptr_f%latitude = latitude
204204

205205
end subroutine
206206

207207
subroutine f_env_state_get_longitude(ptr_c, longitude) bind(C)
208-
type(env_state_t), pointer :: ptr_f => null()
209-
type(c_ptr), intent(in) :: ptr_c
210-
real(c_double), intent(out) :: longitude
208+
type(env_state_t), pointer :: ptr_f => null()
209+
type(c_ptr), intent(in) :: ptr_c
210+
real(c_double), intent(out) :: longitude
211211

212-
call c_f_pointer(ptr_c, ptr_f)
212+
call c_f_pointer(ptr_c, ptr_f)
213213

214-
longitude = ptr_f%longitude
214+
longitude = ptr_f%longitude
215215

216216
end subroutine
217217

218218
subroutine f_env_state_set_longitude(ptr_c, longitude) bind(C)
219-
type(env_state_t), pointer :: ptr_f => null()
220-
type(c_ptr), intent(inout) :: ptr_c
221-
real(c_double), intent(in) :: longitude
219+
type(env_state_t), pointer :: ptr_f => null()
220+
type(c_ptr), intent(inout) :: ptr_c
221+
real(c_double), intent(in) :: longitude
222222

223-
call c_f_pointer(ptr_c, ptr_f)
223+
call c_f_pointer(ptr_c, ptr_f)
224224

225-
ptr_f%longitude = longitude
225+
ptr_f%longitude = longitude
226226

227227
end subroutine
228228

229229
subroutine f_env_state_get_altitude(ptr_c, altitude) bind(C)
230-
type(env_state_t), pointer :: ptr_f => null()
231-
type(c_ptr), intent(in) :: ptr_c
232-
real(c_double), intent(out) :: altitude
230+
type(env_state_t), pointer :: ptr_f => null()
231+
type(c_ptr), intent(in) :: ptr_c
232+
real(c_double), intent(out) :: altitude
233233

234-
call c_f_pointer(ptr_c, ptr_f)
234+
call c_f_pointer(ptr_c, ptr_f)
235235

236-
altitude = ptr_f%altitude
236+
altitude = ptr_f%altitude
237237

238238
end subroutine
239239

240240
subroutine f_env_state_set_altitude(ptr_c, altitude) bind(C)
241-
type(env_state_t), pointer :: ptr_f => null()
242-
type(c_ptr), intent(inout) :: ptr_c
243-
real(c_double), intent(in) :: altitude
241+
type(env_state_t), pointer :: ptr_f => null()
242+
type(c_ptr), intent(inout) :: ptr_c
243+
real(c_double), intent(in) :: altitude
244244

245-
call c_f_pointer(ptr_c, ptr_f)
245+
call c_f_pointer(ptr_c, ptr_f)
246246

247-
ptr_f%altitude = altitude
247+
ptr_f%altitude = altitude
248248

249249
end subroutine
250250

251251
subroutine f_env_state_ppb_to_conc(ptr_c, ppb, conc) bind(C)
252-
type(env_state_t), pointer :: ptr_f => null()
253-
type(c_ptr), intent(in) :: ptr_c
254-
real(c_double), intent(in) :: ppb
255-
real(c_double), intent(out) :: conc
252+
type(env_state_t), pointer :: ptr_f => null()
253+
type(c_ptr), intent(in) :: ptr_c
254+
real(c_double), intent(in) :: ppb
255+
real(c_double), intent(out) :: conc
256256

257-
call c_f_pointer(ptr_c, ptr_f)
257+
call c_f_pointer(ptr_c, ptr_f)
258258

259-
conc = env_state_ppb_to_conc(ptr_f, ppb)
259+
conc = env_state_ppb_to_conc(ptr_f, ppb)
260260

261261
end subroutine
262262

263263
subroutine f_env_state_conc_to_ppb(ptr_c, conc, ppb) bind(C)
264-
type(env_state_t), pointer :: ptr_f => null()
265-
type(c_ptr), intent(in) :: ptr_c
266-
real(c_double), intent(out) :: ppb
267-
real(c_double), intent(in) :: conc
264+
type(env_state_t), pointer :: ptr_f => null()
265+
type(c_ptr), intent(in) :: ptr_c
266+
real(c_double), intent(out) :: ppb
267+
real(c_double), intent(in) :: conc
268268

269-
call c_f_pointer(ptr_c, ptr_f)
269+
call c_f_pointer(ptr_c, ptr_f)
270+
271+
ppb = env_state_conc_to_ppb(ptr_f, conc)
272+
273+
end subroutine
274+
275+
subroutine f_env_state_sat_vapor_pressure(ptr_c, sat_vapor_pressure) bind(C)
276+
type(env_state_t), pointer :: ptr_f => null()
277+
type(c_ptr), intent(in) :: ptr_c
278+
real(c_double), intent(out) :: sat_vapor_pressure
279+
280+
call c_f_pointer(ptr_c, ptr_f)
270281

271-
ppb = env_state_conc_to_ppb(ptr_f, conc)
282+
sat_vapor_pressure = env_state_sat_vapor_pressure(ptr_f)
272283

273284
end subroutine
274285

src/env_state.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern "C" void f_env_state_set_altitude(const void *ptr, const double *altitude
3333
extern "C" void f_env_state_get_altitude(const void *ptr, double *altitude) noexcept;
3434
extern "C" void f_env_state_ppb_to_conc(const void *ptr, const double *ppb, double *conc) noexcept;
3535
extern "C" void f_env_state_conc_to_ppb(const void *ptr, const double *conc, double *ppb) noexcept;
36+
extern "C" void f_env_state_sat_vapor_pressure(const void *ptr, double *sat_vapor_pressure) noexcept;
3637

3738
struct EnvState {
3839
PMCResource ptr;
@@ -240,4 +241,14 @@ struct EnvState {
240241
return ppb;
241242
}
242243

244+
static auto sat_vapor_pressure(const EnvState &self) {
245+
double sat_vapor_pressure;
246+
247+
f_env_state_sat_vapor_pressure(
248+
self.ptr.f_arg(),
249+
&sat_vapor_pressure
250+
);
251+
return sat_vapor_pressure;
252+
}
253+
243254
};

src/pypartmc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ NB_MODULE(_PyPartMC, m) {
438438
"Scaling coefficient for additive coagulation kernel.")
439439
.def("ppb_to_conc", &EnvState::ppb_to_conc, "Convert (ppb) to (molecules m^{-3}).")
440440
.def("conc_to_ppb", &EnvState::conc_to_ppb, "Convert (molecules m^{-3}) to (ppb).")
441+
.def_prop_ro("sat_vapor_pressure", &EnvState::sat_vapor_pressure,
442+
"Returns the current saturation vapor pressure (Pa).")
441443
;
442444

443445
nb::class_<Photolysis>(m,

tests/test_env_state.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,15 @@ def test_conc_ppb_conversions():
191191
assert ppb_orig < conc
192192
np.testing.assert_almost_equal(env_state.ppb_to_conc(ppb), conc_orig)
193193
np.testing.assert_almost_equal(env_state.conc_to_ppb(conc), ppb_orig)
194+
195+
@staticmethod
196+
def test_sat_vapor_pressure():
197+
# arrange
198+
gas_data = ppmc.GasData(GAS_DATA_CTOR_ARG_MINIMAL)
199+
aero_data = ppmc.AeroData(AERO_DATA_CTOR_ARG_MINIMAL)
200+
scenario = ppmc.Scenario(gas_data, aero_data, SCENARIO_CTOR_ARG_MINIMAL)
201+
env_state = ppmc.EnvState(ENV_STATE_CTOR_ARG_MINIMAL)
202+
scenario.init_env_state(env_state, 0.0)
203+
204+
# assert
205+
assert env_state.sat_vapor_pressure > 0.0

0 commit comments

Comments
 (0)