-
Notifications
You must be signed in to change notification settings - Fork 39
/
madx_ptc_intstate.f90
463 lines (369 loc) · 13.3 KB
/
madx_ptc_intstate.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
module madx_ptc_intstate_module
use madx_keywords
implicit none
save
!============================================================================================
! PUBLIC INTERFACE
public :: getintstate
public :: setintstate
public :: initintstate
public :: getmaxaccel
public :: getdebug
public :: getenforce6D
public :: setenforce6D
public :: ptc_setdebuglevel
public :: ptc_setmapdumplevel
public :: ptc_setmadprint
public :: ptc_setseed
public :: ptc_setaccel_method
public :: ptc_setexactmis
public :: ptc_setradiation
public :: ptc_setmodulation
public :: ptc_settotalpath
public :: ptc_settime
public :: ptc_setnocavity
public :: ptc_setspin
public :: ptc_setstochastic
public :: ptc_setenvelope
public :: ptc_setfringe
public :: printintstate
private
!============================================================================================
! PRIVATE
! data structures
logical(lp), public :: maxaccel ! switch saying to make the reference particle to fly always on the crest
logical(lp), public :: enforce6D = .false. ! normally 6D is reduced to 4D if no cavities are present
! this switch prevents it. It is needed to calcualte fg R56 in a chicane
type (internal_state), private :: intstate = default0
integer, private :: debug = 1 ! defines debug level
! routines
!--none--!
!============================================================================================
contains
logical(lp) function getmaxaccel()
implicit none
getmaxaccel = maxaccel
return
end function getmaxaccel
!____________________________________________________________________________________________
type (internal_state) function getintstate()
implicit none
!returns the internal state
getintstate = intstate
return
end function getintstate
!____________________________________________________________________________________________
subroutine setintstate(state)
implicit none
type (internal_state) :: state
!sets the internal state
!if (getdebug() > 1)
intstate = state
if (associated(c_%no) .and. getdebug() > 1) call print(intstate,6)
end subroutine setintstate
!____________________________________________________________________________________________
integer function getdebug()
implicit none
getdebug = debug
end function getdebug
!____________________________________________________________________________________________
subroutine initintstate(intst)
implicit none
type (internal_state) :: intst
!if (getdebug() > 1)
print *, "Initializing internal state"
intstate = intst - nocavity0
call update_states
if ( associated(c_%no) .and. getdebug() > 1) call print(intstate,6)
end subroutine initintstate
!____________________________________________________________________________________________
subroutine ptc_resetinternalstate
implicit none
if (getdebug() > 1) then
print *, "Setting internal state to DEFAULT0"
end if
intstate = default0
default = intstate
call update_states
if (associated(c_%no) .and. getdebug() > 1) call print(intstate,6)
end subroutine ptc_resetinternalstate
!____________________________________________________________________________________________
subroutine ptc_setdebuglevel(level)
implicit none
integer :: level
if (level > 0) then
print *, "Setting debug level to", level
end if
debug = level
end subroutine ptc_setdebuglevel
!____________________________________________________________________________________________
subroutine ptc_setmapdumplevel(level)
use s_extend_poly, only : mapdump ! LD:29.03.2019
implicit none
integer :: level
if (level > 0) then
print *, "Setting mapdump level to", level
end if
mapdump = level
end subroutine ptc_setmapdumplevel
!____________________________________________________________________________________________
subroutine ptc_setmadprint(level)
use precision_constants, only : madxprint ! LD:13.01.2022
implicit none
integer :: level
if (level > 0) then
print *, "Setting madprint level to", level
end if
madxprint = level.ne.0
end subroutine ptc_setmadprint
!____________________________________________________________________________________________
subroutine ptc_setseed(seed)
USE gauss_dis
implicit none
integer :: seed
if (getdebug() > 0) then
print *, "Setting seed to", seed
end if
CALL gaussian_seed(seed)
end subroutine ptc_setseed
!____________________________________________________________________________________________
subroutine setenforce6D(flag)
implicit none
integer :: flag
if (flag == 0) then
if (getdebug() > 1) then
print *, "Switching off ENFORCE6D"
end if
enforce6D = .false.
else
if (getdebug() > 1) then
print *, "Setting ENFORCE6D"
end if
enforce6D = .true.
endif
end subroutine setenforce6D
!____________________________________________________________________________________________
logical(lp) function getenforce6D()
implicit none
getenforce6D = enforce6D
! print *, getenforce6D
end function getenforce6D
!____________________________________________________________________________________________
subroutine ptc_setaccel_method(flag)
implicit none
integer :: flag
if (flag == 1) then
if (getdebug() > 1) then
print *, "Setting MAX ACCEL"
end if
maxaccel = .true.
endif
end subroutine ptc_setaccel_method
!____________________________________________________________________________________________
subroutine ptc_setexactmis(flag)
implicit none
integer :: flag
! print *, "Setting the flag"
! print *, "And the flag is", flag
if (flag == 1) then
if (getdebug() > 1) then
print *, "Switching ON exact missaligment"
end if
always_exactmis=.true.
else
if (getdebug() > 1) then
print *, "Switching OFF exact missaligment"
end if
always_exactmis=.false.
endif
default = intstate
call update_states
if (associated(c_%no) .and. getdebug() > 1) call print(intstate,6)
end subroutine ptc_setexactmis
!____________________________________________________________________________________________
subroutine ptc_setradiation(flag)
implicit none
integer :: flag
if (flag == 1) then
if (getdebug() > 1) then
print *, "Switching ON radiation"
end if
intstate = intstate + radiation0
else
if (getdebug() > 1) then
print *, "Switching OFF radiation"
end if
intstate = intstate - radiation0
endif
default = intstate
call update_states
if (associated(c_%no) .and. getdebug() > 1) call print(intstate,6)
end subroutine ptc_setradiation
!____________________________________________________________________________________________
subroutine ptc_setmodulation(flag)
implicit none
integer :: flag
if (flag == 1) then
if (getdebug() > 1) then
print *, "Switching ON modulation"
end if
intstate = intstate + modulation0
else
if (getdebug() > 1) then
print *, "Switching OFF modulation"
end if
intstate = intstate - modulation0
endif
default = intstate
call update_states
if (associated(c_%no) .and. getdebug() > 1) call print(intstate,6)
end subroutine ptc_setmodulation
!____________________________________________________________________________________________
subroutine ptc_setspin(flag)
implicit none
integer :: flag
if (flag == 1) then
if (getdebug() > 1) then
print *, "Switching ON spin"
end if
intstate = intstate + spin0
else
if (getdebug() > 1) then
print *, "Switching OFF spin"
end if
intstate = intstate - spin0
endif
default = intstate
call update_states
if (associated(c_%no) .and. getdebug() > 1) call print(intstate,6)
end subroutine ptc_setspin
!____________________________________________________________________________________________
subroutine ptc_setstochastic(flag)
implicit none
integer :: flag
if (flag == 1) then
if (getdebug() > 1) then
print *, "Switching ON stochastic"
end if
intstate = intstate + stochastic0
else
if (getdebug() > 1) then
print *, "Switching OFF stochastic"
end if
intstate = intstate - stochastic0
endif
default = intstate
call update_states
if (associated(c_%no) .and. getdebug() > 1) call print(intstate,6)
end subroutine ptc_setstochastic
!____________________________________________________________________________________________
subroutine ptc_setenvelope(flag)
implicit none
integer :: flag
if (flag == 1) then
if (getdebug() > 1) then
print *, "Switching ON envelope"
end if
intstate = intstate + envelope0
else
if (getdebug() > 1) then
print *, "Switching OFF envelope"
end if
intstate = intstate - envelope0
endif
default = intstate
call update_states
if (associated(c_%no) .and. getdebug() > 1) call print(intstate,6)
end subroutine ptc_setenvelope
!____________________________________________________________________________________________
subroutine ptc_setfringe(flag)
implicit none
integer :: flag
if (flag == 1) then
if (getdebug() > 1) then
print *, "Switching ON fringe"
end if
intstate = intstate + fringe0
else
if (getdebug() > 1) then
print *, "Switching OFF fringe"
end if
intstate = intstate - fringe0
endif
default = intstate
call update_states
if (associated(c_%no) .and. getdebug() > 1) call print(intstate,6)
end subroutine ptc_setfringe
!____________________________________________________________________________________________
subroutine ptc_settotalpath(flag)
implicit none
integer :: flag
if (flag == 1) then
if (getdebug() > 1) then
print *, "Switching ON totalpath (and switching OFF delta and only_4d)"
end if
!intstate = intstate + totalpath0
! actually this is done automatically by PTC: only_4d can not be together with totalpath, detla can be on exclusively with only_4d
intstate = intstate - delta0 - only_4d0 + totalpath0
else
if (getdebug() > 1) then
print *, "Switching OFF totalpath"
end if
intstate = intstate - totalpath0
endif
default = intstate
call update_states
if (associated(c_%no) .and. getdebug() > 1) call print(intstate,6)
end subroutine ptc_settotalpath
!____________________________________________________________________________________________
subroutine ptc_settime(flag)
implicit none
integer :: flag
! print *, "Setting the flag"
! print *, "And the flag is", flag
if (flag == 1) then
if (getdebug() > 1) then
print *, "Switching ON time"
end if
intstate = intstate + time0
else
if (getdebug() > 1) then
print *, "Switching OFF time"
end if
intstate = intstate - time0
endif
default = intstate
call update_states
if (associated(c_%no) .and. getdebug() > 1) call print(intstate,6)
end subroutine ptc_settime
!____________________________________________________________________________________________
subroutine ptc_setnocavity(flag)
implicit none
integer :: flag
if (flag == 1) then
if (getdebug() > 1) then
print *, "Switching ON nocavity"
end if
intstate = intstate + nocavity0
else
if (getdebug() > 1) then
print *, "Switching OFF nocavity and (also) delta and only_4d"
end if
intstate = intstate - delta0 - only_4d0 - nocavity0
endif
default = intstate
call update_states
if (associated(c_%no) .and. getdebug() > 1) call print(intstate,6)
end subroutine ptc_setnocavity
!____________________________________________________________________________________________
subroutine printintstate(n)
implicit none
integer :: n
if (associated(c_%no) ) then
call print(intstate,n)
else
write(n,*) 'printintstate: Can not print, PTC is not initialized yet'
endif
end subroutine printintstate
!____________________________________________________________________________________________
end module madx_ptc_intstate_module