From 95d398d503f4f974a83e51b46354503b0cbbb7c3 Mon Sep 17 00:00:00 2001 From: Michele Guerini Rocco Date: Tue, 12 Dec 2023 18:25:24 +0100 Subject: [PATCH] src/equilibrium.f90: use the exact toroidal flux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To improve the analytical model correctness this changes the formula of the toroidal flux to lift the large aspect ratio approximation (a << R₀). In fact, Φ(r) = B₀πr² is technically inconsistent with the field varying as B₀R₀/R. The exact expression is: Φ(r) = B₀πr² 2/[1 + √(1 - r²/R₀²)], which is approximately equal to the former for r << R₀. Note that this change introduces a divergence in the poloidal field at r=R₀ (since ∂Φ/∂r → +∞), so the domain of the equilibrium has been restricted to r model%R0) then + if (present(psi_n)) psi_n = -1 + if (present(dpsidr)) dpsidr = 0 + if (present(dpsidz)) dpsidz = 0 + if (present(ddpsidrr)) ddpsidrr = 0 + if (present(ddpsidzz)) ddpsidzz = 0 + if (present(ddpsidrz)) ddpsidrz = 0 + return + end if + + gamma = 1 / sqrt(1 - (r_g/model%R0)**2) + phi_n = model%B0 * pi*r_g**2 * 2*gamma/(gamma + 1) / phitedge + rho_t = sqrt(phi_n) rho_p = frhopol(rho_t) + ! For ∇Φ_n and ∇∇Φ_n we also need: + ! + ! ∂Φ∂(r²) = B₀π γ(r) + ! ∂²Φ∂(r²)² = B₀π γ³(r) / (2 R₀²) + ! + dphidr2 = model%B0 * pi * gamma / phitedge + ddphidr2dr2 = model%B0 * pi * gamma**3/(2 * model%R0**2) / phitedge + + ! ∇Φ_n = ∂Φ_n/∂(r²) ∇(r²) + ! where ∇(r²) = 2[(R-R₀), (z-z₀)] + dphidr = dphidr2 * 2*(R - model%R0) + dphidz = dphidr2 * 2*(z - model%z0) + + ! ∇∇Φ_n = ∇[∂Φ_n/∂(r²)] ∇(r²) + ∂Φ_n/∂(r²) ∇∇(r²) + ! = ∂²Φ_n/∂(r²)² ∇(r²)∇(r²) + ∂Φ_n/∂(r²) ∇∇(r²) + ! where ∇∇(r²) = 2I + ddphidrdr = ddphidr2dr2 * 4*(R - model%R0)*(R - model%R0) + dphidr2*2 + ddphidzdz = ddphidr2dr2 * 4*(z - model%z0)*(z - model%z0) + dphidr2*2 + ddphidrdz = ddphidr2dr2 * 4*(R - model%R0)*(z - model%z0) + ! ψ_n = ρ_p(ρ_t)² if (present(psi_n)) psi_n = rho_p**2 @@ -871,10 +931,6 @@ contains dq = (model%q1 - model%q0) / (model%alpha/2 + 1) dpsidphi = (model%q0 + dq) / q - ! Since Φ_n = ρ_t²(R,z): ∇Φ_n = 2/a² [R-R₀, z-z₀] - dphidr = 2*(R - model%R0)/model%a**2 - dphidz = 2*(z - model%z0)/model%a**2 - ! Using the above, ∇ψ_n = ∂ψ_n/∂Φ_n ∇Φ_n if (present(dpsidr)) dpsidr = dpsidphi * dphidr if (present(dpsidz)) dpsidz = dpsidphi * dphidz @@ -890,18 +946,18 @@ contains ! ∇q = α/2 (q-q₀) ∇ψ_n/ψ_n ! = α/2 (q-q₀)/ψ_n (∂ψ_n/∂Φ_n) ∇Φ_n. ! - dqdr = model%alpha/2 * (q - model%q0)/rho_p**2 * dpsidphi * dphidr - dqdz = model%alpha/2 * (q - model%q0)/rho_p**2 * dpsidphi * dphidz + dqdr = model%alpha/2 * (model%q1 - model%q0)*rho_p**(model%alpha-2) * dpsidphi * dphidr + dqdz = model%alpha/2 * (model%q1 - model%q0)*rho_p**(model%alpha-2) * dpsidphi * dphidz ddpsidphidr = - dpsidphi * dqdr/q ddpsidphidz = - dpsidphi * dqdz/q - ! Finally, ∇∇Φ_n = ∇∇ ρ_t²(R,z) = 2/a² I, so: + ! Combining all of the above: ! - ! ∇∇ψ_n = ∇(∂ψ_n/∂Φ_n) ∇Φ_n + (∂ψ_n/∂Φ_n) 2/a² I + ! ∇∇ψ_n = ∇(∂ψ_n/∂Φ_n) ∇Φ_n + (∂ψ_n/∂Φ_n) ∇∇Φ_n ! - if (present(ddpsidrr)) ddpsidrr = ddpsidphidr * dphidr + dpsidphi * 2/model%a**2 - if (present(ddpsidzz)) ddpsidzz = ddpsidphidz * dphidz + dpsidphi * 2/model%a**2 - if (present(ddpsidrz)) ddpsidrz = ddpsidphidr * dphidz + if (present(ddpsidrr)) ddpsidrr = ddpsidphidr * dphidr + dpsidphi * ddphidrdr + if (present(ddpsidzz)) ddpsidzz = ddpsidphidz * dphidz + dpsidphi * ddphidzdz + if (present(ddpsidrz)) ddpsidrz = ddpsidphidr * dphidz + dpsidphi * ddphidrdz else ! Numerical data if (R <= rmxm .and. R >= rmnm .and. &