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

gyrokinetics / gs2 / 1989146477

18 Aug 2025 10:42AM UTC coverage: 10.372% (+2.2%) from 8.184%
1989146477

push

gitlab-ci

David Dickinson
Merged in experimental/more_gs2_init_everywhere (pull request #1134)

4646 of 44794 relevant lines covered (10.37%)

124612.73 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
   contains
111
     procedure, public :: read => read_hyper_config
112
     procedure, public :: write => write_hyper_config
113
     procedure, public :: reset => reset_hyper_config
114
     procedure, public :: broadcast => broadcast_hyper_config
115
     procedure, public, nopass :: get_default_name => get_default_name_hyper_config
116
     procedure, public, nopass :: get_default_requires_index => get_default_requires_index_hyper_config
117
  end type hyper_config_type
118

119
  type(hyper_config_type) :: hyper_config
120

121
contains
122

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

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

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

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

210
    end select
211

212
    if (hyper_on) then
×
213
       write (report_unit, *)
×
214
       write (report_unit, fmt="('------------------------------------------------------------')")
×
215
       write (report_unit, *)
×
216

217
       select case (hyper_option_switch)
×
218

219
       case (hyper_option_visc)
220

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

238
       case (hyper_option_res)
239

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

260
       case (hyper_option_both)
261

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

287
  !> FIXME : Add documentation
288
  subroutine wnml_hyper(unit)
×
289
    implicit none
290
    integer, intent(in) :: unit
291
    if (.not. hyper_on) return
×
292
    call hyper_config%write(unit)
×
293
  end subroutine wnml_hyper
294

295
  !> FIXME : Add documentation
296
  subroutine init_hyper(hyper_config_in)
×
297
    use kt_grids, only: ntheta0, naky, akx, aky, kperp2
298
    use theta_grid, only: gds2, gds21, gds22, shat
299
    use gs2_time, only: code_dt
300
    use warning_helpers, only: is_zero
301
    implicit none
302
    type(hyper_config_type), intent(in), optional :: hyper_config_in
303
    integer :: ik, it
304

305
    if (initialized) return
×
306
    initialized = .true.
×
307
    call read_parameters(hyper_config_in)
×
308
    call allocate_arrays
×
309

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

325
       ! Get D_res set up if needed
326
       if (D_hyperres > 0.) then
×
327
          do ik = 1, naky
×
328
             do it = 1, ntheta0
×
329
                D_res(it, ik) = D_hyperres*code_dt * (aky(ik)**2 + akx(it)**2)**nexp &
×
330
                     / akperp4_max
×
331
             end do
332
          end do
333
          D_eta = D_hyperres / akperp4_max
×
334
       end if
335

336
       if (D_hypervisc > 0.) D_v = D_hypervisc / akperp4_max
×
337

338
    case(hyper_option_simple3D)
339
       ! Make the default cut-offs the grid scale
340
       if (ky_cut <= 0.) ky_cut = aky(naky)
×
341
       if (kx_cut <= 0.) kx_cut = akx((ntheta0+1)/2)
×
342

343
       ! Here we're evaluating kperp2 for the specified ky, kx value
344
       if (is_zero(shat)) then
×
345
          kperp2_max = ky_cut*ky_cut + kx_cut*kx_cut
×
346
       else
347
          kperp2_max = maxval(ky_cut * ky_cut * gds2 + &
×
348
               2.0 * ky_cut * kx_cut * gds21 / shat + &
×
349
               kx_cut * kx_cut * gds22 / (shat * shat))
×
350
       end if
351

352
       if (isotropic_model .or. is_zero(shat)) then
×
353
          kperp2_max_zonal = kperp2_max
×
354
       else
355
          kperp2_max_zonal = maxval(kx_cut * kx_cut * gds22 / (shat * shat))
×
356
       end if
357

358
       ! Calculate the filter
359
       ik =1  ! Zonal modes
×
360
       do it = 1, ntheta0
×
361
          hypervisc_filter(:, it, ik) = exp(- ( D_hyper3D * code_dt &
×
362
               * ( kperp2(:, it, ik) / kperp2_max_zonal)**(P_hyper3D / 2)))
×
363
       end do
364

365
       do ik = 2, naky ! Non-zonal modes
×
366
          do it = 1, ntheta0
×
367
             hypervisc_filter(:, it, ik) = exp(- ( D_hyper3D * code_dt &
×
368
                  * ( kperp2(:, it, ik) / kperp2_max )**(P_hyper3D / 2)) )
×
369
          end do
370
       end do
371
    end select
372
  end subroutine init_hyper
373

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

391
    if (present(hyper_config_in)) hyper_config = hyper_config_in
×
392

393
    call hyper_config%init(name = 'hyper_knobs', requires_index = .false.)
×
394

395
    ! Copy out internal values into module level parameters
396
    associate(self => hyper_config)
397
#include "hyper_copy_out_auto_gen.inc"
398
    end associate
399

400
    ierr = error_unit()
×
401

402
    call get_option_value &
403
         (hyper_option, hyperopts, hyper_option_switch, &
404
         ierr, "hyper_option in hyper_knobs",.true.)
×
405

406
    if (.not. isotropic_shear .and. nexp /= 2) then
×
407
       if (proc0) write (ierr, *) 'Forcing nexp = 2.  Higher values not implemented for anisotropic shear model.'
×
408
       nexp = 2
×
409
    end if
410

411

412
    select case (hyper_option_switch)
×
413
    case (hyper_option_none)
414
       if (D_hyperres > 0.) then
×
415
          if (proc0) write(ierr, *) 'hyper_option = ',hyper_option, &
×
416
               ' chooses no hyperresistivity.  D_hyperres ignored.'
×
417
          D_hyperres = -10.
×
418
       end if
419
       if (D_hypervisc > 0.) then
×
420
          if (proc0) write(ierr, *) 'hyper_option = ',hyper_option, &
×
421
               ' chooses no hyperviscosity.  D_hypervisc ignored.'
×
422
          D_hypervisc = -10.
×
423
       endif
424

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

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

461
    case (hyper_option_both)
462
       hyper_on = .true.
×
463

464
       if (D_hyper < 0.) then
×
465
          if (not_exactly_equal(D_hyperres, D_hypervisc)) then
×
466
             if (proc0) write (ierr, *) 'WARNING: It is inconsistent to set D_hypervisc different from ', &
×
467
                  'D_hyperres.  Recommend: Set them equal.'
×
468
          end if
469
       else
470
          if (proc0) write (ierr, *) 'WARNING: Setting D_hypervisc = D_hyperres, each to value of D_hyper'
×
471
          D_hyperres  = D_hyper
×
472
          D_hypervisc = D_hyper
×
473
       end if
474

475
       if (D_hyperres < 0.) then
×
476
          if (proc0) then
×
477
             write(ierr, *) 'hyper_option = ',hyper_option, &
×
478
                  ' chooses hyperresistivity but  D_hyperres < 0 is illegal.'
×
479
             write(ierr, *) 'No hyperresistivity used.'
×
480
          end if
481
       end if
482
       if (D_hypervisc < 0.) then
×
483
          if (proc0) then
×
484
             write(ierr, *) 'hyper_option = ',hyper_option, &
×
485
                  ' chooses hyperviscosity but D_hypervisc < 0 is illegal.'
×
486
             write(ierr, *) 'No hyperviscosity used.'
×
487
          end if
488
       endif
489
       if (D_hypervisc < 0. .and. D_hyperres < 0.) hyper_on = .false.
×
490

491
    case (hyper_option_simple3D) ! MRH
492
       hyper_on = .true.
×
493

494
       if (P_hyper3D < 4.) then
×
495
          hyper_on = .false.
×
496
          if(proc0) write(ierr, *) 'hyper_option = ',hyper_option, &
×
497
               ' chooses a simple hyperviscous filter but  P_hyper3D < 4. is illegal.'
×
498
          if(proc0) write(ierr, *) 'No hyperviscosity used.'
×
499
       endif
500

501
       if (D_hyper3D < 0.) then
×
502
          hyper_on = .false.
×
503
          if(proc0) write(ierr, *) 'hyper_option = ',hyper_option, &
×
504
               ' chooses a simple hyperviscous filter but  D_hyper3D < 0 is illegal.'
×
505
          if(proc0) write(ierr, *) 'No hyperviscosity used.'
×
506
       endif
507
    end select
508
  end subroutine read_parameters
×
509

510
  !> FIXME : Add documentation
511
  subroutine allocate_arrays
×
512
    use theta_grid, only: ntgrid
513
    use kt_grids, only: ntheta0, naky
514
    implicit none
515

516
    if (.not. allocated(D_res)) allocate(D_res(ntheta0, naky))
×
517
    if (.not. allocated(hypervisc_filter)) &
×
518
         allocate(hypervisc_filter(-ntgrid:ntgrid,ntheta0,naky))
×
519

520
    ! Initialise module level variables
521
    D_v = 0 ;  D_eta = 0 ; D_res = 0
×
522
    akx4_max = 0 ; aky_max = 0 ; aky4_max = 0 ; akperp4_max = 0
×
523
    kperp2_max = 0 ; kperp2_max_zonal = 0 ; hypervisc_filter = 1
×
524
  end subroutine allocate_arrays
×
525

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

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

554
    if (.not. hyper_on) return
×
555

556
    ! Calculate hypervisc filter for non-simple3D model
557
    select case (hyper_option_switch)
×
558
    case(hyper_option_both, hyper_option_res, hyper_option_visc)
559
       if (D_hypervisc < 0.) return
×
560

561
       if(isotropic_shear) then
×
562
          call iso_shear
×
563
       else
564
          call aniso_shear
×
565
       end if
566
    end select
567

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

583
    !> FIXME : Add documentation
584
    subroutine aniso_shear
×
585
      real, dimension(naky) :: fac
×
586
      ! Do the Belli-Hammett anisotropic calculation
587
      ! which accounts for some zonal/non-zonal differences
588
      fac = 0.5
×
589
      fac(1) = 1.0
×
590

591
      ! shearing rate due to non-zonal modes (on nonzonal modes)
592
      shear_rate_nz = 0.
×
593
      ! shearing rate due to zonal modes (on nonzonal modes)
594
      shear_rate_z = 0
×
595
      ! shearing rate due to nonzonal modes (on zonal modes)
596
      shear_rate_z_nz = 0.
×
597

598
      ik = 1
×
599
      !$OMP PARALLEL DO DEFAULT(none) &
600
      !$OMP PRIVATE(it) &
601
      !$OMP SHARED(ik, ntheta0, phi, akx, aky, fac) &
602
      !$OMP REDUCTION(+: shear_rate_z) &
603
      !$OMP SCHEDULE(static)
604
      do it = 1, ntheta0
×
605
         shear_rate_z = shear_rate_z + real(conjg(phi(:, it, ik)) &
×
606
              * phi(:, it, ik)) * (akx(it)**2 + aky(ik)**2)**2 * fac(ik)
×
607
      end do
608
      !$OMP END PARALLEL DO
609

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

625
      ! shear_rate = shear_rate ** 0.5
626
      shear_rate_nz = 0.5 * ( -omega_osc + sqrt(omega_osc ** 2 + 2 * shear_rate_nz))
×
627
      shear_rate_z_nz = 0.5 * ( -omega_osc + sqrt(omega_osc ** 2 + 2 * shear_rate_z_nz))
×
628
      shear_rate_z = 0.5 * ( -omega_osc + sqrt(omega_osc ** 2 + 2 * shear_rate_z))
×
629
      ! end of anisotropic shearing rate calculations
630

631
      ik = 1
×
632
      !$OMP PARALLEL DO DEFAULT(none) &
633
      !$OMP PRIVATE(it) &
634
      !$OMP SHARED(ik, ntheta0, hypervisc_filter, D_hypervisc, code_dt, akx, &
635
      !$OMP shear_rate_z_nz, akx4_max) &
636
      !$OMP SCHEDULE(static)
637
      do it = 1, ntheta0
×
638
         hypervisc_filter(:, it, ik) = exp(- (D_hypervisc * code_dt &
×
639
              * (shear_rate_z_nz * akx(it) ** 4 / akx4_max )))
×
640
      end do
641
      !$OMP END PARALLEL DO
642

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

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

678
      do ik = 1, naky
×
679
         !Rely on hypervisc_filter initialised to 1
680
         if (damp_zonal_only .and. ik > 1) exit
×
681
         do it = 1, ntheta0
×
682
            hypervisc_filter(:, it, ik) = exp(- ( D_hypervisc * code_dt &
×
683
                 * ( shear_rate_nz *  (aky(ik) ** 2 + akx(it) ** 2 )**nexp / akperp4_max)))
×
684
         end do
685
      end do
686
    end subroutine iso_shear
×
687
  end subroutine hyper_diff
688

689
  !> FIXME : Add documentation
690
  subroutine finish_hyper
×
691
    implicit none
692
    hyper_on = .false.
×
693
    initialized = .false.
×
694
    if (allocated(D_res)) deallocate(D_res)
×
695
    if (allocated(hypervisc_filter)) deallocate(hypervisc_filter)
×
696
    call hyper_config%reset()
×
697
  end subroutine finish_hyper
×
698

699
#include "hyper_auto_gen.inc"
700
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