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

gyrokinetics / gs2 / 2021218321

04 Sep 2025 07:44AM UTC coverage: 10.606% (+0.03%) from 10.577%
2021218321

push

gitlab-ci

David Dickinson
Merged in feature/move_more_initialisation_to_init_levels (pull request #1161)

4710 of 44407 relevant lines covered (10.61%)

125698.1 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
    !> Try to create the restart directory if initial attempts to write there
61
    !> fail. This is supposed to help with the common mistake where a user
62
    !> has set [[init_g_knobs:restart_dir]] but has forgotten to create it.
63
    logical :: make_restart_dir = .true.
64
    !> Number of timesteps to average over for time-averaged diagnostics
65
    !>
66
    !> @warning Default value differs between old (100) and new (10)
67
    !> diagnostics
68
    integer :: navg = 10
69
    !> Sets the number of output steps between syncing the netcdf file.
70
    !> Higher values may reduce disk overheads but increase the risk of
71
    !> data loss on unclean exit.
72
    integer :: nc_sync_freq = 10
73
    !> Timestep period to write real space fields \(\phi, A_\parallel,
74
    !> B_\parallel\)
75
    !>
76
    !> @warning Non-functional in new diagnostics. Instead use
77
    !> [[gs2_diagnostics_knobs:nwrite]]
78
    !>
79
    !> @warning Default value differs between old (1000) and new (-1)
80
    !> diagnostics
81
    integer :: nmovie = -1
82
    !> Timestep period for writing restart data if
83
    !> [[gs2_diagnostics_knobs:save_for_restart]] is `.true.`. Negative values
84
    !> disable the periodic checkpoints.
85
    integer :: nsave = -1
86
    !> Timestep period for writing outputs
87
    !>
88
    !> @warning Default value differs between old (`== 100`) and new (`== 10`)
89
    !> diagnostics!
90
    integer :: nwrite = 10
91
    !> Timestep period multiplier for certain "large" diagnostics, which are
92
    !> written every `nwrite_mult * nwrite` timesteps.
93
    !>
94
    !> FIXME: What datasets? `phicorr_sum`, `phiextend_sum` in old diagnostics,
95
    !> `f` and `fyx` in new diagnostics?
96
    !>
97
    !> @warning Controls different diagnostics in new diagnostics
98
    integer :: nwrite_mult = 10
99
    !> If `.true.`, write moments at the outboard midplane only, as opposed to
100
    !> along the entire flux surface
101
    !>
102
    !> @warning Non-functional in new diagnostics
103
    !>
104
    !> @warning Default value differs between old (.true.) and new (.false.) diagnostics
105
    logical :: ob_midplane = .false.
106
    !> Only perform tests of omega behaviour (convergence etc.) once the simulation time
107
    !> is at least this value
108
    real :: omega_checks_start = 0.0
109
    !> Threshold complex frequency (\(\Omega\)) for detecting a numerical
110
    !> instability. If \(\abs(\Omega)\) averaged over
111
    !> [[gs2_diagnostics_knobs:navg]] timesteps is greater than `omegatinst`,
112
    !> abort the run.
113
    !>
114
    !> @warning Default value differs between old (1.0) and new (1.0e6)
115
    !> diagnostics
116
    real :: omegatinst = 1.0e6
117
    !> Frequency (\(\omega\)) convergence tolerance. Consider the simulation
118
    !> converged and finish the run if \(\omega\) has changed by less than
119
    !> `omegatol` over the last [[gs2_diagnostics_knobs:navg]] timesteps.
120
    !>
121
    !> More explicitly, the convergence criterion is:
122
    !>
123
    !> $$\sqrt{\sum_t^{n_{avg}} |\bar{\omega} - \omega|^2} < \min{\bar{\omega}, 1.0}\cdot\omega_{tol}$$
124
    !>
125
    !> where \(\bar{\omega}\) is \(\omega\) averaged over the last `navg`
126
    !> timesteps.
127
    real :: omegatol = 1e-3
128
    !> Print the instantaneous fluxes to screen/stdout every
129
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
130
    logical :: print_flux_line = .false.
131
    !> Print estimated frequencies and growth rates to screen/stdout every
132
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
133
    !>
134
    !> @warning Default value differs between old (`.true.`) and new
135
    !> (`.false.`) diagnostics
136
    logical :: print_line = .false.
137
    !> Write the distribution function to `<rootname>.nc.dfn.<processor>`
138
    !> files. Only written at end of simulation
139
    logical :: save_distfn = .false.
140
    !> Write restart files at the end of the simulation. If
141
    !> [[gs2_diagnostics_knobs:nsave]] is positive, then also enable
142
    !> checkpoints by writing restart files every `nsave` timesteps.
143
    logical :: save_for_restart = .false.
144
    !> Save some layout and distribution information in restart files
145
    logical :: save_glo_info_and_grids = .false.
146
    !> If `.true.`, write one restart file per processor, otherwise write a
147
    !> single restart file.
148
    !>
149
    !> If `gs2` has not been built with parallel netCDF, `save_many` is ignored
150
    !> and there is always one file per processor (equivalent to `save_many =
151
    !> .true.`).
152
    !>
153
    !> If `write_many` is enabled, you probably want to also set
154
    !> [[init_g_knobs:read_many]] in order to restart from multiple files.
155
    logical :: save_many = .false.
156
    !> Save parallel and perpendicular velocities in final restart and/or
157
    !> distribution function files
158
    logical :: save_velocities = .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 \(g(v_\parallel,v_\perp)\) at `ik=it=is=1, ig=0` to text file
330
    !> `<runname>.dist`
331
    !>
332
    !> @warning Only to text files
333
    logical :: write_g = .false.
334
    !> FIXME: Add documentation
335
    !>
336
    !> @warning Only outputs to text files
337
    logical :: write_gs = .false.
338
    !> Write \(g\) as a function of real space every
339
    !> [[gs2_diagnostics_knobs:nmovie]] timesteps to text file
340
    !> "<runname>.yxdist"
341
    !>
342
    !> @warning Only to text files
343
    logical :: write_gyx = .false.
344
    !> Write out various heating, free energy and energy injection
345
    !> diagnostics. Text file extension is `.heat`
346
    logical :: write_heating = .false.
347
    !> Write time averaged external current in the antenna,
348
    !> \(\operatorname{Re}(k_\perp^2 A_\mathrm{antenna})\), as a function of
349
    !> \(k_x, k_y\). File suffix is `.jext`
350
    !>
351
    !> @warning Only in new diagnostics
352
    logical :: write_jext = .false.
353
    !> Calculates and writes the electrostatic drive of zonal flows
354
    !> every [[gs2_diagnostics_knobs:nwrite]] timesteps.  The output
355
    !> `kinetic_energy_transfer_theta` resolves this over \(\theta\)
356
    !> only.  `kinetic_energy_transfer_theta_kxsource`,
357
    !> `kinetic_energy_transfer_theta_kxtarget`, and
358
    !> `kinetic_energy_transfer_theta_kysource` give additional
359
    !> insights by resolving over individual source or target scales.
360
    logical :: write_kinetic_energy_transfer = .false.
361
    !> Write the parallel spectrum of \(\phi, A_\parallel,
362
    !> B_\parallel\) at final timestep. File suffix is `.kpar`
363
    !>
364
    !> @warning Output only to text files
365
    logical :: write_kpar = .false.
366
    !> Print estimated frequencies and growth rates to text file every
367
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
368
    logical :: write_line = .true.
369
    !> Write `antenna_w` every [[gs2_diagnostics_knobs:nwrite]]
370
    !> timesteps
371
    !>
372
    !> FIXME: Define `antenna_w`
373
    !>
374
    !> @warning Old diagnostics only writes to text files
375
    !>
376
    !> @warning New diagnostics only writes to netCDF
377
    logical :: write_lorentzian = .false.
378
    !> Write the estimated maximum error from velocity space
379
    !> integrals for various quantities
380
    !>
381
    !> @warning Old diagnostics only outputs to text file
382
    logical :: write_max_verr = .false.
383
    !> Write various moments (total and non-adiabatic part of perturbed species
384
    !> density, perturbed parallel flow, perturbed parallel and perpendicular
385
    !> temperatures, parallel heat flux, particule flux and heat flux) every
386
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
387
    !>
388
    !> @warning Only outputs to netCDF files
389
    !>
390
    !> @warning New diagnostics writes various averages of the moments. To get
391
    !> the same output as old diagnostics, **also** set
392
    !> [[gs2_diagnostics_knobs:write_ntot_over_time]],
393
    !> [[gs2_diagnostics_knobs:write_density_over_time]],
394
    !> [[gs2_diagnostics_knobs:write_upar_over_time]],
395
    !> [[gs2_diagnostics_knobs:write_tperp_over_time]] to `.true.`
396
    !>
397
    !> @warning Default value differs between old (`.false.`) and new
398
    !> (`.true.`) diagnostics
399
    logical :: write_moments = .true.
400
    !> Write the poloidal distributions of the fluxes of particles,
401
    !> parallel momentum, perpendicular momentum, and energy every
402
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps.
403
    !>
404
    !> See section 3.1 and appendix A of [Ball et al. PPCF 58 (2016)
405
    !> 045023](https://doi.org/10.1088/0741-3335/58/4/045023) as well as
406
    !> section 5 of "GS2 analytic geometry specification"
407
    logical :: write_nl_flux_dist = .false.
408
    !> Write the whole total density moment every
409
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
410
    !>
411
    !> @warning Requires [[gs2_diagnostics_knobs:write_moments]] to also be
412
    !> `.true.`
413
    !>
414
    !> @warning Only in new diagnostics
415
    logical :: write_ntot_over_time = .false.
416
    !> Write time-averaged growth rate and frequency to the output text file
417
    !> every [[gs2_diagnostics_knobs:nwrite]] timesteps. Time average is
418
    !> rolling window over the previous [[gs2_diagnostics_knobs:navg]]
419
    !> timesteps
420
    !>
421
    !> @warning Non-functional in new diagnostics, time-average is also written
422
    !> with [[gs2_diagnostics_knobs:write_omega]] instead
423
    logical :: write_omavg = .true.
424
    !> Write instantaneous growth rate and frequency every
425
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
426
    !>
427
    !> @warning Old diagnostics only writes to output text file
428
    !>
429
    !> @warning New diagnostics only writes to netCDF file
430
    !>
431
    !> @warning New diagnostics also writes time-average with this
432
    !> option. Output is the complex frequency, rather than separate growth
433
    !> rate and real frequency
434
    logical :: write_omega = .true.
435
    !> Write parities in distribution and particle fluxes to text file with the
436
    !> suffix `.parity`
437
    !>
438
    !> FIXME: Clarify what this means
439
    logical :: write_parity = .false.
440
    !> Write the entire \(\phi\) field every [[gs2_diagnostics_knobs:nwrite]]
441
    !> timesteps
442
    !>
443
    !> @warning New diagnostics requires
444
    !> [[gs2_diagnostics_knobs:write_fields]] to also be `.true.`
445
    !> (the default) to enable this
446
    logical :: write_phi_over_time = .false.
447
    !> Write a simple quasi-linear metric to netcdf.
448
    logical :: write_ql_metric = .true.
449
    !> Write the particle and momentum flux as a function of \(\theta\) and
450
    !> velocity space. See [[gs2_diagnostics_knobs:write_pflux_sym]] and
451
    !> [[gs2_diagnostics_knobs:write_pflux_tormom]]
452
    !>
453
    !> @warning Only outputs to netCDF
454
    !>
455
    !> @warning Old diagnostics does not write the particle flux, use
456
    !> [[gs2_diagnostics_knobs:write_pflux_sym]] instead
457
    logical :: write_symmetry = .false.
458
    !> Write the whole perturbed perpendicular temperature moment every
459
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
460
    !>
461
    !> @warning Requires [[gs2_diagnostics_knobs:write_moments]] to also be
462
    !> `.true.`
463
    !>
464
    !> @warning Only in new diagnostics
465
    logical :: write_tperp_over_time = .false.
466
    !> Write the whole perturbed parallel velocity moment every
467
    !> [[gs2_diagnostics_knobs:nwrite]] timesteps
468
    !>
469
    !> @warning Requires [[gs2_diagnostics_knobs:write_moments]] to also be
470
    !> `.true.`
471
    !>
472
    !> @warning Only in new diagnostics
473
    logical :: write_upar_over_time = .false.
474
    !> Write estimates of error resulting from velocity space integrals in the
475
    !> calculation of various quantities every [[gs2_diagnostics_knobs:nwrite]]
476
    !> timesteps.
477
    !>
478
    !> @warning Output only to text file
479
    !>
480
    !> @warning New diagnostics also writes to netCDF every
481
    !> [[collisions_knobs:ncheck]] timesteps, along with some other
482
    !> quantities such as collisionality
483
    !>
484
    !> @warning This is expensive
485
    logical :: write_verr = .false.
486
    !> Write the transfer of free energy, \(\tau\), as a function of \((k_x,
487
    !> k_y)\), averaged over \(\theta\), every [[gs2_diagnostics_knobs:nwrite]]
488
    !> timesteps
489
    !>
490
    !> @warning Only in new diagnostics
491
    logical :: write_zonal_transfer = .false.
492
#include "diagnostics_overrides_and_bound_auto_gen.inc"
493
    procedure :: set_smart_defaults => set_smart_defaults_local
494
  end type diagnostics_config_type
495

496
  type(diagnostics_config_type) :: diagnostics_config
497
contains
498

499
  !> Prints a warning about a non-functional diagnostic
500
  subroutine warn_about_nonfunctional_selection(diagnostic_switch, name)
×
501
    use run_parameters, only: use_old_diagnostics
502
    use mp, only: proc0
503
    !> Diagnostic switch
504
    logical, intent(in) :: diagnostic_switch
505
    !> Name of the switch
506
    character(len=*), intent(in) :: name
507

508
    character(len=3) :: diagnostics_module
509

510
    if (use_old_diagnostics) then
×
511
      diagnostics_module = "old"
×
512
    else
513
      diagnostics_module = "new"
×
514
    end if
515

516
    if (diagnostic_switch .and. proc0) then
×
517
      write(*, '(a, a, a, a, a)') "WARNING: diagnostic '", name, &
×
518
           "' is (currently) non-functional in ", diagnostics_module, &
×
519
           " diagnostics module. This will have no effect."
×
520
    end if
521
  end subroutine warn_about_nonfunctional_selection
×
522

523
  !> Set the smart defaults for the new_gs2_diagnostics_config_type instance
524
  subroutine set_smart_defaults_local(self)
×
525
    use nonlinear_terms, only: nonlin
526
    use run_parameters, only: use_old_diagnostics
527
    implicit none
528
    class(diagnostics_config_type), intent(in out) :: self
529
    if (self%is_initialised()) return
×
530
    if(nonlin) then
×
531
       if (.not. self%override_write_fluxes) self%write_fluxes = .true.
×
532
       if (.not. self%override_write_fluxes_by_mode) self%write_fluxes_by_mode = .true.
×
533
    end if
534

535
    if (use_old_diagnostics) then
×
536
       call apply_old_defaults(self)
×
537
    else
538
       call apply_new_defaults(self)
×
539
    end if
540
  end subroutine set_smart_defaults_local
541

542
  !> Set values according to the old diagnostics defaults.
543
  !>
544
  !> Will overwrite existing values, unless the config object has
545
  !> already been initialised, in which case returns without changing
546
  !> any values
547
  subroutine apply_old_defaults(self)
×
548
    type(diagnostics_config_type), intent(inout) :: self
549

550
    if (self%is_initialised()) return
×
551

552
    if (.not. self%override_navg) self%navg = 100
×
553
    if (.not. self%override_nmovie) self%nmovie = 1000
×
554
    if (.not. self%override_nwrite) self%nwrite = 100
×
555
    if (.not. self%override_ob_midplane)self%ob_midplane = .true.
×
556
    if (.not. self%override_omegatinst) self%omegatinst = 1.0
×
557
    if (.not. self%override_print_line) self%print_line = .true.
×
558
    if (.not. self%override_write_correlation) self%write_correlation = .false.
×
559
    if (.not. self%override_write_moments) self%write_moments = .false.
×
560
  end subroutine apply_old_defaults
561

562
  !> Set values according to the new diagnostics defaults.
563
  !>
564
  !> Will overwrite existing values, unless the config object has
565
  !> already been initialised, in which case returns without changing
566
  !> any values
567
  subroutine apply_new_defaults(self)
×
568
    type(diagnostics_config_type), intent(in out) :: self
569

570
    if (self%is_initialised()) return
×
571

572
    if (.not. self%override_navg) self%navg = 10
×
573
    if (.not. self%override_nmovie) self%nmovie = -1
×
574
    if (.not. self%override_nwrite) self%nwrite = 10
×
575
    if (.not. self%override_ob_midplane)self%ob_midplane = .false.
×
576
    if (.not. self%override_omegatinst) self%omegatinst = 1.0e6
×
577
    if (.not. self%override_print_line) self%print_line = .false.
×
578
    if (.not. self%override_write_correlation) self%write_correlation = .true.
×
579
    if (.not. self%override_write_moments) self%write_moments = .true.
×
580
  end subroutine apply_new_defaults
581

582
#include "diagnostics_auto_gen.inc"
583
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