OneSimulation docs Website Free books Plans on Gumroad

Docs › Build a first case in each physics package › Magnetohydrodynamics

5.10 Magnetohydrodynamics

onesim.physics.magnetohydrodynamics

TransverseMHDWaves evolves two velocity and two magnetic perturbations along a background field. Start with periodic endpoints and a single polarization, then add the second. The nominal ideal Alfv\'en speed is \(|B_0|/\sqrt{\rho\mu}\). Compare both propagation direction and component amplitudes. The FD, FV and DG examples in test_transverse_mhd_method_flexibility.py include a rotated line, conservation checks and comparison on the actual carrier. InductionlessMomentum uses a fixed field in the inductionless regime and a dedicated no-slip condition. TwoFluidExchange and RadiationMatterExchange are homogeneous exchange models. Initialize both sides of the exchange and test momentum or energy transfer with externally imposed sources accounted for. The result adapters cover additional provider result families. Their names indicate result types and by themselves give no model construction recipe.

# Use run_periodic_line from this chapter.
from onesim.numerics.fdm import FiniteDifference, PolynomialDifference
from onesim.physics.magnetohydrodynamics import TransverseMHDWaves

line = Line(start=(0, 0, 0), end=(2*np.pi, 0, 0))
wave = TransverseMHDWaves(
    domain=line.line, density=2.0, permeability=0.5, longitudinal_field=1.0,
)
result = run_periodic_line(
    line, wave,
    ((wave.velocity_y, lambda x: 0.1*np.sin(x)), (wave.velocity_z, 0.0),
     (wave.magnetic_y, lambda x: -0.1*np.sin(x)), (wave.magnetic_z, 0.0)),
    Numerics(spatial=FiniteDifference(gradient=PolynomialDifference()),
             time_integrator=ClassicalRungeKutta4()),
    cells=48, end=0.05, dt=0.001,
)
u = result.field(wave.velocity_y)
x = u.space.dof_coordinates[:, 0]
np.testing.assert_allclose(u.values, 0.1*np.sin(x - 0.05), atol=5e-4, rtol=0)

import matplotlib.pyplot as plt
import onesimulation_plot_theme as theme

b = result.field(wave.magnetic_y)
theme.use_theme()
fig,ax=plt.subplots(figsize=(6.8,3.4),layout="constrained")
ax.plot(x,u.values,label="Transverse velocity y")
ax.plot(x,b.values,label="Transverse magnetic field y")
ax.set(xlabel="World x [m]",ylabel="Amplitude in test units")
ax.legend(frameon=False)
plt.show()
Figure computed with OneSimulation: recipe transverse mhdwaves