Skip to content

Commit

Permalink
add Jpar0 based on output-jpar0 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
HarukiST committed Sep 20, 2024
1 parent a25caac commit 8453924
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions hypnotoad/core/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,27 @@ def geometry1(self):

self.Bxy = numpy.sqrt(self.Bpxy**2 + self.Btxy**2)

if hasattr(
self.meshParent.equilibrium.regions[self.equilibriumRegion.name], "pprime"
) and hasattr(
self.meshParent.equilibrium.regions[self.equilibriumRegion.name], "fprime"
):
# Calculate parallel current density from p' and f'
# Note: COCOS +1 convention is assumed
# so mu0 * Jpar = -B f' - mu0 p' f / B

pprime = self.meshParent.equilibrium.regions[
self.equilibriumRegion.name
].pprime(self.psixy)
fprime = self.meshParent.equilibrium.regions[
self.equilibriumRegion.name
].fprime(self.psixy)

mu0 = 4e-7 * numpy.pi
self.Jpar0 = -(
self.Bxy * fprime / mu0 + self.Rxy * self.Btxy * pprime / self.Bxy
)

def geometry2(self):
"""
Continuation of geometry1(), but needs neighbours to have calculated Bp so called
Expand Down Expand Up @@ -1338,10 +1359,21 @@ def curl_bOverB_zetahat(R, Z):
self.bxcvy = self.Bxy / 2.0 * self.curl_bOverB_y
self.bxcvz = self.Bxy / 2.0 * self.curl_bOverB_z
elif self.user_options.curvature_type == "bxkappa":
raise ValueError("bxkappa form of curvature not implemented yet")
self.bxcvx = float("nan")
self.bxcvy = float("nan")
self.bxcvz = float("nan")

# bxkappa for cocos1-extension by H. Seto (QST)

bxcvu = -self.Btxy * self.Rxy / (self.J * self.Bxy**2) * self.DDX("#Bxy")
bxcvv = -self.DDX("#Btxy*#Rxy/#Bxy") / self.J
bxcvw = self.DDX(
"#Bxy*#hy/#Bpxy"
) / self.J - self.Btxy * self.Rxy / self.J / self.Bxy * self.DDX(
"#Btxy*#hy/#Bpxy/#Rxy"
)

self.bxcvx = bxcvu
self.bxcvy = bxcvv
self.bxcvz = bxcvw - self.I * bxcvu

else:
raise ValueError(
"Unrecognized option '"
Expand Down Expand Up @@ -3661,6 +3693,9 @@ def addFromRegionsXArray(name):
if hasattr(next(iter(self.equilibrium.regions.values())), "pressure"):
addFromRegions("pressure")

if hasattr(next(iter(self.regions.values())), "Jpar0"):
addFromRegions("Jpar0")

# Penalty mask
self.penalty_mask = BoutArray(
numpy.zeros((self.nx, self.ny)),
Expand Down

0 comments on commit 8453924

Please sign in to comment.