Skip to content

Commit 7219605

Browse files
committed
update tuple return order to keep old outputs in the same place. update test reference outputs. add note about re-generating test outputs to the readme.
1 parent 0280184 commit 7219605

5 files changed

Lines changed: 152 additions & 109 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ cfspopcon: 0D Plasma Calculations & Plasma OPerating CONtours
1010
POPCONs (Plasma OPerating CONtours) is a tool developed to explore the performance and constraints of tokamak designs based on 0D scaling laws, model plasma kinetic profiles, and physics assumptions on the properties and behavior of the core plasma.
1111

1212
All of our documentation is available at [cfspopcon.readthedocs.io](https://cfspopcon.readthedocs.io/en/latest/). There, you can find installation instructions, instructions for how to run `cfsPOPCON` via the command-line-interface and also explanations of the example Jupyter notebooks in [docs/doc_sources](docs/doc_sources).
13+
14+
To re-generate the saved regression reference outputs in `tests/regression_results`, run the existing CLI helper from the repository root:
15+
16+
```bash
17+
poetry run python tests/utils/regression_results.py
18+
```

cfspopcon/formulas/plasma_profiles/plasma_profiles.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
from .density_peaking import calc_density_peaking, calc_effective_collisionality
1313
from .numerical_profile_fits import evaluate_density_and_temperature_profile_fits
1414

15+
RHO_GRID_EDGE_NUDGE = 1.0e-6
16+
1517

1618
@Algorithm.register_algorithm(
1719
return_keys=[
1820
"effective_collisionality",
1921
"ion_density_peaking",
20-
"ion_density_pedestal_peaking",
2122
"electron_density_peaking",
22-
"electron_density_pedestal_peaking",
23-
"electron_temp_pedestal_peaking",
24-
"ion_temp_pedestal_peaking",
2523
"peak_electron_density",
2624
"peak_fuel_ion_density",
2725
"peak_electron_temp",
@@ -31,6 +29,10 @@
3129
"fuel_ion_density_profile",
3230
"electron_temp_profile",
3331
"ion_temp_profile",
32+
"ion_density_pedestal_peaking",
33+
"electron_density_pedestal_peaking",
34+
"electron_temp_pedestal_peaking",
35+
"ion_temp_pedestal_peaking",
3436
]
3537
)
3638
def calc_peaked_profiles(
@@ -73,11 +75,11 @@ def calc_peaked_profiles(
7375
7476
Returns:
7577
:term:`effective_collisionality`, :term:`ion_density_peaking`, :term:`electron_density_peaking`,
76-
:term:`ion_density_pedestal_peaking`, :term:`electron_density_pedestal_peaking`,
77-
:term:`electron_temp_pedestal_peaking`, :term:`ion_temp_pedestal_peaking`,
7878
:term:`peak_electron_density`, :term:`peak_fuel_ion_density`, :term:`peak_electron_temp`,
7979
:term:`peak_ion_temp`, :term:`rho`, :term:`electron_density_profile`, :term:`fuel_ion_density_profile`,
80-
:term:`electron_temp_profile`, :term:`ion_temp_profile`
80+
:term:`electron_temp_profile`, :term:`ion_temp_profile`, :term:`ion_density_pedestal_peaking`,
81+
:term:`electron_density_pedestal_peaking`, :term:`electron_temp_pedestal_peaking`,
82+
:term:`ion_temp_pedestal_peaking`
8183
"""
8284
effective_collisionality = calc_effective_collisionality(average_electron_density, average_electron_temp, major_radius, z_effective)
8385
ion_density_peaking = calc_density_peaking(effective_collisionality, beta_toroidal, nu_noffset=ion_density_peaking_offset)
@@ -132,11 +134,7 @@ def calc_peaked_profiles(
132134
return (
133135
effective_collisionality,
134136
ion_density_peaking,
135-
ion_density_pedestal_peaking,
136137
electron_density_peaking,
137-
electron_density_pedestal_peaking,
138-
electron_temp_pedestal_peaking,
139-
ion_temp_pedestal_peaking,
140138
peak_electron_density,
141139
peak_fuel_ion_density,
142140
peak_electron_temp,
@@ -146,6 +144,10 @@ def calc_peaked_profiles(
146144
fuel_ion_density_profile,
147145
electron_temp_profile,
148146
ion_temp_profile,
147+
ion_density_pedestal_peaking,
148+
electron_density_pedestal_peaking,
149+
electron_temp_pedestal_peaking,
150+
ion_temp_pedestal_peaking,
149151
)
150152

151153

@@ -213,6 +215,8 @@ def calc_1D_plasma_profiles(
213215
dilution: dilution of main ions [~]
214216
normalized_inverse_temp_scale_length: [~] :term:`glossary link<normalized_inverse_temp_scale_length>`
215217
n_points_for_confined_region_profiles: Number of points to return in the profile grid.
218+
Non-JCH grids stop at ``rho = 1 - 1e-6`` instead of exactly 1.0 so
219+
hollow analytic profiles remain finite at the separatrix.
216220
pedestal_width: Pedestal width in normalized rho for JCH profiles.
217221
t_sep: Separatrix temperature used to anchor the JCH edge temperature profile.
218222
n_sep_ratio: Ratio of separatrix density to pedestal density for JCH profiles.
@@ -517,11 +521,17 @@ def _find_nearest_interior_grid_index(values: np.ndarray, target: float) -> int:
517521

518522

519523
def _build_profile_grid(npoints: int, rho_ped: float | None = None) -> np.ndarray:
520-
"""Build the radial grid and optionally reserve four points across the pedestal."""
521-
rho = np.linspace(0.0, 1.0, num=npoints)
524+
"""Build the radial grid and optionally reserve four points across the pedestal.
522525
526+
Non-JCH grids nudge the final sample to ``rho = 1 - 1e-6`` so the analytic
527+
hollow-profile form is never evaluated exactly at its separatrix singularity.
528+
JCH grids keep the explicit separatrix point because the pedestal model is
529+
anchored there.
530+
"""
523531
if rho_ped is None:
524-
return rho
532+
# Keep the final sample infinitesimally inside the LCFS so hollow
533+
# analytic profiles do not diverge at rho = 1.
534+
return np.linspace(0.0, 1.0 - RHO_GRID_EDGE_NUDGE, num=npoints)
525535

526536
pedestal_points = 4
527537
if npoints < pedestal_points + 1:

tests/regression_results/PRD.json

Lines changed: 88 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"attrs": {
8080
"units": "megawatt"
8181
},
82-
"data": 7.88536,
82+
"data": 7.88537,
8383
"dims": []
8484
},
8585
"P_external": {
@@ -395,7 +395,7 @@
395395
36.1131,
396396
35.8205,
397397
35.5027,
398-
35.1604,
398+
35.1605,
399399
34.7946,
400400
34.4058,
401401
33.9950,
@@ -406,32 +406,32 @@
406406
31.6436,
407407
31.1208,
408408
30.5829,
409-
30.0310,
409+
30.0311,
410410
29.4673,
411411
28.8952,
412-
28.3342,
413-
27.7841,
414-
27.2447,
412+
28.3343,
413+
27.7842,
414+
27.2448,
415415
26.7158,
416416
26.1971,
417417
25.6885,
418418
25.1898,
419-
24.7007,
419+
24.7008,
420420
24.2212,
421421
23.7510,
422-
23.2898,
422+
23.2899,
423423
22.8377,
424424
22.3943,
425425
21.9595,
426426
21.5332,
427-
21.1151,
427+
21.1152,
428428
20.7052,
429429
20.3032,
430-
19.9090,
430+
19.9091,
431431
19.5225,
432432
19.3131,
433-
12.4387,
434-
2.42912
433+
12.4391,
434+
2.42936
435435
],
436436
"dims": [
437437
"dim_rho"
@@ -469,36 +469,36 @@
469469
17.0494,
470470
16.4582,
471471
15.8555,
472-
15.2441,
472+
15.2442,
473473
14.6268,
474474
14.0062,
475475
13.3849,
476476
12.7654,
477477
12.1512,
478478
11.5468,
479479
10.9724,
480-
10.4266,
481-
9.90801,
482-
9.41518,
483-
8.94686,
484-
8.50184,
485-
8.07895,
486-
7.67710,
487-
7.29523,
488-
6.93236,
489-
6.58754,
490-
6.25987,
491-
5.94850,
492-
5.65262,
493-
5.37145,
494-
5.10427,
495-
4.85038,
496-
4.60912,
497-
4.37986,
498-
4.16200,
480+
10.4267,
481+
9.90802,
482+
9.41519,
483+
8.94687,
484+
8.50185,
485+
8.07896,
486+
7.67711,
487+
7.29524,
488+
6.93237,
489+
6.58755,
490+
6.25988,
491+
5.94851,
492+
5.65263,
493+
5.37146,
494+
5.10428,
495+
4.85039,
496+
4.60913,
497+
4.37987,
498+
4.16201,
499499
4.04684,
500-
2.60637,
501-
0.508992
500+
2.60647,
501+
0.509042
502502
],
503503
"dims": [
504504
"dim_rho"
@@ -621,7 +621,7 @@
621621
23.8634,
622622
23.4897,
623623
23.1218,
624-
22.7596,
624+
22.7597,
625625
22.4032,
626626
22.0523,
627627
21.7069,
@@ -630,7 +630,7 @@
630630
20.7029,
631631
20.3787,
632632
20.0595,
633-
19.7453,
633+
19.7454,
634634
19.4361,
635635
19.1317,
636636
18.8321,
@@ -639,8 +639,8 @@
639639
17.9610,
640640
17.6797,
641641
17.5269,
642-
11.2882,
643-
2.20445
642+
11.2887,
643+
2.20467
644644
],
645645
"dims": [
646646
"dim_rho"
@@ -819,36 +819,36 @@
819819
17.0494,
820820
16.4582,
821821
15.8555,
822-
15.2441,
822+
15.2442,
823823
14.6268,
824824
14.0062,
825825
13.3849,
826826
12.7654,
827827
12.1512,
828828
11.5468,
829829
10.9724,
830-
10.4266,
831-
9.90801,
832-
9.41518,
833-
8.94686,
834-
8.50184,
835-
8.07895,
836-
7.67710,
837-
7.29523,
838-
6.93236,
839-
6.58754,
840-
6.25987,
841-
5.94850,
842-
5.65262,
843-
5.37145,
844-
5.10427,
845-
4.85038,
846-
4.60912,
847-
4.37986,
848-
4.16200,
830+
10.4267,
831+
9.90802,
832+
9.41519,
833+
8.94687,
834+
8.50185,
835+
8.07896,
836+
7.67711,
837+
7.29524,
838+
6.93237,
839+
6.58755,
840+
6.25988,
841+
5.94851,
842+
5.65263,
843+
5.37146,
844+
5.10428,
845+
4.85039,
846+
4.60913,
847+
4.37987,
848+
4.16201,
849849
4.04684,
850-
2.60637,
851-
0.508992
850+
2.60647,
851+
0.509042
852852
],
853853
"dims": [
854854
"dim_rho"
@@ -1141,55 +1141,55 @@
11411141
},
11421142
"data": [
11431143
0.00000,
1144-
0.0204082,
1144+
0.0204081,
11451145
0.0408163,
1146-
0.0612245,
1147-
0.0816327,
1146+
0.0612244,
1147+
0.0816326,
11481148
0.102041,
11491149
0.122449,
11501150
0.142857,
11511151
0.163265,
11521152
0.183673,
1153-
0.204082,
1153+
0.204081,
11541154
0.224490,
11551155
0.244898,
11561156
0.265306,
11571157
0.285714,
11581158
0.306122,
1159-
0.326531,
1160-
0.346939,
1159+
0.326530,
1160+
0.346938,
11611161
0.367347,
11621162
0.387755,
11631163
0.408163,
11641164
0.428571,
1165-
0.448980,
1166-
0.469388,
1167-
0.489796,
1165+
0.448979,
1166+
0.469387,
1167+
0.489795,
11681168
0.510204,
11691169
0.530612,
11701170
0.551020,
1171-
0.571429,
1172-
0.591837,
1173-
0.612245,
1174-
0.632653,
1171+
0.571428,
1172+
0.591836,
1173+
0.612244,
1174+
0.632652,
11751175
0.653061,
11761176
0.673469,
1177-
0.693878,
1178-
0.714286,
1179-
0.734694,
1180-
0.755102,
1181-
0.775510,
1177+
0.693877,
1178+
0.714285,
1179+
0.734693,
1180+
0.755101,
1181+
0.775509,
11821182
0.795918,
1183-
0.816327,
1184-
0.836735,
1185-
0.857143,
1186-
0.877551,
1187-
0.897959,
1188-
0.918367,
1189-
0.938776,
1190-
0.959184,
1191-
0.979592,
1192-
1.00000
1183+
0.816326,
1184+
0.836734,
1185+
0.857142,
1186+
0.877550,
1187+
0.897958,
1188+
0.918366,
1189+
0.938775,
1190+
0.959183,
1191+
0.979591,
1192+
0.999999
11931193
],
11941194
"dims": [
11951195
"dim_rho"
104 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)