Skip to content
Open
Show file tree
Hide file tree
Changes from 75 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
## Current develop

### Added (new features/APIs/variables/...)
- [[PR 1391]](https://github.com/parthenon-hpc-lab/parthenon/pull/1391) Towards Curvilinear Swarms
- [[PR 1382]](https://github.com/parthenon-hpc-lab/parthenon/pull/1382) Support Particle AMR
- [[PR 1378]](https://github.com/parthenon-hpc-lab/parthenon/pull/1378) MeshData Swarm Tasks
- [[PR 1377]](https://github.com/parthenon-hpc-lab/parthenon/pull/1377) Extend Initialization Hierarchy
- [[PR 1332]](https://github.com/parthenon-hpc-lab/parthenon/pull/1332) Add global WatchDog
Expand Down Expand Up @@ -36,6 +38,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 1377]](https://github.com/parthenon-hpc-lab/parthenon/pull/1377) Extend Initialization Hierarchy
- [[PR 1376]](https://github.com/parthenon-hpc-lab/parthenon/pull/1376) Refactor SwarmPacks

Expand Down
42 changes: 42 additions & 0 deletions dev/plan_histories/1382.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!-- This file was made in part with generative AI. -->

## Goal

Add correct AMR remeshing support for swarms so particle records are preserved across
refinement, derefinement, and same-level redistribution, while keeping the data path
compatible with device-resident execution and GPU-aware MPI.

## Functional Plan

- Add a dedicated swarm remesh phase that runs after the new leaf mesh and field AMR
transfers are already complete.
- Build the remesh around block ownership changes:
- same-level remap sends every particle in an old block to one new block
- derefinement sends every particle in a child block to its parent block
- refinement uses particle positions only to choose among that old block's daughters
- Represent each transported particle as one complete mixed-type record containing the
destination block identifier plus all swarm variables needed to reconstruct the
particle.
- Pack and unpack those particle records in a precision-independent wire format.
- Keep the swarm payload buffers device-resident during communication so off-rank
transfers can use direct device-buffer MPI, and keep same-rank transfers on the
device as well.
- Recreate the received particles in the destination swarms, restore all particle
variables, and clear any cached swarm pack state invalidated by the ownership change.
- Add the minimal generic swarm-schema helpers needed to enumerate variable names and
compute packed record sizes without hard-coding a particular swarm layout.
- Exercise the new capability in the `particle_tracers` example by enabling AMR tagging
and retaining an analytically checkable particle motion.
- Add focused validation for the new functionality:
- a refinement unit test that checks particles land on the correct daughter blocks
- a derefinement unit test that checks particles reunite on the correct parent block
- regression coverage that checks AMR tracer motion against the analytic translation
- Correct any supporting same-rank swarm communication issue needed to make these AMR
particle transfers reliable.

## Scope Boundaries

- Do not redesign the field AMR transfer path; only integrate the swarm remesh phase at
the correct point in the existing AMR sequence.
- Keep the implementation generic over swarm variable layout rather than tailoring it to
one example problem.
42 changes: 29 additions & 13 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 @@ -152,7 +161,11 @@ must be repeated in the driver’s evolution function until all particles
are completed. See the ``particles`` example for further details. Note
that this pattern is blocking, and may be replaced in the future.

AMR is currently not supported, but support will be added in the future.
AMR support for swarms is available. When the mesh changes, swarm
particles are redistributed to the correct new leaf block after
same-level redistribution, refinement, or derefinement. The
``particle_tracers`` example demonstrates this path for advected tracer
particles on an adaptively refined mesh.

Variable Packing
----------------
Expand All @@ -173,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 @@ -190,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 Expand Up @@ -292,3 +305,6 @@ Putting it all together, you might have an output block that looks like this:
The result would be that both ``swarm1`` and ``swarm2`` output the
variables ``id``, ``x``, ``y``, ``z``, and ``shared_var``. But only ``swarm1``
outputs ``per_swarm_var``.

.. note::
This file was made in part with generative AI.
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
74 changes: 60 additions & 14 deletions example/particle_tracers/particle_tracers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <vector>

// Parthenon includes
#include "amr_criteria/refinement_package.hpp"
#include "basic_types.hpp"
#include "bvals/comms/bvals_in_one.hpp"
#include "config.hpp"
Expand Down Expand Up @@ -115,6 +116,9 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {
const Real advected_amp = 0.5;
adv_pkg->AddParam("advected_mean", advected_mean);
adv_pkg->AddParam("advected_amp", advected_amp);
adv_pkg->AddParam("refine_tol", pin->GetOrAddReal("Background", "refine_tol", 1.25));
adv_pkg->AddParam("derefine_tol",
pin->GetOrAddReal("Background", "derefine_tol", 1.05));
PARTHENON_REQUIRE(advected_mean > advected_amp,
"Advected field must be everywere positive!");

Expand All @@ -130,9 +134,41 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {
// Assign package timestep hook
adv_pkg->EstimateTimestepMesh = EstimateTimestepMesh;

adv_pkg->CheckRefinementBlock = CheckRefinementBlock;

return adv_pkg;
}

AmrTag CheckRefinementBlock(MeshBlockData<Real> *rc) {
auto pmb = rc->GetBlockPointer();
auto pkg = pmb->packages.Get("advection_package");
static auto desc =
parthenon::MakePackDescriptor<field::advected>(pmb->resolved_packages.get());
auto pack = desc.GetPack(rc);

const IndexRange ib = pmb->cellbounds.GetBoundsI(IndexDomain::entire);
const IndexRange jb = pmb->cellbounds.GetBoundsJ(IndexDomain::entire);
const IndexRange kb = pmb->cellbounds.GetBoundsK(IndexDomain::entire);

typename Kokkos::MinMax<Real>::value_type minmax;
pmb->par_reduce(
PARTHENON_AUTO_LABEL, kb.s, kb.e, jb.s, jb.e, ib.s, ib.e,
KOKKOS_LAMBDA(const int k, const int j, const int i,
typename Kokkos::MinMax<Real>::value_type &lminmax) {
const Real val = pack(0, field::advected(), k, j, i);
lminmax.min_val = val < lminmax.min_val ? val : lminmax.min_val;
lminmax.max_val = val > lminmax.max_val ? val : lminmax.max_val;
},
Kokkos::MinMax<Real>(minmax));

const auto &refine_tol = pkg->Param<Real>("refine_tol");
const auto &derefine_tol = pkg->Param<Real>("derefine_tol");

if (minmax.max_val > refine_tol) return AmrTag::refine;
if (minmax.max_val < derefine_tol) return AmrTag::derefine;
return AmrTag::same;
}

} // namespace advection_package

namespace particles_package {
Expand Down Expand Up @@ -248,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 @@ -260,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 @@ -298,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 @@ -309,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 @@ -330,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 @@ -351,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 Expand Up @@ -505,6 +541,15 @@ TaskCollection ParticleDriver::StepTasks() {
auto defrag = tl.AddTask(deposit, parthenon::DefragSwarmsMesh, base, 0.9);
}

if (pmesh->adaptive) {
auto &amr_region = tc.AddRegion(num_partitions);
for (int i = 0; i < num_partitions; ++i) {
auto &tl = amr_region[i];
auto &base = pmesh->mesh_data.GetOrAdd("base", i);
tl.AddTask(none, parthenon::Refinement::Tag<MeshData<Real>>, base.get());
}
}

return tc;
}

Expand Down Expand Up @@ -533,8 +578,9 @@ void ProblemGenerator(MeshBlock *pmb, ParameterInput *pin) {

// Mesh physical size
const auto mesh_size = pmb->pmy_mesh->mesh_size;
const Real mesh_lx1 = mesh_size.xmax(X1DIR) - mesh_size.xmin(X1DIR);
const Real kwave = 2.0 * M_PI / mesh_lx1;
const Real x_min_mesh = mesh_size.xmin(X1DIR);
const Real x_max_mesh = mesh_size.xmax(X1DIR);
const Real kwave = 2.0 * M_PI / (x_max_mesh - x_min_mesh);

// Create pack
static auto desc = parthenon::MakePackDescriptor<field::advected>(resolved_pkgs.get());
Expand Down
4 changes: 4 additions & 0 deletions example/particle_tracers/particle_tracers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
// license in this material to reproduce, prepare derivative works, distribute copies to
// the public, perform publicly and display publicly, and to permit others to do so.
//========================================================================================

#ifndef EXAMPLE_PARTICLE_TRACERS_PARTICLE_TRACERS_HPP_
#define EXAMPLE_PARTICLE_TRACERS_PARTICLE_TRACERS_HPP_

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

#include <memory>

#include "Kokkos_Random.hpp"
Expand Down Expand Up @@ -59,6 +62,7 @@ namespace advection_package {

std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin);
Real EstimateTimestepMesh(MeshData<Real> *rc);
AmrTag CheckRefinementBlock(MeshBlockData<Real> *rc);

} // namespace advection_package

Expand Down
Loading
Loading