Skip to content

Commit 3e6794e

Browse files
authored
Enable mosaic support if available (#209)
1 parent 4de348f commit 3e6794e

File tree

5 files changed

+74
-17
lines changed

5 files changed

+74
-17
lines changed

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,17 @@ target_include_directories(partmclib PRIVATE
286286
target_link_libraries(partmclib PRIVATE camplib)
287287
target_link_libraries(partmclib PRIVATE ${SUNDIALS_items})
288288
target_link_libraries(partmclib PRIVATE klulib)
289+
if(DEFINED ENV{MOSAIC_HOME})
290+
message(STATUS "MOSAIC enabled: $ENV{MOSAIC_HOME}")
291+
target_compile_definitions(partmclib PRIVATE PMC_USE_MOSAIC="1")
292+
find_library(mosaiclib mosaic
293+
DOC "MOSAIC library"
294+
PATHS $ENV{MOSAIC_HOME})
295+
target_link_libraries(partmclib PRIVATE ${mosaiclib})
296+
target_include_directories(partmclib PRIVATE
297+
$ENV{MOSAIC_HOME}/datamodules
298+
)
299+
endif()
289300

290301
### PYBIND11 & PyPartMC ############################################################################
291302

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ PyPartMC is used within the [test workflow of the PySDM project](https://github.
7878
- JSON support is handled with [nlohmann::json](https://github.com/nlohmann/json) and [pybind11_json](https://github.com/pybind/pybind11_json)
7979
- PartMC and selected parts of SUNDIALS are statically linked (and compiled in during `pip install` or `python -m build`)
8080
- C (SUNDIALS), C++ (pybind11, ...) and Fortran (PartMC, CAMP) dependencies are linked through [git submodules](https://github.com/open-atmos/PyPartMC/blob/main/.gitmodules)
81+
- MOSAIC dependency is optionally linked through setting the environmental variable MOSAIC_HOME
8182
- a [mock of Fortran netCDF API](https://github.com/open-atmos/PyPartMC/blob/main/src/fake_netcdf.F90) and a [mock of PartMC spec file API](https://github.com/open-atmos/PyPartMC/blob/main/src/fake_spec_file.F90) are used for i/o from/to JSON
8283

8384
## Troubleshooting

src/run_part.F90

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ subroutine f_run_part( &
5151
call c_f_pointer(gas_data_ptr_c, gas_data_ptr_f)
5252
call c_f_pointer(gas_state_ptr_c, gas_state_ptr_f)
5353
call c_f_pointer(run_part_opt_ptr_c, run_part_opt_ptr_f)
54+
55+
if (env_state_ptr_f%elapsed_time < run_part_opt_ptr_f%del_t) then
56+
call mosaic_init(env_state_ptr_f, aero_data_ptr_f, run_part_opt_ptr_f%del_t, &
57+
run_part_opt_ptr_f%do_optical)
58+
end if
59+
5460
call run_part( &
5561
scenario_ptr_f, &
5662
env_state_ptr_f, &
@@ -127,6 +133,10 @@ subroutine f_run_part_timestep( &
127133
progress_n_dil_out = 0
128134
progress_n_nuc = 0
129135

136+
if (env_state_ptr_f%elapsed_time < run_part_opt_ptr_f%del_t) then
137+
call mosaic_init(env_state_ptr_f, aero_data_ptr_f, run_part_opt_ptr_f%del_t, &
138+
run_part_opt_ptr_f%do_optical)
139+
end if
130140
call run_part_timestep(scenario_ptr_f, env_state_ptr_f, aero_data_ptr_f, aero_state_ptr_f, &
131141
gas_data_ptr_f, gas_state_ptr_f, run_part_opt_ptr_f, camp_core_ptr_f, photolysis_ptr_f, &
132142
i_time, t_start, last_output_time, &
@@ -204,6 +214,11 @@ subroutine f_run_part_timeblock( &
204214
progress_n_dil_out = 0
205215
progress_n_nuc = 0
206216

217+
if (env_state_ptr_f%elapsed_time < run_part_opt_ptr_f%del_t) then
218+
call mosaic_init(env_state_ptr_f, aero_data_ptr_f, run_part_opt_ptr_f%del_t, &
219+
run_part_opt_ptr_f%do_optical)
220+
end if
221+
207222
call run_part_timeblock(scenario_ptr_f, env_state_ptr_f, aero_data_ptr_f, aero_state_ptr_f, &
208223
gas_data_ptr_f, gas_state_ptr_f, run_part_opt_ptr_f, camp_core_ptr_f, photolysis_ptr_f, &
209224
i_time, i_next, t_start, last_output_time, &

src/run_part_opt.F90

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ subroutine f_run_part_opt_from_json(ptr_c) bind(C)
4848
call spec_file_read_logical(file, 'do_parallel', run_part_opt%do_parallel)
4949
if (run_part_opt%do_parallel) then
5050
#ifndef PMC_USE_MPI
51-
call spec_file_die_msg(929006383, file, &
51+
call spec_file_die_msg(929006384, file, &
5252
'cannot use parallel mode, support is not compiled in')
5353
#endif
5454
call spec_file_read_output_type(file, run_part_opt%output_type)
@@ -68,32 +68,60 @@ subroutine f_run_part_opt_from_json(ptr_c) bind(C)
6868
run_part_opt%parallel_coag_type = PARALLEL_COAG_TYPE_LOCAL
6969
end if
7070

71+
call spec_file_read_logical(file, 'do_mosaic', run_part_opt%do_mosaic)
72+
if (run_part_opt%do_mosaic .and. (.not. mosaic_support())) then
73+
call spec_file_die_msg(230495366, file, &
74+
'cannot use MOSAIC, support is not compiled in')
75+
end if
76+
77+
if (run_part_opt%do_mosaic) then
78+
call spec_file_read_logical(file, 'do_optical', &
79+
run_part_opt%do_optical)
80+
else
81+
run_part_opt%do_optical = .false.
82+
end if
83+
7184
call spec_file_read_logical(file, 'do_nucleation', &
7285
run_part_opt%do_nucleation)
73-
!if (run_part_opt%do_nucleation) then
74-
! call spec_file_read_nucleate_type(file, aero_data, &
75-
! run_part_opt%nucleate_type, run_part_opt%nucleate_source)
76-
!else
77-
run_part_opt%nucleate_type = NUCLEATE_TYPE_INVALID
78-
!end if
86+
!!! TODO #214
87+
if (run_part_opt%do_nucleation) then
88+
call spec_file_die_msg(230495367, file, &
89+
'cannot use nucleation, support is not compiled in')
90+
end if
91+
! if (run_part_opt%do_nucleation) then
92+
! call spec_file_read_nucleate_type(file, aero_data, &
93+
! run_part_opt%nucleate_type, run_part_opt%nucleate_source)
94+
! else
95+
! run_part_opt%nucleate_type = NUCLEATE_TYPE_INVALID
96+
! end if
7997

8098
call spec_file_read_logical(file, 'do_condensation', &
8199
run_part_opt%do_condensation)
100+
#ifndef PMC_USE_SUNDIALS
101+
call assert_msg(121370218, &
102+
run_part_opt%do_condensation .eqv. .false., &
103+
"cannot use condensation, SUNDIALS support is not compiled in")
104+
#endif
105+
106+
if (run_part_opt%do_mosaic .and. run_part_opt%do_condensation) then
107+
call spec_file_die_msg(599877805, file, &
108+
'cannot use MOSAIC and condensation simultaneously')
109+
end if
82110

83-
call spec_file_read_real(file, 't_max', run_part_opt%t_max)
84-
call spec_file_read_real(file, 'del_t', run_part_opt%del_t)
85-
call spec_file_read_real(file, 't_output', run_part_opt%t_output)
86-
call spec_file_read_real(file, 't_progress', run_part_opt%t_progress)
111+
call spec_file_read_real(file, 't_max', run_part_opt%t_max)
112+
call spec_file_read_real(file, 'del_t', run_part_opt%del_t)
113+
call spec_file_read_real(file, 't_output', run_part_opt%t_output)
114+
call spec_file_read_real(file, 't_progress', run_part_opt%t_progress)
87115

88-
call spec_file_read_integer(file, 'rand_init', rand_init)
89-
call spec_file_read_logical(file, 'allow_doubling', run_part_opt%allow_doubling)
90-
call spec_file_read_logical(file, 'allow_halving', run_part_opt%allow_halving)
116+
call spec_file_read_integer(file, 'rand_init', rand_init)
117+
call spec_file_read_logical(file, 'allow_doubling', run_part_opt%allow_doubling)
118+
call spec_file_read_logical(file, 'allow_halving', run_part_opt%allow_halving)
91119

92-
call spec_file_read_logical(file, 'do_camp_chem', run_part_opt%do_camp_chem)
120+
call spec_file_read_logical(file, 'do_camp_chem', run_part_opt%do_camp_chem)
93121

94-
run_part_opt%output_type = OUTPUT_TYPE_SINGLE
122+
run_part_opt%output_type = OUTPUT_TYPE_SINGLE
95123

96-
call pmc_srand(rand_init, 0)
124+
call pmc_srand(rand_init, 0)
97125

98126
end subroutine
99127

tests/test_run_part_opt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"do_coagulation": False,
1616
"do_parallel": False,
1717
"do_nucleation": False,
18+
"do_mosaic": False,
19+
"do_optical": False,
1820
"do_condensation": False,
1921
"do_camp_chem": False,
2022
"t_max": 0,

0 commit comments

Comments
 (0)