Skip to content

Add support for tracer particles#102

Merged
pgrete merged 49 commits into
mainfrom
pgrete/tracer
May 7, 2025
Merged

Add support for tracer particles#102
pgrete merged 49 commits into
mainfrom
pgrete/tracer

Conversation

@pgrete
Copy link
Copy Markdown
Contributor

@pgrete pgrete commented Mar 4, 2024

Alright, I'm done with the cleanup,i.e., I

  • separated the general from the problem specific pieces
  • added appropriate callbacks
  • added a test
  • added doc

It'd be great if you, @BenWibking and @mfournier01 could review from the "all the basic bases are covered" point of view.
There's some stuff left I/we may want to address (in the near future) but I think it's cleaner to address those in separate smaller PRs.
I'm particularly interested in @mfournier01 feedback from the "documentation" and "is it clear what's going on" point of view as you're a new developer that will have to modify the code very soon.
So I'd be happy to provide more info in the code/docs already in this PR to make things clearer where required.

Future cleanup items:

  • Allow for 2D sims
  • Add additional/other integrators/advection methods
  • Find origin of tiny drift
  • Migrate to SwarmPacks
  • Allow more flexiblity wrt tracked fields (e.g., not make/calc prims by default)

Python analysis/plotting example:

import matplotlib.pyplot as plt
import numpy as np
import sys
sys.path.insert(
    1,
    "/home/pgrete/src/athenapk/external/parthenon"
    + "/scripts/python/packages/parthenon_tools/parthenon_tools",
)

try:
    import phdf
except ModuleNotFoundError:
    print("Couldn't find module to read Parthenon hdf5 files.")

data = phdf.phdf("../run-turbulence/parthenon.prim.00010.phdf")
tracers = data.GetSwarm("tracers")
xs = tracers.x
ys = tracers.y
zs = tracers.z
ids = tracers.Get("id")

fig = plt.figure()
ax = fig.add_subplot(projection='3d')

ax.scatter(xs, ys, zs,s=1,c=ids)#,cmap="plasma")

results in
image

with lookback times available in

data.Params["tracers/t_lookback"]

from parameters in an output block like

<parthenon/output2>
file_type  = hdf5       # Binary data dump
variables   = prim   # variables to be output
dt         = 0.1        # time increment between outputs
id         = prim
single_precision_output = true

swarms = tracers
tracers_variables = id, x, y, z, rho, s, sdot

and tracers enabled by an additional block as

<tracers>
enabled = true
num_tracers_per_cell = 0.125

@pgrete pgrete changed the title Pgrete/tracer WIP tracers Mar 4, 2024
Comment thread src/tracers/tracers.cpp
Comment thread src/tracers/tracers.cpp Outdated
@pgrete pgrete mentioned this pull request Jan 24, 2025
@pgrete pgrete changed the title WIP tracers Add support for tracer particles Mar 28, 2025
@pgrete pgrete added the enhancement New feature or request label Mar 28, 2025
Copy link
Copy Markdown
Collaborator

@mfournier01 mfournier01 left a comment

Choose a reason for hiding this comment

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

Left a few comments for clarifications of what the code is doing but I haven't found any typo. The documentation is pretty clear.

Comment thread docs/pgen.md
// First order operator split tracer advection
if (stage == integrator->nstages && tracers_pkg->Param<bool>("enabled")) {
const std::string swarm_name = "tracers";
TaskRegion &sync_region_tr = tc.AddRegion(1);
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.

Not yet clear to me: why do we need only one tacklist per region in that case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm actually not sure if this is 100% required, but as long as we're running with a single host thread this should not make any difference.

Comment thread src/hydro/hydro_driver.cpp
Comment thread src/pgen/turbulence.cpp
Comment thread src/tracers/tracers.cpp
Copy link
Copy Markdown
Contributor

@BenWibking BenWibking left a comment

Choose a reason for hiding this comment

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

Minor comments inline.

Also, I added a plotting script in scripts/ based on the example you provided in the docs. I also uploaded an input file that included a <tracers> block, since it looked like none of the existing problems had one.

Comment thread docs/input.md
Comment thread docs/input.md Outdated
tracers_variables = id, x, y, z, rho
```

Tracers can be read/processed by the `phdf` package shipped with the Parthenon submodule.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are particles included in the XDMF output? If not, I think it would be helpful to be explicit that this is the case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They're currently not. I added the info.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, I take that back. They can be written to xdmf but it has to be manually activated.
I now extended the example input file and doc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

image

Comment thread src/hydro/hydro_driver.cpp Outdated
Comment thread src/hydro/hydro_driver.cpp
Comment thread src/tracers/tracers.cpp
Comment thread src/tracers/tracers.cpp
Comment thread src/tracers/tracers.cpp
Comment thread src/tracers/tracers.hpp Outdated
Comment thread src/pgen/turbulence.cpp
@BenWibking
Copy link
Copy Markdown
Contributor

BenWibking commented Apr 15, 2025

Looks nice!

tracers.mp4

@pgrete pgrete enabled auto-merge (squash) May 7, 2025 11:53
Copy link
Copy Markdown
Contributor

@BenWibking BenWibking left a comment

Choose a reason for hiding this comment

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

LGTM

@pgrete pgrete merged commit e7da245 into main May 7, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants