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

gyrokinetics / gs2 / 1998640042

22 Aug 2025 01:50PM UTC coverage: 10.577% (-0.1%) from 10.718%
1998640042

push

gitlab-ci

David Dickinson
Merged in feature/dont_reset_configs_when_finishing_modules (pull request #1160)

4700 of 44434 relevant lines covered (10.58%)

125622.86 hits per line

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

0.0
/src/hyper.f90
1
!> FIXME : Add documentation
2
!!
3
!! @note nexp has been changed in a rush.  Only known to be correct for nexp=2
4
module hyper
5
  use abstract_config, only: abstract_config_type, CONFIG_MAX_NAME_LEN
6
  implicit none
7

8
  private
9

10
  public :: init_hyper, finish_hyper, hyper_diff, D_res, D_v, D_eta, nexp
11
  public :: read_parameters, wnml_hyper, check_hyper, hypervisc_filter
12

13
  public :: hyper_config_type, set_hyper_config, get_hyper_config
14

15
  ! D_v, D_eta are hyper coefficients, normalized correctly
16
  ! i.e., either by unity or by 1/k_perp**2*nexp
17
  real :: D_v, D_eta, D_hypervisc, D_hyperres, omega_osc, D_hyper
18
  real :: akx4_max, aky4_max, aky_max, akperp4_max
19

20
  integer :: hyper_option_switch, nexp
21
  integer, parameter :: hyper_option_none = 1, &
22
       hyper_option_visc = 2, &
23
       hyper_option_res  = 3, &
24
       hyper_option_both = 4, &
25
       hyper_option_simple3D = 5
26

27
  character(9) :: hyper_option
28
  logical :: const_amp, isotropic_shear, damp_zonal_only, gridnorm
29

30
  real, dimension (:, :), allocatable :: D_res
31
  real, dimension (:, :, :), allocatable :: hypervisc_filter
32

33
  ! Coefficients for simple3D hyperviscous model
34
  ! the maximum k_perp ^ 2 including geometric coefficients for non-zonal and zonal modes
35
  real :: kperp2_max, kperp2_max_zonal
36
  ! Hyperviscous coefficient, hyperviscous power, ky cut-off, kx cut-off
37
  real :: D_hyper3D, P_hyper3D, ky_cut, kx_cut
38
  ! Controls if zonal modes are treated identically to non-zonal modes
39
  logical :: isotropic_model
40
  logical :: initialized = .false., hyper_on = .false.
41

42
  !> Used to represent the input configuration of hyper
43
  type, extends(abstract_config_type) :: hyper_config_type
44
     ! namelist : hyper_knobs
45
     ! indexed : false
46
     !> Determines whether hyperviscosity includes time dependent amplitude
47
     !> factor when calculating damping rate. Recommend `true` for
48
     !> linear runs and `false` for nolinear runs, since amplutide of
49
     !> turbulence grows linearly with time in linear run.
50
     logical :: const_amp = .false.
51
     !> If `hyper_option = 'both'` is used then this sets both the
52
     !> hyperresistivity and hyperviscosity damping coefficients. Can
53
     !> override the individual coefficients with
54
     !> [[hyper_knobs:D_hyperres]] and [[hyper_knobs:D_hypervisc]].
55
     real :: d_hyper = -10.0
56
     !> Used with the simple3D hyperviscosity model of the form
57
     !> D_hyper3D * (|kperp|/ max |kperp|)^P_hyper3D
58
     !> and ky_cut, kx_cut set max |kperp|
59
     real :: d_hyper3d = -10.
60
     !> Sets hyperresistivity parameter multiplying damping term.
61
     real :: d_hyperres = -10.0
62
     !> Sets hyperviscosity parameter multiplying damping term. See
63
     !> [E. Belli (2006)
64
     !> thesis](https://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=50BFD54A8F8D72FC225D025FDEDFFFA5?doi=10.1.1.706.9568&rep=rep1&type=pdf)
65
     !> for more information.
66
     real :: d_hypervisc = -10.0
67
     !> If `true` then hyperdissipation only applied to the zonal
68
     !> mode.
69
     logical :: damp_zonal_only = .false.
70
     !> If `true` (default) then set wavenumber parameters entering
71
     !> the models based on the maximum `ky` and `kx` included in the
72
     !> current simulation. If `false` then these values are set to 1.
73
     logical :: gridnorm = .true.
74
     !> Selects the type of hyper terms included. Should be one of
75
     !>
76
     !> - 'default' -- no hyper terms included.
77
     !> - 'none' -- the same as default.
78
     !> - 'visc_only' -- only hyperviscosity included.
79
     !> - 'res_only' -- only hyperresistivity included.
80
     !> - 'both' -- both viscosity and resistivity included.
81
     !> - 'simple3D' -- simple hyperviscous dissipation rate of the
82
     !>    form D_hyper3D * (|kperp|/ max |kperp|)^P_hyper3D
83
     !>    described in [���Multiscale turbulence in magnetic
84
     !>    confinement fusion devices���, M. Hardman, DPhil Thesis,
85
     !>    appendix
86
     !>    B.4](https://ora.ox.ac.uk/objects/uuid:233a22cb-3c8b-4fe0-a689-4a37d8fe0314)
87
     !>    note that the dissipation in this version is applied to g, not h, as
88
     !>    in the reference.
89
     character(len = 9) :: hyper_option = 'default'
90
     !> if true damp zonal and drift waves with same dissipation formula
91
     logical :: isotropic_model = .true.
92
     !> If `true` then use isotropic shear model.
93
     logical :: isotropic_shear = .true.
94
     !> Used with the simple3D hyperviscosity model of the form
95
     !> D_hyper3D * (|kperp|/ max |kperp|)^P_hyper3D
96
     !> and ky_cut, kx_cut set max |kperp|
97
     real :: kx_cut = -10.
98
     !> Used with the simple3D hyperviscosity model of the form
99
     !> D_hyper3D * (|kperp|/ max |kperp|)^P_hyper3D
100
     !> and ky_cut, kx_cut set max |kperp|
101
     real :: ky_cut = -10.
102
     !> Sets the power to which \(k_\bot^2\) is raised in the dissipation filter.
103
     integer :: nexp = 2
104
     !> Sets a parameter in the anisotropic shearing rate calculation.
105
     real :: omega_osc = 0.4
106
     !> Used with the simple3D hyperviscosity model of the form
107
     !> D_hyper3D * (|kperp|/ max |kperp|)^P_hyper3D
108
     !> and ky_cut, kx_cut set max |kperp|
109
     real :: p_hyper3d = 4.
110
#include "hyper_overrides_and_bound_auto_gen.inc"
111
  end type hyper_config_type
112

113
  type(hyper_config_type) :: hyper_config
114

115
contains
116

117
  !> FIXME : Add documentation
118
  subroutine check_hyper(report_unit)
×
119
    implicit none
120
    integer, intent(in) :: report_unit
121
    select case (hyper_option_switch)
×
122
    case (hyper_option_none)
123
       if (D_hyperres > 0.) then
×
124
          write (report_unit, *)
×
125
          write (report_unit, fmt="('################# WARNING #######################')")
×
126
          write (report_unit, fmt="('hyper_option = ',a,' chooses no hyperresistivity.  &
127
               &D_hyperres ignored.')") trim(hyper_option)
×
128
          write (report_unit, fmt="('################# WARNING #######################')")
×
129
          write (report_unit, *)
×
130
          D_hyperres = -10.
×
131
       end if
132
       if (D_hypervisc > 0.) then
×
133
          write (report_unit, *)
×
134
          write (report_unit, fmt="('################# WARNING #######################')")
×
135
          write (report_unit, fmt="('hyper_option = ',a,' chooses no hyperviscosity.  &
136
               &D_hypervisc ignored.')") trim(hyper_option)
×
137
          write (report_unit, fmt="('################# WARNING #######################')")
×
138
          write (report_unit, *)
×
139
          D_hypervisc = -10.
×
140
       endif
141

142
    case (hyper_option_visc)
143
       hyper_on = .true.
×
144
       if (D_hyperres > 0.) then
×
145
          write (report_unit, *)
×
146
          write (report_unit, fmt="('################# WARNING #######################')")
×
147
          write (report_unit, fmt="('hyper_option = ',a,' chooses no hyperresistivity.  &
148
               &D_hyperres ignored.')") trim(hyper_option)
×
149
          write (report_unit, fmt="('################# WARNING #######################')")
×
150
          write (report_unit, *)
×
151
          D_hyperres = -10.
×
152
       end if
153
       if (D_hypervisc < 0.) then
×
154
          write (report_unit, *)
×
155
          write (report_unit, fmt="('################# WARNING #######################')")
×
156
          write (report_unit, fmt="('hyper_option = ',a,' chooses hyperviscosity but &
157
               &D_hypervisc < 0.')") trim(hyper_option)
×
158
          write (report_unit, fmt="('No hyperviscosity used.')")
×
159
          write (report_unit, fmt="('################# WARNING #######################')")
×
160
          write (report_unit, *)
×
161
          hyper_on = .false.
×
162
       endif
163

164
    case (hyper_option_res)
165
       hyper_on = .true.
×
166
       if (D_hyperres < 0.) then
×
167
          write (report_unit, *)
×
168
          write (report_unit, fmt="('################# WARNING #######################')")
×
169
          write (report_unit, fmt="('hyper_option = ',a,' chooses hyperresistivity but D_hyperres < 0.')") trim(hyper_option)
×
170
          write(report_unit, fmt="('No hyperresistivity used.')")
×
171
          write (report_unit, fmt="('################# WARNING #######################')")
×
172
          write (report_unit, *)
×
173
          hyper_on = .false.
×
174
       end if
175
       if (D_hypervisc > 0.) then
×
176
          write (report_unit, *)
×
177
          write (report_unit, fmt="('################# WARNING #######################')")
×
178
          write (report_unit, fmt="('hyper_option = ',a,' chooses no hyperviscosity.  D_hypervisc ignored.')") trim(hyper_option)
×
179
          write (report_unit, fmt="('################# WARNING #######################')")
×
180
          write (report_unit, *)
×
181
          D_hypervisc = -10.
×
182
       endif
183

184
    case (hyper_option_both)
185
       hyper_on = .true.
×
186
       if (D_hyperres < 0.) then
×
187
          write (report_unit, *)
×
188
          write (report_unit, fmt="('################# WARNING #######################')")
×
189
          write (report_unit, fmt="('hyper_option = ',a,' chooses hyperresistivity but D_hyperres < 0.')") trim(hyper_option)
×
190
          write (report_unit, fmt="('No hyperresistivity used.')")
×
191
          write (report_unit, fmt="('################# WARNING #######################')")
×
192
          write (report_unit, *)
×
193
       end if
194
       if (D_hypervisc < 0.) then
×
195
          write (report_unit, *)
×
196
          write (report_unit, fmt="('################# WARNING #######################')")
×
197
          write (report_unit, fmt="('hyper_option = ',a,' chooses hyperviscosity but D_hypervisc < 0.')") trim(hyper_option)
×
198
          write (report_unit, fmt="('No hyperviscosity used.')")
×
199
          write (report_unit, fmt="('################# WARNING #######################')")
×
200
          write (report_unit, *)
×
201
       endif
202
       if (D_hypervisc < 0. .and. D_hyperres < 0.) hyper_on = .false.
×
203

204
    end select
205

206
    if (hyper_on) then
×
207
       write (report_unit, *)
×
208
       write (report_unit, fmt="('------------------------------------------------------------')")
×
209
       write (report_unit, *)
×
210

211
       select case (hyper_option_switch)
×
212

213
       case (hyper_option_visc)
214

215
          write (report_unit, *)
×
216
          write (report_unit, fmt="('Hyperviscosity included without hyperresistivity.')")
×
217
          if (const_amp) then
×
218
             write (report_unit, fmt="('Damping rate is ',e11.4,' at highest k_perp.')") D_hypervisc
×
219
          else
220
             write (report_unit, fmt="('The damping coefficent is ',e11.4)") D_hypervisc
×
221
             write (report_unit, fmt="('The damping rate is proportional to the RMS amplitude of the turbulence.')")
×
222
          end if
223
          if (isotropic_shear) then
×
224
             write (report_unit, fmt="('The hyperviscosity is isotropic in the perpendicular plane.')")
×
225
             write (report_unit, fmt="('This is appropriate for MHD-like calculations.')")
×
226
          else
227
             write (report_unit, fmt="('The hyperviscosity is anisotropic in the perpendicular plane.')")
×
228
             write (report_unit, fmt="('This is appropriate for drift-type calculations.')")
×
229
             write (report_unit, fmt="('omega_osc = ',e11.4)") omega_osc
×
230
          end if
231

232
       case (hyper_option_res)
233

234
          write (report_unit, *)
×
235
          write (report_unit, fmt="('Hyperresistivity included without hyperviscosity.')")
×
236
          if (const_amp) then
×
237
             write (report_unit, fmt="('Damping rate is ',e11.4,' at highest k_perp.')") D_hyperres
×
238
          else
239
             write (report_unit, fmt="('################# WARNING #######################')")
×
240
             write (report_unit, fmt="('const_amp = .false. is not implemented for hyperresistivity.')")
×
241
             write (report_unit, fmt="('################# WARNING #######################')")
×
242
             write (report_unit, *)
×
243
          end if
244
          if (isotropic_shear) then
×
245
             write (report_unit, fmt="('The hyperresistivity is isotropic in the perpendicular plane.')")
×
246
             write (report_unit, fmt="('This is appropriate for MHD-like calculations.')")
×
247
          else
248
             write (report_unit, fmt="('################# WARNING #######################')")
×
249
             write (report_unit, fmt="('isotropic_shear = .false. is not implemented for hyperresistivity.')")
×
250
             write (report_unit, fmt="('################# WARNING #######################')")
×
251
             write (report_unit, *)
×
252
          end if
253

254
       case (hyper_option_both)
255

256
          write (report_unit, *)
×
257
          write (report_unit, fmt="('Hyperresistivity and hyperviscosity included.')")
×
258
          if (const_amp) then
×
259
             write (report_unit, fmt="('Damping rate is ',e11.4,' at highest k_perp.')") D_hyperres
×
260
          else
261
             write (report_unit, fmt="('################# WARNING #######################')")
×
262
             write (report_unit, fmt="('const_amp = .false. is not implemented for hyperresistivity.')")
×
263
             write (report_unit, fmt="('THIS IS AN ERROR.')")
×
264
             write (report_unit, fmt="('################# WARNING #######################')")
×
265
             write (report_unit, *)
×
266
          end if
267
          if (isotropic_shear) then
×
268
             write (report_unit, fmt="('The damping is isotropic in the perpendicular plane.')")
×
269
             write (report_unit, fmt="('This is appropriate for MHD-like calculations.')")
×
270
          else
271
             write (report_unit, fmt="('################# WARNING #######################')")
×
272
             write (report_unit, fmt="('isotropic_shear = .false. is not implemented for hyperresistivity.')")
×
273
             write (report_unit, fmt="('THIS IS AN ERROR.')")
×
274
             write (report_unit, fmt="('################# WARNING #######################')")
×
275
             write (report_unit, *)
×
276
          end if
277
       end select
278
    end if
279
  end subroutine check_hyper
×
280

281
  !> FIXME : Add documentation
282
  subroutine wnml_hyper(unit)
×
283
    implicit none
284
    integer, intent(in) :: unit
285
    if (.not. hyper_on) return
×
286
    call hyper_config%write(unit)
×
287
  end subroutine wnml_hyper
288

289
  !> FIXME : Add documentation
290
  subroutine init_hyper(hyper_config_in)
×
291
    use kt_grids, only: ntheta0, naky, akx, aky, kperp2
292
    use theta_grid, only: gds2, gds21, gds22, shat
293
    use gs2_time, only: code_dt
294
    use warning_helpers, only: is_zero
295
    implicit none
296
    type(hyper_config_type), intent(in), optional :: hyper_config_in
297
    integer :: ik, it
298

299
    if (initialized) return
×
300
    initialized = .true.
×
301
    call read_parameters(hyper_config_in)
×
302
    call allocate_arrays
×
303

304
    select case (hyper_option_switch)
×
305
    case(hyper_option_both, hyper_option_res, hyper_option_visc)
306
       ! Define variables used in hyperviscosity and hyperresistivity models
307
       if (gridnorm) then
×
308
          akx4_max = akx(ntheta0 / 2 + 1)**(2 * nexp)
×
309
          aky_max = aky(naky)
×
310
          aky4_max = aky(naky)**(2 * nexp)
×
311
          akperp4_max = (akx(ntheta0 / 2 + 1)**2  +  aky(naky)**2)**nexp
×
312
       else
313
          akx4_max = 1.
×
314
          aky_max = 1.
×
315
          aky4_max = 1.
×
316
          akperp4_max = 1.
×
317
       end if
318

319
       ! Get D_res set up if needed
320
       if (D_hyperres > 0.) then
×
321
          do ik = 1, naky
×
322
             do it = 1, ntheta0
×
323
                D_res(it, ik) = D_hyperres*code_dt * (aky(ik)**2 + akx(it)**2)**nexp &
×
324
                     / akperp4_max
×
325
             end do
326
          end do
327
          D_eta = D_hyperres / akperp4_max
×
328
       end if
329

330
       if (D_hypervisc > 0.) D_v = D_hypervisc / akperp4_max
×
331

332
    case(hyper_option_simple3D)
333
       ! Make the default cut-offs the grid scale
334
       if (ky_cut <= 0.) ky_cut = aky(naky)
×
335
       if (kx_cut <= 0.) kx_cut = akx((ntheta0+1)/2)
×
336

337
       ! Here we're evaluating kperp2 for the specified ky, kx value
338
       if (is_zero(shat)) then
×
339
          kperp2_max = ky_cut*ky_cut + kx_cut*kx_cut
×
340
       else
341
          kperp2_max = maxval(ky_cut * ky_cut * gds2 + &
×
342
               2.0 * ky_cut * kx_cut * gds21 / shat + &
×
343
               kx_cut * kx_cut * gds22 / (shat * shat))
×
344
       end if
345

346
       if (isotropic_model .or. is_zero(shat)) then
×
347
          kperp2_max_zonal = kperp2_max
×
348
       else
349
          kperp2_max_zonal = maxval(kx_cut * kx_cut * gds22 / (shat * shat))
×
350
       end if
351

352
       ! Calculate the filter
353
       ik =1  ! Zonal modes
×
354
       do it = 1, ntheta0
×
355
          hypervisc_filter(:, it, ik) = exp(- ( D_hyper3D * code_dt &
×
356
               * ( kperp2(:, it, ik) / kperp2_max_zonal)**(P_hyper3D / 2)))
×
357
       end do
358

359
       do ik = 2, naky ! Non-zonal modes
×
360
          do it = 1, ntheta0
×
361
             hypervisc_filter(:, it, ik) = exp(- ( D_hyper3D * code_dt &
×
362
                  * ( kperp2(:, it, ik) / kperp2_max )**(P_hyper3D / 2)) )
×
363
          end do
364
       end do
365
    end select
366
  end subroutine init_hyper
367

368
  !> FIXME : Add documentation
369
  subroutine read_parameters(hyper_config_in)
×
370
    use file_utils, only: error_unit
371
    use text_options, only: text_option, get_option_value
372
    use mp, only: proc0
373
    use warning_helpers, only: not_exactly_equal
374
    implicit none
375
    type(hyper_config_type), intent(in), optional :: hyper_config_in
376
    type (text_option), dimension(6), parameter :: hyperopts = &
377
         (/ text_option('default', hyper_option_none), &
378
            text_option('none', hyper_option_none), &
379
            text_option('visc_only', hyper_option_visc), &
380
            text_option('res_only', hyper_option_res), &
381
            text_option('both', hyper_option_both), &
382
            text_option('simple3D', hyper_option_simple3D) /)
383
    integer :: ierr
384

385
    if (present(hyper_config_in)) hyper_config = hyper_config_in
×
386

387
    call hyper_config%init(name = 'hyper_knobs', requires_index = .false.)
×
388

389
    ! Copy out internal values into module level parameters
390
    associate(self => hyper_config)
391
#include "hyper_copy_out_auto_gen.inc"
392
    end associate
393

394
    ierr = error_unit()
×
395

396
    call get_option_value &
397
         (hyper_option, hyperopts, hyper_option_switch, &
398
         ierr, "hyper_option in hyper_knobs",.true.)
×
399

400
    if (.not. isotropic_shear .and. nexp /= 2) then
×
401
       if (proc0) write (ierr, *) 'Forcing nexp = 2.  Higher values not implemented for anisotropic shear model.'
×
402
       nexp = 2
×
403
    end if
404

405

406
    select case (hyper_option_switch)
×
407
    case (hyper_option_none)
408
       if (D_hyperres > 0.) then
×
409
          if (proc0) write(ierr, *) 'hyper_option = ',hyper_option, &
×
410
               ' chooses no hyperresistivity.  D_hyperres ignored.'
×
411
          D_hyperres = -10.
×
412
       end if
413
       if (D_hypervisc > 0.) then
×
414
          if (proc0) write(ierr, *) 'hyper_option = ',hyper_option, &
×
415
               ' chooses no hyperviscosity.  D_hypervisc ignored.'
×
416
          D_hypervisc = -10.
×
417
       endif
418

419
    case (hyper_option_visc)
420
       hyper_on = .true.
×
421
       if (proc0) write (ierr, *) 'WARNING: It is inconsistent to set D_hypervisc different from ', &
×
422
            'D_hyperres.  Recommend: Set them equal.'
×
423
       if (D_hyperres > 0.) then
×
424
          if (proc0) write(ierr, *) 'hyper_option = ',hyper_option, &
×
425
               ' chooses no hyperresistivity.  D_hyperres ignored.'
×
426
          D_hyperres = -10.
×
427
       end if
428
       if (D_hypervisc < 0.) then
×
429
          if (proc0) then
×
430
             write(ierr, *) 'hyper_option = ',hyper_option, &
×
431
                  ' chooses hyperviscosity but D_hypervisc < 0 is illegal.'
×
432
             write(ierr, *) 'No hyperviscosity used.'
×
433
          end if
434
          hyper_on = .false.
×
435
       endif
436

437
    case (hyper_option_res)
438
       hyper_on = .true.
×
439
       if (proc0) write (ierr, *) 'WARNING: It is inconsistent to set D_hypervisc different from ', &
×
440
            'D_hyperres.  Recommend: Set them equal.'
×
441
       if (D_hyperres < 0.) then
×
442
          if (proc0) then
×
443
             write(ierr, *) 'hyper_option = ',hyper_option, &
×
444
                  ' chooses hyperresistivity but  D_hyperres < 0 is illegal.'
×
445
             write(ierr, *) 'No hyperresistivity used.'
×
446
          end if
447
          hyper_on = .false.
×
448
       end if
449
       if (D_hypervisc > 0.) then
×
450
          if (proc0) write(ierr, *) 'hyper_option = ',hyper_option, &
×
451
               ' chooses no hyperviscosity.  D_hypervisc ignored.'
×
452
          D_hypervisc = -10.
×
453
       endif
454

455
    case (hyper_option_both)
456
       hyper_on = .true.
×
457

458
       if (D_hyper < 0.) then
×
459
          if (not_exactly_equal(D_hyperres, D_hypervisc)) then
×
460
             if (proc0) write (ierr, *) 'WARNING: It is inconsistent to set D_hypervisc different from ', &
×
461
                  'D_hyperres.  Recommend: Set them equal.'
×
462
          end if
463
       else
464
          if (proc0) write (ierr, *) 'WARNING: Setting D_hypervisc = D_hyperres, each to value of D_hyper'
×
465
          D_hyperres  = D_hyper
×
466
          D_hypervisc = D_hyper
×
467
       end if
468

469
       if (D_hyperres < 0.) then
×
470
          if (proc0) then
×
471
             write(ierr, *) 'hyper_option = ',hyper_option, &
×
472
                  ' chooses hyperresistivity but  D_hyperres < 0 is illegal.'
×
473
             write(ierr, *) 'No hyperresistivity used.'
×
474
          end if
475
       end if
476
       if (D_hypervisc < 0.) then
×
477
          if (proc0) then
×
478
             write(ierr, *) 'hyper_option = ',hyper_option, &
×
479
                  ' chooses hyperviscosity but D_hypervisc < 0 is illegal.'
×
480
             write(ierr, *) 'No hyperviscosity used.'
×
481
          end if
482
       endif
483
       if (D_hypervisc < 0. .and. D_hyperres < 0.) hyper_on = .false.
×
484

485
    case (hyper_option_simple3D) ! MRH
486
       hyper_on = .true.
×
487

488
       if (P_hyper3D < 4.) then
×
489
          hyper_on = .false.
×
490
          if(proc0) write(ierr, *) 'hyper_option = ',hyper_option, &
×
491
               ' chooses a simple hyperviscous filter but  P_hyper3D < 4. is illegal.'
×
492
          if(proc0) write(ierr, *) 'No hyperviscosity used.'
×
493
       endif
494

495
       if (D_hyper3D < 0.) then
×
496
          hyper_on = .false.
×
497
          if(proc0) write(ierr, *) 'hyper_option = ',hyper_option, &
×
498
               ' chooses a simple hyperviscous filter but  D_hyper3D < 0 is illegal.'
×
499
          if(proc0) write(ierr, *) 'No hyperviscosity used.'
×
500
       endif
501
    end select
502
  end subroutine read_parameters
×
503

504
  !> FIXME : Add documentation
505
  subroutine allocate_arrays
×
506
    use theta_grid, only: ntgrid
507
    use kt_grids, only: ntheta0, naky
508
    implicit none
509

510
    if (.not. allocated(D_res)) allocate(D_res(ntheta0, naky))
×
511
    if (.not. allocated(hypervisc_filter)) &
×
512
         allocate(hypervisc_filter(-ntgrid:ntgrid,ntheta0,naky))
×
513

514
    ! Initialise module level variables
515
    D_v = 0 ;  D_eta = 0 ; D_res = 0
×
516
    akx4_max = 0 ; aky_max = 0 ; aky4_max = 0 ; akperp4_max = 0
×
517
    kperp2_max = 0 ; kperp2_max_zonal = 0 ; hypervisc_filter = 1
×
518
  end subroutine allocate_arrays
×
519

520
  !> FIXME : Add documentation
521
  subroutine hyper_diff (g0, phi)
×
522
    use gs2_layouts, only: g_lo, ik_idx, it_idx, is_idx
523
    use theta_grid, only: ntgrid
524
    use gs2_time, only: code_dt
525
    use kt_grids, only: aky, akx, naky, ntheta0
526
    implicit none
527
    complex, dimension (-ntgrid:,:,g_lo%llim_proc:), intent (in out) :: g0
528
    complex, dimension (-ntgrid:,:,:), intent (in) :: phi
529
    real, dimension (-ntgrid:ntgrid) :: shear_rate_nz, shear_rate_z, shear_rate_z_nz
×
530
    integer :: iglo, ik, it
531

532
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
533
!
534
! Includes models by Belli and Hammett
535
! to calculate the x-y avged shearing rate
536
! S(theta)^2 = <|grad_perp|^4 |phi|^2>
537
!            =  sum_over_k(kperp^4 * |phi|^2)
538
!               (times crazy fac factor due to FFT conventions.)
539
!
540
! and to implement this anisotropically in k_perp, taking into
541
! account properties of zonal flows.
542
!
543
! Begun December 2001
544
!
545
! Number conservation added April 2006
546
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
547

548
    if (.not. hyper_on) return
×
549

550
    ! Calculate hypervisc filter for non-simple3D model
551
    select case (hyper_option_switch)
×
552
    case(hyper_option_both, hyper_option_res, hyper_option_visc)
553
       if (D_hypervisc < 0.) return
×
554

555
       if(isotropic_shear) then
×
556
          call iso_shear
×
557
       else
558
          call aniso_shear
×
559
       end if
560
    end select
561

562
    ! Apply hypervisc filter
563
    !$OMP PARALLEL DO DEFAULT(none) &
564
    !$OMP PRIVATE(iglo, ik, it) &
565
    !$OMP SHARED(g_lo, damp_zonal_only, g0, hypervisc_filter) &
566
    !$OMP SCHEDULE(static)
567
    do iglo = g_lo%llim_proc, g_lo%ulim_alloc
×
568
       ik = ik_idx(g_lo, iglo)
×
569
       it = it_idx(g_lo, iglo)
×
570
       if (damp_zonal_only .and. ik /= 1) cycle
×
571
       g0(:, 1, iglo) = g0(:, 1, iglo) * hypervisc_filter(:, it, ik)
×
572
       g0(:, 2, iglo) = g0(:, 2, iglo) * hypervisc_filter(:, it, ik)
×
573
    end do
574
    !$OMP END PARALLEL DO
575
  contains
576

577
    !> FIXME : Add documentation
578
    subroutine aniso_shear
×
579
      real, dimension(naky) :: fac
×
580
      ! Do the Belli-Hammett anisotropic calculation
581
      ! which accounts for some zonal/non-zonal differences
582
      fac = 0.5
×
583
      fac(1) = 1.0
×
584

585
      ! shearing rate due to non-zonal modes (on nonzonal modes)
586
      shear_rate_nz = 0.
×
587
      ! shearing rate due to zonal modes (on nonzonal modes)
588
      shear_rate_z = 0
×
589
      ! shearing rate due to nonzonal modes (on zonal modes)
590
      shear_rate_z_nz = 0.
×
591

592
      ik = 1
×
593
      !$OMP PARALLEL DO DEFAULT(none) &
594
      !$OMP PRIVATE(it) &
595
      !$OMP SHARED(ik, ntheta0, phi, akx, aky, fac) &
596
      !$OMP REDUCTION(+: shear_rate_z) &
597
      !$OMP SCHEDULE(static)
598
      do it = 1, ntheta0
×
599
         shear_rate_z = shear_rate_z + real(conjg(phi(:, it, ik)) &
×
600
              * phi(:, it, ik)) * (akx(it)**2 + aky(ik)**2)**2 * fac(ik)
×
601
      end do
602
      !$OMP END PARALLEL DO
603

604
      !$OMP PARALLEL DO DEFAULT(none) &
605
      !$OMP PRIVATE(ik, it) &
606
      !$OMP SHARED(naky, ntheta0, phi, akx, aky, fac) &
607
      !$OMP REDUCTION(+: shear_rate_nz, shear_rate_z_nz) &
608
      !$OMP SCHEDULE(static)
609
      do ik = 2, naky
×
610
         do it = 1, ntheta0
×
611
            shear_rate_nz = shear_rate_nz + real(conjg(phi(:, it, ik)) &
×
612
                 * phi(:, it, ik)) * (akx(it)**2 + aky(ik)**2)**2 * fac(ik)
×
613
            shear_rate_z_nz = shear_rate_z_nz + real(conjg(phi(:, it, ik)) &
×
614
                 * phi(:, it, ik)) * aky(ik)**4 * fac(ik)
×
615
         end do
616
      end do
617
      !$OMP END PARALLEL DO
618

619
      ! shear_rate = shear_rate ** 0.5
620
      shear_rate_nz = 0.5 * ( -omega_osc + sqrt(omega_osc ** 2 + 2 * shear_rate_nz))
×
621
      shear_rate_z_nz = 0.5 * ( -omega_osc + sqrt(omega_osc ** 2 + 2 * shear_rate_z_nz))
×
622
      shear_rate_z = 0.5 * ( -omega_osc + sqrt(omega_osc ** 2 + 2 * shear_rate_z))
×
623
      ! end of anisotropic shearing rate calculations
624

625
      ik = 1
×
626
      !$OMP PARALLEL DO DEFAULT(none) &
627
      !$OMP PRIVATE(it) &
628
      !$OMP SHARED(ik, ntheta0, hypervisc_filter, D_hypervisc, code_dt, akx, &
629
      !$OMP shear_rate_z_nz, akx4_max) &
630
      !$OMP SCHEDULE(static)
631
      do it = 1, ntheta0
×
632
         hypervisc_filter(:, it, ik) = exp(- (D_hypervisc * code_dt &
×
633
              * (shear_rate_z_nz * akx(it) ** 4 / akx4_max )))
×
634
      end do
635
      !$OMP END PARALLEL DO
636

637
      !$OMP PARALLEL DO DEFAULT(none) &
638
      !$OMP PRIVATE(ik, it) &
639
      !$OMP SHARED(naky, ntheta0, hypervisc_filter, D_hypervisc, code_dt, akx, aky, &
640
      !$OMP shear_rate_nz, shear_rate_z, nexp, akperp4_max, akx4_max, aky_max) &
641
      !$OMP SCHEDULE(static)
642
      do ik = 2, naky
×
643
         do it = 1, ntheta0
×
644
            hypervisc_filter(:, it, ik) = exp(- ( D_hypervisc * code_dt &
×
645
                 * ( shear_rate_nz *  (aky(ik) ** 2 + akx(it) ** 2 )**nexp / akperp4_max &
×
646
                 + shear_rate_z * (akx(it) ** 4) * aky(ik) / (akx4_max * aky_max))))
×
647
         end do
648
      end do
649
      !$OMP END PARALLEL DO
650
    end subroutine aniso_shear
×
651

652
    !> FIXME : Add documentation
653
    subroutine iso_shear
×
654
      real, dimension(naky) :: fac
×
655
      if (const_amp) then
×
656
         shear_rate_nz = 1.
×
657
      else
658
         fac = 0.5
×
659
         fac(1) = 1.0
×
660
         shear_rate_nz = 0.
×
661
         do ik = 1, naky
×
662
            if (damp_zonal_only .and. ik > 1) exit
×
663
            do it = 1, ntheta0
×
664
               shear_rate_nz = shear_rate_nz &
×
665
                    + real(conjg(phi(:, it, ik)) * phi(:, it, ik)) &
×
666
                    * (akx(it)**2 + aky(ik)**2)**2 * fac(ik)
×
667
            end do
668
         end do
669
         shear_rate_nz = sqrt(shear_rate_nz)
×
670
      end if
671

672
      do ik = 1, naky
×
673
         !Rely on hypervisc_filter initialised to 1
674
         if (damp_zonal_only .and. ik > 1) exit
×
675
         do it = 1, ntheta0
×
676
            hypervisc_filter(:, it, ik) = exp(- ( D_hypervisc * code_dt &
×
677
                 * ( shear_rate_nz *  (aky(ik) ** 2 + akx(it) ** 2 )**nexp / akperp4_max)))
×
678
         end do
679
      end do
680
    end subroutine iso_shear
×
681
  end subroutine hyper_diff
682

683
  !> FIXME : Add documentation
684
  subroutine finish_hyper
×
685
    implicit none
686
    hyper_on = .false.
×
687
    initialized = .false.
×
688
    if (allocated(D_res)) deallocate(D_res)
×
689
    if (allocated(hypervisc_filter)) deallocate(hypervisc_filter)
×
690
  end subroutine finish_hyper
×
691

692
#include "hyper_auto_gen.inc"
693
end module hyper
×
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