Skip to content

Commit 894e7f2

Browse files
authored
Merge pull request #151 from boutproject/cvode-precon-input
solver:use_precon replacement input
2 parents a4b4299 + 011e75c commit 894e7f2

2 files changed

Lines changed: 30 additions & 39 deletions

File tree

src/boutdata/gridue_to_bout_converter/gridue_to_bout.py

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _importBody(gridue_settings, f):
4646
if line == "\n":
4747
try:
4848
Key = next(k)
49-
except:
49+
except StopIteration:
5050
continue
5151
else:
5252
Str[Key].append(line)
@@ -67,7 +67,7 @@ def _importBody(gridue_settings, f):
6767

6868
try:
6969
vv = next(_l)
70-
except:
70+
except StopIteration:
7171
continue
7272
gridue_settings[k] = data_
7373
return gridue_settings
@@ -114,7 +114,7 @@ def _importDN(values, f):
114114
values = [int(x) for x in next(f).split()]
115115
if len(values) != len(row):
116116
raise ValueError(
117-
"Expected row with {} integers, found {}".format(len(row), len(values))
117+
f"Expected row with {len(row)} integers, found {len(values)}"
118118
)
119119
gridue_settings.update(zip(row, values))
120120

@@ -137,7 +137,7 @@ def importGridue(fname: str = "gridue") -> dict:
137137
A dict containing header and body information from the gridue file.
138138
139139
"""
140-
f = open(fname, mode="r")
140+
f = open(fname)
141141
values = [int(x) for x in next(f).split()]
142142

143143
if len(values) == 5:
@@ -168,7 +168,7 @@ def plot(GridueParams: dict, edgecolor="black", ax: object = None, show=True):
168168
z = GridueParams["zm"]
169169
Nx = len(r)
170170
Ny = len(r[0])
171-
patches = []
171+
172172
plt.figure(figsize=(6, 10))
173173
if ax is None:
174174
ax = plt.gca()
@@ -222,7 +222,6 @@ def calcGridAngle(g: dict):
222222
Bzxy = g["bz"][:, :, 0].T
223223
Bpxy = g["bpol"][:, :, 0].T
224224

225-
psi = g["psi"]
226225
rm = g["rm"]
227226
zm = g["zm"]
228227

@@ -307,7 +306,6 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False):
307306
"""
308307

309308
Rxy = grd["Rxy"]
310-
Zxy = grd["Zxy"]
311309
Brxy = grd["Brxy"]
312310
Bzxy = grd["Bzxy"]
313311
Btxy = grd["Btxy"]
@@ -325,35 +323,34 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False):
325323
(cosBeta, "cos(beta)"),
326324
(tanBeta, "tan(beta)"),
327325
]:
328-
print(
329-
"{} min {}, mean {}, max {}".format(
330-
name, np.amin(var), np.mean(var), np.amax(var)
331-
)
332-
)
326+
print(f"{name} min {np.amin(var)}, mean {np.mean(var)}, max {np.amax(var)}")
333327

334328
dphidy = hy * Btxy / (Bpxy * Rxy)
335329

336-
I = np.zeros(Rxy.shape)
330+
sinty = np.zeros(Rxy.shape)
337331

338332
g11 = (Rxy * Bpxy) ** 2
339333
g22 = 1.0 / (hy * cosBeta) ** 2
340334
g33 = (
341335
1.0 / Rxy**2
342-
+ (Rxy * Bpxy * I) ** 2
336+
+ (Rxy * Bpxy * sinty) ** 2
343337
+ (dphidy / (hy * cosBeta)) ** 2
344-
+ 2.0 * Rxy * Bpxy * I * dphidy * tanBeta / hy
338+
+ 2.0 * Rxy * Bpxy * sinty * dphidy * tanBeta / hy
345339
)
346340
g12 = Rxy * np.abs(Bpxy) * tanBeta / hy
347-
g13 = -Rxy * Bpxy * dphidy * tanBeta / hy - I * (Rxy * Bpxy) ** 2
348-
g23 = -bpsign * dphidy / (hy * cosBeta) ** 2 - Rxy * np.abs(Bpxy) * I * tanBeta / hy
341+
g13 = -Rxy * Bpxy * dphidy * tanBeta / hy - sinty * (Rxy * Bpxy) ** 2
342+
g23 = (
343+
-bpsign * dphidy / (hy * cosBeta) ** 2
344+
- Rxy * np.abs(Bpxy) * sinty * tanBeta / hy
345+
)
349346

350347
J = hy / Bpxy
351348

352-
g_11 = 1.0 / (Rxy * Bpxy * cosBeta) ** 2 + (I * Rxy) ** 2
349+
g_11 = 1.0 / (Rxy * Bpxy * cosBeta) ** 2 + (sinty * Rxy) ** 2
353350
g_22 = hy**2 + (dphidy * Rxy) ** 2
354351
g_33 = Rxy**2
355-
g_12 = bpsign * I * dphidy * Rxy**2 - hy * tanBeta / (Rxy * np.abs(Bpxy))
356-
g_13 = I * Rxy**2
352+
g_12 = bpsign * sinty * dphidy * Rxy**2 - hy * tanBeta / (Rxy * np.abs(Bpxy))
353+
g_13 = sinty * Rxy**2
357354
g_23 = bpsign * dphidy * Rxy**2
358355

359356
Jcheck = (
@@ -378,11 +375,7 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False):
378375
(J - Jcheck, "J - Jcheck"),
379376
(rel_error, "(J - Jcheck)/J"),
380377
]:
381-
print(
382-
"{} min {}, mean {}, max {}".format(
383-
name, np.amin(var), np.mean(var), np.amax(var)
384-
)
385-
)
378+
print(f"{name} min {np.amin(var)}, mean {np.mean(var)}, max {np.amax(var)}")
386379

387380
if np.max(np.abs(rel_error)) > 1e-6:
388381
if ignore_checks:
@@ -422,7 +415,7 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False):
422415
curl_bOverB_z = (
423416
curl_bOverB_zetahat / Rxy
424417
- Btxy * hy / (Bpxy * Rxy) * curl_bOverB_y
425-
- I * curl_bOverB_x
418+
- sinty * curl_bOverB_x
426419
)
427420

428421
bxcvx = Bxy / 2.0 * curl_bOverB_x
@@ -435,11 +428,7 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False):
435428
(bxcvy, "bxcvy"),
436429
(bxcvz, "bxcvz"),
437430
]:
438-
print(
439-
"{} min {}, mean {}, max {}".format(
440-
name, np.amin(var), np.mean(var), np.amax(var)
441-
)
442-
)
431+
print(f"{name} min {np.amin(var)}, mean {np.mean(var)}, max {np.amax(var)}")
443432

444433
return {
445434
"dphidy": dphidy,
@@ -460,7 +449,7 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False):
460449
# Jacobian
461450
"J": J,
462451
# Integrated shear
463-
"sinty": I,
452+
"sinty": sinty,
464453
# Curvature
465454
"curl_bOverB_x": curl_bOverB_x,
466455
"curl_bOverB_y": curl_bOverB_y,
@@ -485,8 +474,8 @@ def calcRZCurvature(g: dict):
485474
Z = g["zm"]
486475

487476
dBzetadR, dBzetadZ = calcRZderivs(R, Z, Bzeta)
488-
dBRdR, dBRdZ = calcRZderivs(R, Z, BR)
489-
dBZdR, dBZdZ = calcRZderivs(R, Z, BZ)
477+
_, dBRdZ = calcRZderivs(R, Z, BR)
478+
dBZdR, _ = calcRZderivs(R, Z, BZ)
490479
dB2dR, dB2dZ = calcRZderivs(R, Z, B2)
491480

492481
# Select point at centre of cell
@@ -869,11 +858,7 @@ def Convert_grids(
869858

870859
if verbose:
871860
print(
872-
"Safety factor: min {}, mean {}, max {}".format(
873-
np.amin(ShiftAngle[:ixseps1]) / (2 * np.pi),
874-
np.mean(ShiftAngle[:ixseps1]) / (2 * np.pi),
875-
np.amax(ShiftAngle[:ixseps1]) / (2 * np.pi),
876-
)
861+
f"Safety factor: min {np.amin(ShiftAngle[:ixseps1]) / (2 * np.pi)}, mean {np.mean(ShiftAngle[:ixseps1]) / (2 * np.pi)}, max {np.amax(ShiftAngle[:ixseps1]) / (2 * np.pi)}"
877862
)
878863

879864
if plotting:

src/boutupgrader/bout_v6_input_file_upgrader.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
{"old": "timestep", "new": "solver:output_step"},
1010
{"old": "nout", "new": "solver:nout"},
1111
{"old": "grid", "new": "mesh:file"},
12+
{
13+
"old": "solver:use_precon",
14+
"new": "solver:cvode_precon_method",
15+
"old_type": bool,
16+
"new_values": {False: "none", True: "user"},
17+
},
1218
]
1319

1420
DELETED = []

0 commit comments

Comments
 (0)