• 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/programs/dump_grids.fpp
1
!> For the given input file initialises the main grids
2
!> and geometry and writes these to file (netcdf or binary).
3
program dump_grids
×
4
  use job_manage, only: job_fork, time_message
×
5
  use mp, only: init_mp, proc0, nproc, broadcast
6
  use file_utils, only: init_file_utils, run_name, run_name_target
7
  use kt_grids, only: init_kt_grids
8
  use theta_grid, only: init_theta_grid
9
  use le_grids, only: init_le_grids
10
  use species, only: init_species
11
  implicit none
12
  logical :: list
13
  logical, parameter :: quiet=.false.
14
  character (len=500) :: filename
15
  real :: time_measure(2)
16

17
  ! Initialize message passing
18
  call init_mp
×
19

20
  ! Report # of processors being used
21
  if (proc0) then
×
22
     if(.not.quiet)then
23
        if (nproc == 1) then
×
24
           write(*,'("Running on ",I0," processor")') nproc
×
25
        else
26
           write(*,'("Running on ",I0," processors")') nproc
×
27
        end if
28
     endif
29

30
     ! Call init_file_utils, ie. initialize the inputs and outputs, checking
31
     !  whether we are doing a run or a list of runs.
32
     call init_file_utils (list, name="gs")
×
33
  end if
34

35
  call broadcast (list)
×
36

37
  ! If given a list of jobs, fork
38
  if (list) call job_fork
×
39

40
  if (proc0) run_name_target = trim(run_name)
×
41
  call broadcast (run_name_target)
×
42
  if (.not. proc0) run_name => run_name_target
×
43

44
  !Initialise
45
  time_measure=0.
×
46
  !/Theta
47
  if(proc0.and.(.not.quiet)) then
×
48
     write(*,'("Init theta_grids")',advance='no')
×
49
  endif
50
  call time_message(.false.,time_measure,'init-theta')
×
51
  call init_theta_grid
×
52
  call time_message(.false.,time_measure,'init-theta')
×
53
  if(proc0.and.(.not.quiet)) then
×
54
     write(*,'("  --> Done in : ",F12.6," seconds")') time_measure(1)
×
55
  endif
56
  time_measure=0.
×
57
  !/KT
58
  if(proc0.and.(.not.quiet)) then
×
59
     write(*,'("Init kt_grids   ")',advance='no')
×
60
  endif
61
  call time_message(.false.,time_measure,'init-kt')
×
62
  call init_kt_grids
×
63
  call time_message(.false.,time_measure,'init-kt')
×
64
  if(proc0.and.(.not.quiet)) then
×
65
     write(*,'("  --> Done in : ",F12.6," seconds")') time_measure(1)
×
66
  endif
67
  time_measure=0.
×
68
  !/SPECIES
69
  if(proc0.and.(.not.quiet)) then
×
70
     write(*,'("Init species   ")',advance='no')
×
71
  endif
72
  call time_message(.false.,time_measure,'init-species')
×
73
  call init_species
×
74
  call time_message(.false.,time_measure,'init-species')
×
75
  if(proc0.and.(.not.quiet)) then
×
76
     write(*,'("  --> Done in : ",F12.6," seconds")') time_measure(1)
×
77
  endif
78
  time_measure=0.
×
79
  !/LE
80
  if(proc0.and.(.not.quiet)) then
×
81
     write(*,'("Init le_grids   ")',advance='no')
×
82
  endif
83
  call time_message(.false.,time_measure,'init-le')
×
84
  call init_le_grids
×
85
  call time_message(.false.,time_measure,'init-le')
×
86
  if(proc0.and.(.not.quiet)) then
×
87
     write(*,'("  --> Done in : ",F12.6," seconds")') time_measure(1)
×
88
  endif
89
  time_measure=0.
×
90

91
  !Now write to file
92
  if(proc0.and.(.not.quiet)) then
×
93
     write(*,'("Write to file   ")',advance='no')
×
94
  endif
95
  call time_message(.false.,time_measure,'write-file')
×
96
  filename=trim(adjustl(run_name))
×
97
  if(proc0) call write_grids_to_file(filename)
×
98
  call time_message(.false.,time_measure,'write-file')
×
99
  if(proc0.and.(.not.quiet)) then
×
100
     write(*,'("  --> Done in : ",F12.6," seconds")') time_measure(1)
×
101
  endif
102
  time_measure=0.
×
103

104
contains
105

106
#ifdef NETCDF
107
!Prefer to write to netcdf file if possible
108

109
  !> FIXME : Add documentation
110
  subroutine write_grids_to_file(fname)
×
111
    use neasyf, only: neasyf_open, neasyf_default_compression, neasyf_dim, neasyf_write, neasyf_close
112
    use kt_grids, only: aky, akx, theta0
113
    use theta_grid, only: theta
114
    use le_grids, only: al, energy, wl, w, negrid
115
    use species, only: nspec
116
    use gs2_metadata, only: create_metadata
117
    use gs2_io, only: nc_geo, nc_species
118
    use gs2_io, only: kx_dim, ky_dim, theta_dim, lambda_dim, species_dim, egrid_dim
119
    implicit none
120
    character(len=*), intent(in) :: fname
121
    integer :: ncid
122
    !> Level of compression if enabled via
123
    !> `GK_NETCDF_DEFAULT_COMPRESSION_ON` macro. Must be a value between
124
    !> 1 (faster, less compression) and 9 (slower, more compression), or
125
    !> 0 (off)
126
#ifdef GK_NETCDF_DEFAULT_COMPRESSION_ON
127
    integer, parameter :: default_compression_level = 1
128
    neasyf_default_compression = default_compression_level
×
129
#else
130
    integer, parameter :: compression_off = 0
131
    neasyf_default_compression = compression_off
132
#endif
133

134
    !First create a file
135
    ncid = neasyf_open(trim(adjustl(fname))//".grids.nc", "w")
×
136
    call create_metadata(ncid, "GS2 grids")
×
137

138
    call neasyf_dim(ncid, trim(kx_dim), values = akx, &
139
         long_name = "Wavenumber perpendicular to flux surface", units = "1/rho_r")
×
140
    call neasyf_dim(ncid, trim(ky_dim), values = aky, &
141
         long_name = "Wavenumber in direction of grad alpha", units = "1/rho_r")
×
142
    call neasyf_dim(ncid, trim(theta_dim), values = theta, long_name = "Poloidal angle", &
143
         units = "rad")
×
144
    call neasyf_dim(ncid, trim(lambda_dim), values = al, &
145
         long_name = "Energy/magnetic moment", units = "1/(2 B_a)")
×
146
    call neasyf_dim(ncid, trim(species_dim), dim_size = nspec)
×
147
    call neasyf_dim(ncid, trim(egrid_dim), dim_size = negrid, &
148
         long_name="See 'energy' for energy grid values")
×
149

150
    call neasyf_write(ncid, 'theta0', theta0, dim_names = [kx_dim,ky_dim], &
151
         long_name = 'theta0')
×
152
    call neasyf_write(ncid, "energy", energy, dim_names = [egrid_dim, species_dim], &
153
         long_name="Energy grid values")
×
154
    call nc_geo(ncid)
×
155
    call nc_species(ncid)
×
156
    call neasyf_write(ncid, 'wl', wl, dim_names = [theta_dim, lambda_dim], &
157
         long_name = "Pitch angle integration weights")
×
158
    call neasyf_write(ncid, 'w', w, dim_names = [egrid_dim, species_dim], &
159
         long_name = "Energy grid integration weights")
×
160
    call neasyf_close(ncid)
×
161
  end subroutine write_grids_to_file
×
162
#else
163
  !Fall back to binary output when netcdf unavailable
164

165
  !> FIXME : Add documentation
166
  subroutine write_grids_to_file(fname)
167
    use kt_grids, only: aky, akx, theta0, kperp2
168
    use theta_grid, only: theta
169
    use theta_grid, only: bmag, bpol, gradpar, grho
170
    use theta_grid, only: cdrift, cvdrift, gbdrift
171
    use theta_grid, only: cdrift0, cvdrift0, gbdrift0
172
    use theta_grid, only: gds2, gds21, gds22, gds23, gds24, gds24_noq
173
    use theta_grid, only: rplot, zplot, aplot
174
    use theta_grid, only: rprime, zprime, aprime
175
    use le_grids, only: al, energy, wl, w
176
    use file_utils, only: get_unused_unit
177

178
    implicit none
179
    character(len=*), intent(in) :: fname
180
    integer :: unit
181

182
    call get_unused_unit(unit)
183

184
    open(unit=unit,file=trim(adjustl(fname))//".ky",form="unformatted")
185
    write(unit) aky
186
    close(unit)
187

188
    open(unit=unit,file=trim(adjustl(fname))//".kx",form="unformatted")
189
    write(unit) akx
190
    close(unit)
191

192
    open(unit=unit,file=trim(adjustl(fname))//".theta0",form="unformatted")
193
    write(unit) theta0
194
    close(unit)
195

196
    open(unit=unit,file=trim(adjustl(fname))//".theta",form="unformatted")
197
    write(unit) theta
198
    close(unit)
199

200
    open(unit=unit,file=trim(adjustl(fname))//".lambda",form="unformatted")
201
    write(unit) al
202
    close(unit)
203

204
    open(unit=unit,file=trim(adjustl(fname))//".energy",form="unformatted")
205
    write(unit) energy
206
    close(unit)
207

208
    open(unit=unit,file=trim(adjustl(fname))//".bmag",form="unformatted")
209
    write(unit) bmag
210
    close(unit)
211

212
    open(unit=unit,file=trim(adjustl(fname))//".bpol",form="unformatted")
213
    write(unit) bpol
214
    close(unit)
215

216
    open(unit=unit,file=trim(adjustl(fname))//".gradpar",form="unformatted")
217
    write(unit) gradpar
218
    close(unit)
219

220
    open(unit=unit,file=trim(adjustl(fname))//".grho",form="unformatted")
221
    write(unit) grho
222
    close(unit)
223

224
    open(unit=unit,file=trim(adjustl(fname))//".cdrift",form="unformatted")
225
    write(unit) cdrift
226
    close(unit)
227

228
    open(unit=unit,file=trim(adjustl(fname))//".cvdrift",form="unformatted")
229
    write(unit) cvdrift
230
    close(unit)
231

232
    open(unit=unit,file=trim(adjustl(fname))//".gbdrift",form="unformatted")
233
    write(unit) gbdrift
234
    close(unit)
235

236
    open(unit=unit,file=trim(adjustl(fname))//".cdrift0",form="unformatted")
237
    write(unit) cdrift0
238
    close(unit)
239

240
    open(unit=unit,file=trim(adjustl(fname))//".cvdrift0",form="unformatted")
241
    write(unit) cvdrift0
242
    close(unit)
243

244
    open(unit=unit,file=trim(adjustl(fname))//".gbdrift0",form="unformatted")
245
    write(unit) gbdrift0
246
    close(unit)
247

248
    open(unit=unit,file=trim(adjustl(fname))//".gds2",form="unformatted")
249
    write(unit) gds2
250
    close(unit)
251

252
    open(unit=unit,file=trim(adjustl(fname))//".gds21",form="unformatted")
253
    write(unit) gds21
254
    close(unit)
255

256
    open(unit=unit,file=trim(adjustl(fname))//".gds22",form="unformatted")
257
    write(unit) gds22
258
    close(unit)
259

260
    open(unit=unit,file=trim(adjustl(fname))//".gds23",form="unformatted")
261
    write(unit) gds23
262
    close(unit)
263

264
    open(unit=unit,file=trim(adjustl(fname))//".gds24",form="unformatted")
265
    write(unit) gds24
266
    close(unit)
267

268
    open(unit=unit,file=trim(adjustl(fname))//".gds24_noq",form="unformatted")
269
    write(unit) gds24_noq
270
    close(unit)
271

272
    open(unit=unit,file=trim(adjustl(fname))//".rplot",form="unformatted")
273
    write(unit) rplot
274
    close(unit)
275

276
    open(unit=unit,file=trim(adjustl(fname))//".zplot",form="unformatted")
277
    write(unit) zplot
278
    close(unit)
279

280
    open(unit=unit,file=trim(adjustl(fname))//".aplot",form="unformatted")
281
    write(unit) aplot
282
    close(unit)
283

284
    open(unit=unit,file=trim(adjustl(fname))//".rprime",form="unformatted")
285
    write(unit) rprime
286
    close(unit)
287

288
    open(unit=unit,file=trim(adjustl(fname))//".zprime",form="unformatted")
289
    write(unit) zprime
290
    close(unit)
291

292
    open(unit=unit,file=trim(adjustl(fname))//".aprime",form="unformatted")
293
    write(unit) aprime
294
    close(unit)
295

296
    open(unit=unit,file=trim(adjustl(fname))//".kperp2",form="unformatted")
297
    write(unit) kperp2
298
    close(unit)
299

300
    open(unit=unit,file=trim(adjustl(fname))//".wl",form="unformatted")
301
    write(unit) wl
302
    close(unit)
303

304
    open(unit=unit,file=trim(adjustl(fname))//".w",form="unformatted")
305
    write(unit) w
306
    close(unit)
307
  end subroutine write_grids_to_file
308
#endif
309
end program dump_grids
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