Skip to content

Commit b7f85f6

Browse files
Nush395Torax team
authored andcommitted
Create helper for creating high resolution grid.
This slightly changes the behaviour of the existing hires grid to np.linspace(0,1,n_rho*hires_factor+1) so that inner faces remain aligned. E.g [0, 0.25, 0.5, 0.75, 1.0] x2-> [0, 0.125, 0.25, 0.375, ..., 0.875, 1.0] PiperOrigin-RevId: 859638056
1 parent a99ae25 commit b7f85f6

File tree

55 files changed

+448
-401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+448
-401
lines changed

torax/_src/geometry/circular_geometry.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ def _build_circular_geometry(
186186
# High resolution versions for j (plasma current) and psi (poloidal flux)
187187
# manipulations. Needed if psi is initialized from plasma current, which is
188188
# the only option for ad-hoc circular geometry.
189-
rho_hires_norm = np.linspace(0, 1, n_rho * hires_factor)
189+
rho_hires_norm = geometry.increase_grid_resolution(
190+
rho_face_norm, hires_factor
191+
)
190192
rho_hires = rho_hires_norm * rho_b
191193

192194
R_out = R_major + rho

torax/_src/geometry/geometry.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,15 @@ def update_geometries_with_Phibdot(
457457
geo_t = dataclasses.replace(geo_t, Phi_b_dot=Phibdot)
458458
geo_t_plus_dt = dataclasses.replace(geo_t_plus_dt, Phi_b_dot=Phibdot)
459459
return geo_t, geo_t_plus_dt
460+
461+
462+
def increase_grid_resolution(faces: chex.Array, factor: int) -> chex.Array:
463+
"""Increase the grid resolution by a factor."""
464+
if factor <= 1:
465+
raise ValueError('factor must be >= 1.')
466+
num_faces = len(faces)
467+
num_cells = num_faces - 1
468+
grid_indices = np.arange(len(faces))
469+
new_num_faces = num_cells * factor + 1
470+
new_indices = np.linspace(0, num_cells, new_num_faces)
471+
return np.interp(new_indices, grid_indices, faces)

torax/_src/geometry/standard_geometry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@ def build_standard_geometry(
410410

411411
# High resolution versions for j (plasma current) and psi (poloidal flux)
412412
# manipulations. Needed if psi is initialized from plasma current.
413-
rho_hires_norm = np.linspace(
414-
0, 1, intermediates.n_rho * intermediates.hires_factor
413+
rho_hires_norm = geometry.increase_grid_resolution(
414+
rho_face_norm, intermediates.hires_factor
415415
)
416416
rho_hires = rho_hires_norm * rho_b
417417

torax/_src/geometry/tests/geometry_test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,39 @@ def test_geometry_eq(self):
169169
geo3 = dataclasses.replace(geo1, Phi_face=np.array([2.0]))
170170
self.assertNotEqual(geo1, geo3)
171171

172+
@parameterized.parameters([
173+
dict(
174+
arr=np.array([1.0, 2.0, 3.0]),
175+
factor=2,
176+
expected_arr=np.array([1.0, 1.5, 2.0, 2.5, 3.0]),
177+
),
178+
dict(
179+
arr=np.array([1.0, 2.0, 3.0, 4.0, 5.0]),
180+
factor=2,
181+
expected_arr=np.array([1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0]),
182+
),
183+
dict(
184+
arr=np.array([1.0, 2.0, 3.0, 4.0, 5.0]),
185+
factor=3,
186+
expected_arr=np.array(
187+
[1.0, 1.33333333, 1.66666667, 2.0, 2.33333333, 2.66666667, 3.0,
188+
3.33333333, 3.66666667, 4.0, 4.33333333, 4.66666667, 5.0]
189+
),
190+
),
191+
dict(
192+
arr=np.array([0.0, 0.25, 0.5, 0.75, 1.0]),
193+
factor=4,
194+
expected_arr=np.array(
195+
[0.0, 0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5,
196+
0.5625, 0.625, 0.6875, 0.75, 0.8125, 0.875, 0.9375, 1.0]
197+
),
198+
),
199+
])
200+
def test_increase_resolution(self, arr, factor, expected_arr):
201+
np.testing.assert_allclose(
202+
geometry.increase_grid_resolution(arr, factor), expected_arr
203+
)
204+
172205

173206
def _pint_face_to_cell(n_rho, face):
174207
cell = np.zeros(n_rho)

torax/_src/mhd/sawtooth/tests/sawtooth_model_test.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -241,42 +241,42 @@ def test_no_subsequent_sawtooth_crashes(self):
241241

242242

243243
_POST_CRASH_TEMPERATURE = np.array([
244-
9.80214764,
245-
9.77449557,
246-
9.74682154,
247-
9.71912539,
248-
9.69140691,
249-
8.17937075,
250-
6.2258966,
244+
9.798375,
245+
9.770761,
246+
9.743125,
247+
9.715467,
248+
9.687787,
249+
8.183115,
250+
6.229396,
251251
4.5,
252252
3.1,
253253
1.7,
254254
])
255255

256256
_POST_CRASH_N = np.array([
257-
0.92905438e20,
258-
0.92652621e20,
259-
0.92399804e20,
260-
0.92146987e20,
261-
0.91894169e20,
262-
0.88178024e20,
263-
0.8345057e20,
264-
0.79219014e20,
265-
0.75698169e20,
266-
0.72177324e20,
257+
9.289564e+19,
258+
9.264304e+19,
259+
9.239043e+19,
260+
9.213783e+19,
261+
9.188523e+19,
262+
8.818625e+19,
263+
8.345811e+19,
264+
7.921901e+19,
265+
7.569817e+19,
266+
7.217732e+19,
267267
])
268268

269269
_POST_CRASH_PSI = np.array([
270-
8.882378,
271-
10.483339,
272-
13.574243,
273-
18.056257,
274-
23.83316,
275-
30.671823,
276-
37.89592,
277-
44.739235,
278-
50.713549,
279-
55.729866,
270+
8.877173,
271+
10.473664,
272+
13.561018,
273+
18.040233,
274+
23.815787,
275+
30.664264,
276+
37.900495,
277+
44.750157,
278+
50.721585,
279+
55.732499,
280280
])
281281

282282

0 commit comments

Comments
 (0)