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

gyrokinetics / gs2 / 2042563664

16 Sep 2025 01:04PM UTC coverage: 10.677% (+0.07%) from 10.607%
2042563664

push

gitlab-ci

David Dickinson
Merged in minor/tidy_up_some_gs2_io_routines (pull request #1173)

4712 of 44131 relevant lines covered (10.68%)

126484.23 hits per line

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

0.0
/src/diagnostics/diagnostics_fields.f90
1
!> This module contains functions for writing quantities
2
!! that have the dimensions of the fields, including
3
!! volume averaged quantities, etc.
4
module diagnostics_fields
5
  implicit none
6
  
7
  private
8
  
9
  public :: write_fields, write_movie, write_eigenfunc, get_phi0
10

11
  interface write_eigenfunc
12
     module procedure write_eigenfunc_gnostics
13
     module procedure write_eigenfunc_raw
14
  end interface write_eigenfunc
15

16
contains
17
  !> FIXME : Add documentation
18
  subroutine write_fields(gnostics)
×
19
    use fields_arrays, only: phinew, aparnew, bparnew
20
    use run_parameters, only: has_phi, has_apar, has_bpar
21
    use diagnostics_config, only: diagnostics_type
22
    use gs2_io, only: nc_write_field, nc_final_fields
23
    implicit none
24
    type(diagnostics_type), intent(inout) :: gnostics
25

26
    if (.not. gnostics%writing) return
×
27

28
    if (has_phi) call nc_write_field(gnostics%file_id, gnostics%nout, phinew, "phi", &
×
29
         "Electrostatic potential", gnostics%igomega, gnostics%write_phi_over_time,&
30
         gnostics%current_results%phi2)
×
31
    if (has_apar) call nc_write_field(gnostics%file_id, gnostics%nout, aparnew, "apar", &
×
32
         "Parallel magnetic potential", gnostics%igomega, gnostics%write_apar_over_time,&
33
         gnostics%current_results%apar2)
×
34
    if (has_bpar) call nc_write_field(gnostics%file_id, gnostics%nout, bparnew, "bpar", &
×
35
         "Parallel magnetic field", gnostics%igomega, gnostics%write_bpar_over_time,&
36
         gnostics%current_results%bpar2)
×
37

38
    call nc_final_fields(gnostics%file_id)
×
39
  end subroutine write_fields
40

41
  !> FIXME : Add documentation  
42
  subroutine write_movie(gnostics)
×
43
    use mp, only: proc0
44
    use diagnostics_config, only: diagnostics_type
45
    use gs2_io, only: nc_loop_movie
46
    implicit none
47
    type(diagnostics_type), intent(in out) :: gnostics
48
    if (proc0) call nc_loop_movie(gnostics%file_id, gnostics%nout_movie, gnostics%user_time)
×
49
    gnostics%nout_movie = gnostics%nout_movie + 1
×
50
  end subroutine write_movie
×
51

52
  !> Calculate the `phi0` array, used to normalise eigenfunctions and
53
  !> moments.
54
  function get_phi0() result(phi0)
×
55
    use fields_arrays, only: phi, apar
56
    use kt_grids, only: ntheta0, naky
57
    use dist_fn, only: def_parity, even
58
    use run_parameters, only: has_apar
59
    use theta_grid, only: theta
60
    implicit none
61
    complex, dimension (ntheta0, naky) :: phi0
62

63
    !Should this actually use igomega instead of 0?
64
    !What if fphi==0? --> See where statements below
65
    phi0 = phi(0,:,:)
×
66

67
    !This looks like a hack for the case where we know we've forced phi(theta=0) to be 0
68
    !this could probably be better addressed by the use of igomega above
69
    if (def_parity .and. has_apar .and. (.not. even)) phi0 = apar(0, :, :)
×
70

71
    !Address locations where phi0=0 by using next point
72
    where (abs(phi0) < 10.0*epsilon(0.0))
×
73
       phi0 = phi(1,:,:)/(theta(1)-theta(0))
×
74
    end where
75

76
    !Check again if any locations are 0, this could be true if fphi (or fapar)
77
    !is zero.
78
    where (abs(phi0) < 10.0*epsilon(0.0))
×
79
       phi0 = 1.0
×
80
    end where
81

82
  end function get_phi0
×
83

84
  !> Write out the fields, normalized to their value at theta=0
85
  subroutine write_eigenfunc_gnostics(gnostics)
×
86
    use diagnostics_config, only: diagnostics_type
87
    use mp, only: proc0
88
    implicit none
89
    type(diagnostics_type), intent(in) :: gnostics
90
    call write_eigenfunc(write_text = proc0 .and. gnostics%ascii_files%write_to_eigenfunc .and. (.not. gnostics%create), &
91
         ascii_unit = gnostics%ascii_files%eigenfunc, netcdf_id = gnostics%file_id)
×
92
  end subroutine write_eigenfunc_gnostics
×
93

94
  !> Write out the fields, normalized to their value at theta=0
95
  subroutine write_eigenfunc_raw(write_text, ascii_unit, netcdf_id)
×
96
    use mp, only: proc0
97
    use file_utils, only: open_output_file, close_output_file
98
    use fields_arrays, only: phi, apar, bpar
99
    use kt_grids, only: ntheta0, naky, theta0, aky
100
    use theta_grid, only: theta, ntgrid
101
    use gs2_io, only: nc_eigenfunc
102
    implicit none
103
    logical, intent(in) :: write_text
104
    integer, intent(in) :: ascii_unit, netcdf_id
105
    complex, dimension (ntheta0, naky) :: phi0
×
106
    integer :: it, ik, ig
107
    
108
    if (.not. proc0) return
×
109

110
    phi0 = get_phi0()
×
111

112
    !Do ascii output
113
    if (write_text) then
×
114
       do ik = 1, naky
×
115
          do it = 1, ntheta0
×
116
             do ig = -ntgrid, ntgrid
×
117
                write (unit = ascii_unit, fmt="(9(1x,e12.5))") &
×
118
                     theta(ig), theta0(it,ik), aky(ik), &
×
119
                     phi(ig,it,ik)/phi0(it,ik), &
×
120
                     apar(ig,it,ik)/phi0(it,ik), &
×
121
                     bpar(ig,it,ik)/phi0(it,ik)
×
122
             end do
123
             write (unit = ascii_unit, fmt="()")
×
124
          end do
125
       end do
126
    end if
127
    
128
    call nc_eigenfunc(netcdf_id, phi0)
×
129
  end subroutine write_eigenfunc_raw
130

131
end module diagnostics_fields
132

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