• 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/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
23
    implicit none
24
    type(diagnostics_type), intent(inout) :: gnostics
25

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

28
    if (has_phi) then
×
29
      call nc_write_field(gnostics%file_id, gnostics%nout, phinew, &
30
           "phi", "Electrostatic potential", gnostics%igomega, gnostics%write_phi_over_time,&
31
           gnostics%current_results%phi2)
×
32
    end if
33

34
    if (has_apar) then
×
35
      call nc_write_field(gnostics%file_id, gnostics%nout, aparnew, &
36
           "apar", "Parallel magnetic potential", gnostics%igomega, gnostics%write_apar_over_time,&
37
           gnostics%current_results%apar2)
×
38
    end if
39

40
    if (has_bpar) then
×
41
      call nc_write_field(gnostics%file_id, gnostics%nout, bparnew, &
42
           "bpar", "Parallel magnetic field", gnostics%igomega, gnostics%write_bpar_over_time,&
43
           gnostics%current_results%bpar2)
×
44
    end if
45
  end subroutine write_fields
46

47
  !> FIXME : Add documentation  
48
  subroutine write_movie(gnostics)
×
49
    use mp, only: proc0
50
    use diagnostics_config, only: diagnostics_type
51
    use gs2_io, only: nc_loop_movie
52
    implicit none
53
    type(diagnostics_type), intent(in) :: gnostics
54

55
    if (proc0) then
×
56
      call nc_loop_movie(gnostics%file_id, gnostics%nout, gnostics%user_time)
×
57
    end if
58
  end subroutine write_movie
×
59

60
  !> Calculate the `phi0` array, used to normalise eigenfunctions and
61
  !> moments.
62
  function get_phi0() result(phi0)
×
63
    use fields_arrays, only: phi, apar
64
    use kt_grids, only: ntheta0, naky
65
    use dist_fn, only: def_parity, even
66
    use run_parameters, only: has_apar
67
    use theta_grid, only: theta
68
    implicit none
69
    complex, dimension (ntheta0, naky) :: phi0
70

71
    !Should this actually use igomega instead of 0?
72
    !What if fphi==0? --> See where statements below
73
    phi0 = phi(0,:,:)
×
74

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

79
    !Address locations where phi0=0 by using next point
80
    where (abs(phi0) < 10.0*epsilon(0.0))
×
81
       phi0 = phi(1,:,:)/(theta(1)-theta(0))
×
82
    end where
83

84
    !Check again if any locations are 0, this could be true if fphi (or fapar)
85
    !is zero.
86
    where (abs(phi0) < 10.0*epsilon(0.0))
×
87
       phi0 = 1.0
×
88
    end where
89

90
  end function get_phi0
×
91

92
  !> Write out the fields, normalized to their value at theta=0
93
  subroutine write_eigenfunc_gnostics(gnostics)
×
94
    use diagnostics_config, only: diagnostics_type
95
    use mp, only: proc0
96
    implicit none
97
    type(diagnostics_type), intent(in) :: gnostics
98
    call write_eigenfunc(write_text = proc0 .and. gnostics%ascii_files%write_to_eigenfunc .and. (.not. gnostics%create), &
99
         ascii_unit = gnostics%ascii_files%eigenfunc, netcdf_id = gnostics%file_id)
×
100
  end subroutine write_eigenfunc_gnostics
×
101

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

118
    phi0 = get_phi0()
×
119

120
    !Do ascii output
121
    if (write_text) then
×
122
       do ik = 1, naky
×
123
          do it = 1, ntheta0
×
124
             do ig = -ntgrid, ntgrid
×
125
                write (unit = ascii_unit, fmt="(9(1x,e12.5))") &
×
126
                     theta(ig), theta0(it,ik), aky(ik), &
×
127
                     phi(ig,it,ik)/phi0(it,ik), &
×
128
                     apar(ig,it,ik)/phi0(it,ik), &
×
129
                     bpar(ig,it,ik)/phi0(it,ik)
×
130
             end do
131
             write (unit = ascii_unit, fmt="()")
×
132
          end do
133
       end do
134
    end if
135
    
136
    call nc_eigenfunc(netcdf_id, phi0)
×
137
  end subroutine write_eigenfunc_raw
138

139
end module diagnostics_fields
140

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