Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
5f0af20
Move sparse/swarmpack to unique dirs
pdmullen Mar 25, 2026
1766a75
Switch to cpp/hpp impl for SwarmPacks
pdmullen Mar 26, 2026
362dd18
Update changelog
pdmullen Mar 26, 2026
088d970
Merge remote-tracking branch 'origin/pdmullen/swarm-pack-uint64' into…
pdmullen Mar 26, 2026
5047be3
Attempt to generalize adding types to SwarmPack
pdmullen Mar 26, 2026
ede9ebc
Fix typo
pdmullen Mar 26, 2026
9ab1221
Format
pdmullen Mar 26, 2026
bb975c3
Add FinalInitialization hook
pdmullen Mar 26, 2026
3ead5b8
Update changelog and copyrights
pdmullen Mar 26, 2026
11f2fb2
Update src/pack/swarm_pack/swarm_pack_types.hpp
pdmullen Mar 26, 2026
03ac095
Fix a few includes
pdmullen Mar 26, 2026
ca734ce
Merge branch 'pdmullen/pack-refactor' of github.com:parthenon-hpc-lab…
pdmullen Mar 26, 2026
da63bf3
Merge remote-tracking branch 'origin/pdmullen/pack-refactor' into pdm…
pdmullen Mar 26, 2026
6d4cbd0
Demo usage and update docs
pdmullen Mar 26, 2026
f4feb75
Fix a few more includes
pdmullen Mar 26, 2026
6d3429d
Merge remote-tracking branch 'origin/pdmullen/pack-refactor' into pdm…
pdmullen Mar 26, 2026
35e3914
Include what you use
pdmullen Mar 27, 2026
0a9d388
Merge remote-tracking branch 'origin/pdmullen/pack-refactor' into pdm…
pdmullen Mar 27, 2026
9a2d47e
Add MeshData swarm tasks
pdmullen Mar 27, 2026
2f15d08
Update copyrights and changelog
pdmullen Mar 27, 2026
7cec51d
Not sure I like this change...
pdmullen Mar 27, 2026
d22f80b
Merge remote-tracking branch 'origin/develop' into pdmullen/pack-refa…
pdmullen Mar 27, 2026
0dc5184
Move PackIdxMap to pack_utils
pdmullen Mar 27, 2026
ccb74cb
Check Swarm Adds are consistent with SwarmPackTypes
pdmullen Mar 27, 2026
17c1b48
Include what you use
pdmullen Mar 27, 2026
628f11e
Merge remote-tracking branch 'origin/pdmullen/pack-refactor' into pdm…
pdmullen Mar 27, 2026
f0fc53a
Merge remote-tracking branch 'origin/pdmullen/final-init' into pdmull…
pdmullen Mar 27, 2026
962a259
Move swarm type check
pdmullen Mar 28, 2026
a996bbd
Merge remote-tracking branch 'origin/pdmullen/pack-refactor' into pdm…
pdmullen Mar 28, 2026
502ef54
Merge remote-tracking branch 'origin/pdmullen/final-init' into pdmull…
pdmullen Mar 28, 2026
9d5676e
Macro name change for type variable enrollment
pdmullen Mar 30, 2026
adb9334
Merge remote-tracking branch 'origin/pdmullen/pack-refactor' into pdm…
pdmullen Mar 30, 2026
6a20a8b
Merge remote-tracking branch 'origin/pdmullen/final-init' into pdmull…
pdmullen Mar 30, 2026
28b3c45
Address PR comments
pdmullen Mar 30, 2026
8b7c477
Address PR comments
pdmullen Mar 31, 2026
9f4dba2
Merge remote-tracking branch 'origin/pdmullen/final-init' into pdmull…
pdmullen Mar 31, 2026
401e59f
Support Particle AMR
pdmullen Apr 7, 2026
6ba07e3
Upload generative AI plan
pdmullen Apr 7, 2026
2b7afe0
Format
pdmullen Apr 7, 2026
9f1f85e
Add missing notices
pdmullen Apr 7, 2026
8b90173
std::memcpy --> Kokkos::bit_cast
pdmullen Apr 7, 2026
b5ee3dc
Fix register usage in particle_tracers
pdmullen Apr 7, 2026
cf08403
Do not host mirror positions for refinement branch
pdmullen Apr 8, 2026
fbe60f7
Move developer docs to dev folder
pdmullen Apr 8, 2026
d16fac6
Cleanup and fold expression
pdmullen Apr 8, 2026
243c751
Cleanup unnecessary ternaries
pdmullen Apr 8, 2026
7ce81e0
Format name change
pdmullen Apr 8, 2026
914c0c7
Move generic utilities to utils
pdmullen Apr 8, 2026
7a6aab1
Rename displs --> offsets
pdmullen Apr 8, 2026
82f021e
Rename PeerSet --> NeighborRanks
pdmullen Apr 8, 2026
d868b57
Unmanaged view for refinement remesh branch
pdmullen Apr 8, 2026
2433629
Update copyrights
pdmullen Apr 8, 2026
57c0ea1
Format
pdmullen Apr 8, 2026
58016eb
Merge branch 'develop' into pdmullen/final-init
pgrete Apr 9, 2026
634e443
Commit team-resolved name change
pdmullen Apr 9, 2026
9d66fff
Call PostInitialization on base
pdmullen Apr 9, 2026
1830f5d
Address pgrete lb comment
pdmullen Apr 9, 2026
e979177
Move generative AI notice to bottom note in rst
pdmullen Apr 10, 2026
c7d5677
Merge remote-tracking branch 'origin/develop' into pdmullen/swarm-mes…
pdmullen Apr 10, 2026
b1c170f
Merge remote-tracking branch 'origin/pdmullen/final-init' into pdmull…
pdmullen Apr 10, 2026
4d453e3
Fix merge conflict resolution
pdmullen Apr 10, 2026
51d240a
Merge remote-tracking branch 'origin/pdmullen/swarm-mesh-data-tasks' …
pdmullen Apr 10, 2026
3b58afa
Tidy up developer docs
pdmullen Apr 10, 2026
3e66bff
Fix more bad merge conflict resolutions
pdmullen Apr 10, 2026
323a787
Merge remote-tracking branch 'origin/pdmullen/swarm-mesh-data-tasks' …
pdmullen Apr 10, 2026
dc1aff8
Towards Curvilinear Swarms
pdmullen Apr 23, 2026
51660d7
Update changelog
pdmullen Apr 23, 2026
bd78759
Update copyrights
pdmullen Apr 23, 2026
aef9a6f
Merge remote-tracking branch 'origin/develop' into pdmullen/particle-…
pdmullen Apr 23, 2026
5754ee6
One more copyright
pdmullen Apr 23, 2026
c31b873
Merge remote-tracking branch 'origin/pdmullen/particle-amr-v2' into p…
pdmullen Apr 23, 2026
04c3c47
Fix bad merge conflict resolution
pdmullen Apr 23, 2026
70f9fb6
Merge remote-tracking branch 'origin/pdmullen/particle-amr-v2' into p…
pdmullen Apr 23, 2026
3c67bac
Fix a few more name changes
pdmullen Apr 23, 2026
c501317
And update copyrights
pdmullen Apr 23, 2026
9842147
Add backwards compatibility for old swarm position names
pdmullen May 6, 2026
6160e04
Update warning
pdmullen May 6, 2026
9dbe184
Merge remote-tracking branch 'origin/develop' into pdmullen/towards-c…
pdmullen May 6, 2026
52c013e
Restart backwards compatibility
pdmullen May 28, 2026
f6d14c7
Merge remote-tracking branch 'origin/develop' into pdmullen/towards-c…
pdmullen May 28, 2026
7213620
Merge remote-tracking branch 'origin/develop' into pdmullen/towards-c…
pdmullen Jun 18, 2026
834fdea
Try to add OpenPMD backwards compatibility
pdmullen Jun 18, 2026
f2edca4
Copyrights and disclaimers
pdmullen Jun 18, 2026
fbee784
Try this
pdmullen Jun 18, 2026
719358a
Formatting
pdmullen Jun 18, 2026
224a884
Include what used
pdmullen Jun 18, 2026
509115f
Merge branch 'develop' into pdmullen/towards-curv-swarm
pdmullen Jul 13, 2026
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Current develop

### Added (new features/APIs/variables/...)
- [[PR 1391]](https://github.com/parthenon-hpc-lab/parthenon/pull/1391) Towards Curvilinear Swarms
- [[PR 1408]](https://github.com/parthenon-hpc-lab/parthenon/pull/1408) Add GetAsUnresolvedString() method to ParameterInput
- [[PR 1050]](https://github.com/parthenon-hpc-lab/parthenon/pull/1050) Add support for OpenPMD/ADIOS2 output (incl slices and coarsened dumps)
- [[PR 1271]](https://github.com/parthenon-hpc-lab/parthenon/pull/1271) Add option to set a minimum number of teams for boundary communication kernels
Expand Down Expand Up @@ -51,6 +52,7 @@


### Incompatibilities (i.e. breaking changes)
- [[PR 1391]](https://github.com/parthenon-hpc-lab/parthenon/pull/1391) Towards Curvilinear Swarms

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

- [[PR 1385]](https://github.com/parthenon-hpc-lab/parthenon/pull/1385) ParameterInput internal storage refactor removes direct access to linked list (`pfirst_block`). Use `GetBlocksWithPrefix()` or `GetBlockNames()` instead.
- [[PR 1351]](https://github.com/parthenon-hpc-lab/parthenon/pull/1351) Bump Kokkos 5 & C++20
- [[PR 1377]](https://github.com/parthenon-hpc-lab/parthenon/pull/1377) Extend Initialization Hierarchy
Expand Down
33 changes: 21 additions & 12 deletions doc/sphinx/src/particles.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. This file was made in part with generative AI.

Particles
=========

Expand All @@ -11,8 +13,8 @@ Swarms

A ``Swarm`` contains all the particle data for all particles of a given
species. It owns a set of ``ParticleVariable``\ s, one for each value of
each particle. For example, the spatial positions ``x``, ``y``, and
``z`` of the particles in a swarm are three separate
each particle. For example, the spatial positions ``x1``, ``x2``, and
``x3`` of the particles in a swarm are three separate
``ParticleVariable``\ s. ``ParticleVariable``\ s can be either ``Real``-,
``uint64_t``-, or ``int``-valued, which is specified by the metadata values
``Metadata::Real``, ``MetaData::UInt64``, and ``Metadata::Integer``. ``ParticleVariable``\ s
Expand All @@ -21,7 +23,7 @@ should also contain the ``Metadata::Particle`` flag. By default,
to 2D data per particle is currently supported, by passing
``std::vector<int>{N1, N2}`` as the second argument to the
``ParticleVariable`` ``Metadata``. All ``Swarm``\ s by default contain
positional ``x``, ``y``, and ``z`` ``ParticleVariable``\ s and a ``uint64`` particle
positional ``x1``, ``x2``, and ``x3`` ``ParticleVariable``\ s and a ``uint64`` particle
``id`` that is persistent and unique for a given simulation.
The latter field can be disabled (e.g., because it is not required for a method
that constant creates and destroys anonymous particles) by providing the
Expand All @@ -47,6 +49,13 @@ permit ``Swarm``s to be retrieved from ``"base"`` ``MeshBlockData`` and ``MeshDa
particles that the reservation holds for a given swarm by calling
``metadata.SetInitialSwarmPoolReservation(nparticles);``.

.. note::

Particle infrastructure now operates in the native ``x1``, ``x2``, and ``x3``
coordinate directions rather than assuming Cartesian ``x``, ``y``, and ``z``.
That said, particles and swarms in curvilinear coordinate systems remain mostly
untested.

The ``Swarm`` is a host-side object, but some of its data members are
required for device- side compution. To access this data, a
``SwarmDeviceContext`` object is created via
Expand Down Expand Up @@ -92,11 +101,11 @@ computations on currently active particles:

.. code:: cpp

auto &x = swarm.Get("x").Get();
auto &x1 = swarm.Get(swarm_position::x1::name()).Get();
swarm.pmy_block->par_for("Simple loop", 0, swarm.GetMaxActiveIndex(),
KOKKOS_LAMBDA(const int n) {
if (swarm_d.IsActive(n)) {
x(n) += 1.0;
x1(n) += 1.0;
}
});

Expand Down Expand Up @@ -177,14 +186,14 @@ Similar to grid variables, swarms can be packed over ``MeshBlock``\ s via ``Swar
a ``SwarmPack`` via a ``std::vector<std::string>`` or the type-based variable prescription
previously used by ``SparsePack``\ s (see :ref:`sparse_packs`).

For packing via string (wherein below, ``swarm_position::x::name()`` returns a string),
For packing via string (wherein below, ``swarm_position::x1::name()`` returns a string),
one must specify the data type by template argument:

.. code:: cpp

std::vector<std::string> vars{swarm_position::x::name(),
swarm_position::y::name(),
swarm_position::z::name()};
std::vector<std::string> vars{swarm_position::x1::name(),
swarm_position::x2::name(),
swarm_position::x3::name()};
static auto desc = MakeSwarmPackDescriptor<Real>(swarm_name, vars);
auto pack = desc.GetPack(md);

Expand All @@ -194,9 +203,9 @@ example), the type can be inferred automatically:

.. code:: cpp

static auto desc = MakeSwarmPackDescriptor<swarm_position::x,
swarm_position::y,
swarm_position::z>(swarm_name);
static auto desc = MakeSwarmPackDescriptor<swarm_position::x1,
swarm_position::x2,
swarm_position::x3>(swarm_name);
auto pack = desc.GetPack(md);


Expand Down
20 changes: 10 additions & 10 deletions example/particle_leapfrog/particle_leapfrog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ void PostInitialization(MeshBlock *pmb, ParameterInput *pin) {
auto new_particles_context = swarm->AddEmptyParticles(num_particles_this_block);

auto &id = swarm->Get<std::uint64_t>(swarm_position::id::name()).Get();
auto &x = swarm->Get<Real>(swarm_position::x::name()).Get();
auto &y = swarm->Get<Real>(swarm_position::y::name()).Get();
auto &z = swarm->Get<Real>(swarm_position::z::name()).Get();
auto &x = swarm->Get<Real>(swarm_position::x1::name()).Get();
auto &y = swarm->Get<Real>(swarm_position::x2::name()).Get();
auto &z = swarm->Get<Real>(swarm_position::x3::name()).Get();
auto &v = swarm->Get<Real>("v").Get();
auto &vv = swarm->Get<Real>("vv").Get();

Expand Down Expand Up @@ -225,7 +225,7 @@ TaskStatus TransportParticles(MeshData<Real> *md, const StagedIntegrator *integr
// NOTE(@pdmullen): the data type for Positions (Real) are automatically deduced from
// the variable typing
static auto desc_pos =
MakeSwarmPackDescriptor<swarm_position::x, swarm_position::y, swarm_position::z>(
MakeSwarmPackDescriptor<swarm_position::x1, swarm_position::x2, swarm_position::x3>(
swarm_name);
auto pack_pos = desc_pos.GetPack(md);

Expand All @@ -250,19 +250,19 @@ TaskStatus TransportParticles(MeshData<Real> *md, const StagedIntegrator *integr
const auto swarm_d = pack_pos.GetContext(b);
if (swarm_d.IsActive(n)) {
// drift
pack_pos(b, swarm_position::x(), n) += pack_v(b, iv + 0, n) * 0.5 * dt;
pack_pos(b, swarm_position::y(), n) += pack_v(b, iv + 1, n) * 0.5 * dt;
pack_pos(b, swarm_position::z(), n) += pack_v(b, iv + 2, n) * 0.5 * dt;
pack_pos(b, swarm_position::x1(), n) += pack_v(b, iv + 0, n) * 0.5 * dt;
pack_pos(b, swarm_position::x2(), n) += pack_v(b, iv + 1, n) * 0.5 * dt;
pack_pos(b, swarm_position::x3(), n) += pack_v(b, iv + 2, n) * 0.5 * dt;

// kick
pack_v(b, iv + 0, n) += ax * dt;
pack_v(b, iv + 1, n) += ay * dt;
pack_v(b, iv + 2, n) += az * dt;

// drift
pack_pos(b, swarm_position::x(), n) += pack_v(b, iv + 0, n) * 0.5 * dt;
pack_pos(b, swarm_position::y(), n) += pack_v(b, iv + 1, n) * 0.5 * dt;
pack_pos(b, swarm_position::z(), n) += pack_v(b, iv + 2, n) * 0.5 * dt;
pack_pos(b, swarm_position::x1(), n) += pack_v(b, iv + 0, n) * 0.5 * dt;
pack_pos(b, swarm_position::x2(), n) += pack_v(b, iv + 1, n) * 0.5 * dt;
pack_pos(b, swarm_position::x3(), n) += pack_v(b, iv + 2, n) * 0.5 * dt;

// id
PARTHENON_REQUIRE(pack_id(b, swarm_position::id(), n) >= 0,
Expand Down
24 changes: 12 additions & 12 deletions example/particle_tracers/particle_tracers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void SourceTracers(MeshBlock *pmb, ParameterInput *pin) {

// Create pack
static auto desc =
MakeSwarmPackDescriptor<swarm_position::x, swarm_position::y, swarm_position::z>(
MakeSwarmPackDescriptor<swarm_position::x1, swarm_position::x2, swarm_position::x3>(
swarm_name);
auto pack = desc.GetPack(mbd.get());

Expand All @@ -296,9 +296,9 @@ void SourceTracers(MeshBlock *pmb, ParameterInput *pin) {
auto rng_gen = rng_pool.get_state();

// Extract particle position
Real &xx = pack(0, swarm_position::x(), n);
Real &yy = pack(0, swarm_position::y(), n);
Real &zz = pack(0, swarm_position::z(), n);
Real &xx = pack(0, swarm_position::x1(), n);
Real &yy = pack(0, swarm_position::x2(), n);
Real &zz = pack(0, swarm_position::x3(), n);

// Rejection sample the x position
Real val;
Expand Down Expand Up @@ -334,7 +334,7 @@ TaskStatus AdvectTracers(MeshData<Real> *md, const Real dt) {

// Create pack
static auto desc =
MakeSwarmPackDescriptor<swarm_position::x, swarm_position::y, swarm_position::z>(
MakeSwarmPackDescriptor<swarm_position::x1, swarm_position::x2, swarm_position::x3>(
swarm_name);
auto pack = desc.GetPack(md);

Expand All @@ -345,9 +345,9 @@ TaskStatus AdvectTracers(MeshData<Real> *md, const Real dt) {
auto [b, n] = pack.GetBlockParticleIndices(idx);
const auto &swarm_d = pack.GetContext(b);
if (swarm_d.IsActive(n)) {
pack(b, swarm_position::x(), n) += vx * dt;
pack(b, swarm_position::y(), n) += vy * dt;
pack(b, swarm_position::z(), n) += vz * dt;
pack(b, swarm_position::x1(), n) += vx * dt;
pack(b, swarm_position::x2(), n) += vy * dt;
pack(b, swarm_position::x3(), n) += vz * dt;
}
});

Expand All @@ -366,7 +366,7 @@ TaskStatus DepositTracers(MeshData<Real> *md) {
// Create packs
static auto desc = MakePackDescriptor<field::deposition>(resolved_pkgs.get());
static auto pdesc =
MakeSwarmPackDescriptor<swarm_position::x, swarm_position::y, swarm_position::z>(
MakeSwarmPackDescriptor<swarm_position::x1, swarm_position::x2, swarm_position::x3>(
swarm_name);
auto vmesh = desc.GetPack(md);
auto vpart = pdesc.GetPack(md);
Expand All @@ -387,9 +387,9 @@ TaskStatus DepositTracers(MeshData<Real> *md) {
const auto &swarm_d = vpart.GetContext(b);
if (swarm_d.IsActive(n)) {
int ip, jp, kp;
const Real &xx = vpart(b, swarm_position::x(), n);
const Real &yy = vpart(b, swarm_position::y(), n);
const Real &zz = vpart(b, swarm_position::z(), n);
const Real &xx = vpart(b, swarm_position::x1(), n);
const Real &yy = vpart(b, swarm_position::x2(), n);
const Real &zz = vpart(b, swarm_position::x3(), n);
swarm_d.Xtoijk(xx, yy, zz, ip, jp, kp);

// For testing in this example we make sure the indices are correct; these
Expand Down
22 changes: 12 additions & 10 deletions example/particles/particles.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//========================================================================================
// (C) (or copyright) 2020-2024. Triad National Security, LLC. All rights reserved.
// (C) (or copyright) 2020-2026. Triad National Security, LLC. All rights reserved.
//
// This program was produced under U.S. Government contract 89233218CNA000001 for Los
// Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC
Expand All @@ -11,6 +11,8 @@
// the public, perform publicly and display publicly, and to permit others to do so.
//========================================================================================

// This file was made in part with generative AI.

#include <algorithm>
#include <limits>
#include <memory>
Expand Down Expand Up @@ -183,9 +185,9 @@ TaskStatus DepositParticles(MeshBlock *pmb) {
const Real &minx_j = pmb->coords.Xf<2>(jb.s);
const Real &minx_k = pmb->coords.Xf<3>(kb.s);

const auto &x = swarm->Get<Real>(swarm_position::x::name()).Get();
const auto &y = swarm->Get<Real>(swarm_position::y::name()).Get();
const auto &z = swarm->Get<Real>(swarm_position::z::name()).Get();
const auto &x = swarm->Get<Real>(swarm_position::x1::name()).Get();
const auto &y = swarm->Get<Real>(swarm_position::x2::name()).Get();
const auto &z = swarm->Get<Real>(swarm_position::x3::name()).Get();
const auto &weight = swarm->Get<Real>("weight").Get();
auto swarm_d = swarm->GetDeviceContext();

Expand Down Expand Up @@ -262,9 +264,9 @@ TaskStatus CreateSomeParticles(MeshBlock *pmb, const double t0) {
const Real &minx_k = pmb->coords.Xf<3>(kb.s);

auto &t = swarm->Get<Real>("t").Get();
auto &x = swarm->Get<Real>(swarm_position::x::name()).Get();
auto &y = swarm->Get<Real>(swarm_position::y::name()).Get();
auto &z = swarm->Get<Real>(swarm_position::z::name()).Get();
auto &x = swarm->Get<Real>(swarm_position::x1::name()).Get();
auto &y = swarm->Get<Real>(swarm_position::x2::name()).Get();
auto &z = swarm->Get<Real>(swarm_position::x3::name()).Get();
auto &v = swarm->Get<Real>("v").Get();
auto &weight = swarm->Get<Real>("weight").Get();

Expand Down Expand Up @@ -373,9 +375,9 @@ TaskStatus TransportParticles(MeshBlock *pmb, const double t0, const double dt)
int max_active_index = swarm->GetMaxActiveIndex();

auto &t = swarm->Get<Real>("t").Get();
auto &x = swarm->Get<Real>(swarm_position::x::name()).Get();
auto &y = swarm->Get<Real>(swarm_position::y::name()).Get();
auto &z = swarm->Get<Real>(swarm_position::z::name()).Get();
auto &x = swarm->Get<Real>(swarm_position::x1::name()).Get();
auto &y = swarm->Get<Real>(swarm_position::x2::name()).Get();
auto &z = swarm->Get<Real>(swarm_position::x3::name()).Get();
auto &v = swarm->Get<Real>("v").Get();

const Real &dx_i = pmb->coords.Dxf<1>(pmb->cellbounds.is(IndexDomain::interior));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright(C) 2020-2025 The Parthenon collaboration
# Licensed under the 3-clause BSD License, see LICENSE file for details
# =========================================================================================
# (C) (or copyright) 2020-2025. Triad National Security, LLC. All rights reserved.
# (C) (or copyright) 2020-2026. Triad National Security, LLC. All rights reserved.
#
# This program was produced under U.S. Government contract 89233218CNA000001 for Los
# Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC
Expand All @@ -16,6 +16,8 @@
# the public, perform publicly and display publicly, and to permit others to do so.
# =========================================================================================

# This file was made in part with generative AI.

from __future__ import print_function

import re
Expand Down Expand Up @@ -450,8 +452,8 @@ def main():
ERROR_FLAG = True
break
swarm = data.GetSwarm(args.swarm)
swarmx = subsample(swarm.x, args.maxparticles)
swarmy = subsample(swarm.y, args.maxparticles)
swarmx = subsample(swarm.x1, args.maxparticles)
swarmy = subsample(swarm.x2, args.maxparticles)
if args.swarmcolor is not None:
if not is_color_like(args.swarmcolor):
if args.swarmcolor not in swarm.variables:
Expand Down
43 changes: 35 additions & 8 deletions scripts/python/packages/parthenon_tools/parthenon_tools/phdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright(C) 2020-2024 The Parthenon collaboration
# Licensed under the 3-clause BSD License, see LICENSE file for details
# =========================================================================================
# (C) (or copyright) 2020-2024. Triad National Security, LLC. All rights reserved.
# (C) (or copyright) 2020-2026. Triad National Security, LLC. All rights reserved.
#
# This program was produced under U.S. Government contract 89233218CNA000001 for Los
# Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC
Expand All @@ -15,6 +15,8 @@
# the public, perform publicly and display publicly, and to permit others to do so.
# =========================================================================================

# This file was made in part with generative AI.

from __future__ import print_function
import h5py as h
import os, sys, errno
Expand All @@ -27,7 +29,8 @@ class Swarm:
name: The name of the swarm
variables: The variables in available in the swarm.
varData: The swarm variables. Greedily accessed.
x, y, z: The x, y, and z positions of the swarm
x, y, z: Legacy position accessors
x1, x2, x3: Position accessors in native mesh coordinates
"""

def __init__(self, fid, swarmname):
Expand All @@ -43,16 +46,28 @@ def Block(self, b):
"""Returns a Python slice for the particles only on block b"""
return slice(self.offsets[b], self.offsets[b] + self.counts[b] + 1)

def _get_exact(self, variable):
if variable not in self.varData:
self.varData[variable] = self.gid[variable][:]
return self.varData[variable]

def _get_compat(self, variables):
for variable in variables:
try:
return self._get_exact(variable)
except KeyError:
pass
print(f"ERROR: none of {variables} found in {self.name}")
return None

def Get(self, variable):
"""Reads data for the named swarm var from file and caches it in the
dictionary. Returns None if variable is not found in the file
or data. Data is always of shape:
[tensor indices, particle index]
"""
try:
if self.varData.get(variable) is None:
self.varData[variable] = self.gid[variable][:]
return self.varData[variable]
return self._get_exact(variable)
except KeyError:
print(f"ERROR: {variable} not found in {self.name}")
return None
Expand All @@ -63,15 +78,27 @@ def id(self):

@property
def x(self):
return self.Get("swarm.x")
return self._get_compat(("swarm.x", "swarm.x1"))

@property
def y(self):
return self.Get("swarm.y")
return self._get_compat(("swarm.y", "swarm.x2"))

@property
def z(self):
return self.Get("swarm.z")
return self._get_compat(("swarm.z", "swarm.x3"))

@property
def x1(self):
return self._get_compat(("swarm.x1", "swarm.x"))

@property
def x2(self):
return self._get_compat(("swarm.x2", "swarm.y"))

@property
def x3(self):
return self._get_compat(("swarm.x3", "swarm.z"))

def __getitem__(self, key):
return self.Get(key)
Expand Down
Loading
Loading