{"id":25004996,"url":"https://github.com/projecttorreypines/mxhequilibrium.jl","last_synced_at":"2026-03-02T08:01:55.900Z","repository":{"id":254167560,"uuid":"569096789","full_name":"ProjectTorreyPines/MXHEquilibrium.jl","owner":"ProjectTorreyPines","description":"Equilibrium.jl with MXH (Miller Extended Harmonics) support","archived":false,"fork":false,"pushed_at":"2025-09-18T20:41:10.000Z","size":892,"stargazers_count":0,"open_issues_count":8,"forks_count":1,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-09-18T22:56:49.017Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://projecttorreypines.github.io/MXHEquilibrium.jl/dev","language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ProjectTorreyPines.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":"NOTICE.md","maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-11-22T04:18:48.000Z","updated_at":"2025-09-18T20:35:52.000Z","dependencies_parsed_at":"2025-09-18T22:20:17.520Z","dependency_job_id":"7c5cf800-1610-4b18-abd2-4e1d1922ba69","html_url":"https://github.com/ProjectTorreyPines/MXHEquilibrium.jl","commit_stats":null,"previous_names":["projecttorreypines/mxhequilibrium.jl"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/ProjectTorreyPines/MXHEquilibrium.jl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProjectTorreyPines%2FMXHEquilibrium.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProjectTorreyPines%2FMXHEquilibrium.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProjectTorreyPines%2FMXHEquilibrium.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProjectTorreyPines%2FMXHEquilibrium.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ProjectTorreyPines","download_url":"https://codeload.github.com/ProjectTorreyPines/MXHEquilibrium.jl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProjectTorreyPines%2FMXHEquilibrium.jl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29995910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-02T01:47:34.672Z","status":"online","status_checked_at":"2026-03-02T02:00:07.342Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-05T00:09:43.474Z","updated_at":"2026-03-02T08:01:55.882Z","avatar_url":"https://github.com/ProjectTorreyPines.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MXHEquilibrium.jl\n\nMXHEquilibrium.jl is a fork of Equilibrium.jl and provides functionality for Miller Extended Harmonic fitting.\n\n## AbstractEquilibrium API\n\n```julia\nusing MXHEquilibrium\ntypeof(S) \u003c: AbstractEquilibrium\n\npsi = S(r, z) # Poloidal flux at r,z\ngradpsi = psi_gradient(S, r, z)\n\nB = Bfield(S, r, z)\nBp = poloidal_Bfield(S, r, z)\n\nJ = Jfield(S, r, z)\nJp = poloidal_Jfield(S, r, z)\n\nF = poloidal_current(S, psi)\nFprime = poloidal_current_gradient(S, psi)\n\np = pressure(S, psi)\npprime = pressure_gradient(S, psi)\n\nV = electric_potential(S, psi)\ngradV = electric_potential_gradient(S, psi)\n\nq = safety_factor(S, psi)\n\nmaxis = magnetic_axis(S)\n\nbtip = B0Ip_sign(S)\n\nrlims, zlims = limits(S)\n\npsi_lims = psi_limits(S)\n\ncc = cocos(S) # Return COCOS structure\n\nfs = flux_surface(S, psi) # returns a boundary object\n\n```\n\n## Solov'ev Equilibrium\nSolov'ev Equilibrium are analytic solutions to the Grad-Shafranov equation where the p' and FF' are constant.\nThe resulting Grad-Shafranov equation takes the form `Δ⋆ψ = α + (1-α)x²` where `α` is some constant.\nThe boundary conditions are found using a plasma shape parameterization.\n\n```julia\n\n# ITER parameters\nδ = 0.33        # Triangularity\nϵ = 0.32        # Inverse aspect ratio a/R0\nκ = 1.7         # Elongation\nB0 = 5.3        # Magnitude of Toroidal field at R0 [T]\nR0 = 6.2        # Major Radius [m]\nZ0 = 0.0        # Elevation\nqstar = 1.57    # Kink safety factor\nalpha = -0.155  # constant\n\nS = solovev(B0, MillerShape(R0, Z0, ϵ, κ, δ), alpha, qstar, B0_dir=1, Ip_dir=1)\n\n\nSolovevEquilibrium\n  B0 = 2.0 [T]\n  S  = MillerShape{Float64}(6.2, 0.0, 0.32, 1.7, 0.33)\n  α  = -0.155\n  q⋆ = 1.57\n  βp = 1.1837605469381924\n  βt = 0.049177281028224634\n  σ  = 1\n  diverted  = false\n  symmetric = true\n```\n\n## EFIT Equilibrium\nEFIT geqdsk files are a commonly used file format.\nHere we provide routines for converting the GEQDSK files into an Equilibrium object.\n\n```julia\nusing EFIT\n\ng = readg(\"g000001.01000\")\nM = efit(g, clockwise_phi=false) # direction of phi needed to determine COCOS ID\nwall = Wall(g)\n\nin_vessel(wall, r, z)\n\n# or\n# M, wall = read_geqdsk(\"g000001.01000\",clockwise_phi=false)\n\n```\n\n## COCOS: Tokamak Coordinate Conventions\nWe provide routines for working determining, transforming, and checking COCOS's.\n```julia\njulia\u003e cocos(3)\nCOCOS = 3\n e_Bp  = 0\n σ_Bp  = -1\n σ_RΦZ = (R,Φ,Z): 1\n σ_ρθΦ = (ρ,Φ,θ): -1\n Φ from top: CCW\n θ from front: CCW\n ψ_ref: Decreasing assuming +Ip, +B0\n sign(q) = -1 assuming +Ip, +B0\n sign(p') = 1 assuming +Ip, +B0\n\njulia\u003e transform_cocos(3,1)\nDict{Any, Any} with 14 entries:\n  \"Z\"        =\u003e 1.0\n  \"Q\"        =\u003e -1\n  \"P\"        =\u003e 1.0\n  \"B\"        =\u003e 1.0\n  \"F_FPRIME\" =\u003e -1.0\n  \"ψ\"        =\u003e -1.0\n  \"TOR\"      =\u003e 1.0\n  \"Φ\"        =\u003e 1.0\n  \"PSI\"      =\u003e -1.0\n  \"I\"        =\u003e 1.0\n  \"J\"        =\u003e 1.0\n  \"R\"        =\u003e 1.0\n  \"F\"        =\u003e 1.0\n  \"PPRIME\"   =\u003e -1.0\n```\n\n## Boundaries\nMXHEquilibrium.jl also provides routines for working with boundries such as walls or flux surfaces. Internally boundaries are stored as a list of points forming a polygon.\n\n```julia\n\nfs = flux_surface(S, psi)\n\nin_plasma(fs, r, z) # or in_vessel(fs, r, z), in_boundary(fs, r, z)\n\ncicumference(fs)\n\narea(fs) # Area enclosed by the boundary\n\nvolume(fs) # assuming toroidal symmetry. F can be a vector with the same length as fs or a function of (r,z)\n\naverage(fs, F) # Average F over the boundary\n\narea_average(fs, F) # average F over the area\n\nvolume_average(fs, F) # average F over the volume\n```\n\n## Parameterized Plasma Shapes\nMXHEquilibrium.jl provides the commonly used plasma shape parameterizations.\n\n```julia\nhelp?\u003e MillerShape # alias = MShape\n\n  MillerShape Structure\n\n  Defines the Miller Plasma Shape Parameterization\n\n  Fields:\n  R0 - Major Radius [m]\n  Z0 - Elevation [m]\n  ϵ - Inverse Aspect Ratio a/R0 where a = minor radius\n  κ - Elongation\n  δ - Triangularity\n\nhelp?\u003e TurnbullMillerShape # alias = TMShape\n\n  TurnbullMillerShape Structure\n\n  Defines the Turnbull-Miller Plasma Shape Parameterization\n  \u003e Turnbull, A. D., et al. \"Improved magnetohydrodynamic stability through optimization of higher order moments in cross-section shape of tokamaks.\" Physics of Plasmas 6.4 (1999): 1113-1116.\n \n  Fields:\n  R0 - Major Radius [m]\n  Z0 - Elevation [m]\n  ϵ - Inverse Aspect Ratio a/R0 where a = minor radius\n  κ - Elongation\n  δ - Triangularity\n  ζ - Squareness\n\nhelp?\u003e AsymmetricMillerShape # alias = AMShape\n\n  AsymmetricMillerShape Structure\n\n  Defines the Asymmetric Miller Plasma Shape Parameterization\n \n  Fields:\n  R0 - Major Radius [m]\n  Z0 - Elevation [m]\n  ϵ - Inverse Aspect Ratio a/R0 where a = minor radius\n  κ - Elongation\n  δl - Lower Triangularity\n  δu - Upper Triangularity\n\nhelp?\u003e MillerExtendedHarmonicShape # alias = MXHShape \n\n  MillerExtendedHarmonicShape Structure\n\n  Defines the Miller Extended Harmonic Plasma Shape Parameterization\n  \u003e Arbon, Ryan, Jeff Candy, and Emily A. Belli. \"Rapidly-convergent flux-surface shape parameterization.\" Plasma Physics and Controlled Fusion 63.1 (2020): 012001.\n\n  Fields:\n  R0 - Major Radius [m]\n  Z0 - Elevation [m]\n  ϵ - Inverse Aspect Ratio a/R0 where a = minor radius\n  κ - Elongation\n  c0 - Tilt\n  c - Cosine coefficients i.e. [ovality,...]\n  s - Sine coefficients i.e. [asin(triangularity), squareness,...]\n```\n\n## Flux Surface Fitting\nMXHEquilibrium.jl provides routines for fitting flux surfaces to a PlasmaShape\n\n```julia\njulia\u003e g = readg(@__DIR__*\"/test/g150219.03200\");\n\njulia\u003e M = efit(g,clockwise_phi=false);\n\njulia\u003e bdry = boundary(M);\n\njulia\u003e MXH = fit(bdry,MXHShape(10)) # use 10 fourier components\nMillerExtendedHarmonicShape{10, Float64}\n  R0 = 1.6667475890195798 [m]\n  Z0 = -0.14918543837718545 [m]\n  ϵ  = 0.3278211449811159\n  κ  = 1.8166930389369045\n  δ  = 0.4745349500498265\n  ζ  = 0.0640865222160445\n  ξ  = -0.12517240241115193\n  τ  = -0.0847654065659985\n\njulia\u003e bdry = boundary(MXH; N=100)\n\njulia\u003e fMXH = fit(bdry,MXHShape(10))\nMillerExtendedHarmonicShape{10, Float64}\n  R0 = 1.6667278385191975 [m]\n  Z0 = -0.14918543837718545 [m]\n  ϵ  = 0.3277787473904293\n  κ  = 1.8167208515952422\n  δ  = 0.4745418627448689\n  ζ  = 0.06313553088494958\n  ξ  = -0.11595260388302828\n  τ  = -0.08051086241624195\n```\n\n## Online documentation\nFor more details, see the [online documentation](https://projecttorreypines.github.io/MXHEquilibrium.jl/dev).\n\n![Docs](https://github.com/ProjectTorreyPines/MXHEquilibrium.jl/actions/workflows/make_docs.yml/badge.svg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojecttorreypines%2Fmxhequilibrium.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprojecttorreypines%2Fmxhequilibrium.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojecttorreypines%2Fmxhequilibrium.jl/lists"}