Skip to content

Commit 2223661

Browse files
authored
Merge pull request #145 from slayoo/camp
add CAMP-related args to run_part
2 parents f54eeff + d490aa8 commit 2223661

File tree

12 files changed

+149
-7
lines changed

12 files changed

+149
-7
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ set(PyPartMC_sources
3939
pypartmc.cpp gimmicks.cpp fake_netcdf.cpp fake_mpi.cpp fake_spec_file.cpp
4040
run_part.F90 run_part_opt.F90 util.F90 aero_data.F90 aero_state.F90 env_state.F90 gas_data.F90
4141
gas_state.F90 scenario.F90 condense.F90 aero_particle.F90 bin_grid.F90
42+
camp_core.F90 photolysis.F90
4243
)
4344
add_prefix(src/ PyPartMC_sources)
4445

src/camp_core.F90

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
!###################################################################################################
2+
! This file is a part of PyPartMC licensed under the GNU General Public License v3 (LICENSE file) #
3+
! Copyright (C) 2022 University of Illinois Urbana-Champaign #
4+
! Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
5+
!###################################################################################################
6+
7+
module PyPartMC_camp_core
8+
use iso_c_binding
9+
use camp_camp_core
10+
implicit none
11+
12+
contains
13+
14+
subroutine f_camp_core_ctor(ptr_c) bind(C)
15+
type(camp_core_t), pointer :: ptr_f => null()
16+
type(c_ptr), intent(out) :: ptr_c
17+
18+
ptr_f => camp_core_t()
19+
call ptr_f%initialize()
20+
ptr_c = c_loc(ptr_f)
21+
end subroutine
22+
23+
subroutine f_camp_core_dtor(ptr_c) bind(C)
24+
type(camp_core_t), pointer :: ptr_f => null()
25+
type(c_ptr), intent(in) :: ptr_c
26+
27+
call c_f_pointer(ptr_c, ptr_f)
28+
deallocate(ptr_f)
29+
end subroutine
30+
end module

src/camp_core.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*##################################################################################################
2+
# This file is a part of PyPartMC licensed under the GNU General Public License v3 (LICENSE file) #
3+
# Copyright (C) 2022 University of Illinois Urbana-Champaign #
4+
# Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
5+
##################################################################################################*/
6+
7+
#pragma once
8+
9+
#include "gimmicks.hpp"
10+
#include "pmc_resource.hpp"
11+
12+
extern "C" void f_camp_core_ctor(void *ptr) noexcept;
13+
extern "C" void f_camp_core_dtor(void *ptr) noexcept;
14+
15+
struct CampCore {
16+
PMCResource ptr;
17+
18+
CampCore() :
19+
ptr(f_camp_core_ctor, f_camp_core_dtor)
20+
{
21+
}
22+
};

src/env_state.F90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
module PyPartMC_env_state
88
use iso_c_binding
99
use pmc_env_state
10+
use camp_env_state, only: camp_env_state_t => env_state_t
1011
implicit none
1112

1213
contains

src/photolysis.F90

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
!###################################################################################################
2+
! This file is a part of PyPartMC licensed under the GNU General Public License v3 (LICENSE file) #
3+
! Copyright (C) 2022 University of Illinois Urbana-Champaign #
4+
! Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
5+
!###################################################################################################
6+
7+
module PyPartMC_photolysis
8+
use iso_c_binding
9+
use pmc_photolysis
10+
implicit none
11+
12+
contains
13+
14+
subroutine f_photolysis_ctor(ptr_c) bind(C)
15+
type(photolysis_t), pointer :: ptr_f => null()
16+
type(c_ptr), intent(out) :: ptr_c
17+
18+
allocate(ptr_f)
19+
ptr_c = c_loc(ptr_f)
20+
end subroutine
21+
22+
subroutine f_photolysis_dtor(ptr_c) bind(C)
23+
type(photolysis_t), pointer :: ptr_f => null()
24+
type(c_ptr), intent(in) :: ptr_c
25+
26+
call c_f_pointer(ptr_c, ptr_f)
27+
deallocate(ptr_f)
28+
end subroutine
29+
end module

src/photolysis.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*##################################################################################################
2+
# This file is a part of PyPartMC licensed under the GNU General Public License v3 (LICENSE file) #
3+
# Copyright (C) 2022 University of Illinois Urbana-Champaign #
4+
# Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
5+
##################################################################################################*/
6+
7+
#pragma once
8+
9+
#include "gimmicks.hpp"
10+
#include "pmc_resource.hpp"
11+
12+
extern "C" void f_photolysis_ctor(void *ptr) noexcept;
13+
extern "C" void f_photolysis_dtor(void *ptr) noexcept;
14+
15+
struct Photolysis {
16+
PMCResource ptr;
17+
18+
Photolysis() :
19+
ptr(f_photolysis_ctor, f_photolysis_dtor)
20+
{
21+
}
22+
};

src/pypartmc.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "gas_state.hpp"
1919
#include "condense.hpp"
2020
#include "bin_grid.hpp"
21+
#include "camp_core.hpp"
22+
#include "photolysis.hpp"
2123

2224
#define STRINGIFY(x) #x
2325
#define MACRO_STRINGIFY(x) STRINGIFY(x)
@@ -172,6 +174,24 @@ PYBIND11_MODULE(_PyPartMC, m) {
172174
.def_property("pressure", &EnvState::get_pressure, &EnvState::set_pressure)
173175
;
174176

177+
py::class_<Photolysis>(m,
178+
"Photolysis",
179+
R"pbdoc(
180+
PartMC interface to a photolysis module
181+
)pbdoc"
182+
)
183+
.def(py::init<>())
184+
;
185+
186+
py::class_<CampCore>(m,
187+
"CampCore",
188+
R"pbdoc(
189+
An interface between PartMC and the CAMP
190+
)pbdoc"
191+
)
192+
.def(py::init<>())
193+
;
194+
175195
py::class_<Scenario>(m,
176196
"Scenario",
177197
R"pbdoc(
@@ -291,9 +311,11 @@ PYBIND11_MODULE(_PyPartMC, m) {
291311
"AeroState",
292312
"AeroParticle",
293313
"BinGrid",
314+
"CampCore",
294315
"EnvState",
295316
"GasData",
296317
"GasState",
318+
"Photolysis",
297319
"RunPartOpt",
298320
"Scenario",
299321
"condense_equilib_particles",

src/run_part.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "gas_state.hpp"
1313
#include "run_part_opt.hpp"
1414
#include "scenario.hpp"
15+
#include "camp_core.hpp"
16+
#include "photolysis.hpp"
1517

1618
extern "C" void f_run_part(
1719
const void*,
@@ -20,6 +22,8 @@ extern "C" void f_run_part(
2022
const void*,
2123
const void*,
2224
const void*,
25+
const void*,
26+
const void*,
2327
const void*
2428
) noexcept;
2529

@@ -30,7 +34,9 @@ void run_part(
3034
const AeroState &aero_state,
3135
const GasData &gas_data,
3236
const GasState &gas_state,
33-
const RunPartOpt &run_part_opt
37+
const RunPartOpt &run_part_opt,
38+
const CampCore &camp_core,
39+
const Photolysis &photolysis
3440
) {
3541
f_run_part(
3642
scenario.ptr.f_arg(),
@@ -39,7 +45,9 @@ void run_part(
3945
aero_state.ptr.f_arg(),
4046
gas_data.ptr.f_arg(),
4147
gas_state.ptr.f_arg(),
42-
run_part_opt.ptr.f_arg()
48+
run_part_opt.ptr.f_arg(),
49+
camp_core.ptr.f_arg(),
50+
photolysis.ptr.f_arg()
4351
);
4452
}
4553

src/run_part_opt.F90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ subroutine f_run_part_opt_from_json(ptr_c) bind(C)
4848
call spec_file_read_logical(file, 'allow_doubling', run_part_opt%allow_doubling)
4949
call spec_file_read_logical(file, 'allow_halving', run_part_opt%allow_halving)
5050

51+
call spec_file_read_logical(file, 'do_camp_chem', run_part_opt%do_camp_chem)
52+
5153
run_part_opt%output_type = OUTPUT_TYPE_SINGLE
5254

5355
end subroutine

tests/test_dtors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
pytest.param(ppmc.AeroParticle(
1818
ppmc.AeroData(AERO_DATA_CTOR_ARG_MINIMAL),
1919
[0]
20-
), id='AeroParticle')
20+
), id='AeroParticle'),
21+
pytest.param(ppmc.Photolysis(), id='Photolysis'),
22+
pytest.param(ppmc.CampCore(), id='CampCore')
2123
))
2224
def test_dtors(sut): # pylint: disable=unused-argument
2325
# arrange

0 commit comments

Comments
 (0)