• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gyrokinetics / gs2 / 1970319704

06 Aug 2025 03:50PM UTC coverage: 8.18% (+0.002%) from 8.178%
1970319704

push

gitlab-ci

David Dickinson
Merged in bugfix/fix_issue_88_multiple_ncheck (pull request #1109)

3667 of 44831 relevant lines covered (8.18%)

124503.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/diagnostics_configuration.f90
1
module diagnostics_configuration
2
  use abstract_config, only: abstract_config_type, CONFIG_MAX_NAME_LEN
3
  implicit none
4
  private
5
  public :: diagnostics_config, warn_about_nonfunctional_selection
6
  public :: diagnostics_config_type, set_diagnostics_config, get_diagnostics_config
7

8
  !> Used to represent the input configuration of
9
  !> gs2_diagnostics. This is the version used by the original
10
  !> diagnostics module.
11
  type, extends(abstract_config_type) :: diagnostics_config_type
12
    ! namelist : gs2_diagnostics_knobs
13
    ! indexed : false
14
    !> Append output data to a previous output file `<run name>.out.nc` if it
15
    !> already exists. Grid sizes must be unchanged.
16
    logical :: append_old = .false.
17
    !> Used for nonlinear convergence check
18
    !> ([[gs2_diagnostics_knobs:use_nonlin_convergence]]). The maximum number
19
    !> of time steps, after which consider the run converged regardless.
20
    integer :: conv_max_step = 80000
21
    !> Used for the nonlinear convergence check
22
    !> ([[gs2_diagnostics_knobs:use_nonlin_convergence]]). The minimum number
23
    !> of time steps before convergence condition can trigger an exit.
24
    integer :: conv_min_step = 4000
25
    !> Used for the nonlinear convergence check
26
    !> ([[gs2_diagnostics_knobs:use_nonlin_convergence]]). The number of
27
    !> timesteps the convergence condition averages over
28
    integer :: conv_nstep_av = 4000
29
    !> Used for the nonlinear convergence check
30
    !> ([[gs2_diagnostics_knobs:use_nonlin_convergence]]). The number of steps
31
    !> where convergence is true before convergence is accepted
32
    integer :: conv_nsteps_converged = 10000
33
    !> Used for the nonlinear convergence check
34
    !> ([[gs2_diagnostics_knobs:use_nonlin_convergence]]). Multiplier for the
35
    !> cumulative average of the heat flux
36
    real :: conv_test_multiplier = 4e-1
37
    !> Sets a threshold on the maximum damping rate. If all modes are more strongly
38
    !> damped over the entire [[gs2_diagnostics_knobs:navg]] period then the simulation
39
    !> will exit.
40
    real :: damped_threshold = -9e38
41
    !> Exit when the run has reached convergence
42
    logical :: exit_when_converged = .true.
43
    !> Verify that the restart file(s) can be written before starting the run
44
    logical :: file_safety_check = .true.
45
    !> Index in \(\theta\) to measure various diagnostics at. By default, this
46
    !> is the outboard midplane \(\theta = 0\), but it may be useful to set
47
    !> this to a non-zero value for tearing parity modes.
48
    integer :: igomega = 0
49
    !> Write out \(\phi, A_\parallel, B_\parallel\) in real space over time,
50
    !> suitable for creating animations. Timestep period is controlled with
51
    !> [[gs2_diagnostics_knobs:nmovie]]
52
    !>
53
    !>
54
    !> @warning This option can write a lot of data! Consider doing the Fourier
55
    !> transforms of the fields in post-processing instead.
56
    !>
57
    !> @warning In new diagnostics, the timestep period is controlled with
58
    !> [[gs2_diagnostics_knobs:nwrite]]
59
    logical :: make_movie = .false.
60
    !> Number of timesteps to average over for time-averaged diagnostics
61
    !>
62
    !> @warning Default value differs between old (100) and new (10)
63
    !> diagnostics
64
    integer :: navg = 10
65
    !> Sets the number of output steps between syncing the netcdf file.
66
    !> Higher values may reduce disk overheads but increase the risk of
67
    !> data loss on unclean exit.
68
    integer :: nc_sync_freq = 10
69
    !> Timestep period to write real space fields \(\phi, A_\parallel,
70
    !> B_\parallel\)
71
    !>
72
    !> @warning Non-functional in new diagnostics. Instead use
73
    !> [[gs2_diagnostics_knobs:nwrite]]
74
    !>
75
    !> @warning Default value differs between old (1000) and new (-1)
76
    !> diagnostics
77
    integer :: nmovie = -1
78
    !> Timestep period for writing restart data if
79
    !> [[gs2_diagnostics_knobs:save_for_restart]] is `.true.`. Negative values
80
    !> disable the periodic checkpoints.
81
    integer :: nsave = -1
82
    !> Timestep period for writing outputs
83
    !>
84
    !> @warning Default value differs between old (`== 100`) and new (`== 10`)
85
    !> diagnostics!
86
    integer :: nwrite = 10
87
    !> Timestep period multiplier for certain "large" diagnostics, which are
88
    !> written every `nwrite_mult * nwrite` timesteps.
89
    !>
90
    !> FIXME: What datasets? `phicorr_sum`, `phiextend_sum` in old diagnostics,
91
    !> `f` and `fyx` in new diagnostics?
92
    !>
93
    !> @warning Controls different diagnostics in new diagnostics
94
    integer :: nwrite_mult = 10
95
    !> If `.true.`, write moments at the outboard midplane only, as opposed to
96
    !> along the entire flux surface
97
    !>
98
    !> @warning Non-functional in new diagnostics
99
    !>
100
    !> @warning Default value differs between old (.true.) and new (.false.) diagnostics
101
    logical :: ob_midplane = .false.
102
    !> Only perform tests of omega behaviour (convergence etc.) once the simulation time
103
    !> is at least this value
104
    real :: omega_checks_start = 0.0
105
    !> Threshold complex frequency (\(\Omega\)) for detecting a numerical
106
    !> instability. If \(\abs(\Omega)\) averaged over
107
    !> [[gs2_diagnostics_knobs:navg]] timesteps is greater than `omegatinst`,
108
    !> abort the run.
109
    !>
110
    !> @warning Default value differs between old (1.0) and new (1.0e6)
111
    !> diagnostics
112
    real :: omegatinst = 1.0e6
113
    !> Frequency (\(\omega\)) convergence tolerance. Consider the simulation
114
    !> converged and finish the run if \(\omega\) has changed by less than
115
    !> `omegatol` over the last [[gs2_diagnostics_knobs:navg]] timesteps.
116
    !>
117
    !> More explicitly, the convergence criterion is:
118
    !>
119
    !> $$\sqrt{\sum_t^{n_{avg}} |\bar{\omega} - \omega|^2} < \min{\bar{\omega}, 1.0}\cdot\omega_{tol}$$
120
    !>
121
    !> where \(\bar{\omega}\) is \(\omega\) averaged over the last `navg`
122
    !> timesteps.
123
    real :: omegatol = 1e-3
124
    !> Print the instantaneous fluxes to screen/stdout every
125
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
126
    logical :: print_flux_line = .false.
127
    !> Print estimated frequencies and growth rates to screen/stdout every
128
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
129
    !>
130
    !> @warning Default value differs between old (`.true.`) and new
131
    !> (`.false.`) diagnostics
132
    logical :: print_line = .false.
133
    !> Write the distribution function to `<rootname>.nc.dfn.<processor>`
134
    !> files. Only written at end of simulation
135
    logical :: save_distfn = .false.
136
    !> Write restart files at the end of the simulation. If
137
    !> [[gs2_diagnostics_knobs:nsave]] is positive, then also enable
138
    !> checkpoints by writing restart files every `nsave` timesteps.
139
    logical :: save_for_restart = .false.
140
    !> Save some layout and distribution information in restart files
141
    logical :: save_glo_info_and_grids = .false.
142
    !> If `.true.`, write one restart file per processor, otherwise write a
143
    !> single restart file.
144
    !>
145
    !> If `gs2` has not been built with parallel netCDF, `save_many` is ignored
146
    !> and there is always one file per processor (equivalent to `save_many =
147
    !> .true.`).
148
    !>
149
    !> If `write_many` is enabled, you probably want to also set
150
    !> [[init_g_knobs:read_many]] in order to restart from multiple files.
151
    logical :: save_many = .false.
152
    !> Save parallel and perpendicular velocities in final restart and/or
153
    !> distribution function files
154
    logical :: save_velocities = .false.
155
    !> @warning Not used
156
    !>
157
    !> @warning Only in new diagnostics
158
    logical :: serial_netcdf4 = .false.
159
    !> For nonlinear runs, stop the run when the averaged differential of the
160
    !> summed averaged heat flux drops below a threshold for a period of time,
161
    !> controlled by [[gs2_diagnostics_knobs:conv_test_multiplier]],
162
    !> [[gs2_diagnostics_knobs:conv_nsteps_converged]],
163
    !> [[gs2_diagnostics_knobs:conv_nsteps_av]],
164
    !> [[gs2_diagnostics_knobs:conv_max_step]], and
165
    !> [[gs2_diagnostics_knobs:conv_min_step]].
166
    logical :: use_nonlin_convergence = .false.
167
    !> If `.false.`, skip writing any diagnostics
168
    !>
169
    !> @warning Only in new diagnostics
170
    !>
171
    !> @warning This also turns off checking the linear convergence
172
    logical :: write_any = .true.
173
    !> Write the entire \(A_\parallel\) field every
174
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
175
    !>
176
    !> @warning New diagnostics requires
177
    !> [[gs2_diagnostics_knobs:write_fields]] to also be `.true.`
178
    !> (the default) to enable this
179
    logical :: write_apar_over_time = .false.
180
    !> Write diagnostics to text files. Generally this creates a different text
181
    !> file for each diagnostic. Note that this independent of whether or not
182
    !> netCDF files are used.
183
    !>
184
    !> FIXME: Verify old and new diagnostics write these files in same format
185
    logical :: write_ascii = .true.
186
    !> Write flux surface averaged low-order moments of \(g\) every
187
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
188
    !>
189
    !> @warning Prints a warning that this is ignored unless
190
    !> `grid_option==box`, but this doesn't appear to be the case?
191
    logical :: write_avg_moments = .false.
192
    !> Write the entire \(B_\parallel\) field every
193
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
194
    !>
195
    !> @warning New diagnostics requires
196
    !> [[gs2_diagnostics_knobs:write_fields]] to also be `.true.`
197
    !> (the default) to enable this
198
    logical :: write_bpar_over_time = .false.
199
    !> Write the collision error every [[gs2_diagnostics_knobs:nwrite]]
200
    !> timesteps to text file with suffix `.cres`
201
    !>
202
    !> FIXME: What does this mean?
203
    !>
204
    !> @warning In new diagnostics, only writes to ascii
205
    !>
206
    !> @warning This is expensive
207
    logical :: write_cerr = .false.
208
    !> Write collisional heating (collisional and hyper viscous rate of loss of
209
    !> free energy for each mode) every [[gs2_diagnostics_knobs:nwrite]]
210
    !> timesteps
211
    !>
212
    !> @warning Only in new diagnostics
213
    logical :: write_collisional = .false.
214
    !> Write two point parallel correlation function calculated from the
215
    !> electric potential as a function of \(k_y\) and parallel separation
216
    !> every [[gs2_diagnostics_knobs:nwrite]] timesteps
217
    !>
218
    !> @warning Default value differs between old (`.false.`) and new
219
    !> (`.true.`) diagnostics
220
    logical :: write_correlation = .true.
221
    !> Write two point parallel correlation function calculated from the
222
    !> electric potential as a function of \(k_y\) and parallel separation,
223
    !> time averaged and calculated along the extended domain every
224
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps once istep > nstep/4.
225
    !>
226
    !> @warning This diagnostic can have large persistent memory cost.
227
    logical :: write_correlation_extend = .false.
228
    !> Write the cross phase between electron density and perpendicular
229
    !> electron temperature every [[gs2_diagnostics_knobs:nwrite]]
230
    !> timesteps. Calculated at both the outboard midplane, averaged across
231
    !> \(x\) and \(y\); and averaged across all space
232
    !>
233
    !> @warning In old diagnostics, only written to text files
234
    logical :: write_cross_phase = .false.
235
    !> Write the whole non-adiabatic part of the density moment every
236
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
237
    !>
238
    !> @warning Requires [[gs2_diagnostics_knobs:write_moments]] to also be
239
    !> `.true.`
240
    !>
241
    !> @warning Only in new diagnostics
242
    logical :: write_density_over_time = .false.
243
    !> Write \(\phi, A_\parallel, B_\parallel\) normalised to the value of
244
    !> \(\phi\) at the outboard midplane every [[gs2_diagnostics_knobs:nwrite]]
245
    !> timesteps.
246
    !>
247
    !> If [[gs2_diagnostics_knobs:write_ascii]] is enabled, the text file is
248
    !> `<runname>.eigenfunc`.
249
    !>
250
    !> @note The normalising factor for a given \((\theta, k_y)\) point may not
251
    !> be exactly \(\phi\) at the outboard midplane if this value is zero
252
    !> there. If the adjacent point in \(\theta\) is also zero, then the fields
253
    !> will be unnormalised at that \((\theta, k_y)\).
254
    !>
255
    !> @warning If this option is turned on, the same normalising factor will
256
    !> also be used for the text output in
257
    !> [[gs2_diagnostics_knobs:write_final_moments]]
258
    !>
259
    !> @warning In old diagnostics, this is only done on exit, not every
260
    !> `nwrite` timesteps!
261
    !>
262
    !> @warning The text output is normalised (see note above), but the netCDF
263
    !> output is not
264
    logical :: write_eigenfunc = .false.
265
    !> Enable writing \(\phi, A_\parallel, B_\parallel\) every
266
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
267
    !>
268
    !> @warning In old diagnostics, this only writes them on exit and
269
    !> [[gs2_diagnostics_knobs:write_phi_over_time]],
270
    !> [[gs2_diagnostics_knobs:write_apar_over_time]] and
271
    !> [[gs2_diagnostics_knobs:write_bpar_over_time]] instead control writing
272
    !> the fields over time, respectively. In new diagnostics, this will disable
273
    !> writing all three fields if set to `.false.`
274
    !>
275
    !> @warning Default value differs between old (`.false.`) and new
276
    !> (`.true.`) diagnostics
277
    logical :: write_fields = .true.
278
    !> Write the right-hand sides of the field equations at the final
279
    !> timestep. If [[gs2_diagnostics_knobs:write_ascii]] is enabled, the file
280
    !> suffix is `.antot`
281
    logical :: write_final_antot = .false.
282
    !> Write \(\delta B\) at the final timestep. If
283
    !> [[gs2_diagnostics_knobs:write_ascii]] is enabled, the file suffix is
284
    !> `.db`. This is not written to netCDF!
285
    logical :: write_final_db = .false.
286
    !> Write \(E_\parallel\) at the final timestep. If
287
    !> [[gs2_diagnostics_knobs:write_ascii]] is enabled, the file suffix is
288
    !> `.epar`
289
    logical :: write_final_epar = .false.
290
    !> Write \(\phi, A_\parallel, B_\parallel\) at the final timestep. If
291
    !> [[gs2_diagnostics_knobs:write_ascii]] is enabled, the file suffix is
292
    !> `.fields`
293
    logical :: write_final_fields = .false.
294
    !> Write various moments (densities, parallel and perpendicular
295
    !> velocities and temperatures, and heat and momentum fluxes) at
296
    !> the final timestep. If [[gs2_diagnostics_knobs:write_ascii]]
297
    !> is enabled, the file suffix is `.fields` and contains the
298
    !> moments, their magnitudes, and field-line averages. The netCDF
299
    !> output has only the values.
300
    !>
301
    !> @warning If [[gs2_diagnostics_knobs:write_eigenfunc]] is
302
    !> enabled, then the same normalising factor is used for the
303
    !> final moments. Otherwise, the moments are unnormalised.
304
    !>
305
    !> @warning The text output is normalised (see note above), but
306
    !> the netCDF output is not
307
    logical :: write_final_moments = .false.
308
    !> Write instantaneous fluxes to output file every
309
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
310
    !>
311
    !> @warning Output formats and quantities differ between old and new
312
    !> diagnostics
313
    logical :: write_flux_line = .false.
314
    !> Write fluxes (heat, momentum and particle; total and per-species) every
315
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps.
316
    !>
317
    !> If run is nonlinear, this defaults to true
318
    !>
319
    !> @warning In old diagnostics, this also turns on `write_fluxes_by_mode`
320
    logical :: write_fluxes = .false.
321
    !> Write fluxes (heat, momentum and particle; total and per-species) as a
322
    !> function of Fourier mode every [[gs2_diagnostics_knobs:nwrite]]
323
    !> timesteps.
324
    !>
325
    !> If run is nonlinear, this defaults to true
326
    !>
327
    !> @warning In old diagnostics, this is combined with `write_fluxes`
328
    logical :: write_fluxes_by_mode = .false.
329
    !> Write moments (density, parallel flow, and parallel and perpendicular
330
    !> temperatures) in non-guiding centre coordinates every
331
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
332
    logical :: write_full_moments_notgc = .false.
333
    !> Write \(g(v_\parallel,v_\perp)\) at `ik=it=is=1, ig=0` to text file
334
    !> `<runname>.dist`
335
    !>
336
    !> @warning Only to text files
337
    logical :: write_g = .false.
338
    !> FIXME: Add documentation
339
    !>
340
    !> @warning Only outputs to text files
341
    logical :: write_gs = .false.
342
    !> Write \(g\) as a function of real space every
343
    !> [[gs2_diagnostics_knobs:nmovie]] timesteps to text file
344
    !> "<runname>.yxdist"
345
    !>
346
    !> @warning Only to text files
347
    logical :: write_gyx = .false.
348
    !> Write out various heating, free energy and energy injection
349
    !> diagnostics. Text file extension is `.heat`
350
    logical :: write_heating = .false.
351
    !> Write time averaged external current in the antenna,
352
    !> \(\operatorname{Re}(k_\perp^2 A_\mathrm{antenna})\), as a function of
353
    !> \(k_x, k_y\). File suffix is `.jext`
354
    !>
355
    !> @warning Only in new diagnostics
356
    logical :: write_jext = .false.
357
    !> Calculates and writes the electrostatic drive of zonal flows
358
    !> every [[gs2_diagnostics_knobs:nwrite]] timesteps.  The output
359
    !> `kinetic_energy_transfer_theta` resolves this over \(\theta\)
360
    !> only.  `kinetic_energy_transfer_theta_kxsource`,
361
    !> `kinetic_energy_transfer_theta_kxtarget`, and
362
    !> `kinetic_energy_transfer_theta_kysource` give additional
363
    !> insights by resolving over individual source or target scales.
364
    logical :: write_kinetic_energy_transfer = .false.
365
    !> Write the parallel spectrum of \(\phi, A_\parallel,
366
    !> B_\parallel\) at final timestep. File suffix is `.kpar`
367
    !>
368
    !> @warning Output only to text files
369
    logical :: write_kpar = .false.
370
    !> Print estimated frequencies and growth rates to text file every
371
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
372
    logical :: write_line = .true.
373
    !> Write `antenna_w` every [[gs2_diagnostics_knobs:nwrite]]
374
    !> timesteps
375
    !>
376
    !> FIXME: Define `antenna_w`
377
    !>
378
    !> @warning Old diagnostics only writes to text files
379
    !>
380
    !> @warning New diagnostics only writes to netCDF
381
    logical :: write_lorentzian = .false.
382
    !> Write the estimated maximum error from velocity space
383
    !> integrals for various quantities
384
    !>
385
    !> @warning Old diagnostics only outputs to text file
386
    logical :: write_max_verr = .false.
387
    !> Write various moments (total and non-adiabatic part of perturbed species
388
    !> density, perturbed parallel flow, perturbed parallel and perpendicular
389
    !> temperatures, parallel heat flux, particule flux and heat flux) every
390
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
391
    !>
392
    !> @warning Only outputs to netCDF files
393
    !>
394
    !> @warning New diagnostics writes various averages of the moments. To get
395
    !> the same output as old diagnostics, **also** set
396
    !> [[gs2_diagnostics_knobs:write_ntot_over_time]],
397
    !> [[gs2_diagnostics_knobs:write_density_over_time]],
398
    !> [[gs2_diagnostics_knobs:write_upar_over_time]],
399
    !> [[gs2_diagnostics_knobs:write_tperp_over_time]] to `.true.`
400
    !>
401
    !> @warning Default value differs between old (`.false.`) and new
402
    !> (`.true.`) diagnostics
403
    logical :: write_moments = .true.
404
    !> Write the poloidal distributions of the fluxes of particles,
405
    !> parallel momentum, perpendicular momentum, and energy every
406
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps.
407
    !>
408
    !> See section 3.1 and appendix A of [Ball et al. PPCF 58 (2016)
409
    !> 045023](https://doi.org/10.1088/0741-3335/58/4/045023) as well as
410
    !> section 5 of "GS2 analytic geometry specification"
411
    logical :: write_nl_flux_dist = .false.
412
    !> Write the whole total density moment every
413
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
414
    !>
415
    !> @warning Requires [[gs2_diagnostics_knobs:write_moments]] to also be
416
    !> `.true.`
417
    !>
418
    !> @warning Only in new diagnostics
419
    logical :: write_ntot_over_time = .false.
420
    !> Write time-averaged growth rate and frequency to the output text file
421
    !> every [[gs2_diagnostics_knobs:nwrite]] timesteps. Time average is
422
    !> rolling window over the previous [[gs2_diagnostics_knobs:navg]]
423
    !> timesteps
424
    !>
425
    !> @warning Non-functional in new diagnostics, time-average is also written
426
    !> with [[gs2_diagnostics_knobs:write_omega]] instead
427
    logical :: write_omavg = .true.
428
    !> Write instantaneous growth rate and frequency every
429
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
430
    !>
431
    !> @warning Old diagnostics only writes to output text file
432
    !>
433
    !> @warning New diagnostics only writes to netCDF file
434
    !>
435
    !> @warning New diagnostics also writes time-average with this
436
    !> option. Output is the complex frequency, rather than separate growth
437
    !> rate and real frequency
438
    logical :: write_omega = .true.
439
    !> Write parities in distribution and particle fluxes to text file with the
440
    !> suffix `.parity`
441
    !>
442
    !> FIXME: Clarify what this means
443
    logical :: write_parity = .false.
444
    !> Write the entire \(\phi\) field every [[gs2_diagnostics_knobs:nwrite]]
445
    !> timesteps
446
    !>
447
    !> @warning New diagnostics requires
448
    !> [[gs2_diagnostics_knobs:write_fields]] to also be `.true.`
449
    !> (the default) to enable this
450
    logical :: write_phi_over_time = .false.
451
    !> Write a simple quasi-linear metric to netcdf.
452
    logical :: write_ql_metric = .true.
453
    !> Write the particle and momentum flux as a function of \(\theta\) and
454
    !> velocity space. See [[gs2_diagnostics_knobs:write_pflux_sym]] and
455
    !> [[gs2_diagnostics_knobs:write_pflux_tormom]]
456
    !>
457
    !> @warning Only outputs to netCDF
458
    !>
459
    !> @warning Old diagnostics does not write the particle flux, use
460
    !> [[gs2_diagnostics_knobs:write_pflux_sym]] instead
461
    logical :: write_symmetry = .false.
462
    !> Write the whole perturbed perpendicular temperature moment every
463
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
464
    !>
465
    !> @warning Requires [[gs2_diagnostics_knobs:write_moments]] to also be
466
    !> `.true.`
467
    !>
468
    !> @warning Only in new diagnostics
469
    logical :: write_tperp_over_time = .false.
470
    !> Write the whole perturbed parallel velocity moment every
471
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
472
    !>
473
    !> @warning Requires [[gs2_diagnostics_knobs:write_moments]] to also be
474
    !> `.true.`
475
    !>
476
    !> @warning Only in new diagnostics
477
    logical :: write_upar_over_time = .false.
478
    !> Write estimates of error resulting from velocity space integrals in the
479
    !> calculation of various quantities every [[gs2_diagnostics_knobs:nwrite]]
480
    !> timesteps.
481
    !>
482
    !> @warning Output only to text file
483
    !>
484
    !> @warning New diagnostics also writes to netCDF every
485
    !> [[collisions_knobs:ncheck]] timesteps, along with some other
486
    !> quantities such as collisionality
487
    !>
488
    !> @warning This is expensive
489
    logical :: write_verr = .false.
490
    !> Write the transfer of free energy, \(\tau\), as a function of \((k_x,
491
    !> k_y)\), averaged over \(\theta\), every [[gs2_diagnostics_knobs:nwrite]]
492
    !> timesteps
493
    !>
494
    !> @warning Only in new diagnostics
495
    logical :: write_zonal_transfer = .false.
496
  contains
497
    procedure, public :: read => read_diagnostics_config
498
    procedure, public :: write => write_diagnostics_config
499
    procedure, public :: reset => reset_diagnostics_config
500
    procedure, public :: broadcast => broadcast_diagnostics_config
501
    procedure, public, nopass :: get_default_name => get_default_name_diagnostics_config
502
    procedure, public, nopass :: get_default_requires_index => get_default_requires_index_diagnostics_config
503
    procedure :: set_smart_defaults => set_smart_defaults_local
504
  end type diagnostics_config_type
505

506
  type(diagnostics_config_type) :: diagnostics_config
507
contains
508

509
  !> Prints a warning about a non-functional diagnostic
510
  subroutine warn_about_nonfunctional_selection(diagnostic_switch, name)
×
511
    use run_parameters, only: use_old_diagnostics
512
    use mp, only: proc0
513
    !> Diagnostic switch
514
    logical, intent(in) :: diagnostic_switch
515
    !> Name of the switch
516
    character(len=*), intent(in) :: name
517

518
    character(len=3) :: diagnostics_module
519

520
    if (use_old_diagnostics) then
×
521
      diagnostics_module = "old"
×
522
    else
523
      diagnostics_module = "new"
×
524
    end if
525

526
    if (diagnostic_switch .and. proc0) then
×
527
      write(*, '(a, a, a, a, a)') "WARNING: diagnostic '", name, &
×
528
           "' is (currently) non-functional in ", diagnostics_module, &
×
529
           " diagnostics module. This will have no effect."
×
530
    end if
531
  end subroutine warn_about_nonfunctional_selection
×
532

533
  subroutine set_smart_defaults_local(self)
×
534
    use nonlinear_terms, only: nonlin
535
    use run_parameters, only: use_old_diagnostics
536
    implicit none
537
    class(diagnostics_config_type), intent(in out) :: self
538
    if (self%is_initialised()) return
×
539
  !> Set the smart defaults for the new_gs2_diagnostics_config_type instance
540
    if(nonlin) then
×
541
       self%write_fluxes = .true.
×
542
       self%write_fluxes_by_mode = .true.
×
543
    end if
544

545
    if (use_old_diagnostics) then
×
546
       call apply_old_defaults(self)
×
547
    else
548
       call apply_new_defaults(self)
×
549
    end if
550
  end subroutine set_smart_defaults_local
551

552
  !> Set values according to the old diagnostics defaults.
553
  !>
554
  !> Will overwrite existing values, unless the config object has
555
  !> already been initialised, in which case returns without changing
556
  !> any values
557
  subroutine apply_old_defaults(gs2_diagnostics_config_in)
×
558
    type(diagnostics_config_type), intent(inout) :: gs2_diagnostics_config_in
559

560
    if (gs2_diagnostics_config_in%is_initialised()) return
×
561

562
    gs2_diagnostics_config_in%navg = 100
×
563
    gs2_diagnostics_config_in%nmovie = 1000
×
564
    gs2_diagnostics_config_in%nwrite = 100
×
565
    gs2_diagnostics_config_in%ob_midplane = .true.
×
566
    gs2_diagnostics_config_in%omegatinst = 1.0
×
567
    gs2_diagnostics_config_in%print_line = .true.
×
568
    gs2_diagnostics_config_in%write_correlation = .false.
×
569
    gs2_diagnostics_config_in%write_moments = .false.
×
570
  end subroutine apply_old_defaults
571

572
  !> Set values according to the new diagnostics defaults.
573
  !>
574
  !> Will overwrite existing values, unless the config object has
575
  !> already been initialised, in which case returns without changing
576
  !> any values
577
  subroutine apply_new_defaults(new_gs2_diagnostics_config_in)
×
578
    type(diagnostics_config_type), intent(in out) :: new_gs2_diagnostics_config_in
579

580
    if (new_gs2_diagnostics_config_in%is_initialised()) return
×
581

582
    new_gs2_diagnostics_config_in%navg = 10
×
583
    new_gs2_diagnostics_config_in%nmovie = -1
×
584
    new_gs2_diagnostics_config_in%nwrite = 10
×
585
    new_gs2_diagnostics_config_in%ob_midplane = .false.
×
586
    new_gs2_diagnostics_config_in%omegatinst = 1.0e6
×
587
    new_gs2_diagnostics_config_in%print_line = .false.
×
588
    new_gs2_diagnostics_config_in%write_correlation = .true.
×
589
    new_gs2_diagnostics_config_in%write_moments = .true.
×
590
  end subroutine apply_new_defaults
591

592
#include "diagnostics_auto_gen.inc"
593
end module diagnostics_configuration
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc