From 2e21381529231d7b6cfe5c67c40fb97a42d39c75 Mon Sep 17 00:00:00 2001 From: Ben Dudson Date: Wed, 24 Jun 2026 20:37:04 -0700 Subject: [PATCH 1/4] solver:use_precon replacement input Replaced with solver:precon_method in CVODE solver --- src/boutupgrader/bout_v6_input_file_upgrader.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/boutupgrader/bout_v6_input_file_upgrader.py b/src/boutupgrader/bout_v6_input_file_upgrader.py index 5fb041f8e..dca3dc497 100644 --- a/src/boutupgrader/bout_v6_input_file_upgrader.py +++ b/src/boutupgrader/bout_v6_input_file_upgrader.py @@ -9,6 +9,12 @@ {"old": "timestep", "new": "solver:output_step"}, {"old": "nout", "new": "solver:nout"}, {"old": "grid", "new": "mesh:file"}, + { + "old": "solver:use_precon", + "new": "solver:precon_method", + "old_type": bool, + "new_values": {False: "none", True: "user"}, + }, ] DELETED = [] From 83bc3dba00491c463e8e144a7f5901d39405257c Mon Sep 17 00:00:00 2001 From: Ben Dudson Date: Wed, 24 Jun 2026 21:13:46 -0700 Subject: [PATCH 2/4] Should be cvode_precon_method --- src/boutupgrader/bout_v6_input_file_upgrader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boutupgrader/bout_v6_input_file_upgrader.py b/src/boutupgrader/bout_v6_input_file_upgrader.py index dca3dc497..79dd88c15 100644 --- a/src/boutupgrader/bout_v6_input_file_upgrader.py +++ b/src/boutupgrader/bout_v6_input_file_upgrader.py @@ -11,7 +11,7 @@ {"old": "grid", "new": "mesh:file"}, { "old": "solver:use_precon", - "new": "solver:precon_method", + "new": "solver:cvode_precon_method", "old_type": bool, "new_values": {False: "none", True: "user"}, }, From 69a6be4566a8028da35f85d1e2542e9fc2fa1a02 Mon Sep 17 00:00:00 2001 From: Ben Dudson Date: Wed, 24 Jun 2026 21:23:21 -0700 Subject: [PATCH 3/4] Fix Ruff check --- .../gridue_to_bout.py | 54 ++++++++----------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/src/boutdata/gridue_to_bout_converter/gridue_to_bout.py b/src/boutdata/gridue_to_bout_converter/gridue_to_bout.py index 737e9ad1c..5018239ad 100644 --- a/src/boutdata/gridue_to_bout_converter/gridue_to_bout.py +++ b/src/boutdata/gridue_to_bout_converter/gridue_to_bout.py @@ -46,7 +46,7 @@ def _importBody(gridue_settings, f): if line == "\n": try: Key = next(k) - except: + except StopIteration: continue else: Str[Key].append(line) @@ -67,7 +67,7 @@ def _importBody(gridue_settings, f): try: vv = next(_l) - except: + except StopIteration: continue gridue_settings[k] = data_ return gridue_settings @@ -114,7 +114,7 @@ def _importDN(values, f): values = [int(x) for x in next(f).split()] if len(values) != len(row): raise ValueError( - "Expected row with {} integers, found {}".format(len(row), len(values)) + f"Expected row with {len(row)} integers, found {len(values)}" ) gridue_settings.update(zip(row, values)) @@ -137,7 +137,7 @@ def importGridue(fname: str = "gridue") -> dict: A dict containing header and body information from the gridue file. """ - f = open(fname, mode="r") + f = open(fname) values = [int(x) for x in next(f).split()] if len(values) == 5: @@ -168,7 +168,7 @@ def plot(GridueParams: dict, edgecolor="black", ax: object = None, show=True): z = GridueParams["zm"] Nx = len(r) Ny = len(r[0]) - patches = [] + plt.figure(figsize=(6, 10)) if ax is None: ax = plt.gca() @@ -222,7 +222,6 @@ def calcGridAngle(g: dict): Bzxy = g["bz"][:, :, 0].T Bpxy = g["bpol"][:, :, 0].T - psi = g["psi"] rm = g["rm"] zm = g["zm"] @@ -307,7 +306,6 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False): """ Rxy = grd["Rxy"] - Zxy = grd["Zxy"] Brxy = grd["Brxy"] Bzxy = grd["Bzxy"] Btxy = grd["Btxy"] @@ -326,34 +324,32 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False): (tanBeta, "tan(beta)"), ]: print( - "{} min {}, mean {}, max {}".format( - name, np.amin(var), np.mean(var), np.amax(var) - ) + f"{name} min {np.amin(var)}, mean {np.mean(var)}, max {np.amax(var)}" ) dphidy = hy * Btxy / (Bpxy * Rxy) - I = np.zeros(Rxy.shape) + sinty = np.zeros(Rxy.shape) g11 = (Rxy * Bpxy) ** 2 g22 = 1.0 / (hy * cosBeta) ** 2 g33 = ( 1.0 / Rxy**2 - + (Rxy * Bpxy * I) ** 2 + + (Rxy * Bpxy * sinty) ** 2 + (dphidy / (hy * cosBeta)) ** 2 - + 2.0 * Rxy * Bpxy * I * dphidy * tanBeta / hy + + 2.0 * Rxy * Bpxy * sinty * dphidy * tanBeta / hy ) g12 = Rxy * np.abs(Bpxy) * tanBeta / hy - g13 = -Rxy * Bpxy * dphidy * tanBeta / hy - I * (Rxy * Bpxy) ** 2 - g23 = -bpsign * dphidy / (hy * cosBeta) ** 2 - Rxy * np.abs(Bpxy) * I * tanBeta / hy + g13 = -Rxy * Bpxy * dphidy * tanBeta / hy - sinty * (Rxy * Bpxy) ** 2 + g23 = -bpsign * dphidy / (hy * cosBeta) ** 2 - Rxy * np.abs(Bpxy) * sinty * tanBeta / hy J = hy / Bpxy - g_11 = 1.0 / (Rxy * Bpxy * cosBeta) ** 2 + (I * Rxy) ** 2 + g_11 = 1.0 / (Rxy * Bpxy * cosBeta) ** 2 + (sinty * Rxy) ** 2 g_22 = hy**2 + (dphidy * Rxy) ** 2 g_33 = Rxy**2 - g_12 = bpsign * I * dphidy * Rxy**2 - hy * tanBeta / (Rxy * np.abs(Bpxy)) - g_13 = I * Rxy**2 + g_12 = bpsign * sinty * dphidy * Rxy**2 - hy * tanBeta / (Rxy * np.abs(Bpxy)) + g_13 = sinty * Rxy**2 g_23 = bpsign * dphidy * Rxy**2 Jcheck = ( @@ -379,9 +375,7 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False): (rel_error, "(J - Jcheck)/J"), ]: print( - "{} min {}, mean {}, max {}".format( - name, np.amin(var), np.mean(var), np.amax(var) - ) + f"{name} min {np.amin(var)}, mean {np.mean(var)}, max {np.amax(var)}" ) if np.max(np.abs(rel_error)) > 1e-6: @@ -422,7 +416,7 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False): curl_bOverB_z = ( curl_bOverB_zetahat / Rxy - Btxy * hy / (Bpxy * Rxy) * curl_bOverB_y - - I * curl_bOverB_x + - sinty * curl_bOverB_x ) bxcvx = Bxy / 2.0 * curl_bOverB_x @@ -436,9 +430,7 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False): (bxcvz, "bxcvz"), ]: print( - "{} min {}, mean {}, max {}".format( - name, np.amin(var), np.mean(var), np.amax(var) - ) + f"{name} min {np.amin(var)}, mean {np.mean(var)}, max {np.amax(var)}" ) return { @@ -460,7 +452,7 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False): # Jacobian "J": J, # Integrated shear - "sinty": I, + "sinty": sinty, # Curvature "curl_bOverB_x": curl_bOverB_x, "curl_bOverB_y": curl_bOverB_y, @@ -485,8 +477,8 @@ def calcRZCurvature(g: dict): Z = g["zm"] dBzetadR, dBzetadZ = calcRZderivs(R, Z, Bzeta) - dBRdR, dBRdZ = calcRZderivs(R, Z, BR) - dBZdR, dBZdZ = calcRZderivs(R, Z, BZ) + _, dBRdZ = calcRZderivs(R, Z, BR) + dBZdR, _ = calcRZderivs(R, Z, BZ) dB2dR, dB2dZ = calcRZderivs(R, Z, B2) # Select point at centre of cell @@ -869,11 +861,7 @@ def Convert_grids( if verbose: print( - "Safety factor: min {}, mean {}, max {}".format( - np.amin(ShiftAngle[:ixseps1]) / (2 * np.pi), - np.mean(ShiftAngle[:ixseps1]) / (2 * np.pi), - np.amax(ShiftAngle[:ixseps1]) / (2 * np.pi), - ) + 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)}" ) if plotting: From 011e75cdf05ccf045aca70dd1a1ca51d590ca247 Mon Sep 17 00:00:00 2001 From: bendudson Date: Thu, 25 Jun 2026 04:23:47 +0000 Subject: [PATCH 4/4] Apply ruff changes --- .../gridue_to_bout_converter/gridue_to_bout.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/boutdata/gridue_to_bout_converter/gridue_to_bout.py b/src/boutdata/gridue_to_bout_converter/gridue_to_bout.py index 5018239ad..139812fcc 100644 --- a/src/boutdata/gridue_to_bout_converter/gridue_to_bout.py +++ b/src/boutdata/gridue_to_bout_converter/gridue_to_bout.py @@ -323,9 +323,7 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False): (cosBeta, "cos(beta)"), (tanBeta, "tan(beta)"), ]: - print( - f"{name} min {np.amin(var)}, mean {np.mean(var)}, max {np.amax(var)}" - ) + print(f"{name} min {np.amin(var)}, mean {np.mean(var)}, max {np.amax(var)}") dphidy = hy * Btxy / (Bpxy * Rxy) @@ -341,7 +339,10 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False): ) g12 = Rxy * np.abs(Bpxy) * tanBeta / hy g13 = -Rxy * Bpxy * dphidy * tanBeta / hy - sinty * (Rxy * Bpxy) ** 2 - g23 = -bpsign * dphidy / (hy * cosBeta) ** 2 - Rxy * np.abs(Bpxy) * sinty * tanBeta / hy + g23 = ( + -bpsign * dphidy / (hy * cosBeta) ** 2 + - Rxy * np.abs(Bpxy) * sinty * tanBeta / hy + ) J = hy / Bpxy @@ -374,9 +375,7 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False): (J - Jcheck, "J - Jcheck"), (rel_error, "(J - Jcheck)/J"), ]: - print( - f"{name} min {np.amin(var)}, mean {np.mean(var)}, max {np.amax(var)}" - ) + print(f"{name} min {np.amin(var)}, mean {np.mean(var)}, max {np.amax(var)}") if np.max(np.abs(rel_error)) > 1e-6: if ignore_checks: @@ -429,9 +428,7 @@ def calcMetric(grd: dict, bpsign, verbose=False, ignore_checks=False): (bxcvy, "bxcvy"), (bxcvz, "bxcvz"), ]: - print( - f"{name} min {np.amin(var)}, mean {np.mean(var)}, max {np.amax(var)}" - ) + print(f"{name} min {np.amin(var)}, mean {np.mean(var)}, max {np.amax(var)}") return { "dphidy": dphidy,