Guest User

script_mol

a guest
Nov 6th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 1.12 KB | None | 0 0
  1. using DifferentialEquations, ModelingToolkit, MethodOfLines, DomainSets
  2. using Symbolics: @register_symbolic
  3.  
  4. @parameters x t
  5. @variables ρ(..) v(..)
  6. Dt = Differential(t)
  7. Dx = Differential(x)
  8.  
  9. GM = 4e20
  10. cs = 2.87e5
  11. cs2 = 8.24e10
  12.  
  13. eq = [
  14.         Dt(ρ(x,t)) ~ -exp(-x) * (2*ρ(x,t)*v(x,t) + v(x,t)*Dx(ρ(x,t)) + ρ(x,t)*Dx(v(x,t))),
  15.         Dt(v(x,t)) ~ -v(x,t)*exp(-x) * Dx(v(x,t)) - cs2/(ρ(x,t)) * exp(-x) * Dx(ρ(x,t)) - GM*exp(-2*x)
  16.     ]
  17.  
  18. x_min, x_max = 20.2, 21.8
  19. t_min, t_max = 0.0, 30_000.0
  20.  
  21. domains = [x ∈ Interval(x_min, x_max), t ∈ Interval(t_min, t_max)]
  22.  
  23. ρ_init(x) = 1e-11 * exp(4.84e9 * exp(-x) - 7.6)
  24. function v_init(x)
  25.     if (x > 21.6)
  26.         return 2 * cs
  27.     else
  28.         return 0.0
  29.     end
  30. end
  31.  
  32. @register_symbolic v_init(x)
  33.  
  34. bcs = [
  35.     ρ(x,t_min) ~ ρ_init(x),
  36.     ρ(x_min,t) ~ ρ_init(x_min),
  37.     v(x,t_min) ~ v_init(x),
  38.     v(x_min,t) ~ v_init(x_min)
  39. ]
  40.  
  41. @named pdesys = PDESystem(eq, bcs, domains, [x,t], [ρ(x,t),v(x,t)])
  42.  
  43. N = 5
  44. dx = (x_max-x_min)/N
  45. order = 2
  46. discretization = MOLFiniteDifference([x=>dx], t)
  47.  
  48. prob = discretize(pdesys, discretization)
  49. sol = solve(prob, Tsit5(), saveat=100)
Advertisement
Add Comment
Please, Sign In to add comment