Skip to content
Merged
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/Particle/ParticleContainer_ImpactX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ void init_ParticleContainer_ImpactX(py::module& m) {

// TODO: we might need to move all or most of the defines in here into a
// test/example submodule, so they do not collide with downstream projects
make_ParticleContainer_and_Iterators<SoAParticle<8, 0>, 8, 0>(m); // ImpactX 24.03+
make_ParticleContainer_and_Iterators<SoAParticle<11, 0>, 11, 0>(m); // ImpactX 26.01+
}
14 changes: 8 additions & 6 deletions tests/test_particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@


def test_particle_init():
p1 = amr.Particle_8_0()
p1 = amr.Particle_11_0()
print(p1)

p2 = amr.Particle_8_0(1.0, 2.0, 3.0)
p2 = amr.Particle_11_0(1.0, 2.0, 3.0)
assert p2.x == 1.0 and p2.y == 2.0 and p2.z == 3.0

p3 = amr.Particle_8_0(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0)
p3 = amr.Particle_11_0(
1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0
)
assert p3.x == 1.0 and p3.get_rdata(0) == 4.0 and p3.get_rdata(6) == 10.0

p4 = amr.Particle_8_0(1.0, 2.0, 3.0, rdata_0=4.0)
p4 = amr.Particle_11_0(1.0, 2.0, 3.0, rdata_0=4.0)
assert (
p4.x == 1.0
and p4.z == 3.0
and p4.get_rdata(0) == 4.0
and p4.get_rdata(1) == 0 == p4.get_rdata(2) == p4.get_rdata(3)
)

p5 = amr.Particle_8_0(x=1.0, rdata_1=1.0, rdata_3=3.0)
p5 = amr.Particle_11_0(x=1.0, rdata_1=1.0, rdata_3=3.0)
assert (
p5.x == 1.0
and p5.get_rdata(1) == 1.0
Expand All @@ -35,7 +37,7 @@ def test_particle_init():

@pytest.mark.skipif(amr.Config.spacedim != 3, reason="Requires AMREX_SPACEDIM = 3")
def test_particle_set():
p1 = amr.Particle_8_0()
p1 = amr.Particle_11_0()
p1.setPos(1, 1.5)
assert (
np.isclose(p1.pos(0), 0)
Expand Down
18 changes: 10 additions & 8 deletions tests/test_particleContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def empty_particle_container(std_geometry, distmap, boxarr):

@pytest.fixture(scope="function")
def empty_soa_particle_container(std_geometry, distmap, boxarr):
pc = amr.ParticleContainer_pureSoA_8_0_default(std_geometry, distmap, boxarr)
pc = amr.ParticleContainer_pureSoA_11_0_default(std_geometry, distmap, boxarr)
return pc


Expand Down Expand Up @@ -74,32 +74,34 @@ def particle_container(Npart, std_geometry, distmap, boxarr, std_real_box):

@pytest.fixture(scope="function")
def soa_particle_container(Npart, std_geometry, distmap, boxarr, std_real_box):
pc = amr.ParticleContainer_pureSoA_8_0_default(std_geometry, distmap, boxarr)
myt = amr.ParticleInitType_pureSoA_8_0()
myt.real_array_data = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]
pc = amr.ParticleContainer_pureSoA_11_0_default(std_geometry, distmap, boxarr)
myt = amr.ParticleInitType_pureSoA_11_0()
myt.real_array_data = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.1, 1.2]
myt.int_array_data = []

with pytest.raises(Exception):
pc.set_soa_compile_time_names(
["x", "y", "z", "z", "b", "c", "d", "e"], []
["x", "y", "z", "z", "b", "c", "d", "e", "f", "g", "h"], []
) # error: z added twice
pc.set_soa_compile_time_names(["x", "y", "z", "a", "b", "c", "d", "e"], [])
pc.set_soa_compile_time_names(
["x", "y", "z", "a", "b", "c", "d", "e", "f", "g", "h"], []
)

iseed = 1
pc.init_random(Npart, iseed, myt, False, std_real_box)

# add runtime components: 1 real 2 int
with pytest.raises(Exception):
pc.add_real_comp("a", True) # already used as a compile-time component
pc.add_real_comp("f", True)
pc.add_real_comp("w", True)
pc.add_int_comp("i1", True)
pc.add_int_comp("i2", True)

# assign some values to runtime components
for lvl in range(pc.finest_level + 1):
for pti in pc.iterator(level=lvl):
soa = pti.soa()
soa.get_real_data(8).assign(1.2345)
soa.get_real_data(11).assign(1.2345)
soa.get_int_data(0).assign(42)
soa.get_int_data(1).assign(33)

Expand Down
Loading