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

gyrokinetics / gs2 / 1821477209

16 May 2025 02:50PM UTC coverage: 8.139% (+0.2%) from 7.92%
1821477209

push

gitlab-ci

David Dickinson
Merged in bugfix/use_uv_in_coverage_test_to_install_packages (pull request #1142)

3704 of 45511 relevant lines covered (8.14%)

122643.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 gs2_layouts, only: init_gs2_layouts
301
    use warning_helpers, only: is_zero
302
    implicit none
303
    type(hyper_config_type), intent(in), optional :: hyper_config_in
304
    integer :: ik, it
305

306
    if (initialized) return
×
307
    initialized = .true.
×
308

309
    call init_gs2_layouts
×
310
    call read_parameters(hyper_config_in)
×
311
    call allocate_arrays
×
312

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

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

339
       if (D_hypervisc > 0.) D_v = D_hypervisc / akperp4_max
×
340

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

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

355
       if (isotropic_model .or. is_zero(shat)) then
×
356
          kperp2_max_zonal = kperp2_max
×
357
       else
358
          kperp2_max_zonal = maxval(kx_cut * kx_cut * gds22 / (shat * shat))
×
359
       end if
360

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

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

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

394
    if (present(hyper_config_in)) hyper_config = hyper_config_in
×
395

396
    call hyper_config%init(name = 'hyper_knobs', requires_index = .false.)
×
397

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

403
    ierr = error_unit()
×
404

405
    call get_option_value &
406
         (hyper_option, hyperopts, hyper_option_switch, &
407
         ierr, "hyper_option in hyper_knobs",.true.)
×
408

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

414

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

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

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

464
    case (hyper_option_both)
465
       hyper_on = .true.
×
466

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

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

494
    case (hyper_option_simple3D) ! MRH
495
       hyper_on = .true.
×
496

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

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

513
  !> FIXME : Add documentation
514
  subroutine allocate_arrays
×
515
    use theta_grid, only: ntgrid
516
    use kt_grids, only: ntheta0, naky
517
    implicit none
518

519
    if (.not. allocated(D_res)) allocate(D_res(ntheta0, naky))
×
520
    if (.not. allocated(hypervisc_filter)) &
×
521
         allocate(hypervisc_filter(-ntgrid:ntgrid,ntheta0,naky))
×
522

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

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

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

557
    if (.not. hyper_on) return
×
558

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

564
       if(isotropic_shear) then
×
565
          call iso_shear
×
566
       else
567
          call aniso_shear
×
568
       end if
569
    end select
570

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

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

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

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

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

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

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

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

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

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

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

702
#include "hyper_auto_gen.inc"
703
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