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

gyrokinetics / gs2 / 1969858349

06 Aug 2025 12:16PM UTC coverage: 8.174% (+0.004%) from 8.17%
1969858349

push

gitlab-ci

David Dickinson
Merged in minor/remove_unused_reset_init_routines (pull request #1105)

3673 of 44933 relevant lines covered (8.17%)

124220.92 hits per line

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

0.0
/src/programs/dump_response.f90
1
!> A program to generate response matrix data for a given input file
2
!> and dump the resulting arrays to file to be used by subsequent runs.
3
!>
4
!> By default this will produce a single set of response matrix files
5
!> for the time step in the provided input file. The input file can
6
!> contain a `dump_response_knobs` namelist which specifies
7
!> `n_time_steps`. If this is greater than one then the program will
8
!> produce response matrix files for `n_time_steps`
9
!> timesteps. Specifically, it will produce these files for time steps
10
!> {delt/delt_adj^N, N=0, n_time_steps-1}. This may be useful for
11
!> precomputing the response matrices required for a nonlinear run
12
!> where the timestep is allowed to vary and take values from this sequence.
13
!>
14
!> Written by : David Dickinson (ddickinson@users.sourceforge.net)
15
program dump_response
×
16
  use job_manage, only: job_fork
×
17
  use mp, only: init_mp, proc0, nproc, broadcast
18
  use file_utils, only: init_file_utils, run_name, input_unit_exist
19
  use constants, only: run_name_size
20
  use standard_header, only: standard_header_type
21
  implicit none
22
  logical :: list, exist
23
  logical, parameter :: quiet=.false.
24
  character (run_name_size), target :: cbuff
25
  integer :: istep, n_time_steps, in_file
26
  type(standard_header_type) :: local_header
×
27
  namelist /dump_response_knobs/n_time_steps
28

29
  call init_mp
×
30

31
  local_header = standard_header_type()
×
32

33
  ! Report # of processors being used
34
  if (proc0) then
×
35
     if(.not.quiet)then
36
        if (nproc == 1) then
×
37
           write(*,'("Running on ",I0," processor")') nproc
×
38
        else
39
           write(*,'("Running on ",I0," processors")') nproc
×
40
        end if
41
     endif
42

43
     ! Call init_file_utils, ie. initialize the inputs and outputs, checking
44
     ! whether we are doing a run or a list of runs.
45
     call init_file_utils (list, name="gs")
×
46
  end if
47

48
  call broadcast (list)
×
49

50
  ! If given a list of jobs, fork
51
  if (list) call job_fork
×
52

53
  if (proc0) cbuff = trim(run_name)
×
54
  call broadcast (cbuff)
×
55
  if (.not. proc0) run_name = cbuff
×
56

57
  if(proc0) then
×
58
     n_time_steps=1
×
59
     in_file = input_unit_exist ("dump_response_knobs", exist)
×
60
     if(exist) read(unit=in_file,nml=dump_response_knobs)
×
61
  endif
62
  call broadcast(n_time_steps)
×
63

64
  ! This routine initialises the response matrix and dumps it to file.
65
  ! This call will use the time step as specified in the input file.
66
  call init_and_dump(quiet)
×
67
  ! Now we deal with the other time steps in the sequence if n_time_steps > 1
68
  do istep=2,n_time_steps
×
69
     !Reduce the time step
70
     call next_time_step
×
71

72
     !Dump response
73
     call init_and_dump(quiet)
×
74
  enddo
75

76
  !Clean up
77
  call finish_dump_response
×
78

79
contains
80

81
  !> Changes to the next time step in the sequence as determined by the usual
82
  !> rules to reduce the timestep in a nonlinear simulation.
83
  subroutine next_time_step
×
84
    use gs2_time, only: code_dt, save_dt
85
    use gs2_reinit, only: reduce_time_step
86
    use fields, only: finish_fields_level_2
87
    use collisions, only: finish_collisions
88
    use dist_fn, only: finish_dist_fn_level_3
89
    implicit none
90

91
    !First reduce the time step
92
    call reduce_time_step
×
93

94
    !Save the time step
95
    call save_dt(code_dt)
×
96

97
    ! Now reset the modules -- we should _probably_ use the init system here
98
    ! to drop to the lowest level needed to change the time step (as we do in
99
    ! gs2_main)
100
    call finish_dist_fn_level_3
×
101
    call finish_collisions
×
102
    call finish_fields_level_2
×
103
  end subroutine next_time_step
×
104

105
  !> Initialise the response matrices and write to file
106
  subroutine init_and_dump(quiet)
×
107
    use fields, only: fields_pre_init, fields_init_response, set_dump_and_read_response, dump_response_to_file
108
    use job_manage, only: time_message
109
    use gs2_time, only: code_dt
110
    use mp, only: proc0
111
    implicit none
112
    logical, intent(in) :: quiet
113
    real :: time_measure(2)
114
    character (len=64) :: str_code_dt
115

116
    if(proc0.and.(.not.quiet)) write(*,'("")')
×
117
    time_measure = 0.
×
118

119
    !Prepare to initialise the fields
120
    if(proc0.and.(.not.quiet)) then
×
121
       write(*,'("Pre-init")',advance='no')
×
122
    endif
123
    call time_message(.false.,time_measure,'Pre-init')
×
124
    call fields_pre_init
×
125
    call time_message(.false.,time_measure,'Pre-init')
×
126
    if(proc0.and.(.not.quiet)) then
×
127
       write(*,'("  --> Done in : ",ES14.6E3," seconds")') time_measure(1)
×
128
    endif
129
    time_measure=0.
×
130

131
    !Now need to disable dump_response and read_response before
132
    !we try to initialise the response matrix
133
    call set_dump_and_read_response(.false.,.false.)
×
134

135
    !Now call the initialisation routine
136
    if(proc0.and.(.not.quiet)) then
×
137
       write(*,'("Init")', advance='no')
×
138
    endif
139
    call time_message(.false.,time_measure,'Init')
×
140
    call fields_init_response
×
141
    call time_message(.false.,time_measure,'Init')
×
142
    if(proc0.and.(.not.quiet)) then
×
143
       write(*,'("  --> Done in : ",ES14.6E3," seconds")') time_measure(1)
×
144
    endif
145
    time_measure=0.
×
146

147
    !Now we make the dt string
148
    write(str_code_dt,'(ES14.6E3)') code_dt
×
149

150
    !Now write response to files
151
    if(proc0.and.(.not.quiet)) then
×
152
       write(*,'("Dumping to file for timestep ",A,A,A)',advance='no') "'",trim(adjustl(str_code_dt)),"'"
×
153
    endif
154
    call time_message(.false.,time_measure,'Dump')
×
155
    call dump_response_to_file()
×
156
    call time_message(.false.,time_measure,'Dump')
×
157
    if(proc0.and.(.not.quiet)) then
×
158
       write(*,'("  --> Done in : ",ES14.6E3," seconds")') time_measure(1)
×
159
    endif
160
    time_measure=0.
×
161
  end subroutine init_and_dump
×
162

163
  !> Call the finialise routines for any module we have initialised.
164
  subroutine finish_dump_response
×
165
    use antenna, only: finish_antenna
166
    use collisions, only: finish_collisions
167
    use dist_fn, only: finish_dist_fn
168
    use fields, only: finish_fields
169
    use file_utils, only: finish_file_utils
170
    use hyper, only: finish_hyper
171
    use init_g, only: finish_init_g
172
    use kt_grids, only: finish_kt_grids
173
    use le_grids, only: finish_le_grids
174
    use mp, only: proc0, finish_mp
175
    use run_parameters, only: finish_run_parameters
176
    use species, only: finish_species
177

178
    implicit none
179

180
    call finish_antenna
×
181
    call finish_collisions
×
182
    call finish_dist_fn
×
183
    call finish_fields
×
184
    call finish_hyper
×
185
    call finish_init_g
×
186
    call finish_kt_grids
×
187
    call finish_le_grids
×
188
    call finish_run_parameters
×
189
    call finish_species
×
190
    if (proc0) call finish_file_utils
×
191
    call finish_mp
×
192

193
  end subroutine finish_dump_response
×
194
end program dump_response
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