diff --git a/src/aero_particle.hpp b/src/aero_particle.hpp index 36c21759..14860302 100644 --- a/src/aero_particle.hpp +++ b/src/aero_particle.hpp @@ -222,7 +222,7 @@ struct AeroParticle { } static auto sources(const AeroParticle &self) { - int len = AeroData::__len__(*self.aero_data); + int len = AeroData::n_source(*self.aero_data); auto fn = f_aero_particle_get_component_sources; return pypartmc::get_array_values_set_len(self, fn, len); } diff --git a/tests/test_aero_particle.py b/tests/test_aero_particle.py index 7c65cae6..372802dd 100644 --- a/tests/test_aero_particle.py +++ b/tests/test_aero_particle.py @@ -4,6 +4,7 @@ # Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors # #################################################################################################### +import copy import gc import numpy as np @@ -14,6 +15,7 @@ from .test_aero_data import AERO_DATA_CTOR_ARG_MINIMAL from .test_aero_dist import AERO_DIST_CTOR_ARG_MINIMAL +from .test_aero_mode import AERO_MODE_CTOR_LOG_NORMAL from .test_aero_state import AERO_STATE_CTOR_ARG_MINIMAL from .test_env_state import ENV_STATE_CTOR_ARG_MINIMAL @@ -504,16 +506,23 @@ def test_refract_core(): def test_sources(): # arrange aero_data = ppmc.AeroData(AERO_DATA_CTOR_ARG_MINIMAL) - aero_dist = ppmc.AeroDist(aero_data, AERO_DIST_CTOR_ARG_MINIMAL) + # two log-normal modes differing only in name (i.e. source) + modes = copy.deepcopy(AERO_MODE_CTOR_LOG_NORMAL) + modes["test_mode_2"] = copy.deepcopy(AERO_MODE_CTOR_LOG_NORMAL["test_mode"]) + aero_dist = ppmc.AeroDist(aero_data, [modes]) aero_state = ppmc.AeroState(aero_data, *AERO_STATE_CTOR_ARG_MINIMAL) _ = aero_state.dist_sample(aero_dist, 1.0, 0.0) - sut = aero_state.particle(0) + # act - sources = sut.sources + sources = [ + aero_state.particle(i_part).sources for i_part in range(len(aero_state)) + ] # assert - assert len(sources) == aero_dist.n_mode - assert isinstance(sources[0], int) + assert aero_data.n_source == aero_dist.n_mode + assert all(len(src) == aero_data.n_source for src in sources) + assert isinstance(sources[0][0], int) + assert all(sum(src) == 1 for src in sources) @staticmethod def test_get_weighting():