Skip to content

Drift kinetic model#228

Draft
emilegrivet wants to merge 25 commits intodevelfrom
drift_kinetic_model
Draft

Drift kinetic model#228
emilegrivet wants to merge 25 commits intodevelfrom
drift_kinetic_model

Conversation

@emilegrivet
Copy link
Copy Markdown

@emilegrivet emilegrivet commented Apr 23, 2026

Addition of a plotting method for the KineticBackground objects. Possibility to plot a 1D or 2D projection of the phase space background.

Initialization of the example/drift_kinetic_model directory and of the parameter and pproc files.

emilegrivet and others added 22 commits April 14, 2026 12:01
…entation of the base_units system, and added the possibility to modulate the alpha parameter in the toy_drift model method __init__
…lation, modification of the calculation of the growth rate
…mdata directory instead of the general one (params_diocotron.py)
Copy link
Copy Markdown
Member

@spossann spossann left a comment

Choose a reason for hiding this comment

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

Looks good! I have some minor comments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is this example file for?

Comment thread src/struphy/io/options.py

# fields background
BackgroundTypes = Literal["LogicalConst", "FluidEquilibrium"]
DimensionToPlot = Literal["e1", "e2", "e3", "v1", "v2", "v3"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should maybe be called KineticDimensionsToPlot

Comment thread src/struphy/kinetic_background/base.py Outdated
Comment thread src/struphy/kinetic_background/base.py Outdated
Comment thread src/struphy/kinetic_background/base.py Outdated
if axe_to_plot - 3 > self.vdim:
AssertionError("Coordinate " + dim_1 + " does not exist with this background")
linspace_space = xp.array([0.0])
integrate_linspace_vel = xp.linspace(0.0, v_lim, integrate_resol)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this ok here that the velocity space starts at 0? I would expect xp.linspace(-v_lim, v_lim, integrate_resol), but then this will not work for a mu-coordinate.

if axe_to_plot < 3:
plot_linspace = xp.linspace(0.0, 1.0, resol)
else:
plot_linspace = xp.linspace(0.0, v_lim, resol)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here, use negative velocities?

etas = xp.meshgrid(*tabs, indexing="ij")
total_density = self(*etas)
if use_mu and axe_to_plot == 4:
B_tab = equil.b_xyz(etas[0], etas[1], etas[2])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is also equil.absB0 for the absolute value as a 0-form (regular function).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The equilibrium here does not always provide a domain, which is mandatory to call equil.absB0 (as it calls internally b_cart).

for i in range(3):
tabs[i][0] = logical_coord[i]
tabs[axe_to_plot] = plot_linspace
etas = xp.meshgrid(*tabs, indexing="ij")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe there should be an upper bound on integrate_resol, otherwise the memory could blow up with meshgrid.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove the output from all cells!

@spossann
Copy link
Copy Markdown
Member

spossann commented May 5, 2026

And: don't forget git merge devel to be up-to-date.

Copy link
Copy Markdown
Member

@spossann spossann left a comment

Choose a reason for hiding this comment

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

Bug in test?

# Testing with GyroMaxwellian2D:
equil = equils.HomogenSlab(B0x=0.0, B0y=0.0, B0z=1.0)
background = maxwellians.GyroMaxwellian2D(n=(n_init, None), vth_para=(vth, None), vth_perp=(vth, None), equil=equil)
background.plot_density_profile("e1")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here I would expect to see the cosine from n_init, but I don't. Maybe sg went wrong with the np.max operation?

emilegrivet and others added 3 commits May 7, 2026 11:41
Co-authored-by: Stefan Possanner <stefan.possanner@ipp.mpg.de>
Co-authored-by: Stefan Possanner <stefan.possanner@ipp.mpg.de>
Co-authored-by: Stefan Possanner <stefan.possanner@ipp.mpg.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants