44# Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
55####################################################################################################
66
7+ import platform
8+
79import numpy as np
810import pytest
911
@@ -52,7 +54,7 @@ def test_run_part(common_args):
5254
5355 @staticmethod
5456 def test_run_part_timestep (common_args ):
55- ( last_output_time , last_progress_time , i_output ) = ppmc .run_part_timestep (
57+ last_output_time , last_progress_time , i_output = ppmc .run_part_timestep (
5658 * common_args , 1 , 0 , 0 , 0 , 1
5759 )
5860
@@ -63,14 +65,18 @@ def test_run_part_timestep(common_args):
6365
6466 @staticmethod
6567 def test_run_part_timeblock (common_args ):
68+ # arrange
6669 num_times = int (
6770 RUN_PART_OPT_CTOR_ARG_SIMULATION ["t_output" ]
6871 / RUN_PART_OPT_CTOR_ARG_SIMULATION ["del_t" ]
6972 )
70- (last_output_time , last_progress_time , i_output ) = ppmc .run_part_timeblock (
73+
74+ # act
75+ last_output_time , last_progress_time , i_output = ppmc .run_part_timeblock (
7176 * common_args , 1 , num_times , 0 , 0 , 0 , 1
7277 )
7378
79+ # assert
7480 assert last_output_time == RUN_PART_OPT_CTOR_ARG_SIMULATION ["t_output" ]
7581 assert last_progress_time == 0.0
7682 assert i_output == 2
@@ -94,8 +100,65 @@ def test_run_part_do_condensation(common_args, tmp_path):
94100 "do_condensation" : True ,
95101 }
96102 )
97- aero_state .dist_sample (aero_dist , 1.0 , 0.0 , True , True )
103+ aero_state .dist_sample (aero_dist , 1.0 , 0.0 , False , False )
98104 ppmc .condense_equilib_particles (env_state , aero_data , aero_state )
99105 ppmc .run_part (* args )
100106
101107 assert np .sum (aero_state .masses (include = ["H2O" ])) > 0.0
108+
109+ @staticmethod
110+ @pytest .mark .parametrize (
111+ "flags" ,
112+ (
113+ ((True , True ), (True , False )),
114+ ((True , True ), (False , True )),
115+ ((True , True ), (False , False )),
116+ ((False , False ), (True , False )),
117+ ((False , False ), (False , True )),
118+ ((False , False ), (True , True )),
119+ ((True , False ), (False , False )),
120+ ((True , False ), (False , True )),
121+ ((False , True ), (False , False )),
122+ ((False , True ), (True , False )),
123+ ),
124+ )
125+ @pytest .mark .parametrize (
126+ "fun_args" ,
127+ (
128+ ("run_part" , []),
129+ ("run_part_timestep" , [0 , 0 , 0 , 0 , 0 ]),
130+ ("run_part_timeblock" , [0 , 0 , 0 , 0 , 0 , 0 ]),
131+ ),
132+ )
133+ @pytest .mark .skipif (platform .machine () == "arm64" , reason = "TODO #348" )
134+ def test_run_part_allow_flag_mismatch (common_args , tmp_path , fun_args , flags ):
135+ # arrange
136+ filename = tmp_path / "test"
137+ env_state = ppmc .EnvState (ENV_STATE_CTOR_ARG_HIGH_RH )
138+ aero_data = ppmc .AeroData (AERO_DATA_CTOR_ARG_FULL )
139+ aero_dist = ppmc .AeroDist (aero_data , AERO_DIST_CTOR_ARG_FULL )
140+ aero_state = ppmc .AeroState (aero_data , * AERO_STATE_CTOR_ARG_MINIMAL )
141+ args = list (common_args )
142+ args [0 ].init_env_state (env_state , 0.0 )
143+ args [1 ] = env_state
144+ args [2 ] = aero_data
145+ args [3 ] = aero_state
146+ args [6 ] = ppmc .RunPartOpt (
147+ {
148+ ** RUN_PART_OPT_CTOR_ARG_SIMULATION ,
149+ "output_prefix" : str (filename ),
150+ "allow_doubling" : flags [0 ][0 ],
151+ "allow_halving" : flags [0 ][1 ],
152+ }
153+ )
154+ aero_state .dist_sample (aero_dist , 1.0 , 0.0 , flags [1 ][0 ], flags [1 ][1 ])
155+
156+ # act
157+ with pytest .raises (RuntimeError ) as excinfo :
158+ getattr (ppmc , fun_args [0 ])(* args , * fun_args [1 ])
159+
160+ # assert
161+ assert (
162+ str (excinfo .value )
163+ == "allow halving/doubling flags set differently then while sampling"
164+ )
0 commit comments