Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/aero_particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(self, fn, len);
}
Expand Down
19 changes: 14 additions & 5 deletions tests/test_aero_particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
####################################################################################################

import copy
import gc

import numpy as np
Expand All @@ -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

Expand Down Expand Up @@ -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():
Expand Down
Loading