-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2D incompressible MHD equations #141
Comments
I am currently working on WENO schemes, which are good for discretizing systems such as this one. The upwind scheme (which we currently use) has exhibited instability for similar problems. Soon we should be able to solve your problem more effectively. |
Glad to hear that! However, the comparison script I posted does not use WENO schemes; I believe it is also using the central difference schemes for the 1st and 2nd order derivative terms. So maybe I made some mistakes in expressing the system? That one will also get into numerical issues but at a later time, where some of the variables (i.e. density, pressure) become negative. |
Ah, that is a bug then. May be related to #130, the workaround was to rearrange the form of the coefficients, though I am not sure this is applicable here. Thanks for your excellently written issue, this will be very helpful in debugging. |
Is the problem solved? I haven't tested with the WENO solver. |
Please try this with the WENO scheme @henry2004y. Note that this scheme is sensitive to solver choice, for best results use a strong stability preserving solver like |
Thanks for the reminder. I will try later today. Currently it does not look promising. I've been waiting for around an hour in the discretization step for a grid size of 16*16. Let's see when it will be finished. |
You can also try FBDF() or QBDF, they seem quite good with advective problems |
With discretization = MOLFiniteDifference([x=>dx, z=>dz], t,
advection_scheme=FBDF(),#WENOScheme(),
approx_order=2,
grid_align=center_align) in MethodOfLines v0.7.2, I get Discretization:
ERROR: LoadError: ArgumentError: Only `UpwindScheme()` and `WENOScheme()` are supported advection schemes. Are |
I mean as the solver, not the advection scheme - WENO it must be noted has issues with non periodic bcs, or less than 2 BCs per boundary - so try this too - a neumann0 condition often affects the solution little |
Ah, sorry. Need to refresh my memory a bit 😓 |
Hi,
I want to see if this package can solve a system of 2D compressible ideal magnetohydrodynamic equations in the X-Z plane.
Problem Description
The original equations are
Since$\nabla\cdot\mathbf{B}=0$ , instead of solving the magnetic field directly, we can solve for the magnetic vector potential $\mathbf{A}$ .$$\mathbf{B} = \nabla\times\mathbf{A} = \nabla\times(0, A_y, 0) = (-\frac{\partial A_y}{\partial z}, 0, \frac{\partial A_y}{\partial x})$$ , the last equation above can be simplified to
Let
The normalized 2D equations can be written as
where$\gamma= 5/3$ is the adiabatic index, $\nu_m, \eta_m$ are some normalized constants, and
Solving with MethodOfLines.jl
Based on my understanding of the examples given in the tutorials, in principle we shall be able to solve this. For simplicity, I set$\eta_m = 0$ and $\nu_m = 0$ . Here is my attempt:
Solving with MethodOfLines.jl
```julia # 2D magnetic reconnection for GEM challenge solved using MethodOfLines.jl. # # Initial condition: # Harris sheet equilibrium with perturbation # # Configuration: # z # Lz/2 | conducting, Bz = ∂Bz/∂z = ∂By/∂z = 0 # | # | periodic # -Lx/2 | Lx/2 # --------------------------------------------> x # | # | # | # -Lz/2 | conducting, Bz = ∂Bz/∂z = ∂By/∂z = 0 # # Ref: # [Fu1995], section 7.4 and Appendix 2 # [Birn+2001]( https://doi.org/10.1029/1999JA900449)
using ModelingToolkit, MethodOfLines, OrdinaryDiffEq, DomainSets
const Lx = 25.6
const Lz = 12.8
const nx = 16
const nz = 16
"background field"
const B₀ = 1.0
"mass density"
const ρ₀ = 1.0
"mass density at infinity"
const ρ∞ = 0.2ρ₀
"width of current sheet"
const λ = 0.5
"perturbation amplitude of the magnetic flux"
const ψ₀ = 0.1
"initial plasma β"
const β = 1.0
"Alfven velocity"
#const va = √(B₀^2/ρ₀)
"pressure normalization parameter"
const p₀ = 0.5βB₀^2
"temperature normalization parameter"
#const T₀ = 0.5β*va^2
physical parameters in MHD equations
"adiabatic index"
const γ = 5/3
const η = 0.0 # η/(vaL₀)
const ν = 0.0 # μ/(vaL₀*ρ₀)
@parameters x z t
#@parameters η, ν
@variables ρ(..) p(..) ux(..) uz(..) Ay(..) Bx(..) Bz(..)
Dt = Differential(t)
Dx = Differential(x)
Dz = Differential(z)
Dxx = Differential(x)^2
Dzz = Differential(z)^2
∇²(u) = Dxx(u) + Dzz(u)
x_min = -Lx/2
z_min = -Lz/2
t_min = 0.0
x_max = Lx/2
z_max = Lz/2
t_max = 10.0
dx = Lx /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ay(x,z,t)) - uz(x,z,t)Dz(Ay(x,z,t)) +
η∇²(Ay(x,z,t)),
Bx(x,z,t) ~ -Dz(Ay(x,z,t)),
Bz(x,z,t) ~ Dx(Ay(x,z,t))
]
domains = [x ∈ Interval(x_min, x_max),
z ∈ Interval(z_min, z_max),
t ∈ Interval(t_min, t_max)]
BCs: periodic in x, Neumann in z
ICs: set from functions
bcs = [ρ(x,z,0) ~ ρ0(x,z,0),
ρ(x_min,z,t) ~ ρ(x_max,z,t),
Dz(ρ(x,z_min,t)) ~ 0.0,
Dz(ρ(x,z_max,t)) ~ 0.0,
@nAmed pdesys = PDESystem(eq, bcs, domains,
[x,z,t],
[ρ(x,z,t), p(x,z,t), ux(x,z,t), uz(x,z,t), Ay(x,z,t), Bx(x,z,t), Bz(x,z,t)])
Discretization
order = 2
discretization = MOLFiniteDifference([x=>dx, z=>dz], t, approx_order=order, grid_align=center_align)
Convert the PDE problem into an ODE problem
println("Discretization:")
@time prob = discretize(pdesys, discretization)
println("Solve:")
#@time sol = solve(prob, Tsit5(), saveat=0.1)
@time sol = solve(prob, RK4(), dt=0.05, saveat=0.1)
Extracting results
grid = get_discrete(pdesys, discretization)
discrete_x = grid[x]
discrete_z = grid[z]
discrete_t = sol[t]
@time solBx = map(d -> sol[d][end], grid[Bx(x, z, t)])
solBz = map(d -> sol[d][end], grid[Bz(x, z, t)])
solρ = map(d -> sol[d][end], grid[ρ(x, z, t)])
Testing
I hope I don't make mistakes in expressing the system of PDEs, but the test result is not quite what I expect: it quickly develops some numerical instabilities. As a comparison, here is my hand-written script for solving the PDEs with RK4 in time (fixed timestep) and central differencing in space:
Hand-written finite difference code
With my hand-written script, the initial condition looks like

and the solutions at
t=30
areWith the first script using this package, I get rapidly increasing densities, e.g. at
t=1.8
which is a hint for instabilityTroubleshooting
Currently I am uncertain where the problem is. Could you please take a look and offer me some guidance? Thanks!
The text was updated successfully, but these errors were encountered: