-
Notifications
You must be signed in to change notification settings - Fork 22
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
Generalize toroidal angle beyond phi cylindrical #465
Comments
including code here for generating new basis vector compute funs. From mathematica>
from mathematica >
In python for parsing and code generation: import re
f = open("../derivatives.txt")
lines = f.readlines()
f = open("../derivatives_labels.txt")
labels = f.readlines()
assert len(lines) == len(labels)
def txt_to_desc(s):
X, d = s.split("^")
X = X.replace("(", "").replace(")", "")
d = d.replace("(", "").replace(")", "").replace(",", "")
s = X + "_" + "r"*int(d[0]) + "t"*int(d[1]) +"z"*int(d[2])
out = """data["{}"]""".format(s)
return out
slines = []
pattern = "\([A-Z]\^\([0-9]\,[0-9]\,[0-9]\)\)"
for line in lines:
s = line.replace("}", "").replace("{", "").replace("[\\[Rho],\\[Theta],\\[Zeta]]", "").replace(" ", "*").replace("\n", "")
matches = re.findall(pattern, s)
for m in matches:
s = s.replace(m, txt_to_desc(m))
s = s.replace("R*", """data["R"]*""")
s = "jnp.array([" + s + "]).T"
s = s.replace("^", "**")
s = s.replace("W", "omega")
slines += [s]
lab = ["rho", "theta", "zeta"]
tex = [""] + ["""{\\\\""" + foo + "}" for foo in lab]
cha = ["", "r", "t", "z"]
des = ["", "radial", "poloidal", "toroidal"]
Des = ["", "Radial", "Poloidal", "Toroidal"]
cnt = 0
for k, line in enumerate(labels):
l = int(line[0])
i = int(line[2])
j = int(line[4])
name = f"e_{lab[l]}"
if i>0:
name += f"_{cha[i]}{cha[j]}"
# elif i>0 and j==0:
# name += f"_{cha[i-1]}"
label = r"\\mathbf{e}_" + f"{tex[l+1]}"
if i>0:
label = f"\\\partial_{tex[i]}{tex[j]} " + label
description = f"Covariant {Des[l+1]} basis vector"
if i>0 and j>0:
description += f", second derivative wrt {des[i]} and {des[j]} coordinates"
elif i>0 and j==0:
description += f", derivative wrt {des[i]} coordinate"
s = (
f"""
@register_compute_fun(
name="{name}",
label="{label}",
units="m",
units_long="meters",
description="{description}",
dim=3,
params=[],
transforms={{}},
profiles=[],
coordinates="rtz",
"""
)
src=(
f"""
def _e_sub_{lab[l]}_{cha[i]}{cha[j]}(params, transforms, profiles, data, **kwargs):
data["{name}"] = {slines[k]}
return data
"""
)
pattern = r"data\[(.*?)\]"
variables = re.findall(pattern, src)
variables = [s.replace("'", "").replace('"', "") for s in variables]
variables = sorted(list(set(variables[1:])))
s += f"data={variables}\n)"
print(s+src)
cnt += 1 |
unalmis
added a commit
that referenced
this issue
Aug 11, 2023
Generalize basis vectors for new toroidal angle. See #465
unalmis
added a commit
that referenced
this issue
Aug 23, 2023
Magnetic axis limits and new variables Also generalizes magnetic field quantities for new toroidal angle with stream function. See #465
Draft
7 tasks
@unalmis check what is done and check boxes |
I marked the two I knew were done and added couple |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has come up several times now, and would be very useful for dealing with strongly shaped axes, racetrack/figure8 type shapes etc.
The main things to do:
Equilibrium.to_sfl
to specify which SFL coordinatesThe text was updated successfully, but these errors were encountered: